LibrePCB Developers Documentation
packageeditorstate_select.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_PACKAGEEDITORSTATE_SELECT_H
21#define LIBREPCB_EDITOR_PACKAGEEDITORSTATE_SELECT_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "packageeditorstate.h"
27
29
30#include <QtCore>
31#include <QtWidgets>
32
33#include <memory>
34#include <optional.hpp>
35
36/*******************************************************************************
37 * Namespace / Forward Declarations
38 ******************************************************************************/
39namespace librepcb {
40
41class Angle;
42class Polygon;
43class Zone;
44
45namespace editor {
46
47class CmdDragSelectedFootprintItems;
48class CmdPolygonEdit;
49class CmdZoneEdit;
50class FootprintClipboardData;
51
52/*******************************************************************************
53 * Class PackageEditorState_Select
54 ******************************************************************************/
55
60 Q_OBJECT
61
62 enum class SubState {
63 IDLE,
64 SELECTING,
65 MOVING,
66 PASTING,
67 MOVING_POLYGON_VERTEX,
68 MOVING_ZONE_VERTEX,
69 };
70
71public:
72 // Constructors / Destructor
75 explicit PackageEditorState_Select(Context& context) noexcept;
77
78 // General Methods
79 bool exit() noexcept override;
81 const noexcept override;
82
83 // Event Handlers
85 QGraphicsSceneMouseEvent& e) noexcept override;
87 QGraphicsSceneMouseEvent& e) noexcept override;
89 QGraphicsSceneMouseEvent& e) noexcept override;
91 QGraphicsSceneMouseEvent& e) noexcept override;
93 QGraphicsSceneMouseEvent& e) noexcept override;
94 bool processSelectAll() noexcept override;
95 bool processCut() noexcept override;
96 bool processCopy() noexcept override;
97 bool processPaste() noexcept override;
98 bool processMove(const Point& delta) noexcept override;
99 bool processRotate(const Angle& rotation) noexcept override;
100 bool processMirror(Qt::Orientation orientation) noexcept override;
101 bool processFlip(Qt::Orientation orientation) noexcept override;
102 bool processMoveAlign() noexcept override;
103 bool processSnapToGrid() noexcept override;
104 bool processRemove() noexcept override;
105 bool processEditProperties() noexcept override;
106 bool processGenerateOutline() noexcept override;
107 bool processGenerateCourtyard() noexcept override;
108 bool processImportDxf() noexcept override;
109 bool processAbortCommand() noexcept override;
110
111 // Operator Overloadings
113 delete;
114
115private: // Methods
116 bool openContextMenuAtPos(const Point& pos) noexcept;
117 bool openPropertiesDialogOfItem(std::shared_ptr<QGraphicsItem> item) noexcept;
118 bool openPropertiesDialogOfItemAtPos(const Point& pos) noexcept;
119 bool copySelectedItemsToClipboard() noexcept;
120 bool canPasteGeometry(
121 const std::unique_ptr<FootprintClipboardData>& data) const noexcept;
123 std::unique_ptr<FootprintClipboardData> data) noexcept;
124 bool startPaste(std::unique_ptr<FootprintClipboardData> data,
125 const tl::optional<Point>& fixedPosition);
126 bool rotateSelectedItems(const Angle& angle) noexcept;
127 bool mirrorSelectedItems(Qt::Orientation orientation,
128 bool flipLayers) noexcept;
129 bool moveAlignSelectedItems() noexcept;
130 bool snapSelectedItemsToGrid() noexcept;
131 bool removeSelectedItems() noexcept;
132 bool generateOutline() noexcept;
133 bool generateCourtyard() noexcept;
134 void removePolygonVertices(std::shared_ptr<Polygon> polygon,
135 const QVector<int> vertices) noexcept;
136 void startAddingPolygonVertex(std::shared_ptr<Polygon> polygon, int vertex,
137 const Point& pos) noexcept;
138 void removeZoneVertices(std::shared_ptr<Zone> zone,
139 const QVector<int> vertices) noexcept;
140 void startAddingZoneVertex(std::shared_ptr<Zone> zone, int vertex,
141 const Point& pos) noexcept;
142 void setSelectionRect(const Point& p1, const Point& p2) noexcept;
143 void clearSelectionRect(bool updateItemsSelectionState) noexcept;
144 QList<std::shared_ptr<QGraphicsItem>> findItemsAtPosition(
145 const Point& pos) noexcept;
146 bool findPolygonVerticesAtPosition(const Point& pos) noexcept;
147 bool findZoneVerticesAtPosition(const Point& pos) noexcept;
148 void setState(SubState state) noexcept;
149
150private: // Types / Data
154
156 std::shared_ptr<Polygon> mSelectedPolygon;
161
163 std::shared_ptr<Zone> mSelectedZone;
167 QScopedPointer<CmdZoneEdit> mCmdZoneEdit;
168};
169
170/*******************************************************************************
171 * End of File
172 ******************************************************************************/
173
174} // namespace editor
175} // namespace librepcb
176
177#endif
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
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 Zone class.
Definition: zone.h:43
The CmdDragSelectedFootprintItems class.
Definition: cmddragselectedfootprintitems.h:54
The CmdPolygonEdit class.
Definition: cmdpolygonedit.h:51
The CmdZoneEdit class.
Definition: cmdzoneedit.h:48
The EditorWidgetBase class.
Definition: editorwidgetbase.h:62
The FootprintClipboardData class.
Definition: footprintclipboarddata.h:55
The PackageEditorState_Select class.
Definition: packageeditorstate_select.h:59
bool processGraphicsSceneMouseMoved(QGraphicsSceneMouseEvent &e) noexcept override
Definition: packageeditorstate_select.cpp:143
bool processGenerateCourtyard() noexcept override
Definition: packageeditorstate_select.cpp:606
void setState(SubState state) noexcept
Definition: packageeditorstate_select.cpp:1695
bool moveAlignSelectedItems() noexcept
Definition: packageeditorstate_select.cpp:1270
void clearSelectionRect(bool updateItemsSelectionState) noexcept
Definition: packageeditorstate_select.cpp:1634
bool processEditProperties() noexcept override
Definition: packageeditorstate_select.cpp:563
bool processMoveAlign() noexcept override
Definition: packageeditorstate_select.cpp:528
bool processGraphicsSceneLeftMouseButtonReleased(QGraphicsSceneMouseEvent &e) noexcept override
Definition: packageeditorstate_select.cpp:302
bool mirrorSelectedItems(Qt::Orientation orientation, bool flipLayers) noexcept
Definition: packageeditorstate_select.cpp:1247
bool processGenerateOutline() noexcept override
Definition: packageeditorstate_select.cpp:595
SubState mState
Definition: packageeditorstate_select.h:151
bool copySelectedItemsToClipboard() noexcept
Definition: packageeditorstate_select.cpp:995
bool processRemove() noexcept override
Definition: packageeditorstate_select.cpp:552
bool rotateSelectedItems(const Angle &angle) noexcept
Definition: packageeditorstate_select.cpp:1230
~PackageEditorState_Select() noexcept
Definition: packageeditorstate_select.cpp:86
bool generateCourtyard() noexcept
Definition: packageeditorstate_select.cpp:1408
bool processAbortCommand() noexcept override
Definition: packageeditorstate_select.cpp:700
bool processPaste() noexcept override
Definition: packageeditorstate_select.cpp:431
bool pasteGeometryFromClipboard(std::unique_ptr< FootprintClipboardData > data) noexcept
Definition: packageeditorstate_select.cpp:1088
QScopedPointer< CmdZoneEdit > mCmdZoneEdit
The zone edit command (nullptr if not editing)
Definition: packageeditorstate_select.h:167
void removeZoneVertices(std::shared_ptr< Zone > zone, const QVector< int > vertices) noexcept
Definition: packageeditorstate_select.cpp:1585
bool removeSelectedItems() noexcept
Definition: packageeditorstate_select.cpp:1311
bool canPasteGeometry(const std::unique_ptr< FootprintClipboardData > &data) const noexcept
Definition: packageeditorstate_select.cpp:1061
bool openPropertiesDialogOfItem(std::shared_ptr< QGraphicsItem > item) noexcept
Definition: packageeditorstate_select.cpp:927
bool processRotate(const Angle &rotation) noexcept override
Definition: packageeditorstate_select.cpp:487
std::shared_ptr< Polygon > mSelectedPolygon
The current polygon selected for editing (nullptr if none)
Definition: packageeditorstate_select.h:156
bool processSelectAll() noexcept override
Definition: packageeditorstate_select.cpp:385
bool findZoneVerticesAtPosition(const Point &pos) noexcept
Definition: packageeditorstate_select.cpp:1675
bool processImportDxf() noexcept override
Definition: packageeditorstate_select.cpp:617
bool openContextMenuAtPos(const Point &pos) noexcept
Definition: packageeditorstate_select.cpp:739
QScopedPointer< CmdDragSelectedFootprintItems > mCmdDragSelectedItems
Definition: packageeditorstate_select.h:153
void startAddingPolygonVertex(std::shared_ptr< Polygon > polygon, int vertex, const Point &pos) noexcept
Definition: packageeditorstate_select.cpp:1564
bool openPropertiesDialogOfItemAtPos(const Point &pos) noexcept
Definition: packageeditorstate_select.cpp:984
PackageEditorState_Select(const PackageEditorState_Select &other)=delete
bool findPolygonVerticesAtPosition(const Point &pos) noexcept
Definition: packageeditorstate_select.cpp:1654
bool processCut() noexcept override
Definition: packageeditorstate_select.cpp:405
void startAddingZoneVertex(std::shared_ptr< Zone > zone, int vertex, const Point &pos) noexcept
Definition: packageeditorstate_select.cpp:1606
QVector< int > mSelectedZoneVertices
The zone vertex indices selected for editing (empty if none)
Definition: packageeditorstate_select.h:165
bool exit() noexcept override
Definition: packageeditorstate_select.cpp:94
QVector< int > mSelectedPolygonVertices
The polygon vertex indices selected for editing (empty if none)
Definition: packageeditorstate_select.h:158
QList< std::shared_ptr< QGraphicsItem > > findItemsAtPosition(const Point &pos) noexcept
Definition: packageeditorstate_select.cpp:1643
bool processSnapToGrid() noexcept override
Definition: packageeditorstate_select.cpp:539
bool processGraphicsSceneRightMouseButtonReleased(QGraphicsSceneMouseEvent &e) noexcept override
Definition: packageeditorstate_select.cpp:369
Point mStartPos
Definition: packageeditorstate_select.h:152
void setSelectionRect(const Point &p1, const Point &p2) noexcept
Definition: packageeditorstate_select.cpp:1627
bool processFlip(Qt::Orientation orientation) noexcept override
Definition: packageeditorstate_select.cpp:514
bool processMirror(Qt::Orientation orientation) noexcept override
Definition: packageeditorstate_select.cpp:500
QSet< EditorWidgetBase::Feature > getAvailableFeatures() const noexcept override
Definition: packageeditorstate_select.cpp:104
void removePolygonVertices(std::shared_ptr< Polygon > polygon, const QVector< int > vertices) noexcept
Definition: packageeditorstate_select.cpp:1538
bool startPaste(std::unique_ptr< FootprintClipboardData > data, const tl::optional< Point > &fixedPosition)
Definition: packageeditorstate_select.cpp:1187
bool snapSelectedItemsToGrid() noexcept
Definition: packageeditorstate_select.cpp:1299
bool processGraphicsSceneLeftMouseButtonPressed(QGraphicsSceneMouseEvent &e) noexcept override
Definition: packageeditorstate_select.cpp:204
SubState
Definition: packageeditorstate_select.h:62
bool processMove(const Point &delta) noexcept override
Definition: packageeditorstate_select.cpp:463
QScopedPointer< CmdPolygonEdit > mCmdPolygonEdit
The polygon edit command (nullptr if not editing)
Definition: packageeditorstate_select.h:160
bool processCopy() noexcept override
Definition: packageeditorstate_select.cpp:420
std::shared_ptr< Zone > mSelectedZone
The current zone selected for editing (nullptr if none)
Definition: packageeditorstate_select.h:163
bool generateOutline() noexcept
Definition: packageeditorstate_select.cpp:1320
bool processGraphicsSceneLeftMouseButtonDoubleClicked(QGraphicsSceneMouseEvent &e) noexcept override
Definition: packageeditorstate_select.cpp:354
The PackageEditorState class is the base class of all package editor FSM states.
Definition: packageeditorstate.h:52
Definition: occmodel.cpp:77
Definition: uuid.h:183
Definition: packageeditorfsm.h:90