QCAD
Open Source 2D CAD
RDocumentInterface.h
Go to the documentation of this file.
1 
20 #ifndef RDOCUMENTINTERFACE_H
21 #define RDOCUMENTINTERFACE_H
22 
23 #include "core_global.h"
24 
25 #include <QKeyEvent>
26 #include <QList>
27 #include <QMap>
28 #include <QMutex>
29 #include <QSharedPointer>
30 #include <QStack>
31 #include <QQueue>
32 #include <QSwipeGesture>
33 #include <QPanGesture>
34 #include <QPinchGesture>
35 
36 #include "RAction.h"
37 #include "RCommandEvent.h"
38 #include "RCoordinateEvent.h"
39 #include "RCoordinateListener.h"
40 #include "RDocument.h"
41 #include "RExporter.h"
42 #include "RLayerListener.h"
43 #include "RStorage.h"
44 #include "RTerminateEvent.h"
45 #include "RTextLabel.h"
46 #include "RUcs.h"
47 
48 #define RDEFAULT_QLIST_QREAL QList<qreal>()
49 #ifndef RDEFAULT_MIN1
50 #define RDEFAULT_MIN1 -1
51 #endif
52 
53 class RGraphicsScene;
54 class RGraphicsView;
55 class RMouseEvent;
56 class ROperation;
57 class RPropertyEvent;
58 class RSnap;
59 class RSnapRestriction;
60 class RScriptHandler;
61 class RTransaction;
62 class RWheelEvent;
63 
64 
65 
84 public:
85  enum IoErrorCode {
113  IoErrorGeneralImportUrlError
114  };
115 
116 public:
117  RDocumentInterface(RDocument& document);
119 
120  void clearCaches();
121 
123  RStorage& getStorage();
124  QList<RGraphicsScene*> getGraphicsScenes();
125  RGraphicsView* getGraphicsViewWithFocus();
126 
127  void addCoordinateListener(RCoordinateListener* l);
128  void notifyCoordinateListeners();
129 
130  void addLayerListener(RLayerListener* l);
131  void removeLayerListener(RLayerListener* l);
132  void notifyLayerListeners();
133 
134  void clear();
135 
139  RScriptHandler* getScriptHandler(const QString& extension);
140  bool isScriptRunning();
141 
142  void setDefaultAction(RAction* action);
143  void setCurrentAction(RAction* action);
144  void terminateCurrentAction();
145  void queueAction(RAction* action);
146  void killAllActions();
147 
148  RAction* getCurrentAction();
149  bool hasCurrentAction() const;
150  RAction* getCurrentStatefulAction();
151  bool hasCurrentStatefulAction() const;
152 
153  void suspend();
154  void resume();
155 
156  void setClickMode(RAction::ClickMode m);
157  RAction::ClickMode getClickMode();
158 
159  void terminateEvent(RTerminateEvent& event);
160 
161  void keyPressEvent(QKeyEvent& event);
162  void keyReleaseEvent(QKeyEvent& event);
163  void mouseMoveEvent(RMouseEvent& event);
164  void mousePressEvent(RMouseEvent& event);
165  void mouseReleaseEvent(RMouseEvent& event);
166  void mouseDoubleClickEvent(RMouseEvent& event);
167  void coordinateEvent(RCoordinateEvent& event);
168  void coordinateEventPreview(RCoordinateEvent& event);
169  void commandEvent(RCommandEvent& event);
170  void commandEventPreview(RCommandEvent& event);
171  void wheelEvent(RWheelEvent& event);
172  void tabletEvent(RTabletEvent& event);
173  void swipeGestureEvent(QSwipeGesture& gesture);
174  void panGestureEvent(QPanGesture& gesture);
175  void pinchGestureEvent(QPinchGesture& gesture);
176 
177  void propertyChangeEvent(RPropertyEvent& event);
178  void ucsSetEvent(const QString& ucsName);
179  void zoomChangeEvent(RGraphicsView& view);
180 
181  void enableUpdates();
182  void disableUpdates();
183 
184  void enableRegeneration();
185  void disableRegeneration();
186 
187  void enableMouseTracking();
188  void disableMouseTracking();
189 
190  void updateAllEntities();
191 
192  void regenerateScenes(bool undone = false);
193  void regenerateScenes(QSet<REntity::Id>& entityIds, bool updateViews);
194  void regenerateScenes(REntity::Id entityId, bool updateViews);
195 
196  void updateSelectionStatus(QSet<REntity::Id>& entityIds, bool updateViews);
197  void updateSelectionStatus(REntity::Id entityId, bool updateViews);
198 
199  void regenerateViews(bool force=false);
200  void regenerateViews(QSet<REntity::Id>& entityIds);
201  void repaintViews();
202 
203  void registerScene(RGraphicsScene& scene);
204  void unregisterScene(RGraphicsScene& scene);
205 
206  void setCursor(const QCursor& cursor, bool global = true);
207 
209  const QUrl& url, const QString& nameFilter = "", bool notify = true);
211  const QString& fileName, const QString& nameFilter = "", bool notify = true);
212 
213  QString getCorrectedFileName(const QString& fileName, const QString& fileVersion);
214  bool exportFile(const QString& fileName, const QString& fileVersion = "", bool resetModified = true);
215 
216  void undo();
217  void redo();
218  void flushTransactions();
219  void flushRedo();
220 
221  void setSnap(RSnap* snap);
222  RSnap* getSnap();
223 
224  void setSnapRestriction(RSnapRestriction* snapRestriction);
225  RSnapRestriction* getSnapRestriction();
226 
227  RVector snap(RMouseEvent& event, bool preview = false);
228 
229  REntity::Id getClosestEntity(RInputEvent& event);
230  REntity::Id getClosestEntity(const RVector& position,
231  double range, double strictRange = RMAXDOUBLE,
232  bool includeLockedLayers = true,
233  bool selectedOnly = false);
234  void highlightEntity(REntity::Id entityId);
235  void highlightReferencePoint(const RRefPoint& position);
236  void selectEntities(const QSet<REntity::Id>& entityIds, bool add = false);
237  void selectEntity(REntity::Id entityId, bool add = false);
238  bool deselectEntities(const QSet<REntity::Id>& entityIds);
239  void deselectEntity(REntity::Id entityId);
240  void selectBoxXY(const RBox& box, bool add = false);
241  void selectAll();
242  void deselectAll();
243  void clearSelection();
244  bool hasSelection();
245 
246  void addZoomBoxToPreview(const RBox& box);
247  void addShapeToPreview(RShape& shape, const RColor& color,
248  const QBrush& brush, RLineweight::Lineweight lineweight,
249  Qt::PenStyle style, const QList<qreal>& dashValues = RDEFAULT_QLIST_QREAL);
250  void addAuxShapeToPreview(RShape& shape);
251  void addEntityToPreview(REntity& entity);
252  void beginPreview();
253  void endPreview();
254  void clearPreview();
255  bool isPreviewEmpty();
256  void keepPreview();
257 
258  void showPropertiesOf(REntity& entity);
259  void clearProperties();
260 
261  void zoomIn();
262  void zoomOut();
263  void autoZoom(int margin = RDEFAULT_MIN1);
264  bool zoomToSelection();
265  void zoomTo(const RBox& region, int margin = 0);
266  void zoomPrevious();
267 
268  void previewOperation(const ROperation* operation);
269  RTransaction applyOperation(const ROperation* operation);
270 
271  void objectChangeEvent(QList<RObject::Id>& objectIds);
272 
273  RVector getRelativeZero() const;
274  RVector getLastPosition() const;
275  void setRelativeZero(const RVector& p);
276 
277  void lockRelativeZero();
278  void unlockRelativeZero();
279  bool isRelativeZeroLocked() const;
280 
281  void lockSnap();
282  void unlockSnap();
283  void toggleSnapLock();
284  bool isSnapLocked() const;
285 
286  RVector getCursorPosition() const;
287  void setCursorPosition(const RVector& p);
288  void setCursorOverride(bool on);
289  bool getCursorOverride() const;
290 
291  void deleteTerminatedActions();
292 
293  void setCurrentColor(const RColor& color);
294  RColor getCurrentColor();
295 
296  void setCurrentLineweight(RLineweight::Lineweight lw);
297  RLineweight::Lineweight getCurrentLineweight();
298 
299  void setCurrentLinetype(RLinetype::Id ltId);
300  void setCurrentLinetypePattern(const RLinetypePattern& p);
301  RLinetype::Id getCurrentLinetypeId();
302  RLinetypePattern getCurrentLinetypePattern();
303 
304  void setCurrentLayer(RLayer::Id layerId);
305  void setCurrentLayer(const RLayer& layer);
306  void setCurrentLayer(const QString& layerName);
307 
308  void setCurrentBlock(const RBlock& block);
309  void setCurrentBlock(const QString& blockName);
310 
311  void setCurrentView(const QString& viewName);
312 
313  void setCurrentUcs(const RUcs& ucs);
314  void setCurrentUcs(const QString& ucsName);
315  RUcs getCurrentUcs();
316  QString getCurrentUcsName();
317 
318  RGraphicsView* getLastKnownViewWithFocus();
319  void setLastKnownViewWithFocus(RGraphicsView* view);
320 
322  static void deleteClipboard();
323  bool isClipboard() {
324  return this==clipboard;
325  }
326  bool isSuspended() {
327  return suspended;
328  }
329  void setNotifyListeners(bool on) {
330  notifyGlobalListeners = on;
331  }
332 
333  bool isDeleting() const {
334  return deleting;
335  }
336 
337  QVariant eval(const QString& ext, const QString& script);
338 
339 private:
340  void handleClickEvent(RAction& action, RMouseEvent& event);
341  void previewClickEvent(RAction& action, RMouseEvent& event);
342 
343 private:
345  QList<RGraphicsScene*> scenes;
347  QMap<QString, RScriptHandler*> scriptHandlers;
348 
350  QStack<RAction*> currentActions;
351  QQueue<RAction*> queuedActions;
352 
353  QList<RCoordinateListener*> coordinateListeners;
354  QList<RLayerListener*> layerListeners;
355 
358 
365  QString currentUcsName;
366  bool suspended;
367 
370 
372 
374  bool deleting;
376 
379 
380  // used to use mouse button press (not release) to define points
381  //RMouseEvent* pressEvent;
382 };
383 
386 
387 #endif
No permissions to read file.
Definition: RDocumentInterface.h:105
Represents a box e.g.
Definition: RBox.h:43
This abstract class is an interface for all operation implementations.
Definition: ROperation.h:44
File size is zero bytes.
Definition: RDocumentInterface.h:97
static RDocumentInterface * clipboard
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RDocumentInterface.h:371
Abstract base class for all grid and object snap implementations.
Definition: RSnap.h:44
QQueue< RAction * > queuedActions
Definition: RDocumentInterface.h:351
bool allowRegeneration
Definition: RDocumentInterface.h:369
bool keepPreviewOnce
Definition: RDocumentInterface.h:377
File not found.
Definition: RDocumentInterface.h:101
bool notifyGlobalListeners
Definition: RDocumentInterface.h:373
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RCommandEvent.h:31
A tablet event for a graphics scene.
Definition: RTabletEvent.h:43
void setNotifyListeners(bool on)
Definition: RDocumentInterface.h:329
Represents a user coordinate system (UCS) in a drawing.
Definition: RUcs.h:41
An input event for a graphics scene.
Definition: RInputEvent.h:41
bool mouseTrackingEnabled
Definition: RDocumentInterface.h:378
QList< RLayerListener * > layerListeners
Definition: RDocumentInterface.h:354
IoErrorCode
Definition: RDocumentInterface.h:85
ClickMode
Current mouse click mode.
Definition: RAction.h:67
RUcs currentUcs
Definition: RDocumentInterface.h:364
Represents a reference point of an entity.
Definition: RRefPoint.h:18
Abstract base class for all graphics scenes.
Definition: RGraphicsScene.h:61
Abstract base class for all snap restriction implementations.
Definition: RSnapRestriction.h:37
Represents a block definition in a drawing.
Definition: RBlock.h:44
No suitable importer was found.
Definition: RDocumentInterface.h:93
#define QCADCORE_EXPORT
Definition: core_global.h:10
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RPropertyEvent.h:40
QMap< QString, RScriptHandler * > scriptHandlers
Definition: RDocumentInterface.h:347
RDocument & document
Definition: RDocumentInterface.h:344
int Id
Definition: RObject.h:57
void getDocument()
Definition: simple.js:60
This is the abstract base class for all storage implementations.
Definition: RStorage.h:62
QString currentUcsName
Definition: RDocumentInterface.h:365
Transaction implementation.
Definition: RTransaction.h:74
Abstract base class for classes that are interested in being notified whenever a layer has been added...
Definition: RLayerListener.h:37
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RLinetypePattern.h:45
RVector cursorPosition
Definition: RDocumentInterface.h:363
bool cursorOverride
Definition: RDocumentInterface.h:375
RSnapRestriction * currentSnapRestriction
Definition: RDocumentInterface.h:357
Lineweight
Definition: RLineweight.h:42
RAction * defaultAction
Definition: RDocumentInterface.h:349
#define RDEFAULT_QLIST_QREAL
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RDocumentInterface.h:48
Color.
Definition: RColor.h:42
bool deleting
Definition: RDocumentInterface.h:374
bool snapLocked
Definition: RDocumentInterface.h:362
RVector relativeZero
Definition: RDocumentInterface.h:360
Abstract base class for all action classes.
Definition: RAction.h:62
Base class for all entity classes.
Definition: REntity.h:64
bool suspended
Definition: RDocumentInterface.h:366
A graphics document contains and owns entities, layers, user coordinate systems, variables, block definitions, etc.
Definition: RDocument.h:67
Q_DECLARE_METATYPE(RMath *)
bool isDeleting() const
Definition: RDocumentInterface.h:333
A mouse event for a graphics scene.
Definition: RMouseEvent.h:42
#define RMAXDOUBLE
Definition: RMath.h:63
RGraphicsView * lastKnownViewWithFocus
Definition: RDocumentInterface.h:346
No error occurred during import or export.
Definition: RDocumentInterface.h:89
void getClipboard()
Definition: library.js:225
#define RDEFAULT_MIN1
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RExplodable.h:30
bool relativeZeroLocked
Definition: RDocumentInterface.h:361
Abstract base class for classes that are interested in the current coordinate of the mouse cursor...
Definition: RCoordinateListener.h:38
QList< RGraphicsScene * > scenes
Definition: RDocumentInterface.h:345
Abstract base class for all script handlers.
Definition: RScriptHandler.h:44
QStack< RAction * > currentActions
Definition: RDocumentInterface.h:350
Interface for interaction between a graphics document and a user.
Definition: RDocumentInterface.h:83
QList< RCoordinateListener * > coordinateListeners
Definition: RDocumentInterface.h:353
Represents a layer in a drawing.
Definition: RLayer.h:48
void autoZoom()
Auto zoom.
Definition: simple_view.js:27
RVector lastPosition
Definition: RDocumentInterface.h:359
Interface for geometrical shape classes.
Definition: RShape.h:52
bool isSuspended()
Definition: RDocumentInterface.h:326
bool allowUpdate
Definition: RDocumentInterface.h:368
General import error, i.e.
Definition: RDocumentInterface.h:109
bool isClipboard()
Definition: RDocumentInterface.h:323
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RTerminateEvent.h:34
void zoomTo(void p1, void p2, void p3, void p4, void p5)
Zooms to the given entity.
Definition: simple_view.js:21
A mouse wheel event for a graphics scene.
Definition: RWheelEvent.h:41
RSnap * currentSnap
Definition: RDocumentInterface.h:356
Coordinate Event.
Definition: RCoordinateEvent.h:37
Graphics view.
Definition: RGraphicsView.h:58