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_CORE_CIRCUIT_H
21#define LIBREPCB_CORE_CIRCUIT_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../../fileio/filepath.h"
27#include "../../library/cmp/componentprefix.h"
28#include "../../types/circuitidentifier.h"
29#include "../../types/elementname.h"
30#include "../../types/fileproofname.h"
31#include "../../types/uuid.h"
32#include "assemblyvariant.h"
33
34#include <QtCore>
35
36#include <memory>
37
38/*******************************************************************************
39 * Namespace / Forward Declarations
40 ******************************************************************************/
41namespace librepcb {
42
43class Component;
44class ComponentInstance;
45class NetClass;
46class NetSignal;
47class Project;
48class TransactionalDirectory;
49
50/*******************************************************************************
51 * Class Circuit
52 ******************************************************************************/
53
70class Circuit final : public QObject {
71 Q_OBJECT
72
73public:
74 // Constructors / Destructor
75 Circuit() = delete;
76 Circuit(const Circuit& other) = delete;
77 explicit Circuit(Project& project);
78 ~Circuit() noexcept;
79
80 // Getters
81 Project& getProject() const noexcept { return mProject; }
82
83 // AssemblyVariant Methods
85 return mAssemblyVariants;
86 }
87 const AssemblyVariantList& getAssemblyVariants() const noexcept {
88 return mAssemblyVariants;
89 }
90 int addAssemblyVariant(std::shared_ptr<AssemblyVariant> av, int index = -1);
91 void removeAssemblyVariant(std::shared_ptr<AssemblyVariant> av);
92 void setAssemblyVariantName(std::shared_ptr<AssemblyVariant> av,
93 const FileProofName& newName);
94
95 // NetClass Methods
96 const QMap<Uuid, NetClass*>& getNetClasses() const noexcept {
97 return mNetClasses;
98 }
99 NetClass* getNetClassByName(const ElementName& name) const noexcept;
100 void addNetClass(NetClass& netclass);
101 void removeNetClass(NetClass& netclass);
102 void setNetClassName(NetClass& netclass, const ElementName& newName);
103
104 // NetSignal Methods
105 QString generateAutoNetSignalName() const noexcept;
106 const QMap<Uuid, NetSignal*>& getNetSignals() const noexcept {
107 return mNetSignals;
108 }
109 NetSignal* getNetSignalByName(const QString& name) const noexcept;
110 NetSignal* getNetSignalWithMostElements() const noexcept;
111 void addNetSignal(NetSignal& netsignal);
112 void removeNetSignal(NetSignal& netsignal);
113 void setNetSignalName(NetSignal& netsignal, const CircuitIdentifier& newName,
114 bool isAutoName);
115
116 // ComponentInstance Methods
118 const ComponentPrefix& cmpPrefix) const noexcept;
119 const QMap<Uuid, ComponentInstance*>& getComponentInstances() const noexcept {
120 return mComponentInstances;
121 }
123 const Uuid& uuid) const noexcept;
125 const QString& name) const noexcept;
129 const CircuitIdentifier& newName);
130
131 // General Methods
132
138 void serialize(SExpression& root) const;
139
140 // Operator Overloadings
141 Circuit& operator=(const Circuit& rhs) = delete;
142 bool operator==(const Circuit& rhs) noexcept { return (this == &rhs); }
143 bool operator!=(const Circuit& rhs) noexcept { return (this != &rhs); }
144
145signals:
146 void assemblyVariantAdded(std::shared_ptr<AssemblyVariant>& av);
147 void assemblyVariantRemoved(std::shared_ptr<AssemblyVariant>& av);
148 void netClassAdded(NetClass& netclass);
149 void netClassRemoved(NetClass& netclass);
150 void netSignalAdded(NetSignal& netsignal);
151 void netSignalRemoved(NetSignal& netsignal);
154
155private:
158 QMap<Uuid, NetClass*> mNetClasses;
159 QMap<Uuid, NetSignal*> mNetSignals;
160 QMap<Uuid, ComponentInstance*> mComponentInstances;
161};
162
163/*******************************************************************************
164 * End of File
165 ******************************************************************************/
166
167} // namespace librepcb
168
169#endif
The Circuit class represents all electrical connections in a project (drawn in the schematics)
Definition: circuit.h:70
const QMap< Uuid, NetClass * > & getNetClasses() const noexcept
Definition: circuit.h:96
NetSignal * getNetSignalWithMostElements() const noexcept
Definition: circuit.cpp:208
bool operator!=(const Circuit &rhs) noexcept
Definition: circuit.h:143
AssemblyVariantList & getAssemblyVariants() noexcept
Definition: circuit.h:84
void addNetClass(NetClass &netclass)
Definition: circuit.cpp:141
NetClass * getNetClassByName(const ElementName &name) const noexcept
Definition: circuit.cpp:132
void addComponentInstance(ComponentInstance &cmp)
Definition: circuit.cpp:295
void setNetClassName(NetClass &netclass, const ElementName &newName)
Definition: circuit.cpp:171
QString generateAutoComponentInstanceName(const ComponentPrefix &cmpPrefix) const noexcept
Definition: circuit.cpp:271
~Circuit() noexcept
Definition: circuit.cpp:48
void componentRemoved(ComponentInstance &cmp)
Circuit(const Circuit &other)=delete
const QMap< Uuid, ComponentInstance * > & getComponentInstances() const noexcept
Definition: circuit.h:119
void netClassAdded(NetClass &netclass)
ComponentInstance * getComponentInstanceByUuid(const Uuid &uuid) const noexcept
Definition: circuit.cpp:282
void removeComponentInstance(ComponentInstance &cmp)
Definition: circuit.cpp:318
bool operator==(const Circuit &rhs) noexcept
Definition: circuit.h:142
Circuit & operator=(const Circuit &rhs)=delete
QMap< Uuid, NetSignal * > mNetSignals
Definition: circuit.h:159
void componentAdded(ComponentInstance &cmp)
QMap< Uuid, ComponentInstance * > mComponentInstances
Definition: circuit.h:160
void setNetSignalName(NetSignal &netsignal, const CircuitIdentifier &newName, bool isAutoName)
Definition: circuit.cpp:250
void netSignalAdded(NetSignal &netsignal)
void removeNetClass(NetClass &netclass)
Definition: circuit.cpp:162
void netClassRemoved(NetClass &netclass)
Project & getProject() const noexcept
Definition: circuit.h:81
const AssemblyVariantList & getAssemblyVariants() const noexcept
Definition: circuit.h:87
Project & mProject
A reference to the Project object (from the ctor)
Definition: circuit.h:156
ComponentInstance * getComponentInstanceByName(const QString &name) const noexcept
Definition: circuit.cpp:287
void setComponentInstanceName(ComponentInstance &cmp, const CircuitIdentifier &newName)
Definition: circuit.cpp:329
void assemblyVariantRemoved(std::shared_ptr< AssemblyVariant > &av)
void assemblyVariantAdded(std::shared_ptr< AssemblyVariant > &av)
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition: circuit.cpp:349
void netSignalRemoved(NetSignal &netsignal)
QMap< Uuid, NetClass * > mNetClasses
Definition: circuit.h:158
AssemblyVariantList mAssemblyVariants
Definition: circuit.h:157
void addNetSignal(NetSignal &netsignal)
Definition: circuit.cpp:220
NetSignal * getNetSignalByName(const QString &name) const noexcept
Definition: circuit.cpp:199
void removeAssemblyVariant(std::shared_ptr< AssemblyVariant > av)
Definition: circuit.cpp:103
QString generateAutoNetSignalName() const noexcept
Definition: circuit.cpp:190
void removeNetSignal(NetSignal &netsignal)
Definition: circuit.cpp:241
const QMap< Uuid, NetSignal * > & getNetSignals() const noexcept
Definition: circuit.h:106
void setAssemblyVariantName(std::shared_ptr< AssemblyVariant > av, const FileProofName &newName)
Definition: circuit.cpp:115
int addAssemblyVariant(std::shared_ptr< AssemblyVariant > av, int index=-1)
Definition: circuit.cpp:78
The ComponentInstance class.
Definition: componentinstance.h:54
The NetClass class.
Definition: netclass.h:46
The NetSignal class.
Definition: netsignal.h:50
The Project class represents a whole (opened) project with all its content.
Definition: project.h:71
The SExpression class.
Definition: sexpression.h:69
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
Definition: occmodel.cpp:77
type_safe::constrained_type< QString, CircuitIdentifierConstraint, CircuitIdentifierVerifier > CircuitIdentifier
Definition: circuitidentifier.h:96
type_safe::constrained_type< QString, ComponentPrefixConstraint, ComponentPrefixVerifier > ComponentPrefix
Definition: componentprefix.h:85
type_safe::constrained_type< QString, FileProofNameConstraint, FileProofNameVerifier > FileProofName
Definition: fileproofname.h:89
type_safe::constrained_type< QString, ElementNameConstraint, ElementNameVerifier > ElementName
Definition: elementname.h:84