1 /* Class for interpereting the entities found in a DXF file
2 Matt Squires
3 Google SOC
4 2 July 05
5 */
7 #ifndef DXF_ENTITIES_H
8 #define DXF_ENTITIES_H
10 #include"read_dxf.h"
11 #include<vector>
16 class entity{
17 public:
18 void basic_entity( std::vector< dxfpair > info); // Extract all of the typical entity information (e.g. layer name, positions)
19 void entity_display();
20 double ret_x();
21 double ret_y();
22 double ret_z();
23 char* ret_layer_name(char* string);
24 char* ret_ltype_name(char* string);
25 double ret_min_x();
26 double ret_max_x();
27 double ret_min_y();
28 double ret_max_y();
31 protected:
32 char layer[10000];
33 char linetype[10000];
34 double x;
35 double y;
36 double z;
37 double min_x;
38 double max_x;
39 double min_y;
40 double max_y;
41 void reset_extents();
42 void test_coord(double x, double y);
43 };
49 class vertex : public entity {
50 public:
51 vertex( std::vector< dxfpair > info);
52 void display();
53 double ret_bulge();
55 private:
56 double bulge;
57 };
63 class polyline : public entity {
64 public:
65 polyline( std::vector< std::vector< dxfpair > > sections );
66 std::vector< vertex > ret_points();
67 double bulge(int point);
68 double bulge_r(int point);
69 double bulge_start_angle(int point);
70 double bulge_end_angle(int point);
71 bool is_closed();
72 void display();
74 private:
75 double buldge;
76 int pline_flag; // 70
77 double start_width; // 40
78 double end_width; // 41
79 int curves_flag;
80 std::vector< vertex > points;
81 };
83 class lwpolyline : public entity {
84 public:
85 lwpolyline( std::vector< dxfpair > section );
86 std::vector< vertex > ret_points();
87 double bulge(int point);
88 double bulge_r(int point);
89 double bulge_start_angle(int point);
90 double bulge_end_angle(int point);
91 bool is_closed();
92 void display();
94 private:
95 double buldge;
96 int pline_flag; // 70
97 double start_width; // 40
98 double end_width; // 41
99 int curves_flag;
100 std::vector< vertex > points;
101 };
103 class arc : public entity {
104 public:
105 arc( std::vector< dxfpair > info);
106 double ret_radius();
107 double ret_srt_ang();
108 double ret_end_ang();
109 void display();
111 private:
112 double radius;
113 double start_angle;
114 double end_angle;
115 };
120 class circle : public entity {
121 public:
122 circle( std::vector< dxfpair > info);
123 void display();
124 double ret_radius();
126 private:
127 double radius;
128 };
131 class line : public entity {
132 public:
133 line( std::vector< dxfpair > info);
134 void display();
135 double ret_xf();
136 double ret_yf();
137 double ret_zf();
139 private:
140 double xf;
141 double yf;
142 double zf;
143 };
145 class ellipse : public entity {
146 public:
147 ellipse( std::vector< dxfpair > info);
148 void display();
149 double ret_x_ma;
150 double ret_y_ma;
151 double ret_z_ma;
152 double ret_ratio;
153 double ret_start_p;
154 double ret_end_p;
157 private:
158 double x_major_axis;
159 double y_major_axis;
160 double z_major_axis;
161 double ratio;
162 double start_param;
163 double end_param;
164 };
168 class text : public entity {
169 public:
170 text( std::vector< dxfpair > info);
171 void display();
172 char * ret_text(char *string);
173 double ret_txt_ht();
174 double ret_txt_rot();
176 private:
177 char dxf_text[10000];
178 double text_height; // dxf 40
179 double text_rotation; //dxf 50
180 };
183 class insert : public entity {
184 public:
185 insert( std::vector< dxfpair > info);
186 void display();
187 char* name(char* string);
188 double ret_x_sf;
189 double ret_y_sf;
190 double ret_z_sf;
191 double ret_rotation;
193 private:
194 char block_name[10000];
195 double x_scale_factor;
196 double y_scale_factor;
197 double z_scale_factor;
198 double rotation;
199 };
206 class entities{
207 // Well I said that I would only use STL containers internally, but I would have to use a dynamically linked list, and I haven't done for a long time soo STL is my crutch.
208 // I also think that there are others in my same boat that prefer stl containers because they are much easier to use
209 public:
210 entities(std::vector< std::vector< dxfpair > > sections); // Put the various entities into their respective vectors
211 void display_all();
212 std::vector< polyline > ret_plines();
213 std::vector< circle > ret_circles();
214 std::vector< line > ret_lines();
215 std::vector< text > ret_texts();
216 std::vector< ellipse > ret_ellipses();
217 std::vector< arc > ret_arcs();
218 std::vector< lwpolyline > ret_lwplines();
219 std::vector< insert > ret_inserts();
220 // Overload the return function to depend on the layer
221 std::vector< polyline > ret_plines(char * layer);
222 std::vector< circle > ret_circles(char * layer);
223 std::vector< line > ret_lines(char * layer);
224 std::vector< text > ret_texts(char * layer);
225 std::vector< ellipse > ret_ellipses(char * layer);
226 std::vector< arc > ret_arcs(char * layer);
227 std::vector< lwpolyline > ret_lwplines(char * layer);
228 std::vector< insert > ret_inserts(char * layer);
230 int plines_size();
231 int circles_size();
232 int lines_size();
233 int texts_size();
237 private:
238 void add_polyline(polyline pline);
239 void add_circle(circle circ);
240 void add_line(line ln);
242 std::vector< polyline > ents_polyline;
243 std::vector< arc > ents_arc;
244 std::vector< circle > ents_circle;
245 std::vector< line > ents_line;
246 std::vector< ellipse > ents_ellipse;
247 std::vector< text > ents_text;
248 std::vector< lwpolyline > ents_lwpolyline;
249 std::vector< insert > ents_insert;
252 };
256 #endif