1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_filter.hxx"
26
27 #include <string.h>
28 #include <dxftblrd.hxx>
29
30 //----------------------------------DXFLType-----------------------------------
31
DXFLType()32 DXFLType::DXFLType()
33 {
34 pSucc=NULL;
35 sName[0]=0;
36 nFlags=0;
37 sDescription[0]=0;
38 nDashCount=0;
39 }
40
Read(DXFGroupReader & rDGR)41 void DXFLType::Read(DXFGroupReader & rDGR)
42 {
43 long nDashIndex=-1;
44
45 while (rDGR.Read()!=0)
46 {
47 switch (rDGR.GetG())
48 {
49 case 2: strncpy( sName, rDGR.GetS(), DXF_MAX_STRING_LEN + 1 ); break;
50 case 70: nFlags=rDGR.GetI(); break;
51 case 3: strncpy( sDescription, rDGR.GetS(), DXF_MAX_STRING_LEN + 1 ); break;
52 case 73:
53 if (nDashIndex!=-1) {
54 rDGR.SetError();
55 return;
56 }
57 nDashCount=rDGR.GetI();
58 if (nDashCount>DXF_MAX_DASH_COUNT)
59 nDashCount=DXF_MAX_DASH_COUNT;
60 nDashIndex=0;
61 break;
62 case 40: fPatternLength=rDGR.GetF(); break;
63 case 49:
64 if (nDashCount==-1) {
65 rDGR.SetError();
66 return;
67 }
68 if (nDashIndex<nDashCount)
69 fDash[nDashIndex++]=rDGR.GetF();
70 break;
71 }
72 }
73 }
74
75 //----------------------------------DXFLayer-----------------------------------
76
DXFLayer()77 DXFLayer::DXFLayer()
78 {
79 pSucc=NULL;
80 sName[0]=0;
81 nFlags=0;
82 nColor=-1;
83 sLineType[0]=0;
84 }
85
Read(DXFGroupReader & rDGR)86 void DXFLayer::Read(DXFGroupReader & rDGR)
87 {
88 while (rDGR.Read()!=0) {
89 switch(rDGR.GetG()) {
90 case 2: strncpy( sName, rDGR.GetS(), DXF_MAX_STRING_LEN + 1 ); break;
91 case 70: nFlags=rDGR.GetI(); break;
92 case 62: nColor=rDGR.GetI(); break;
93 case 6: strncpy( sLineType, rDGR.GetS(), DXF_MAX_STRING_LEN + 1 ); break;
94 }
95 }
96 }
97
98 //----------------------------------DXFStyle-----------------------------------
99
DXFStyle()100 DXFStyle::DXFStyle()
101 {
102 pSucc=NULL;
103 sName[0]=0;
104 nFlags=0;
105 fHeight=0.0;
106 fWidthFak=1.0;
107 fOblAngle=0.0;
108 nTextGenFlags=0;
109 fLastHeightUsed=0.0;
110 sPrimFontFile[0]=0;
111 sBigFontFile[0]=0;
112 }
113
Read(DXFGroupReader & rDGR)114 void DXFStyle::Read(DXFGroupReader & rDGR)
115 {
116 while (rDGR.Read()!=0) {
117 switch(rDGR.GetG()) {
118 case 2: strncpy( sName, rDGR.GetS(), DXF_MAX_STRING_LEN + 1 ); break;
119 case 70: nFlags=rDGR.GetI(); break;
120 case 40: fHeight=rDGR.GetF(); break;
121 case 41: fWidthFak=rDGR.GetF(); break;
122 case 50: fOblAngle=rDGR.GetF(); break;
123 case 71: nTextGenFlags=rDGR.GetI(); break;
124 case 42: fLastHeightUsed=rDGR.GetF(); break;
125 case 3: strncpy( sPrimFontFile, rDGR.GetS(), DXF_MAX_STRING_LEN + 1 ); break;
126 case 4: strncpy( sBigFontFile, rDGR.GetS(), DXF_MAX_STRING_LEN + 1 ); break;
127 }
128 }
129 }
130
131 //----------------------------------DXFVPort-----------------------------------
132
DXFVPort()133 DXFVPort::DXFVPort()
134 {
135 pSucc=NULL;
136
137 sName[0]=0;
138 nFlags=0;
139 fMinX=0;
140 fMinY=0;
141 fMaxX=0;
142 fMaxY=0;
143 fCenterX=0;
144 fCenterY=0;
145 fSnapBaseX=0;
146 fSnapBaseY=0;
147 fSnapSapcingX=0;
148 fSnapSpacingY=0;
149 fGridX=0;
150 fGridY=0;
151 aDirection=DXFVector(0,0,1);
152 aTarget=DXFVector(0,0,0);
153 fHeight=0;
154 fAspectRatio=0;
155 fLensLength=0;
156 fFrontClipPlane=0;
157 fBackClipPlane=0;
158 fTwistAngle=0;
159 nStatus=0;
160 nID=0;
161 nMode=0;
162 nCircleZoomPercent=0;
163 nFastZoom=0;
164 nUCSICON=0;
165 nSnap=0;
166 nGrid=0;
167 nSnapStyle=0;
168 nSnapIsopair=0;
169 }
170
Read(DXFGroupReader & rDGR)171 void DXFVPort::Read(DXFGroupReader & rDGR)
172 {
173 while (rDGR.Read()!=0) {
174 switch(rDGR.GetG()) {
175 case 2: strncpy( sName, rDGR.GetS(), DXF_MAX_STRING_LEN + 1); break;
176 case 70: nFlags=rDGR.GetI(); break;
177 case 10: fMinX=rDGR.GetF(); break;
178 case 20: fMinY=rDGR.GetF(); break;
179 case 11: fMaxX=rDGR.GetF(); break;
180 case 21: fMaxY=rDGR.GetF(); break;
181 case 12: fCenterX=rDGR.GetF(); break;
182 case 22: fCenterY=rDGR.GetF(); break;
183 case 13: fSnapBaseX=rDGR.GetF(); break;
184 case 23: fSnapBaseY=rDGR.GetF(); break;
185 case 14: fSnapSapcingX=rDGR.GetF(); break;
186 case 24: fSnapSpacingY=rDGR.GetF(); break;
187 case 15: fGridX=rDGR.GetF(); break;
188 case 25: fGridY=rDGR.GetF(); break;
189 case 16: aDirection.fx=rDGR.GetF(); break;
190 case 26: aDirection.fy=rDGR.GetF(); break;
191 case 36: aDirection.fz=rDGR.GetF(); break;
192 case 17: aTarget.fx=rDGR.GetF(); break;
193 case 27: aTarget.fy=rDGR.GetF(); break;
194 case 37: aTarget.fz=rDGR.GetF(); break;
195 case 40: fHeight=rDGR.GetF(); break;
196 case 41: fAspectRatio=rDGR.GetF(); break;
197 case 42: fLensLength=rDGR.GetF(); break;
198 case 43: fFrontClipPlane=rDGR.GetF(); break;
199 case 44: fBackClipPlane=rDGR.GetF(); break;
200 case 51: fTwistAngle=rDGR.GetF(); break;
201 case 68: nStatus=rDGR.GetI(); break;
202 case 69: nID=rDGR.GetI(); break;
203 case 71: nMode=rDGR.GetI(); break;
204 case 72: nCircleZoomPercent=rDGR.GetI(); break;
205 case 73: nFastZoom=rDGR.GetI(); break;
206 case 74: nUCSICON=rDGR.GetI(); break;
207 case 75: nSnap=rDGR.GetI(); break;
208 case 76: nGrid=rDGR.GetI(); break;
209 case 77: nSnapStyle=rDGR.GetI(); break;
210 case 78: nSnapIsopair=rDGR.GetI(); break;
211 }
212 }
213 }
214
215 //----------------------------------DXFTables----------------------------------
216
217
DXFTables()218 DXFTables::DXFTables()
219 {
220 pLTypes=NULL;
221 pLayers=NULL;
222 pStyles=NULL;
223 pVPorts=NULL;
224 }
225
226
~DXFTables()227 DXFTables::~DXFTables()
228 {
229 Clear();
230 }
231
232
Read(DXFGroupReader & rDGR)233 void DXFTables::Read(DXFGroupReader & rDGR)
234 {
235 DXFLType * * ppLT, * pLT;
236 DXFLayer * * ppLa, * pLa;
237 DXFStyle * * ppSt, * pSt;
238 DXFVPort * * ppVP, * pVP;
239
240 ppLT=&pLTypes;
241 while(*ppLT!=NULL) ppLT=&((*ppLT)->pSucc);
242
243 ppLa=&pLayers;
244 while(*ppLa!=NULL) ppLa=&((*ppLa)->pSucc);
245
246 ppSt=&pStyles;
247 while(*ppSt!=NULL) ppSt=&((*ppSt)->pSucc);
248
249 ppVP=&pVPorts;
250 while(*ppVP!=NULL) ppVP=&((*ppVP)->pSucc);
251
252 for (;;) {
253 while (rDGR.GetG()!=0) rDGR.Read();
254 if (strcmp(rDGR.GetS(),"EOF")==0 ||
255 strcmp(rDGR.GetS(),"ENDSEC")==0) break;
256 else if (strcmp(rDGR.GetS(),"LTYPE")==0) {
257 pLT=new DXFLType;
258 pLT->Read(rDGR);
259 *ppLT=pLT;
260 ppLT=&(pLT->pSucc);
261 }
262 else if (strcmp(rDGR.GetS(),"LAYER")==0) {
263 pLa=new DXFLayer;
264 pLa->Read(rDGR);
265 *ppLa=pLa;
266 ppLa=&(pLa->pSucc);
267 }
268 else if (strcmp(rDGR.GetS(),"STYLE")==0) {
269 pSt=new DXFStyle;
270 pSt->Read(rDGR);
271 *ppSt=pSt;
272 ppSt=&(pSt->pSucc);
273 }
274 else if (strcmp(rDGR.GetS(),"VPORT")==0) {
275 pVP=new DXFVPort;
276 pVP->Read(rDGR);
277 *ppVP=pVP;
278 ppVP=&(pVP->pSucc);
279 }
280 else rDGR.Read();
281 }
282 }
283
284
Clear()285 void DXFTables::Clear()
286 {
287 DXFLType * pLT;
288 DXFLayer * pLa;
289 DXFStyle * pSt;
290 DXFVPort * pVP;
291
292 while (pStyles!=NULL) {
293 pSt=pStyles;
294 pStyles=pSt->pSucc;
295 delete pSt;
296 }
297 while (pLayers!=NULL) {
298 pLa=pLayers;
299 pLayers=pLa->pSucc;
300 delete pLa;
301 }
302 while (pLTypes!=NULL) {
303 pLT=pLTypes;
304 pLTypes=pLT->pSucc;
305 delete pLT;
306 }
307 while (pVPorts!=NULL) {
308 pVP=pVPorts;
309 pVPorts=pVP->pSucc;
310 delete pVP;
311 }
312 }
313
314
SearchLType(const char * pName) const315 DXFLType * DXFTables::SearchLType(const char * pName) const
316 {
317 DXFLType * p;
318 for (p=pLTypes; p!=NULL; p=p->pSucc) {
319 if (strcmp(pName,p->sName)==0) break;
320 }
321 return p;
322 }
323
324
SearchLayer(const char * pName) const325 DXFLayer * DXFTables::SearchLayer(const char * pName) const
326 {
327 DXFLayer * p;
328 for (p=pLayers; p!=NULL; p=p->pSucc) {
329 if (strcmp(pName,p->sName)==0) break;
330 }
331 return p;
332 }
333
334
SearchVPort(const char * pName) const335 DXFVPort * DXFTables::SearchVPort(const char * pName) const
336 {
337 DXFVPort * p;
338 for (p=pVPorts; p!=NULL; p=p->pSucc) {
339 if (strcmp(pName,p->sName)==0) break;
340 }
341 return p;
342 }
343
344
345