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_EDITOR_PACKAGEEDITORFSM_H
21 #define LIBREPCB_EDITOR_PACKAGEEDITORFSM_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "../../editorwidgetbase.h"
27 
29 
30 #include <QtCore>
31 
32 #include <memory>
33 
34 /*******************************************************************************
35  * Namespace / Forward Declarations
36  ******************************************************************************/
37 namespace librepcb {
38 
39 class Footprint;
40 class Package;
41 
42 namespace editor {
43 
44 class FootprintGraphicsItem;
45 class GraphicsScene;
46 class GraphicsView;
47 class PackageEditorState;
48 class PackageEditorWidget;
49 class PrimitiveTextGraphicsItem;
50 class UndoStack;
51 
52 /*******************************************************************************
53  * Class PackageEditorFsm
54  ******************************************************************************/
55 
60 class PackageEditorFsm final : public QObject {
61  Q_OBJECT
62 
63 private: // Types
64  enum class State {
65  IDLE,
66  SELECT,
75  ADD_NAMES,
76  ADD_VALUES,
77  DRAW_LINE,
78  DRAW_ARC,
79  DRAW_RECT,
82  DRAW_TEXT,
83  DRAW_ZONE,
84  ADD_HOLES,
85  MEASURE,
86  };
87 
88 public: // Types
89  struct Context {
97  std::shared_ptr<Footprint> currentFootprint;
98  std::shared_ptr<FootprintGraphicsItem> currentGraphicsItem;
100  };
101 
102 public:
103  // Constructors / Destructor
104  PackageEditorFsm() = delete;
105  PackageEditorFsm(const PackageEditorFsm& other) = delete;
106  explicit PackageEditorFsm(const Context& context) noexcept;
107  virtual ~PackageEditorFsm() noexcept;
108 
109  // Getters
110  EditorWidgetBase::Tool getCurrentTool() const noexcept;
111  std::shared_ptr<Footprint> getCurrentFootprint() const noexcept;
112  const QSet<EditorWidgetBase::Feature>& getAvailableFeatures() const noexcept {
113  return mAvailableFeatures;
114  }
115 
116  // General Methods
117  void updateAvailableFeatures() noexcept;
118 
119  // Event Handlers
121  const std::shared_ptr<Footprint>& fpt) noexcept;
122  bool processKeyPressed(const QKeyEvent& e) noexcept;
123  bool processKeyReleased(const QKeyEvent& e) noexcept;
124  bool processGraphicsSceneMouseMoved(QGraphicsSceneMouseEvent& e) noexcept;
126  QGraphicsSceneMouseEvent& e) noexcept;
128  QGraphicsSceneMouseEvent& e) noexcept;
130  QGraphicsSceneMouseEvent& e) noexcept;
132  QGraphicsSceneMouseEvent& e) noexcept;
133  bool processSelectAll() noexcept;
134  bool processCut() noexcept;
135  bool processCopy() noexcept;
136  bool processPaste() noexcept;
137  bool processMove(Qt::ArrowType direction) noexcept;
138  bool processRotate(const Angle& rotation) noexcept;
139  bool processMirror(Qt::Orientation orientation) noexcept;
140  bool processFlip(Qt::Orientation orientation) noexcept;
141  bool processSnapToGrid() noexcept;
142  bool processRemove() noexcept;
143  bool processEditProperties() noexcept;
144  bool processGenerateOutline() noexcept;
145  bool processGenerateCourtyard() noexcept;
146  bool processAbortCommand() noexcept;
147  bool processStartSelecting() noexcept;
148  bool processStartAddingFootprintThtPads() noexcept;
150  FootprintPad::Function function) noexcept;
151  bool processStartAddingNames() noexcept;
152  bool processStartAddingValues() noexcept;
153  bool processStartDrawLines() noexcept;
154  bool processStartDrawArcs() noexcept;
155  bool processStartDrawRects() noexcept;
156  bool processStartDrawPolygons() noexcept;
157  bool processStartDrawCircles() noexcept;
158  bool processStartDrawTexts() noexcept;
159  bool processStartDrawZones() noexcept;
160  bool processStartAddingHoles() noexcept;
161  bool processStartDxfImport() noexcept;
162  bool processStartMeasure() noexcept;
163 
164  // Operator Overloadings
165  PackageEditorFsm& operator=(const PackageEditorFsm& rhs) = delete;
166 
167 signals:
168  void toolChanged(EditorWidgetBase::Tool newTool);
170  void statusBarMessageChanged(const QString& message, int timeoutMs = -1);
171 
172 private: // Methods
173  PackageEditorState* getCurrentState() const noexcept;
174  bool setNextState(State state) noexcept;
175  bool leaveCurrentState() noexcept;
176  bool enterNextState(State state) noexcept;
177  bool switchToPreviousState() noexcept;
178 
179 private: // Data
181  QMap<State, PackageEditorState*> mStates;
184  QScopedPointer<PrimitiveTextGraphicsItem> mSelectFootprintGraphicsItem;
185  QSet<EditorWidgetBase::Feature> mAvailableFeatures;
186 };
187 
188 /*******************************************************************************
189  * End of File
190  ******************************************************************************/
191 
192 } // namespace editor
193 } // namespace librepcb
194 
195 #endif
bool processSnapToGrid() noexcept
Definition: packageeditorfsm.cpp:382
bool processGraphicsSceneLeftMouseButtonPressed(QGraphicsSceneMouseEvent &e) noexcept
Definition: packageeditorfsm.cpp:265
std::shared_ptr< Footprint > currentFootprint
Definition: packageeditorfsm.h:97
PackageEditorWidget & editorWidget
Definition: packageeditorfsm.h:91
bool processStartDrawZones() noexcept
Definition: packageeditorfsm.cpp:491
Definition: packageeditorfsm.h:89
ToolBarProxy & commandToolBar
Definition: packageeditorfsm.h:99
bool processAbortCommand() noexcept
Definition: packageeditorfsm.cpp:423
The PackageEditorWidget class.
Definition: packageeditorwidget.h:65
bool processStartDrawTexts() noexcept
Definition: packageeditorfsm.cpp:487
bool enterNextState(State state) noexcept
Definition: packageeditorfsm.cpp:554
std::shared_ptr< FootprintGraphicsItem > currentGraphicsItem
Definition: packageeditorfsm.h:98
The GraphicsView class.
Definition: graphicsview.h:51
bool processStartAddingFootprintSmtPads(FootprintPad::Function function) noexcept
Definition: packageeditorfsm.cpp:439
bool processStartMeasure() noexcept
Definition: packageeditorfsm.cpp:509
bool processStartDxfImport() noexcept
Definition: packageeditorfsm.cpp:499
Definition: occmodel.cpp:77
QMap< State, PackageEditorState * > mStates
Definition: packageeditorfsm.h:181
bool processStartDrawPolygons() noexcept
Definition: packageeditorfsm.cpp:479
bool processGraphicsSceneLeftMouseButtonDoubleClicked(QGraphicsSceneMouseEvent &e) noexcept
Definition: packageeditorfsm.cpp:285
bool processGraphicsSceneRightMouseButtonReleased(QGraphicsSceneMouseEvent &e) noexcept
Definition: packageeditorfsm.cpp:296
PackageEditorState * getCurrentState() const noexcept
Definition: packageeditorfsm.cpp:517
Tool
Definition: editorwidgetbase.h:76
bool processStartDrawRects() noexcept
Definition: packageeditorfsm.cpp:475
LengthUnit & lengthUnit
Definition: packageeditorfsm.h:95
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
The Package class represents a package of a component (including footprint and 3D model) ...
Definition: package.h:59
bool switchToPreviousState() noexcept
Definition: packageeditorfsm.cpp:568
bool processRotate(const Angle &rotation) noexcept
Definition: packageeditorfsm.cpp:355
State
Definition: packageeditorfsm.h:64
Context mContext
Definition: packageeditorfsm.h:180
The Footprint class represents one footprint variant of a package.
Definition: footprint.h:55
bool processGenerateCourtyard() noexcept
Definition: packageeditorfsm.cpp:415
bool processStartDrawLines() noexcept
Definition: packageeditorfsm.cpp:467
The ToolBarProxy class allows to map a list of QAction&#39;s to one QToolBar.
Definition: toolbarproxy.h:45
EditorWidgetBase::Context & editorContext
Definition: packageeditorfsm.h:90
bool setNextState(State state) noexcept
Definition: packageeditorfsm.cpp:521
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:106
bool processStartSelecting() noexcept
Definition: packageeditorfsm.cpp:431
bool processStartDrawCircles() noexcept
Definition: packageeditorfsm.cpp:483
bool processSelectAll() noexcept
Definition: packageeditorfsm.cpp:314
bool processCopy() noexcept
Definition: packageeditorfsm.cpp:330
bool processKeyPressed(const QKeyEvent &e) noexcept
Definition: packageeditorfsm.cpp:237
bool processStartAddingValues() noexcept
Definition: packageeditorfsm.cpp:463
bool processRemove() noexcept
Definition: packageeditorfsm.cpp:390
UndoStack & undoStack
Definition: packageeditorfsm.h:92
GraphicsScene & graphicsScene
Definition: packageeditorfsm.h:93
bool processEditProperties() noexcept
Definition: packageeditorfsm.cpp:399
std::shared_ptr< Footprint > getCurrentFootprint() const noexcept
Definition: packageeditorfsm.cpp:173
void statusBarMessageChanged(const QString &message, int timeoutMs=-1)
bool processStartAddingFootprintThtPads() noexcept
Definition: packageeditorfsm.cpp:435
The GraphicsScene class.
Definition: graphicsscene.h:45
Function
Definition: footprintpad.h:71
bool processGenerateOutline() noexcept
Definition: packageeditorfsm.cpp:407
bool leaveCurrentState() noexcept
Definition: packageeditorfsm.cpp:537
QSet< EditorWidgetBase::Feature > mAvailableFeatures
Definition: packageeditorfsm.h:185
bool processGraphicsSceneLeftMouseButtonReleased(QGraphicsSceneMouseEvent &e) noexcept
Definition: packageeditorfsm.cpp:275
bool processCut() noexcept
Definition: packageeditorfsm.cpp:322
Package & package
Definition: packageeditorfsm.h:96
State mPreviousState
Definition: packageeditorfsm.h:183
PackageEditorFsm & operator=(const PackageEditorFsm &rhs)=delete
bool processKeyReleased(const QKeyEvent &e) noexcept
Definition: packageeditorfsm.cpp:246
void toolChanged(EditorWidgetBase::Tool newTool)
bool processStartAddingNames() noexcept
Definition: packageeditorfsm.cpp:459
bool processGraphicsSceneMouseMoved(QGraphicsSceneMouseEvent &e) noexcept
Definition: packageeditorfsm.cpp:255
EditorWidgetBase::Tool getCurrentTool() const noexcept
Definition: packageeditorfsm.cpp:129
virtual ~PackageEditorFsm() noexcept
Definition: packageeditorfsm.cpp:119
The PackageEditorFsm class is the finit state machine (FSM) of the package editor.
Definition: packageeditorfsm.h:60
QScopedPointer< PrimitiveTextGraphicsItem > mSelectFootprintGraphicsItem
Definition: packageeditorfsm.h:184
bool processStartAddingHoles() noexcept
Definition: packageeditorfsm.cpp:495
The EditorWidgetBase class.
Definition: editorwidgetbase.h:62
bool processStartDrawArcs() noexcept
Definition: packageeditorfsm.cpp:471
bool processMove(Qt::ArrowType direction) noexcept
Definition: packageeditorfsm.cpp:346
const QSet< EditorWidgetBase::Feature > & getAvailableFeatures() const noexcept
Definition: packageeditorfsm.h:112
bool processFlip(Qt::Orientation orientation) noexcept
Definition: packageeditorfsm.cpp:373
The PackageEditorState class is the base class of all package editor FSM states.
Definition: packageeditorstate.h:52
bool processChangeCurrentFootprint(const std::shared_ptr< Footprint > &fpt) noexcept
Definition: packageeditorfsm.cpp:197
The LengthUnit class represents a length unit (millimeters, inches,...) and provides some useful meth...
Definition: lengthunit.h:60
Definition: editorwidgetbase.h:68
void updateAvailableFeatures() noexcept
Definition: packageeditorfsm.cpp:182
bool processPaste() noexcept
Definition: packageeditorfsm.cpp:338
bool processMirror(Qt::Orientation orientation) noexcept
Definition: packageeditorfsm.cpp:364
GraphicsView & graphicsView
Definition: packageeditorfsm.h:94
State mCurrentState
Definition: packageeditorfsm.h:182