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