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 "boardeditorfsm.h"
27
29
30#include <QtCore>
31#include <QtWidgets>
32
33#include <memory>
34#include <optional>
35
36/*******************************************************************************
37 * Namespace / Forward Declarations
38 ******************************************************************************/
39namespace librepcb {
40
41class Board;
42class Layer;
43class LengthUnit;
44class NetSignal;
45class Point;
46
47namespace editor {
48
49class BoardGraphicsScene;
50class UndoCommand;
51
52/*******************************************************************************
53 * Class BoardEditorState
54 ******************************************************************************/
55
59class BoardEditorState : public QObject {
60 Q_OBJECT
61
62public:
64
65 enum class FindFlag {
66 // Item types
67 Vias = (1 << 0),
68 NetPoints = (1 << 1),
69 NetLines = (1 << 2),
70 Devices = (1 << 3),
71 FootprintPads = (1 << 4),
72 Planes = (1 << 5),
73 Zones = (1 << 6),
74 Polygons = (1 << 7),
75 StrokeTexts = (1 << 8),
76 Holes = (1 << 9),
79
80 // Match behavior
81 AcceptNearMatch = (1 << 10),
82 AcceptNextGridMatch = (1 << 11),
83
84 // Performance options
85 SkipLowerPriorityMatches = (1 << 15),
86 };
87 Q_DECLARE_FLAGS(FindFlags, FindFlag)
88
89 // Constructors / Destructor
90 BoardEditorState() = delete;
91 BoardEditorState(const BoardEditorState& other) = delete;
92 explicit BoardEditorState(const Context& context,
93 QObject* parent = nullptr) noexcept;
94 virtual ~BoardEditorState() noexcept;
95
96 // General Methods
97 virtual bool entry() noexcept { return true; }
98 virtual bool exit() noexcept { return true; }
99
100 // Event Handlers
101 virtual bool processAddDevice(ComponentInstance& component,
102 const Uuid& device,
103 const Uuid& footprint) noexcept {
104 Q_UNUSED(component);
105 Q_UNUSED(device);
106 Q_UNUSED(footprint);
107 return false;
108 }
109 virtual bool processImportDxf() noexcept { return false; }
110 virtual bool processSelectAll() noexcept { return false; }
111 virtual bool processCut() noexcept { return false; }
112 virtual bool processCopy() noexcept { return false; }
113 virtual bool processPaste() noexcept { return false; }
114 virtual bool processMove(const Point& delta) noexcept {
115 Q_UNUSED(delta);
116 return false;
117 }
118 virtual bool processRotate(const Angle& rotation) noexcept {
119 Q_UNUSED(rotation);
120 return false;
121 }
122 virtual bool processFlip(Qt::Orientation orientation) noexcept {
123 Q_UNUSED(orientation);
124 return false;
125 }
126 virtual bool processSnapToGrid() noexcept { return false; }
127 virtual bool processSetLocked(bool locked) noexcept {
128 Q_UNUSED(locked);
129 return false;
130 }
131 virtual bool processChangeLineWidth(int step) noexcept {
132 Q_UNUSED(step);
133 return false;
134 }
135 virtual bool processResetAllTexts() noexcept { return false; }
136 virtual bool processRemove() noexcept { return false; }
137 virtual bool processEditProperties() noexcept { return false; }
138 virtual bool processAbortCommand() noexcept { return false; }
139 virtual bool processKeyPressed(const QKeyEvent& e) noexcept {
140 Q_UNUSED(e);
141 return false;
142 }
143 virtual bool processKeyReleased(const QKeyEvent& e) noexcept {
144 Q_UNUSED(e);
145 return false;
146 }
148 QGraphicsSceneMouseEvent& e) noexcept {
149 Q_UNUSED(e);
150 return false;
151 }
153 QGraphicsSceneMouseEvent& e) noexcept {
154 Q_UNUSED(e);
155 return false;
156 }
158 QGraphicsSceneMouseEvent& e) noexcept {
159 Q_UNUSED(e);
160 return false;
161 }
163 QGraphicsSceneMouseEvent& e) noexcept {
164 Q_UNUSED(e);
165 return false;
166 }
168 QGraphicsSceneMouseEvent& e) noexcept {
169 Q_UNUSED(e);
170 return false;
171 }
172 virtual bool processSwitchToBoard(int index) noexcept {
173 Q_UNUSED(index);
174 return false; // Do NOT allow switching board by default
175 }
176
177 // Operator Overloadings
179
180signals:
188 void statusBarMessageChanged(const QString& message, int timeoutMs = -1);
189
190protected: // Methods
191 Board* getActiveBoard() noexcept;
193 bool getIgnoreLocks() const noexcept;
194 PositiveLength getGridInterval() const noexcept;
195 const LengthUnit& getLengthUnit() const noexcept;
196 QSet<const Layer*> getAllowedGeometryLayers() noexcept;
197 void makeLayerVisible(const QString& layer) noexcept;
198 void abortBlockingToolsInOtherEditors() noexcept;
199 bool execCmd(UndoCommand* cmd);
200 QWidget* parentWidget() noexcept;
201 QList<std::shared_ptr<QGraphicsItem>> findItemsAtPos(
202 const Point& pos, FindFlags flags, const Layer* cuLayer = nullptr,
203 const QSet<const NetSignal*>& netsignals = {},
204 const QVector<std::shared_ptr<QGraphicsItem>>& except = {}) noexcept;
205 template <typename T = QGraphicsItem>
206 std::shared_ptr<T> findItemAtPos(
207 const Point& pos, FindFlags flags, const Layer* cuLayer = nullptr,
208 const QSet<const NetSignal*>& netsignals = {},
209 const QVector<std::shared_ptr<QGraphicsItem>>& except = {}) noexcept {
210 const QList<std::shared_ptr<QGraphicsItem>> items =
212 netsignals, except);
213 std::shared_ptr<T> castedItem =
214 std::dynamic_pointer_cast<T>(items.value(0, nullptr));
215 if ((!items.isEmpty()) && (!castedItem)) {
216 // Probably wrong flags are passed?!?!
217 qCritical() << "Found a board item, but it has the wrong type!";
218 }
219 return castedItem;
220 }
221
222protected: // 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 Board class represents a PCB of a project and is always part of a circuit.
Definition board.h:73
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:60
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
The board editor state base class.
Definition boardeditorstate.h:59
Context mContext
Definition boardeditorstate.h:223
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:137
virtual bool processAbortCommand() noexcept
Definition boardeditorstate.h:138
virtual bool processGraphicsSceneLeftMouseButtonDoubleClicked(QGraphicsSceneMouseEvent &e) noexcept
Definition boardeditorstate.h:162
virtual bool exit() noexcept
Definition boardeditorstate.h:98
void statusBarMessageChanged(const QString &message, int timeoutMs=-1)
const LengthUnit & getLengthUnit() const noexcept
Definition boardeditorstate.cpp:98
virtual bool processKeyPressed(const QKeyEvent &e) noexcept
Definition boardeditorstate.h:139
virtual bool processSnapToGrid() noexcept
Definition boardeditorstate.h:126
virtual bool processSetLocked(bool locked) noexcept
Definition boardeditorstate.h:127
virtual bool entry() noexcept
Definition boardeditorstate.h:97
virtual bool processSelectAll() noexcept
Definition boardeditorstate.h:110
virtual bool processMove(const Point &delta) noexcept
Definition boardeditorstate.h:114
QWidget * parentWidget() noexcept
Definition boardeditorstate.cpp:164
virtual bool processGraphicsSceneRightMouseButtonReleased(QGraphicsSceneMouseEvent &e) noexcept
Definition boardeditorstate.h:167
virtual bool processGraphicsSceneLeftMouseButtonReleased(QGraphicsSceneMouseEvent &e) noexcept
Definition boardeditorstate.h:157
virtual bool processRotate(const Angle &rotation) noexcept
Definition boardeditorstate.h:118
virtual bool processImportDxf() noexcept
Definition boardeditorstate.h:109
virtual bool processKeyReleased(const QKeyEvent &e) noexcept
Definition boardeditorstate.h:143
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:168
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:206
BoardGraphicsScene * getActiveBoardScene() noexcept
Definition boardeditorstate.cpp:86
FindFlag
Definition boardeditorstate.h:65
virtual bool processResetAllTexts() noexcept
Definition boardeditorstate.h:135
virtual bool processGraphicsSceneMouseMoved(QGraphicsSceneMouseEvent &e) noexcept
Definition boardeditorstate.h:147
bool getIgnoreLocks() const noexcept
Definition boardeditorstate.cpp:90
void abortBlockingToolsInOtherEditors() noexcept
Definition boardeditorstate.cpp:156
virtual bool processGraphicsSceneLeftMouseButtonPressed(QGraphicsSceneMouseEvent &e) noexcept
Definition boardeditorstate.h:152
PositiveLength getGridInterval() const noexcept
Definition boardeditorstate.cpp:94
Board * getActiveBoard() noexcept
Definition boardeditorstate.cpp:82
virtual bool processCopy() noexcept
Definition boardeditorstate.h:112
virtual bool processCut() noexcept
Definition boardeditorstate.h:111
virtual bool processFlip(Qt::Orientation orientation) noexcept
Definition boardeditorstate.h:122
virtual bool processPaste() noexcept
Definition boardeditorstate.h:113
QSet< const Layer * > getAllowedGeometryLayers() noexcept
Definition boardeditorstate.cpp:107
bool execCmd(UndoCommand *cmd)
Definition boardeditorstate.cpp:160
virtual bool processRemove() noexcept
Definition boardeditorstate.h:136
virtual bool processSwitchToBoard(int index) noexcept
Definition boardeditorstate.h:172
virtual bool processChangeLineWidth(int step) noexcept
Definition boardeditorstate.h:131
virtual bool processAddDevice(ComponentInstance &component, const Uuid &device, const Uuid &footprint) noexcept
Definition boardeditorstate.h:101
void makeLayerVisible(const QString &layer) noexcept
Definition boardeditorstate.cpp:148
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:76
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition length.h:810
Definition uuid.h:186
FSM Context.
Definition boardeditorfsm.h:88