LibrePCB Developers Documentation
schematiceditorfsm.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_SCHEMATICEDITORFSM_H
21#define LIBREPCB_EDITOR_SCHEMATICEDITORFSM_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include <QtCore>
27#include <QtWidgets>
28
29/*******************************************************************************
30 * Namespace / Forward Declarations
31 ******************************************************************************/
32namespace librepcb {
33
34class Angle;
35class Point;
36class Project;
37class Uuid;
38class Workspace;
39
40namespace editor {
41
42class GraphicsView;
43class ProjectEditor;
44class SchematicEditor;
45class SchematicEditorState;
46class ToolBarProxy;
47class UndoStack;
48
49/*******************************************************************************
50 * Class SchematicEditorFsm
51 ******************************************************************************/
52
56class SchematicEditorFsm final : public QObject {
57 Q_OBJECT
58
59public:
61 enum State {
78 };
79
81 struct Context {
89 };
90
91 // Constructors / Destructor
93 SchematicEditorFsm(const SchematicEditorFsm& other) = delete;
94 explicit SchematicEditorFsm(const Context& context,
95 QObject* parent = nullptr) noexcept;
96 virtual ~SchematicEditorFsm() noexcept;
97
98 // Getters
99 State getCurrentState() const noexcept { return mCurrentState; }
100
101 // Event Handlers
102 bool processSelect() noexcept;
103 bool processAddComponent(const QString& searchTerm = QString()) noexcept;
104 bool processAddComponent(const Uuid& cmp, const Uuid& symbVar) noexcept;
105 bool processAddNetLabel() noexcept;
106 bool processDrawPolygon() noexcept;
107 bool processAddText() noexcept;
108 bool processDrawWire() noexcept;
109 bool processMeasure() noexcept;
110 bool processAbortCommand() noexcept;
111 bool processSelectAll() noexcept;
112 bool processCut() noexcept;
113 bool processCopy() noexcept;
114 bool processPaste() noexcept;
115 bool processMove(const Point& delta) noexcept;
116 bool processRotate(const Angle& rotation) noexcept;
117 bool processMirror(Qt::Orientation orientation) noexcept;
118 bool processResetAllTexts() noexcept;
119 bool processRemove() noexcept;
120 bool processEditProperties() noexcept;
121 bool processKeyPressed(const QKeyEvent& e) noexcept;
122 bool processKeyReleased(const QKeyEvent& e) noexcept;
123 bool processGraphicsSceneMouseMoved(QGraphicsSceneMouseEvent& e) noexcept;
125 QGraphicsSceneMouseEvent& e) noexcept;
127 QGraphicsSceneMouseEvent& e) noexcept;
129 QGraphicsSceneMouseEvent& e) noexcept;
131 QGraphicsSceneMouseEvent& e) noexcept;
132
149 bool processSwitchToSchematicPage(int index) noexcept;
150
151 // Operator Overloadings
152 SchematicEditorFsm& operator=(const SchematicEditorFsm& rhs) = delete;
153
154signals:
155 void stateChanged(State newState);
156 void statusBarMessageChanged(const QString& message, int timeoutMs = -1);
157
158private:
160 bool setNextState(State state) noexcept;
161 bool leaveCurrentState() noexcept;
162 bool enterNextState(State state) noexcept;
163 bool switchToPreviousState() noexcept;
164
165private: // Data
169};
170
171/*******************************************************************************
172 * End of File
173 ******************************************************************************/
174
175} // namespace editor
176} // namespace librepcb
177
178Q_DECLARE_METATYPE(librepcb::editor::SchematicEditorFsm::State)
179
180#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 Project class represents a whole (opened) project with all its content.
Definition: project.h:71
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
The Workspace class represents a workspace with all its data (library, projects, settings,...
Definition: workspace.h:54
The GraphicsView class.
Definition: graphicsview.h:51
The ProjectEditor class.
Definition: projecteditor.h:66
The schematic editor finite state machine (FSM)
Definition: schematiceditorfsm.h:56
bool processResetAllTexts() noexcept
Definition: schematiceditorfsm.cpp:209
State getCurrentState() const noexcept
Definition: schematiceditorfsm.h:99
bool processGraphicsSceneRightMouseButtonReleased(QGraphicsSceneMouseEvent &e) noexcept
Definition: schematiceditorfsm.cpp:294
bool processKeyReleased(const QKeyEvent &e) noexcept
Definition: schematiceditorfsm.cpp:245
bool setNextState(State state) noexcept
Definition: schematiceditorfsm.cpp:327
bool processKeyPressed(const QKeyEvent &e) noexcept
Definition: schematiceditorfsm.cpp:236
bool processGraphicsSceneLeftMouseButtonDoubleClicked(QGraphicsSceneMouseEvent &e) noexcept
Definition: schematiceditorfsm.cpp:284
void statusBarMessageChanged(const QString &message, int timeoutMs=-1)
bool processSelectAll() noexcept
Definition: schematiceditorfsm.cpp:146
bool processDrawPolygon() noexcept
Definition: schematiceditorfsm.cpp:119
bool processRemove() noexcept
Definition: schematiceditorfsm.cpp:218
SchematicEditorFsm(const SchematicEditorFsm &other)=delete
bool processSelect() noexcept
Definition: schematiceditorfsm.cpp:81
bool processCopy() noexcept
Definition: schematiceditorfsm.cpp:164
bool processEditProperties() noexcept
Definition: schematiceditorfsm.cpp:227
State mPreviousState
Definition: schematiceditorfsm.h:168
State
FSM States.
Definition: schematiceditorfsm.h:61
@ ADD_COMPONENT
librepcb::editor::SchematicEditorState_AddComponent
Definition: schematiceditorfsm.h:71
@ MEASURE
librepcb::editor::SchematicEditorState_Measure
Definition: schematiceditorfsm.h:77
@ SELECT
librepcb::editor::SchematicEditorState_Select
Definition: schematiceditorfsm.h:65
@ DRAW_WIRE
librepcb::editor::SchematicEditorState_DrawWire
Definition: schematiceditorfsm.h:67
@ DRAW_POLYGON
librepcb::editor::SchematicEditorState_DrawPolygon
Definition: schematiceditorfsm.h:73
@ ADD_NETLABEL
librepcb::editor::SchematicEditorState_AddNetLabel
Definition: schematiceditorfsm.h:69
@ ADD_TEXT
librepcb::editor::SchematicEditorState_AddText
Definition: schematiceditorfsm.h:75
@ IDLE
no state active
Definition: schematiceditorfsm.h:63
bool processCut() noexcept
Definition: schematiceditorfsm.cpp:155
bool leaveCurrentState() noexcept
Definition: schematiceditorfsm.cpp:337
bool switchToPreviousState() noexcept
Definition: schematiceditorfsm.cpp:371
bool processMeasure() noexcept
Definition: schematiceditorfsm.cpp:131
bool processAbortCommand() noexcept
Definition: schematiceditorfsm.cpp:135
bool processSwitchToSchematicPage(int index) noexcept
Definition: schematiceditorfsm.cpp:310
bool processGraphicsSceneLeftMouseButtonReleased(QGraphicsSceneMouseEvent &e) noexcept
Definition: schematiceditorfsm.cpp:274
bool processGraphicsSceneLeftMouseButtonPressed(QGraphicsSceneMouseEvent &e) noexcept
Definition: schematiceditorfsm.cpp:264
bool processMove(const Point &delta) noexcept
Definition: schematiceditorfsm.cpp:182
bool enterNextState(State state) noexcept
Definition: schematiceditorfsm.cpp:360
State mCurrentState
Definition: schematiceditorfsm.h:167
bool processGraphicsSceneMouseMoved(QGraphicsSceneMouseEvent &e) noexcept
Definition: schematiceditorfsm.cpp:254
bool processRotate(const Angle &rotation) noexcept
Definition: schematiceditorfsm.cpp:191
bool processAddText() noexcept
Definition: schematiceditorfsm.cpp:123
bool processDrawWire() noexcept
Definition: schematiceditorfsm.cpp:127
bool processAddComponent(const QString &searchTerm=QString()) noexcept
Definition: schematiceditorfsm.cpp:85
SchematicEditorState * getCurrentStateObj() const noexcept
Definition: schematiceditorfsm.cpp:323
bool processMirror(Qt::Orientation orientation) noexcept
Definition: schematiceditorfsm.cpp:200
bool processAddNetLabel() noexcept
Definition: schematiceditorfsm.cpp:115
QMap< State, SchematicEditorState * > mStates
Definition: schematiceditorfsm.h:166
bool processPaste() noexcept
Definition: schematiceditorfsm.cpp:173
The SchematicEditor class.
Definition: schematiceditor.h:73
The schematic editor state base class.
Definition: schematiceditorstate.h:57
The ToolBarProxy class allows to map a list of QAction's to one QToolBar.
Definition: toolbarproxy.h:45
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:106
Definition: occmodel.cpp:77
FSM Context.
Definition: schematiceditorfsm.h:81
GraphicsView & editorGraphicsView
Definition: schematiceditorfsm.h:86
ToolBarProxy & commandToolBar
Definition: schematiceditorfsm.h:87
SchematicEditor & editor
Definition: schematiceditorfsm.h:85
Workspace & workspace
Definition: schematiceditorfsm.h:82
UndoStack & undoStack
Definition: schematiceditorfsm.h:88
Project & project
Definition: schematiceditorfsm.h:83
ProjectEditor & projectEditor
Definition: schematiceditorfsm.h:84