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 TransactionalDirectory;
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 
72 class Circuit final : public QObject, public SerializableObject {
73  Q_OBJECT
74 
75 public:
76  // Constructors / Destructor
77  Circuit() = delete;
78  Circuit(const Circuit& other) = delete;
79  Circuit(Project& project, bool create);
80  ~Circuit() noexcept;
81 
82  // Getters
83  Project& getProject() const noexcept { return mProject; }
84 
85  // NetClass Methods
86  const QMap<Uuid, NetClass*>& getNetClasses() const noexcept {
87  return mNetClasses;
88  }
89  NetClass* getNetClassByUuid(const Uuid& uuid) const noexcept;
90  NetClass* getNetClassByName(const ElementName& name) const noexcept;
91  void addNetClass(NetClass& netclass);
92  void removeNetClass(NetClass& netclass);
93  void setNetClassName(NetClass& netclass, const ElementName& newName);
94 
95  // NetSignal Methods
96  QString generateAutoNetSignalName() const noexcept;
97  const QMap<Uuid, NetSignal*>& getNetSignals() const noexcept {
98  return mNetSignals;
99  }
100  NetSignal* getNetSignalByUuid(const Uuid& uuid) const noexcept;
101  NetSignal* getNetSignalByName(const QString& name) const noexcept;
102  NetSignal* getNetSignalWithMostElements() const noexcept;
103  void addNetSignal(NetSignal& netsignal);
104  void removeNetSignal(NetSignal& netsignal);
105  void setNetSignalName(NetSignal& netsignal, const CircuitIdentifier& newName,
106  bool isAutoName);
107  void setHighlightedNetSignal(NetSignal* signal) noexcept;
108 
109  // ComponentInstance Methods
111  const library::ComponentPrefix& cmpPrefix) const noexcept;
112  const QMap<Uuid, ComponentInstance*>& getComponentInstances() const noexcept {
113  return mComponentInstances;
114  }
116  noexcept;
117  ComponentInstance* getComponentInstanceByName(const QString& name) const
118  noexcept;
122  const CircuitIdentifier& newName);
123 
124  // General Methods
125  void save();
126 
127  // Operator Overloadings
128  Circuit& operator=(const Circuit& rhs) = delete;
129  bool operator==(const Circuit& rhs) noexcept { return (this == &rhs); }
130  bool operator!=(const Circuit& rhs) noexcept { return (this != &rhs); }
131 
132 signals:
133 
134  void netClassAdded(NetClass& netclass);
135  void netClassRemoved(NetClass& netclass);
136  void netSignalAdded(NetSignal& netsignal);
137  void netSignalRemoved(NetSignal& netsignal);
140 
141 private:
143  void serialize(SExpression& root) const override;
144 
145  // General
147  QScopedPointer<TransactionalDirectory> mDirectory;
148 
149  QMap<Uuid, NetClass*> mNetClasses;
150  QMap<Uuid, NetSignal*> mNetSignals;
151  QMap<Uuid, ComponentInstance*> mComponentInstances;
152 };
153 
154 /*******************************************************************************
155  * End of File
156  ******************************************************************************/
157 
158 } // namespace project
159 } // namespace librepcb
160 
161 #endif // LIBREPCB_PROJECT_CIRCUIT_H
The Circuit class represents all electrical connections in a project (drawed in the schematics) ...
Definition: circuit.h:72
void removeComponentInstance(ComponentInstance &cmp)
Definition: circuit.cpp:349
NetSignal * getNetSignalWithMostElements() const noexcept
Definition: circuit.cpp:227
void addNetSignal(NetSignal &netsignal)
Definition: circuit.cpp:238
const QMap< Uuid, ComponentInstance * > & getComponentInstances() const noexcept
Definition: circuit.h:112
void removeNetClass(NetClass &netclass)
Definition: circuit.cpp:174
const QMap< Uuid, NetSignal * > & getNetSignals() const noexcept
Definition: circuit.h:97
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: circuit.cpp:390
void componentAdded(ComponentInstance &cmp)
void addNetClass(NetClass &netclass)
Definition: circuit.cpp:150
void addComponentInstance(ComponentInstance &cmp)
Definition: circuit.cpp:325
The Project class represents a whole (opened) project with all its content.
Definition: project.h:79
NetClass * getNetClassByName(const ElementName &name) const noexcept
Definition: circuit.cpp:141
void componentRemoved(ComponentInstance &cmp)
Project & mProject
A reference to the Project object (from the ctor)
Definition: circuit.h:146
bool operator!=(const Circuit &rhs) noexcept
Definition: circuit.h:130
bool operator==(const Circuit &rhs) noexcept
Definition: circuit.h:129
void setHighlightedNetSignal(NetSignal *signal) noexcept
Definition: circuit.cpp:291
QString generateAutoNetSignalName() const noexcept
Definition: circuit.cpp:205
NetSignal * getNetSignalByUuid(const Uuid &uuid) const noexcept
Definition: circuit.cpp:214
Project & getProject() const noexcept
Definition: circuit.h:83
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:43
void removeNetSignal(NetSignal &netsignal)
Definition: circuit.cpp:262
void netClassAdded(NetClass &netclass)
void setComponentInstanceName(ComponentInstance &cmp, const CircuitIdentifier &newName)
Definition: circuit.cpp:360
ComponentInstance * getComponentInstanceByName(const QString &name) const noexcept
Definition: circuit.cpp:317
void setNetClassName(NetClass &netclass, const ElementName &newName)
Definition: circuit.cpp:185
The NetClass class.
Definition: netclass.h:52
QScopedPointer< TransactionalDirectory > mDirectory
Definition: circuit.h:147
type_safe::constrained_type< QString, ComponentPrefixConstraint, ComponentPrefixVerifier > ComponentPrefix
Definition: componentprefix.h:77
QMap< Uuid, ComponentInstance * > mComponentInstances
Definition: circuit.h:151
type_safe::constrained_type< QString, CircuitIdentifierConstraint, CircuitIdentifierVerifier > CircuitIdentifier
Definition: circuitidentifier.h:89
void netSignalRemoved(NetSignal &netsignal)
NetClass * getNetClassByUuid(const Uuid &uuid) const noexcept
Definition: circuit.cpp:137
NetSignal * getNetSignalByName(const QString &name) const noexcept
Definition: circuit.cpp:218
void netSignalAdded(NetSignal &netsignal)
~Circuit() noexcept
Definition: circuit.cpp:107
const QMap< Uuid, NetClass * > & getNetClasses() const noexcept
Definition: circuit.h:86
QMap< Uuid, NetSignal * > mNetSignals
Definition: circuit.h:150
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:149
void setNetSignalName(NetSignal &netsignal, const CircuitIdentifier &newName, bool isAutoName)
Definition: circuit.cpp:273
ComponentInstance * getComponentInstanceByUuid(const Uuid &uuid) const noexcept
Definition: circuit.cpp:312
The ComponentInstance class.
Definition: componentinstance.h:64
The SExpression class.
Definition: sexpression.h:57
void save()
Definition: circuit.cpp:381
Circuit & operator=(const Circuit &rhs)=delete
QString generateAutoComponentInstanceName(const library::ComponentPrefix &cmpPrefix) const noexcept
Definition: circuit.cpp:301
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:92