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 ******************************************************************************/
37namespace librepcb {
38
39class Footprint;
40class Package;
41
42namespace editor {
43
44class FootprintGraphicsItem;
45class GraphicsScene;
46class GraphicsView;
47class PackageEditorState;
48class PackageEditorWidget;
49class PrimitiveTextGraphicsItem;
50class UndoStack;
51
52/*******************************************************************************
53 * Class PackageEditorFsm
54 ******************************************************************************/
55
60class PackageEditorFsm final : public QObject {
61 Q_OBJECT
62
63private: // Types
64 enum class State {
65 IDLE,
66 SELECT,
67 ADD_THT_PADS,
68 ADD_SMT_PADS_STANDARD,
69 ADD_SMT_PADS_THERMAL,
70 ADD_SMT_PADS_BGA,
71 ADD_SMT_PADS_EDGE_CONNECTOR,
72 ADD_SMT_PADS_TEST,
73 ADD_SMT_PADS_LOCAL_FIDUCIAL,
74 ADD_SMT_PADS_GLOBAL_FIDUCIAL,
75 ADD_NAMES,
76 ADD_VALUES,
77 DRAW_LINE,
78 DRAW_ARC,
79 DRAW_RECT,
80 DRAW_POLYGON,
81 DRAW_CIRCLE,
82 DRAW_TEXT,
83 DRAW_ZONE,
84 ADD_HOLES,
85 MEASURE,
86 };
87
88public: // Types
89 struct Context {
97 std::shared_ptr<Footprint> currentFootprint;
98 std::shared_ptr<FootprintGraphicsItem> currentGraphicsItem;
100 };
101
102public:
103 // Constructors / Destructor
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;
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
167signals:
168 void toolChanged(EditorWidgetBase::Tool newTool);
170 void statusBarMessageChanged(const QString& message, int timeoutMs = -1);
171
172private: // 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
179private: // Data
186};
187
188/*******************************************************************************
189 * End of File
190 ******************************************************************************/
191
192} // namespace editor
193} // namespace librepcb
194
195#endif
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
The Footprint class represents one footprint variant of a package.
Definition: footprint.h:55
The FootprintPad class represents a pad of a footprint.
Definition: footprintpad.h:55
The LengthUnit class represents a length unit (millimeters, inches,...) and provides some useful meth...
Definition: lengthunit.h:60
The Package class represents a package of a component (including footprint and 3D model)
Definition: package.h:59
The EditorWidgetBase class.
Definition: editorwidgetbase.h:62
The GraphicsScene class.
Definition: graphicsscene.h:45
The GraphicsView class.
Definition: graphicsview.h:51
The PackageEditorFsm class is the finit state machine (FSM) of the package editor.
Definition: packageeditorfsm.h:60
Context mContext
Definition: packageeditorfsm.h:180
bool processGraphicsSceneRightMouseButtonReleased(QGraphicsSceneMouseEvent &e) noexcept
Definition: packageeditorfsm.cpp:296
bool processKeyReleased(const QKeyEvent &e) noexcept
Definition: packageeditorfsm.cpp:246
bool processStartAddingNames() noexcept
Definition: packageeditorfsm.cpp:459
bool processStartAddingHoles() noexcept
Definition: packageeditorfsm.cpp:495
bool setNextState(State state) noexcept
Definition: packageeditorfsm.cpp:521
bool processStartAddingValues() noexcept
Definition: packageeditorfsm.cpp:463
bool processKeyPressed(const QKeyEvent &e) noexcept
Definition: packageeditorfsm.cpp:237
bool processGraphicsSceneLeftMouseButtonDoubleClicked(QGraphicsSceneMouseEvent &e) noexcept
Definition: packageeditorfsm.cpp:285
void statusBarMessageChanged(const QString &message, int timeoutMs=-1)
PackageEditorState * getCurrentState() const noexcept
Definition: packageeditorfsm.cpp:517
bool processChangeCurrentFootprint(const std::shared_ptr< Footprint > &fpt) noexcept
Definition: packageeditorfsm.cpp:197
EditorWidgetBase::Tool getCurrentTool() const noexcept
Definition: packageeditorfsm.cpp:129
bool processStartSelecting() noexcept
Definition: packageeditorfsm.cpp:431
bool processStartDrawLines() noexcept
Definition: packageeditorfsm.cpp:467
bool processSelectAll() noexcept
Definition: packageeditorfsm.cpp:314
bool processStartDrawRects() noexcept
Definition: packageeditorfsm.cpp:475
bool processRemove() noexcept
Definition: packageeditorfsm.cpp:390
QSet< EditorWidgetBase::Feature > mAvailableFeatures
Definition: packageeditorfsm.h:185
bool processCopy() noexcept
Definition: packageeditorfsm.cpp:330
bool processStartAddingFootprintSmtPads(FootprintPad::Function function) noexcept
Definition: packageeditorfsm.cpp:439
bool processEditProperties() noexcept
Definition: packageeditorfsm.cpp:399
State mPreviousState
Definition: packageeditorfsm.h:183
State
Definition: packageeditorfsm.h:64
bool processCut() noexcept
Definition: packageeditorfsm.cpp:322
QMap< State, PackageEditorState * > mStates
Definition: packageeditorfsm.h:181
bool leaveCurrentState() noexcept
Definition: packageeditorfsm.cpp:537
bool switchToPreviousState() noexcept
Definition: packageeditorfsm.cpp:568
bool processStartDrawTexts() noexcept
Definition: packageeditorfsm.cpp:487
bool processStartDxfImport() noexcept
Definition: packageeditorfsm.cpp:499
bool processGenerateOutline() noexcept
Definition: packageeditorfsm.cpp:407
bool processAbortCommand() noexcept
Definition: packageeditorfsm.cpp:423
bool processFlip(Qt::Orientation orientation) noexcept
Definition: packageeditorfsm.cpp:373
void toolChanged(EditorWidgetBase::Tool newTool)
QScopedPointer< PrimitiveTextGraphicsItem > mSelectFootprintGraphicsItem
Definition: packageeditorfsm.h:184
bool processGraphicsSceneLeftMouseButtonReleased(QGraphicsSceneMouseEvent &e) noexcept
Definition: packageeditorfsm.cpp:275
bool processGraphicsSceneLeftMouseButtonPressed(QGraphicsSceneMouseEvent &e) noexcept
Definition: packageeditorfsm.cpp:265
bool processStartDrawCircles() noexcept
Definition: packageeditorfsm.cpp:483
void updateAvailableFeatures() noexcept
Definition: packageeditorfsm.cpp:182
bool enterNextState(State state) noexcept
Definition: packageeditorfsm.cpp:554
State mCurrentState
Definition: packageeditorfsm.h:182
bool processGraphicsSceneMouseMoved(QGraphicsSceneMouseEvent &e) noexcept
Definition: packageeditorfsm.cpp:255
bool processRotate(const Angle &rotation) noexcept
Definition: packageeditorfsm.cpp:355
const QSet< EditorWidgetBase::Feature > & getAvailableFeatures() const noexcept
Definition: packageeditorfsm.h:112
bool processStartMeasure() noexcept
Definition: packageeditorfsm.cpp:509
PackageEditorFsm(const PackageEditorFsm &other)=delete
std::shared_ptr< Footprint > getCurrentFootprint() const noexcept
Definition: packageeditorfsm.cpp:173
virtual ~PackageEditorFsm() noexcept
Definition: packageeditorfsm.cpp:119
bool processStartDrawZones() noexcept
Definition: packageeditorfsm.cpp:491
bool processGenerateCourtyard() noexcept
Definition: packageeditorfsm.cpp:415
bool processMirror(Qt::Orientation orientation) noexcept
Definition: packageeditorfsm.cpp:364
bool processStartDrawArcs() noexcept
Definition: packageeditorfsm.cpp:471
bool processStartAddingFootprintThtPads() noexcept
Definition: packageeditorfsm.cpp:435
bool processStartDrawPolygons() noexcept
Definition: packageeditorfsm.cpp:479
bool processMove(Qt::ArrowType direction) noexcept
Definition: packageeditorfsm.cpp:346
bool processPaste() noexcept
Definition: packageeditorfsm.cpp:338
bool processSnapToGrid() noexcept
Definition: packageeditorfsm.cpp:382
The PackageEditorState class is the base class of all package editor FSM states.
Definition: packageeditorstate.h:52
The PackageEditorWidget class.
Definition: packageeditorwidget.h:66
The PrimitiveTextGraphicsItem class is the graphical representation of a text.
Definition: primitivetextgraphicsitem.h:52
The ToolBarProxy class allows to map a list of QAction's to one QToolBar.
Definition: toolbarproxy.h:45
The UndoStack class holds UndoCommand objects and provides undo/redo commands.
Definition: undostack.h:106
Definition: occmodel.cpp:77
Definition: editorwidgetbase.h:68
Definition: packageeditorfsm.h:89
LengthUnit & lengthUnit
Definition: packageeditorfsm.h:95
PackageEditorWidget & editorWidget
Definition: packageeditorfsm.h:91
Package & package
Definition: packageeditorfsm.h:96
GraphicsView & graphicsView
Definition: packageeditorfsm.h:94
std::shared_ptr< FootprintGraphicsItem > currentGraphicsItem
Definition: packageeditorfsm.h:98
ToolBarProxy & commandToolBar
Definition: packageeditorfsm.h:99
GraphicsScene & graphicsScene
Definition: packageeditorfsm.h:93
EditorWidgetBase::Context & editorContext
Definition: packageeditorfsm.h:90
std::shared_ptr< Footprint > currentFootprint
Definition: packageeditorfsm.h:97
UndoStack & undoStack
Definition: packageeditorfsm.h:92