1 /*
2 * Code for the conversion of DXF information in the TABLES section
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 */
12 #include"tables.h"
13 #include<iostream>
18 int determine_table(char* value){
19 // Common Elements as far as I am concerend
20 if ( strncmp(value,"LAYER",5) == 0 ) return 0;
21 if ( strncmp(value,"LTYPE",5) == 0 ) return 1;
22 if ( strncmp(value,"STYLE",5) == 0 ) return 2;
23 if ( strncmp(value,"UCS",3) == 0 ) return 3;
24 if ( strncmp(value,"VIEW",4) == 0 ) return 4;
25 if ( strncmp(value,"VPORT",4) == 0 ) return 5;
26 if ( strncmp(value,"APPID",5) == 0 ) return 6;
27 if ( strncmp(value,"BLOCK_RECORD",12) == 0 ) return 7;
28 else return -1;
29 }
32 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
33 // TABLE
34 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
37 int table::ret_maxN(){
38 return max_number;
39 }
45 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
46 // LAYER
47 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
50 layer::layer( std::vector< dxfpair > info){
51 // Get the vertex information
53 //basic_entity( info );
54 //static char string[10000];
55 char string[10000];
56 for (int i = 0; i < info.size(); i++){
57 switch( info[i].group_code ){
58 case 2:
59 info[i].value_char(layer_name);
60 break;
61 case 6:
62 info[i].value_char(ltype_name);
63 break;
65 case 62:
66 info[i].value_char(string);
67 color_number = atoi(string);
68 //std::cout << "I found a color and its number = " << color_number << std::endl;
69 break;
70 case 290:
71 info[i].value_char(string);
72 plotting_flag = atoi(string);
73 break;
74 }
75 }
76 }
78 void layer::display(){
79 std::cout << "LAYER\n";
80 //std::cout << "\tx = " << x << "\ty = " << y << "\tz = " << z << "\tbulge = " << bulge << std::flush;
81 }
83 char* layer::name(char* string){
84 return( strcpy(string,layer_name) );
85 }
89 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
90 // LTYPE
91 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
94 ltype::ltype( std::vector< dxfpair > info){
95 // Get the linetype information
97 //static char string[10000];
98 char string[10000];
99 for (int i = 0; i < info.size(); i++){
100 switch( info[i].group_code ){
101 case 2:
102 info[i].value_char(ltype_name);
103 break;
104 case 3:
105 info[i].value_char(descriptive_txt);
106 break;
107 case 73:
108 info[i].value_char(string);
109 num_elements = atoi(string);
110 break;
111 case 40:
112 info[i].value_char(string);
113 pattern_length = atof(string);
114 break;
115 case 49:
116 info[i].value_char(string);
117 pattern.push_back( atof(string) );
118 break;
119 }
120 }
121 }
125 char* ltype::name(char* string){
126 return( strcpy(string,ltype_name) );
127 }
130 std::vector< double > ltype::ret_pattern(){
131 return pattern;
132 }
135 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
136 // tables
137 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
141 tables::tables(std::vector< std::vector< dxfpair > > sections){
142 // Read the main information about the entities section and then put it in the enetites class
143 int value;
144 char string[10000];
146 for(int i = 0; i < sections.size(); i++){
147 //std::cout << "start" << std::endl;
148 sections[i][0].value_char(string);
149 value = determine_table(string);
150 //std::cout << "sections.size() = " << sections.size() << std::endl << "i = " << i << std::endl << "string = " << string << std::endl;
151 switch( value ){
152 case 0:
153 // LAYER
154 //std::cout << "tables start layer " << std::endl;
155 tables_layer.push_back( layer( sections[i] ) );
156 //std::cout << "tables end layer " << std::endl;
157 break;
159 case 1:
160 // LTYPE
161 //std::cout << "tables start ltype " << std::endl;
162 tables_ltype.push_back( ltype( sections[i] ) );
163 //std::cout << "tables end ltype " << std::endl;
164 break;
166 //case 3:
167 // break;
169 default:
170 break;
171 // Nothing here
172 }
174 }
176 }
181 ltype tables::ret_ltype(char ltype_name[10000], char layer_name[10000]){
182 int string_len = 0;
183 char name[10000];
184 char temp[10000];
185 // The ltype information may be given in the entitity or in the layer information
186 // Assume that if there is a name defined in the linetype that it trumps any other layer information
187 if ( strlen(ltype_name) > 0 ) strcpy(name,ltype_name);
188 else strcpy(name,layer_name);
189 for (int i = 0; i < tables_ltype.size();i++){
190 string_len = strlen(tables_ltype[i].name(temp));
191 if (strncmp(tables_ltype[i].name(temp),name,string_len) == 0 ) return tables_ltype[i];
192 }
193 return tables_ltype[0];
194 }
197 layer tables::ret_layer(char layer_name[10000]){
198 int string_len = 0;
199 char temp[10000];
201 for (int i = 0; i < tables_layer.size();i++){
202 string_len = strlen(tables_layer[i].name(temp));
203 if (strncmp(tables_layer[i].name(temp),layer_name,string_len) == 0 ) return tables_layer[i];
204 }
205 return tables_layer[0];
206 }
209 std::vector< layer > tables::ret_layers(){
210 return tables_layer;
211 }