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 
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 {
90  std::shared_ptr<Footprint> currentFootprint;
91  std::shared_ptr<FootprintGraphicsItem> currentGraphicsItem;
93  };
94 
95 public:
96  // Constructors / Destructor
97  PackageEditorFsm() = delete;
98  PackageEditorFsm(const PackageEditorFsm& other) = delete;
99  explicit PackageEditorFsm(const Context& context) noexcept;
100  virtual ~PackageEditorFsm() noexcept;
101 
102  // Getters
103  EditorWidgetBase::Tool getCurrentTool() const noexcept;
104 
105  // Event Handlers
107  const std::shared_ptr<Footprint>& fpt) noexcept;
108  bool processGraphicsSceneMouseMoved(QGraphicsSceneMouseEvent& e) noexcept;
110  QGraphicsSceneMouseEvent& e) noexcept;
112  QGraphicsSceneMouseEvent& e) noexcept;
114  QGraphicsSceneMouseEvent& e) noexcept;
116  QGraphicsSceneMouseEvent& e) noexcept;
117  bool processCut() noexcept;
118  bool processCopy() noexcept;
119  bool processPaste() 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:305
const IF_GraphicsLayerProvider & layerProvider
Definition: packageeditorfsm.h:88
std::shared_ptr< Footprint > currentFootprint
Definition: packageeditorfsm.h:90
EditorWidgetBase::Tool getCurrentTool() const noexcept
Definition: packageeditorfsm.cpp:86
bool processStartAddingFootprintThtPads() noexcept
Definition: packageeditorfsm.cpp:277
QScopedPointer< PrimitiveTextGraphicsItem > mSelectFootprintGraphicsItem
Definition: packageeditorfsm.h:152
GraphicsScene & graphicsScene
Definition: packageeditorfsm.h:86
bool processRotateCw() noexcept
Definition: packageeditorfsm.cpp:238
State mCurrentState
Definition: packageeditorfsm.h:151
bool processRemove() noexcept
Definition: packageeditorfsm.cpp:256
std::shared_ptr< FootprintGraphicsItem > currentGraphicsItem
Definition: packageeditorfsm.h:91
The Package class represents a package of a component (including footprint and 3D model) ...
Definition: package.h:56
PackageEditorWidget & editorWidget
Definition: packageeditorfsm.h:84
void toolChanged(EditorWidgetBase::Tool newTool)
bool processCopy() noexcept
Definition: packageeditorfsm.cpp:222
bool leaveCurrentState() noexcept
Definition: packageeditorfsm.cpp:339
bool processStartDrawLines() noexcept
Definition: packageeditorfsm.cpp:293
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:309
Package & package
Definition: packageeditorfsm.h:89
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:313
bool processStartAddingNames() noexcept
Definition: packageeditorfsm.cpp:285
GraphicsView & graphicsView
Definition: packageeditorfsm.h:87
bool setNextState(State state) noexcept
Definition: packageeditorfsm.cpp:325
bool enterNextState(State state) noexcept
Definition: packageeditorfsm.cpp:348
bool processRotateCcw() noexcept
Definition: packageeditorfsm.cpp:247
bool processPaste() noexcept
Definition: packageeditorfsm.cpp:230
bool processGraphicsSceneLeftMouseButtonPressed(QGraphicsSceneMouseEvent &e) noexcept
Definition: packageeditorfsm.cpp:173
virtual ~PackageEditorFsm() noexcept
Definition: packageeditorfsm.cpp:76
The PackageEditorWidget class.
Definition: packageeditorwidget.h:63
State
Definition: packageeditorfsm.h:67
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:49
The PackageEditorFsm class is the finit state machine (FSM) of the package editor.
Definition: packageeditorfsm.h:63
bool processStartDrawRects() noexcept
Definition: packageeditorfsm.cpp:297
bool processCut() noexcept
Definition: packageeditorfsm.cpp:214
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:85
bool processGraphicsSceneLeftMouseButtonReleased(QGraphicsSceneMouseEvent &e) noexcept
Definition: packageeditorfsm.cpp:183
bool processStartAddingValues() noexcept
Definition: packageeditorfsm.cpp:289
Context mContext
Definition: packageeditorfsm.h:149
The GraphicsScene class.
Definition: graphicsscene.h:43
ToolBarProxy & commandToolBar
Definition: packageeditorfsm.h:92
bool processAbortCommand() noexcept
Definition: packageeditorfsm.cpp:265
The PrimitiveTextGraphicsItem class is the graphical representation of a text.
Definition: primitivetextgraphicsitem.h:46
The ToolBarProxy class allows to map a list of QAction's to one QToolBar.
Definition: toolbarproxy.h:44
PackageEditorState * getCurrentState() const noexcept
Definition: packageeditorfsm.cpp:321
bool processStartSelecting() noexcept
Definition: packageeditorfsm.cpp:273
The Footprint class represents one footprint variant of a package.
Definition: footprint.h:61
The EditorWidgetBase class.
Definition: editorwidgetbase.h:62
bool processStartAddingFootprintSmtPads() noexcept
Definition: packageeditorfsm.cpp:281
bool processStartDrawPolygons() noexcept
Definition: packageeditorfsm.cpp:301