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 
61 class SymbolEditorFsm final : public QObject {
62  Q_OBJECT
63 
64 private: // Types
65  enum class State {
66  IDLE,
67  SELECT,
68  ADD_PINS,
69  ADD_NAMES,
70  ADD_VALUES,
71  DRAW_LINE,
72  DRAW_RECT,
75  DRAW_TEXT
76  };
77 
78 public: // Types
79  struct Context {
88  };
89 
90 public:
91  // Constructors / Destructor
92  SymbolEditorFsm() = delete;
93  SymbolEditorFsm(const SymbolEditorFsm& other) = delete;
94  explicit SymbolEditorFsm(const Context& context) noexcept;
95  virtual ~SymbolEditorFsm() noexcept;
96 
97  // Getters
98  EditorWidgetBase::Tool getCurrentTool() const noexcept;
99 
100  // Event Handlers
101  bool processGraphicsSceneMouseMoved(QGraphicsSceneMouseEvent& e) noexcept;
103  QGraphicsSceneMouseEvent& e) noexcept;
105  QGraphicsSceneMouseEvent& e) noexcept;
107  QGraphicsSceneMouseEvent& e) noexcept;
109  QGraphicsSceneMouseEvent& e) noexcept;
110  bool processCut() noexcept;
111  bool processCopy() noexcept;
112  bool processPaste() noexcept;
113  bool processRotateCw() noexcept;
114  bool processRotateCcw() noexcept;
115  bool processMirror() noexcept;
116  bool processRemove() noexcept;
117  bool processAbortCommand() noexcept;
118  bool processStartSelecting() noexcept;
119  bool processStartAddingSymbolPins() noexcept;
120  bool processStartAddingNames() noexcept;
121  bool processStartAddingValues() noexcept;
122  bool processStartDrawLines() noexcept;
123  bool processStartDrawRects() noexcept;
124  bool processStartDrawPolygons() noexcept;
125  bool processStartDrawCircles() noexcept;
126  bool processStartDrawTexts() noexcept;
127 
128  // Operator Overloadings
129  SymbolEditorState& operator=(const SymbolEditorState& rhs) = delete;
130 
131 signals:
132  void toolChanged(EditorWidgetBase::Tool newTool);
133 
134 private: // Methods
135  SymbolEditorState* getCurrentState() const noexcept;
136  bool setNextState(State state) noexcept;
137  bool leaveCurrentState() noexcept;
138  bool enterNextState(State state) noexcept;
139 
140 private: // Data
143 };
144 
145 /*******************************************************************************
146  * End of File
147  ******************************************************************************/
148 
149 } // namespace editor
150 } // namespace library
151 } // namespace librepcb
152 
153 #endif // LIBREPCB_LIBRARY_EDITOR_SYMBOLEDITORFSM_H
Symbol & symbol
Definition: symboleditorfsm.h:85
bool setNextState(State state) noexcept
Definition: symboleditorfsm.cpp:259
bool processStartDrawLines() noexcept
Definition: symboleditorfsm.cpp:231
The SymbolEditorState class is the base class of all symbol editor FSM states.
Definition: symboleditorstate.h:49
bool processGraphicsSceneMouseMoved(QGraphicsSceneMouseEvent &e) noexcept
Definition: symboleditorfsm.cpp:105
The SymbolEditorWidget class.
Definition: symboleditorwidget.h:62
bool processStartDrawRects() noexcept
Definition: symboleditorfsm.cpp:235
ToolBarProxy & commandToolBar
Definition: symboleditorfsm.h:87
bool processStartDrawCircles() noexcept
Definition: symboleditorfsm.cpp:243
bool processGraphicsSceneLeftMouseButtonReleased(QGraphicsSceneMouseEvent &e) noexcept
Definition: symboleditorfsm.cpp:123
The GraphicsView class.
Definition: graphicsview.h:47
bool processRotateCw() noexcept
Definition: symboleditorfsm.cpp:175
The IF_GraphicsLayerProvider class defines an interface for classes which provide layers...
Definition: graphicslayer.h:227
The SymbolEditorFsm class is the finit state machine (FSM) of the symbol editor.
Definition: symboleditorfsm.h:61
QMap< State, SymbolEditorState * > mStates
Definition: symboleditorfsm.h:141
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:107
bool processStartAddingSymbolPins() noexcept
Definition: symboleditorfsm.cpp:219
SymbolGraphicsItem & symbolGraphicsItem
Definition: symboleditorfsm.h:86
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:247
bool processGraphicsSceneLeftMouseButtonPressed(QGraphicsSceneMouseEvent &e) noexcept
Definition: symboleditorfsm.cpp:114
SymbolEditorWidget & editorWidget
Definition: symboleditorfsm.h:80
bool processGraphicsSceneLeftMouseButtonDoubleClicked(QGraphicsSceneMouseEvent &e) noexcept
Definition: symboleditorfsm.cpp:132
bool processStartDrawPolygons() noexcept
Definition: symboleditorfsm.cpp:239
GraphicsScene & graphicsScene
Definition: symboleditorfsm.h:83
SymbolEditorState * getCurrentState() const noexcept
Definition: symboleditorfsm.cpp:255
bool processGraphicsSceneRightMouseButtonReleased(QGraphicsSceneMouseEvent &e) noexcept
Definition: symboleditorfsm.cpp:142
virtual ~SymbolEditorFsm() noexcept
Definition: symboleditorfsm.cpp:63
bool processRotateCcw() noexcept
Definition: symboleditorfsm.cpp:183
EditorWidgetBase::Tool getCurrentTool() const noexcept
Definition: symboleditorfsm.cpp:73
bool processRemove() noexcept
Definition: symboleditorfsm.cpp:199
The SymbolGraphicsItem class.
Definition: symbolgraphicsitem.h:58
bool processStartAddingNames() noexcept
Definition: symboleditorfsm.cpp:223
bool processStartAddingValues() noexcept
Definition: symboleditorfsm.cpp:227
bool processMirror() noexcept
Definition: symboleditorfsm.cpp:191
bool leaveCurrentState() noexcept
Definition: symboleditorfsm.cpp:269
bool processStartSelecting() noexcept
Definition: symboleditorfsm.cpp:215
State
Definition: symboleditorfsm.h:65
bool processCopy() noexcept
Definition: symboleditorfsm.cpp:159
bool enterNextState(State state) noexcept
Definition: symboleditorfsm.cpp:278
bool processAbortCommand() noexcept
Definition: symboleditorfsm.cpp:207
GraphicsView & graphicsView
Definition: symboleditorfsm.h:84
The GraphicsScene class.
Definition: graphicsscene.h:43
const IF_GraphicsLayerProvider & layerProvider
Definition: symboleditorfsm.h:82
The ToolBarProxy class allows to map a list of QAction's to one QToolBar.
Definition: toolbarproxy.h:44
State mCurrentState
Definition: symboleditorfsm.h:142
UndoStack & undoStack
Definition: symboleditorfsm.h:81
bool processCut() noexcept
Definition: symboleditorfsm.cpp:151
bool processPaste() noexcept
Definition: symboleditorfsm.cpp:167
The EditorWidgetBase class.
Definition: editorwidgetbase.h:62