LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 {
108  };
110 
111  // Constructors / Destructor
112  Schematic() = delete;
113  Schematic(const Schematic& other) = delete;
114  Schematic(Project& project, std::unique_ptr<TransactionalDirectory> directory)
115  : Schematic(project, std::move(directory), false, QString()) {}
116  ~Schematic() noexcept;
117 
118  // Getters: General
119  Project& getProject() const noexcept { return mProject; }
120  FilePath getFilePath() const noexcept;
121  const GridProperties& getGridProperties() const noexcept {
122  return *mGridProperties;
123  }
124  GraphicsScene& getGraphicsScene() const noexcept { return *mGraphicsScene; }
125  bool isEmpty() const noexcept;
126  QList<SI_Base*> getItemsAtScenePos(const Point& pos) const noexcept;
127  QList<SI_NetPoint*> getNetPointsAtScenePos(const Point& pos) const noexcept;
128  QList<SI_NetLine*> getNetLinesAtScenePos(const Point& pos) const noexcept;
129  QList<SI_NetLabel*> getNetLabelsAtScenePos(const Point& pos) const noexcept;
130  QList<SI_SymbolPin*> getPinsAtScenePos(const Point& pos) const noexcept;
131 
132  // Setters: General
133  void setGridProperties(const GridProperties& grid) noexcept;
134 
135  // Getters: Attributes
136  const Uuid& getUuid() const noexcept { return mUuid; }
137  const ElementName& getName() const noexcept { return mName; }
138  const QIcon& getIcon() const noexcept { return mIcon; }
139 
140  // Symbol Methods
141  QList<SI_Symbol*> getSymbols() const noexcept { return mSymbols; }
142  SI_Symbol* getSymbolByUuid(const Uuid& uuid) const noexcept;
143  void addSymbol(SI_Symbol& symbol);
144  void removeSymbol(SI_Symbol& symbol);
145 
146  // NetSegment Methods
147  SI_NetSegment* getNetSegmentByUuid(const Uuid& uuid) const noexcept;
148  void addNetSegment(SI_NetSegment& netsegment);
149  void removeNetSegment(SI_NetSegment& netsegment);
150 
151  // General Methods
152  void addToProject();
153  void removeFromProject();
154  void save();
155  void showInView(GraphicsView& view) noexcept;
156  void saveViewSceneRect(const QRectF& rect) noexcept { mViewRect = rect; }
157  const QRectF& restoreViewSceneRect() const noexcept { return mViewRect; }
158  void setSelectionRect(const Point& p1, const Point& p2,
159  bool updateItems) noexcept;
160  void clearSelection() const noexcept;
161  void updateAllNetLabelAnchors() noexcept;
162  void renderToQPainter(QPainter& painter) const noexcept;
163  std::unique_ptr<SchematicSelectionQuery> createSelectionQuery() const
164  noexcept;
165 
166  // Inherited from AttributeProvider
168  QString getBuiltInAttributeValue(const QString& key) const noexcept override;
170  QVector<const AttributeProvider*> getAttributeProviderParents() const
171  noexcept override;
172 
173  // Operator Overloadings
174  Schematic& operator=(const Schematic& rhs) = delete;
175  bool operator==(const Schematic& rhs) noexcept { return (this == &rhs); }
176  bool operator!=(const Schematic& rhs) noexcept { return (this != &rhs); }
177 
178  // Static Methods
179  static Schematic* create(Project& project,
180  std::unique_ptr<TransactionalDirectory> directory,
181  const ElementName& name);
182 
183 signals:
184 
186  void attributesChanged() override;
187 
188 private:
189  Schematic(Project& project, std::unique_ptr<TransactionalDirectory> directory,
190  bool create, const QString& newName);
191  void updateIcon() noexcept;
192 
194  void serialize(SExpression& root) const override;
195 
196  // General
200 
201  QScopedPointer<GraphicsScene> mGraphicsScene;
203  QRectF mViewRect;
204 
205  // Attributes
208  QIcon mIcon;
209 
212 };
213 
214 /*******************************************************************************
215  * End of File
216  ******************************************************************************/
217 
218 } // namespace project
219 } // namespace librepcb
220 
221 #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:201
void setSelectionRect(const Point &p1, const Point &p2, bool updateItems) noexcept
Definition: schematic.cpp:368
~Schematic() noexcept
Definition: schematic.cpp:127
The SI_NetPoint class.
Definition: si_netpoint.h:48
QList< SI_NetLabel * > getNetLabelsAtScenePos(const Point &pos) const noexcept
Definition: schematic.cpp:207
The SchematicSelectionQuery class.
Definition: schematicselectionquery.h:50
SI_NetSegment * getNetSegmentByUuid(const Uuid &uuid) const noexcept
Definition: schematic.cpp:277
bool operator!=(const Schematic &rhs) noexcept
Definition: schematic.h:176
ElementName mName
Definition: schematic.h:207
this is the default value (behind all other items)
Definition: schematic.h:102
SI_Symbol * getSymbolByUuid(const Uuid &uuid) const noexcept
Definition: schematic.cpp:240
QIcon mIcon
Definition: schematic.h:208
QList< SI_Base * > getItemsAtScenePos(const Point &pos) const noexcept
Definition: schematic.cpp:152
const Uuid & getUuid() const noexcept
Definition: schematic.h:136
void removeFromProject()
Definition: schematic.cpp:334
void setGridProperties(const GridProperties &grid) noexcept
Definition: schematic.cpp:232
void saveViewSceneRect(const QRectF &rect) noexcept
Definition: schematic.h:156
The Schematic class represents one schematic page of a project and is always part of a circuit...
Definition: schematic.h:83
The Schematic Item Base (SI_Base) class.
Definition: si_base.h:52
The GraphicsView class.
Definition: graphicsview.h:47
const QIcon & getIcon() const noexcept
Definition: schematic.h:138
std::unique_ptr< SchematicSelectionQuery > createSelectionQuery() const noexcept
Definition: schematic.cpp:404
The Project class represents a whole (opened) project with all its content.
Definition: project.h:79
Helper class to access a subdirectory of TransactionalFileSystem.
Definition: transactionaldirectory.h:52
The GridProperties class.
Definition: gridproperties.h:43
Schematic(Project &project, std::unique_ptr< TransactionalDirectory > directory)
Definition: schematic.h:114
void save()
Definition: schematic.cpp:353
void updateAllNetLabelAnchors() noexcept
Definition: schematic.cpp:392
static Schematic * create(Project &project, std::unique_ptr< TransactionalDirectory > directory, const ElementName &name)
Definition: schematic.cpp:452
Uuid mUuid
Definition: schematic.h:206
QString getBuiltInAttributeValue(const QString &key) const noexceptoverride
Get the value of a built-in attribute (if available)
Definition: schematic.cpp:414
void updateIcon() noexcept
Definition: schematic.cpp:433
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:210
The SI_SymbolPin class.
Definition: si_symbolpin.h:58
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:199
void clearSelection() const noexcept
Definition: schematic.cpp:387
std::unique_ptr< TransactionalDirectory > mDirectory
Definition: schematic.h:198
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: schematic.cpp:437
QScopedPointer< GridProperties > mGridProperties
Definition: schematic.h:202
QRectF mViewRect
Definition: schematic.h:203
GraphicsScene & getGraphicsScene() const noexcept
Definition: schematic.h:124
FilePath getFilePath() const noexcept
Definition: schematic.cpp:144
QVector< const AttributeProvider * > getAttributeProviderParents() const noexceptoverride
Get all parent attribute providers (fallback if attribute not found)
Definition: schematic.cpp:424
void addNetSegment(SI_NetSegment &netsegment)
Definition: schematic.cpp:284
The SI_NetSegment class.
Definition: si_netsegment.h:55
Z value for #project#SI_NetLine items.
Definition: schematic.h:105
QList< SI_NetSegment * > mNetSegments
Definition: schematic.h:211
const ElementName & getName() const noexcept
Definition: schematic.h:137
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:127
const QRectF & restoreViewSceneRect() const noexcept
Definition: schematic.h:157
void removeNetSegment(SI_NetSegment &netsegment)
Definition: schematic.cpp:301
Z value for #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:119
void showInView(GraphicsView &view) noexcept
Definition: schematic.cpp:364
The SI_NetLabel class.
Definition: si_netlabel.h:51
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
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:247
The SI_NetLine class.
Definition: si_netline.h:64
Project & mProject
A reference to the Project object (from the ctor)
Definition: schematic.h:197
void removeSymbol(SI_Symbol &symbol)
Definition: schematic.cpp:264
QList< SI_Symbol * > getSymbols() const noexcept
Definition: schematic.h:141
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:398
Z value for #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:314
const GridProperties & getGridProperties() const noexcept
Definition: schematic.h:121
Z value for hidden #project#SI_NetPoint items.
Definition: schematic.h:106