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 BoardPads = (1 << 5),
74 Planes = (1 << 6),
75 Zones = (1 << 7),
76 Polygons = (1 << 8),
77 StrokeTexts = (1 << 9),
78 Holes = (1 << 10),
81
82 // Match behavior
83 AcceptNearMatch = (1 << 10),
84 AcceptNextGridMatch = (1 << 11),
85
86 // Performance options
87 SkipLowerPriorityMatches = (1 << 15),
88
89 // Other options
90 DevicesOfPads = (1 << 20), // Don't return pads, but their device.
91 };
92 Q_DECLARE_FLAGS(FindFlags, FindFlag)
93
94 // Constructors / Destructor
95 BoardEditorState() = delete;
96 BoardEditorState(const BoardEditorState& other) = delete;
97 explicit BoardEditorState(const Context& context,
98 QObject* parent = nullptr) noexcept;
99 virtual ~BoardEditorState() noexcept;
100
101 // General Methods
102 virtual bool entry() noexcept { return true; }
103 virtual bool exit() noexcept { return true; }
104
105 // Event Handlers
106 virtual bool processAddDevice(ComponentInstance& component,
107 const Uuid& device,
108 const Uuid& footprint) noexcept {
109 Q_UNUSED(component);
110 Q_UNUSED(device);
111 Q_UNUSED(footprint);
112 return false;
113 }
114 virtual bool processImportDxf() noexcept { return false; }
115 virtual bool processSelectAll() noexcept { return false; }
116 virtual bool processCut() noexcept { return false; }
117 virtual bool processCopy() noexcept { return false; }
118 virtual bool processPaste() noexcept { return false; }
119 virtual bool processMove(const Point& delta) noexcept {
120 Q_UNUSED(delta);
121 return false;
122 }
123 virtual bool processRotate(const Angle& rotation) noexcept {
124 Q_UNUSED(rotation);
125 return false;
126 }
127 virtual bool processFlip(Qt::Orientation orientation) noexcept {
128 Q_UNUSED(orientation);
129 return false;
130 }
131 virtual bool processSnapToGrid() noexcept { return false; }
132 virtual bool processSetLocked(bool locked) noexcept {
133 Q_UNUSED(locked);
134 return false;
135 }
136 virtual bool processChangeLineWidth(int step) noexcept {
137 Q_UNUSED(step);
138 return false;
139 }
140 virtual bool processResetAllTexts() noexcept { return false; }
141 virtual bool processRemove() noexcept { return false; }
142 virtual bool processEditProperties() noexcept { return false; }
143 virtual bool processAbortCommand() noexcept { return false; }
144 virtual bool processKeyPressed(const GraphicsSceneKeyEvent& e) noexcept {
145 Q_UNUSED(e);
146 return false;
147 }
148 virtual bool processKeyReleased(const GraphicsSceneKeyEvent& e) noexcept {
149 Q_UNUSED(e);
150 return false;
151 }
153 const GraphicsSceneMouseEvent& e) noexcept {
154 Q_UNUSED(e);
155 return false;
156 }
158 const GraphicsSceneMouseEvent& e) noexcept {
159 Q_UNUSED(e);
160 return false;
161 }
163 const GraphicsSceneMouseEvent& e) noexcept {
164 Q_UNUSED(e);
165 return false;
166 }
168 const GraphicsSceneMouseEvent& e) noexcept {
169 Q_UNUSED(e);
170 return false;
171 }
173 const GraphicsSceneMouseEvent& e) noexcept {
174 Q_UNUSED(e);
175 return false;
176 }
177
178 // Operator Overloadings
180
181signals:
189
190protected: // Methods
192 bool getIgnoreLocks() const noexcept;
193 PositiveLength getGridInterval() const noexcept;
194 const LengthUnit& getLengthUnit() const noexcept;
195 QSet<const Layer*> getAllowedGeometryLayers() noexcept;
196 void makeLayerVisible(const QString& layer) noexcept;
197 void abortBlockingToolsInOtherEditors() noexcept;
198 bool execCmd(UndoCommand* cmd);
199 QWidget* parentWidget() noexcept;
200 QList<std::shared_ptr<QGraphicsItem>> findItemsAtPos(
201 const Point& pos, FindFlags flags, const Layer* cuLayer = nullptr,
202 const QSet<const NetSignal*>& netsignals = {},
203 const QVector<std::shared_ptr<QGraphicsItem>>& except = {}) noexcept;
204 template <typename T = QGraphicsItem>
205 std::shared_ptr<T> findItemAtPos(
206 const Point& pos, FindFlags flags, const Layer* cuLayer = nullptr,
207 const QSet<const NetSignal*>& netsignals = {},
208 const QVector<std::shared_ptr<QGraphicsItem>>& except = {}) noexcept {
209 const QList<std::shared_ptr<QGraphicsItem>> items =
211 netsignals, except);
212 std::shared_ptr<T> castedItem =
213 std::dynamic_pointer_cast<T>(items.value(0, nullptr));
214 if ((!items.isEmpty()) && (!castedItem)) {
215 // Probably wrong flags are passed?!?!
216 qCritical() << "Found a board item, but it has the wrong type!";
217 }
218 return castedItem;
219 }
220
221protected: // Data
224};
225
226} // namespace editor
227} // namespace librepcb
228
229Q_DECLARE_OPERATORS_FOR_FLAGS(librepcb::editor::BoardEditorState::FindFlags)
230
231/*******************************************************************************
232 * End of File
233 ******************************************************************************/
234
235#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:64
The board editor state base class.
Definition boardeditorstate.h:60
Context mContext
Definition boardeditorstate.h:222
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:142
virtual bool processAbortCommand() noexcept
Definition boardeditorstate.h:143
virtual bool exit() noexcept
Definition boardeditorstate.h:103
const LengthUnit & getLengthUnit() const noexcept
Definition boardeditorstate.cpp:94
virtual bool processGraphicsSceneLeftMouseButtonPressed(const GraphicsSceneMouseEvent &e) noexcept
Definition boardeditorstate.h:157
virtual bool processSnapToGrid() noexcept
Definition boardeditorstate.h:131
virtual bool processSetLocked(bool locked) noexcept
Definition boardeditorstate.h:132
BoardEditorFsmAdapter & mAdapter
Definition boardeditorstate.h:223
virtual bool entry() noexcept
Definition boardeditorstate.h:102
virtual bool processSelectAll() noexcept
Definition boardeditorstate.h:115
virtual bool processMove(const Point &delta) noexcept
Definition boardeditorstate.h:119
QWidget * parentWidget() noexcept
Definition boardeditorstate.cpp:151
virtual bool processRotate(const Angle &rotation) noexcept
Definition boardeditorstate.h:123
virtual bool processGraphicsSceneMouseMoved(const GraphicsSceneMouseEvent &e) noexcept
Definition boardeditorstate.h:152
virtual bool processImportDxf() noexcept
Definition boardeditorstate.h:114
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:205
BoardGraphicsScene * getActiveBoardScene() noexcept
Definition boardeditorstate.cpp:82
virtual bool processResetAllTexts() noexcept
Definition boardeditorstate.h:140
bool getIgnoreLocks() const noexcept
Definition boardeditorstate.cpp:86
virtual bool processKeyReleased(const GraphicsSceneKeyEvent &e) noexcept
Definition boardeditorstate.h:148
virtual bool processGraphicsSceneLeftMouseButtonDoubleClicked(const GraphicsSceneMouseEvent &e) noexcept
Definition boardeditorstate.h:167
virtual bool processKeyPressed(const GraphicsSceneKeyEvent &e) noexcept
Definition boardeditorstate.h:144
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:162
FindFlag
Definition boardeditorstate.h:66
virtual bool processCopy() noexcept
Definition boardeditorstate.h:117
virtual bool processCut() noexcept
Definition boardeditorstate.h:116
virtual bool processFlip(Qt::Orientation orientation) noexcept
Definition boardeditorstate.h:127
virtual bool processPaste() noexcept
Definition boardeditorstate.h:118
virtual bool processGraphicsSceneRightMouseButtonReleased(const GraphicsSceneMouseEvent &e) noexcept
Definition boardeditorstate.h:172
QSet< const Layer * > getAllowedGeometryLayers() noexcept
Definition boardeditorstate.cpp:98
bool execCmd(UndoCommand *cmd)
Definition boardeditorstate.cpp:147
virtual bool processRemove() noexcept
Definition boardeditorstate.h:141
virtual bool processChangeLineWidth(int step) noexcept
Definition boardeditorstate.h:136
virtual bool processAddDevice(ComponentInstance &component, const Uuid &device, const Uuid &footprint) noexcept
Definition boardeditorstate.h:106
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:99
Definition graphicsscene.h:52
Definition graphicsscene.h:45