LibrePCB Developers Documentation
packageeditorfsm.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_PACKAGEEDITORFSM_H
21 #define LIBREPCB_LIBRARY_EDITOR_PACKAGEEDITORFSM_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 class PrimitiveTextGraphicsItem;
43 
44 namespace library {
45 
46 class Package;
47 class Footprint;
48 class FootprintGraphicsItem;
49 
50 namespace editor {
51 
52 class PackageEditorState;
53 class PackageEditorWidget;
54 
55 /*******************************************************************************
56  * Class PackageEditorFsm
57  ******************************************************************************/
58 
63 class PackageEditorFsm final : public QObject {
64  Q_OBJECT
65 
66 private: // Types
67  enum class State {
68  IDLE,
69  SELECT,
72  ADD_NAMES,
73  ADD_VALUES,
74  DRAW_LINE,
75  DRAW_RECT,
78  DRAW_TEXT,
79  ADD_HOLES,
80  };
81 
82 public: // Types
83  struct Context {
91  std::shared_ptr<Footprint> currentFootprint;
92  std::shared_ptr<FootprintGraphicsItem> currentGraphicsItem;
94  };
95 
96 public:
97  // Constructors / Destructor
98  PackageEditorFsm() = delete;
99  PackageEditorFsm(const PackageEditorFsm& other) = delete;
100  explicit PackageEditorFsm(const Context& context) noexcept;
101  virtual ~PackageEditorFsm() noexcept;
102 
103  // Getters
104  EditorWidgetBase::Tool getCurrentTool() const noexcept;
105 
106  // Event Handlers
108  const std::shared_ptr<Footprint>& fpt) noexcept;
109  bool processGraphicsSceneMouseMoved(QGraphicsSceneMouseEvent& e) noexcept;
111  QGraphicsSceneMouseEvent& e) noexcept;
113  QGraphicsSceneMouseEvent& e) noexcept;
115  QGraphicsSceneMouseEvent& e) noexcept;
117  QGraphicsSceneMouseEvent& e) noexcept;
118  bool processCut() noexcept;
119  bool processCopy() noexcept;
120  bool processPaste() noexcept;
121  bool processRotateCw() noexcept;
122  bool processRotateCcw() noexcept;
123  bool processMirror() noexcept;
124  bool processFlip() noexcept;
125  bool processRemove() noexcept;
126  bool processAbortCommand() noexcept;
127  bool processStartSelecting() noexcept;
128  bool processStartAddingFootprintThtPads() noexcept;
129  bool processStartAddingFootprintSmtPads() noexcept;
130  bool processStartAddingNames() noexcept;
131  bool processStartAddingValues() noexcept;
132  bool processStartDrawLines() noexcept;
133  bool processStartDrawRects() noexcept;
134  bool processStartDrawPolygons() noexcept;
135  bool processStartDrawCircles() noexcept;
136  bool processStartDrawTexts() noexcept;
137  bool processStartAddingHoles() noexcept;
138 
139  // Operator Overloadings
140  PackageEditorFsm& operator=(const PackageEditorFsm& rhs) = delete;
141 
142 signals:
143  void toolChanged(EditorWidgetBase::Tool newTool);
144 
145 private: // Methods
146  PackageEditorState* getCurrentState() const noexcept;
147  bool setNextState(State state) noexcept;
148  bool leaveCurrentState() noexcept;
149  bool enterNextState(State state) noexcept;
150 
151 private: // Data
156 };
157 
158 /*******************************************************************************
159  * End of File
160  ******************************************************************************/
161 
162 } // namespace editor
163 } // namespace library
164 } // namespace librepcb
165 
166 #endif // LIBREPCB_LIBRARY_EDITOR_PACKAGEEDITORFSM_H
bool processStartDrawCircles() noexcept
Definition: packageeditorfsm.cpp:325
const IF_GraphicsLayerProvider & layerProvider
Definition: packageeditorfsm.h:89
bool processMirror() noexcept
Definition: packageeditorfsm.cpp:258
std::shared_ptr< Footprint > currentFootprint
Definition: packageeditorfsm.h:91
EditorWidgetBase::Tool getCurrentTool() const noexcept
Definition: packageeditorfsm.cpp:87
bool processStartAddingFootprintThtPads() noexcept
Definition: packageeditorfsm.cpp:297
QScopedPointer< PrimitiveTextGraphicsItem > mSelectFootprintGraphicsItem
Definition: packageeditorfsm.h:155
The Workspace class represents a workspace with all its data (library, projects, settings, ...)
Definition: workspace.h:62
GraphicsScene & graphicsScene
Definition: packageeditorfsm.h:87
bool processRotateCw() noexcept
Definition: packageeditorfsm.cpp:240
State mCurrentState
Definition: packageeditorfsm.h:154
Definition: airwiresbuilder.cpp:32
bool processRemove() noexcept
Definition: packageeditorfsm.cpp:276
std::shared_ptr< FootprintGraphicsItem > currentGraphicsItem
Definition: packageeditorfsm.h:92
The Package class represents a package of a component (including footprint and 3D model) ...
Definition: package.h:56
PackageEditorWidget & editorWidget
Definition: packageeditorfsm.h:85
void toolChanged(EditorWidgetBase::Tool newTool)
bool processCopy() noexcept
Definition: packageeditorfsm.cpp:224
bool leaveCurrentState() noexcept
Definition: packageeditorfsm.cpp:359
bool processStartDrawLines() noexcept
Definition: packageeditorfsm.cpp:313
The GraphicsView class.
Definition: graphicsview.h:47
bool processChangeCurrentFootprint(const std::shared_ptr< Footprint > &fpt) noexcept
Definition: packageeditorfsm.cpp:123
bool processStartDrawTexts() noexcept
Definition: packageeditorfsm.cpp:329
Package & package
Definition: packageeditorfsm.h:90
The IF_GraphicsLayerProvider class defines an interface for classes which provide layers...
Definition: graphicslayer.h:227
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:107
bool processStartAddingHoles() noexcept
Definition: packageeditorfsm.cpp:333
bool processStartAddingNames() noexcept
Definition: packageeditorfsm.cpp:305
GraphicsView & graphicsView
Definition: packageeditorfsm.h:88
bool setNextState(State state) noexcept
Definition: packageeditorfsm.cpp:345
bool enterNextState(State state) noexcept
Definition: packageeditorfsm.cpp:368
bool processRotateCcw() noexcept
Definition: packageeditorfsm.cpp:249
bool processPaste() noexcept
Definition: packageeditorfsm.cpp:232
bool processGraphicsSceneLeftMouseButtonPressed(QGraphicsSceneMouseEvent &e) noexcept
Definition: packageeditorfsm.cpp:175
virtual ~PackageEditorFsm() noexcept
Definition: packageeditorfsm.cpp:77
The PackageEditorWidget class.
Definition: packageeditorwidget.h:63
State
Definition: packageeditorfsm.h:67
bool processGraphicsSceneLeftMouseButtonDoubleClicked(QGraphicsSceneMouseEvent &e) noexcept
Definition: packageeditorfsm.cpp:195
The PackageEditorState class is the base class of all package editor FSM states.
Definition: packageeditorstate.h:49
The PackageEditorFsm class is the finit state machine (FSM) of the package editor.
Definition: packageeditorfsm.h:63
bool processStartDrawRects() noexcept
Definition: packageeditorfsm.cpp:317
workspace::Workspace & workspace
Definition: packageeditorfsm.h:84
bool processCut() noexcept
Definition: packageeditorfsm.cpp:216
bool processGraphicsSceneRightMouseButtonReleased(QGraphicsSceneMouseEvent &e) noexcept
Definition: packageeditorfsm.cpp:206
QMap< State, PackageEditorState * > mStates
Definition: packageeditorfsm.h:153
bool processGraphicsSceneMouseMoved(QGraphicsSceneMouseEvent &e) noexcept
Definition: packageeditorfsm.cpp:165
UndoStack & undoStack
Definition: packageeditorfsm.h:86
bool processGraphicsSceneLeftMouseButtonReleased(QGraphicsSceneMouseEvent &e) noexcept
Definition: packageeditorfsm.cpp:185
bool processStartAddingValues() noexcept
Definition: packageeditorfsm.cpp:309
Context mContext
Definition: packageeditorfsm.h:152
The GraphicsScene class.
Definition: graphicsscene.h:43
ToolBarProxy & commandToolBar
Definition: packageeditorfsm.h:93
bool processAbortCommand() noexcept
Definition: packageeditorfsm.cpp:285
The PrimitiveTextGraphicsItem class is the graphical representation of a text.
Definition: primitivetextgraphicsitem.h:46
bool processFlip() noexcept
Definition: packageeditorfsm.cpp:267
The ToolBarProxy class allows to map a list of QAction&#39;s to one QToolBar.
Definition: toolbarproxy.h:44
PackageEditorState * getCurrentState() const noexcept
Definition: packageeditorfsm.cpp:341
bool processStartSelecting() noexcept
Definition: packageeditorfsm.cpp:293
The Footprint class represents one footprint variant of a package.
Definition: footprint.h:61
The EditorWidgetBase class.
Definition: editorwidgetbase.h:63
bool processStartAddingFootprintSmtPads() noexcept
Definition: packageeditorfsm.cpp:301
bool processStartDrawPolygons() noexcept
Definition: packageeditorfsm.cpp:321