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 
60 class SI_Symbol final : public SI_Base,
61  public SerializableObject,
62  public AttributeProvider {
63  Q_OBJECT
64 
65 public:
66  // Constructors / Destructor
67  SI_Symbol() = delete;
68  SI_Symbol(const SI_Symbol& other) = delete;
69  explicit SI_Symbol(Schematic& schematic, const SExpression& node);
70  explicit SI_Symbol(Schematic& schematic, ComponentInstance& cmpInstance,
71  const Uuid& symbolItem, const Point& position = Point(),
72  const Angle& rotation = Angle(), bool mirrored = false);
73  ~SI_Symbol() noexcept;
74 
75  // Getters
76  const Uuid& getUuid() const noexcept { return mUuid; }
77  const Angle& getRotation() const noexcept { return mRotation; }
78  bool getMirrored() const noexcept { return mMirrored; }
79  QString getName() const noexcept;
80  SI_SymbolPin* getPin(const Uuid& pinUuid) const noexcept {
81  return mPins.value(pinUuid);
82  }
83  const QHash<Uuid, SI_SymbolPin*>& getPins() const noexcept { return mPins; }
85  return *mComponentInstance;
86  }
87  const library::Symbol& getLibSymbol() const noexcept { return *mSymbol; }
89  noexcept {
90  return *mSymbVarItem;
91  }
92 
93  // Setters
94  void setPosition(const Point& newPos) noexcept;
95  void setRotation(const Angle& newRotation) noexcept;
96  void setMirrored(bool newMirrored) noexcept;
97 
98  // General Methods
99  void addToSchematic() override;
100  void removeFromSchematic() override;
101 
103  void serialize(SExpression& root) const override;
104 
105  // Helper Methods
106  Point mapToScene(const Point& relativePos) const noexcept;
107 
108  // Inherited from AttributeProvider
110  QString getBuiltInAttributeValue(const QString& key) const noexcept override;
112  QVector<const AttributeProvider*> getAttributeProviderParents() const
113  noexcept override;
114 
115  // Inherited from SI_Base
116  Type_t getType() const noexcept override { return SI_Base::Type_t::Symbol; }
117  const Point& getPosition() const noexcept override { return mPosition; }
118  QPainterPath getGrabAreaScenePx() const noexcept override;
119  void setSelected(bool selected) noexcept override;
120 
121  // Operator Overloadings
122  SI_Symbol& operator=(const SI_Symbol& rhs) = delete;
123 
124 private slots:
125 
127 
128 signals:
129 
131  void attributesChanged() override;
132 
133 private:
134  void init(const Uuid& symbVarItemUuid);
135  void updateGraphicsItemTransform() noexcept;
136  bool checkAttributesValidity() const noexcept;
137 
138  // General
141  const library::Symbol* mSymbol;
143  QScopedPointer<SGI_Symbol> mGraphicsItem;
144 
145  // Attributes
146  Uuid mUuid;
149  bool mMirrored;
150 };
151 
152 /*******************************************************************************
153  * End of File
154  ******************************************************************************/
155 
156 } // namespace project
157 } // namespace librepcb
158 
159 #endif // LIBREPCB_PROJECT_SI_SYMBOL_H
Point mPosition
Definition: si_symbol.h:147
void setRotation(const Angle &newRotation) noexcept
Definition: si_symbol.cpp:186
SI_SymbolPin * getPin(const Uuid &pinUuid) const noexcept
Definition: si_symbol.h:80
The SI_Symbol class.
Definition: si_symbol.h:60
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: si_symbol.cpp:238
void setMirrored(bool newMirrored) noexcept
Definition: si_symbol.cpp:195
const Angle & getRotation() const noexcept
Definition: si_symbol.h:77
const library::ComponentSymbolVariantItem & getCompSymbVarItem() const noexcept
Definition: si_symbol.h:88
QPainterPath getGrabAreaScenePx() const noexceptoverride
Definition: si_symbol.cpp:284
bool mMirrored
Definition: si_symbol.h:149
void addToSchematic() override
Definition: si_symbol.cpp:208
QString getName() const noexcept
Definition: si_symbol.cpp:165
QString getBuiltInAttributeValue(const QString &key) const noexceptoverride
Get the value of a built-in attribute (if available)
Definition: si_symbol.cpp:267
const Point & getPosition() const noexceptoverride
Definition: si_symbol.h:117
Type_t getType() const noexceptoverride
Definition: si_symbol.h:116
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:146
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:81
void schematicOrComponentAttributesChanged()
Definition: si_symbol.cpp:298
void setPosition(const Point &newPos) noexcept
Definition: si_symbol.cpp:177
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:46
ComponentInstance & getComponentInstance() const noexcept
Definition: si_symbol.h:84
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:81
void init(const Uuid &symbVarItemUuid)
Definition: si_symbol.cpp:111
void setSelected(bool selected) noexceptoverride
Definition: si_symbol.cpp:288
The SGI_Symbol class.
Definition: sgi_symbol.h:57
ComponentInstance * mComponentInstance
Definition: si_symbol.h:139
Type_t
Definition: si_base.h:57
void removeFromSchematic() override
Definition: si_symbol.cpp:223
librepcb::project::SI_Symbol
const library::Symbol * mSymbol
Definition: si_symbol.h:141
QVector< const AttributeProvider * > getAttributeProviderParents() const noexceptoverride
Get all parent attribute providers (fallback if attribute not found)
Definition: si_symbol.cpp:275
const Uuid & getUuid() const noexcept
Definition: si_symbol.h:76
const QHash< Uuid, SI_SymbolPin * > & getPins() const noexcept
Definition: si_symbol.h:83
bool getMirrored() const noexcept
Definition: si_symbol.h:78
Point mapToScene(const Point &relativePos) const noexcept
Definition: si_symbol.cpp:253
const library::Symbol & getLibSymbol() const noexcept
Definition: si_symbol.h:87
QScopedPointer< SGI_Symbol > mGraphicsItem
Definition: si_symbol.h:143
const library::ComponentSymbolVariantItem * mSymbVarItem
Definition: si_symbol.h:140
~SI_Symbol() noexcept
Definition: si_symbol.cpp:155
Angle mRotation
Definition: si_symbol.h:148
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:61
void updateGraphicsItemTransform() noexcept
Definition: si_symbol.cpp:306
bool checkAttributesValidity() const noexcept
Definition: si_symbol.cpp:313
QHash< Uuid, SI_SymbolPin * > mPins
key: symbol pin UUID
Definition: si_symbol.h:142
The ComponentInstance class.
Definition: componentinstance.h:64
The SExpression class.
Definition: sexpression.h:60
The AttributeProvider class defines an interface for classes which provides some attributes which can...
Definition: attributeprovider.h:62