LibrePCB Developers Documentation
Loading...
Searching...
No Matches
schematiceditorstate.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_SCHEMATICEDITORSTATE_H
21#define LIBREPCB_EDITOR_SCHEMATICEDITORSTATE_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../../../graphics/graphicsscene.h"
27#include "schematiceditorfsm.h"
29
31
32#include <QtCore>
33
34#include <memory>
35
36/*******************************************************************************
37 * Namespace / Forward Declarations
38 ******************************************************************************/
39namespace librepcb {
40
41class Layer;
42class LengthUnit;
43class Point;
44class Schematic;
45
46namespace editor {
47
48class SchematicGraphicsScene;
49class UndoCommand;
50
51/*******************************************************************************
52 * Class SchematicEditorState
53 ******************************************************************************/
54
58class SchematicEditorState : public QObject {
59 Q_OBJECT
60
61public:
63
64 enum class FindFlag {
65 // Item types
66 NetPoints = (1 << 0),
67 NetLines = (1 << 1),
68 NetLabels = (1 << 2),
69 Symbols = (1 << 3),
70 SymbolPins = (1 << 4),
71 SymbolPinsWithComponentSignal = (1 << 5), // Subset of SymbolPins.
72 Polygons = (1 << 6),
73 Texts = (1 << 7),
75 Texts,
76
77 // Match behavior
78 AcceptNearMatch = (1 << 10),
79 AcceptNearestWithinGrid = (1 << 11),
80
81 // Performance options
82 SkipLowerPriorityMatches = (1 << 15),
83 };
84 Q_DECLARE_FLAGS(FindFlags, FindFlag)
85
86 // Constructors / Destructor
89 explicit SchematicEditorState(const Context& context,
90 QObject* parent = nullptr) noexcept;
91 virtual ~SchematicEditorState() noexcept;
92
93 // General Methods
94 virtual bool entry() noexcept { return true; }
95 virtual bool exit() noexcept { return true; }
96
97 // Event Handlers
98 virtual bool processAddComponent(
99 const QString& searchTerm = QString()) noexcept {
100 Q_UNUSED(searchTerm);
101 return false;
102 }
103 virtual bool processAddComponent(const Uuid& cmp,
104 const Uuid& symbVar) noexcept {
105 Q_UNUSED(cmp);
106 Q_UNUSED(symbVar);
107 return false;
108 }
109 virtual bool processSelectAll() noexcept { return false; }
110 virtual bool processCut() noexcept { return false; }
111 virtual bool processCopy() noexcept { return false; }
112 virtual bool processPaste() noexcept { return false; }
113 virtual bool processMove(const Point& delta) noexcept {
114 Q_UNUSED(delta);
115 return false;
116 }
117 virtual bool processRotate(const Angle& rotation) noexcept {
118 Q_UNUSED(rotation);
119 return false;
120 }
121 virtual bool processMirror(Qt::Orientation orientation) noexcept {
122 Q_UNUSED(orientation);
123 return false;
124 }
125 virtual bool processSnapToGrid() noexcept { return false; }
126 virtual bool processResetAllTexts() noexcept { return false; }
127 virtual bool processRemove() noexcept { return false; }
128 virtual bool processEditProperties() noexcept { return false; }
129 virtual bool processAbortCommand() noexcept { return false; }
130 virtual bool processKeyPressed(const GraphicsSceneKeyEvent& e) noexcept {
131 Q_UNUSED(e);
132 return false;
133 }
134 virtual bool processKeyReleased(const GraphicsSceneKeyEvent& e) noexcept {
135 Q_UNUSED(e);
136 return false;
137 }
139 const GraphicsSceneMouseEvent& e) noexcept {
140 Q_UNUSED(e);
141 return false;
142 }
144 const GraphicsSceneMouseEvent& e) noexcept {
145 Q_UNUSED(e);
146 return false;
147 }
149 const GraphicsSceneMouseEvent& e) noexcept {
150 Q_UNUSED(e);
151 return false;
152 }
154 const GraphicsSceneMouseEvent& e) noexcept {
155 Q_UNUSED(e);
156 return false;
157 }
159 const GraphicsSceneMouseEvent& e) noexcept {
160 Q_UNUSED(e);
161 return false;
162 }
163
164 // Operator Overloadings
166
167signals:
175
176protected: // Methods
178 PositiveLength getGridInterval() const noexcept;
179 const LengthUnit& getLengthUnit() const noexcept;
180 static const QSet<const Layer*>& getAllowedGeometryLayers() noexcept;
181 void abortBlockingToolsInOtherEditors() noexcept;
182 bool execCmd(UndoCommand* cmd);
183 QWidget* parentWidget() noexcept;
184 QList<std::shared_ptr<QGraphicsItem>> findItemsAtPos(
185 const Point& pos, FindFlags flags,
186 const QVector<std::shared_ptr<QGraphicsItem>>& except = {}) noexcept;
187 template <typename T = QGraphicsItem>
188 std::shared_ptr<T> findItemAtPos(
189 const Point& pos, FindFlags flags,
190 const QVector<std::shared_ptr<QGraphicsItem>>& except = {}) noexcept {
191 const QList<std::shared_ptr<QGraphicsItem>> items =
193 std::shared_ptr<T> castedItem =
194 std::dynamic_pointer_cast<T>(items.value(0, nullptr));
195 if ((!items.isEmpty()) && (!castedItem)) {
196 // Probably wrong flags are passed?!?!
197 qCritical() << "Found a schematic item, but it has the wrong type!";
198 }
199 return castedItem;
200 }
201
202protected: // Data
205};
206
207} // namespace editor
208} // namespace librepcb
209
210Q_DECLARE_OPERATORS_FOR_FLAGS(librepcb::editor::SchematicEditorState::FindFlags)
211
212/*******************************************************************************
213 * End of File
214 ******************************************************************************/
215
216#endif
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition angle.h:76
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 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 schematic editor FSM.
Definition schematiceditorfsmadapter.h:60
The schematic editor state base class.
Definition schematiceditorstate.h:58
Context mContext
Definition schematiceditorstate.h:203
void requestLeavingState()
Signal to indicate that the current tool should be exited.
virtual bool processEditProperties() noexcept
Definition schematiceditorstate.h:128
virtual bool processAbortCommand() noexcept
Definition schematiceditorstate.h:129
virtual bool exit() noexcept
Definition schematiceditorstate.h:95
static const QSet< const Layer * > & getAllowedGeometryLayers() noexcept
Definition schematiceditorstate.cpp:90
const LengthUnit & getLengthUnit() const noexcept
Definition schematiceditorstate.cpp:85
virtual bool processGraphicsSceneLeftMouseButtonPressed(const GraphicsSceneMouseEvent &e) noexcept
Definition schematiceditorstate.h:143
virtual bool processAddComponent(const QString &searchTerm=QString()) noexcept
Definition schematiceditorstate.h:98
virtual bool processSnapToGrid() noexcept
Definition schematiceditorstate.h:125
QList< std::shared_ptr< QGraphicsItem > > findItemsAtPos(const Point &pos, FindFlags flags, const QVector< std::shared_ptr< QGraphicsItem > > &except={}) noexcept
Definition schematiceditorstate.cpp:116
SchematicEditorFsmAdapter & mAdapter
Definition schematiceditorstate.h:204
virtual bool entry() noexcept
Definition schematiceditorstate.h:94
virtual bool processSelectAll() noexcept
Definition schematiceditorstate.h:109
virtual bool processMove(const Point &delta) noexcept
Definition schematiceditorstate.h:113
QWidget * parentWidget() noexcept
Definition schematiceditorstate.cpp:112
virtual bool processRotate(const Angle &rotation) noexcept
Definition schematiceditorstate.h:117
virtual bool processGraphicsSceneMouseMoved(const GraphicsSceneMouseEvent &e) noexcept
Definition schematiceditorstate.h:138
SchematicEditorState & operator=(const SchematicEditorState &rhs)=delete
FindFlag
Definition schematiceditorstate.h:64
virtual bool processResetAllTexts() noexcept
Definition schematiceditorstate.h:126
virtual bool processKeyReleased(const GraphicsSceneKeyEvent &e) noexcept
Definition schematiceditorstate.h:134
virtual bool processGraphicsSceneLeftMouseButtonDoubleClicked(const GraphicsSceneMouseEvent &e) noexcept
Definition schematiceditorstate.h:153
virtual bool processKeyPressed(const GraphicsSceneKeyEvent &e) noexcept
Definition schematiceditorstate.h:130
void abortBlockingToolsInOtherEditors() noexcept
Definition schematiceditorstate.cpp:104
PositiveLength getGridInterval() const noexcept
Definition schematiceditorstate.cpp:81
virtual bool processAddComponent(const Uuid &cmp, const Uuid &symbVar) noexcept
Definition schematiceditorstate.h:103
virtual bool processMirror(Qt::Orientation orientation) noexcept
Definition schematiceditorstate.h:121
SchematicGraphicsScene * getActiveSchematicScene() noexcept
Definition schematiceditorstate.cpp:77
virtual bool processGraphicsSceneLeftMouseButtonReleased(const GraphicsSceneMouseEvent &e) noexcept
Definition schematiceditorstate.h:148
std::shared_ptr< T > findItemAtPos(const Point &pos, FindFlags flags, const QVector< std::shared_ptr< QGraphicsItem > > &except={}) noexcept
Definition schematiceditorstate.h:188
virtual bool processCopy() noexcept
Definition schematiceditorstate.h:111
virtual bool processCut() noexcept
Definition schematiceditorstate.h:110
virtual bool processPaste() noexcept
Definition schematiceditorstate.h:112
virtual bool processGraphicsSceneRightMouseButtonReleased(const GraphicsSceneMouseEvent &e) noexcept
Definition schematiceditorstate.h:158
bool execCmd(UndoCommand *cmd)
Definition schematiceditorstate.cpp:108
virtual bool processRemove() noexcept
Definition schematiceditorstate.h:127
The SchematicGraphicsScene class.
Definition schematicgraphicsscene.h:67
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
Definition graphicsscene.h:52
Definition graphicsscene.h:45
FSM Context.
Definition schematiceditorfsm.h:62