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