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  SI_NetSegment* getNetSegmentByUuid(const Uuid& uuid) const noexcept;
152  void addNetSegment(SI_NetSegment& netsegment);
153  void removeNetSegment(SI_NetSegment& netsegment);
154 
155  // General Methods
156  void addToProject();
157  void removeFromProject();
158  void save();
159  void showInView(GraphicsView& view) noexcept;
160  void saveViewSceneRect(const QRectF& rect) noexcept { mViewRect = rect; }
161  const QRectF& restoreViewSceneRect() const noexcept { return mViewRect; }
162  void setSelectionRect(const Point& p1, const Point& p2,
163  bool updateItems) noexcept;
164  void clearSelection() const noexcept;
165  void updateAllNetLabelAnchors() noexcept;
166  void renderToQPainter(QPainter& painter) const noexcept;
167  std::unique_ptr<SchematicSelectionQuery> createSelectionQuery() const
168  noexcept;
169 
170  // Inherited from AttributeProvider
172  QString getBuiltInAttributeValue(const QString& key) const noexcept override;
174  QVector<const AttributeProvider*> getAttributeProviderParents() const
175  noexcept override;
176 
177  // Operator Overloadings
178  Schematic& operator=(const Schematic& rhs) = delete;
179  bool operator==(const Schematic& rhs) noexcept { return (this == &rhs); }
180  bool operator!=(const Schematic& rhs) noexcept { return (this != &rhs); }
181 
182  // Static Methods
183  static Schematic* create(Project& project,
184  std::unique_ptr<TransactionalDirectory> directory,
185  const ElementName& name);
186 
187 signals:
188 
190  void attributesChanged() override;
191 
192 private:
193  Schematic(Project& project, std::unique_ptr<TransactionalDirectory> directory,
194  bool create, const QString& newName);
195  void updateIcon() noexcept;
196 
198  void serialize(SExpression& root) const override;
199 
200  // General
202  std::unique_ptr<TransactionalDirectory> mDirectory;
204 
205  QScopedPointer<GraphicsScene> mGraphicsScene;
206  QScopedPointer<GridProperties> mGridProperties;
207  QRectF mViewRect;
208 
209  // Attributes
212  QIcon mIcon;
213 
214  QList<SI_Symbol*> mSymbols;
215  QList<SI_NetSegment*> mNetSegments;
216 };
217 
218 /*******************************************************************************
219  * End of File
220  ******************************************************************************/
221 
222 } // namespace project
223 } // namespace librepcb
224 
225 #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:205
void setSelectionRect(const Point &p1, const Point &p2, bool updateItems) noexcept
Definition: schematic.cpp:373
~Schematic() noexcept
Definition: schematic.cpp:127
QList< SI_NetLabel * > getNetLabelsAtScenePos(const Point &pos) const noexcept
Definition: schematic.cpp:207
SI_NetSegment * getNetSegmentByUuid(const Uuid &uuid) const noexcept
Definition: schematic.cpp:282
bool operator!=(const Schematic &rhs) noexcept
Definition: schematic.h:180
ElementName mName
Definition: schematic.h:211
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: alignment.cpp:30
QIcon mIcon
Definition: schematic.h:212
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:160
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:179
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:409
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:397
static Schematic * create(Project &project, std::unique_ptr< TransactionalDirectory > directory, const ElementName &name)
Definition: schematic.cpp:457
Uuid mUuid
Definition: schematic.h:210
void updateIcon() noexcept
Definition: schematic.cpp:438
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:214
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:203
void clearSelection() const noexcept
Definition: schematic.cpp:392
std::unique_ptr< TransactionalDirectory > mDirectory
Definition: schematic.h:202
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: schematic.cpp:442
QScopedPointer< GridProperties > mGridProperties
Definition: schematic.h:206
QRectF mViewRect
Definition: schematic.h:207
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:215
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:161
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:419
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:429
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:201
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:403
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