LibrePCB Developers Documentation
bi_footprint.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_FOOTPRINT_H
21 #define LIBREPCB_PROJECT_BI_FOOTPRINT_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../graphicsitems/bgi_footprint.h"
27 #include "bi_base.h"
28 #include "bi_stroketext.h"
29 
32 
33 #include <QtCore>
34 
35 /*******************************************************************************
36  * Namespace / Forward Declarations
37  ******************************************************************************/
38 namespace librepcb {
39 
40 namespace library {
41 class Footprint;
42 }
43 
44 namespace project {
45 
46 class Board;
47 class BI_Device;
48 class BI_FootprintPad;
49 
50 /*******************************************************************************
51  * Class BI_Footprint
52  ******************************************************************************/
53 
57 class BI_Footprint final : public BI_Base,
58  public SerializableObject,
59  public AttributeProvider {
60  Q_OBJECT
61 
62 public:
63  // Constructors / Destructor
64  BI_Footprint() = delete;
65  BI_Footprint(const BI_Footprint& other) = delete;
66  BI_Footprint(BI_Device& device, const BI_Footprint& other);
67  BI_Footprint(BI_Device& device, const SExpression& node);
68  explicit BI_Footprint(BI_Device& device);
69  ~BI_Footprint() noexcept;
70 
71  // Getters
72  const Uuid& getComponentInstanceUuid() const noexcept;
73  BI_Device& getDeviceInstance() const noexcept { return mDevice; }
74  BI_FootprintPad* getPad(const Uuid& padUuid) const noexcept {
75  return mPads.value(padUuid);
76  }
77  const QMap<Uuid, BI_FootprintPad*>& getPads() const noexcept { return mPads; }
78  const library::Footprint& getLibFootprint() const noexcept;
79  const Angle& getRotation() const noexcept;
80  bool isSelectable() const noexcept override;
81  bool isUsed() const noexcept;
82  QRectF getBoundingRect() const noexcept;
83  BGI_Footprint& getGraphicsItem() noexcept { return *mGraphicsItem; }
84 
85  // StrokeText Methods
86  const QList<BI_StrokeText*>& getStrokeTexts() const noexcept {
87  return mStrokeTexts;
88  }
89  void addStrokeText(BI_StrokeText& text);
90  void removeStrokeText(BI_StrokeText& text);
91 
92  // General Methods
93  void resetStrokeTextsToLibraryFootprint();
94  void addToBoard() override;
95  void removeFromBoard() override;
96 
98  void serialize(SExpression& root) const override;
99 
100  // Helper Methods
101  Point mapToScene(const Point& relativePos) const noexcept;
102 
103  // Inherited from AttributeProvider
105  QVector<const AttributeProvider*> getAttributeProviderParents() const
106  noexcept override;
107 
108  // Inherited from BI_Base
109  Type_t getType() const noexcept override {
110  return BI_Base::Type_t::Footprint;
111  }
112  const Point& getPosition() const noexcept override;
113  bool getIsMirrored() const noexcept override;
114  QPainterPath getGrabAreaScenePx() const noexcept override;
115  void setSelected(bool selected) noexcept override;
116 
117  // Operator Overloadings
118  BI_Footprint& operator=(const BI_Footprint& rhs) = delete;
119 
120 private slots:
121  void deviceInstanceAttributesChanged();
122  void deviceInstanceMoved(const Point& pos);
123  void deviceInstanceRotated(const Angle& rot);
124  void deviceInstanceMirrored(bool mirrored);
125 
126 signals:
128  void attributesChanged() override;
129 
130 private:
131  void init();
132  void updateGraphicsItemTransform() noexcept;
133 
134  // General
136  QScopedPointer<BGI_Footprint> mGraphicsItem;
137  QMap<Uuid, BI_FootprintPad*> mPads;
138  QList<BI_StrokeText*> mStrokeTexts;
139 };
140 
141 /*******************************************************************************
142  * End of File
143  ******************************************************************************/
144 
145 } // namespace project
146 } // namespace librepcb
147 
148 #endif // LIBREPCB_PROJECT_BI_FOOTPRINT_H
QScopedPointer< BGI_Footprint > mGraphicsItem
Definition: bi_footprint.h:136
BI_Device & mDevice
Definition: bi_footprint.h:135
QMap< Uuid, BI_FootprintPad * > mPads
key: footprint pad UUID
Definition: bi_footprint.h:137
BI_FootprintPad * getPad(const Uuid &padUuid) const noexcept
Definition: bi_footprint.h:74
The BI_StrokeText class.
Definition: bi_stroketext.h:56
const QMap< Uuid, BI_FootprintPad * > & getPads() const noexcept
Definition: bi_footprint.h:77
Definition: airwiresbuilder.cpp:32
The BGI_Footprint class.
Definition: bgi_footprint.h:54
Type_t
Definition: bi_base.h:57
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
const QList< BI_StrokeText * > & getStrokeTexts() const noexcept
Definition: bi_footprint.h:86
The SerializableObject class is the base class for all classes which need to be serializable/deserial...
Definition: serializableobject.h:43
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
BGI_Footprint & getGraphicsItem() noexcept
Definition: bi_footprint.h:83
The BI_FootprintPad class.
Definition: bi_footprintpad.h:56
The Board Item Base (BI_Base) class.
Definition: bi_base.h:52
BI_Device & getDeviceInstance() const noexcept
Definition: bi_footprint.h:73
The BI_Device class.
Definition: bi_device.h:62
QList< BI_StrokeText * > mStrokeTexts
Definition: bi_footprint.h:138
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
The SExpression class.
Definition: sexpression.h:57
The Footprint class represents one footprint variant of a package.
Definition: footprint.h:61
Type_t getType() const noexcept override
Definition: bi_footprint.h:109
The AttributeProvider class defines an interface for classes which provides some attributes which can...
Definition: attributeprovider.h:59