LibrePCB Developers Documentation
si_symbol.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_SI_SYMBOL_H
21 #define LIBREPCB_CORE_SI_SYMBOL_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../../../geometry/text.h"
27 #include "../../../types/angle.h"
28 #include "../../../types/point.h"
29 #include "../../../types/uuid.h"
30 #include "../../../utils/signalslot.h"
31 #include "si_base.h"
32 
33 #include <QtCore>
34 
35 /*******************************************************************************
36  * Namespace / Forward Declarations
37  ******************************************************************************/
38 namespace librepcb {
39 
40 class ComponentInstance;
41 class ComponentSymbolVariantItem;
42 class SI_SymbolPin;
43 class SI_Text;
44 class Schematic;
45 class Symbol;
46 
47 /*******************************************************************************
48  * Class SI_Symbol
49  ******************************************************************************/
50 
54 class SI_Symbol final : public SI_Base {
55  Q_OBJECT
56 
57 public:
58  // Signals
59  enum class Event {
63  };
66 
67  // Constructors / Destructor
68  SI_Symbol() = delete;
69  SI_Symbol(const SI_Symbol& other) = delete;
70  SI_Symbol(Schematic& schematic, const Uuid& uuid,
71  ComponentInstance& cmpInstance, const Uuid& symbolItem,
72  const Point& position, const Angle& rotation, bool mirrored,
73  bool loadInitialTexts);
74  ~SI_Symbol() noexcept;
75 
76  // Getters
77  const Uuid& getUuid() const noexcept { return mUuid; }
78  const Point& getPosition() const noexcept { return mPosition; }
79  const Angle& getRotation() const noexcept { return mRotation; }
80  bool getMirrored() const noexcept { return mMirrored; }
81  QString getName() const noexcept;
82  SI_SymbolPin* getPin(const Uuid& pinUuid) const noexcept {
83  return mPins.value(pinUuid);
84  }
85  const QHash<Uuid, SI_SymbolPin*>& getPins() const noexcept { return mPins; }
87  return mComponentInstance;
88  }
89  const Symbol& getLibSymbol() const noexcept { return *mSymbol; }
91  return *mSymbVarItem;
92  }
93 
94  // Setters
95  void setPosition(const Point& newPos) noexcept;
96  void setRotation(const Angle& newRotation) noexcept;
97  void setMirrored(bool newMirrored) noexcept;
98 
99  // Text Methods
100  TextList getDefaultTexts() const noexcept;
101  const QMap<Uuid, SI_Text*>& getTexts() const noexcept { return mTexts; }
102  void addText(SI_Text& text);
103  void removeText(SI_Text& text);
104 
105  // General Methods
106  void addToSchematic() override;
107  void removeFromSchematic() override;
108 
114  void serialize(SExpression& root) const;
115 
116  // Operator Overloadings
117  SI_Symbol& operator=(const SI_Symbol& rhs) = delete;
118 
119 signals:
120  void textAdded(SI_Text& text);
121  void textRemoved(SI_Text& text);
122  void attributesChanged();
123 
124 private:
125  bool checkAttributesValidity() const noexcept;
126 
127  // General
130  const Symbol* mSymbol;
131  QHash<Uuid, SI_SymbolPin*> mPins;
132  QMap<Uuid, SI_Text*> mTexts;
133 
134  // Attributes
138  bool mMirrored;
139 };
140 
141 /*******************************************************************************
142  * End of File
143  ******************************************************************************/
144 
145 } // namespace librepcb
146 
147 #endif
SI_SymbolPin * getPin(const Uuid &pinUuid) const noexcept
Definition: si_symbol.h:82
void removeFromSchematic() override
Definition: si_symbol.cpp:222
const QMap< Uuid, SI_Text * > & getTexts() const noexcept
Definition: si_symbol.h:101
The SI_Text class represents a text label in a schematic.
Definition: si_text.h:48
The Symbol class represents the part of a component which is added to schematics. ...
Definition: symbol.h:55
const Symbol * mSymbol
Definition: si_symbol.h:130
QHash< Uuid, SI_SymbolPin * > mPins
key: symbol pin UUID
Definition: si_symbol.h:131
Definition: occmodel.cpp:76
void textRemoved(SI_Text &text)
const Angle & getRotation() const noexcept
Definition: si_symbol.h:79
The Schematic Item Base (SI_Base) class.
Definition: si_base.h:45
ComponentInstance & getComponentInstance() const noexcept
Definition: si_symbol.h:86
const Symbol & getLibSymbol() const noexcept
Definition: si_symbol.h:89
const Point & getPosition() const noexcept
Definition: si_symbol.h:78
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:76
const QHash< Uuid, SI_SymbolPin * > & getPins() const noexcept
Definition: si_symbol.h:85
const ComponentSymbolVariantItem * mSymbVarItem
Definition: si_symbol.h:129
QMap< Uuid, SI_Text * > mTexts
key: text UUID
Definition: si_symbol.h:132
void setMirrored(bool newMirrored) noexcept
Definition: si_symbol.cpp:143
The ComponentSymbolVariantItem class represents one symbol of a component symbol variant.
Definition: componentsymbolvariantitem.h:54
Angle mRotation
Definition: si_symbol.h:137
The Schematic class represents one schematic page of a project and is always part of a circuit...
Definition: schematic.h:74
bool getMirrored() const noexcept
Definition: si_symbol.h:80
ComponentInstance & mComponentInstance
Definition: si_symbol.h:128
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:78
void addText(SI_Text &text)
Definition: si_symbol.cpp:170
Event
Definition: si_symbol.h:59
~SI_Symbol() noexcept
Definition: si_symbol.cpp:106
Signal< SI_Symbol, Event > onEdited
Definition: si_symbol.h:64
void removeText(SI_Text &text)
Definition: si_symbol.cpp:188
Slot< SI_Symbol, Event > OnEditedSlot
Definition: si_symbol.h:65
SI_Symbol & operator=(const SI_Symbol &rhs)=delete
The SI_SymbolPin class.
Definition: si_symbolpin.h:52
The Signal class is used to emit signals on non-QObject derived classes.
Definition: signalslot.h:65
The ComponentInstance class.
Definition: componentinstance.h:54
void textAdded(SI_Text &text)
void setRotation(const Angle &newRotation) noexcept
Definition: si_symbol.cpp:136
const Uuid & getUuid() const noexcept
Definition: si_symbol.h:77
The SI_Symbol class.
Definition: si_symbol.h:54
bool checkAttributesValidity() const noexcept
Definition: si_symbol.cpp:265
void setPosition(const Point &newPos) noexcept
Definition: si_symbol.cpp:129
QString getName() const noexcept
Definition: si_symbol.cpp:117
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:56
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition: si_symbol.cpp:241
Uuid mUuid
Definition: si_symbol.h:135
Point mPosition
Definition: si_symbol.h:136
void addToSchematic() override
Definition: si_symbol.cpp:203
bool mMirrored
Definition: si_symbol.h:138
The SExpression class.
Definition: sexpression.h:66
const ComponentSymbolVariantItem & getCompSymbVarItem() const noexcept
Definition: si_symbol.h:90
TextList getDefaultTexts() const noexcept
Definition: si_symbol.cpp:154