LibrePCB Developers Documentation
symboleditorfsm.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_SYMBOLEDITORFSM_H
21#define LIBREPCB_EDITOR_SYMBOLEDITORFSM_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../../editorwidgetbase.h"
27
28#include <QtCore>
29
30#include <memory>
31
32/*******************************************************************************
33 * Namespace / Forward Declarations
34 ******************************************************************************/
35namespace librepcb {
36
37class Symbol;
38
39namespace editor {
40
41class GraphicsScene;
42class GraphicsView;
43class SymbolEditorState;
44class SymbolEditorWidget;
45class SymbolGraphicsItem;
46class UndoStack;
47
48/*******************************************************************************
49 * Class SymbolEditorFsm
50 ******************************************************************************/
51
56class SymbolEditorFsm final : public QObject {
57 Q_OBJECT
58
59private: // Types
60 enum class State {
61 IDLE,
62 SELECT,
63 ADD_PINS,
64 ADD_NAMES,
65 ADD_VALUES,
66 DRAW_LINE,
67 DRAW_ARC,
68 DRAW_RECT,
69 DRAW_POLYGON,
70 DRAW_CIRCLE,
71 DRAW_TEXT,
72 MEASURE,
73 };
74
75public: // Types
76 struct Context {
86 };
87
88public:
89 // Constructors / Destructor
90 SymbolEditorFsm() = delete;
91 SymbolEditorFsm(const SymbolEditorFsm& other) = delete;
92 explicit SymbolEditorFsm(const Context& context) noexcept;
93 virtual ~SymbolEditorFsm() noexcept;
94
95 // Getters
96 EditorWidgetBase::Tool getCurrentTool() const noexcept;
97 const QSet<EditorWidgetBase::Feature>& getAvailableFeatures() const noexcept {
98 return mAvailableFeatures;
99 }
100
101 // General Methods
102 void updateAvailableFeatures() noexcept;
103
104 // Event Handlers
105 bool processKeyPressed(const QKeyEvent& e) noexcept;
106 bool processKeyReleased(const QKeyEvent& e) noexcept;
107 bool processGraphicsSceneMouseMoved(QGraphicsSceneMouseEvent& e) noexcept;
109 QGraphicsSceneMouseEvent& e) noexcept;
111 QGraphicsSceneMouseEvent& e) noexcept;
113 QGraphicsSceneMouseEvent& e) noexcept;
115 QGraphicsSceneMouseEvent& e) noexcept;
116 bool processSelectAll() noexcept;
117 bool processCut() noexcept;
118 bool processCopy() noexcept;
119 bool processPaste() noexcept;
120 bool processMove(Qt::ArrowType direction) noexcept;
121 bool processRotate(const Angle& rotation) noexcept;
122 bool processMirror(Qt::Orientation orientation) noexcept;
123 bool processSnapToGrid() noexcept;
124 bool processRemove() noexcept;
125 bool processEditProperties() noexcept;
126 bool processAbortCommand() noexcept;
127 bool processStartSelecting() noexcept;
128 bool processStartAddingSymbolPins() noexcept;
129 bool processStartAddingNames() noexcept;
130 bool processStartAddingValues() noexcept;
131 bool processStartDrawLines() noexcept;
132 bool processStartDrawArcs() noexcept;
133 bool processStartDrawRects() noexcept;
134 bool processStartDrawPolygons() noexcept;
135 bool processStartDrawCircles() noexcept;
136 bool processStartDrawTexts() noexcept;
137 bool processStartDxfImport() noexcept;
138 bool processStartMeasure() noexcept;
139
140 // Operator Overloadings
141 SymbolEditorState& operator=(const SymbolEditorState& rhs) = delete;
142
143signals:
144 void toolChanged(EditorWidgetBase::Tool newTool);
146 void statusBarMessageChanged(const QString& message, int timeoutMs = -1);
147
148private: // Methods
149 SymbolEditorState* getCurrentState() const noexcept;
150 bool setNextState(State state) noexcept;
151 bool leaveCurrentState() noexcept;
152 bool enterNextState(State state) noexcept;
153 bool switchToPreviousState() noexcept;
154
155private: // Data
160};
161
162/*******************************************************************************
163 * End of File
164 ******************************************************************************/
165
166} // namespace editor
167} // namespace librepcb
168
169#endif
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
The LengthUnit class represents a length unit (millimeters, inches,...) and provides some useful meth...
Definition: lengthunit.h:60
The Symbol class represents the part of a component which is added to schematics.
Definition: symbol.h:55
The EditorWidgetBase class.
Definition: editorwidgetbase.h:62
The GraphicsScene class.
Definition: graphicsscene.h:45
The GraphicsView class.
Definition: graphicsview.h:51
The SymbolEditorFsm class is the finit state machine (FSM) of the symbol editor.
Definition: symboleditorfsm.h:56
bool processGraphicsSceneRightMouseButtonReleased(QGraphicsSceneMouseEvent &e) noexcept
Definition: symboleditorfsm.cpp:186
bool processKeyReleased(const QKeyEvent &e) noexcept
Definition: symboleditorfsm.cpp:141
SymbolEditorFsm(const SymbolEditorFsm &other)=delete
bool processStartAddingNames() noexcept
Definition: symboleditorfsm.cpp:299
bool setNextState(State state) noexcept
Definition: symboleditorfsm.cpp:353
bool processStartAddingValues() noexcept
Definition: symboleditorfsm.cpp:303
bool processKeyPressed(const QKeyEvent &e) noexcept
Definition: symboleditorfsm.cpp:133
bool processGraphicsSceneLeftMouseButtonDoubleClicked(QGraphicsSceneMouseEvent &e) noexcept
Definition: symboleditorfsm.cpp:176
void statusBarMessageChanged(const QString &message, int timeoutMs=-1)
EditorWidgetBase::Tool getCurrentTool() const noexcept
Definition: symboleditorfsm.cpp:82
bool processStartSelecting() noexcept
Definition: symboleditorfsm.cpp:291
bool processStartDrawLines() noexcept
Definition: symboleditorfsm.cpp:307
bool processSelectAll() noexcept
Definition: symboleditorfsm.cpp:203
bool processStartDrawRects() noexcept
Definition: symboleditorfsm.cpp:315
QMap< State, SymbolEditorState * > mStates
Definition: symboleditorfsm.h:156
bool processRemove() noexcept
Definition: symboleditorfsm.cpp:267
QSet< EditorWidgetBase::Feature > mAvailableFeatures
Definition: symboleditorfsm.h:159
bool processCopy() noexcept
Definition: symboleditorfsm.cpp:219
SymbolEditorState * getCurrentState() const noexcept
Definition: symboleditorfsm.cpp:349
bool processEditProperties() noexcept
Definition: symboleditorfsm.cpp:275
State mPreviousState
Definition: symboleditorfsm.h:158
State
Definition: symboleditorfsm.h:60
bool processCut() noexcept
Definition: symboleditorfsm.cpp:211
bool leaveCurrentState() noexcept
Definition: symboleditorfsm.cpp:365
bool switchToPreviousState() noexcept
Definition: symboleditorfsm.cpp:396
bool processStartDrawTexts() noexcept
Definition: symboleditorfsm.cpp:327
virtual ~SymbolEditorFsm() noexcept
Definition: symboleditorfsm.cpp:72
bool processStartDxfImport() noexcept
Definition: symboleditorfsm.cpp:331
bool processAbortCommand() noexcept
Definition: symboleditorfsm.cpp:283
void toolChanged(EditorWidgetBase::Tool newTool)
bool processGraphicsSceneLeftMouseButtonReleased(QGraphicsSceneMouseEvent &e) noexcept
Definition: symboleditorfsm.cpp:167
bool processGraphicsSceneLeftMouseButtonPressed(QGraphicsSceneMouseEvent &e) noexcept
Definition: symboleditorfsm.cpp:158
bool processStartDrawCircles() noexcept
Definition: symboleditorfsm.cpp:323
void updateAvailableFeatures() noexcept
Definition: symboleditorfsm.cpp:118
bool enterNextState(State state) noexcept
Definition: symboleditorfsm.cpp:382
State mCurrentState
Definition: symboleditorfsm.h:157
bool processGraphicsSceneMouseMoved(QGraphicsSceneMouseEvent &e) noexcept
Definition: symboleditorfsm.cpp:149
bool processRotate(const Angle &rotation) noexcept
Definition: symboleditorfsm.cpp:243
const QSet< EditorWidgetBase::Feature > & getAvailableFeatures() const noexcept
Definition: symboleditorfsm.h:97
bool processStartMeasure() noexcept
Definition: symboleditorfsm.cpp:341
bool processMirror(Qt::Orientation orientation) noexcept
Definition: symboleditorfsm.cpp:251
bool processStartDrawArcs() noexcept
Definition: symboleditorfsm.cpp:311
bool processStartAddingSymbolPins() noexcept
Definition: symboleditorfsm.cpp:295
bool processStartDrawPolygons() noexcept
Definition: symboleditorfsm.cpp:319
bool processMove(Qt::ArrowType direction) noexcept
Definition: symboleditorfsm.cpp:235
bool processPaste() noexcept
Definition: symboleditorfsm.cpp:227
bool processSnapToGrid() noexcept
Definition: symboleditorfsm.cpp:259
The SymbolEditorState class is the base class of all symbol editor FSM states.
Definition: symboleditorstate.h:52
The SymbolEditorWidget class.
Definition: symboleditorwidget.h:63
The SymbolGraphicsItem class.
Definition: symbolgraphicsitem.h:56
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
Definition: editorwidgetbase.h:68
Definition: symboleditorfsm.h:76
LengthUnit & lengthUnit
Definition: symboleditorfsm.h:82
Symbol & symbol
Definition: symboleditorfsm.h:83
GraphicsView & graphicsView
Definition: symboleditorfsm.h:81
ToolBarProxy & commandToolBar
Definition: symboleditorfsm.h:85
SymbolEditorWidget & editorWidget
Definition: symboleditorfsm.h:78
GraphicsScene & graphicsScene
Definition: symboleditorfsm.h:80
SymbolGraphicsItem & symbolGraphicsItem
Definition: symboleditorfsm.h:84
EditorWidgetBase::Context & editorContext
Definition: symboleditorfsm.h:77
UndoStack & undoStack
Definition: symboleditorfsm.h:79