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  ******************************************************************************/
32 #include <librepcb/common/uuid.h>
33 
34 #include <QtCore>
35 #include <QtWidgets>
36 
37 #include <memory>
38 
39 /*******************************************************************************
40  * Namespace / Forward Declarations
41  ******************************************************************************/
42 namespace librepcb {
43 
44 class GridProperties;
45 class GraphicsView;
46 class GraphicsScene;
47 class SmartSExprFile;
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, const FilePath& filepath, bool restore,
115  bool readOnly)
116  : Schematic(project, filepath, restore, readOnly, false, QString()) {}
117  ~Schematic() noexcept;
118 
119  // Getters: General
120  Project& getProject() const noexcept { return mProject; }
121  const FilePath& getFilePath() const noexcept { return mFilePath; }
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  // Symbol Methods
142  QList<SI_Symbol*> getSymbols() const noexcept { return mSymbols; }
143  SI_Symbol* getSymbolByUuid(const Uuid& uuid) const noexcept;
144  void addSymbol(SI_Symbol& symbol);
145  void removeSymbol(SI_Symbol& symbol);
146 
147  // NetSegment Methods
148  SI_NetSegment* getNetSegmentByUuid(const Uuid& uuid) const noexcept;
149  void addNetSegment(SI_NetSegment& netsegment);
150  void removeNetSegment(SI_NetSegment& netsegment);
151 
152  // General Methods
153  void addToProject();
154  void removeFromProject();
155  bool save(bool toOriginal, QStringList& errors) noexcept;
156  void showInView(GraphicsView& view) noexcept;
157  void saveViewSceneRect(const QRectF& rect) noexcept { mViewRect = rect; }
158  const QRectF& restoreViewSceneRect() const noexcept { return mViewRect; }
159  void setSelectionRect(const Point& p1, const Point& p2,
160  bool updateItems) noexcept;
161  void clearSelection() const noexcept;
162  void updateAllNetLabelAnchors() noexcept;
163  void renderToQPainter(QPainter& painter) const noexcept;
164  std::unique_ptr<SchematicSelectionQuery> createSelectionQuery() const
165  noexcept;
166 
167  // Inherited from AttributeProvider
169  QString getBuiltInAttributeValue(const QString& key) const noexcept override;
171  QVector<const AttributeProvider*> getAttributeProviderParents() const
172  noexcept override;
173 
174  // Operator Overloadings
175  Schematic& operator=(const Schematic& rhs) = delete;
176  bool operator==(const Schematic& rhs) noexcept { return (this == &rhs); }
177  bool operator!=(const Schematic& rhs) noexcept { return (this != &rhs); }
178 
179  // Static Methods
180  static Schematic* create(Project& project, const FilePath& filepath,
181  const ElementName& name);
182 
183 signals:
184 
186  void attributesChanged() override;
187 
188 private:
189  Schematic(Project& project, const FilePath& filepath, bool restore,
190  bool readOnly, bool create, const QString& newName);
191  void updateIcon() noexcept;
192 
194  void serialize(SExpression& root) const override;
195 
196  // General
198  FilePath
200  QScopedPointer<SmartSExprFile> mFile;
202 
203  QScopedPointer<GraphicsScene> mGraphicsScene;
205  QRectF mViewRect;
206 
207  // Attributes
210  QIcon mIcon;
211 
214 };
215 
216 /*******************************************************************************
217  * End of File
218  ******************************************************************************/
219 
220 } // namespace project
221 } // namespace librepcb
222 
223 #endif // LIBREPCB_PROJECT_SCHEMATIC_H
bool isEmpty() const noexcept
Definition: schematic.cpp:153
The SI_Symbol class.
Definition: si_symbol.h:60
QScopedPointer< GraphicsScene > mGraphicsScene
Definition: schematic.h:203
void setSelectionRect(const Point &p1, const Point &p2, bool updateItems) noexcept
Definition: schematic.cpp:381
~Schematic() noexcept
Definition: schematic.cpp:135
The SI_NetPoint class.
Definition: si_netpoint.h:48
QList< SI_NetLabel * > getNetLabelsAtScenePos(const Point &pos) const noexcept
Definition: schematic.cpp:212
The SchematicSelectionQuery class.
Definition: schematicselectionquery.h:50
SI_NetSegment * getNetSegmentByUuid(const Uuid &uuid) const noexcept
Definition: schematic.cpp:282
bool operator!=(const Schematic &rhs) noexcept
Definition: schematic.h:177
ElementName mName
Definition: schematic.h:209
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
QIcon mIcon
Definition: schematic.h:210
QList< SI_Base * > getItemsAtScenePos(const Point &pos) const noexcept
Definition: schematic.cpp:157
const Uuid & getUuid() const noexcept
Definition: schematic.h:137
void removeFromProject()
Definition: schematic.cpp:339
void setGridProperties(const GridProperties &grid) noexcept
Definition: schematic.cpp:237
Schematic(Project &project, const FilePath &filepath, bool restore, bool readOnly)
Definition: schematic.h:114
void saveViewSceneRect(const QRectF &rect) noexcept
Definition: schematic.h:157
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
bool save(bool toOriginal, QStringList &errors) noexcept
Definition: schematic.cpp:358
The GraphicsView class.
Definition: graphicsview.h:47
const QIcon & getIcon() const noexcept
Definition: schematic.h:139
std::unique_ptr< SchematicSelectionQuery > createSelectionQuery() const noexcept
Definition: schematic.cpp:417
The Project class represents a whole (opened) project with all its content.
Definition: project.h:84
The GridProperties class.
Definition: gridproperties.h:43
void updateAllNetLabelAnchors() noexcept
Definition: schematic.cpp:405
Uuid mUuid
Definition: schematic.h:208
QString getBuiltInAttributeValue(const QString &key) const noexceptoverride
Get the value of a built-in attribute (if available)
Definition: schematic.cpp:427
void updateIcon() noexcept
Definition: schematic.cpp:446
void attributesChanged() override
This signal is emited when the value of attributes has changed.
FilePath mFilePath
the filepath of the schematic *.lp file (from the ctor)
Definition: schematic.h:199
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:46
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:212
The SI_SymbolPin class.
Definition: si_symbolpin.h:58
The SmartSExprFile class represents an S-Expressions file and provides methods to load/save DOM trees...
Definition: smartsexprfile.h:56
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:81
bool mIsAddedToProject
Definition: schematic.h:201
void clearSelection() const noexcept
Definition: schematic.cpp:400
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: schematic.cpp:458
QScopedPointer< GridProperties > mGridProperties
Definition: schematic.h:204
QRectF mViewRect
Definition: schematic.h:205
GraphicsScene & getGraphicsScene() const noexcept
Definition: schematic.h:125
static Schematic * create(Project &project, const FilePath &filepath, const ElementName &name)
Definition: schematic.cpp:473
QVector< const AttributeProvider * > getAttributeProviderParents() const noexceptoverride
Get all parent attribute providers (fallback if attribute not found)
Definition: schematic.cpp:437
void addNetSegment(SI_NetSegment &netsegment)
Definition: schematic.cpp:289
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:213
const ElementName & getName() const noexcept
Definition: schematic.h:138
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:130
const FilePath & getFilePath() const noexcept
Definition: schematic.h:121
const QRectF & restoreViewSceneRect() const noexcept
Definition: schematic.h:158
void removeNetSegment(SI_NetSegment &netsegment)
Definition: schematic.cpp:306
Z value for #project#SI_Symbol items.
Definition: schematic.h:103
QList< SI_NetPoint * > getNetPointsAtScenePos(const Point &pos) const noexcept
Definition: schematic.cpp:194
Project & getProject() const noexcept
Definition: schematic.h:120
void showInView(GraphicsView &view) noexcept
Definition: schematic.cpp:377
QScopedPointer< SmartSExprFile > mFile
Definition: schematic.h:200
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:221
The GraphicsScene class.
Definition: graphicsscene.h:43
void addSymbol(SI_Symbol &symbol)
Definition: schematic.cpp:252
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:269
QList< SI_Symbol * > getSymbols() const noexcept
Definition: schematic.h:142
The SExpression class.
Definition: sexpression.h:60
QList< SI_NetLine * > getNetLinesAtScenePos(const Point &pos) const noexcept
Definition: schematic.cpp:203
void renderToQPainter(QPainter &painter) const noexcept
Definition: schematic.cpp:411
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:62
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
Z value for hidden #project#SI_NetPoint items.
Definition: schematic.h:106