QCAD
Open Source 2D CAD
RExporter.h
Go to the documentation of this file.
1 
20 #ifndef REXPORTER_H
21 #define REXPORTER_H
22 
23 #include <stdint.h>
24 
25 #include "core_global.h"
26 
27 #include <QBrush>
28 #include <QColor>
29 #include <QPen>
30 #include <QStack>
31 #include <QTextLayout>
32 
33 #include "REntity.h"
34 #include "RImageData.h"
35 #include "RMatrix.h"
36 #include "RPainterPath.h"
37 #include "RTextBasedData.h"
38 #include "RView.h"
39 #include "RViewportEntity.h"
40 
41 class RArc;
42 class RCircle;
43 class RDocument;
44 class REllipse;
45 class RLine;
46 class RLinetype;
47 class RLinetypePattern;
48 class RMessageHandler;
49 class RPainterPathSource;
50 class RPoint;
51 class RPolyline;
52 class RProgressHandler;
53 class RRay;
54 class RSpline;
55 class RTriangle;
56 class RVector;
57 class RXLine;
58 
59 #ifndef RDEFAULT_MIN1
60 #define RDEFAULT_MIN1 -1
61 #endif
62 
72 
73 public:
74  RExporter();
75  RExporter(RDocument& document, RMessageHandler* messageHandler = NULL, RProgressHandler* progressHandler = NULL);
76  virtual ~RExporter();
77 
78  QString getErrorMessage() const;
79 
80  void setLayerSource(RDocument* ls);
81  void setBlockSource(RDocument* bs);
82 
86  RDocument& getDocument() const;
87 
88  void setProjectionRenderingHint(RS::ProjectionRenderingHint p);
89  RS::ProjectionRenderingHint getProjectionRenderingHint();
90 
91  //virtual RBox getClipRectangle() const;
92  void setClipping(bool on);
93  bool getClipping() const;
94 
95  virtual void setPen(const QPen& pen);
96  virtual QPen getPen(const RPainterPath& path);
97  virtual QPen getPen();
98  virtual void setBrush(const QBrush& brush);
99  virtual QBrush getBrush(const RPainterPath& path);
100  virtual QBrush getBrush();
101 
102  virtual RColor getColor(bool resolve);
103 
104  virtual void setEntityAttributes(bool forceSelected=false);
105 
106  virtual void setStyle(Qt::PenStyle penStyle);
107  virtual void setBrushStyle(Qt::BrushStyle brushStyle);
108  virtual void setDashPattern(const QVector<qreal>& dashes);
109 
110  virtual void setColor(float r, float g, float b, float a = 1.0f);
111  virtual void setColor(const RColor& color);
112 
113  virtual void setLineweight(RLineweight::Lineweight weight);
114 
115  virtual void setLinetypeId(RLinetype::Id ltId);
116  virtual void setLinetypePattern(const RLinetypePattern& ltPattern);
117  virtual RLinetypePattern getLinetypePattern();
118 
119  virtual REntity* getBlockRefOrEntity();
120  virtual REntity::Id getBlockRefOrEntityId();
121  virtual REntity* getEntity();
122  virtual REntity* getCurrentBlockRef() const;
123  virtual RViewportEntity* getCurrentViewport() const;
124  virtual QStack<REntity*> getBlockRefViewportStack() const;
125 
129  virtual const REntity* getEntity() const;
130 
131  virtual bool isEntitySelected();
132 
133  virtual void startExport();
134  virtual void endExport();
135 
136  virtual bool exportDocument();
137  virtual bool exportDocumentSettings();
138  virtual void exportDocumentSetting(const QString& key, const QVariant& value, const QString& dictionaryName = "QCAD_OBJECTS");
139 
140  virtual void exportIntListWithName(const QString& dictionaryName, const QString& name, const QString& listName, QList<int64_t>& values);
141 
142  virtual void exportLayers();
143  virtual void exportBlocks();
144  virtual void exportViews();
145  virtual void exportLinetypes();
146 
147  virtual void exportLayer(RLayer& /*layer*/) {}
148  virtual void exportLayer(RLayer::Id layerId);
149  virtual void exportBlock(RBlock& /*block*/) {}
150  virtual void exportBlock(RBlock::Id blockId);
151  virtual void exportView(RView& /*view*/) {}
152  virtual void exportView(RView::Id viewId);
153  virtual void exportLinetype(RLinetype& /*linetype*/) {}
154 
155  virtual void exportEntities(bool allBlocks = true, bool undone = false);
156  virtual void exportEntities(const RBox& box);
157  virtual void exportEntities(QSet<REntity::Id>& entityIds, bool allBlocks = true);
158  virtual void exportEntity(REntity& entity, bool preview = false, bool allBlocks = true, bool forceSelected = false);
159  virtual void exportEntity(REntity::Id entityId, bool allBlocks = true, bool forceSelected = false);
160  virtual QSharedPointer<RLayer> getEntityLayer(REntity& entity);
161  virtual bool isVisible(REntity& entity);
162  virtual void startEntity(bool /*topLevelEntity*/) {}
163  virtual void endEntity() {}
164  virtual void exportCurrentEntity(bool preview = false, bool forceSelected = false);
165  virtual void unexportEntity(REntity::Id entityId);
166 
167  virtual void exportShapes(const QList<QSharedPointer<RShape> >& shapes);
168  virtual void exportShape(QSharedPointer<RShape> shape);
169  virtual void exportShapeSegment(QSharedPointer<RShape> shape, double angle);
170 
174  virtual double exportLine(const RLine& line, double offset = RNANDOUBLE);
175 
179  virtual bool exportLinetypeShape(QList<RPainterPath>& pps, const RLine& line, double total, double length, double angle, const RVector& cursor);
180 
186  virtual void exportLineSegment(const RLine& line, double angle = RNANDOUBLE) = 0;
187 
191  virtual void exportXLine(const RXLine& xLine) = 0;
192 
196  virtual void exportRay(const RRay& ray) = 0;
197 
201  virtual void exportPoint(const RPoint& point) = 0;
202 
203  virtual void exportCircle(const RCircle& circle);
204 
205  virtual void exportArc(const RArc& arc, double offset = RNANDOUBLE);
206 
207  virtual void exportArcSegment(const RArc& arc, bool allowForZeroLength = false);
208 
209  virtual void exportEllipse(const REllipse& ellipse, double offset = RNANDOUBLE);
210 
211  virtual void exportPolyline(const RPolyline& polyline, bool polylineGen = true, double offset = RNANDOUBLE);
212 
213  virtual void exportSpline(const RSpline& spline, double offset = RNANDOUBLE);
214 
215  virtual void exportSplineSegment(const RSpline& spline);
216 
220  virtual void exportExplodable(const RExplodable& explodable, double offset = RNANDOUBLE);
221 
225  virtual void exportPainterPathSource(const RPainterPathSource& pathSource);
226 
227  virtual void exportPainterPaths(const QList<RPainterPath>& paths);
228  virtual void exportPainterPaths(const QList<RPainterPath>& paths, double angle, const RVector& pos);
229 
230  virtual void exportBoundingBoxPaths(const QList<RPainterPath>& paths);
231 
232  virtual void exportImage(const RImageData& image, bool forceSelected = false);
233  virtual QList<RPainterPath> exportText(const RTextBasedData& text, bool forceSelected = false);
234  virtual void exportClipRectangle(const RBox& clipRectangle, bool forceSelected = false);
235 
236  virtual void exportThickPolyline(const RPolyline& polyline) {
237  RPolyline pl = polyline;
238  pl.stripWidths();
239  exportPolyline(pl);
240  }
241 
242 // virtual void exportThickLine(const RLine& line, double w1, double w2) {
243 // Q_UNUSED(w1)
244 // Q_UNUSED(w2)
245 // exportLineSegment(line);
246 // }
247 
248 // virtual void exportThickArc(const RArc& arc, double w1, double w2) {
249 // Q_UNUSED(w1)
250 // Q_UNUSED(w2)
251 // exportArcSegment(arc);
252 // }
253 
254  virtual void exportQuad(
255  const RVector& p1,
256  const RVector& p2,
257  const RVector& p3,
258  const RVector& p4
259  );
260 
261  virtual void exportVerticalQuad(
262  const RVector& p1,
263  const RVector& p2,
264  double height
265  );
266 
267  virtual void exportBox(const RBox& box);
268 
272  virtual void exportTriangle(const RTriangle& triangle) = 0;
273 
274  virtual void exportRectangle(const RVector& p1, const RVector& p2);
275 
276  virtual double getLineTypePatternScale(const RLinetypePattern& p) const;
277 
281  virtual bool isTextRenderedAsText() {
283  }
284 
285  QStack<REntity*> getEntityStack();
286 
287  void pushEntity(REntity* e);
288  void popEntity();
289 
290  void setDraftMode(bool on);
291 
293  setDraftMode(!draftMode);
294  }
295 
296  bool getDraftMode() const {
297  return draftMode;
298  }
299 
300  void setTwoColorSelectedMode(bool on) {
301  twoColorSelectedMode = on;
302  }
303 
304  bool getTwoColorSelectedMode() const {
305  return twoColorSelectedMode;
306  }
307 
308  void setScreenBasedLinetypes(bool on);
309 
311  setScreenBasedLinetypes(!screenBasedLinetypes);
312  }
313 
314  virtual bool getScreenBasedLinetypes() const {
315  return screenBasedLinetypes;
316  }
317 
322  bool isVisualExporter() const {
323  return visualExporter;
324  }
325 
326  void setVisualExporter(bool on) {
327  visualExporter = on;
328  }
329 
330  double getPixelSizeHint() const {
331  return pixelSizeHint;
332  }
333 
334  void setPixelSizeHint(double v) {
335  pixelSizeHint = v;
336  }
337 
338  bool getPixelUnit() const {
339  return pixelUnit;
340  }
341 
342  void setPixelUnit(bool on) {
343  pixelUnit = on;
344  }
345 
346 protected:
350  QBrush currentBrush;
351  QStack<REntity*> entityStack;
353  QStack<REntity*> blockRefViewportStack;
356  bool draftMode;
360  QString errorMessage;
362  bool pixelUnit;
363  bool clipping;
364 
365 private:
367 };
368 
370 
371 #endif
RDocument * layerSource
Definition: RExporter.h:354
bool getDraftMode() const
Definition: RExporter.h:296
Represents a box e.g.
Definition: RBox.h:43
bool isVisualExporter() const
Definition: RExporter.h:322
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RMessageHandler.h:33
void setPixelSizeHint(double v)
Definition: RExporter.h:334
Viewport entity.
Definition: RViewportEntity.h:38
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RSpline.h:55
double getPixelSizeHint() const
Definition: RExporter.h:330
RLinetypePattern currentLinetypePattern
Definition: RExporter.h:349
RLayer * currentLayer
Definition: RExporter.h:352
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RImageData.h:41
Low-level mathematical representation of a triangle.
Definition: RTriangle.h:46
virtual void startEntity(bool)
Definition: RExporter.h:162
bool clipping
Definition: RExporter.h:363
bool twoColorSelectedMode
Definition: RExporter.h:357
Low-level mathematical representation of an arc.
Definition: RArc.h:40
Represents a block definition in a drawing.
Definition: RBlock.h:44
RDocument * document
Definition: RExporter.h:347
#define QCADCORE_EXPORT
Definition: core_global.h:10
RDocument * blockSource
Definition: RExporter.h:355
QStack< REntity * > blockRefViewportStack
Definition: RExporter.h:353
RS::ProjectionRenderingHint projectionRenderingHint
Definition: RExporter.h:366
int Id
Definition: RObject.h:57
void stripWidths()
Definition: RPolyline.cpp:746
virtual void endEntity()
Definition: RExporter.h:163
bool getPixelUnit() const
Definition: RExporter.h:338
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RLinetypePattern.h:45
QPen currentPen
Definition: RExporter.h:348
virtual bool isTextRenderedAsText()
Override to force text rendering mode.
Definition: RExporter.h:281
#define RNANDOUBLE
Definition: RMath.h:71
QString errorMessage
Definition: RExporter.h:360
ProjectionRenderingHint
Sets the current rendering hint for exports.
Definition: RS.h:131
Lineweight
Definition: RLineweight.h:42
Stores and manages all data that defines the geometry and appearance of a text based entity (text...
Definition: RTextBasedData.h:44
Color.
Definition: RColor.h:42
void toggleDraftMode()
Definition: RExporter.h:292
virtual void exportView(RView &)
Definition: RExporter.h:151
virtual void exportThickPolyline(const RPolyline &polyline)
Definition: RExporter.h:236
bool draftMode
Definition: RExporter.h:356
double pixelSizeHint
Definition: RExporter.h:361
Base class for all entity classes.
Definition: REntity.h:64
A graphics document contains and owns entities, layers, user coordinate systems, variables, block definitions, etc.
Definition: RDocument.h:67
Q_DECLARE_METATYPE(RMath *)
Low-level mathematical representation of an ellipse or ellipse arc.
Definition: REllipse.h:42
Extended painter path with a z-level and a pen.
Definition: RPainterPath.h:46
Interface for entity data classes that can deliver painter paths.
Definition: RPainterPathSource.h:40
void getDocument()
Returns the current RDocument or undefined.
Definition: simple.js:21
Low-level mathematical representation of an infinite line.
Definition: RXLine.h:42
bool pixelUnit
Definition: RExporter.h:362
virtual void exportBlock(RBlock &)
Definition: RExporter.h:149
Low-level mathematical representation of a line.
Definition: RLine.h:41
Interface for explodable shape classes.
Definition: RExplodable.h:40
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RPoint.h:38
Represents a linetype in a drawing.
Definition: RLinetype.h:50
void setVisualExporter(bool on)
Definition: RExporter.h:326
static bool isTextRenderedAsText()
Definition: RSettings.cpp:673
Abstract base class for exporters.
Definition: RExporter.h:71
Low-level mathematical representation of a circle.
Definition: RCircle.h:39
QStack< REntity * > entityStack
Definition: RExporter.h:351
QBrush currentBrush
Definition: RExporter.h:350
void setPixelUnit(bool on)
Definition: RExporter.h:342
virtual void exportLayer(RLayer &)
Definition: RExporter.h:147
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition: RPolyline.h:49
Represents a layer in a drawing.
Definition: RLayer.h:48
Represents a view in a drawing.
Definition: RView.h:42
bool visualExporter
Definition: RExporter.h:359
bool getTwoColorSelectedMode() const
Definition: RExporter.h:304
Low-level mathematical representation of a ray.
Definition: RRay.h:42
bool screenBasedLinetypes
Definition: RExporter.h:358
virtual void exportLinetype(RLinetype &)
Definition: RExporter.h:153
virtual bool getScreenBasedLinetypes() const
Definition: RExporter.h:314
void toggleScreenBasedLinetypes()
Definition: RExporter.h:310
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RProgressHandler.h:33
void setTwoColorSelectedMode(bool on)
Definition: RExporter.h:300