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