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_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  QRectF getBoundingRect() const noexcept;
90 
91  // Setters
92  void setPosition(const Point& newPos) noexcept;
93  void setRotation(const Angle& newRotation) noexcept;
94  void setMirrored(bool newMirrored) noexcept;
95 
96  // General Methods
97  void addToSchematic() override;
98  void removeFromSchematic() override;
99 
101  void serialize(SExpression& root) const override;
102 
103  // Helper Methods
104  Point mapToScene(const Point& relativePos) const noexcept;
105 
106  // Inherited from AttributeProvider
108  QString getBuiltInAttributeValue(const QString& key) const noexcept override;
110  QVector<const AttributeProvider*> getAttributeProviderParents() const
111  noexcept override;
112 
113  // Inherited from SI_Base
114  Type_t getType() const noexcept override { return SI_Base::Type_t::Symbol; }
115  const Point& getPosition() const noexcept override { return mPosition; }
116  QPainterPath getGrabAreaScenePx() const noexcept override;
117  void setSelected(bool selected) noexcept override;
118 
119  // Operator Overloadings
120  SI_Symbol& operator=(const SI_Symbol& rhs) = delete;
121 
122 private slots:
123 
124  void schematicOrComponentAttributesChanged();
125 
126 signals:
127 
129  void attributesChanged() override;
130 
131 private:
132  void init(const Uuid& symbVarItemUuid);
133  void updateGraphicsItemTransform() noexcept;
134  bool checkAttributesValidity() const noexcept;
135 
136  // General
140  QHash<Uuid, SI_SymbolPin*> mPins;
141  QScopedPointer<SGI_Symbol> mGraphicsItem;
142 
143  // Attributes
147  bool mMirrored;
148 };
149 
150 /*******************************************************************************
151  * End of File
152  ******************************************************************************/
153 
154 } // namespace project
155 } // namespace librepcb
156 
157 #endif // LIBREPCB_PROJECT_SI_SYMBOL_H
Point mPosition
Definition: si_symbol.h:145
Type_t getType() const noexcept override
Definition: si_symbol.h:114
SI_SymbolPin * getPin(const Uuid &pinUuid) const noexcept
Definition: si_symbol.h:77
The SI_Symbol class.
Definition: si_symbol.h:57
const Angle & getRotation() const noexcept
Definition: si_symbol.h:74
const library::ComponentSymbolVariantItem & getCompSymbVarItem() const noexcept
Definition: si_symbol.h:85
bool mMirrored
Definition: si_symbol.h:147
Definition: airwiresbuilder.cpp:32
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:144
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
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
ComponentInstance * mComponentInstance
Definition: si_symbol.h:137
Type_t
Definition: si_base.h:57
const library::Symbol * mSymbol
Definition: si_symbol.h:139
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
const library::Symbol & getLibSymbol() const noexcept
Definition: si_symbol.h:84
QScopedPointer< SGI_Symbol > mGraphicsItem
Definition: si_symbol.h:141
const library::ComponentSymbolVariantItem * mSymbVarItem
Definition: si_symbol.h:138
Angle mRotation
Definition: si_symbol.h:146
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
The ComponentSymbolVariantItem class represents one symbol of a component symbol variant.
Definition: componentsymbolvariantitem.h:58
const Point & getPosition() const noexcept override
Definition: si_symbol.h:115
QHash< Uuid, SI_SymbolPin * > mPins
key: symbol pin UUID
Definition: si_symbol.h:140
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