-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdxf.h
More file actions
195 lines (169 loc) · 5.99 KB
/
dxf.h
File metadata and controls
195 lines (169 loc) · 5.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// dxf.h
// Copyright (c) 2009, Dan Heeks
// This program is released under the BSD license. See the file COPYING for details.
#pragma once
#include <algorithm>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <fstream>
#include <sstream>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
//Following is required to be defined on Ubuntu with OCC 6.3.1
#ifndef HAVE_IOSTREAM
#define HAVE_IOSTREAM
#endif
typedef int Aci_t; // AutoCAD color index
typedef enum
{
eUnspecified = 0, // Unspecified (No units)
eInches,
eFeet,
eMiles,
eMillimeters,
eCentimeters,
eMeters,
eKilometers,
eMicroinches,
eMils,
eYards,
eAngstroms,
eNanometers,
eMicrons,
eDecimeters,
eDekameters,
eHectometers,
eGigameters,
eAstronomicalUnits,
eLightYears,
eParsecs
} eDxfUnits_t;
struct SplineData
{
double norm[3];
int degree;
int knots;
int control_points;
int fit_points;
int flag;
std::list<double> starttanx;
std::list<double> starttany;
std::list<double> starttanz;
std::list<double> endtanx;
std::list<double> endtany;
std::list<double> endtanz;
std::list<double> knot;
std::list<double> weight;
std::list<double> controlx;
std::list<double> controly;
std::list<double> controlz;
std::list<double> fitx;
std::list<double> fity;
std::list<double> fitz;
};
class CDxfWrite{
private:
std::ofstream* m_ofs;
bool m_fail;
void WriteExtrusion(double thickness, const double* extru);
public:
CDxfWrite(const char* filepath);
~CDxfWrite();
bool Failed(){return m_fail;}
void WriteLine(const double* s, const double* e, const char* layer_name, double thickness, const double* extru = NULL);
void WritePoint(const double*, const char*);
void WriteArc(const double* s, const double* e, const double* c, bool dir, const char* layer_name, double thickness, const double* extru = NULL);
void WriteEllipse(const double* c, double major_radius, double minor_radius, double rotation, double start_angle, double end_angle, bool dir, const char* layer_name, double thickness, const double* extru = NULL);
void WriteCircle(const double* c, double radius, const char* layer_name, double thickness, const double* extru = NULL);
};
class CPolyLinePoint
{
public:
double x;
double y;
double z;
bool bulge_found;
double bulge;
CPolyLinePoint(double px, double py, double pz, bool pbulge_found, double pbulge){x = px; y = py; z = pz; bulge_found = pbulge_found; bulge = pbulge;}
};
// derive a class from this and implement it's virtual functions
class CDxfRead{
private:
std::ifstream* m_ifs;
bool m_fail;
char m_str[1024];
char m_unused_line[1024];
eDxfUnits_t m_eUnits;
bool m_measurement_inch;
char m_layer_name[1024];
char m_section_name[1024];
bool m_ignore_errors;
long m_line_number;
long m_number_of_lines;
int m_current_percent;
typedef std::map< std::string,Aci_t > LayerAciMap_t;
LayerAciMap_t m_layer_aci; // layer names -> layer color aci map
bool ReadUCS();
bool ReadUnits();
bool ReadLayer();
bool ReadSection();
bool ReadBlock();
bool ReadEndBlock();
bool ReadInsert();
bool ReadLine();
bool ReadText();
bool ReadMText();
bool ReadRText();
bool ReadArc();
bool ReadCircle();
bool ReadEllipse();
bool ReadPoint();
bool ReadSpline();
bool ReadLwPolyLine();
bool ReadPolyLine();
bool ReadVertex(double *pVertex, bool *bulge_found, double *bulge);
void OnReadArc(double start_angle, double end_angle, double radius, const double* c, bool hidden);
void OnReadCircle(const double* c, double radius, bool hidden);
void OnReadEllipse(const double* c, const double* m, double ratio, double start_angle, double end_angle);
bool ReadLeader();
bool ReadMLine();
bool ReadXLine();
bool ReadDimension();
void get_line();
void put_line(const char *value);
void DerefACI();
void StorePolyLinePoint(double x, double y, double z, bool bulge_found, double bulge);
void AddPolyLinePoints(bool mirrored, bool closed);
void ResetExtrusionAndThickness();
bool ReadExtrusionOrThickness(int n);
protected:
Aci_t m_aci; // manifest color name or 256 for layer color
double m_extrusion_vector[3];
double m_thickness;
void(*m_percent_callback)(int);
public:
CDxfRead(const char* filepath, void(*percent_callback)(int) = NULL); // this opens the file
~CDxfRead(); // this closes the file
bool Failed(){return m_fail;}
void DoRead(const bool ignore_errors = false); // this reads the file and calls the following functions
double mm( double value ) const;
bool IgnoreErrors() const { return(m_ignore_errors); }
virtual void OnReadUCS(const double* /*ucs point*/){}
virtual void OnReadBlock(const char* /*block_name*/, const double* /*base_point*/){}
virtual void OnReadInsert(const char* /*block_name*/, const double* /*insert_point*/, double /*rotation_angle*/){}
virtual void OnReadEndBlock(){}
virtual void OnReadLine(const double* /*s*/, const double* /*e*/, bool /*hidden*/){}
virtual void OnReadPoint(const double* /*s*/){}
virtual void OnReadText(const double* /*point*/, const double /*height*/, const char* /*text*/, int /*hj*/, int /*vj*/){}
virtual void OnReadArc(const double* /*s*/, const double* /*e*/, const double* /*c*/, bool /*dir*/, bool /*hidden*/){}
virtual void OnReadCircle(const double* /*s*/, const double* /*c*/, bool /*dir*/, bool /*hidden*/){}
virtual void OnReadEllipse(const double* /*c*/, double /*major_radius*/, double /*minor_radius*/, double /*rotation*/, double /*start_angle*/, double /*end_angle*/, bool /*dir*/){}
virtual void OnReadSpline(struct SplineData& /*sd*/){}
virtual void OnReadDimension(int /*dimension_type*/, double /*angle*/, double /*angle2*/, double /*angle3*/, double /*radius_leader_length*/, const double * /*def_point*/, const double * /*mid*/, const double * /*p1*/, const double * /*p2*/, const double * /*p3*/, const double * /*p4*/, const double * /*p5*/){}
virtual void AddGraphics() { }
std::string LayerName() const;
};