LibrePCB Developers Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
boardeditorevent.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_PROJECT_BOARDEDITOREVENT_H
21 #define LIBREPCB_PROJECT_BOARDEDITOREVENT_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include <librepcb/common/uuid.h>
27 
28 #include <QtCore>
29 
30 /*******************************************************************************
31  * Namespace / Forward Declarations
32  ******************************************************************************/
33 namespace librepcb {
34 namespace project {
35 
36 class Project;
37 class Board;
38 class ComponentInstance;
39 
40 namespace editor {
41 
42 class BoardEditor;
43 
44 namespace Ui {
45 class BoardEditor;
46 }
47 
48 /*******************************************************************************
49  * Class BEE_Base
50  ******************************************************************************/
51 
55 class BEE_Base {
56 public:
58  enum EventType_t {
59  // Triggered Actions (SEE_Base objects, no additional parameters)
62  // StartMove, ///< start command: move elements
65  // StartDrawRect, ///< start command: draw rect
67  // StartDrawCircle, ///< start command: draw circle
71  // StartAddNetLabel, ///< start command: add netlabel
80  // Redirected QEvent's (SEE_RedirectedQEvent objects, with pointer to a
81  // QEvent)
83  // Special Events (with some additional parameters)
86  // SwitchToSchematicPage, ///< @see #project#SEE_SwitchToSchematicPage
87  };
88 
89  // Constructors / Destructor
90  BEE_Base(EventType_t type);
91  virtual ~BEE_Base();
92 
93  // Getters
94  EventType_t getType() const noexcept { return mType; }
95  bool isAccepted() const noexcept { return mAccepted; }
96 
97  // Setters
98  virtual void setAccepted(bool accepted) noexcept { mAccepted = accepted; }
99 
100 protected:
102  bool mAccepted;
103 };
104 
105 /*******************************************************************************
106  * Class BEE_RedirectedQEvent
107  ******************************************************************************/
108 
112 class BEE_RedirectedQEvent final : public BEE_Base {
113 public:
114  // Constructors / Destructor
115  BEE_RedirectedQEvent(EventType_t type, QEvent* event)
116  : BEE_Base(type), mQEvent(event) {}
118 
119  // Getters
120  QEvent* getQEvent() const noexcept { return mQEvent; }
121 
122  // Setters
123  void setAccepted(bool accepted) noexcept {
124  mQEvent->setAccepted(accepted);
125  BEE_Base::setAccepted(accepted);
126  }
127 
128  // Static Methods
129 
137  static QEvent* getQEventFromBEE(const BEE_Base* bee) noexcept {
138  const BEE_RedirectedQEvent* r =
139  dynamic_cast<const BEE_RedirectedQEvent*>(bee);
140  return (r ? r->getQEvent() : nullptr);
141  }
142 
143 private:
144  QEvent* mQEvent;
145 };
146 
147 /*******************************************************************************
148  * Class BEE_StartAddDevice
149  ******************************************************************************/
150 
156 class BEE_StartAddDevice final : public BEE_Base {
157 public:
158  // Constructors / Destructor
159  BEE_StartAddDevice() = delete;
160  BEE_StartAddDevice(const BEE_StartAddDevice& other) = delete;
161  BEE_StartAddDevice(ComponentInstance& cmp, const Uuid& dev, const Uuid& fpt);
163 
164  // Getters
166  return mComponentInstance;
167  }
168  const Uuid& getDeviceUuid() const noexcept { return mDeviceUuid; }
169  const Uuid& getFootprintUuid() const noexcept { return mFootprintUuid; }
170 
171 private:
175 };
176 
177 /*******************************************************************************
178  * End of File
179  ******************************************************************************/
180 
181 } // namespace editor
182 } // namespace project
183 } // namespace librepcb
184 
185 #endif // LIBREPCB_PROJECT_BOARDEDITOREVENT_H
cut the selected elements (ctrl+x)
Definition: boardeditorevent.h:73
Uuid mFootprintUuid
Definition: boardeditorevent.h:174
flip the selected elements vertical (Shift+f)
Definition: boardeditorevent.h:78
paste the elements from the clipboard (ctrl+v)
Definition: boardeditorevent.h:74
QEvent * getQEvent() const noexcept
Definition: boardeditorevent.h:120
start command: draw trace
Definition: boardeditorevent.h:69
remove the selected elements
Definition: boardeditorevent.h:79
Uuid mDeviceUuid
Definition: boardeditorevent.h:173
start command: draw polygon
Definition: boardeditorevent.h:66
copy the selected elements to clipboard (ctrl+c)
Definition: boardeditorevent.h:72
virtual void setAccepted(bool accepted) noexcept
Definition: boardeditorevent.h:98
const Uuid & getFootprintUuid() const noexcept
Definition: boardeditorevent.h:169
start command: add via
Definition: boardeditorevent.h:70
rotate the selected elements 90° CCW (r)
Definition: boardeditorevent.h:75
The BEE_RedirectedQEvent class.
Definition: boardeditorevent.h:112
BEE_Base(EventType_t type)
Definition: boardeditorevent.cpp:41
The BEE_StartAddDevice class.
Definition: boardeditorevent.h:156
bool mAccepted
Definition: boardeditorevent.h:102
EventType_t
FSM event types.
Definition: boardeditorevent.h:58
ComponentInstance & getComponentInstance() const noexcept
Definition: boardeditorevent.h:165
start command: draw plane
Definition: boardeditorevent.h:68
abort the currently active command (esc)
Definition: boardeditorevent.h:60
~BEE_StartAddDevice()
Definition: boardeditorevent.cpp:59
start command: select elements
Definition: boardeditorevent.h:61
bool isAccepted() const noexcept
Definition: boardeditorevent.h:95
QEvent * mQEvent
Definition: boardeditorevent.h:144
EventType_t mType
Definition: boardeditorevent.h:101
const Uuid & getDeviceUuid() const noexcept
Definition: boardeditorevent.h:168
static QEvent * getQEventFromBEE(const BEE_Base *bee) noexcept
Helper method to get the QEvent from a pointer to BEE_Base.
Definition: boardeditorevent.h:137
flip the selected elements horizontal (f)
Definition: boardeditorevent.h:77
rotate the selected elements 90° CW (Shift+r)
Definition: boardeditorevent.h:76
EventType_t getType() const noexcept
Definition: boardeditorevent.h:94
virtual ~BEE_RedirectedQEvent()
Definition: boardeditorevent.h:117
start command: add hole
Definition: boardeditorevent.h:64
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
ComponentInstance & mComponentInstance
Definition: boardeditorevent.h:172
virtual ~BEE_Base()
Definition: boardeditorevent.cpp:44
The ComponentInstance class.
Definition: componentinstance.h:64
start command: add stroke text
Definition: boardeditorevent.h:63
BEE_RedirectedQEvent(EventType_t type, QEvent *event)
Definition: boardeditorevent.h:115
The BEE_Base (Board Editor Event Base) class.
Definition: boardeditorevent.h:55
void setAccepted(bool accepted) noexcept
Definition: boardeditorevent.h:123