LibrePCB Developers Documentation
Loading...
Searching...
No Matches
boardeditorstate.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_BOARDEDITORSTATE_H
21#define LIBREPCB_EDITOR_BOARDEDITORSTATE_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../../../graphics/graphicsscene.h"
27#include "boardeditorfsm.h"
29
31
32#include <QtCore>
33
34#include <memory>
35#include <optional>
36
37/*******************************************************************************
38 * Namespace / Forward Declarations
39 ******************************************************************************/
40namespace librepcb {
41
42class Board;
43class Layer;
44class LengthUnit;
45class NetSignal;
46class Point;
47
48namespace editor {
49
50class BoardGraphicsScene;
51class UndoCommand;
52
53/*******************************************************************************
54 * Class BoardEditorState
55 ******************************************************************************/
56
60class BoardEditorState : public QObject {
61 Q_OBJECT
62
63public:
65
66 enum class FindFlag : uint32_t {
67 // Item types
68 Vias = (1 << 0),
69 NetPoints = (1 << 1),
70 NetLines = (1 << 2),
71 Devices = (1 << 3),
72 FootprintPads = (1 << 4),
73 Planes = (1 << 5),
74 Zones = (1 << 6),
75 Polygons = (1 << 7),
76 StrokeTexts = (1 << 8),
77 Holes = (1 << 9),
80
81 // Match behavior
82 AcceptNearMatch = (1 << 10),
83 AcceptNextGridMatch = (1 << 11),
84
85 // Performance options
86 SkipLowerPriorityMatches = (1 << 15),
87
88 // Other options
89 DevicesOfPads = (1 << 20), // Don't return pads, but their device.
90 };
91 Q_DECLARE_FLAGS(FindFlags, FindFlag)
92
93 // Constructors / Destructor
94 BoardEditorState() = delete;
95 BoardEditorState(const BoardEditorState& other) = delete;
96 explicit BoardEditorState(const Context& context,
97 QObject* parent = nullptr) noexcept;
98 virtual ~BoardEditorState() noexcept;
99
100 // General Methods
101 virtual bool entry() noexcept { return true; }
102 virtual bool exit() noexcept { return true; }
103
104 // Event Handlers
105 virtual bool processAddDevice(ComponentInstance& component,
106 const Uuid& device,
107 const Uuid& footprint) noexcept {
108 Q_UNUSED(component);
109 Q_UNUSED(device);
110 Q_UNUSED(footprint);
111 return false;
112 }
113 virtual bool processImportDxf() noexcept { return false; }
114 virtual bool processSelectAll() noexcept { return false; }
115 virtual bool processCut() noexcept { return false; }
116 virtual bool processCopy() noexcept { return false; }
117 virtual bool processPaste() noexcept { return false; }
118 virtual bool processMove(const Point& delta) noexcept {
119 Q_UNUSED(delta);
120 return false;
121 }
122 virtual bool processRotate(const Angle& rotation) noexcept {
123 Q_UNUSED(rotation);
124 return false;
125 }
126 virtual bool processFlip(Qt::Orientation orientation) noexcept {
127 Q_UNUSED(orientation);
128 return false;
129 }
130 virtual bool processSnapToGrid() noexcept { return false; }
131 virtual bool processSetLocked(bool locked) noexcept {
132 Q_UNUSED(locked);
133 return false;
134 }
135 virtual bool processChangeLineWidth(int step) noexcept {
136 Q_UNUSED(step);
137 return false;
138 }
139 virtual bool processResetAllTexts() noexcept { return false; }
140 virtual bool processRemove() noexcept { return false; }
141 virtual bool processEditProperties() noexcept { return false; }
142 virtual bool processAbortCommand() noexcept { return false; }
143 virtual bool processKeyPressed(const GraphicsSceneKeyEvent& e) noexcept {
144 Q_UNUSED(e);
145 return false;
146 }
147 virtual bool processKeyReleased(const GraphicsSceneKeyEvent& e) noexcept {
148 Q_UNUSED(e);
149 return false;
150 }
152 const GraphicsSceneMouseEvent& e) noexcept {
153 Q_UNUSED(e);
154 return false;
155 }
157 const GraphicsSceneMouseEvent& e) noexcept {
158 Q_UNUSED(e);
159 return false;
160 }
162 const GraphicsSceneMouseEvent& e) noexcept {
163 Q_UNUSED(e);
164 return false;
165 }
167 const GraphicsSceneMouseEvent& e) noexcept {
168 Q_UNUSED(e);
169 return false;
170 }
172 const GraphicsSceneMouseEvent& e) noexcept {
173 Q_UNUSED(e);
174 return false;
175 }
176
177 // Operator Overloadings
179
180signals:
188
189protected: // Methods
191 bool getIgnoreLocks() const noexcept;
192 PositiveLength getGridInterval() const noexcept;
193 const LengthUnit& getLengthUnit() const noexcept;
194 QSet<const Layer*> getAllowedGeometryLayers() noexcept;
195 void makeLayerVisible(const QString& layer) noexcept;
196 void abortBlockingToolsInOtherEditors() noexcept;
197 bool execCmd(UndoCommand* cmd);
198 QWidget* parentWidget() noexcept;
199 QList<std::shared_ptr<QGraphicsItem>> findItemsAtPos(
200 const Point& pos, FindFlags flags, const Layer* cuLayer = nullptr,
201 const QSet<const NetSignal*>& netsignals = {},
202 const QVector<std::shared_ptr<QGraphicsItem>>& except = {}) noexcept;
203 template <typename T = QGraphicsItem>
204 std::shared_ptr<T> findItemAtPos(
205 const Point& pos, FindFlags flags, const Layer* cuLayer = nullptr,
206 const QSet<const NetSignal*>& netsignals = {},
207 const QVector<std::shared_ptr<QGraphicsItem>>& except = {}) noexcept {
208 const QList<std::shared_ptr<QGraphicsItem>> items =
210 netsignals, except);
211 std::shared_ptr<T> castedItem =
212 std::dynamic_pointer_cast<T>(items.value(0, nullptr));
213 if ((!items.isEmpty()) && (!castedItem)) {
214 // Probably wrong flags are passed?!?!
215 qCritical() << "Found a board item, but it has the wrong type!";
216 }
217 return castedItem;
218 }
219
220protected: // Data
223};
224
225} // namespace editor
226} // namespace librepcb
227
228Q_DECLARE_OPERATORS_FOR_FLAGS(librepcb::editor::BoardEditorState::FindFlags)
229
230/*******************************************************************************
231 * End of File
232 ******************************************************************************/
233
234#endif
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition angle.h:76
The ComponentInstance class.
Definition componentinstance.h:54
The Layer class provides all supported geometry layers.
Definition layer.h:42
The LengthUnit class represents a length unit (millimeters, inches,...) and provides some useful meth...
Definition lengthunit.h:62
The NetSignal class.
Definition netsignal.h:50
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5....
Definition point.h:78
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition uuid.h:56
Interface for the integration of the board editor FSM.
Definition boardeditorfsmadapter.h:63
The board editor state base class.
Definition boardeditorstate.h:60
Context mContext
Definition boardeditorstate.h:221
void requestLeavingState()
Signal to indicate that the current tool should be exited.
BoardEditorState & operator=(const BoardEditorState &rhs)=delete
virtual bool processEditProperties() noexcept
Definition boardeditorstate.h:141
virtual bool processAbortCommand() noexcept
Definition boardeditorstate.h:142
virtual bool exit() noexcept
Definition boardeditorstate.h:102
const LengthUnit & getLengthUnit() const noexcept
Definition boardeditorstate.cpp:94
virtual bool processGraphicsSceneLeftMouseButtonPressed(const GraphicsSceneMouseEvent &e) noexcept
Definition boardeditorstate.h:156
virtual bool processSnapToGrid() noexcept
Definition boardeditorstate.h:130
virtual bool processSetLocked(bool locked) noexcept
Definition boardeditorstate.h:131
BoardEditorFsmAdapter & mAdapter
Definition boardeditorstate.h:222
virtual bool entry() noexcept
Definition boardeditorstate.h:101
virtual bool processSelectAll() noexcept
Definition boardeditorstate.h:114
virtual bool processMove(const Point &delta) noexcept
Definition boardeditorstate.h:118
QWidget * parentWidget() noexcept
Definition boardeditorstate.cpp:151
virtual bool processRotate(const Angle &rotation) noexcept
Definition boardeditorstate.h:122
virtual bool processGraphicsSceneMouseMoved(const GraphicsSceneMouseEvent &e) noexcept
Definition boardeditorstate.h:151
virtual bool processImportDxf() noexcept
Definition boardeditorstate.h:113
QList< std::shared_ptr< QGraphicsItem > > findItemsAtPos(const Point &pos, FindFlags flags, const Layer *cuLayer=nullptr, const QSet< const NetSignal * > &netsignals={}, const QVector< std::shared_ptr< QGraphicsItem > > &except={}) noexcept
Definition boardeditorstate.cpp:155
std::shared_ptr< T > findItemAtPos(const Point &pos, FindFlags flags, const Layer *cuLayer=nullptr, const QSet< const NetSignal * > &netsignals={}, const QVector< std::shared_ptr< QGraphicsItem > > &except={}) noexcept
Definition boardeditorstate.h:204
BoardGraphicsScene * getActiveBoardScene() noexcept
Definition boardeditorstate.cpp:82
virtual bool processResetAllTexts() noexcept
Definition boardeditorstate.h:139
bool getIgnoreLocks() const noexcept
Definition boardeditorstate.cpp:86
virtual bool processKeyReleased(const GraphicsSceneKeyEvent &e) noexcept
Definition boardeditorstate.h:147
virtual bool processGraphicsSceneLeftMouseButtonDoubleClicked(const GraphicsSceneMouseEvent &e) noexcept
Definition boardeditorstate.h:166
virtual bool processKeyPressed(const GraphicsSceneKeyEvent &e) noexcept
Definition boardeditorstate.h:143
void abortBlockingToolsInOtherEditors() noexcept
Definition boardeditorstate.cpp:143
PositiveLength getGridInterval() const noexcept
Definition boardeditorstate.cpp:90
virtual bool processGraphicsSceneLeftMouseButtonReleased(const GraphicsSceneMouseEvent &e) noexcept
Definition boardeditorstate.h:161
FindFlag
Definition boardeditorstate.h:66
virtual bool processCopy() noexcept
Definition boardeditorstate.h:116
virtual bool processCut() noexcept
Definition boardeditorstate.h:115
virtual bool processFlip(Qt::Orientation orientation) noexcept
Definition boardeditorstate.h:126
virtual bool processPaste() noexcept
Definition boardeditorstate.h:117
virtual bool processGraphicsSceneRightMouseButtonReleased(const GraphicsSceneMouseEvent &e) noexcept
Definition boardeditorstate.h:171
QSet< const Layer * > getAllowedGeometryLayers() noexcept
Definition boardeditorstate.cpp:98
bool execCmd(UndoCommand *cmd)
Definition boardeditorstate.cpp:147
virtual bool processRemove() noexcept
Definition boardeditorstate.h:140
virtual bool processChangeLineWidth(int step) noexcept
Definition boardeditorstate.h:135
virtual bool processAddDevice(ComponentInstance &component, const Uuid &device, const Uuid &footprint) noexcept
Definition boardeditorstate.h:105
void makeLayerVisible(const QString &layer) noexcept
Definition boardeditorstate.cpp:135
The BoardGraphicsScene class.
Definition boardgraphicsscene.h:77
The UndoCommand class represents a command which you can undo/redo.
Definition undocommand.h:46
Definition occmodel.cpp:77
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition length.h:810
Definition uuid.h:186
FSM Context.
Definition boardeditorfsm.h:88
Definition graphicsscene.h:52
Definition graphicsscene.h:45