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, char* 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 addAttribute(const DL_AttributeData& data);
103  virtual RDimensionData convDimensionData(const DL_DimensionData& data);
104  virtual void addDimAlign(const DL_DimensionData& data, const DL_DimAlignedData& edata);
105  virtual void addDimLinear(const DL_DimensionData& data, const DL_DimLinearData& edata);
106  virtual void addDimRadial(const DL_DimensionData& data, const DL_DimRadialData& edata);
107  virtual void addDimDiametric(const DL_DimensionData& data, const DL_DimDiametricData& edata);
108  virtual void addDimAngular(const DL_DimensionData& data, const DL_DimAngularData& edata);
109  virtual void addDimAngular3P(const DL_DimensionData& data, const DL_DimAngular3PData& edata);
110  virtual void addDimOrdinate(const DL_DimensionData& data, const DL_DimOrdinateData& edata);
111  virtual void addLeader(const DL_LeaderData &data);
112  virtual void addLeaderVertex(const DL_LeaderVertexData &data);
113  virtual void addHatch(const DL_HatchData& data);
114  virtual void addHatchLoop(const DL_HatchLoopData& data);
115  virtual void addHatchEdge(const DL_HatchEdgeData& data);
116  virtual void addImage(const DL_ImageData &data);
117  virtual void linkImage(const DL_ImageDefData &data);
119  virtual void addXRecord(const std::string& handle);
120  virtual void addXRecordString(int code, const std::string& value);
121  virtual void addXRecordReal(int code, double value);
122  virtual void addXRecordInt(int code, int value);
123  virtual void addXRecordBool(int code, bool value);
125  virtual void addXDataApp(const std::string& appId);
126  virtual void addXDataString(int code, const std::string& value);
127  virtual void addXDataReal(int code, double value);
128  virtual void addXDataInt(int code, int value);
130  virtual void addDictionary(const DL_DictionaryData& data);
131  virtual void addDictionaryEntry(const DL_DictionaryEntryData& data);
133  virtual void setVariableVector(const std::string& key, double v1, double v2, double v3, int code);
134  virtual void setVariableString(const std::string& key, const std::string& value, int code);
135  virtual void setVariableInt(const std::string& key, int value, int code);
136  virtual void setVariableDouble(const std::string& key, double value, int code);
138  static QString decode(const QString& str);
140 private:
141  static QString getEncoding(const QString& str);
143  void importEntity(QSharedPointer<REntity> entity);
145  QString getXDataString(const QString& appId, int code, int pos=0);
146  int getXDataInt(const QString& appId, int code, int pos=0);
148 private:
149  QString fileName;
151  // list of locked layers. layers are locked after importing all entities:
152  QStringList lockedLayers;
160  QByteArray mtext;
161  QMap<QString, RDxfTextStyle> textStyles;
162  QMultiMap<int, RObject::Id> images;
163  // pattern for linetype
164  QList<double> pattern;
166  // Current app id for XData:
167  QString xDataAppId;
168  // AppID -> list of code / value pairs
169  QMap<QString, QList<QPair<int, QVariant> > > xData;
170  QString qcadDictHandle;
171  bool inDict;
172  // Dictionary handles -> names
173  QMap<QString, QString> qcadDict;
174  QString variableKey;
175 };
180 #endif
virtual void addTrace(const DL_TraceData &)
Called for every trace start.
Definition: dl_creationadapter.h:94
virtual void addAttribute(const DL_AttributeData &)
Called for every Block Attribute entity.
Definition: dl_creationadapter.h:73
Dictionary entry data.
Definition: dl_entities.h:1719
Copyright (c) 2011-2015 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:83
Radial Dimension Data.
Definition: dl_entities.h:1099
Hatch data.
Definition: dl_entities.h:1380
virtual void addXRecord(const std::string &)
Called for every XRecord with the given handle.
Definition: dl_creationadapter.h:103
Generic Dimension Data.
Definition: dl_entities.h:906
virtual void addImage(const DL_ImageData &)
Called for every image entity.
Definition: dl_creationadapter.h:98
virtual void addVertex(const DL_VertexData &)
Called for every polyline vertex.
Definition: dl_creationadapter.h:61
Ordinate Dimension Data.
Definition: dl_entities.h:1266
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:77
virtual void addDictionaryEntry(const DL_DictionaryEntryData &)
Called for dictionary entries.
Definition: dl_creationadapter.h:115
Low-level mathematical representation of a spline.
Definition: RSpline.h:54
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:111
virtual void addXRecordInt(int, int)
Called for XRecords of type int.
Definition: dl_creationadapter.h:106
virtual void addSolid(const DL_SolidData &)
Called for every solid start.
Definition: dl_creationadapter.h:96
Aligned Dimension Data.
Definition: dl_entities.h:1016
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:121
virtual void addDimDiametric(const DL_DimensionData &, const DL_DimDiametricData &)
Called for every diametric dimension entity.
Definition: dl_creationadapter.h:81
QMap< QString, QString > qcadDict
Definition: RDxfImporter.h:173
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:75
Circle Data.
Definition: dl_entities.h:351
virtual void endEntity()
Called after an entity has been completed.
Definition: dl_creationadapter.h:117
virtual void addSpline(const DL_SplineData &)
Called for every spline.
Definition: dl_creationadapter.h:63
Text Data.
Definition: dl_entities.h:795
virtual void addXRecordString(int, const std::string &)
Called for XRecords of type string.
Definition: dl_creationadapter.h:104
Line Data.
Definition: dl_entities.h:220
RLeaderData leader
Definition: RDxfImporter.h:157
virtual void addXDataString(int, const std::string &)
Called for XData tuples.
Definition: dl_creationadapter.h:110
virtual void addHatchLoop(const DL_HatchLoopData &)
Called for every hatch loop.
Definition: dl_creationadapter.h:100
Text style data.
Definition: dl_entities.h:129
Linear (rotated) Dimension Data.
Definition: dl_entities.h:1053
RDxfServices dxfServices
Definition: RDxfImporter.h:150
virtual void addLeader(const DL_LeaderData &)
Called for every leader start.
Definition: dl_creationadapter.h:89
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:85
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RFileImporter.h:37
QByteArray mtext
Definition: RDxfImporter.h:160
bool italic
Definition: RDxfImporter.h:53
Spline knot data.
Definition: dl_entities.h:551
virtual void endSection()
Called when a section (entity, table entry, etc.) is finished.
Definition: dl_creationadapter.h:44
RPolyline polyline
Definition: RDxfImporter.h:154
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:112
virtual void setVariableDouble(const std::string &, double, int)
Called for every double variable in the DXF file (e.g.
Definition: dl_creationadapter.h:124
virtual void addDimOrdinate(const DL_DimensionData &, const DL_DimOrdinateData &)
Called for every ordinate dimension entity.
Definition: dl_creationadapter.h:87
virtual void addLine(const DL_LineData &)
Called for every line.
Definition: dl_creationadapter.h:52
bool leaderArrowHead
Definition: RDxfImporter.h:158
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:122
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:107
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:99
virtual void setVariableInt(const std::string &, int, int)
Called for every int variable in the DXF file (e.g.
Definition: dl_creationadapter.h:123
Hatch edge data.
Definition: dl_entities.h:1449
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RDxfServices.h:39
Spline fit point data.
Definition: dl_entities.h:597
Polyline Data.
Definition: dl_entities.h:381
Point Data.
Definition: dl_entities.h:196
virtual void addDimRadial(const DL_DimensionData &, const DL_DimRadialData &)
Called for every radial dimension entity.
Definition: dl_creationadapter.h:79
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:89
Copyright (c) 2011-2015 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:63
Block Data.
Definition: dl_entities.h:58
MText Data.
Definition: dl_entities.h:714
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:169
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RHatchData.h:42
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RDimensionData.h:38
RHatchData hatch
Definition: RDxfImporter.h:159
virtual void addDictionary(const DL_DictionaryData &)
Called for dictionary objects.
Definition: dl_creationadapter.h:114
virtual void addHatchEdge(const DL_HatchEdgeData &)
Called for every hatch edge entity.
Definition: dl_creationadapter.h:101
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:314
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:90
bool inDict
Definition: RDxfImporter.h:171
virtual void addPolyline(const DL_PolylineData &)
Called for every polyline start.
Definition: dl_creationadapter.h:60
XLine Data.
Definition: dl_entities.h:254
QMultiMap< int, RObject::Id > images
Definition: RDxfImporter.h:162
Trace Data / solid data / 3d face data.
Definition: dl_entities.h:439
bool polylinePlineGen
Definition: RDxfImporter.h:155
RSpline spline
Definition: RDxfImporter.h:156
Image Data.
Definition: dl_entities.h:1619
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:1217
virtual void addText(const DL_TextData &)
Called for every Text entity.
Definition: dl_creationadapter.h:72
Ray Data.
Definition: dl_entities.h:283
virtual void addControlPoint(const DL_ControlPointData &)
Called for every spline control point.
Definition: dl_creationadapter.h:64
QString qcadDictHandle
Definition: RDxfImporter.h:170
Insert Data.
Definition: dl_entities.h:664
Spline control point data.
Definition: dl_entities.h:570
bool bold
Definition: RDxfImporter.h:52
QString variableKey
Definition: RDxfImporter.h:174
virtual void addPoint(const DL_PointData &)
Called for every point.
Definition: dl_creationadapter.h:51
Leader (arrow).
Definition: dl_entities.h:1309
QList< double > pattern
Definition: RDxfImporter.h:164
Layer Data.
Definition: dl_entities.h:36
Angular Dimension Data.
Definition: dl_entities.h:1157
Diametric Dimension Data.
Definition: dl_entities.h:1128
Vertex Data.
Definition: dl_entities.h:411
Ellipse Data.
Definition: dl_entities.h:617
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:109
QStringList lockedLayers
Definition: RDxfImporter.h:152
Block attribute data.
Definition: dl_entities.h:866
Dictionary data.
Definition: dl_entities.h:1709
QString fileName
Definition: RDxfImporter.h:149
Image Definition Data.
Definition: dl_entities.h:1685
QString xDataAppId
Definition: RDxfImporter.h:167
Hatch boundary path (loop) data.
Definition: dl_entities.h:1427
virtual void addXRecordReal(int, double)
Called for XRecords of type double.
Definition: dl_creationadapter.h:105
Spline Data.
Definition: dl_entities.h:506
virtual void endBlock()
Called to end the current block.
Definition: dl_creationadapter.h:49
QMap< QString, RDxfTextStyle > textStyles
Definition: RDxfImporter.h:161
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:92
Copyright (c) 2011-2015 by Andrew Mustun.
Definition: RProgressHandler.h:33
Represents a text style.
Definition: RDxfImporter.h:47
Leader Vertex Data.
Definition: dl_entities.h:1356