LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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_PROJECT_SI_SYMBOL_H
21 #define LIBREPCB_PROJECT_SI_SYMBOL_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../graphicsitems/sgi_symbol.h"
27 #include "si_base.h"
28 
31 
32 #include <QtCore>
33 
34 /*******************************************************************************
35  * Namespace / Forward Declarations
36  ******************************************************************************/
37 namespace librepcb {
38 
39 namespace library {
40 class Symbol;
41 class ComponentSymbolVariantItem;
42 } // namespace library
43 
44 namespace project {
45 
46 class Schematic;
47 class ComponentInstance;
48 class SI_SymbolPin;
49 
50 /*******************************************************************************
51  * Class SI_Symbol
52  ******************************************************************************/
53 
57 class SI_Symbol final : public SI_Base,
58  public SerializableObject,
59  public AttributeProvider {
60  Q_OBJECT
61 
62 public:
63  // Constructors / Destructor
64  SI_Symbol() = delete;
65  SI_Symbol(const SI_Symbol& other) = delete;
66  explicit SI_Symbol(Schematic& schematic, const SExpression& node);
67  explicit SI_Symbol(Schematic& schematic, ComponentInstance& cmpInstance,
68  const Uuid& symbolItem, const Point& position = Point(),
69  const Angle& rotation = Angle(), bool mirrored = false);
70  ~SI_Symbol() noexcept;
71 
72  // Getters
73  const Uuid& getUuid() const noexcept { return mUuid; }
74  const Angle& getRotation() const noexcept { return mRotation; }
75  bool getMirrored() const noexcept { return mMirrored; }
76  QString getName() const noexcept;
77  SI_SymbolPin* getPin(const Uuid& pinUuid) const noexcept {
78  return mPins.value(pinUuid);
79  }
80  const QHash<Uuid, SI_SymbolPin*>& getPins() const noexcept { return mPins; }
82  return *mComponentInstance;
83  }
84  const library::Symbol& getLibSymbol() const noexcept { return *mSymbol; }
86  noexcept {
87  return *mSymbVarItem;
88  }
89 
90  // Setters
91  void setPosition(const Point& newPos) noexcept;
92  void setRotation(const Angle& newRotation) noexcept;
93  void setMirrored(bool newMirrored) noexcept;
94 
95  // General Methods
96  void addToSchematic() override;
97  void removeFromSchematic() override;
98 
100  void serialize(SExpression& root) const override;
101 
102  // Helper Methods
103  Point mapToScene(const Point& relativePos) const noexcept;
104 
105  // Inherited from AttributeProvider
107  QString getBuiltInAttributeValue(const QString& key) const noexcept override;
109  QVector<const AttributeProvider*> getAttributeProviderParents() const
110  noexcept override;
111 
112  // Inherited from SI_Base
113  Type_t getType() const noexcept override { return SI_Base::Type_t::Symbol; }
114  const Point& getPosition() const noexcept override { return mPosition; }
115  QPainterPath getGrabAreaScenePx() const noexcept override;
116  void setSelected(bool selected) noexcept override;
117 
118  // Operator Overloadings
119  SI_Symbol& operator=(const SI_Symbol& rhs) = delete;
120 
121 private slots:
122 
124 
125 signals:
126 
128  void attributesChanged() override;
129 
130 private:
131  void init(const Uuid& symbVarItemUuid);
132  void updateGraphicsItemTransform() noexcept;
133  bool checkAttributesValidity() const noexcept;
134 
135  // General
138  const library::Symbol* mSymbol;
140  QScopedPointer<SGI_Symbol> mGraphicsItem;
141 
142  // Attributes
143  Uuid mUuid;
146  bool mMirrored;
147 };
148 
149 /*******************************************************************************
150  * End of File
151  ******************************************************************************/
152 
153 } // namespace project
154 } // namespace librepcb
155 
156 #endif // LIBREPCB_PROJECT_SI_SYMBOL_H
Point mPosition
Definition: si_symbol.h:144
void setRotation(const Angle &newRotation) noexcept
Definition: si_symbol.cpp:160
SI_SymbolPin * getPin(const Uuid &pinUuid) const noexcept
Definition: si_symbol.h:77
The SI_Symbol class.
Definition: si_symbol.h:57
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: si_symbol.cpp:212
void setMirrored(bool newMirrored) noexcept
Definition: si_symbol.cpp:169
const Angle & getRotation() const noexcept
Definition: si_symbol.h:74
const library::ComponentSymbolVariantItem & getCompSymbVarItem() const noexcept
Definition: si_symbol.h:85
QPainterPath getGrabAreaScenePx() const noexceptoverride
Definition: si_symbol.cpp:258
bool mMirrored
Definition: si_symbol.h:146
void addToSchematic() override
Definition: si_symbol.cpp:182
QString getName() const noexcept
Definition: si_symbol.cpp:139
QString getBuiltInAttributeValue(const QString &key) const noexceptoverride
Get the value of a built-in attribute (if available)
Definition: si_symbol.cpp:241
const Point & getPosition() const noexceptoverride
Definition: si_symbol.h:114
Type_t getType() const noexceptoverride
Definition: si_symbol.h:113
The Schematic class represents one schematic page of a project and is always part of a circuit...
Definition: schematic.h:83
The Schematic Item Base (SI_Base) class.
Definition: si_base.h:52
Uuid mUuid
Definition: si_symbol.h:143
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
void schematicOrComponentAttributesChanged()
Definition: si_symbol.cpp:272
void setPosition(const Point &newPos) noexcept
Definition: si_symbol.cpp:151
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:43
ComponentInstance & getComponentInstance() const noexcept
Definition: si_symbol.h:81
The Symbol class represents the part of a component which is added to schematics. ...
Definition: symbol.h:57
The SI_SymbolPin class.
Definition: si_symbolpin.h:58
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:78
void init(const Uuid &symbVarItemUuid)
Definition: si_symbol.cpp:85
void setSelected(bool selected) noexceptoverride
Definition: si_symbol.cpp:262
The SGI_Symbol class.
Definition: sgi_symbol.h:54
ComponentInstance * mComponentInstance
Definition: si_symbol.h:136
Type_t
Definition: si_base.h:57
void removeFromSchematic() override
Definition: si_symbol.cpp:197
librepcb::project::SI_Symbol
const library::Symbol * mSymbol
Definition: si_symbol.h:138
QVector< const AttributeProvider * > getAttributeProviderParents() const noexceptoverride
Get all parent attribute providers (fallback if attribute not found)
Definition: si_symbol.cpp:249
const Uuid & getUuid() const noexcept
Definition: si_symbol.h:73
const QHash< Uuid, SI_SymbolPin * > & getPins() const noexcept
Definition: si_symbol.h:80
bool getMirrored() const noexcept
Definition: si_symbol.h:75
Point mapToScene(const Point &relativePos) const noexcept
Definition: si_symbol.cpp:227
const library::Symbol & getLibSymbol() const noexcept
Definition: si_symbol.h:84
QScopedPointer< SGI_Symbol > mGraphicsItem
Definition: si_symbol.h:140
const library::ComponentSymbolVariantItem * mSymbVarItem
Definition: si_symbol.h:137
~SI_Symbol() noexcept
Definition: si_symbol.cpp:129
Angle mRotation
Definition: si_symbol.h:145
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
void attributesChanged() override
This signal is emited when the value of attributes has changed.
The ComponentSymbolVariantItem class represents one symbol of a component symbol variant.
Definition: componentsymbolvariantitem.h:58
void updateGraphicsItemTransform() noexcept
Definition: si_symbol.cpp:280
bool checkAttributesValidity() const noexcept
Definition: si_symbol.cpp:287
QHash< Uuid, SI_SymbolPin * > mPins
key: symbol pin UUID
Definition: si_symbol.h:139
The ComponentInstance class.
Definition: componentinstance.h:64
The SExpression class.
Definition: sexpression.h:57
The AttributeProvider class defines an interface for classes which provides some attributes which can...
Definition: attributeprovider.h:59