LibrePCB Developers Documentation
schematic.h
Go to the documentation of this file.
1 /*
2  * LibrePCB - Professional EDA for everyone!
3  * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4  * https://librepcb.org/
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef LIBREPCB_PROJECT_SCHEMATIC_H
21 #define LIBREPCB_PROJECT_SCHEMATIC_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
33 #include <librepcb/common/uuid.h>
34 
35 #include <QtCore>
36 #include <QtWidgets>
37 
38 #include <memory>
39 
40 /*******************************************************************************
41  * Namespace / Forward Declarations
42  ******************************************************************************/
43 namespace librepcb {
44 
45 class GridProperties;
46 class GraphicsView;
47 class GraphicsScene;
48 
49 namespace project {
50 
51 class Project;
52 class NetSignal;
53 class ComponentInstance;
54 class SI_Base;
55 class SI_Symbol;
56 class SI_SymbolPin;
57 class SI_NetSegment;
58 class SI_NetPoint;
59 class SI_NetLine;
60 class SI_NetLabel;
61 class SchematicSelectionQuery;
62 
63 /*******************************************************************************
64  * Class Schematic
65  ******************************************************************************/
66 
83 class Schematic final : public QObject,
84  public AttributeProvider,
85  public SerializableObject {
86  Q_OBJECT
87 
88 public:
89  // Types
90 
101  enum ItemZValue {
109  };
111 
112  // Constructors / Destructor
113  Schematic() = delete;
114  Schematic(const Schematic& other) = delete;
115  Schematic(Project& project, std::unique_ptr<TransactionalDirectory> directory)
116  : Schematic(project, std::move(directory), false, QString()) {}
117  ~Schematic() noexcept;
118 
119  // Getters: General
120  Project& getProject() const noexcept { return mProject; }
121  FilePath getFilePath() const noexcept;
122  const GridProperties& getGridProperties() const noexcept {
123  return *mGridProperties;
124  }
125  GraphicsScene& getGraphicsScene() const noexcept { return *mGraphicsScene; }
126  bool isEmpty() const noexcept;
127  QList<SI_Base*> getItemsAtScenePos(const Point& pos) const noexcept;
128  QList<SI_NetPoint*> getNetPointsAtScenePos(const Point& pos) const noexcept;
129  QList<SI_NetLine*> getNetLinesAtScenePos(const Point& pos) const noexcept;
130  QList<SI_NetLabel*> getNetLabelsAtScenePos(const Point& pos) const noexcept;
131  QList<SI_SymbolPin*> getPinsAtScenePos(const Point& pos) const noexcept;
132 
133  // Setters: General
134  void setGridProperties(const GridProperties& grid) noexcept;
135 
136  // Getters: Attributes
137  const Uuid& getUuid() const noexcept { return mUuid; }
138  const ElementName& getName() const noexcept { return mName; }
139  const QIcon& getIcon() const noexcept { return mIcon; }
140 
141  // Setters: Attributes
142  void setName(const ElementName& name) noexcept;
143 
144  // Symbol Methods
145  QList<SI_Symbol*> getSymbols() const noexcept { return mSymbols; }
146  SI_Symbol* getSymbolByUuid(const Uuid& uuid) const noexcept;
147  void addSymbol(SI_Symbol& symbol);
148  void removeSymbol(SI_Symbol& symbol);
149 
150  // NetSegment Methods
151  QList<SI_NetSegment*> getNetSegments() const noexcept { return mNetSegments; }
152  SI_NetSegment* getNetSegmentByUuid(const Uuid& uuid) const noexcept;
153  void addNetSegment(SI_NetSegment& netsegment);
154  void removeNetSegment(SI_NetSegment& netsegment);
155 
156  // General Methods
157  void addToProject();
158  void removeFromProject();
159  void save();
160  void showInView(GraphicsView& view) noexcept;
161  void saveViewSceneRect(const QRectF& rect) noexcept { mViewRect = rect; }
162  const QRectF& restoreViewSceneRect() const noexcept { return mViewRect; }
163  void selectAll() noexcept;
164  void setSelectionRect(const Point& p1, const Point& p2,
165  bool updateItems) noexcept;
166  void clearSelection() const noexcept;
167  void updateAllNetLabelAnchors() noexcept;
168  void renderToQPainter(QPainter& painter) const noexcept;
169  std::unique_ptr<SchematicSelectionQuery> createSelectionQuery() const
170  noexcept;
171 
172  // Inherited from AttributeProvider
174  QString getBuiltInAttributeValue(const QString& key) const noexcept override;
176  QVector<const AttributeProvider*> getAttributeProviderParents() const
177  noexcept override;
178 
179  // Operator Overloadings
180  Schematic& operator=(const Schematic& rhs) = delete;
181  bool operator==(const Schematic& rhs) noexcept { return (this == &rhs); }
182  bool operator!=(const Schematic& rhs) noexcept { return (this != &rhs); }
183 
184  // Static Methods
185  static Schematic* create(Project& project,
186  std::unique_ptr<TransactionalDirectory> directory,
187  const ElementName& name);
188 
189 signals:
190 
192  void attributesChanged() override;
193 
194 private:
195  Schematic(Project& project, std::unique_ptr<TransactionalDirectory> directory,
196  bool create, const QString& newName);
197  void updateIcon() noexcept;
198 
200  void serialize(SExpression& root) const override;
201 
202  // General
204  std::unique_ptr<TransactionalDirectory> mDirectory;
206 
207  QScopedPointer<GraphicsScene> mGraphicsScene;
208  QScopedPointer<GridProperties> mGridProperties;
209  QRectF mViewRect;
210 
211  // Attributes
214  QIcon mIcon;
215 
216  QList<SI_Symbol*> mSymbols;
217  QList<SI_NetSegment*> mNetSegments;
218 };
219 
220 /*******************************************************************************
221  * End of File
222  ******************************************************************************/
223 
224 } // namespace project
225 } // namespace librepcb
226 
227 #endif // LIBREPCB_PROJECT_SCHEMATIC_H
bool isEmpty() const noexcept
Definition: schematic.cpp:148
The SI_Symbol class.
Definition: si_symbol.h:57
QScopedPointer< GraphicsScene > mGraphicsScene
Definition: schematic.h:207
void setSelectionRect(const Point &p1, const Point &p2, bool updateItems) noexcept
Definition: schematic.cpp:378
~Schematic() noexcept
Definition: schematic.cpp:127
QList< SI_NetLabel * > getNetLabelsAtScenePos(const Point &pos) const noexcept
Definition: schematic.cpp:207
void selectAll() noexcept
Definition: schematic.cpp:373
SI_NetSegment * getNetSegmentByUuid(const Uuid &uuid) const noexcept
Definition: schematic.cpp:282
bool operator!=(const Schematic &rhs) noexcept
Definition: schematic.h:182
ElementName mName
Definition: schematic.h:213
this is the default value (behind all other items)
Definition: schematic.h:102
SI_Symbol * getSymbolByUuid(const Uuid &uuid) const noexcept
Definition: schematic.cpp:245
Definition: airwiresbuilder.cpp:32
QIcon mIcon
Definition: schematic.h:214
QList< SI_Base * > getItemsAtScenePos(const Point &pos) const noexcept
Definition: schematic.cpp:152
const Uuid & getUuid() const noexcept
Definition: schematic.h:137
void removeFromProject()
Definition: schematic.cpp:339
void setGridProperties(const GridProperties &grid) noexcept
Definition: schematic.cpp:232
void saveViewSceneRect(const QRectF &rect) noexcept
Definition: schematic.h:161
The Schematic class represents one schematic page of a project and is always part of a circuit...
Definition: schematic.h:83
bool operator==(const Schematic &rhs) noexcept
Definition: schematic.h:181
The GraphicsView class.
Definition: graphicsview.h:47
Schematic & operator=(const Schematic &rhs)=delete
const QIcon & getIcon() const noexcept
Definition: schematic.h:139
std::unique_ptr< SchematicSelectionQuery > createSelectionQuery() const noexcept
Definition: schematic.cpp:414
The Project class represents a whole (opened) project with all its content.
Definition: project.h:80
The GridProperties class.
Definition: gridproperties.h:43
Schematic(Project &project, std::unique_ptr< TransactionalDirectory > directory)
Definition: schematic.h:115
void save()
Definition: schematic.cpp:358
void updateAllNetLabelAnchors() noexcept
Definition: schematic.cpp:402
static Schematic * create(Project &project, std::unique_ptr< TransactionalDirectory > directory, const ElementName &name)
Definition: schematic.cpp:462
Uuid mUuid
Definition: schematic.h:212
void updateIcon() noexcept
Definition: schematic.cpp:443
void attributesChanged() override
This signal is emited when the value of attributes has changed.
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:43
ItemZValue
Z Values of all items in a schematic scene (to define the stacking order)
Definition: schematic.h:101
QList< SI_Symbol * > mSymbols
Definition: schematic.h:216
QList< SI_NetSegment * > getNetSegments() const noexcept
Definition: schematic.h:151
void setName(const ElementName &name) noexcept
Definition: schematic.cpp:236
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:78
bool mIsAddedToProject
Definition: schematic.h:205
void clearSelection() const noexcept
Definition: schematic.cpp:397
std::unique_ptr< TransactionalDirectory > mDirectory
Definition: schematic.h:204
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: schematic.cpp:447
QScopedPointer< GridProperties > mGridProperties
Definition: schematic.h:208
QRectF mViewRect
Definition: schematic.h:209
GraphicsScene & getGraphicsScene() const noexcept
Definition: schematic.h:125
FilePath getFilePath() const noexcept
Definition: schematic.cpp:144
void addNetSegment(SI_NetSegment &netsegment)
Definition: schematic.cpp:289
The SI_NetSegment class.
Definition: si_netsegment.h:55
Z value for librepcb::project::SI_NetLine items.
Definition: schematic.h:105
QList< SI_NetSegment * > mNetSegments
Definition: schematic.h:217
const ElementName & getName() const noexcept
Definition: schematic.h:138
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
const QRectF & restoreViewSceneRect() const noexcept
Definition: schematic.h:162
void removeNetSegment(SI_NetSegment &netsegment)
Definition: schematic.cpp:306
Z value for librepcb::project::SI_Symbol items.
Definition: schematic.h:103
QList< SI_NetPoint * > getNetPointsAtScenePos(const Point &pos) const noexcept
Definition: schematic.cpp:189
Project & getProject() const noexcept
Definition: schematic.h:120
void showInView(GraphicsView &view) noexcept
Definition: schematic.cpp:369
QString getBuiltInAttributeValue(const QString &key) const noexcept override
Get the value of a built-in attribute (if available)
Definition: schematic.cpp:424
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
QVector< const AttributeProvider * > getAttributeProviderParents() const noexcept override
Get all parent attribute providers (fallback if attribute not found)
Definition: schematic.cpp:434
QList< SI_SymbolPin * > getPinsAtScenePos(const Point &pos) const noexcept
Definition: schematic.cpp:216
The GraphicsScene class.
Definition: graphicsscene.h:43
void addSymbol(SI_Symbol &symbol)
Definition: schematic.cpp:252
Project & mProject
A reference to the Project object (from the ctor)
Definition: schematic.h:203
void removeSymbol(SI_Symbol &symbol)
Definition: schematic.cpp:269
QList< SI_Symbol * > getSymbols() const noexcept
Definition: schematic.h:145
The SExpression class.
Definition: sexpression.h:57
QList< SI_NetLine * > getNetLinesAtScenePos(const Point &pos) const noexcept
Definition: schematic.cpp:198
void renderToQPainter(QPainter &painter) const noexcept
Definition: schematic.cpp:408
Z value for librepcb::project::SI_NetLabel items.
Definition: schematic.h:104
The AttributeProvider class defines an interface for classes which provides some attributes which can...
Definition: attributeprovider.h:59
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:92
void addToProject()
Definition: schematic.cpp:319
const GridProperties & getGridProperties() const noexcept
Definition: schematic.h:122