1 /*
2 * Class for interpereting the entities found in a DXF file
3 *
4 * Author:
5 * Matt Squires <squiresm@colorado.edu>
6 *
7 * Copyright (C) 2005 Matt Squires
8 *
9 * Released under GNU GPL and LGPL, read the file 'GPL.txt' and 'LGPL.txt' for details
10 */
13 #include"entities.h"
14 #include<iostream>
15 #include<math.h>
17 int detmine_entity(char* value){
18 // Common Elements as far as I am concerend
19 if ( strncmp(value,"POLYLINE",8) == 0 ) return 0;
20 if ( strncmp(value,"ARC",3) == 0 ) return 1;
21 if ( strncmp(value,"CIRCLE",6) == 0 ) return 2;
22 if ( strncmp(value,"LINE",4) == 0 ) return 3;
23 if ( strncmp(value,"SPLINE",6) == 0 ) return 4;
24 if ( strncmp(value,"XLINE",5) == 0 ) return 5;
25 if ( strncmp(value,"RAY",3) == 0 ) return 6;
26 if ( strncmp(value,"DIMENSION",9) == 0 ) return 7;
27 if ( strncmp(value,"ELLIPSE",7) == 0 ) return 8;
28 if ( strncmp(value,"INSERT",6) == 0 ) return 9;
29 if ( strncmp(value,"VERTEX",6) == 0 ) return 10;
30 if ( strncmp(value,"TEXT",4) == 0 ) return 11;
32 // Less Common eletities as far as I am concerend
33 if ( strncmp(value,"3DSOLID",7) == 0 ) return 12;
34 if ( strncmp(value,"ACAD_PROXY_ENTITY",17) == 0 ) return 13;
35 if ( strncmp(value,"ARCALIGNEDTEXT",14) == 0 ) return 14;
36 if ( strncmp(value,"ATTDEF",6) == 0 ) return 15;
37 if ( strncmp(value,"ATTRIB",6) == 0 ) return 16;
38 if ( strncmp(value,"BODY",4) == 0 ) return 17;
39 if ( strncmp(value,"HATCH",5) == 0 ) return 18;
40 if ( strncmp(value,"IMAGE",5) == 0 ) return 19;
41 if ( strncmp(value,"LEADER",6) == 0 ) return 20;
42 if ( strncmp(value,"LWPOLYLINE",10) == 0 ) return 21;
43 if ( strncmp(value,"MLINE",5) == 0 ) return 22;
44 if ( strncmp(value,"MTEXT",5) == 0 ) return 23;
45 if ( strncmp(value,"OLEFRAME",8) == 0 ) return 24;
46 if ( strncmp(value,"POINT",5) == 0 ) return 25;
47 if ( strncmp(value,"REGION",6) == 0 ) return 26;
48 if ( strncmp(value,"RTEXT",5) == 0 ) return 27;
49 if ( strncmp(value,"SEQEND",6) == 0 ) return 28;
50 if ( strncmp(value,"SHAPE",5) == 0 ) return 29;
51 if ( strncmp(value,"SOLID",5) == 0 ) return 30;
52 if ( strncmp(value,"3DFACE",6) == 0 ) return 31;
53 if ( strncmp(value,"TOLERANCE",9) == 0 ) return 32;
54 if ( strncmp(value,"TRACE",5) == 0 ) return 33;
55 if ( strncmp(value,"VIEWPORT",8) == 0 ) return 34;
56 if ( strncmp(value,"WIPEOUT",7) == 0 ) return 35;
57 else return -1;
58 }
61 void entity::basic_entity( std::vector< dxfpair > info){
62 // Extract all of the typical entity information (e.g. layer name, positions)
63 static char string[10000];
64 for (int i = 0; i < info.size(); i++){
65 switch( info[i].group_code ){
66 case 6:
67 strcpy( string," "); // Clear the string out
68 info[i].value_char(string);
69 strcpy(linetype,string);
70 break;
71 case 8:
72 strcpy( string," "); // Clear the string out
73 info[i].value_char(string);
74 strcpy(layer,string);
75 break;
76 case 10:
77 info[i].value_char(string);
78 x = atof(string);
79 if ( x < min_x ){
80 min_x = x;
81 }
82 if ( x > max_x ){
83 max_x = x;
84 }
85 break;
86 case 20:
87 info[i].value_char(string);
88 y = atof(string);
89 if ( y < min_y ){
90 min_y = y;
91 }
92 if ( y > max_y ){
93 max_y = y;
94 }
95 break;
96 case 30:
97 info[i].value_char(string);
98 z = atof(string);
99 break;
100 }
101 }
103 }
105 void entity::entity_display(){
106 std::cout << "\tlayer = " << layer << "\n\tlinetype = " << linetype << "\n\tx = " << x << "\ty = " << y << "\tz = " << z << std::flush;
107 }
109 double entity::ret_x(){
110 return x;
111 }
113 double entity::ret_y(){
114 return y;
115 }
117 double entity::ret_z(){
118 return z;
119 }
122 char* entity::ret_layer_name(char* string){
123 return( strcpy(string,layer) );
124 }
126 char* entity::ret_ltype_name(char* string){
127 return( strcpy(string,linetype) );
128 }
130 double entity::ret_min_x(){
131 return min_x;
132 }
134 double entity::ret_max_x(){
135 return max_x;
136 }
138 double entity::ret_min_y(){
139 return min_y;
140 }
142 double entity::ret_max_y(){
143 return max_y;
144 }
146 void entity::test_coord(double x, double y){
147 if ( x < min_x ){
148 min_x = x;
149 }
150 if ( x > max_x ){
151 max_x = x;
152 }
153 if ( y < min_y ){
154 min_y = y;
155 }
156 if ( y > max_y ){
157 max_y = y;
158 }
159 }
162 void entity::reset_extents(){
163 min_x = -1e20;
164 max_x = 1e20;
165 min_y = -1e20;
166 max_y = 1e20;
167 }
170 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
171 // VERTEX
172 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
175 vertex::vertex( std::vector< dxfpair > info){
176 // Get the vertex information
178 basic_entity( info );
179 static char string[10000];
180 for (int i = 0; i < info.size(); i++){
181 switch( info[i].group_code ){
182 case 42:
183 info[i].value_char(string);
184 bulge = atof(string);
185 break;
186 }
187 }
188 }
190 double vertex::ret_bulge(){
191 return bulge;
192 }
194 void vertex::display(){
195 std::cout << "VERTEX\n";
196 std::cout << "\tx = " << x << "\ty = " << y << "\tz = " << z << "\tbulge = " << bulge << std::flush;
197 }
204 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
205 // POLYLINE
206 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
209 // The polyline is handled a little differently compared to the other entities because a POLYLINE is built from a bunch of VERTEX entities
210 polyline::polyline( std::vector< std::vector< dxfpair > > sections ){
211 reset_extents();
212 // get the polyline information
213 basic_entity( sections[0] );
214 points.clear();
215 static char string[10000];
216 //char string[10000];
217 pline_flag = 0;
218 curves_flag = 0;
219 for (int i = 0; i < sections[0].size(); i++){
220 switch( sections[0][i].group_code ){
221 case 70:
222 sections[0][i].value_char(string);
223 pline_flag = atoi(string);
224 break;
225 case 40:
226 sections[0][i].value_char(string);
227 start_width = atoi(string);
228 break;
229 case 41:
230 sections[0][i].value_char(string);
231 end_width = atoi(string);
232 break;
233 case 75:
234 sections[0][i].value_char(string);
235 curves_flag = atoi(string);
236 break;
237 }
238 }
239 // Now add the VERTEX entities to the POLYLINE
240 for (int i = 1; i < sections.size(); i++){
241 points.push_back( vertex( sections[i] ) );
242 }
243 }
246 std::vector< vertex > polyline::ret_points(){
247 return points;
248 }
250 double polyline::bulge(int point){
251 return points[point].ret_bulge();
252 }
254 double polyline::bulge_r(int point){
255 // Make sure we are not exceeding the bounds of the points vector
256 if (point >= (points.size()-1)) return 0;
258 double dx = points[point+1].ret_x() - points[point].ret_x();
259 double dy = points[point+1].ret_y() - points[point].ret_y();
260 double bulge = points[point].ret_bulge();
261 double l = sqrt(dx*dx + dy*dy);
262 double r = fabs(l*(bulge*bulge+1)/bulge/4);
264 return r;
265 }
267 double polyline::bulge_start_angle(int point){
268 // Make sure we are not exceeding the bounds of the points vector
269 if (point >= (points.size()-1)) return 0;
271 double dx = points[point+1].ret_x() - points[point].ret_x();
272 double dy = points[point+1].ret_y() - points[point].ret_y();
273 double bulge = points[point].ret_bulge();
274 double xmid = dx/2 + points[point].ret_x();
275 double ymid = dy/2 + points[point].ret_y();
276 double l = sqrt(dx*dx + dy*dy);
277 double r = fabs(l*(bulge*bulge+1)/bulge/4);
279 double a = fabs(bulge*l/2);
280 double sb = bulge/fabs(bulge); //sign of bulge
281 double theta_p = 4*atan(bulge);
282 double theta_c;
283 dx != 0 ? theta_c = atan(dy/dx) : theta_c = 1.57079632679489661923; // Check to make sure that dx is not zero and will give a negative number
284 if (dx > 0) sb *= -1; // Correct for different point ordering and bulge direction
286 double cx = xmid + sb*(r-a)*sin(theta_c);
287 double cy = ymid - sb*(r-a)*cos(theta_c);
289 // Now calculate the angle
290 double theta = asin(points[point].ret_x()/r);
291 if (dy < 0) theta = 6.2831853 - theta; // The angle is greater than pi so fix this because max(asin) = pi
293 return theta;
294 }
296 double polyline::bulge_end_angle(int point){
297 // Make sure we are not exceeding the bounds of the points vector
298 if (point >= (points.size()-1)) return 0;
300 double dx = points[point+1].ret_x() - points[point].ret_x();
301 double dy = points[point+1].ret_y() - points[point].ret_y();
302 double bulge = points[point].ret_bulge();
303 double xmid = dx/2 + points[point].ret_x();
304 double ymid = dy/2 + points[point].ret_y();
305 double l = sqrt(dx*dx + dy*dy);
306 double r = fabs(l*(bulge*bulge+1)/bulge/4);
308 double a = fabs(bulge*l/2);
309 double sb = bulge/fabs(bulge); //sign of bulge
310 double theta_p = 4*atan(bulge);
311 double theta_c;
312 dx != 0 ? theta_c = atan(dy/dx) : theta_c = 1.57079632679489661923; // Check to make sure that dx is not zero and will give a negative number
313 if (dx > 0) sb *= -1; // Correct for different point ordering and bulge direction
315 double cx = xmid + sb*(r-a)*sin(theta_c);
316 double cy = ymid - sb*(r-a)*cos(theta_c);
318 // Now calculate the angle
319 double theta = asin(points[point+1].ret_x()/r);
320 if (dy < 0) theta = 6.2831853 - theta; // The angle is greater than pi so fix this because max(asin) = pi
322 return theta;
323 }
326 bool polyline::is_closed(){
327 // pline-flag holds info about closed pline in the 1 bit. The info is bit wise encoded so use bit wise operators
328 return bool(pline_flag&1);
329 }
331 void polyline::display(){
332 std::cout << "POLYLINE\n";
333 entity_display();
334 std::cout << std::endl;
335 for (int i = 0; i < points.size(); i++){
336 points[i].display();
337 std::cout << std::endl;
338 }
339 std::cout << std::endl;
340 }
345 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
346 // LWPOLYLINE
347 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
350 // The lwpolyline is different than the polyline because there are no vertex entities. Use the same basic process as the polyline but parse it out differently
351 lwpolyline::lwpolyline( std::vector< dxfpair > section ){
353 // First break up the data into the same format that is used by the polyline entity
354 std::vector< std::vector< dxfpair > > sections;
355 std::vector< dxfpair > first;
356 std::vector< dxfpair > others;
358 sections.clear();
359 first.clear();
360 others.clear();
362 int gc; // make a shorter name for group_code;
364 int vertex_part;
365 int already_found = 0;
367 for (int i = 0; i < section.size(); i++){
368 gc = section[i].group_code;
369 // Encode bitwise information to keep track of what has been found
370 vertex_part = 0;
371 if (gc == 10 ) vertex_part += 1;
372 if (gc == 20 ) vertex_part += 2;
373 if (gc == 30 ) vertex_part += 4;
374 if (gc == 40 ) vertex_part += 8;
375 if (gc == 41 ) vertex_part += 16;
376 if (gc == 42 ) vertex_part += 32;
377 //std::cout << "\n\nvertex_part = " << vertex_part << std::endl << "already_found = " << already_found << std::endl << "(vertex_part&already_found) = " << (vertex_part&already_found) << std::endl;
378 if ( vertex_part == 0 ){
379 // If header stuff has been found save it under first.
380 // I.E. in a polyline the first set of information is linetype and layer, all of what should be in here
381 first.push_back( section[i] );
382 }
383 else if ( (vertex_part&already_found) == 0 ){
384 // Now work on what would be the vertex information
385 // New information is still being found so keep saving it
386 others.push_back( section[i] );
387 //std::cout << "add to others" << std::endl;
388 already_found += vertex_part; // Keep track of what has been found
389 }
390 else{
391 sections.push_back( others );
392 //std::cout << "sections.size() = " << sections.size() << std::endl;
393 // Now clear the information out and start over
394 others.clear();
395 others.push_back( section[i] );
396 already_found = vertex_part;
397 }
398 }
400 // Now put on the last data that was found
401 if (others.size() > 0 ){
402 sections.push_back( others );
403 }
405 reset_extents();
406 basic_entity( first );
407 points.clear();
408 static char string[10000];
409 //char string[10000];
410 pline_flag = 0;
411 curves_flag = 0;
412 for (int i = 0; i < first.size(); i++){
413 switch( sections[0][i].group_code ){
414 case 70:
415 first[i].value_char(string);
416 pline_flag = atoi(string);
417 break;
418 case 40:
419 first[i].value_char(string);
420 start_width = atoi(string);
421 break;
422 case 41:
423 first[i].value_char(string);
424 end_width = atoi(string);
425 break;
426 case 75:
427 first[i].value_char(string);
428 curves_flag = atoi(string);
429 break;
430 }
431 }
432 // Now add the VERTEX entities to the POLYLINE
433 for (int i = 0; i < sections.size(); i++){
434 points.push_back( vertex( sections[i] ) );
435 }
436 }
440 std::vector< vertex > lwpolyline::ret_points(){
441 return points;
442 }
445 double lwpolyline::bulge(int point){
446 return points[point].ret_bulge();
447 }
449 double lwpolyline::bulge_r(int point){
450 // Make sure we are not exceeding the bounds of the points vector
451 if (point >= (points.size()-1)) return 0;
453 double dx = points[point+1].ret_x() - points[point].ret_x();
454 double dy = points[point+1].ret_y() - points[point].ret_y();
455 double bulge = points[point].ret_bulge();
456 double l = sqrt(dx*dx + dy*dy);
457 double r = fabs(l*(bulge*bulge+1)/bulge/4);
459 return r;
460 }
462 double lwpolyline::bulge_start_angle(int point){
463 // Make sure we are not exceeding the bounds of the points vector
464 if (point >= (points.size()-1)) return 0;
466 double dx = points[point+1].ret_x() - points[point].ret_x();
467 double dy = points[point+1].ret_y() - points[point].ret_y();
468 double bulge = points[point].ret_bulge();
469 double xmid = dx/2 + points[point].ret_x();
470 double ymid = dy/2 + points[point].ret_y();
471 double l = sqrt(dx*dx + dy*dy);
472 double r = fabs(l*(bulge*bulge+1)/bulge/4);
474 double a = fabs(bulge*l/2);
475 double sb = bulge/fabs(bulge); //sign of bulge
476 double theta_p = 4*atan(bulge);
477 double theta_c;
478 dx != 0 ? theta_c = atan(dy/dx) : theta_c = 1.57079632679489661923; // Check to make sure that dx is not zero and will give a negative number
479 if (dx > 0) sb *= -1; // Correct for different point ordering and bulge direction
481 double cx = xmid + sb*(r-a)*sin(theta_c);
482 double cy = ymid - sb*(r-a)*cos(theta_c);
484 // Now calculate the angle
485 double theta = asin(points[point].ret_x()/r);
486 if (dy < 0) theta = 6.2831853 - theta; // The angle is greater than pi so fix this because max(asin) = pi
488 return theta;
489 }
491 double lwpolyline::bulge_end_angle(int point){
492 // Make sure we are not exceeding the bounds of the points vector
493 if (point >= (points.size()-1)) return 0;
495 double dx = points[point+1].ret_x() - points[point].ret_x();
496 double dy = points[point+1].ret_y() - points[point].ret_y();
497 double bulge = points[point].ret_bulge();
498 double xmid = dx/2 + points[point].ret_x();
499 double ymid = dy/2 + points[point].ret_y();
500 double l = sqrt(dx*dx + dy*dy);
501 double r = fabs(l*(bulge*bulge+1)/bulge/4);
503 double a = fabs(bulge*l/2);
504 double sb = bulge/fabs(bulge); //sign of bulge
505 double theta_p = 4*atan(bulge);
506 double theta_c;
507 dx != 0 ? theta_c = atan(dy/dx) : theta_c = 1.57079632679489661923; // Check to make sure that dx is not zero and will give a negative number
508 if (dx > 0) sb *= -1; // Correct for different point ordering and bulge direction
510 double cx = xmid + sb*(r-a)*sin(theta_c);
511 double cy = ymid - sb*(r-a)*cos(theta_c);
513 // Now calculate the angle
514 double theta = asin(points[point+1].ret_x()/r);
515 if (dy < 0) theta = 6.2831853 - theta; // The angle is greater than pi so fix this because max(asin) = pi
517 return theta;
518 }
520 bool lwpolyline::is_closed(){
521 // pline-flag holds info about closed pline in the 1 bit. The info is bit wise encoded so use bit wise operators
522 return bool(pline_flag&1);
523 }
525 void lwpolyline::display(){
526 std::cout << "lwpolyline\n";
527 entity_display();
528 std::cout << std::endl;
529 for (int i = 0; i < points.size(); i++){
530 points[i].display();
531 std::cout << std::endl;
532 }
533 std::cout << std::endl;
534 }
538 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
539 // ARC
540 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
543 arc::arc( std::vector< dxfpair > info){
545 reset_extents();
546 basic_entity( info );
547 static char string[10000];
548 for (int i = 0; i < info.size(); i++){
549 switch( info[i].group_code ){
550 case 40:
551 info[i].value_char(string);
552 radius = atof(string);
553 test_coord(x+radius,y+radius);
554 test_coord(x-radius,y-radius);
555 break;
556 case 50:
557 info[i].value_char(string);
558 start_angle = atof(string);
559 break;
560 case 51:
561 info[i].value_char(string);
562 end_angle = atof(string);
563 break;
564 default:
565 break;
566 }
567 }
568 }
570 double arc::ret_radius(){
571 return radius;
572 }
575 double arc::ret_srt_ang(){
576 return start_angle;
577 }
580 double arc::ret_end_ang(){
581 return end_angle;
582 }
585 void arc::display(){
586 std::cout << "ARC\n";
587 entity_display();
588 std::cout << "\n\tradius = " << radius << "\tstart_angle = " << start_angle << "end_angle = " << end_angle << std::flush;
589 }
593 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
594 // CIRCLE
595 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
598 circle::circle( std::vector< dxfpair > info){
600 reset_extents();
601 basic_entity( info );
602 static char string[10000];
603 for (int i = 0; i < info.size(); i++){
604 switch( info[i].group_code ){
605 case 40:
606 info[i].value_char(string);
607 radius = atof(string);
608 test_coord(x+radius,y+radius);
609 test_coord(x-radius,y-radius);
610 break;
611 }
612 }
613 }
615 void circle::display(){
616 std::cout << "CIRCLE\n";
617 entity_display();
618 std::cout << "\n\tradius = " << radius << std::flush;
619 }
622 double circle::ret_radius(){
623 return radius;
624 }
627 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
628 // LINE
629 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
632 line::line( std::vector< dxfpair > info){
634 reset_extents();
635 basic_entity( info );
636 static char string[10000];
637 for (int i = 0; i < info.size(); i++){
638 switch( info[i].group_code ){
639 case 11:
640 info[i].value_char(string);
641 xf = atof(string);
642 break;
643 case 21:
644 info[i].value_char(string);
645 yf = atof(string);
646 break;
647 case 31:
648 info[i].value_char(string);
649 zf = atof(string);
650 break;
651 }
652 }
653 test_coord(xf,yf);
655 }
657 void line::display(){
658 std::cout << "LINE\n";
659 entity_display();
660 std::cout << "\n\txf = " << xf << "\tyf = " << yf << "\tzf = " << zf << std::flush;
661 }
664 double line::ret_xf(){
665 return xf;
666 }
668 double line::ret_yf(){
669 return yf;
670 }
672 double line::ret_zf(){
673 return zf;
674 }
679 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
680 // TEXT
681 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
683 text::text( std::vector< dxfpair > info){
685 reset_extents();
686 basic_entity( info );
687 static char string[10000];
688 for (int i = 0; i < info.size(); i++){
689 switch( info[i].group_code ){
690 case 1:
691 info[i].value_char(dxf_text); // directly copy the text into a string
692 break;
693 case 40:
694 info[i].value_char(string);
695 text_height = atof(string);
696 break;
697 case 50:
698 info[i].value_char(string);
699 text_rotation = atof(string);
700 break;
701 }
702 }
703 }
705 char * text::ret_text(char *string){
706 return( strcpy(string,dxf_text) );
707 }
709 double text::ret_txt_ht(){
710 return text_height;
711 }
713 double text::ret_txt_rot(){
714 return text_rotation;
715 }
717 void text::display(){
718 char tmp[10000];
719 std::cout << "TEXT\n";
720 entity_display();
721 std::cout << "\ndxf_text = " << ret_text(tmp) << std::flush;
722 }
724 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
725 // INSERT
726 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
728 insert::insert( std::vector< dxfpair > info){
730 basic_entity( info );
731 static char string[10000];
732 for (int i = 0; i < info.size(); i++){
733 switch( info[i].group_code ){
734 case 2:
735 info[i].value_char(block_name); // directly copy the text into a string
736 break;
737 case 41:
738 info[i].value_char(string);
739 x_scale_factor = atof(string);
740 break;
741 case 42:
742 info[i].value_char(string);
743 y_scale_factor = atof(string);
744 break;
745 case 43:
746 info[i].value_char(string);
747 z_scale_factor = atof(string);
748 break;
749 case 50:
750 info[i].value_char(string);
751 rotation = atof(string);
752 break;
753 }
754 }
755 }
758 char * insert::name(char *string){
759 return( strcpy(string,block_name) );
760 }
764 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
765 // entities
766 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
770 entities::entities(std::vector< std::vector< dxfpair > > sections){
771 // Read the main information about the entities section and then put it in the enetites class
772 int value;
773 char string[10000];
774 std::vector< dxfpair > single_line;
775 std::vector< std::vector< dxfpair > > pline;
776 pline.clear();
777 single_line.clear();
779 for(int i = 0; i < sections.size(); i++){
780 sections[i][0].value_char(string);
781 value = detmine_entity(string);
782 switch( value ){
783 case 0:
784 // Get everything from the start of the polyline designation to an SEQEND value
785 pline.clear(); // First clear out the pline information
786 do{
787 pline.push_back( sections[i] );
788 sections[++i][0].value_char(string);
789 }while( strncmp(string,"SEQEND",6) != 0 );
790 ents_polyline.push_back( polyline( pline ) );
791 break;
793 case 1:
794 // ARC
795 ents_arc.push_back( arc( sections[i] ) );
796 break;
798 case 2:
799 // CIRCLE
800 ents_circle.push_back( circle( sections[i] ) );
801 break;
803 case 3:
804 // LINE
805 ents_line.push_back( line( sections[i] ) );
806 break;
807 case 11:
808 // TEXT
809 ents_text.push_back( text( sections[i] ) );
810 break;
811 case 21:
812 // LWPOLYLINE
813 ents_lwpolyline.push_back( lwpolyline( sections[i] ) );
814 case 9:
815 // INSERT
816 ents_insert.push_back( insert( sections[i] ) );
818 //default:
819 // Nothing here
820 }
822 }
824 }
827 // Maybe all of this could be turned into fewer function by using templates, but no time right now. MBS
829 std::vector< polyline > entities::ret_plines(){
830 std::vector< polyline > pls;
831 pls.clear();
832 for(int i = 0; i < ents_polyline.size();i++){
833 pls.push_back( ents_polyline[i] );
834 }
835 return pls;
836 }
838 std::vector< lwpolyline > entities::ret_lwplines(){
839 std::vector< lwpolyline > lwpls;
840 lwpls.clear();
841 for(int i = 0; i < ents_lwpolyline.size();i++){
842 lwpls.push_back( ents_lwpolyline[i] );
843 }
844 return lwpls;
845 }
848 std::vector< arc > entities::ret_arcs(){
849 std::vector< arc > a;
850 a.clear();
851 for(int i = 0; i < ents_arc.size();i++){
852 a.push_back( ents_arc[i] );
853 }
854 return a;
855 }
857 std::vector< circle > entities::ret_circles(){
858 std::vector< circle > circs;
859 circs.clear();
860 for(int i = 0; i < ents_circle.size();i++){
861 circs.push_back( ents_circle[i] );
862 }
863 return circs;
864 }
867 std::vector< line > entities::ret_lines(){
868 std::vector< line > lns;
869 lns.clear();
870 for(int i = 0; i < ents_line.size();i++){
871 lns.push_back( ents_line[i] );
872 }
873 return lns;
874 }
877 std::vector< text > entities::ret_texts(){
878 std::vector< text > txts;
879 txts.clear();
880 for(int i = 0; i < ents_text.size();i++){
881 txts.push_back( ents_text[i] );
882 }
883 return txts;
884 }
887 std::vector< insert > entities::ret_inserts(){
888 std::vector< insert > ins;
889 ins.clear();
890 for(int i = 0; i < ents_insert.size();i++){
891 ins.push_back( ents_insert[i] );
892 }
893 return ins;
894 }
898 // Overload the return function to depend on the layer
899 std::vector< polyline > entities::ret_plines(char * layer){
900 char temp[10000];
901 std::vector< polyline > pls;
902 pls.clear();
904 for(int i = 0; i < ents_polyline.size();i++){
905 if ( strcmp( layer,ents_polyline[i].ret_layer_name(temp) ) == 0 ){
906 pls.push_back( ents_polyline[i] );
907 }
908 }
909 return pls;
910 }
913 std::vector< lwpolyline > entities::ret_lwplines(char * layer){
914 char temp[10000];
915 std::vector< lwpolyline > lwpls;
916 lwpls.clear();
918 for(int i = 0; i < ents_lwpolyline.size();i++){
919 if ( strcmp( layer,ents_lwpolyline[i].ret_layer_name(temp) ) == 0 ){
920 lwpls.push_back( ents_lwpolyline[i] );
921 }
922 }
923 return lwpls;
924 }
927 std::vector< circle > entities::ret_circles(char * layer){
928 char temp[10000];
929 std::vector< circle > circs;
930 circs.clear();
932 for(int i = 0; i < ents_circle.size();i++){
933 if ( strcmp( layer,ents_circle[i].ret_layer_name(temp) ) == 0 ){
934 circs.push_back( ents_circle[i] );
935 }
936 }
937 return circs;
938 }
941 std::vector< line > entities::ret_lines(char * layer){
942 char temp[10000];
943 std::vector< line > lns;
944 lns.clear();
946 for(int i = 0; i < ents_line.size();i++){
947 if ( strcmp( layer,ents_line[i].ret_layer_name(temp) ) == 0 ){
948 lns.push_back( ents_line[i] );
949 }
950 }
951 return lns;
952 }
955 std::vector< text > entities::ret_texts(char * layer){
956 char temp[10000];
957 std::vector< text > txts;
958 txts.clear();
960 for(int i = 0; i < ents_text.size();i++){
961 if ( strcmp( layer,ents_text[i].ret_layer_name(temp) ) == 0 ){
962 txts.push_back( ents_text[i] );
963 }
964 }
965 return txts;
966 }
969 /*std::vector< ellipse > entities::ret_ellipses(char * layer){
970 char temp[10000];
971 std::vector< polyline > pls;
972 pls.clear();
974 for(int i = 0; i < ents_polyline.size();i++){
975 if ( strcmp( layer,ents_polyline[i].ret_layer_name(temp) ) == 0 ){
976 pls.push_back( ents_polyline[i] );
977 }
978 }
979 return pls;
980 }*/
983 std::vector< arc > entities::ret_arcs(char * layer){
984 char temp[10000];
985 std::vector< arc > a;
986 a.clear();
988 for(int i = 0; i < ents_arc.size();i++){
989 if ( strcmp( layer,ents_arc[i].ret_layer_name(temp) ) == 0 ){
990 a.push_back( ents_arc[i] );
991 }
992 }
993 return a;
994 }
997 std::vector< insert > entities::ret_inserts(char * layer){
998 char temp[10000];
999 std::vector< insert > ins;
1000 ins.clear();
1002 for(int i = 0; i < ents_insert.size();i++){
1003 if ( strcmp( layer,ents_insert[i].ret_layer_name(temp) ) == 0 ){
1004 ins.push_back( ents_insert[i] );
1005 }
1006 }
1007 return ins;
1008 }
1013 void entities::display_all(){
1014 for (int i = 0; i < ents_polyline.size(); i++){
1015 ents_polyline[i].display();
1016 }
1017 std::cout << std::endl;
1018 for (int i = 0; i < ents_lwpolyline.size(); i++){
1019 ents_lwpolyline[i].display();
1020 }
1021 std::cout << std::endl;
1022 for (int i = 0; i < ents_circle.size(); i++){
1023 ents_circle[i].display();
1024 }
1025 std::cout << std::endl;
1026 for (int i = 0; i < ents_text.size(); i++){
1027 ents_text[i].display();
1028 }
1029 }