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 void setEntityAttributes(bool forceSelected=false);
103 
104  virtual void setStyle(Qt::PenStyle penStyle);
105  virtual void setBrushStyle(Qt::BrushStyle brushStyle);
106  virtual void setDashPattern(const QVector<qreal>& dashes);
107 
108  virtual void setColor(float r, float g, float b, float a = 1.0f);
109  virtual void setColor(const RColor& color);
110 
111  virtual void setLineweight(RLineweight::Lineweight weight);
112 
113  virtual void setLinetypeId(RLinetype::Id ltId);
114  virtual void setLinetypePattern(const RLinetypePattern& ltPattern);
115  virtual RLinetypePattern getLinetypePattern();
116 
117  virtual REntity* getBlockRefOrEntity();
118  virtual REntity::Id getBlockRefOrEntityId();
119  virtual REntity* getEntity();
120  virtual REntity* getCurrentBlockRef() const;
121  virtual RViewportEntity* getCurrentViewport() const;
122 
126  virtual const REntity* getEntity() const;
127 
128  virtual bool isEntitySelected();
129 
130  virtual void startExport();
131  virtual void endExport();
132 
133  virtual bool exportDocument();
134  virtual bool exportDocumentSettings();
135  virtual void exportDocumentSetting(const QString& key, const QVariant& value, const QString& dictionaryName = "QCAD_OBJECTS");
136 
137  virtual void exportIntListWithName(const QString& dictionaryName, const QString& name, const QString& listName, QList<int64_t>& values);
138 
139  virtual void exportLayers();
140  virtual void exportBlocks();
141  virtual void exportViews();
142  virtual void exportLinetypes();
143 
144  virtual void exportLayer(RLayer& /*layer*/) {}
145  virtual void exportLayer(RLayer::Id layerId);
146  virtual void exportBlock(RBlock& /*block*/) {}
147  virtual void exportBlock(RBlock::Id blockId);
148  virtual void exportView(RView& /*view*/) {}
149  virtual void exportView(RView::Id viewId);
150  virtual void exportLinetype(RLinetype& /*linetype*/) {}
151 
152  virtual void exportEntities(bool allBlocks = true, bool undone = false);
153  virtual void exportEntities(const RBox& box);
154  virtual void exportEntities(QSet<REntity::Id>& entityIds, bool allBlocks = true);
155  virtual void exportEntity(REntity& entity, bool preview = false, bool allBlocks = true, bool forceSelected = false);
156  virtual void exportEntity(REntity::Id entityId, bool allBlocks = true, bool forceSelected = false);
157  virtual QSharedPointer<RLayer> getEntityLayer(REntity& entity);
158  virtual bool isVisible(REntity& entity);
159  virtual void startEntity(bool /*topLevelEntity*/) {}
160  virtual void endEntity() {}
161  virtual void exportCurrentEntity(bool preview = false, bool forceSelected = false);
162  virtual void unexportEntity(REntity::Id entityId);
163 
164  virtual void exportShapes(const QList<QSharedPointer<RShape> >& shapes);
165  virtual void exportShape(QSharedPointer<RShape> shape);
166  virtual void exportShapeSegment(QSharedPointer<RShape> shape, double angle);
167 
171  virtual double exportLine(const RLine& line, double offset = RNANDOUBLE);
172 
176  virtual bool exportLinetypeShape(QList<RPainterPath>& pps, const RLine& line, double total, double length, double angle, const RVector& cursor);
177 
183  virtual void exportLineSegment(const RLine& line, double angle = RNANDOUBLE) = 0;
184 
188  virtual void exportXLine(const RXLine& xLine) = 0;
189 
193  virtual void exportRay(const RRay& ray) = 0;
194 
198  virtual void exportPoint(const RPoint& point) = 0;
199 
200  virtual void exportCircle(const RCircle& circle);
201 
202  virtual void exportArc(const RArc& arc, double offset = RNANDOUBLE);
203 
204  virtual void exportArcSegment(const RArc& arc, bool allowForZeroLength = false);
205 
206  virtual void exportEllipse(const REllipse& ellipse, double offset = RNANDOUBLE);
207 
208  virtual void exportPolyline(const RPolyline& polyline, bool polylineGen = true, double offset = RNANDOUBLE);
209 
210  virtual void exportSpline(const RSpline& spline, double offset = RNANDOUBLE);
211 
212  virtual void exportSplineSegment(const RSpline& spline);
213 
217  virtual void exportExplodable(const RExplodable& explodable, double offset = RNANDOUBLE);
218 
222  virtual void exportPainterPathSource(const RPainterPathSource& pathSource);
223 
224  virtual void exportPainterPaths(const QList<RPainterPath>& paths);
225  virtual void exportPainterPaths(const QList<RPainterPath>& paths, double angle, const RVector& pos);
226 
227  virtual void exportBoundingBoxPaths(const QList<RPainterPath>& paths);
228 
229  virtual void exportImage(const RImageData& image, bool forceSelected = false);
230  virtual QList<RPainterPath> exportText(const RTextBasedData& text, bool forceSelected = false);
231  virtual void exportClipRectangle(const RBox& clipRectangle, bool forceSelected = false);
232 
233  virtual void exportThickPolyline(const RPolyline& polyline) {
234  RPolyline pl = polyline;
235  pl.stripWidths();
236  exportPolyline(pl);
237  }
238 
239 // virtual void exportThickLine(const RLine& line, double w1, double w2) {
240 // Q_UNUSED(w1)
241 // Q_UNUSED(w2)
242 // exportLineSegment(line);
243 // }
244 
245 // virtual void exportThickArc(const RArc& arc, double w1, double w2) {
246 // Q_UNUSED(w1)
247 // Q_UNUSED(w2)
248 // exportArcSegment(arc);
249 // }
250 
251  virtual void exportQuad(
252  const RVector& p1,
253  const RVector& p2,
254  const RVector& p3,
255  const RVector& p4
256  );
257 
258  virtual void exportVerticalQuad(
259  const RVector& p1,
260  const RVector& p2,
261  double height
262  );
263 
264  virtual void exportBox(const RBox& box);
265 
269  virtual void exportTriangle(const RTriangle& triangle) = 0;
270 
271  virtual void exportRectangle(const RVector& p1, const RVector& p2);
272 
273  virtual double getLineTypePatternScale(const RLinetypePattern& p) const;
274 
275  QStack<REntity*> getEntityStack();
276 
277  void setDraftMode(bool on);
278 
280  setDraftMode(!draftMode);
281  }
282 
283  bool getDraftMode() const {
284  return draftMode;
285  }
286 
287  void setTwoColorSelectedMode(bool on) {
288  twoColorSelectedMode = on;
289  }
290 
291  bool getTwoColorSelectedMode() const {
292  return twoColorSelectedMode;
293  }
294 
295  void setScreenBasedLinetypes(bool on);
296 
298  setScreenBasedLinetypes(!screenBasedLinetypes);
299  }
300 
301  bool getScreenBasedLinetypes() const {
302  return screenBasedLinetypes;
303  }
304 
309  bool isVisualExporter() const {
310  return visualExporter;
311  }
312 
313  void setVisualExporter(bool on) {
314  visualExporter = on;
315  }
316 
317  double getPixelSizeHint() const {
318  return pixelSizeHint;
319  }
320 
321  void setPixelSizeHint(double v) {
322  pixelSizeHint = v;
323  }
324 
325  bool getPixelUnit() const {
326  return pixelUnit;
327  }
328 
329  void setPixelUnit(bool on) {
330  pixelUnit = on;
331  }
332 
333 protected:
337  QBrush currentBrush;
338  QStack<REntity*> entityStack;
340  QStack<REntity*> blockRefViewportStack;
343  bool draftMode;
347  QString errorMessage;
349  bool pixelUnit;
350  bool clipping;
351 
352 private:
354 };
355 
357 
358 #endif
RDocument * layerSource
Definition: RExporter.h:341
bool getDraftMode() const
Definition: RExporter.h:283
Represents a box e.g.
Definition: RBox.h:43
bool isVisualExporter() const
Definition: RExporter.h:309
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RMessageHandler.h:33
void setPixelSizeHint(double v)
Definition: RExporter.h:321
Viewport entity.
Definition: RViewportEntity.h:38
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RSpline.h:56
double getPixelSizeHint() const
Definition: RExporter.h:317
RLinetypePattern currentLinetypePattern
Definition: RExporter.h:336
RLayer * currentLayer
Definition: RExporter.h:339
Copyright (c) 2011-2016 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:159
bool clipping
Definition: RExporter.h:350
bool twoColorSelectedMode
Definition: RExporter.h:344
Low-level mathematical representation of an arc.
Definition: RArc.h:41
Represents a block definition in a drawing.
Definition: RBlock.h:44
bool getScreenBasedLinetypes() const
Definition: RExporter.h:301
RDocument * document
Definition: RExporter.h:334
#define QCADCORE_EXPORT
Definition: core_global.h:10
RDocument * blockSource
Definition: RExporter.h:342
QStack< REntity * > blockRefViewportStack
Definition: RExporter.h:340
RS::ProjectionRenderingHint projectionRenderingHint
Definition: RExporter.h:353
int Id
Definition: RObject.h:53
void stripWidths()
Definition: RPolyline.cpp:689
virtual void endEntity()
Definition: RExporter.h:160
bool getPixelUnit() const
Definition: RExporter.h:325
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RLinetypePattern.h:45
QPen currentPen
Definition: RExporter.h:335
#define RNANDOUBLE
Definition: RMath.h:71
QString errorMessage
Definition: RExporter.h:347
ProjectionRenderingHint
Sets the current rendering hint for exports.
Definition: RS.h:129
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:43
Color.
Definition: RColor.h:42
void toggleDraftMode()
Definition: RExporter.h:279
virtual void exportView(RView &)
Definition: RExporter.h:148
virtual void exportThickPolyline(const RPolyline &polyline)
Definition: RExporter.h:233
bool draftMode
Definition: RExporter.h:343
double pixelSizeHint
Definition: RExporter.h:348
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:43
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:14
Low-level mathematical representation of an infinite line.
Definition: RXLine.h:42
bool pixelUnit
Definition: RExporter.h:349
virtual void exportBlock(RBlock &)
Definition: RExporter.h:146
Low-level mathematical representation of a line.
Definition: RLine.h:42
Interface for explodable shape classes.
Definition: RExplodable.h:40
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RPoint.h:38
Represents a linetype in a drawing.
Definition: RLinetype.h:50
void setVisualExporter(bool on)
Definition: RExporter.h:313
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:338
QBrush currentBrush
Definition: RExporter.h:337
void setPixelUnit(bool on)
Definition: RExporter.h:329
virtual void exportLayer(RLayer &)
Definition: RExporter.h:144
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition: RPolyline.h:50
Represents a layer in a drawing.
Definition: RLayer.h:47
Represents a view in a drawing.
Definition: RView.h:42
bool visualExporter
Definition: RExporter.h:346
bool getTwoColorSelectedMode() const
Definition: RExporter.h:291
Low-level mathematical representation of a ray.
Definition: RRay.h:42
bool screenBasedLinetypes
Definition: RExporter.h:345
virtual void exportLinetype(RLinetype &)
Definition: RExporter.h:150
void toggleScreenBasedLinetypes()
Definition: RExporter.h:297
Copyright (c) 2011-2016 by Andrew Mustun.
Definition: RProgressHandler.h:33
void setTwoColorSelectedMode(bool on)
Definition: RExporter.h:287