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_CORE_SCHEMATIC_H
21 #define LIBREPCB_CORE_SCHEMATIC_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../../fileio/filepath.h"
27 #include "../../fileio/transactionaldirectory.h"
28 #include "../../types/elementname.h"
29 #include "../../types/lengthunit.h"
30 #include "../../types/uuid.h"
31 
32 #include <QtCore>
33 
34 #include <memory>
35 
36 /*******************************************************************************
37  * Namespace / Forward Declarations
38  ******************************************************************************/
39 namespace librepcb {
40 
41 class ComponentInstance;
42 class NetSignal;
43 class Point;
44 class Project;
45 class SI_Base;
46 class SI_NetLabel;
47 class SI_NetLine;
48 class SI_NetPoint;
49 class SI_NetSegment;
50 class SI_Polygon;
51 class SI_Symbol;
52 class SI_SymbolPin;
53 class SI_Text;
54 
55 /*******************************************************************************
56  * Class Schematic
57  ******************************************************************************/
58 
74 class Schematic final : public QObject {
75  Q_OBJECT
76 
77 public:
78  // Constructors / Destructor
79  Schematic() = delete;
80  Schematic(const Schematic& other) = delete;
81  Schematic(Project& project, std::unique_ptr<TransactionalDirectory> directory,
82  const QString& directoryName, const Uuid& uuid,
83  const ElementName& name);
84  ~Schematic() noexcept;
85 
86  // Getters: General
87  Project& getProject() const noexcept { return mProject; }
88  const QString& getDirectoryName() const noexcept { return mDirectoryName; }
90  bool isEmpty() const noexcept;
91 
92  // Getters: Attributes
93  const Uuid& getUuid() const noexcept { return mUuid; }
94  const ElementName& getName() const noexcept { return mName; }
95  const PositiveLength& getGridInterval() const noexcept {
96  return mGridInterval;
97  }
98  const LengthUnit& getGridUnit() const noexcept { return mGridUnit; }
99 
100  // Setters: Attributes
101  void setName(const ElementName& name) noexcept;
102  void setGridInterval(const PositiveLength& interval) noexcept {
103  mGridInterval = interval;
104  }
105  void setGridUnit(const LengthUnit& unit) noexcept { mGridUnit = unit; }
106 
107  // Symbol Methods
108  const QMap<Uuid, SI_Symbol*>& getSymbols() const noexcept { return mSymbols; }
109  void addSymbol(SI_Symbol& symbol);
110  void removeSymbol(SI_Symbol& symbol);
111 
112  // NetSegment Methods
113  const QMap<Uuid, SI_NetSegment*>& getNetSegments() const noexcept {
114  return mNetSegments;
115  }
116  void addNetSegment(SI_NetSegment& netsegment);
117  void removeNetSegment(SI_NetSegment& netsegment);
118 
119  // Polygon Methods
120  const QMap<Uuid, SI_Polygon*>& getPolygons() const noexcept {
121  return mPolygons;
122  }
123  void addPolygon(SI_Polygon& polygon);
124  void removePolygon(SI_Polygon& polygon);
125 
126  // Text Methods
127  const QMap<Uuid, SI_Text*>& getTexts() const noexcept { return mTexts; }
128  void addText(SI_Text& text);
129  void removeText(SI_Text& text);
130 
131  // General Methods
132  void addToProject();
133  void removeFromProject();
134  void save();
135  void updateAllNetLabelAnchors() noexcept;
136 
137  // Operator Overloadings
138  Schematic& operator=(const Schematic& rhs) = delete;
139  bool operator==(const Schematic& rhs) noexcept { return (this == &rhs); }
140  bool operator!=(const Schematic& rhs) noexcept { return (this != &rhs); }
141 
142 signals:
143  void symbolAdded(SI_Symbol& symbol);
144  void symbolRemoved(SI_Symbol& symbol);
145  void netSegmentAdded(SI_NetSegment& netSegment);
146  void netSegmentRemoved(SI_NetSegment& netSegment);
147  void polygonAdded(SI_Polygon& polygon);
148  void polygonRemoved(SI_Polygon& polygon);
149  void textAdded(SI_Text& text);
150  void textRemoved(SI_Text& text);
151 
152  void attributesChanged();
153 
154 private:
155  // General
157  const QString mDirectoryName;
158  std::unique_ptr<TransactionalDirectory> mDirectory;
160 
161  // Attributes
166 
167  QMap<Uuid, SI_Symbol*> mSymbols;
168  QMap<Uuid, SI_NetSegment*> mNetSegments;
169  QMap<Uuid, SI_Polygon*> mPolygons;
170  QMap<Uuid, SI_Text*> mTexts;
171 };
172 
173 /*******************************************************************************
174  * End of File
175  ******************************************************************************/
176 
177 } // namespace librepcb
178 
179 #endif
void addSymbol(SI_Symbol &symbol)
Definition: schematic.cpp:110
void addText(SI_Text &text)
Definition: schematic.cpp:199
The SI_Text class represents a text label in a schematic.
Definition: si_text.h:48
const QString & getDirectoryName() const noexcept
Definition: schematic.h:88
void textAdded(SI_Text &text)
QMap< Uuid, SI_NetSegment * > mNetSegments
Definition: schematic.h:168
bool mIsAddedToProject
Definition: schematic.h:159
void polygonAdded(SI_Polygon &polygon)
Schematic & operator=(const Schematic &rhs)=delete
void removeSymbol(SI_Symbol &symbol)
Definition: schematic.cpp:126
void symbolAdded(SI_Symbol &symbol)
Definition: occmodel.cpp:77
const QMap< Uuid, SI_Text * > & getTexts() const noexcept
Definition: schematic.h:127
Uuid mUuid
Definition: schematic.h:162
void polygonRemoved(SI_Polygon &polygon)
bool operator==(const Schematic &rhs) noexcept
Definition: schematic.h:139
TransactionalDirectory & getDirectory() noexcept
Definition: schematic.h:89
~Schematic() noexcept
Definition: schematic.cpp:74
Helper class to access a subdirectory of TransactionalFileSystem.
Definition: transactionaldirectory.h:51
const PositiveLength & getGridInterval() const noexcept
Definition: schematic.h:95
const QMap< Uuid, SI_NetSegment * > & getNetSegments() const noexcept
Definition: schematic.h:113
QMap< Uuid, SI_Polygon * > mPolygons
Definition: schematic.h:169
LengthUnit mGridUnit
Definition: schematic.h:165
void symbolRemoved(SI_Symbol &symbol)
Project & mProject
A reference to the Project object (from the ctor)
Definition: schematic.h:156
void setName(const ElementName &name) noexcept
Definition: schematic.cpp:101
The Schematic class represents one schematic page of a project and is always part of a circuit...
Definition: schematic.h:74
void removeNetSegment(SI_NetSegment &netsegment)
Definition: schematic.cpp:155
void setGridInterval(const PositiveLength &interval) noexcept
Definition: schematic.h:102
QMap< Uuid, SI_Text * > mTexts
Definition: schematic.h:170
void addNetSegment(SI_NetSegment &netsegment)
Definition: schematic.cpp:139
void setGridUnit(const LengthUnit &unit) noexcept
Definition: schematic.h:105
PositiveLength mGridInterval
Definition: schematic.h:164
void removeText(SI_Text &text)
Definition: schematic.cpp:214
const ElementName & getName() const noexcept
Definition: schematic.h:94
void save()
Definition: schematic.cpp:294
const LengthUnit & getGridUnit() const noexcept
Definition: schematic.h:98
const QMap< Uuid, SI_Polygon * > & getPolygons() const noexcept
Definition: schematic.h:120
The Project class represents a whole (opened) project with all its content.
Definition: project.h:71
std::unique_ptr< TransactionalDirectory > mDirectory
Definition: schematic.h:158
bool isEmpty() const noexcept
Definition: schematic.cpp:92
bool operator!=(const Schematic &rhs) noexcept
Definition: schematic.h:140
void updateAllNetLabelAnchors() noexcept
Definition: schematic.cpp:328
void removePolygon(SI_Polygon &polygon)
Definition: schematic.cpp:185
The SI_Symbol class.
Definition: si_symbol.h:54
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:812
void netSegmentRemoved(SI_NetSegment &netSegment)
void textRemoved(SI_Text &text)
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
const Uuid & getUuid() const noexcept
Definition: schematic.h:93
void netSegmentAdded(SI_NetSegment &netSegment)
void addPolygon(SI_Polygon &polygon)
Definition: schematic.cpp:169
The SI_Polygon class represents a polygon in a schematic.
Definition: si_polygon.h:47
The LengthUnit class represents a length unit (millimeters, inches,...) and provides some useful meth...
Definition: lengthunit.h:60
ElementName mName
Definition: schematic.h:163
QMap< Uuid, SI_Symbol * > mSymbols
Definition: schematic.h:167
void addToProject()
Definition: schematic.cpp:227
const QString mDirectoryName
Definition: schematic.h:157
const QMap< Uuid, SI_Symbol * > & getSymbols() const noexcept
Definition: schematic.h:108
The SI_NetSegment class.
Definition: si_netsegment.h:53
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:84
void removeFromProject()
Definition: schematic.cpp:262
Project & getProject() const noexcept
Definition: schematic.h:87