LibrePCB Developers Documentation
Loading...
Searching...
No Matches
footprintgraphicsitem.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_EDITOR_FOOTPRINTGRAPHICSITEM_H
21#define LIBREPCB_EDITOR_FOOTPRINTGRAPHICSITEM_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
28
29#include <QtCore>
30#include <QtWidgets>
31
32#include <memory>
33
34/*******************************************************************************
35 * Namespace / Forward Declarations
36 ******************************************************************************/
37namespace librepcb {
38
39class Angle;
40class Circle;
41class Component;
42class FootprintPad;
43class Hole;
44class Point;
45class Polygon;
46class StrokeText;
47class Zone;
48
49namespace editor {
50
51class CircleGraphicsItem;
52class FootprintPadGraphicsItem;
53class GraphicsLayerList;
54class HoleGraphicsItem;
55class PolygonGraphicsItem;
56class StrokeTextGraphicsItem;
57class ZoneGraphicsItem;
58
59/*******************************************************************************
60 * Class FootprintGraphicsItem
61 ******************************************************************************/
62
66class FootprintGraphicsItem final : public QGraphicsItemGroup {
67public:
68 enum class FindFlag {
69 // Item types
70 Pads = (1 << 0),
71 Circles = (1 << 1),
72 Polygons = (1 << 2),
73 StrokeTexts = (1 << 3),
74 Zones = (1 << 4),
75 Holes = (1 << 5),
77
78 // Match behavior
79 AcceptNearMatch = (1 << 10),
80 };
81 Q_DECLARE_FLAGS(FindFlags, FindFlag)
82
83 // Constructors / Destructor
86 FootprintGraphicsItem(std::shared_ptr<Footprint> footprint,
87 const GraphicsLayerList& layers, const StrokeFont& font,
88 const PackagePadList* packagePadList = nullptr,
89 const Component* component = nullptr,
90 const QStringList& localeOrder = {}) noexcept;
91 ~FootprintGraphicsItem() noexcept;
92
93 // Getters
95 std::shared_ptr<FootprintPad> pad) noexcept {
96 return mPadGraphicsItems.value(pad);
97 }
98 std::shared_ptr<CircleGraphicsItem> getGraphicsItem(
99 std::shared_ptr<Circle> circle) noexcept {
100 return mCircleGraphicsItems.value(circle);
101 }
102 std::shared_ptr<PolygonGraphicsItem> getGraphicsItem(
103 std::shared_ptr<Polygon> polygon) noexcept {
104 return mPolygonGraphicsItems.value(polygon);
105 }
106 std::shared_ptr<StrokeTextGraphicsItem> getGraphicsItem(
107 std::shared_ptr<StrokeText> text) noexcept {
108 return mStrokeTextGraphicsItems.value(text);
109 }
110 std::shared_ptr<ZoneGraphicsItem> getGraphicsItem(
111 std::shared_ptr<Zone> zone) noexcept {
112 return mZoneGraphicsItems.value(zone);
113 }
114 std::shared_ptr<HoleGraphicsItem> getGraphicsItem(
115 std::shared_ptr<Hole> hole) noexcept {
116 return mHoleGraphicsItems.value(hole);
117 }
118 QList<std::shared_ptr<FootprintPadGraphicsItem>> getSelectedPads() noexcept;
119 QList<std::shared_ptr<CircleGraphicsItem>> getSelectedCircles() noexcept;
120 QList<std::shared_ptr<PolygonGraphicsItem>> getSelectedPolygons() noexcept;
121 QList<std::shared_ptr<StrokeTextGraphicsItem>>
122 getSelectedStrokeTexts() noexcept;
123 QList<std::shared_ptr<ZoneGraphicsItem>> getSelectedZones() noexcept;
124 QList<std::shared_ptr<HoleGraphicsItem>> getSelectedHoles() noexcept;
125 QList<std::shared_ptr<QGraphicsItem>> findItemsAtPos(
126 const QPainterPath& posAreaSmall, const QPainterPath& posAreaLarge,
127 FindFlags flags) noexcept;
128
129 // Setters
130 void setPosition(const Point& pos) noexcept;
131 void setRotation(const Angle& rot) noexcept;
132
133 // General Methods
134 void updateAllTexts() noexcept;
135 void setSelectionRect(const QRectF rect) noexcept;
136
137 // Operator Overloadings
138 FootprintGraphicsItem& operator=(const FootprintGraphicsItem& rhs) = delete;
139
140private: // Methods
141 void syncPads() noexcept;
142 void syncCircles() noexcept;
143 void syncPolygons() noexcept;
144 void syncStrokeTexts() noexcept;
145 void syncZones() noexcept;
146 void syncHoles() noexcept;
147 void footprintEdited(const Footprint& footprint,
148 Footprint::Event event) noexcept;
149 void substituteText(StrokeTextGraphicsItem& text) noexcept;
150
151private: // Data
155 const PackagePadList* mPackagePadList; // Can be nullptr.
156 QPointer<const Component> mComponent; // Can be nullptr.
157 QStringList mLocaleOrder;
158 QMap<std::shared_ptr<FootprintPad>, std::shared_ptr<FootprintPadGraphicsItem>>
160 QMap<std::shared_ptr<Circle>, std::shared_ptr<CircleGraphicsItem>>
162 QMap<std::shared_ptr<Polygon>, std::shared_ptr<PolygonGraphicsItem>>
164 QMap<std::shared_ptr<StrokeText>, std::shared_ptr<StrokeTextGraphicsItem>>
166 QMap<std::shared_ptr<Zone>, std::shared_ptr<ZoneGraphicsItem>>
168 QMap<std::shared_ptr<Hole>, std::shared_ptr<HoleGraphicsItem>>
170
171 // Slots
173};
174
175} // namespace editor
176} // namespace librepcb
177
178Q_DECLARE_OPERATORS_FOR_FLAGS(
179 librepcb::editor::FootprintGraphicsItem::FindFlags)
180
181/*******************************************************************************
182 * End of File
183 ******************************************************************************/
184
185#endif
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition angle.h:76
The Circle class.
Definition circle.h:46
The Component class represents a "generic" device in the library.
Definition component.h:73
The Footprint class represents one footprint variant of a package.
Definition footprint.h:55
The FootprintPad class represents a pad of a footprint.
Definition footprintpad.h:54
The Hole class.
Definition hole.h:45
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5....
Definition point.h:78
The Polygon class.
Definition polygon.h:45
The StrokeFont class.
Definition strokefont.h:56
The StrokeText class.
Definition stroketext.h:51
The Zone class.
Definition zone.h:43
The CircleGraphicsItem class.
Definition circlegraphicsitem.h:48
The FootprintGraphicsItem class.
Definition footprintgraphicsitem.h:66
std::shared_ptr< CircleGraphicsItem > getGraphicsItem(std::shared_ptr< Circle > circle) noexcept
Definition footprintgraphicsitem.h:98
QList< std::shared_ptr< ZoneGraphicsItem > > getSelectedZones() noexcept
Definition footprintgraphicsitem.cpp:127
QMap< std::shared_ptr< Hole >, std::shared_ptr< HoleGraphicsItem > > mHoleGraphicsItems
Definition footprintgraphicsitem.h:169
QMap< std::shared_ptr< Polygon >, std::shared_ptr< PolygonGraphicsItem > > mPolygonGraphicsItems
Definition footprintgraphicsitem.h:163
std::shared_ptr< FootprintPadGraphicsItem > getGraphicsItem(std::shared_ptr< FootprintPad > pad) noexcept
Definition footprintgraphicsitem.h:94
QMap< std::shared_ptr< FootprintPad >, std::shared_ptr< FootprintPadGraphicsItem > > mPadGraphicsItems
Definition footprintgraphicsitem.h:159
QPointer< const Component > mComponent
Definition footprintgraphicsitem.h:156
const PackagePadList * mPackagePadList
Definition footprintgraphicsitem.h:155
QMap< std::shared_ptr< Zone >, std::shared_ptr< ZoneGraphicsItem > > mZoneGraphicsItems
Definition footprintgraphicsitem.h:167
void syncZones() noexcept
Definition footprintgraphicsitem.cpp:424
void footprintEdited(const Footprint &footprint, Footprint::Event event) noexcept
Definition footprintgraphicsitem.cpp:469
void syncCircles() noexcept
Definition footprintgraphicsitem.cpp:352
QList< std::shared_ptr< QGraphicsItem > > findItemsAtPos(const QPainterPath &posAreaSmall, const QPainterPath &posAreaLarge, FindFlags flags) noexcept
Definition footprintgraphicsitem.cpp:148
QList< std::shared_ptr< FootprintPadGraphicsItem > > getSelectedPads() noexcept
Definition footprintgraphicsitem.cpp:83
void syncHoles() noexcept
Definition footprintgraphicsitem.cpp:447
std::shared_ptr< ZoneGraphicsItem > getGraphicsItem(std::shared_ptr< Zone > zone) noexcept
Definition footprintgraphicsitem.h:110
void substituteText(StrokeTextGraphicsItem &text) noexcept
Definition footprintgraphicsitem.cpp:496
QList< std::shared_ptr< CircleGraphicsItem > > getSelectedCircles() noexcept
Definition footprintgraphicsitem.cpp:94
void syncPads() noexcept
Definition footprintgraphicsitem.cpp:329
QList< std::shared_ptr< HoleGraphicsItem > > getSelectedHoles() noexcept
Definition footprintgraphicsitem.cpp:138
const GraphicsLayerList & mLayers
Definition footprintgraphicsitem.h:153
QList< std::shared_ptr< PolygonGraphicsItem > > getSelectedPolygons() noexcept
Definition footprintgraphicsitem.cpp:105
~FootprintGraphicsItem() noexcept
Definition footprintgraphicsitem.cpp:75
void updateAllTexts() noexcept
Definition footprintgraphicsitem.cpp:287
std::shared_ptr< StrokeTextGraphicsItem > getGraphicsItem(std::shared_ptr< StrokeText > text) noexcept
Definition footprintgraphicsitem.h:106
QMap< std::shared_ptr< Circle >, std::shared_ptr< CircleGraphicsItem > > mCircleGraphicsItems
Definition footprintgraphicsitem.h:161
Footprint::OnEditedSlot mOnEditedSlot
Definition footprintgraphicsitem.h:172
FindFlag
Definition footprintgraphicsitem.h:68
QMap< std::shared_ptr< StrokeText >, std::shared_ptr< StrokeTextGraphicsItem > > mStrokeTextGraphicsItems
Definition footprintgraphicsitem.h:165
QList< std::shared_ptr< StrokeTextGraphicsItem > > getSelectedStrokeTexts() noexcept
Definition footprintgraphicsitem.cpp:116
void setSelectionRect(const QRectF rect) noexcept
Definition footprintgraphicsitem.cpp:296
std::shared_ptr< PolygonGraphicsItem > getGraphicsItem(std::shared_ptr< Polygon > polygon) noexcept
Definition footprintgraphicsitem.h:102
const StrokeFont & mFont
Definition footprintgraphicsitem.h:154
void setRotation(const Angle &rot) noexcept
Definition footprintgraphicsitem.cpp:283
void syncPolygons() noexcept
Definition footprintgraphicsitem.cpp:375
std::shared_ptr< HoleGraphicsItem > getGraphicsItem(std::shared_ptr< Hole > hole) noexcept
Definition footprintgraphicsitem.h:114
std::shared_ptr< Footprint > mFootprint
Definition footprintgraphicsitem.h:152
void syncStrokeTexts() noexcept
Definition footprintgraphicsitem.cpp:399
QStringList mLocaleOrder
Definition footprintgraphicsitem.h:157
void setPosition(const Point &pos) noexcept
Definition footprintgraphicsitem.cpp:279
The FootprintPadGraphicsItem class.
Definition footprintpadgraphicsitem.h:50
The GraphicsLayerList class.
Definition graphicslayerlist.h:48
The HoleGraphicsItem class is the graphical representation of a librepcb::Hole.
Definition holegraphicsitem.h:48
The PolygonGraphicsItem class.
Definition polygongraphicsitem.h:48
The StrokeTextGraphicsItem class is the graphical representation of a librepcb::StrokeText.
Definition stroketextgraphicsitem.h:49
The ZoneGraphicsItem class.
Definition zonegraphicsitem.h:48
Definition occmodel.cpp:77
Definition uuid.h:186