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