LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
circuit.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_CIRCUIT_H
21 #define LIBREPCB_PROJECT_CIRCUIT_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
31 #include <librepcb/common/uuid.h>
33 
34 #include <QtCore>
35 
36 /*******************************************************************************
37  * Namespace / Forward Declarations
38  ******************************************************************************/
39 namespace librepcb {
40 
41 class SmartSExprFile;
42 
43 namespace library {
44 class Component;
45 }
46 
47 namespace project {
48 
49 class Project;
50 class NetClass;
51 class NetSignal;
52 class ComponentInstance;
53 
54 /*******************************************************************************
55  * Class Circuit
56  ******************************************************************************/
57 
75 class Circuit final : public QObject, public SerializableObject {
76  Q_OBJECT
77 
78 public:
79  // Constructors / Destructor
80  Circuit() = delete;
81  Circuit(const Circuit& other) = delete;
82  Circuit(Project& project, bool restore, bool readOnly, bool create);
83  ~Circuit() noexcept;
84 
85  // Getters
86  Project& getProject() const noexcept { return mProject; }
87 
88  // NetClass Methods
89  const QMap<Uuid, NetClass*>& getNetClasses() const noexcept {
90  return mNetClasses;
91  }
92  NetClass* getNetClassByUuid(const Uuid& uuid) const noexcept;
93  NetClass* getNetClassByName(const ElementName& name) const noexcept;
94  void addNetClass(NetClass& netclass);
95  void removeNetClass(NetClass& netclass);
96  void setNetClassName(NetClass& netclass, const ElementName& newName);
97 
98  // NetSignal Methods
99  QString generateAutoNetSignalName() const noexcept;
100  const QMap<Uuid, NetSignal*>& getNetSignals() const noexcept {
101  return mNetSignals;
102  }
103  NetSignal* getNetSignalByUuid(const Uuid& uuid) const noexcept;
104  NetSignal* getNetSignalByName(const QString& name) const noexcept;
105  NetSignal* getNetSignalWithMostElements() const noexcept;
106  void addNetSignal(NetSignal& netsignal);
107  void removeNetSignal(NetSignal& netsignal);
108  void setNetSignalName(NetSignal& netsignal, const CircuitIdentifier& newName,
109  bool isAutoName);
110  void setHighlightedNetSignal(NetSignal* signal) noexcept;
111 
112  // ComponentInstance Methods
114  const library::ComponentPrefix& cmpPrefix) const noexcept;
115  const QMap<Uuid, ComponentInstance*>& getComponentInstances() const noexcept {
116  return mComponentInstances;
117  }
119  noexcept;
120  ComponentInstance* getComponentInstanceByName(const QString& name) const
121  noexcept;
125  const CircuitIdentifier& newName);
126 
127  // General Methods
128  bool save(bool toOriginal, QStringList& errors) noexcept;
129 
130  // Operator Overloadings
131  Circuit& operator=(const Circuit& rhs) = delete;
132  bool operator==(const Circuit& rhs) noexcept { return (this == &rhs); }
133  bool operator!=(const Circuit& rhs) noexcept { return (this != &rhs); }
134 
135 signals:
136 
137  void netClassAdded(NetClass& netclass);
138  void netClassRemoved(NetClass& netclass);
139  void netSignalAdded(NetSignal& netsignal);
140  void netSignalRemoved(NetSignal& netsignal);
143 
144 private:
146  void serialize(SExpression& root) const override;
147 
148  // General
150 
151  // File "circuit/circuit.lp"
154 
155  QMap<Uuid, NetClass*> mNetClasses;
156  QMap<Uuid, NetSignal*> mNetSignals;
157  QMap<Uuid, ComponentInstance*> mComponentInstances;
158 };
159 
160 /*******************************************************************************
161  * End of File
162  ******************************************************************************/
163 
164 } // namespace project
165 } // namespace librepcb
166 
167 #endif // LIBREPCB_PROJECT_CIRCUIT_H
The Circuit class represents all electrical connections in a project (drawed in the schematics) ...
Definition: circuit.h:75
void removeComponentInstance(ComponentInstance &cmp)
Definition: circuit.cpp:360
NetSignal * getNetSignalWithMostElements() const noexcept
Definition: circuit.cpp:238
void addNetSignal(NetSignal &netsignal)
Definition: circuit.cpp:249
const QMap< Uuid, ComponentInstance * > & getComponentInstances() const noexcept
Definition: circuit.h:115
void removeNetClass(NetClass &netclass)
Definition: circuit.cpp:185
const QMap< Uuid, NetSignal * > & getNetSignals() const noexcept
Definition: circuit.h:100
FilePath mFilepath
Definition: circuit.h:152
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: circuit.cpp:411
void componentAdded(ComponentInstance &cmp)
void addNetClass(NetClass &netclass)
Definition: circuit.cpp:161
void addComponentInstance(ComponentInstance &cmp)
Definition: circuit.cpp:336
The Project class represents a whole (opened) project with all its content.
Definition: project.h:84
NetClass * getNetClassByName(const ElementName &name) const noexcept
Definition: circuit.cpp:152
void componentRemoved(ComponentInstance &cmp)
Project & mProject
A reference to the Project object (from the ctor)
Definition: circuit.h:149
bool operator!=(const Circuit &rhs) noexcept
Definition: circuit.h:133
bool operator==(const Circuit &rhs) noexcept
Definition: circuit.h:132
void setHighlightedNetSignal(NetSignal *signal) noexcept
Definition: circuit.cpp:302
QString generateAutoNetSignalName() const noexcept
Definition: circuit.cpp:216
NetSignal * getNetSignalByUuid(const Uuid &uuid) const noexcept
Definition: circuit.cpp:225
Project & getProject() const noexcept
Definition: circuit.h:86
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:46
void removeNetSignal(NetSignal &netsignal)
Definition: circuit.cpp:273
void netClassAdded(NetClass &netclass)
The SmartSExprFile class represents an S-Expressions file and provides methods to load/save DOM trees...
Definition: smartsexprfile.h:56
void setComponentInstanceName(ComponentInstance &cmp, const CircuitIdentifier &newName)
Definition: circuit.cpp:371
ComponentInstance * getComponentInstanceByName(const QString &name) const noexcept
Definition: circuit.cpp:328
void setNetClassName(NetClass &netclass, const ElementName &newName)
Definition: circuit.cpp:196
The NetClass class.
Definition: netclass.h:52
SmartSExprFile * mFile
Definition: circuit.h:153
type_safe::constrained_type< QString, ComponentPrefixConstraint, ComponentPrefixVerifier > ComponentPrefix
Definition: componentprefix.h:77
QMap< Uuid, ComponentInstance * > mComponentInstances
Definition: circuit.h:157
type_safe::constrained_type< QString, CircuitIdentifierConstraint, CircuitIdentifierVerifier > CircuitIdentifier
Definition: circuitidentifier.h:89
void netSignalRemoved(NetSignal &netsignal)
This class represents absolute, well-formatted paths to files or directories.
Definition: filepath.h:130
NetClass * getNetClassByUuid(const Uuid &uuid) const noexcept
Definition: circuit.cpp:148
bool save(bool toOriginal, QStringList &errors) noexcept
Definition: circuit.cpp:392
NetSignal * getNetSignalByName(const QString &name) const noexcept
Definition: circuit.cpp:229
void netSignalAdded(NetSignal &netsignal)
~Circuit() noexcept
Definition: circuit.cpp:115
const QMap< Uuid, NetClass * > & getNetClasses() const noexcept
Definition: circuit.h:89
QMap< Uuid, NetSignal * > mNetSignals
Definition: circuit.h:156
The NetSignal class.
Definition: netsignal.h:56
void netClassRemoved(NetClass &netclass)
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
QMap< Uuid, NetClass * > mNetClasses
Definition: circuit.h:155
void setNetSignalName(NetSignal &netsignal, const CircuitIdentifier &newName, bool isAutoName)
Definition: circuit.cpp:284
ComponentInstance * getComponentInstanceByUuid(const Uuid &uuid) const noexcept
Definition: circuit.cpp:323
The ComponentInstance class.
Definition: componentinstance.h:64
The SExpression class.
Definition: sexpression.h:60
Circuit & operator=(const Circuit &rhs)=delete
QString generateAutoComponentInstanceName(const library::ComponentPrefix &cmpPrefix) const noexcept
Definition: circuit.cpp:312
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:92