LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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_LIBRARY_EDITOR_SYMBOLEDITORFSM_H
21 #define LIBREPCB_LIBRARY_EDITOR_SYMBOLEDITORFSM_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../../common/editorwidgetbase.h"
27 
28 #include <QtCore>
29 
30 #include <memory>
31 
32 /*******************************************************************************
33  * Namespace / Forward Declarations
34  ******************************************************************************/
35 namespace librepcb {
36 
37 class UndoStack;
38 class GraphicsScene;
39 class GraphicsView;
40 class GridProperties;
41 class IF_GraphicsLayerProvider;
42 
43 namespace library {
44 
45 class Symbol;
46 class SymbolGraphicsItem;
47 
48 namespace editor {
49 
50 class SymbolEditorState;
51 class SymbolEditorWidget;
52 
53 /*******************************************************************************
54  * Class SymbolEditorFsm
55  ******************************************************************************/
56 
64 class SymbolEditorFsm final : public QObject {
65  Q_OBJECT
66 
67 private: // Types
68  enum class State {
69  IDLE,
70  SELECT,
71  ADD_PINS,
72  ADD_NAMES,
73  ADD_VALUES,
74  DRAW_LINE,
75  DRAW_RECT,
78  DRAW_TEXT
79  };
80 
81 public: // Types
82  struct Context {
91  };
92 
93 public:
94  // Constructors / Destructor
95  SymbolEditorFsm() = delete;
96  SymbolEditorFsm(const SymbolEditorFsm& other) = delete;
97  explicit SymbolEditorFsm(const Context& context) noexcept;
98  virtual ~SymbolEditorFsm() noexcept;
99 
100  // Getters
101  EditorWidgetBase::Tool getCurrentTool() const noexcept;
102 
103  // Event Handlers
104  bool processGraphicsSceneMouseMoved(QGraphicsSceneMouseEvent& e) noexcept;
106  QGraphicsSceneMouseEvent& e) noexcept;
108  QGraphicsSceneMouseEvent& e) noexcept;
110  QGraphicsSceneMouseEvent& e) noexcept;
112  QGraphicsSceneMouseEvent& e) noexcept;
113  bool processRotateCw() noexcept;
114  bool processRotateCcw() noexcept;
115  bool processRemove() noexcept;
116  bool processAbortCommand() noexcept;
117  bool processStartSelecting() noexcept;
118  bool processStartAddingSymbolPins() noexcept;
119  bool processStartAddingNames() noexcept;
120  bool processStartAddingValues() noexcept;
121  bool processStartDrawLines() noexcept;
122  bool processStartDrawRects() noexcept;
123  bool processStartDrawPolygons() noexcept;
124  bool processStartDrawCircles() noexcept;
125  bool processStartDrawTexts() noexcept;
126 
127  // Operator Overloadings
128  SymbolEditorState& operator=(const SymbolEditorState& rhs) = delete;
129 
130 signals:
131  void toolChanged(EditorWidgetBase::Tool newTool);
132 
133 private: // Methods
134  SymbolEditorState* getCurrentState() const noexcept;
135  bool setNextState(State state) noexcept;
136  bool leaveCurrentState() noexcept;
137  bool enterNextState(State state) noexcept;
138 
139 private: // Data
142 };
143 
144 /*******************************************************************************
145  * End of File
146  ******************************************************************************/
147 
148 } // namespace editor
149 } // namespace library
150 } // namespace librepcb
151 
152 #endif // LIBREPCB_LIBRARY_EDITOR_SYMBOLEDITORFSM_H
Symbol & symbol
Definition: symboleditorfsm.h:88
bool setNextState(State state) noexcept
Definition: symboleditorfsm.cpp:227
bool processStartDrawLines() noexcept
Definition: symboleditorfsm.cpp:199
The SymbolEditorState class is the base class of all symbol editor FSM states.
Definition: symboleditorstate.h:52
bool processGraphicsSceneMouseMoved(QGraphicsSceneMouseEvent &e) noexcept
Definition: symboleditorfsm.cpp:105
The SymbolEditorWidget class.
Definition: symboleditorwidget.h:65
bool processStartDrawRects() noexcept
Definition: symboleditorfsm.cpp:203
ToolBarProxy & commandToolBar
Definition: symboleditorfsm.h:90
bool processStartDrawCircles() noexcept
Definition: symboleditorfsm.cpp:211
bool processGraphicsSceneLeftMouseButtonReleased(QGraphicsSceneMouseEvent &e) noexcept
Definition: symboleditorfsm.cpp:123
The GraphicsView class.
Definition: graphicsview.h:47
bool processRotateCw() noexcept
Definition: symboleditorfsm.cpp:151
The IF_GraphicsLayerProvider class defines an interface for classes which provide layers...
Definition: graphicslayer.h:250
The SymbolEditorFsm class is the finit state machine (FSM) of the symbol editor.
Definition: symboleditorfsm.h:64
QMap< State, SymbolEditorState * > mStates
Definition: symboleditorfsm.h:140
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:120
bool processStartAddingSymbolPins() noexcept
Definition: symboleditorfsm.cpp:187
SymbolGraphicsItem & symbolGraphicsItem
Definition: symboleditorfsm.h:89
void toolChanged(EditorWidgetBase::Tool newTool)
The Symbol class represents the part of a component which is added to schematics. ...
Definition: symbol.h:57
bool processStartDrawTexts() noexcept
Definition: symboleditorfsm.cpp:215
bool processGraphicsSceneLeftMouseButtonPressed(QGraphicsSceneMouseEvent &e) noexcept
Definition: symboleditorfsm.cpp:114
SymbolEditorWidget & editorWidget
Definition: symboleditorfsm.h:83
bool processGraphicsSceneLeftMouseButtonDoubleClicked(QGraphicsSceneMouseEvent &e) noexcept
Definition: symboleditorfsm.cpp:132
bool processStartDrawPolygons() noexcept
Definition: symboleditorfsm.cpp:207
GraphicsScene & graphicsScene
Definition: symboleditorfsm.h:86
SymbolEditorState * getCurrentState() const noexcept
Definition: symboleditorfsm.cpp:223
bool processGraphicsSceneRightMouseButtonReleased(QGraphicsSceneMouseEvent &e) noexcept
Definition: symboleditorfsm.cpp:142
virtual ~SymbolEditorFsm() noexcept
Definition: symboleditorfsm.cpp:63
bool processRotateCcw() noexcept
Definition: symboleditorfsm.cpp:159
EditorWidgetBase::Tool getCurrentTool() const noexcept
Definition: symboleditorfsm.cpp:73
bool processRemove() noexcept
Definition: symboleditorfsm.cpp:167
The SymbolGraphicsItem class.
Definition: symbolgraphicsitem.h:61
bool processStartAddingNames() noexcept
Definition: symboleditorfsm.cpp:191
bool processStartAddingValues() noexcept
Definition: symboleditorfsm.cpp:195
bool leaveCurrentState() noexcept
Definition: symboleditorfsm.cpp:237
bool processStartSelecting() noexcept
Definition: symboleditorfsm.cpp:183
State
Definition: symboleditorfsm.h:68
bool enterNextState(State state) noexcept
Definition: symboleditorfsm.cpp:246
bool processAbortCommand() noexcept
Definition: symboleditorfsm.cpp:175
GraphicsView & graphicsView
Definition: symboleditorfsm.h:87
The GraphicsScene class.
Definition: graphicsscene.h:43
const IF_GraphicsLayerProvider & layerProvider
Definition: symboleditorfsm.h:85
The ToolBarProxy class allows to map a list of QAction's to one QToolBar.
Definition: toolbarproxy.h:47
State mCurrentState
Definition: symboleditorfsm.h:141
UndoStack & undoStack
Definition: symboleditorfsm.h:84
The EditorWidgetBase class.
Definition: editorwidgetbase.h:66