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