LibrePCB Developers Documentation
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 HoleGraphicsItem;
54class IF_GraphicsLayerProvider;
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),
76 All = Pads | Circles | Polygons | StrokeTexts | Zones | Holes,
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,
88 const StrokeFont& font,
89 const PackagePadList* packagePadList = nullptr,
90 const Component* component = nullptr,
91 const QStringList& localeOrder = {}) noexcept;
92 ~FootprintGraphicsItem() noexcept;
93
94 // Getters
96 std::shared_ptr<FootprintPad> pad) noexcept {
97 return mPadGraphicsItems.value(pad);
98 }
99 std::shared_ptr<CircleGraphicsItem> getGraphicsItem(
100 std::shared_ptr<Circle> circle) noexcept {
101 return mCircleGraphicsItems.value(circle);
102 }
103 std::shared_ptr<PolygonGraphicsItem> getGraphicsItem(
104 std::shared_ptr<Polygon> polygon) noexcept {
105 return mPolygonGraphicsItems.value(polygon);
106 }
107 std::shared_ptr<StrokeTextGraphicsItem> getGraphicsItem(
108 std::shared_ptr<StrokeText> text) noexcept {
109 return mStrokeTextGraphicsItems.value(text);
110 }
111 std::shared_ptr<ZoneGraphicsItem> getGraphicsItem(
112 std::shared_ptr<Zone> zone) noexcept {
113 return mZoneGraphicsItems.value(zone);
114 }
115 std::shared_ptr<HoleGraphicsItem> getGraphicsItem(
116 std::shared_ptr<Hole> hole) noexcept {
117 return mHoleGraphicsItems.value(hole);
118 }
119 QList<std::shared_ptr<FootprintPadGraphicsItem>> getSelectedPads() noexcept;
120 QList<std::shared_ptr<CircleGraphicsItem>> getSelectedCircles() noexcept;
121 QList<std::shared_ptr<PolygonGraphicsItem>> getSelectedPolygons() noexcept;
122 QList<std::shared_ptr<StrokeTextGraphicsItem>>
123 getSelectedStrokeTexts() noexcept;
124 QList<std::shared_ptr<ZoneGraphicsItem>> getSelectedZones() noexcept;
125 QList<std::shared_ptr<HoleGraphicsItem>> getSelectedHoles() noexcept;
126 QList<std::shared_ptr<QGraphicsItem>> findItemsAtPos(
127 const QPainterPath& posAreaSmall, const QPainterPath& posAreaLarge,
128 FindFlags flags) noexcept;
129
130 // Setters
131 void setPosition(const Point& pos) noexcept;
132 void setRotation(const Angle& rot) noexcept;
133
134 // General Methods
135 void updateAllTexts() noexcept;
136 void setSelectionRect(const QRectF rect) noexcept;
137
138 // Operator Overloadings
139 FootprintGraphicsItem& operator=(const FootprintGraphicsItem& rhs) = delete;
140
141private: // Methods
142 void syncPads() noexcept;
143 void syncCircles() noexcept;
144 void syncPolygons() noexcept;
145 void syncStrokeTexts() noexcept;
146 void syncZones() noexcept;
147 void syncHoles() noexcept;
148 void footprintEdited(const Footprint& footprint,
149 Footprint::Event event) noexcept;
150 void substituteText(StrokeTextGraphicsItem& text) noexcept;
151
152private: // Data
153 std::shared_ptr<Footprint> mFootprint;
156 const PackagePadList* mPackagePadList; // Can be nullptr.
157 QPointer<const Component> mComponent; // Can be nullptr.
158 QStringList mLocaleOrder;
159 QMap<std::shared_ptr<FootprintPad>, std::shared_ptr<FootprintPadGraphicsItem>>
161 QMap<std::shared_ptr<Circle>, std::shared_ptr<CircleGraphicsItem>>
163 QMap<std::shared_ptr<Polygon>, std::shared_ptr<PolygonGraphicsItem>>
165 QMap<std::shared_ptr<StrokeText>, std::shared_ptr<StrokeTextGraphicsItem>>
167 QMap<std::shared_ptr<Zone>, std::shared_ptr<ZoneGraphicsItem>>
169 QMap<std::shared_ptr<Hole>, std::shared_ptr<HoleGraphicsItem>>
171
172 // Slots
174};
175
176} // namespace editor
177} // namespace librepcb
178
179Q_DECLARE_OPERATORS_FOR_FLAGS(
180 librepcb::editor::FootprintGraphicsItem::FindFlags)
181
182/*******************************************************************************
183 * End of File
184 ******************************************************************************/
185
186#endif
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
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:55
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:79
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:99
QList< std::shared_ptr< ZoneGraphicsItem > > getSelectedZones() noexcept
Definition: footprintgraphicsitem.cpp:127
QMap< std::shared_ptr< Hole >, std::shared_ptr< HoleGraphicsItem > > mHoleGraphicsItems
Definition: footprintgraphicsitem.h:170
QMap< std::shared_ptr< Polygon >, std::shared_ptr< PolygonGraphicsItem > > mPolygonGraphicsItems
Definition: footprintgraphicsitem.h:164
std::shared_ptr< FootprintPadGraphicsItem > getGraphicsItem(std::shared_ptr< FootprintPad > pad) noexcept
Definition: footprintgraphicsitem.h:95
QMap< std::shared_ptr< FootprintPad >, std::shared_ptr< FootprintPadGraphicsItem > > mPadGraphicsItems
Definition: footprintgraphicsitem.h:160
QPointer< const Component > mComponent
Definition: footprintgraphicsitem.h:157
const PackagePadList * mPackagePadList
Definition: footprintgraphicsitem.h:156
QMap< std::shared_ptr< Zone >, std::shared_ptr< ZoneGraphicsItem > > mZoneGraphicsItems
Definition: footprintgraphicsitem.h:168
void syncZones() noexcept
Definition: footprintgraphicsitem.cpp:425
void footprintEdited(const Footprint &footprint, Footprint::Event event) noexcept
Definition: footprintgraphicsitem.cpp:471
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:448
std::shared_ptr< ZoneGraphicsItem > getGraphicsItem(std::shared_ptr< Zone > zone) noexcept
Definition: footprintgraphicsitem.h:111
void substituteText(StrokeTextGraphicsItem &text) noexcept
Definition: footprintgraphicsitem.cpp:498
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
QList< std::shared_ptr< PolygonGraphicsItem > > getSelectedPolygons() noexcept
Definition: footprintgraphicsitem.cpp:105
~FootprintGraphicsItem() noexcept
Definition: footprintgraphicsitem.cpp:75
void updateAllTexts() noexcept
Definition: footprintgraphicsitem.cpp:287
const IF_GraphicsLayerProvider & mLayerProvider
Definition: footprintgraphicsitem.h:154
std::shared_ptr< StrokeTextGraphicsItem > getGraphicsItem(std::shared_ptr< StrokeText > text) noexcept
Definition: footprintgraphicsitem.h:107
QMap< std::shared_ptr< Circle >, std::shared_ptr< CircleGraphicsItem > > mCircleGraphicsItems
Definition: footprintgraphicsitem.h:162
Footprint::OnEditedSlot mOnEditedSlot
Definition: footprintgraphicsitem.h:173
FindFlag
Definition: footprintgraphicsitem.h:68
QMap< std::shared_ptr< StrokeText >, std::shared_ptr< StrokeTextGraphicsItem > > mStrokeTextGraphicsItems
Definition: footprintgraphicsitem.h:166
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:103
const StrokeFont & mFont
Definition: footprintgraphicsitem.h:155
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:115
std::shared_ptr< Footprint > mFootprint
Definition: footprintgraphicsitem.h:153
void syncStrokeTexts() noexcept
Definition: footprintgraphicsitem.cpp:400
QStringList mLocaleOrder
Definition: footprintgraphicsitem.h:158
void setPosition(const Point &pos) noexcept
Definition: footprintgraphicsitem.cpp:279
The FootprintPadGraphicsItem class.
Definition: footprintpadgraphicsitem.h:50
The HoleGraphicsItem class is the graphical representation of a librepcb::Hole.
Definition: holegraphicsitem.h:48
The IF_GraphicsLayerProvider class defines an interface for classes which provide layers.
Definition: graphicslayer.h:111
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