LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bi_device.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_BI_DEVICE_H
21 #define LIBREPCB_PROJECT_BI_DEVICE_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../../erc/if_ercmsgprovider.h"
27 #include "../graphicsitems/bgi_footprint.h"
28 #include "bi_base.h"
29 
33 #include <librepcb/common/uuid.h>
34 
35 #include <QtCore>
36 
37 /*******************************************************************************
38  * Namespace / Forward Declarations
39  ******************************************************************************/
40 namespace librepcb {
41 
42 namespace library {
43 class Device;
44 class Package;
45 class Footprint;
46 } // namespace library
47 
48 namespace project {
49 
50 class Project;
51 class Board;
52 class ComponentInstance;
53 class BI_Footprint;
54 
55 /*******************************************************************************
56  * Class BI_Device
57  ******************************************************************************/
58 
62 class BI_Device final : public BI_Base,
63  public AttributeProvider,
64  public IF_ErcMsgProvider,
65  public SerializableObject {
66  Q_OBJECT
68 
69 public:
70  // Constructors / Destructor
71  BI_Device() = delete;
72  BI_Device(const BI_Device& other) = delete;
73  BI_Device(Board& board, const BI_Device& other);
74  BI_Device(Board& board, const SExpression& node);
75  BI_Device(Board& board, ComponentInstance& compInstance,
76  const Uuid& deviceUuid, const Uuid& footprintUuid,
77  const Point& position, const Angle& rotation, bool mirror);
78  ~BI_Device() noexcept;
79 
80  // Getters
81  const Uuid& getComponentInstanceUuid() const noexcept;
83  return *mCompInstance;
84  }
85  const library::Device& getLibDevice() const noexcept { return *mLibDevice; }
86  const library::Package& getLibPackage() const noexcept {
87  return *mLibPackage;
88  }
89  const library::Footprint& getLibFootprint() const noexcept {
90  return *mLibFootprint;
91  }
92  BI_Footprint& getFootprint() const noexcept { return *mFootprint; }
93  const Angle& getRotation() const noexcept { return mRotation; }
94  bool isSelectable() const noexcept override;
95  bool isUsed() const noexcept;
96 
97  // Setters
98  void setPosition(const Point& pos) noexcept;
99  void setRotation(const Angle& rot) noexcept;
100  void setIsMirrored(bool mirror);
101 
102  // General Methods
103  void addToBoard() override;
104  void removeFromBoard() override;
105 
107  void serialize(SExpression& root) const override;
108 
109  // Inherited from AttributeProvider
111  QString getUserDefinedAttributeValue(const QString& key) const
112  noexcept override;
114  QString getBuiltInAttributeValue(const QString& key) const noexcept override;
116  QVector<const AttributeProvider*> getAttributeProviderParents() const
117  noexcept override;
118 
119  // Inherited from BI_Base
120  Type_t getType() const noexcept override { return BI_Base::Type_t::Device; }
121  const Point& getPosition() const noexcept override { return mPosition; }
122  bool getIsMirrored() const noexcept override { return mIsMirrored; }
123  QPainterPath getGrabAreaScenePx() const noexcept override;
124  void setSelected(bool selected) noexcept override;
125 
126  // Operator Overloadings
127  BI_Device& operator=(const BI_Device& rhs) = delete;
128 
129 signals:
130 
132  void attributesChanged() override;
133 
134  void moved(const Point& newPos);
135  void rotated(const Angle& newRotation);
136  void mirrored(bool newIsMirrored);
137 
138 private:
139  void initDeviceAndPackageAndFootprint(const Uuid& deviceUuid,
140  const Uuid& footprintUuid);
141  void init();
142  bool checkAttributesValidity() const noexcept;
143  void updateErcMessages() noexcept;
144  const QStringList& getLocaleOrder() const noexcept;
145 
146  // General
148  const library::Device* mLibDevice;
149  const library::Package* mLibPackage;
150  const library::Footprint* mLibFootprint;
151  QScopedPointer<BI_Footprint> mFootprint;
152 
153  // Attributes
159 };
160 
161 /*******************************************************************************
162  * End of File
163  ******************************************************************************/
164 
165 } // namespace project
166 } // namespace librepcb
167 
168 #endif // LIBREPCB_PROJECT_BI_DEVICE_H
const library::Footprint & getLibFootprint() const noexcept
Definition: bi_device.h:89
librepcb::project::BI_Device
const library::Package * mLibPackage
Definition: bi_device.h:149
#define DECLARE_ERC_MSG_CLASS_NAME(msgOwnerClassName)
Definition: if_ercmsgprovider.h:44
ComponentInstance & getComponentInstance() const noexcept
Definition: bi_device.h:82
void serialize(SExpression &root) const override
Serialize the object into an existing S-Expression node.
Definition: bi_device.cpp:246
void updateErcMessages() noexcept
Definition: bi_device.cpp:317
void attributesChanged() override
This signal is emited when the value of attributes has changed.
QString getBuiltInAttributeValue(const QString &key) const noexceptoverride
Get the value of a built-in attribute (if available)
Definition: bi_device.cpp:272
BI_Footprint & getFootprint() const noexcept
Definition: bi_device.h:92
bool getIsMirrored() const noexceptoverride
Definition: bi_device.h:122
~BI_Device() noexcept
Definition: bi_device.cpp:178
The Package class represents a package of a component (including footprint and 3D model) ...
Definition: package.h:56
The Device class represents an instance of a component (a "real" component)
Definition: device.h:54
void addToBoard() override
Definition: bi_device.cpp:222
const library::Package & getLibPackage() const noexcept
Definition: bi_device.h:86
Type_t
Definition: bi_base.h:57
const library::Device * mLibDevice
Definition: bi_device.h:148
The IF_ErcMsgProvider class.
Definition: if_ercmsgprovider.h:59
ComponentInstance * mCompInstance
Definition: bi_device.h:147
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
void mirrored(bool newIsMirrored)
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:43
const QStringList & getLocaleOrder() const noexcept
Definition: bi_device.cpp:320
void setPosition(const Point &pos) noexcept
Definition: bi_device.cpp:198
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:78
The BI_Footprint class.
Definition: bi_footprint.h:57
bool isSelectable() const noexceptoverride
Definition: bi_device.cpp:297
bool checkAttributesValidity() const noexcept
Definition: bi_device.cpp:310
const library::Device & getLibDevice() const noexcept
Definition: bi_device.h:85
bool isUsed() const noexcept
Definition: bi_device.cpp:190
Point mPosition
Definition: bi_device.h:154
const library::Footprint * mLibFootprint
Definition: bi_device.h:150
void initDeviceAndPackageAndFootprint(const Uuid &deviceUuid, const Uuid &footprintUuid)
Definition: bi_device.cpp:122
The Board Item Base (BI_Base) class.
Definition: bi_base.h:52
void removeFromBoard() override
Definition: bi_device.cpp:234
const Angle & getRotation() const noexcept
Definition: bi_device.h:93
QVector< const AttributeProvider * > getAttributeProviderParents() const noexceptoverride
Get all parent attribute providers (fallback if attribute not found)
Definition: bi_device.cpp:284
void setSelected(bool selected) noexceptoverride
Definition: bi_device.cpp:301
Type_t getType() const noexceptoverride
Definition: bi_device.h:120
void moved(const Point &newPos)
The BI_Device class.
Definition: bi_device.h:62
QString getUserDefinedAttributeValue(const QString &key) const noexceptoverride
Get the value of a user defined attribute (if available)
Definition: bi_device.cpp:263
void setIsMirrored(bool mirror)
Definition: bi_device.cpp:212
const Uuid & getComponentInstanceUuid() const noexcept
Definition: bi_device.cpp:186
AttributeList mAttributes
not yet used, but already specified in file format
Definition: bi_device.h:158
void init()
Definition: bi_device.cpp:158
The Board class represents a PCB of a project and is always part of a circuit.
Definition: board.h:83
void setRotation(const Angle &rot) noexcept
Definition: bi_device.cpp:205
bool mIsMirrored
Definition: bi_device.h:156
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
QPainterPath getGrabAreaScenePx() const noexceptoverride
Definition: bi_device.cpp:293
The ComponentInstance class.
Definition: componentinstance.h:64
The SExpression class.
Definition: sexpression.h:57
The Footprint class represents one footprint variant of a package.
Definition: footprint.h:61
QScopedPointer< BI_Footprint > mFootprint
Definition: bi_device.h:151
const Point & getPosition() const noexceptoverride
Definition: bi_device.h:121
Angle mRotation
Definition: bi_device.h:155
The AttributeProvider class defines an interface for classes which provides some attributes which can...
Definition: attributeprovider.h:59
void rotated(const Angle &newRotation)