LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
66 class PackageEditorFsm final : public QObject {
67  Q_OBJECT
68 
69 private: // Types
70  enum class State {
71  IDLE,
72  SELECT,
75  ADD_NAMES,
76  ADD_VALUES,
77  DRAW_LINE,
78  DRAW_RECT,
81  DRAW_TEXT,
82  ADD_HOLES,
83  };
84 
85 public: // Types
86  struct Context {
93  std::shared_ptr<Footprint> currentFootprint;
94  std::shared_ptr<FootprintGraphicsItem> currentGraphicsItem;
96  };
97 
98 public:
99  // Constructors / Destructor
100  PackageEditorFsm() = delete;
101  PackageEditorFsm(const PackageEditorFsm& other) = delete;
102  explicit PackageEditorFsm(const Context& context) noexcept;
103  virtual ~PackageEditorFsm() noexcept;
104 
105  // Getters
106  EditorWidgetBase::Tool getCurrentTool() const noexcept;
107 
108  // Event Handlers
110  const std::shared_ptr<Footprint>& fpt) noexcept;
111  bool processGraphicsSceneMouseMoved(QGraphicsSceneMouseEvent& e) noexcept;
113  QGraphicsSceneMouseEvent& e) noexcept;
115  QGraphicsSceneMouseEvent& e) noexcept;
117  QGraphicsSceneMouseEvent& e) noexcept;
119  QGraphicsSceneMouseEvent& e) noexcept;
120  bool processRotateCw() noexcept;
121  bool processRotateCcw() noexcept;
122  bool processRemove() noexcept;
123  bool processAbortCommand() noexcept;
124  bool processStartSelecting() noexcept;
125  bool processStartAddingFootprintThtPads() noexcept;
126  bool processStartAddingFootprintSmtPads() noexcept;
127  bool processStartAddingNames() noexcept;
128  bool processStartAddingValues() noexcept;
129  bool processStartDrawLines() noexcept;
130  bool processStartDrawRects() noexcept;
131  bool processStartDrawPolygons() noexcept;
132  bool processStartDrawCircles() noexcept;
133  bool processStartDrawTexts() noexcept;
134  bool processStartAddingHoles() noexcept;
135 
136  // Operator Overloadings
137  PackageEditorFsm& operator=(const PackageEditorFsm& rhs) = delete;
138 
139 signals:
140  void toolChanged(EditorWidgetBase::Tool newTool);
141 
142 private: // Methods
143  PackageEditorState* getCurrentState() const noexcept;
144  bool setNextState(State state) noexcept;
145  bool leaveCurrentState() noexcept;
146  bool enterNextState(State state) noexcept;
147 
148 private: // Data
153 };
154 
155 /*******************************************************************************
156  * End of File
157  ******************************************************************************/
158 
159 } // namespace editor
160 } // namespace library
161 } // namespace librepcb
162 
163 #endif // LIBREPCB_LIBRARY_EDITOR_PACKAGEEDITORFSM_H
bool processStartDrawCircles() noexcept
Definition: packageeditorfsm.cpp:281
const IF_GraphicsLayerProvider & layerProvider
Definition: packageeditorfsm.h:91
std::shared_ptr< Footprint > currentFootprint
Definition: packageeditorfsm.h:93
EditorWidgetBase::Tool getCurrentTool() const noexcept
Definition: packageeditorfsm.cpp:86
bool processStartAddingFootprintThtPads() noexcept
Definition: packageeditorfsm.cpp:253
QScopedPointer< PrimitiveTextGraphicsItem > mSelectFootprintGraphicsItem
Definition: packageeditorfsm.h:152
GraphicsScene & graphicsScene
Definition: packageeditorfsm.h:89
bool processRotateCw() noexcept
Definition: packageeditorfsm.cpp:214
State mCurrentState
Definition: packageeditorfsm.h:151
bool processRemove() noexcept
Definition: packageeditorfsm.cpp:232
std::shared_ptr< FootprintGraphicsItem > currentGraphicsItem
Definition: packageeditorfsm.h:94
The Package class represents a package of a component (including footprint and 3D model) ...
Definition: package.h:56
PackageEditorWidget & editorWidget
Definition: packageeditorfsm.h:87
void toolChanged(EditorWidgetBase::Tool newTool)
bool leaveCurrentState() noexcept
Definition: packageeditorfsm.cpp:315
bool processStartDrawLines() noexcept
Definition: packageeditorfsm.cpp:269
The GraphicsView class.
Definition: graphicsview.h:47
bool processChangeCurrentFootprint(const std::shared_ptr< Footprint > &fpt) noexcept
Definition: packageeditorfsm.cpp:122
bool processStartDrawTexts() noexcept
Definition: packageeditorfsm.cpp:285
Package & package
Definition: packageeditorfsm.h:92
The IF_GraphicsLayerProvider class defines an interface for classes which provide layers...
Definition: graphicslayer.h:250
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:120
bool processStartAddingHoles() noexcept
Definition: packageeditorfsm.cpp:289
bool processStartAddingNames() noexcept
Definition: packageeditorfsm.cpp:261
GraphicsView & graphicsView
Definition: packageeditorfsm.h:90
bool setNextState(State state) noexcept
Definition: packageeditorfsm.cpp:301
bool enterNextState(State state) noexcept
Definition: packageeditorfsm.cpp:324
bool processRotateCcw() noexcept
Definition: packageeditorfsm.cpp:223
bool processGraphicsSceneLeftMouseButtonPressed(QGraphicsSceneMouseEvent &e) noexcept
Definition: packageeditorfsm.cpp:173
virtual ~PackageEditorFsm() noexcept
Definition: packageeditorfsm.cpp:76
The PackageEditorWidget class.
Definition: packageeditorwidget.h:66
State
Definition: packageeditorfsm.h:70
bool processGraphicsSceneLeftMouseButtonDoubleClicked(QGraphicsSceneMouseEvent &e) noexcept
Definition: packageeditorfsm.cpp:193
The PackageEditorState class is the base class of all package editor FSM states.
Definition: packageeditorstate.h:52
The PackageEditorFsm class is the finit state machine (FSM) of the package editor.
Definition: packageeditorfsm.h:66
bool processStartDrawRects() noexcept
Definition: packageeditorfsm.cpp:273
bool processGraphicsSceneRightMouseButtonReleased(QGraphicsSceneMouseEvent &e) noexcept
Definition: packageeditorfsm.cpp:204
QMap< State, PackageEditorState * > mStates
Definition: packageeditorfsm.h:150
bool processGraphicsSceneMouseMoved(QGraphicsSceneMouseEvent &e) noexcept
Definition: packageeditorfsm.cpp:163
UndoStack & undoStack
Definition: packageeditorfsm.h:88
bool processGraphicsSceneLeftMouseButtonReleased(QGraphicsSceneMouseEvent &e) noexcept
Definition: packageeditorfsm.cpp:183
bool processStartAddingValues() noexcept
Definition: packageeditorfsm.cpp:265
Context mContext
Definition: packageeditorfsm.h:149
The GraphicsScene class.
Definition: graphicsscene.h:43
ToolBarProxy & commandToolBar
Definition: packageeditorfsm.h:95
bool processAbortCommand() noexcept
Definition: packageeditorfsm.cpp:241
The PrimitiveTextGraphicsItem class is the graphical representation of a text.
Definition: primitivetextgraphicsitem.h:51
The ToolBarProxy class allows to map a list of QAction's to one QToolBar.
Definition: toolbarproxy.h:47
PackageEditorState * getCurrentState() const noexcept
Definition: packageeditorfsm.cpp:297
bool processStartSelecting() noexcept
Definition: packageeditorfsm.cpp:249
The Footprint class represents one footprint variant of a package.
Definition: footprint.h:61
The EditorWidgetBase class.
Definition: editorwidgetbase.h:65
bool processStartAddingFootprintSmtPads() noexcept
Definition: packageeditorfsm.cpp:257
bool processStartDrawPolygons() noexcept
Definition: packageeditorfsm.cpp:277