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_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 {
89  };
90 
91 public:
92  // Constructors / Destructor
93  SymbolEditorFsm() = delete;
94  SymbolEditorFsm(const SymbolEditorFsm& other) = delete;
95  explicit SymbolEditorFsm(const Context& context) noexcept;
96  virtual ~SymbolEditorFsm() noexcept;
97 
98  // Getters
99  EditorWidgetBase::Tool getCurrentTool() const noexcept;
100 
101  // Event Handlers
102  bool processGraphicsSceneMouseMoved(QGraphicsSceneMouseEvent& e) noexcept;
104  QGraphicsSceneMouseEvent& e) noexcept;
106  QGraphicsSceneMouseEvent& e) noexcept;
108  QGraphicsSceneMouseEvent& e) noexcept;
110  QGraphicsSceneMouseEvent& e) noexcept;
111  bool processSelectAll() noexcept;
112  bool processCut() noexcept;
113  bool processCopy() noexcept;
114  bool processPaste() noexcept;
115  bool processRotateCw() noexcept;
116  bool processRotateCcw() noexcept;
117  bool processMirror() noexcept;
118  bool processRemove() noexcept;
119  bool processAbortCommand() noexcept;
120  bool processStartSelecting() noexcept;
121  bool processStartAddingSymbolPins() noexcept;
122  bool processStartAddingNames() noexcept;
123  bool processStartAddingValues() noexcept;
124  bool processStartDrawLines() noexcept;
125  bool processStartDrawRects() noexcept;
126  bool processStartDrawPolygons() noexcept;
127  bool processStartDrawCircles() noexcept;
128  bool processStartDrawTexts() noexcept;
129 
130  // Operator Overloadings
131  SymbolEditorState& operator=(const SymbolEditorState& rhs) = delete;
132 
133 signals:
134  void toolChanged(EditorWidgetBase::Tool newTool);
135 
136 private: // Methods
137  SymbolEditorState* getCurrentState() const noexcept;
138  bool setNextState(State state) noexcept;
139  bool leaveCurrentState() noexcept;
140  bool enterNextState(State state) noexcept;
141 
142 private: // Data
145 };
146 
147 /*******************************************************************************
148  * End of File
149  ******************************************************************************/
150 
151 } // namespace editor
152 } // namespace library
153 } // namespace librepcb
154 
155 #endif // LIBREPCB_LIBRARY_EDITOR_SYMBOLEDITORFSM_H
Symbol & symbol
Definition: symboleditorfsm.h:86
bool setNextState(State state) noexcept
Definition: symboleditorfsm.cpp:267
bool processStartDrawLines() noexcept
Definition: symboleditorfsm.cpp:239
The SymbolEditorState class is the base class of all symbol editor FSM states.
Definition: symboleditorstate.h:49
The Workspace class represents a workspace with all its data (library, projects, settings, ...)
Definition: workspace.h:62
bool processGraphicsSceneMouseMoved(QGraphicsSceneMouseEvent &e) noexcept
Definition: symboleditorfsm.cpp:105
The SymbolEditorWidget class.
Definition: symboleditorwidget.h:62
bool processStartDrawRects() noexcept
Definition: symboleditorfsm.cpp:243
ToolBarProxy & commandToolBar
Definition: symboleditorfsm.h:88
Definition: airwiresbuilder.cpp:32
bool processStartDrawCircles() noexcept
Definition: symboleditorfsm.cpp:251
bool processGraphicsSceneLeftMouseButtonReleased(QGraphicsSceneMouseEvent &e) noexcept
Definition: symboleditorfsm.cpp:123
The GraphicsView class.
Definition: graphicsview.h:47
bool processRotateCw() noexcept
Definition: symboleditorfsm.cpp:183
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:143
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:107
workspace::Workspace & workspace
Definition: symboleditorfsm.h:80
bool processStartAddingSymbolPins() noexcept
Definition: symboleditorfsm.cpp:227
SymbolGraphicsItem & symbolGraphicsItem
Definition: symboleditorfsm.h:87
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:255
bool processGraphicsSceneLeftMouseButtonPressed(QGraphicsSceneMouseEvent &e) noexcept
Definition: symboleditorfsm.cpp:114
SymbolEditorWidget & editorWidget
Definition: symboleditorfsm.h:81
bool processGraphicsSceneLeftMouseButtonDoubleClicked(QGraphicsSceneMouseEvent &e) noexcept
Definition: symboleditorfsm.cpp:132
bool processStartDrawPolygons() noexcept
Definition: symboleditorfsm.cpp:247
GraphicsScene & graphicsScene
Definition: symboleditorfsm.h:84
SymbolEditorState * getCurrentState() const noexcept
Definition: symboleditorfsm.cpp:263
bool processGraphicsSceneRightMouseButtonReleased(QGraphicsSceneMouseEvent &e) noexcept
Definition: symboleditorfsm.cpp:142
virtual ~SymbolEditorFsm() noexcept
Definition: symboleditorfsm.cpp:63
bool processRotateCcw() noexcept
Definition: symboleditorfsm.cpp:191
EditorWidgetBase::Tool getCurrentTool() const noexcept
Definition: symboleditorfsm.cpp:73
bool processRemove() noexcept
Definition: symboleditorfsm.cpp:207
The SymbolGraphicsItem class.
Definition: symbolgraphicsitem.h:58
bool processStartAddingNames() noexcept
Definition: symboleditorfsm.cpp:231
bool processStartAddingValues() noexcept
Definition: symboleditorfsm.cpp:235
bool processMirror() noexcept
Definition: symboleditorfsm.cpp:199
bool leaveCurrentState() noexcept
Definition: symboleditorfsm.cpp:277
bool processStartSelecting() noexcept
Definition: symboleditorfsm.cpp:223
State
Definition: symboleditorfsm.h:65
bool processCopy() noexcept
Definition: symboleditorfsm.cpp:167
bool enterNextState(State state) noexcept
Definition: symboleditorfsm.cpp:286
bool processAbortCommand() noexcept
Definition: symboleditorfsm.cpp:215
GraphicsView & graphicsView
Definition: symboleditorfsm.h:85
The GraphicsScene class.
Definition: graphicsscene.h:43
const IF_GraphicsLayerProvider & layerProvider
Definition: symboleditorfsm.h:83
The ToolBarProxy class allows to map a list of QAction&#39;s to one QToolBar.
Definition: toolbarproxy.h:44
bool processSelectAll() noexcept
Definition: symboleditorfsm.cpp:151
State mCurrentState
Definition: symboleditorfsm.h:144
UndoStack & undoStack
Definition: symboleditorfsm.h:82
bool processCut() noexcept
Definition: symboleditorfsm.cpp:159
bool processPaste() noexcept
Definition: symboleditorfsm.cpp:175
The EditorWidgetBase class.
Definition: editorwidgetbase.h:63