LibrePCB Developers Documentation
schematiceditorstate.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_SCHEMATICEDITORSTATE_H
21 #define LIBREPCB_EDITOR_SCHEMATICEDITORSTATE_H
22 
23 /*******************************************************************************
24  * Includes
25  ******************************************************************************/
26 #include "schematiceditorfsm.h"
27 
29 
30 #include <QtCore>
31 #include <QtWidgets>
32 
33 #include <memory>
34 
35 /*******************************************************************************
36  * Namespace / Forward Declarations
37  ******************************************************************************/
38 namespace librepcb {
39 
40 class Layer;
41 class LengthUnit;
42 class Point;
43 class Schematic;
44 
45 namespace editor {
46 
47 class SchematicGraphicsScene;
48 class UndoCommand;
49 
50 /*******************************************************************************
51  * Class SchematicEditorState
52  ******************************************************************************/
53 
57 class SchematicEditorState : public QObject {
58  Q_OBJECT
59 
60 public:
62 
63  enum class FindFlag {
64  // Item types
65  NetPoints = (1 << 0),
66  NetLines = (1 << 1),
67  NetLabels = (1 << 2),
68  Symbols = (1 << 3),
69  SymbolPins = (1 << 4),
70  SymbolPinsWithComponentSignal = (1 << 5), // Subset of SymbolPins.
71  Polygons = (1 << 6),
72  Texts = (1 << 7),
74  Texts,
75 
76  // Match behavior
77  AcceptNearMatch = (1 << 10),
78  AcceptNearestWithinGrid = (1 << 11),
79 
80  // Performance options
81  SkipLowerPriorityMatches = (1 << 15),
82  };
83  Q_DECLARE_FLAGS(FindFlags, FindFlag)
84 
85  // Constructors / Destructor
86  SchematicEditorState() = delete;
87  SchematicEditorState(const SchematicEditorState& other) = delete;
88  explicit SchematicEditorState(const Context& context,
89  QObject* parent = nullptr) noexcept;
90  virtual ~SchematicEditorState() noexcept;
91 
92  // General Methods
93  virtual bool entry() noexcept { return true; }
94  virtual bool exit() noexcept { return true; }
95 
96  // Event Handlers
97  virtual bool processAddComponent(
98  const QString& searchTerm = QString()) noexcept {
99  Q_UNUSED(searchTerm);
100  return false;
101  }
102  virtual bool processAddComponent(const Uuid& cmp,
103  const Uuid& symbVar) noexcept {
104  Q_UNUSED(cmp);
105  Q_UNUSED(symbVar);
106  return false;
107  }
108  virtual bool processSelectAll() noexcept { return false; }
109  virtual bool processCut() noexcept { return false; }
110  virtual bool processCopy() noexcept { return false; }
111  virtual bool processPaste() noexcept { return false; }
112  virtual bool processMove(const Point& delta) noexcept {
113  Q_UNUSED(delta);
114  return false;
115  }
116  virtual bool processRotate(const Angle& rotation) noexcept {
117  Q_UNUSED(rotation);
118  return false;
119  }
120  virtual bool processMirror(Qt::Orientation orientation) noexcept {
121  Q_UNUSED(orientation);
122  return false;
123  }
124  virtual bool processResetAllTexts() noexcept { return false; }
125  virtual bool processRemove() noexcept { return false; }
126  virtual bool processEditProperties() noexcept { return false; }
127  virtual bool processAbortCommand() noexcept { return false; }
128  virtual bool processKeyPressed(const QKeyEvent& e) noexcept {
129  Q_UNUSED(e);
130  return false;
131  }
132  virtual bool processKeyReleased(const QKeyEvent& e) noexcept {
133  Q_UNUSED(e);
134  return false;
135  }
137  QGraphicsSceneMouseEvent& e) noexcept {
138  Q_UNUSED(e);
139  return false;
140  }
142  QGraphicsSceneMouseEvent& e) noexcept {
143  Q_UNUSED(e);
144  return false;
145  }
147  QGraphicsSceneMouseEvent& e) noexcept {
148  Q_UNUSED(e);
149  return false;
150  }
152  QGraphicsSceneMouseEvent& e) noexcept {
153  Q_UNUSED(e);
154  return false;
155  }
157  QGraphicsSceneMouseEvent& e) noexcept {
158  Q_UNUSED(e);
159  return false;
160  }
161  virtual bool processSwitchToSchematicPage(int index) noexcept {
162  Q_UNUSED(index);
163  return false; // Do NOT allow switching page by default
164  }
165 
166  // Operator Overloadings
168 
169 signals:
170  void statusBarMessageChanged(const QString& message, int timeoutMs = -1);
171 
172 protected: // Methods
173  Schematic* getActiveSchematic() noexcept;
175  PositiveLength getGridInterval() const noexcept;
176  const LengthUnit& getLengthUnit() const noexcept;
177  static const QSet<const Layer*>& getAllowedGeometryLayers() noexcept;
178  void abortBlockingToolsInOtherEditors() noexcept;
179  bool execCmd(UndoCommand* cmd);
180  QWidget* parentWidget() noexcept;
181  QList<std::shared_ptr<QGraphicsItem>> findItemsAtPos(
182  const Point& pos, FindFlags flags,
183  const QVector<std::shared_ptr<QGraphicsItem>>& except = {}) noexcept;
184  template <typename T = QGraphicsItem>
185  std::shared_ptr<T> findItemAtPos(
186  const Point& pos, FindFlags flags,
187  const QVector<std::shared_ptr<QGraphicsItem>>& except = {}) noexcept {
188  const QList<std::shared_ptr<QGraphicsItem>> items =
190  std::shared_ptr<T> castedItem =
191  std::dynamic_pointer_cast<T>(items.value(0, nullptr));
192  if ((!items.isEmpty()) && (!castedItem)) {
193  // Probably wrong flags are passed?!?!
194  qCritical() << "Found a schematic item, but it has the wrong type!";
195  }
196  return castedItem;
197  }
198 
199 protected: // Data
201 };
202 
203 } // namespace editor
204 } // namespace librepcb
205 
206 Q_DECLARE_OPERATORS_FOR_FLAGS(librepcb::editor::SchematicEditorState::FindFlags)
207 
208 /*******************************************************************************
209  * End of File
210  ******************************************************************************/
211 
212 #endif
virtual ~SchematicEditorState() noexcept
Definition: schematiceditorstate.cpp:69
static const QSet< const Layer * > & getAllowedGeometryLayers() noexcept
Definition: schematiceditorstate.cpp:99
The schematic editor state base class.
Definition: schematiceditorstate.h:57
Schematic * getActiveSchematic() noexcept
Definition: schematiceditorstate.cpp:76
virtual bool processPaste() noexcept
Definition: schematiceditorstate.h:111
Context mContext
Definition: schematiceditorstate.h:200
Definition: occmodel.cpp:77
PositiveLength getGridInterval() const noexcept
Definition: schematiceditorstate.cpp:85
FindFlag
Definition: schematiceditorstate.h:63
virtual bool processAbortCommand() noexcept
Definition: schematiceditorstate.h:127
virtual bool processEditProperties() noexcept
Definition: schematiceditorstate.h:126
virtual bool processCut() noexcept
Definition: schematiceditorstate.h:109
The Angle class is used to represent an angle (for example 12.75 degrees)
Definition: angle.h:78
virtual bool processKeyPressed(const QKeyEvent &e) noexcept
Definition: schematiceditorstate.h:128
SchematicEditorState & operator=(const SchematicEditorState &rhs)=delete
std::shared_ptr< T > findItemAtPos(const Point &pos, FindFlags flags, const QVector< std::shared_ptr< QGraphicsItem >> &except={}) noexcept
Definition: schematiceditorstate.h:185
const LengthUnit & getLengthUnit() const noexcept
Definition: schematiceditorstate.cpp:89
The SchematicGraphicsScene class.
Definition: schematicgraphicsscene.h:67
virtual bool processResetAllTexts() noexcept
Definition: schematiceditorstate.h:124
The Schematic class represents one schematic page of a project and is always part of a circuit...
Definition: schematic.h:74
The Point class is used to represent a point/coordinate/vector, for example (1.2mm; 5...
Definition: point.h:79
virtual bool processGraphicsSceneLeftMouseButtonPressed(QGraphicsSceneMouseEvent &e) noexcept
Definition: schematiceditorstate.h:141
virtual bool processSelectAll() noexcept
Definition: schematiceditorstate.h:108
The UndoCommand class represents a command which you can undo/redo.
Definition: undocommand.h:46
void statusBarMessageChanged(const QString &message, int timeoutMs=-1)
virtual bool processGraphicsSceneLeftMouseButtonDoubleClicked(QGraphicsSceneMouseEvent &e) noexcept
Definition: schematiceditorstate.h:151
QList< std::shared_ptr< QGraphicsItem > > findItemsAtPos(const Point &pos, FindFlags flags, const QVector< std::shared_ptr< QGraphicsItem >> &except={}) noexcept
Definition: schematiceditorstate.cpp:125
virtual bool processMirror(Qt::Orientation orientation) noexcept
Definition: schematiceditorstate.h:120
FSM Context.
Definition: schematiceditorfsm.h:81
virtual bool processRotate(const Angle &rotation) noexcept
Definition: schematiceditorstate.h:116
bool execCmd(UndoCommand *cmd)
Definition: schematiceditorstate.cpp:117
virtual bool processAddComponent(const QString &searchTerm=QString()) noexcept
Definition: schematiceditorstate.h:97
virtual bool exit() noexcept
Definition: schematiceditorstate.h:94
virtual bool processAddComponent(const Uuid &cmp, const Uuid &symbVar) noexcept
Definition: schematiceditorstate.h:102
virtual bool processGraphicsSceneLeftMouseButtonReleased(QGraphicsSceneMouseEvent &e) noexcept
Definition: schematiceditorstate.h:146
type_safe::constrained_type< Length, PositiveLengthConstraint, PositiveLengthVerifier > PositiveLength
Definition: length.h:812
virtual bool processKeyReleased(const QKeyEvent &e) noexcept
Definition: schematiceditorstate.h:132
virtual bool processGraphicsSceneRightMouseButtonReleased(QGraphicsSceneMouseEvent &e) noexcept
Definition: schematiceditorstate.h:156
virtual bool processRemove() noexcept
Definition: schematiceditorstate.h:125
virtual bool processGraphicsSceneMouseMoved(QGraphicsSceneMouseEvent &e) noexcept
Definition: schematiceditorstate.h:136
The Uuid class is a replacement for QUuid to get UUID strings without {} braces.
Definition: uuid.h:58
SchematicGraphicsScene * getActiveSchematicScene() noexcept
Definition: schematiceditorstate.cpp:81
virtual bool entry() noexcept
Definition: schematiceditorstate.h:93
virtual bool processSwitchToSchematicPage(int index) noexcept
Definition: schematiceditorstate.h:161
The LengthUnit class represents a length unit (millimeters, inches,...) and provides some useful meth...
Definition: lengthunit.h:60
QWidget * parentWidget() noexcept
Definition: schematiceditorstate.cpp:121
virtual bool processMove(const Point &delta) noexcept
Definition: schematiceditorstate.h:112
virtual bool processCopy() noexcept
Definition: schematiceditorstate.h:110
void abortBlockingToolsInOtherEditors() noexcept
Definition: schematiceditorstate.cpp:113