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