Open Source 2D CAD
Go to the documentation of this file.
23 #include "dxf_global.h"
27 #include "RDimensionEntity.h"
28 #include "RDocument.h"
29 #include "RDxfServices.h"
30 #include "RFileImporter.h"
31 #include "RHatchData.h"
32 #include "RLeaderData.h"
33 #include "RPolyline.h"
34 #include "RSpline.h"
36 class RDxfImporter;
37 class RImageEntity;
38 class RMessageHandler;
39 class RProgressHandler;
40 class RVector;
48 public:
49  RDxfTextStyle() : bold(false), italic(false) {}
51  QString font;
52  bool bold;
53  bool italic;
54 };
63 public:
64  RDxfImporter(RDocument& document,
65  RMessageHandler* messageHandler = NULL, RProgressHandler* progressHandler = NULL);
66  virtual ~RDxfImporter();
68  virtual bool importFile(const QString& fileName, const QString& nameFilter);
70  virtual void processCodeValuePair(unsigned int groupCode, const std::string& groupValue);
72 private:
73  // Methods from DL_CreationInterface:
74  virtual void addLayer(const DL_LayerData& data);
75  virtual void addLinetype(const DL_LinetypeData& data);
76  virtual void addLinetypeDash(double length);
77  virtual void addBlock(const DL_BlockData& data);
78  virtual void endBlock();
79  virtual void addPoint(const DL_PointData& data);
80  virtual void addLine(const DL_LineData& data);
81  virtual void addXLine(const DL_XLineData& data);
82  virtual void addRay(const DL_RayData& data);
83  virtual void addArc(const DL_ArcData& data);
84  virtual void addEllipse(const DL_EllipseData& data);
85  virtual void addCircle(const DL_CircleData& data);
86  virtual void addPolyline(const DL_PolylineData& data);
87  virtual void addVertex(const DL_VertexData& data);
88  virtual void endEntity();
89  virtual void endSection();
90  virtual void addSpline(const DL_SplineData& data);
91  virtual void addControlPoint(const DL_ControlPointData& data);
92  virtual void addFitPoint(const DL_FitPointData& data);
93  virtual void addKnot(const DL_KnotData& data);
94  virtual void addInsert(const DL_InsertData& data);
95  virtual void addSolid(const DL_SolidData& data);
96  virtual void addTrace(const DL_TraceData& data);
97  virtual void addTextStyle(const DL_StyleData& data);
98  virtual void addMTextChunk(const std::string& text);
99  virtual void addMText(const DL_MTextData& data);
100  RTextBasedData getTextBasedData(const DL_TextData& data);
101  virtual void addText(const DL_TextData& data);
102  virtual void addArcAlignedText(const DL_ArcAlignedTextData& data);
103  virtual void addAttribute(const DL_AttributeData& data);
104  virtual RDimensionData convDimensionData(const DL_DimensionData& data);
105  virtual void addDimAlign(const DL_DimensionData& data, const DL_DimAlignedData& edata);
106  virtual void addDimLinear(const DL_DimensionData& data, const DL_DimLinearData& edata);
107  virtual void addDimRadial(const DL_DimensionData& data, const DL_DimRadialData& edata);
108  virtual void addDimDiametric(const DL_DimensionData& data, const DL_DimDiametricData& edata);
109  virtual void addDimAngular(const DL_DimensionData& data, const DL_DimAngularData& edata);
110  virtual void addDimAngular3P(const DL_DimensionData& data, const DL_DimAngular3PData& edata);
111  virtual void addDimOrdinate(const DL_DimensionData& data, const DL_DimOrdinateData& edata);
112  virtual void addLeader(const DL_LeaderData &data);
113  virtual void addLeaderVertex(const DL_LeaderVertexData &data);
114  virtual void addHatch(const DL_HatchData& data);
115  virtual void addHatchLoop(const DL_HatchLoopData& data);
116  virtual void addHatchEdge(const DL_HatchEdgeData& data);
117  virtual void addImage(const DL_ImageData &data);
118  virtual void linkImage(const DL_ImageDefData &data);
120  virtual void addXRecord(const std::string& handle);
121  virtual void addXRecordString(int code, const std::string& value);
122  virtual void addXRecordReal(int code, double value);
123  virtual void addXRecordInt(int code, int value);
124  virtual void addXRecordBool(int code, bool value);
126  virtual void addXDataApp(const std::string& appId);
127  virtual void addXDataString(int code, const std::string& value);
128  virtual void addXDataReal(int code, double value);
129  virtual void addXDataInt(int code, int value);
131  virtual void addDictionary(const DL_DictionaryData& data);
132  virtual void addDictionaryEntry(const DL_DictionaryEntryData& data);
134  virtual void setVariableVector(const std::string& key, double v1, double v2, double v3, int code);
135  virtual void setVariableString(const std::string& key, const std::string& value, int code);
136  virtual void setVariableInt(const std::string& key, int value, int code);
137  virtual void setVariableDouble(const std::string& key, double value, int code);
139  static QString decode(const QString& str);
141 private:
142  static QString getEncoding(const QString& str);
144  void importEntity(QSharedPointer<REntity> entity);
146  QString getXDataString(const QString& appId, int code, int pos=0);
147  int getXDataInt(const QString& appId, int code, int pos=0);
149 private:
150  QString fileName;
152  // list of locked layers. layers are locked after importing all entities:
153  QStringList lockedLayers;
161  QByteArray mtext;
162  QMap<QString, RDxfTextStyle> textStyles;
163  QMultiMap<int, RObject::Id> images;
164  // pattern for linetype
165  QList<double> pattern;
167  // Current app id for XData:
168  QString xDataAppId;
169  // AppID -> list of code / value pairs
170  QMap<QString, QList<QPair<int, QVariant> > > xData;
171  QString qcadDictHandle;
172  bool inDict;
173  // Dictionary handles -> names
174  QMap<QString, QString> qcadDict;
175  QString variableKey;
176 };
181 #endif
virtual void addTrace(const DL_TraceData &)
Called for every trace start.
Definition: dl_creationadapter.h:95
virtual void addAttribute(const DL_AttributeData &)
Called for every block Attribute entity.
Definition: dl_creationadapter.h:74
Dictionary entry data.
Definition: dl_entities.h:1803
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RMessageHandler.h:33
Definition: RDxfImporter.h:49
virtual void addDimAngular(const DL_DimensionData &, const DL_DimAngularData &)
Called for every angular dimension (2 lines version) entity.
Definition: dl_creationadapter.h:84
Radial Dimension Data.
Definition: dl_entities.h:1183
Hatch data.
Definition: dl_entities.h:1464
virtual void addXRecord(const std::string &)
Called for every XRecord with the given handle.
Definition: dl_creationadapter.h:104
Generic Dimension Data.
Definition: dl_entities.h:990
virtual void addImage(const DL_ImageData &)
Called for every image entity.
Definition: dl_creationadapter.h:99
virtual void addVertex(const DL_VertexData &)
Called for every polyline vertex.
Definition: dl_creationadapter.h:61
Ordinate Dimension Data.
Definition: dl_entities.h:1350
QString font
Definition: RDxfImporter.h:51
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
virtual void addTextStyle(const DL_StyleData &)
Called for every text style.
Definition: dl_creationadapter.h:50
Point entity.
Definition: RImageEntity.h:38
virtual void addDimLinear(const DL_DimensionData &, const DL_DimLinearData &)
Called for every linear or rotated dimension entity.
Definition: dl_creationadapter.h:78
virtual void addDictionaryEntry(const DL_DictionaryEntryData &)
Called for dictionary entries.
Definition: dl_creationadapter.h:116
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RSpline.h:55
An abstract adapter class for receiving DXF events when a DXF file is being read. ...
Definition: dl_creationadapter.h:39
virtual void addXDataReal(int, double)
Called for XData tuples.
Definition: dl_creationadapter.h:112
virtual void addXRecordInt(int, int)
Called for XRecords of type int.
Definition: dl_creationadapter.h:107
virtual void addSolid(const DL_SolidData &)
Called for every solid start.
Definition: dl_creationadapter.h:97
Aligned Dimension Data.
Definition: dl_entities.h:1100
virtual void setVariableVector(const std::string &, double, double, double, int)
Called for every vector variable in the DXF file (e.g.
Definition: dl_creationadapter.h:122
virtual void addDimDiametric(const DL_DimensionData &, const DL_DimDiametricData &)
Called for every diametric dimension entity.
Definition: dl_creationadapter.h:82
QMap< QString, QString > qcadDict
Definition: RDxfImporter.h:174
virtual void addMTextChunk(const std::string &)
Called for additional text chunks for MTEXT entities.
Definition: dl_creationadapter.h:71
virtual void addDimAlign(const DL_DimensionData &, const DL_DimAlignedData &)
Called for every aligned dimension entity.
Definition: dl_creationadapter.h:76
Circle Data.
Definition: dl_entities.h:352
virtual void endEntity()
Called after an entity has been completed.
Definition: dl_creationadapter.h:118
virtual void addSpline(const DL_SplineData &)
Called for every spline.
Definition: dl_creationadapter.h:63
Text Data.
Definition: dl_entities.h:800
virtual void addXRecordString(int, const std::string &)
Called for XRecords of type string.
Definition: dl_creationadapter.h:105
Line Data.
Definition: dl_entities.h:221
RLeaderData leader
Definition: RDxfImporter.h:158
virtual void addXDataString(int, const std::string &)
Called for XData tuples.
Definition: dl_creationadapter.h:111
virtual void addHatchLoop(const DL_HatchLoopData &)
Called for every hatch loop.
Definition: dl_creationadapter.h:101
Text style data.
Definition: dl_entities.h:130
Linear (rotated) Dimension Data.
Definition: dl_entities.h:1137
RDxfServices dxfServices
Definition: RDxfImporter.h:151
virtual void addLeader(const DL_LeaderData &)
Called for every leader start.
Definition: dl_creationadapter.h:90
virtual void addKnot(const DL_KnotData &)
Called for every spline knot value.
Definition: dl_creationadapter.h:66
virtual void addDimAngular3P(const DL_DimensionData &, const DL_DimAngular3PData &)
Called for every angular dimension (3 points version) entity.
Definition: dl_creationadapter.h:86
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RFileImporter.h:37
QByteArray mtext
Definition: RDxfImporter.h:161
bool italic
Definition: RDxfImporter.h:53
Spline knot data.
Definition: dl_entities.h:556
virtual void endSection()
Called when a section (entity, table entry, etc.) is finished.
Definition: dl_creationadapter.h:44
RPolyline polyline
Definition: RDxfImporter.h:155
virtual void addArc(const DL_ArcData &)
Called for every arc.
Definition: dl_creationadapter.h:56
virtual void addMText(const DL_MTextData &)
Called for every multi Text entity.
Definition: dl_creationadapter.h:70
virtual void addXDataInt(int, int)
Called for XData tuples.
Definition: dl_creationadapter.h:113
virtual void setVariableDouble(const std::string &, double, int)
Called for every double variable in the DXF file (e.g.
Definition: dl_creationadapter.h:125
virtual void addDimOrdinate(const DL_DimensionData &, const DL_DimOrdinateData &)
Called for every ordinate dimension entity.
Definition: dl_creationadapter.h:88
virtual void addArcAlignedText(const DL_ArcAlignedTextData &)
Called for every arc aligned text entity.
Definition: dl_creationadapter.h:73
virtual void addLine(const DL_LineData &)
Called for every line.
Definition: dl_creationadapter.h:52
bool leaderArrowHead
Definition: RDxfImporter.h:159
virtual void setVariableString(const std::string &, const std::string &, int)
Called for every string variable in the DXF file (e.g.
Definition: dl_creationadapter.h:123
virtual void addXLine(const DL_XLineData &)
Called for every xline.
Definition: dl_creationadapter.h:53
virtual void addInsert(const DL_InsertData &)
Called for every insert.
Definition: dl_creationadapter.h:68
virtual void addXRecordBool(int, bool)
Called for XRecords of type bool.
Definition: dl_creationadapter.h:108
virtual void addCircle(const DL_CircleData &)
Called for every circle.
Definition: dl_creationadapter.h:57
virtual bool importFile(const QString &fileName, const QString &nameFilter)=0
Must be implemented by file importers to import the given file into the document. ...
Stores and manages all data that defines the geometry and appearance of a text based entity (text...
Definition: RTextBasedData.h:44
virtual void linkImage(const DL_ImageDefData &)
Called for every image definition.
Definition: dl_creationadapter.h:100
virtual void setVariableInt(const std::string &, int, int)
Called for every int variable in the DXF file (e.g.
Definition: dl_creationadapter.h:124
Hatch edge data.
Definition: dl_entities.h:1533
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RDxfServices.h:39
Spline fit point data.
Definition: dl_entities.h:602
Polyline Data.
Definition: dl_entities.h:382
Point Data.
Definition: dl_entities.h:197
virtual void addDimRadial(const DL_DimensionData &, const DL_DimRadialData &)
Called for every radial dimension entity.
Definition: dl_creationadapter.h:80
virtual void processCodeValuePair(unsigned int, const std::string &)
Called for every code / value tuple of the DXF file.
Definition: dl_creationadapter.h:43
virtual void addFitPoint(const DL_FitPointData &)
Called for every spline fit point.
Definition: dl_creationadapter.h:65
Line Type Data.
Definition: dl_entities.h:90
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RLeaderData.h:37
Definition: dxf_global.h:10
A graphics document contains and owns entities, layers, user coordinate systems, variables, block definitions, etc.
Definition: RDocument.h:67
Block Data.
Definition: dl_entities.h:59
MText Data.
Definition: dl_entities.h:719
virtual void addBlock(const DL_BlockData &)
Called for every block.
Definition: dl_creationadapter.h:48
QMap< QString, QList< QPair< int, QVariant > > > xData
Definition: RDxfImporter.h:170
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RHatchData.h:44
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RDimensionData.h:38
RHatchData hatch
Definition: RDxfImporter.h:160
virtual void addDictionary(const DL_DictionaryData &)
Called for dictionary objects.
Definition: dl_creationadapter.h:115
virtual void addHatchEdge(const DL_HatchEdgeData &)
Called for every hatch edge entity.
Definition: dl_creationadapter.h:102
virtual void addLinetypeDash(double)
Called for every dash in linetype pattern.
Definition: dl_creationadapter.h:47
Importer for the DXF format, based on the dxflib library.
Definition: RDxfImporter.h:62
Arc Data.
Definition: dl_entities.h:315
virtual void addRay(const DL_RayData &)
Called for every ray.
Definition: dl_creationadapter.h:54
virtual void addLeaderVertex(const DL_LeaderVertexData &)
Called for every leader vertex.
Definition: dl_creationadapter.h:91
bool inDict
Definition: RDxfImporter.h:172
virtual void addPolyline(const DL_PolylineData &)
Called for every polyline start.
Definition: dl_creationadapter.h:60
XLine Data.
Definition: dl_entities.h:255
QMultiMap< int, RObject::Id > images
Definition: RDxfImporter.h:163
Trace Data / solid data / 3d face data.
Definition: dl_entities.h:444
bool polylinePlineGen
Definition: RDxfImporter.h:156
RSpline spline
Definition: RDxfImporter.h:157
Image Data.
Definition: dl_entities.h:1703
virtual void addLayer(const DL_LayerData &)
Called for every layer.
Definition: dl_creationadapter.h:45
Angular Dimension Data (3 points version).
Definition: dl_entities.h:1301
virtual void addText(const DL_TextData &)
Called for every text entity.
Definition: dl_creationadapter.h:72
Ray Data.
Definition: dl_entities.h:284
virtual void addControlPoint(const DL_ControlPointData &)
Called for every spline control point.
Definition: dl_creationadapter.h:64
QString qcadDictHandle
Definition: RDxfImporter.h:171
Insert Data.
Definition: dl_entities.h:669
Spline control point data.
Definition: dl_entities.h:575
bool bold
Definition: RDxfImporter.h:52
QString variableKey
Definition: RDxfImporter.h:175
virtual void addPoint(const DL_PointData &)
Called for every point.
Definition: dl_creationadapter.h:51
Leader (arrow).
Definition: dl_entities.h:1393
QList< double > pattern
Definition: RDxfImporter.h:165
Layer Data.
Definition: dl_entities.h:36
Angular Dimension Data.
Definition: dl_entities.h:1241
Diametric Dimension Data.
Definition: dl_entities.h:1212
Vertex Data.
Definition: dl_entities.h:416
Ellipse Data.
Definition: dl_entities.h:622
Low-level mathematical representation of an open polyline or closed polyline (= polygon).
Definition: RPolyline.h:49
virtual void addXDataApp(const std::string &)
Called for every beginning of an XData section of the given application.
Definition: dl_creationadapter.h:110
QStringList lockedLayers
Definition: RDxfImporter.h:153
Block attribute data.
Definition: dl_entities.h:950
Dictionary data.
Definition: dl_entities.h:1793
QString fileName
Definition: RDxfImporter.h:150
Image Definition Data.
Definition: dl_entities.h:1769
QString xDataAppId
Definition: RDxfImporter.h:168
Hatch boundary path (loop) data.
Definition: dl_entities.h:1511
virtual void addXRecordReal(int, double)
Called for XRecords of type double.
Definition: dl_creationadapter.h:106
Spline Data.
Definition: dl_entities.h:511
virtual void endBlock()
Called to end the current block.
Definition: dl_creationadapter.h:49
QMap< QString, RDxfTextStyle > textStyles
Definition: RDxfImporter.h:162
virtual void addLinetype(const DL_LinetypeData &)
Called for every linetype.
Definition: dl_creationadapter.h:46
virtual void addEllipse(const DL_EllipseData &)
Called for every ellipse.
Definition: dl_creationadapter.h:58
virtual void addHatch(const DL_HatchData &)
Called for every hatch entity.
Definition: dl_creationadapter.h:93
Arc Aligned Text Data.
Definition: dl_entities.h:870
Copyright (c) 2011-2017 by Andrew Mustun.
Definition: RProgressHandler.h:33
Represents a text style.
Definition: RDxfImporter.h:47
Leader Vertex Data.
Definition: dl_entities.h:1440