LibrePCB Developers Documentation
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_CORE_BI_DEVICE_H
21#define LIBREPCB_CORE_BI_DEVICE_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../../../attribute/attribute.h"
27#include "../../../geometry/stroketext.h"
28#include "../../../types/uuid.h"
29#include "../../../utils/signalslot.h"
30#include "bi_base.h"
31#include "bi_stroketext.h"
32
33#include <QtCore>
34
35/*******************************************************************************
36 * Namespace / Forward Declarations
37 ******************************************************************************/
38namespace librepcb {
39
40class BI_FootprintPad;
41class Board;
42class ComponentInstance;
43class Device;
44class Footprint;
45class Package;
46class PackageModel;
47class Part;
48class Project;
49
50/*******************************************************************************
51 * Class BI_Device
52 ******************************************************************************/
53
57class BI_Device final : public BI_Base {
58 Q_OBJECT
59
60public:
61 // Signals
62 enum class Event {
63 BoardLayersChanged,
64 PositionChanged,
65 RotationChanged,
66 MirroredChanged,
67 StopMaskOffsetsChanged,
68 };
71
72 // Constructors / Destructor
73 BI_Device() = delete;
74 BI_Device(const BI_Device& other) = delete;
75 BI_Device(Board& board, ComponentInstance& compInstance,
76 const Uuid& deviceUuid, const Uuid& footprintUuid,
77 const Point& position, const Angle& rotation, bool mirror,
78 bool locked, bool loadInitialStrokeTexts);
79 ~BI_Device() noexcept;
80
81 // Getters
82 const Uuid& getComponentInstanceUuid() const noexcept;
84 return mCompInstance;
85 }
86 const Device& getLibDevice() const noexcept { return *mLibDevice; }
87 const Package& getLibPackage() const noexcept { return *mLibPackage; }
88 const Footprint& getLibFootprint() const noexcept { return *mLibFootprint; }
89 const PackageModel* getLibModel() const noexcept { return mLibModel; }
90 tl::optional<Uuid> getLibModelUuid() const noexcept;
91 tl::optional<Uuid> getDefaultLibModelUuid() const noexcept;
92 const Point& getPosition() const noexcept { return mPosition; }
93 const Angle& getRotation() const noexcept { return mRotation; }
94 bool getMirrored() const noexcept { return mMirrored; }
95 bool isLocked() const noexcept { return mLocked; }
96 const AttributeList& getAttributes() const noexcept { return mAttributes; }
97 BI_FootprintPad* getPad(const Uuid& padUuid) const noexcept {
98 return mPads.value(padUuid);
99 }
100 const QMap<Uuid, BI_FootprintPad*>& getPads() const noexcept { return mPads; }
101 const QHash<Uuid, tl::optional<Length>>& getHoleStopMasks() const noexcept {
103 }
104 QVector<std::shared_ptr<const Part>> getParts(
105 const tl::optional<Uuid>& assemblyVariant) const noexcept;
106 bool isInAssemblyVariant(const Uuid& assemblyVariant) const noexcept;
107 bool doesPackageRequireAssembly(bool resolveAuto) const noexcept;
108 bool isUsed() const noexcept;
109
110 // Setters
111 void setPosition(const Point& pos) noexcept;
112 void setRotation(const Angle& rot) noexcept;
113 void setMirrored(bool mirror);
114 void setLocked(bool locked) noexcept;
115 void setAttributes(const AttributeList& attributes) noexcept;
116 void setModel(const tl::optional<Uuid>& uuid);
117
118 // StrokeText Methods
119 StrokeTextList getDefaultStrokeTexts() const noexcept;
120 const QMap<Uuid, BI_StrokeText*>& getStrokeTexts() const noexcept {
121 return mStrokeTexts;
122 }
123 void addStrokeText(BI_StrokeText& text);
125
126 // General Methods
127 void addToBoard() override;
128 void removeFromBoard() override;
129
135 void serialize(SExpression& root) const;
136
137 // Operator Overloadings
138 BI_Device& operator=(const BI_Device& rhs) = delete;
139
140signals:
142
145
146private:
147 bool checkAttributesValidity() const noexcept;
148 void updateHoleStopMaskOffsets() noexcept;
149 const QStringList& getLocaleOrder() const noexcept;
150
151 // General
157
158 // Attributes
164
167 QHash<Uuid, tl::optional<Length>> mHoleStopMaskOffsets;
168};
169
170/*******************************************************************************
171 * End of File
172 ******************************************************************************/
173
174} // namespace librepcb
175
176#endif
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
The Board Item Base (BI_Base) class.
Definition: bi_base.h:45
The BI_Device class.
Definition: bi_device.h:57
bool mLocked
Definition: bi_device.h:162
bool getMirrored() const noexcept
Definition: bi_device.h:94
void removeStrokeText(BI_StrokeText &text)
Definition: bi_device.cpp:280
const PackageModel * mLibModel
nullptr if no model available/selected
Definition: bi_device.h:156
const Angle & getRotation() const noexcept
Definition: bi_device.h:93
ComponentInstance & getComponentInstance() const noexcept
Definition: bi_device.h:83
const Package * mLibPackage
Definition: bi_device.h:154
BI_Device & operator=(const BI_Device &rhs)=delete
Signal< BI_Device, Event > onEdited
Definition: bi_device.h:69
ComponentInstance & mCompInstance
Definition: bi_device.h:152
void removeFromBoard() override
Definition: bi_device.cpp:364
QHash< Uuid, tl::optional< Length > > mHoleStopMaskOffsets
Definition: bi_device.h:167
const Footprint & getLibFootprint() const noexcept
Definition: bi_device.h:88
const QMap< Uuid, BI_StrokeText * > & getStrokeTexts() const noexcept
Definition: bi_device.h:120
void addStrokeText(BI_StrokeText &text)
Definition: bi_device.cpp:261
void strokeTextAdded(BI_StrokeText &strokeText)
void strokeTextRemoved(BI_StrokeText &strokeText)
void updateHoleStopMaskOffsets() noexcept
Definition: bi_device.cpp:421
bool isUsed() const noexcept
Definition: bi_device.cpp:235
Event
Definition: bi_device.h:62
StrokeTextList getDefaultStrokeTexts() const noexcept
Definition: bi_device.cpp:246
void setModel(const tl::optional< Uuid > &uuid)
Definition: bi_device.cpp:335
const Device * mLibDevice
Definition: bi_device.h:153
QVector< std::shared_ptr< const Part > > getParts(const tl::optional< Uuid > &assemblyVariant) const noexcept
Definition: bi_device.cpp:198
bool checkAttributesValidity() const noexcept
Definition: bi_device.cpp:415
const AttributeList & getAttributes() const noexcept
Definition: bi_device.h:96
bool isInAssemblyVariant(const Uuid &assemblyVariant) const noexcept
Definition: bi_device.cpp:218
const QMap< Uuid, BI_FootprintPad * > & getPads() const noexcept
Definition: bi_device.h:100
~BI_Device() noexcept
Definition: bi_device.cpp:171
bool isLocked() const noexcept
Definition: bi_device.h:95
BI_Device(const BI_Device &other)=delete
const PackageModel * getLibModel() const noexcept
Definition: bi_device.h:89
Angle mRotation
Definition: bi_device.h:160
Slot< BI_Device, Event > OnEditedSlot
Definition: bi_device.h:70
tl::optional< Uuid > getLibModelUuid() const noexcept
Definition: bi_device.cpp:186
void setMirrored(bool mirror)
Definition: bi_device.cpp:311
BI_FootprintPad * getPad(const Uuid &padUuid) const noexcept
Definition: bi_device.h:97
const Package & getLibPackage() const noexcept
Definition: bi_device.h:87
const Point & getPosition() const noexcept
Definition: bi_device.h:92
QMap< Uuid, BI_FootprintPad * > mPads
key: footprint pad UUID
Definition: bi_device.h:165
AttributeList mAttributes
Not used yet, but specified in file format.
Definition: bi_device.h:163
void serialize(SExpression &root) const
Serialize into librepcb::SExpression node.
Definition: bi_device.cpp:384
void setRotation(const Angle &rot) noexcept
Definition: bi_device.cpp:303
void addToBoard() override
Definition: bi_device.cpp:344
void setAttributes(const AttributeList &attributes) noexcept
Definition: bi_device.cpp:328
tl::optional< Uuid > getDefaultLibModelUuid() const noexcept
Definition: bi_device.cpp:190
const Device & getLibDevice() const noexcept
Definition: bi_device.h:86
const QStringList & getLocaleOrder() const noexcept
Definition: bi_device.cpp:441
QMap< Uuid, BI_StrokeText * > mStrokeTexts
Definition: bi_device.h:166
void setLocked(bool locked) noexcept
Definition: bi_device.cpp:322
bool mMirrored
Definition: bi_device.h:161
Point mPosition
Definition: bi_device.h:159
void setPosition(const Point &pos) noexcept
Definition: bi_device.cpp:295
const Footprint * mLibFootprint
Definition: bi_device.h:155
const QHash< Uuid, tl::optional< Length > > & getHoleStopMasks() const noexcept
Definition: bi_device.h:101
bool doesPackageRequireAssembly(bool resolveAuto) const noexcept
Definition: bi_device.cpp:230
const Uuid & getComponentInstanceUuid() const noexcept
Definition: bi_device.cpp:182
The BI_FootprintPad class.
Definition: bi_footprintpad.h:48
The BI_StrokeText class.
Definition: bi_stroketext.h:49
The Board class represents a PCB of a project and is always part of a circuit.
Definition: board.h:73
The ComponentInstance class.
Definition: componentinstance.h:54
The Device class represents an instance of a component (a "real" component)
Definition: device.h:55
The Footprint class represents one footprint variant of a package.
Definition: footprint.h:55
The Length class is used to represent a length (for example 12.75 millimeters)
Definition: length.h:83
The Package class represents a package of a component (including footprint and 3D model)
Definition: package.h:59
Represents a 3D model of a librepcb::Package.
Definition: packagemodel.h:43
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5....
Definition: point.h:79
The SExpression class.
Definition: sexpression.h:69
The Signal class is used to emit signals on non-QObject derived classes.
Definition: signalslot.h:65
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
Definition: occmodel.cpp:77
Definition: uuid.h:183