]> Shamusworld >> Repos - architektonas/blob - src/base/rs_filterdxf1.cpp
3d65ea54c436aa2717310b1cc3c225d2403c3d89
[architektonas] / src / base / rs_filterdxf1.cpp
1 // rs_filterdxf1.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // (C) 2010 Underground Software
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  05/28/2010  Added this text. :-)
13 //
14
15 #include "rs_filterdxf1.h"
16
17 #include <iostream>
18 #include "rs_filterdxf.h"
19 #include "rs_font.h"
20 #include "rs_information.h"
21 #include "rs_utility.h"
22 #include "rs_system.h"
23 #include "rs_dimlinear.h"
24 #include "rs_dimaligned.h"
25 #include "rs_dimangular.h"
26 #include "rs_dimdiametric.h"
27 #include "rs_dimradial.h"
28
29 /**
30  * Default constructor.
31  */
32 RS_FilterDXF1::RS_FilterDXF1(): RS_FilterInterface()
33 {
34         RS_DEBUG->print("Setting up DXF 1 filter...");
35         graphic = NULL;
36         addImportFormat(RS2::FormatDXF1);
37 }
38
39 /**
40  * Implementation of the method used for RS_Import to communicate
41  * with this filter.
42  *
43  * @param graphic The graphic in which the entities from the file
44  * will be created or the graphics from which the entities are
45  * taken to be stored in a file.
46  */
47 bool RS_FilterDXF1::fileImport(Drawing& g, const QString& file, RS2::FormatType /*type*/)
48 {
49         RS_DEBUG->print("DXF1 Filter: importing file '%s'...", file.toLatin1().data());
50
51         this->graphic = &g;
52
53         fPointer = 0;
54         fBuf = 0;
55         fBufP = 0;
56         fSize = 0;
57         dosFile = false;
58         name = file;
59
60         if (readFileInBuffer())
61         {
62                 separateBuf();
63                 return readFromBuffer();
64         }
65
66         return false;
67 }
68
69
70
71 /**
72  * Reads a dxf1 file from buffer.
73  */
74 bool RS_FilterDXF1::readFromBuffer()
75 {
76         RS_DEBUG->print("\nDXF: Read from buffer");
77
78         bool      ret;                    // returned value
79         QString dxfLine;                // A line in the dxf file
80         QString dxfCode;                // A Code in the dxf file as string
81         int       code = -1;                // Dxf-code as number
82         double    vx1 = 0.0, vy1 = 0.0;       // Start point
83         double    vx2 = 0.0, vy2 = 0.0;       // End point
84         double    vcx = 0.0, vcy = 0.0;       // Centre
85         double    vcr = 0.0;                // Radius
86         double    va1 = 0.0, va2 = 0.0;       // Start / End Angle
87         //double    vab=0.0,                // Bulge
88         //           vpx=0.0, vpy=0.0;       // First Polyline point
89         //double    ax=0.0, ay=0.0;         // Current coordinate
90         //bool      plClose=false;          // Polyline closed-flag
91         QString lastLayer;              // Last used layer name (test adding only
92         //   if the new layer!=lastLayer)
93         //int       currentLayerNum=0;      // Current layer number
94         RS_Layer * currentLayer = 0;         // Pointer to current layer
95         //QList<RGraphic> blockList;        // List of blocks
96         //blockList.setAutoDelete( true );
97         //bool      oldColorNumbers=false;  // use old color numbers (qcad<1.5.3)
98         RS_Pen pen;
99
100         ///if(!add) graphic->clearLayers();
101
102         //graphic->addLayer(DEF_DEFAULTLAYER);
103
104         //RS_DEBUG->print( "\nDefault layer added" );
105
106         // Loaded graphics without unit information: load as unit less:
107         //graphic->setUnit( None );
108
109         RS_DEBUG->print("\nUnit set");
110
111         resetBufP();
112
113         if (fBuf)
114         {
115                 RS_DEBUG->print("\nBuffer OK");
116                 RS_DEBUG->print("\nBuffer: ");
117                 RS_DEBUG->print(fBuf);
118
119                 do
120                 {
121                         dxfLine = getBufLine();
122                         pen = RS_Pen(RS_Color(RS2::FlagByLayer), RS2::WidthByLayer, RS2::LineByLayer);
123
124                         RS_DEBUG->print("\ndxfLine: ");
125                         RS_DEBUG->print(dxfLine.toAscii().data());
126
127                         // $-Setting in the header of DXF found
128                         //
129                         if (!dxfLine.isEmpty() && dxfLine[0] == '$')
130                         {
131                                 // Units:
132                                 //
133                                 if (dxfLine == "$INSUNITS")
134                                 {
135                                         dxfCode = getBufLine();
136                                         if (!dxfCode.isEmpty())
137                                         {
138                                                 if (dxfCode.toInt() == 70)
139                                                 {
140                                                         dxfLine = getBufLine();
141                                                         if (!dxfLine.isEmpty())
142                                                         {
143                                                                 graphic->addVariable("$INSUNITS", dxfLine, 70);
144                                                                 /*
145                                                                                         switch( dxfLine.toInt() ) {
146                                                                                         case  0: graphic->setUnit( RS2::None );       break;
147                                                                                         case  1: graphic->setUnit( RS2::Inch );       break;
148                                                                                         case  2: graphic->setUnit( RS2::Foot );       break;
149                                                                                         case  3: graphic->setUnit( RS2::Mile );       break;
150                                                                                         case  4: graphic->setUnit( RS2::Millimeter ); break;
151                                                                                         case  5: graphic->setUnit( RS2::Centimeter ); break;
152                                                                                         case  6: graphic->setUnit( RS2::Meter );      break;
153                                                                                         case  7: graphic->setUnit( RS2::Kilometer );  break;
154                                                                                         case  8: graphic->setUnit( RS2::Microinch );  break;
155                                                                                         case  9: graphic->setUnit( RS2::Mil );        break;
156                                                                                         case 10: graphic->setUnit( RS2::Yard );       break;
157                                                                                         case 11: graphic->setUnit( RS2::Angstrom );   break;
158                                                                                         case 12: graphic->setUnit( RS2::Nanometer );  break;
159                                                                                         case 13: graphic->setUnit( RS2::Micron );     break;
160                                                                                         case 14: graphic->setUnit( RS2::Decimeter );  break;
161                                                                                         case 15: graphic->setUnit( RS2::Decameter );  break;
162                                                                                         case 16: graphic->setUnit( RS2::Hectometer ); break;
163                                                                                         case 17: graphic->setUnit( RS2::Gigameter );  break;
164                                                                                         case 18: graphic->setUnit( RS2::Astro );      break;
165                                                                                         case 19: graphic->setUnit( RS2::Lightyear );  break;
166                                                                                         case 20: graphic->setUnit( RS2::Parsec );     break;
167                                                                                         }
168
169                                                                                         graphic->setDimensionUnit( graphic->getUnit() );
170                                                                                         //graphic->setGridUnit( graphic->getUnit() );
171                                                                 */
172                                                         }
173                                                 }
174                                         }
175                                 }
176
177                                 // Dimenison Units:
178                                 //
179                                 else if (dxfLine == "$DIMALT")
180                                 {
181                                         dxfCode = getBufLine();
182                                         if (!dxfCode.isEmpty())
183                                         {
184                                                 if (dxfCode.toInt() == 70)
185                                                 {
186                                                         dxfLine = getBufLine();
187                                                         if (!dxfLine.isEmpty())
188                                                         {
189                                                                 graphic->addVariable("$DIMALT", dxfLine, 70);
190                                                                 /*
191                                                                                         switch( dxfLine.toInt() ) {
192                                                                                         case  0: graphic->setDimensionUnit( RS2::None );       break;
193                                                                                         case  1: graphic->setDimensionUnit( RS2::Inch );       break;
194                                                                                         case  2: graphic->setDimensionUnit( RS2::Foot );       break;
195                                                                                         case  3: graphic->setDimensionUnit( RS2::Mile );       break;
196                                                                                         case  4: graphic->setDimensionUnit( RS2::Millimeter ); break;
197                                                                                         case  5: graphic->setDimensionUnit( RS2::Centimeter ); break;
198                                                                                         case  6: graphic->setDimensionUnit( RS2::Meter );      break;
199                                                                                         case  7: graphic->setDimensionUnit( RS2::Kilometer );  break;
200                                                                                         case  8: graphic->setDimensionUnit( RS2::Microinch );  break;
201                                                                                         case  9: graphic->setDimensionUnit( RS2::Mil );        break;
202                                                                                         case 10: graphic->setDimensionUnit( RS2::Yard );       break;
203                                                                                         case 11: graphic->setDimensionUnit( RS2::Angstrom );   break;
204                                                                                         case 12: graphic->setDimensionUnit( RS2::Nanometer );  break;
205                                                                                         case 13: graphic->setDimensionUnit( RS2::Micron );     break;
206                                                                                         case 14: graphic->setDimensionUnit( RS2::Decimeter );  break;
207                                                                                         case 15: graphic->setDimensionUnit( RS2::Decameter );  break;
208                                                                                         case 16: graphic->setDimensionUnit( RS2::Hectometer ); break;
209                                                                                         case 17: graphic->setDimensionUnit( RS2::Gigameter );  break;
210                                                                                         case 18: graphic->setDimensionUnit( RS2::Astro );      break;
211                                                                                         case 19: graphic->setDimensionUnit( RS2::Lightyear );  break;
212                                                                                         case 20: graphic->setDimensionUnit( RS2::Parsec );     break;
213                                                                                         }
214                                                                 */
215                                                         }
216                                                 }
217                                         }
218                                 }
219
220                                 // Dimension Format:
221                                 //
222                                 /*else if( dxfLine=="$DIMLUNIT" ) {
223                                 if(dxfCode=getBufLine()) {
224                                         if( dxfCode.toInt()==70 ) {
225                                         if( dxfLine=getBufLine() ) {
226                                                 switch( dxfLine.toInt() ) {
227                                                 case 1: graphic->setDimensionFormat( Scientific ); break;
228                                                 case 2:
229                                                 case 3: graphic->setDimensionFormat( Decimal ); break;
230                                                 case 4:
231                                                 case 5: graphic->setDimensionFormat( Fractional ); break;
232                                                 default: break;
233                                                 }
234                                         }
235                                         }
236                                 }
237                         }*/
238
239                                 // Dimension Arrow Size:
240                                 //
241                                 else if (dxfLine == "$DIMASZ")
242                                 {
243                                         dxfCode = getBufLine();
244                                         if (!dxfCode.isEmpty() && dxfCode.toInt() == 40)
245                                         {
246                                                 dxfLine = getBufLine();
247                                                 if (!dxfLine.isEmpty())
248                                                 {
249                                                         graphic->addVariable("$DIMASZ", dxfLine, 40);
250                                                         //graphic->setDimensionArrowSize( dxfLine.toDouble() );
251                                                 }
252                                         }
253                                 }
254
255                                 // Dimension Scale:
256                                 //
257                                 /*
258                                 else if( dxfLine=="$DIMSCALE" ) {
259                                 if(dxfCode=getBufLine()) {
260                                         if( dxfCode.toInt()==40 ) {
261                                         if( dxfLine=getBufLine() ) {
262                                                 graphic->setDimensionScale( dxfLine.toDouble() );
263                                         }
264                                         }
265                                 }
266                         }
267                                 */
268
269                                 // Dimension Text Height:
270                                 //
271                                 else if (dxfLine == "$DIMTXT")
272                                 {
273                                         dxfCode = getBufLine();
274                                         if (!dxfCode.isEmpty())
275                                         {
276                                                 if (dxfCode.toInt() == 40)
277                                                 {
278                                                         dxfLine = getBufLine();
279                                                         if (!dxfLine.isEmpty())
280                                                         {
281                                                                 graphic->addVariable("$DIMTXT", dxfLine, 40);
282                                                                 //graphic->setDimensionTextHeight( dxfLine.toDouble() );
283                                                         }
284                                                 }
285                                         }
286                                 }
287
288                                 // Dimension exactness:
289                                 //
290                                 else if (dxfLine == "$DIMRND")
291                                 {
292                                         dxfCode = getBufLine();
293                                         if (dxfCode.toInt() == 40)
294                                         {
295                                                 dxfLine = getBufLine();
296                                                 if (!dxfLine.isEmpty())
297                                                 {
298                                                         graphic->addVariable("$DIMRND", dxfLine, 40);
299                                                         //if( dxfLine.toDouble()>0.000001 ) {
300                                                         //graphic->setDimensionExactness( dxfLine.toDouble() );
301                                                 }
302                                                 //}
303                                         }
304                                 }
305
306                                 // Dimension over length:
307                                 //
308                                 else if (dxfLine == "$DIMEXE")
309                                 {
310                                         dxfCode = getBufLine();
311                                                 if (dxfCode.toInt() == 40)
312                                                 {
313                                                         dxfLine = getBufLine();
314                                                         if (!dxfLine.isEmpty())
315                                                         {
316                                                                 graphic->addVariable("$DIMEXE", dxfLine, 40);
317                                                                 //graphic->setDimensionOverLength( dxfLine.toDouble() );
318                                                         }
319                                                 }
320                                 }
321
322                                 // Dimension under length:
323                                 //
324                                 else if( dxfLine=="$DIMEXO" )
325                                 {
326                                         dxfCode = getBufLine();
327                                                 if( dxfCode.toInt()==40 )
328                                                 {
329                                                         dxfLine = getBufLine();
330                                                         if (!dxfLine.isEmpty())
331                                                         {
332                                                                 graphic->addVariable("$DIMEXO", dxfLine, 40);
333                                                                 //graphic->setDimensionUnderLength( dxfLine.toDouble() );
334                                                         }
335                                                 }
336                                 }
337
338
339                                 // Angle dimension format:
340                                 //
341                                 else if( dxfLine=="$DIMAUNIT" )
342                                 {
343                                         dxfCode = getBufLine();
344                                                 if( dxfCode.toInt()==70 )
345                                                 {
346                                                         dxfLine = getBufLine();
347                                                         if (!dxfLine.isEmpty())
348                                                         {
349                                                                 graphic->addVariable("$DIMAUNIT", dxfLine, 70);
350                                                                 /*
351                                                                                         switch( dxfLine.toInt() ) {
352                                                                                         case 0: graphic->setAngleDimensionFormat( DecimalDegrees ); break;
353                                                                                         case 1: graphic->setAngleDimensionFormat( DegreesMinutesSeconds ); break;
354                                                                                         case 2: graphic->setAngleDimensionFormat( Gradians ); break;
355                                                                                         case 3: graphic->setAngleDimensionFormat( Radians ); break;
356                                                                                         case 4: graphic->setAngleDimensionFormat( Surveyor ); break;
357                                                                                         default: break;
358                                                                                         }
359                                                                 */
360                                                         }
361                                                 }
362                                 }
363
364                                 // Angle dimension exactness:
365                                 //
366                                 else if( dxfLine=="$DIMADEC" )
367                                 {
368                                         dxfCode = getBufLine();
369                                                 if( dxfCode.toInt()==70 )
370                                                 {
371                                                         dxfLine = getBufLine();
372                                                         if (!dxfLine.isEmpty())
373                                                         {
374                                                                 graphic->addVariable("$DIMADEC", dxfLine, 70);
375                                                                 //graphic->setAngleDimensionExactness( RS_Math::pow(0.1, dxfLine.toInt()) );
376                                                         }
377                                                 }
378                                 }
379
380                                 // Grid x/y:
381                                 //
382                                 else if (dxfLine == "$GRIDUNIT")
383                                 {
384                                         dxfCode = getBufLine();
385
386                                         if (dxfCode.toInt() == 10)
387                                         {
388                                                 dxfLine = getBufLine();
389
390                                                 if (!dxfLine.isEmpty())
391                                                 {
392                                                         double x = atof(dxfLine.toAscii().data());
393                                                         dxfLine = getBufLine();
394
395                                                         if (!dxfLine.isEmpty())
396                                                         {
397                                                                 double y = atof(dxfLine.toAscii().data());
398
399                                                                 graphic->addVariable("$GRIDUNIT", Vector(x, y), 10);
400                                                         }
401                                                 }
402                                         }
403                                 }
404                                 /*
405                                                         double gx=dxfLine.toDouble();
406                                                         if (gx<0.0001) gx=0.0001;
407                                                         graphic->setMinGridX(gx);
408                                                         graphic->setGridFormat( Fractional );
409
410                                                         for( double q=0.00000001; q<=100000.0; q*=10.0 ) {
411                                                         if( mtCompFloat(gx, q, q/1000.0) ) {
412                                                                 graphic->setGridFormat( Decimal );
413                                                                 break;
414                                                         }
415                                                         }
416
417                                                 }
418                                                 }
419                                         }
420                                         if(dxfCode=getBufLine()) {
421                                                 if( dxfCode.toInt()==20 ) {
422                                                 if( dxfLine=getBufLine() ) {
423                                                         double gy=dxfLine.toDouble();
424                                                         if (gy<0.0001) gy=0.0001;
425                                                         graphic->setMinGridY(gy);
426                                                 }
427                                                 }
428                                         }
429                                 */
430
431                                 // Page limits min x/y:
432                                 //
433                                 /*else if( dxfLine=="$PLIMMIN" ) {
434                                 if(dxfCode=getBufLine()) {
435                                         if( dxfCode.toInt()==10 ) {
436                                         if( dxfLine=getBufLine() ) {
437                                                 graphic->setPageOriginX( dxfLine.toDouble() );
438                                         }
439                                         }
440                                 }
441                                 if(dxfCode=getBufLine()) {
442                                         if( dxfCode.toInt()==20 ) {
443                                         if( dxfLine=getBufLine() ) {
444                                                 graphic->setPageOriginY( dxfLine.toDouble() );
445                                         }
446                                         }
447                                 }
448                         }
449                                 */
450
451                                 // Page limits min x/y:
452                                 //
453                                 /*
454                                         else if( dxfLine=="$PLIMMAX" ) {
455                                                 if(dxfCode=getBufLine()) {
456                                                 if( dxfCode.toInt()==10 ) {
457                                                         if( dxfLine=getBufLine() ) {
458                                                         graphic->setPageSizeX( dxfLine.toDouble() - graphic->getPageOriginX() );
459                                                         }
460                                                 }
461                                                 }
462                                                 if(dxfCode=getBufLine()) {
463                                                 if( dxfCode.toInt()==20 ) {
464                                                         if( dxfLine=getBufLine() ) {
465                                                         graphic->setPageSizeY( dxfLine.toDouble() - graphic->getPageOriginY() );
466                                                         }
467                                                 }
468                                                 }
469                                         }
470                                 */
471
472                                 // Paper space scale:
473                                 //
474                                 /*
475                                         else if( dxfLine=="$PSVPSCALE" ) {
476                                                 if(dxfCode=getBufLine()) {
477                                                 if( dxfCode.toInt()==40 ) {
478                                                         if( dxfLine=getBufLine() ) {
479                                                         graphic->setPaperSpace( dxfLine.toDouble() );
480                                                         }
481                                                 }
482                                                 }
483                                         }
484                                 */
485
486                         }
487
488                         // Entity
489                         //
490                         else if (!dxfLine.isEmpty() &&
491                                         dxfLine[0] >= 'A' && dxfLine[0] <= 'Z')
492                         {
493                                 if (dxfLine == "EOF")
494                                 {
495                                         // End of file reached
496                                         //
497                                 }
498
499                                 // ------
500                                 // Layer:
501                                 // ------
502                                 else if (dxfLine == "LAYER")
503                                 {
504                                         currentLayer = 0;
505                                         do
506                                         {
507                                                 dxfCode = getBufLine();
508                                                 if(!dxfCode.isEmpty())
509                                                         code = dxfCode.toInt();
510                                                 if(!dxfCode.isEmpty() && code != 0)
511                                                 {
512                                                         dxfLine = getBufLine();
513                                                         if (!dxfLine.isEmpty())
514                                                         {
515                                                                 switch(code)
516                                                                 {
517                                                                 case  2:  // Layer name
518                                                                         if (dxfLine=="(null)" || dxfLine=="default") {
519                                                                                 dxfLine = "0";
520                                                                         }
521                                                                         graphic->addLayer(new RS_Layer(dxfLine));
522                                                                         graphic->activateLayer(dxfLine);
523                                                                         currentLayer = graphic->getActiveLayer();
524                                                                         lastLayer=dxfLine;
525                                                                         break;
526                                                                 case 70:  // Visibility
527                                                                         /*
528                                                                         if(dxfLine.toInt()&5) {
529                                                                         if(currentLayerNum>=0 && currentLayerNum<DEF_MAXLAYERS) {
530                                                                                 graphic->layer[currentLayerNum].DelFlag(Y_VISIBLE);
531                                                                         }
532                                                                 }
533                                                                         */
534                                                                         break;
535                                                                 case  6:  // style
536                                                                         //if(currentLayer)
537                                                                         //currentLayer->setStyle( graphic->nameToStyle(dxfLine) );
538                                                                         pen.setLineType(RS_FilterDXF::nameToLineType(dxfLine));
539                                                                         break;
540                                                                 case 39:  // Thickness
541                                                                         //if(currentLayer) currentLayer->setWidth(dxfLine.toInt());
542                                                                         pen.setWidth(RS_FilterDXF::numberToWidth(dxfLine.toInt()));
543                                                                         break;
544                                                                 case 62:  // Color
545                                                                         pen.setColor(RS_FilterDXF::numberToColor(dxfLine.toInt()));
546                                                                         //if(currentLayer) {
547                                                                         //      currentLayer->setColor( graphic->numberToColor(dxfLine.toInt(), !oldColorNumbers));
548                                                                         //}
549                                                                         break;
550                                                                 default:
551                                                                         break;
552                                                                 }
553                                                         }
554                                                 }
555                                         }
556                                         while(!dxfCode.isEmpty() && code != 0);
557
558                                         if (currentLayer)
559                                         {
560                                                 currentLayer->setPen(pen);
561                                         }
562                                         //graphic->setStyle("CONTINOUS");
563                                         //graphic->setWidth(0);
564                                         //graphic->setColor(0, false);
565                                 }
566
567                                 // ------
568                                 // Point:
569                                 // ------
570                                 else if(dxfLine=="POINT") {
571                                         do {
572                                                 dxfCode=getBufLine();
573                                                 if(!dxfCode.isEmpty())
574                                                         code=dxfCode.toInt();
575                                                 if(!dxfCode.isEmpty() && code!=0) {
576                                                         dxfLine=getBufLine();
577                                                         if(!dxfLine.isEmpty()) {
578                                                                 switch(code) {
579                                                                 case  6:  // style
580                                                                         pen.setLineType(RS_FilterDXF::nameToLineType(dxfLine));
581                                                                         break;
582                                                                 case  8:  // Layer
583                                                                         //if(dxfLine!=lastLayer) {
584                                                                         if (dxfLine=="(null)" || dxfLine=="default") {
585                                                                                 dxfLine = "0";
586                                                                         }
587                                                                         graphic->activateLayer(dxfLine);
588                                                                         //lastLayer=dxfLine;
589                                                                         //}
590                                                                         break;
591                                                                 case 10:  // X1
592                                                                         dxfLine.replace( QRegExp(","), "." );
593                                                                         vx1 = dxfLine.toDouble();
594                                                                         break;
595                                                                 case 20:  // Y1
596                                                                         dxfLine.replace( QRegExp(","), "." );
597                                                                         vy1 = dxfLine.toDouble();
598                                                                         break;
599                                                                 case 39:  // Thickness
600                                                                         pen.setWidth(RS_FilterDXF::numberToWidth(dxfLine.toInt()));
601                                                                         break;
602                                                                 case 62:  // Color
603                                                                         pen.setColor(RS_FilterDXF::numberToColor(dxfLine.toInt()));
604                                                                         break;
605                                                                 default:
606                                                                         break;
607                                                                 }
608                                                         }
609                                                 }
610                                         }
611                                         while(!dxfCode.isEmpty() && code != 0);
612
613                                         graphic->setActivePen(pen);
614                                         graphic->addEntity(new RS_Point(graphic,
615                                                                                                         RS_PointData(Vector(vx1, vy1))));
616                                 }
617
618                                 // -----
619                                 // Line:
620                                 // -----
621                                 else if(dxfLine=="LINE") {
622                                         do {
623                                                 dxfCode=getBufLine();
624
625                                                 if(!dxfCode.isEmpty())
626                                                         code=dxfCode.toInt();
627                                                 if(!dxfCode.isEmpty() && code!=0) {
628
629                                                         dxfLine=getBufLine();
630
631                                                         if(!dxfLine.isEmpty()) {
632                                                                 switch(code) {
633                                                                 case  6:  // style
634                                                                         pen.setLineType(RS_FilterDXF::nameToLineType(dxfLine));
635                                                                         break;
636                                                                 case  8:  // Layer
637                                                                         //if(dxfLine!=lastLayer) {
638                                                                         if (dxfLine=="(null)" || dxfLine=="default") {
639                                                                                 dxfLine = "0";
640                                                                         }
641                                                                         graphic->activateLayer(dxfLine);
642                                                                         //lastLayer=dxfLine;
643                                                                         //}
644                                                                         break;
645                                                                 case 10:  // X1
646                                                                         dxfLine.replace( QRegExp(","), "." );
647                                                                         vx1 = dxfLine.toDouble();
648                                                                         break;
649                                                                 case 20:  // Y1
650                                                                         dxfLine.replace( QRegExp(","), "." );
651                                                                         vy1 = dxfLine.toDouble();
652                                                                         break;
653                                                                 case 11:  // X2
654                                                                         dxfLine.replace( QRegExp(","), "." );
655                                                                         vx2 = dxfLine.toDouble();
656                                                                         break;
657                                                                 case 21:  // Y2
658                                                                         dxfLine.replace( QRegExp(","), "." );
659                                                                         vy2 = dxfLine.toDouble();
660                                                                         break;
661                                                                 case 39:  // Thickness
662                                                                         pen.setWidth(RS_FilterDXF::numberToWidth(dxfLine.toInt()));
663                                                                         break;
664                                                                 case 62:  // Color
665                                                                         pen.setColor(RS_FilterDXF::numberToColor(dxfLine.toInt()));
666                                                                         break;
667                                                                 default:
668                                                                         break;
669                                                                 }
670                                                         }
671                                                 }
672                                         } while(!dxfCode.isEmpty() && code!=0);
673
674                                         //if(!mtCompFloat(vx1, vx2) || !mtCompFloat(vy1, vy2)) {
675                                         //graphic->addLine(vx1, vy1, vx2, vy2, currentLayerNum, add);
676                                         graphic->setActivePen(pen);
677                                         graphic->addEntity(new RS_Line(graphic,
678                                                                                                 RS_LineData(Vector(vx1, vy1), Vector(vx2, vy2))));
679                                         //}
680                                 }
681
682
683                                 // ----
684                                 // Arc:
685                                 // ----
686                                 else if(dxfLine=="ARC") {
687                                         do {
688                                                 dxfCode=getBufLine();
689                                                 if(!dxfCode.isEmpty())
690                                                         code=dxfCode.toInt();
691                                                 if(!dxfCode.isEmpty() && code!=0) {
692                                                         dxfLine=getBufLine();
693                                                         if(!dxfLine.isEmpty()) {
694                                                                 switch(code) {
695                                                                 case  6:  // style
696                                                                         pen.setLineType(RS_FilterDXF::nameToLineType(dxfLine));
697                                                                         break;
698                                                                 case  8:  // Layer
699                                                                         //if(dxfLine!=lastLayer) {
700                                                                         if (dxfLine=="(null)" || dxfLine=="default") {
701                                                                                 dxfLine = "0";
702                                                                         }
703                                                                         graphic->activateLayer(dxfLine);
704                                                                         //lastLayer=dxfLine;
705                                                                         //}
706                                                                         break;
707                                                                 case 10:  // Centre X
708                                                                         dxfLine.replace( QRegExp(","), "." );
709                                                                         vcx = dxfLine.toDouble();
710                                                                         break;
711                                                                 case 20:  // Centre Y
712                                                                         dxfLine.replace( QRegExp(","), "." );
713                                                                         vcy = dxfLine.toDouble();
714                                                                         break;
715                                                                 case 40:  // Radius
716                                                                         dxfLine.replace( QRegExp(","), "." );
717                                                                         vcr = dxfLine.toDouble();
718                                                                         break;
719                                                                 case 50:  // Start Angle
720                                                                         dxfLine.replace( QRegExp(","), "." );
721                                                                         va1 = RS_Math::correctAngle(dxfLine.toDouble()/ARAD);
722                                                                         break;
723                                                                 case 51:  // End Angle
724                                                                         dxfLine.replace( QRegExp(","), "." );
725                                                                         va2 = RS_Math::correctAngle(dxfLine.toDouble()/ARAD);
726                                                                         break;
727                                                                 case 39:  // Thickness
728                                                                         pen.setWidth(RS_FilterDXF::numberToWidth(dxfLine.toInt()));
729                                                                         break;
730                                                                 case 62:  // Color
731                                                                         pen.setColor(RS_FilterDXF::numberToColor(dxfLine.toInt()));
732                                                                         break;
733                                                                 default:
734                                                                         break;
735                                                                 }
736                                                         }
737                                                 }
738                                         } while(!dxfCode.isEmpty() && code!=0);
739                                         //if(vcr>0.0 && !mtCompFloat(va1, va2)) {
740                                         //  graphic->addArc(vcx, vcy, vcr, va1, va2, false, currentLayerNum, add);
741                                         //}
742                                         graphic->setActivePen(pen);
743                                         graphic->addEntity(new RS_Arc(graphic,
744                                                                                                 RS_ArcData(Vector(vcx, vcy),
745                                                                                                                         vcr, va1, va2, false)));
746                                 }
747
748                                 // -------
749                                 // Circle:
750                                 // -------
751                                 else if(dxfLine=="CIRCLE") {
752                                         do {
753                                                 dxfCode=getBufLine();
754                                                 if(!dxfCode.isEmpty())
755                                                         code=dxfCode.toInt();
756                                                 if(!dxfCode.isEmpty() && code!=0) {
757                                                         dxfLine=getBufLine();
758                                                         if(!dxfLine.isEmpty()) {
759                                                                 switch(code) {
760                                                                 case  6:  // style
761                                                                         pen.setLineType(RS_FilterDXF::nameToLineType(dxfLine));
762                                                                         break;
763                                                                 case  8:  // Layer
764                                                                         //if(dxfLine!=lastLayer) {
765                                                                         if (dxfLine=="(null)" || dxfLine=="default") {
766                                                                                 dxfLine = "0";
767                                                                         }
768                                                                         graphic->activateLayer(dxfLine);
769                                                                         //lastLayer=dxfLine;
770                                                                         //}
771                                                                         break;
772                                                                 case 10:  // Centre X
773                                                                         dxfLine.replace( QRegExp(","), "." );
774                                                                         vcx = dxfLine.toDouble();
775                                                                         break;
776                                                                 case 20:  // Centre Y
777                                                                         dxfLine.replace( QRegExp(","), "." );
778                                                                         vcy = dxfLine.toDouble();
779                                                                         break;
780                                                                 case 40:  // Radius
781                                                                         dxfLine.replace( QRegExp(","), "." );
782                                                                         vcr = dxfLine.toDouble();
783                                                                         break;
784                                                                 case 39:  // Thickness
785                                                                         pen.setWidth(RS_FilterDXF::numberToWidth(dxfLine.toInt()));
786                                                                         break;
787                                                                 case 62:  // Color
788                                                                         pen.setColor(RS_FilterDXF::numberToColor(dxfLine.toInt()));
789                                                                         break;
790                                                                 default:
791                                                                         break;
792                                                                 }
793                                                         }
794                                                 }
795                                         } while(!dxfCode.isEmpty() && code!=0);
796                                         /*if(vcr>0.0) {
797                                         graphic->addCircle(vcx, vcy, vcr, 0.0, 360.0, false, currentLayerNum, add);
798                                 }*/
799                                         graphic->setActivePen(pen);
800                                         graphic->addEntity(new RS_Circle(graphic,
801                                                                                                         RS_CircleData(Vector(vcx, vcy),
802                                                                                                                                 vcr)));
803                                 }
804
805
806                                 // ------
807                                 // Hatch:
808                                 // ------
809                                 /*
810                                 if(dxfLine=="HATCH") {
811                                 do {
812                                         dxfCode=getBufLine();
813                                         if(dxfCode) code=dxfCode.toInt();
814                                         if(dxfCode && code!=0) {
815                                         dxfLine=getBufLine();
816                                         if(dxfLine) {
817                                                 switch(code) {
818                                                 case  8:  // Layer
819                                                 //  if(dxfLine!=lastLayer) {
820                                                                         if (dxfLine=="(null)" || dxfLine=="default") {
821                                                                                 dxfLine = "0";
822                                                                         }
823                                                         graphic->activateLayer(dxfLine);
824                                                         //lastLayer=dxfLine;
825                                                         //}
826                                                         break;
827                                                 case 10:  // X1
828                                                         vx1 = dxfLine.toDouble();
829                                                         break;
830                                                 case 20:  // Y1
831                                                         vy1 = dxfLine.toDouble();
832                                                         //graphic->Vec[vc].CreatePoint(vy1, vx1, currentLayerNum);
833                                                         //if(vc<vElements-1) ++vc;
834                                                         break;
835                                                 case 11:  // X2
836                                                         vx2 = dxfLine.toDouble();
837                                                         break;
838                                                 case 21:  // Y2
839                                                         vy2 = dxfLine.toDouble();
840                                                         //graphic->Vec[vc].CreatePoint(vy2, vx2, currentLayerNum);
841                                                         //if(vc<vElements-1) ++vc;
842                                                         break;
843                                                 default:
844                                                         break;
845                                                 }
846                                         }
847                                         }
848                                 }while(dxfCode && code!=0);
849                                 / *
850                                 if(!mt.CompFloat(vx1, vx2) || !mt.CompFloat(vy1, vy2)) {
851                                         graphic->Vec[vc].CreateLine(vx1, vy1, vx2, vy2, currentLayerNum);
852                                         if(vc<vElements-1) ++vc;
853                                 }
854                                 if(++updProgress==1000) {
855                                         np->getStateWin()->UpdateProgressBar((int)(pcFact*vc)+25);
856                                         updProgress=0;
857                                 }
858                                 * /
859                         }
860                                 */
861
862
863                                 // -----
864                                 // Text:
865                                 // -----
866                                 else if(dxfLine=="TEXT") {
867
868                                         QString vtext;          // the text
869                                         char  vtextStyle[256];  // text style (normal_ro, cursive_ri, normal_st, ...)
870                                         double vheight=10.0;     // text height
871                                         double vtextAng=0.0;     // text angle
872                                         //double vradius=0.0;      // text radius
873                                         //double vletterspace=2.0; // Text letter space
874                                         //double vwordspace=6.0;   // Text wordspace
875                                         QString vfont;         // font "normal", "cursive", ...
876                                         RS2::HAlign vhalign=RS2::HAlignLeft;
877                                         // alignment (0=left, 1=center, 2=right)
878                                         //int   vattachement=7;   // 1=top left, 2, 3, 4, 5, 6, 7, 8, 9=bottom right
879                                         //uint  vfl=0;            // special flags
880                                         bool  codeSeven=false;  // Have we found a code seven?
881
882                                         vtextStyle[0] = '\0';
883                                         vfont="normal";
884
885                                         do {
886                                                 dxfCode=getBufLine();
887                                                 if(!dxfCode.isEmpty())
888                                                         code=dxfCode.toInt();
889                                                 if(!dxfCode.isEmpty() && code!=0) {
890                                                         if(code!=1 && code!=3 && code!=7)
891                                                                 dxfLine=getBufLine();
892                                                         if(!dxfLine.isEmpty() || code==1 || code==3 || code==7) {
893
894                                                                 switch(code)
895                                                                 {
896                                                                 case  1:  // Text itself
897                                                                         vtext = getBufLine();
898                                                                         strDecodeDxfString(vtext);
899                                                                         break;
900
901                                                                 case  3:  // Text parts (always 250 chars)
902                                                                         vtext = getBufLine();
903                                                                         break;
904
905                                                                 case  6:  // style
906                                                                         pen.setLineType(RS_FilterDXF::nameToLineType(dxfLine));
907                                                                         break;
908
909                                                                 case  7:
910                                                                         // Text style (normal_ro#50.0,
911                                                                         //    cursive_ri#20.0, normal_st)
912                                                                         qstrncpy(vtextStyle, getBufLine().toAscii().data(), 249);
913
914                                                                         // get font typ:
915                                                                         //
916                                                                         {
917                                                                                 char dummy[256];
918                                                                                 sscanf(vtextStyle, "%[^_#\n]", dummy);
919                                                                                 vfont = dummy;
920                                                                         }
921
922                                                                         // get text style:
923                                                                         //
924                                                                         /*
925                                                                                                                         if(strstr(vtextStyle, "_ro"))
926                                                                                                                                 vfl=vfl|E_ROUNDOUT;
927                                                                                                                         else if(strstr(vtextStyle, "_ri"))
928                                                                                                                                 vfl=vfl|E_ROUNDIN;
929                                                                                                                         else
930                                                                                                                                 vfl=vfl|E_STRAIGHT;
931                                                                         */
932
933
934                                                                         /*if(strstr(vtextStyle, "_fix")) {
935                                                                                 vfl=vfl|E_FIXEDWIDTH;
936                                                                 }*/
937
938                                                                         // get radius, letterspace, wordspace:
939                                                                         //
940                                                                         {
941                                                                                 char * ptr;  // pointer to value
942                                                                                 ptr = strchr(vtextStyle, '#');
943
944                                                                                 if (ptr)
945                                                                                 {
946                                                                                         // Parse radius
947                                                                                         /*if(vfl&E_ROUNDOUT || vfl&E_ROUNDIN) {
948                                                                                                 ++ptr;
949                                                                                                 if(ptr[0]) {
950                                                                                                         sscanf(ptr, "%lf", &vradius);
951                                                                                                 }
952                                                                                                 ptr = strchr(ptr, '#');
953                                                                                 }*/
954                                                                                         /*if(ptr) {
955                                                                                                 // Parse letter space:
956                                                                                                 ++ptr;
957                                                                                                 if(ptr[0]) {
958                                                                                                         sscanf(ptr, "%lf", &vletterspace);
959                                                                                                 }
960                                                                                                 // Parse word space:
961                                                                                                 ptr = strchr(ptr, '#');
962                                                                                                 if(ptr) {
963                                                                                                         ++ptr;
964                                                                                                         if(ptr[0]) {
965                                                                                                                 sscanf(ptr, "%lf", &vwordspace);
966                                                                                                         }
967                                                                                                 }
968                                                                                 }*/
969                                                                                 }
970                                                                         }
971                                                                         codeSeven = true;
972                                                                         break;
973
974                                                                 case  8:  // Layer
975                                                                         //if(dxfLine!=lastLayer) {
976                                                                         if (dxfLine == "(null)" || dxfLine == "default")
977                                                                         {
978                                                                                 dxfLine = "0";
979                                                                         }
980
981                                                                         graphic->activateLayer(dxfLine);
982                                                                         //lastLayer=dxfLine;
983                                                                         //}
984                                                                         break;
985
986                                                                 case 10:  // X1
987                                                                         dxfLine.replace( QRegExp(","), "." );
988                                                                         vx1 = dxfLine.toDouble();
989                                                                         break;
990                                                                 case 20:  // Y1
991                                                                         dxfLine.replace( QRegExp(","), "." );
992                                                                         vy1 = dxfLine.toDouble();
993                                                                         break;
994                                                                 case 40:  // height
995                                                                         dxfLine.replace( QRegExp(","), "." );
996                                                                         vheight = dxfLine.toDouble();
997                                                                         /*if(!codeSeven) {
998                                                                                 vletterspace = vheight*0.2;
999                                                                                 vwordspace = vheight*0.6;
1000                                                                 }*/
1001                                                                         break;
1002                                                                 case 50:  // angle
1003                                                                         dxfLine.replace( QRegExp(","), "." );
1004                                                                         vtextAng = dxfLine.toDouble() / ARAD;
1005                                                                         break;
1006                                                                 case 72:  {// alignment
1007                                                                                 //if(!mtext) {
1008                                                                                 int v = dxfLine.toInt();
1009                                                                                 if(v==1)
1010                                                                                         vhalign = RS2::HAlignCenter;
1011                                                                                 else if(v==2)
1012                                                                                         vhalign = RS2::HAlignRight;
1013                                                                                 else
1014                                                                                         vhalign = RS2::HAlignLeft;
1015                                                                                 //}
1016                                                                         }
1017                                                                         break;
1018                                                                 case 39:  // Thickness
1019                                                                         pen.setWidth(RS_FilterDXF::numberToWidth(dxfLine.toInt()));
1020                                                                         break;
1021                                                                 case 62:  // Color
1022                                                                         pen.setColor(RS_FilterDXF::numberToColor(dxfLine.toInt()));
1023                                                                         break;
1024                                                                 default:
1025                                                                         break;
1026                                                                 }
1027                                                         }
1028                                                 }
1029                                         }
1030                                         while(!dxfCode.isEmpty() && code != 0);
1031
1032                                         char * i = strchr(vtextStyle, '#');
1033
1034                                         if (i != NULL)
1035                                         {
1036                                                 i[0] = '\0';
1037                                         }
1038
1039                                         graphic->addEntity(
1040                                                 new RS_Text(graphic,
1041                                                                         RS_TextData(
1042                                                                                 Vector(vx1, vy1),
1043                                                                                 vheight,
1044                                                                                 100.0,
1045                                                                                 RS2::VAlignBottom,
1046                                                                                 vhalign,
1047                                                                                 RS2::LeftToRight,
1048                                                                                 RS2::Exact,
1049                                                                                 1.0,
1050                                                                                 vtext,
1051                                                                                 vtextStyle,
1052                                                                                 vtextAng
1053                                                                         )
1054                                                                 )
1055                                         );
1056                                 }
1057
1058                                 // ----------
1059                                 // Dimension:
1060                                 // ----------
1061                                 else if(dxfLine=="DIMENSION") {
1062                                         int typ=1;
1063                                         double v10=0.0, v20=0.0;
1064                                         double v13=0.0, v23=0.0;
1065                                         double v14=0.0, v24=0.0;
1066                                         double v15=0.0, v25=0.0;
1067                                         double v16=0.0, v26=0.0;
1068                                         double v40=0.0, v50=0.0;
1069                                         QString dimText;
1070                                         do {
1071                                                 dxfCode=getBufLine();
1072                                                 if(!dxfCode.isEmpty()) {
1073                                                         code=dxfCode.toInt();
1074                                                 }
1075                                                 if(!dxfCode.isEmpty() && code!=0) {
1076                                                         dxfLine=getBufLine();
1077                                                         if(!dxfLine.isEmpty()) {
1078                                                                 switch(code) {
1079                                                                 case  1:  // Text (if any)
1080                                                                         dimText=dxfLine;
1081
1082                                                                         // Mend unproper savings of older versions:
1083                                                                         if(dimText==" " || dimText==";;")
1084                                                                                 dimText="";
1085
1086                                                                         //else dimText.replace(QRegExp("%%c"), "�");
1087                                                                         else
1088                                                                                 strDecodeDxfString(dimText);
1089                                                                         break;
1090                                                                 case  6:  // style
1091                                                                         pen.setLineType(RS_FilterDXF::nameToLineType(dxfLine));
1092                                                                         break;
1093                                                                 case  8:  // Layer
1094                                                                         //if(dxfLine!=lastLayer) {
1095                                                                         if (dxfLine=="(null)" || dxfLine=="default") {
1096                                                                                 dxfLine = "0";
1097                                                                         }
1098                                                                         graphic->activateLayer(dxfLine);
1099                                                                         //lastLayer=dxfLine;
1100                                                                         //}
1101                                                                         break;
1102                                                                 case 10:  // line position x
1103                                                                         dxfLine.replace( QRegExp(","), "." );
1104                                                                         v10 = dxfLine.toDouble();
1105                                                                         break;
1106                                                                 case 20:  // line position y
1107                                                                         dxfLine.replace( QRegExp(","), "." );
1108                                                                         v20 = dxfLine.toDouble();
1109                                                                         break;
1110                                                                 case 13:  // X1
1111                                                                         dxfLine.replace( QRegExp(","), "." );
1112                                                                         v13 = dxfLine.toDouble();
1113                                                                         break;
1114                                                                 case 23:  // Y1
1115                                                                         dxfLine.replace( QRegExp(","), "." );
1116                                                                         v23 = dxfLine.toDouble();
1117                                                                         break;
1118                                                                 case 14:  // X2
1119                                                                         dxfLine.replace( QRegExp(","), "." );
1120                                                                         v14 = dxfLine.toDouble();
1121                                                                         break;
1122                                                                 case 24:  // Y2
1123                                                                         dxfLine.replace( QRegExp(","), "." );
1124                                                                         v24 = dxfLine.toDouble();
1125                                                                         break;
1126                                                                 case 15:  // X3
1127                                                                         dxfLine.replace( QRegExp(","), "." );
1128                                                                         v15 = dxfLine.toDouble();
1129                                                                         break;
1130                                                                 case 25:  // Y3
1131                                                                         dxfLine.replace( QRegExp(","), "." );
1132                                                                         v25 = dxfLine.toDouble();
1133                                                                         break;
1134                                                                 case 16:  // X4
1135                                                                         dxfLine.replace( QRegExp(","), "." );
1136                                                                         v16 = dxfLine.toDouble();
1137                                                                         break;
1138                                                                 case 26:  // Y4
1139                                                                         dxfLine.replace( QRegExp(","), "." );
1140                                                                         v26 = dxfLine.toDouble();
1141                                                                         break;
1142                                                                 case 40:
1143                                                                         dxfLine.replace( QRegExp(","), "." );
1144                                                                         v40 = dxfLine.toDouble();
1145                                                                         break;
1146                                                                 case 50:
1147                                                                         dxfLine.replace( QRegExp(","), "." );
1148                                                                         v50 = dxfLine.toDouble();
1149                                                                         break;
1150                                                                 case 70:  // Typ
1151                                                                         typ = dxfLine.toInt();
1152                                                                         break;
1153                                                                 case 39:  // Thickness
1154                                                                         pen.setWidth(RS_FilterDXF::numberToWidth(dxfLine.toInt()));
1155                                                                         break;
1156                                                                 case 62:  // Color
1157                                                                         pen.setColor(RS_FilterDXF::numberToColor(dxfLine.toInt()));
1158                                                                         break;
1159
1160                                                                 default:
1161                                                                         break;
1162                                                                 }
1163                                                         }
1164                                                 }
1165                                         } while(!dxfCode.isEmpty() && code!=0);
1166
1167                                         //double dist;
1168
1169                                         // Remove Bit values:
1170                                         if(typ>=128) {
1171                                                 typ-=128;   // Location of Text
1172                                         }
1173                                         if(typ>= 64) {
1174                                                 typ-= 64;   // Ordinate
1175                                         }
1176
1177                                         switch(typ) {
1178                                                 // Horiz. / vert.:
1179                                         case 0: {
1180                                                         RS_DimLinear* d =
1181                                                                 new RS_DimLinear(
1182                                                                         graphic,
1183                                                                         RS_DimensionData(
1184                                                                                 Vector(v10, v20),
1185                                                                                 Vector(0.0, 0.0),
1186                                                                                 RS2::VAlignBottom,
1187                                                                                 RS2::HAlignCenter,
1188                                                                                 RS2::Exact,
1189                                                                                 1.0,
1190                                                                                 dimText,
1191                                                                                 "ISO-25",
1192                                                                                 0.0
1193                                                                         ),
1194                                                                         RS_DimLinearData(
1195                                                                                 Vector(v13, v23),
1196                                                                                 Vector(v14, v24),
1197                                                                                 v50/ARAD,
1198                                                                                 0.0
1199                                                                         )
1200                                                                 );
1201                                                         d->update();
1202                                                         graphic->addEntity(d);
1203                                                 }
1204                                                 break;
1205
1206                                                 // Aligned:
1207                                         case 1: {
1208                                                         double angle =
1209                                                                 Vector(v13, v23).angleTo(Vector(v10,v20));
1210                                                         double dist =
1211                                                                 Vector(v13, v23).distanceTo(Vector(v10,v20));
1212
1213                                                         Vector defP;
1214                                                         defP.setPolar(dist, angle);
1215                                                         defP+=Vector(v14, v24);
1216
1217                                                         RS_DimAligned* d =
1218                                                                 new RS_DimAligned(
1219                                                                         graphic,
1220                                                                         RS_DimensionData(
1221                                                                                 defP,
1222                                                                                 Vector(0.0, 0.0),
1223                                                                                 RS2::VAlignBottom,
1224                                                                                 RS2::HAlignCenter,
1225                                                                                 RS2::Exact,
1226                                                                                 1.0,
1227                                                                                 dimText,
1228                                                                                 "ISO-25",
1229                                                                                 0.0
1230                                                                         ),
1231                                                                         RS_DimAlignedData(
1232                                                                                 Vector(v13, v23),
1233                                                                                 Vector(v14, v24)
1234                                                                         )
1235                                                                 );
1236                                                         d->update();
1237                                                         graphic->addEntity(d);
1238                                                 }
1239                                                 break;
1240
1241                                                 // Angle:
1242                                         case 2: {
1243                                                         RS_Line tl1(NULL,
1244                                                                                 RS_LineData(Vector(v13, v23),
1245                                                                                                         Vector(v14, v24)));
1246                                                         RS_Line tl2(NULL,
1247                                                                                 RS_LineData(Vector(v10, v20),
1248                                                                                                         Vector(v15, v25)));
1249
1250                                                         VectorSolutions s;
1251                                                         //bool inters=false;
1252                                                         //tmpEl1.getIntersection(&tmpEl2,
1253                                                         //                       &inters, &vcx, &vcy, 0,0,0,0, false);
1254                                                         s = RS_Information::getIntersection(
1255                                                                         &tl1, &tl2, false);
1256
1257                                                         if (s.get(0).valid) {
1258                                                                 vcx = s.get(0).x;
1259                                                                 vcy = s.get(0).y;
1260                                                                 //vcr = Vector(vcx, vcy).distanceTo(v16, v26);
1261
1262                                                                 /*if(Vector(vcx,vcy).distanceTo(v13,v23)<vcr) {
1263                                                                         va1 = tl1.getAngle1();
1264                                                         } else {
1265                                                                         va1 = tl2.getAngle2();
1266                                                         }
1267
1268                                                                 if(Vector(vcx,vcy).distanceTo(v10,v20)<vcr) {
1269                                                                         va2 = tl2.getAngle1();
1270                                                         } else {
1271                                                                         va2 = tl2.getAngle2();
1272                                                         }
1273                                                                 */
1274                                                                 /*
1275                                                                 graphic->addDimension(vcx, vcy, va1, va2,
1276                                                                                         mtGetDistance(vcx, vcy, v13, v23),
1277                                                                                         mtGetDistance(vcx, vcy, v10, v20),
1278                                                                                                         vcr,
1279                                                                                                         E_ROUNDOUT,
1280                                                                                                         currentLayerNum,
1281                                                                                                         add);
1282                                                                 */
1283                                                                 //Vector dp4;
1284                                                                 //dp4.setPolar();
1285                                                                 RS_DimAngular* d =
1286                                                                         new RS_DimAngular(
1287                                                                                 graphic,
1288                                                                                 RS_DimensionData(
1289                                                                                         Vector(v10, v20),
1290                                                                                         Vector(0.0, 0.0),
1291                                                                                         RS2::VAlignBottom,
1292                                                                                         RS2::HAlignCenter,
1293                                                                                         RS2::Exact,
1294                                                                                         1.0,
1295                                                                                         dimText,
1296                                                                                         "ISO-25",
1297                                                                                         0.0
1298                                                                                 ),
1299                                                                                 RS_DimAngularData(
1300                                                                                         Vector(v13, v23),
1301                                                                                         Vector(vcx, vcy),
1302                                                                                         Vector(vcx, vcy),
1303                                                                                         Vector(v16, v26)
1304                                                                                 )
1305                                                                         );
1306                                                                 d->update();
1307                                                                 graphic->addEntity(d);
1308                                                         }
1309                                                 }
1310                                                 break;
1311
1312                                                 // Radius:
1313                                         case 4: {
1314                                                         /*
1315                                                                                                 graphic->addDimension(v10, v20, v15, v25,
1316                                                                                                                                         0.0, 0.0,
1317                                                                                                                                                                         v40,
1318                                                                                                                                                                         E_STRAIGHT|E_RADIUS,
1319                                                                                                                                                                         currentLayerNum,
1320                                                                                                                                                                         add);
1321                                                                                                                                 */
1322
1323                                                         double ang =
1324                                                                 Vector(v10, v20)
1325                                                                 .angleTo(Vector(v15, v25));
1326                                                         Vector v2;
1327                                                         v2.setPolar(v40, ang);
1328                                                         RS_DimRadial* d =
1329                                                                 new RS_DimRadial(
1330                                                                         graphic,
1331                                                                         RS_DimensionData(
1332                                                                                 Vector(v10, v20),
1333                                                                                 Vector(0.0, 0.0),
1334                                                                                 RS2::VAlignBottom,
1335                                                                                 RS2::HAlignCenter,
1336                                                                                 RS2::Exact,
1337                                                                                 1.0,
1338                                                                                 dimText,
1339                                                                                 "ISO-25",
1340                                                                                 0.0
1341                                                                         ),
1342                                                                         RS_DimRadialData(
1343                                                                                 Vector(v10, v20) + v2,
1344                                                                                 0.0
1345                                                                         )
1346                                                                 );
1347                                                         d->update();
1348                                                         graphic->addEntity(d);
1349                                                 }
1350                                                 break;
1351
1352                                                 // Arrow:
1353                                         case 7: {
1354                                                         /*
1355                                                                                 graphic->addDimension(v13, v23, v14, v24,
1356                                                                                                                                 0.0, 0.0, 0.0,
1357                                                                                                                                 E_STRAIGHT|E_ARROW,
1358                                                                                                                                 currentLayerNum,
1359                                                                                                                                 add);
1360                                                         */
1361                                                         /*
1362                                                         double ang =
1363                                                                 Vector(v10, v20)
1364                                                                 .angleTo(Vector(v15, v25));
1365                                                         Vector v2;
1366                                                         v2.setPolar(v40, ang);
1367                                                         RS_DimDiametric* d =
1368                                                                 new RS_DimDiametric(
1369                                                                         graphic,
1370                                                                         RS_DimensionData(
1371                                                                                 Vector(v10, v20),
1372                                                                                 Vector(0.0, 0.0),
1373                                                                                 RS2::VAlignBottom,
1374                                                                                 RS2::HAlignCenter,
1375                                                                                 RS2::Exact,
1376                                                                                 1.0,
1377                                                                                 dimText,
1378                                                                                 "ISO-25",
1379                                                                                 0.0
1380                                                                         ),
1381                                                                         RS_DimDiametricData(
1382                                                                                 Vector(v10, v20) + v2,
1383                                                                                 0.0
1384                                                                         )
1385                                                                 );
1386                                                         d->update();
1387                                                         graphic->addEntity(d);
1388                                                         */
1389                                                         RS_LeaderData data(true);
1390                                                         RS_Leader* d =
1391                                                                 new RS_Leader(graphic, data);
1392                                                         d->addVertex(Vector(v14, v24));
1393                                                         d->addVertex(Vector(v10, v20));
1394                                                         d->update();
1395                                                         graphic->addEntity(d);
1396                                                 }
1397                                                 break;
1398                                         }
1399                                         //graphic->elementCurrent()->setText(dimText);
1400                                 }
1401
1402
1403
1404                                 // ---------
1405                                 // Hatching:
1406                                 // ---------
1407                                 /*
1408                                         else if(dxfLine=="HATCH") {
1409                                                 QString patternName="45";
1410                                                 double patternScale=1.0;
1411                                                 //int numPaths=1;
1412                                                 //int numEdges=1;
1413                                                 int nextObjectTyp=T_LINE;
1414                                                 double v10=0.0, v20=0.0,
1415                                                         v11=0.0, v21=0.0,
1416                                                         v40=0.0, v50=0.0,
1417                                                         v51=0.0;
1418                                                 do {
1419                                                 dxfCode=getBufLine();
1420                                                 if(dxfCode) code=dxfCode.toInt();
1421                                                 if(dxfCode && code!=0) {
1422                                                         dxfLine=getBufLine();
1423                                                         if(dxfLine) {
1424                                                         switch(code) {
1425                                                                 case  2:
1426                                                                 patternName = dxfLine;
1427                                                                 break;
1428                                                                 case  6:  // style
1429                                                                 pen.setLineType(RS_FilterDXF::nameToLineType(dxfLine));
1430                                                                 break;
1431                                                                 case  8:  // Layer
1432                                                                 //  if(dxfLine!=lastLayer) {
1433                                                                         if (dxfLine=="(null)" || dxfLine=="default") {
1434                                                                                 dxfLine = "0";
1435                                                                         }
1436                                                                         graphic->activateLayer(dxfLine);
1437                                                                         //lastLayer=dxfLine;
1438                                                                 //}
1439                                                                 break;
1440                                                                 case 10:  // Start point/center of boundary line/arc
1441                                                                 dxfLine.replace( QRegExp(","), "." );
1442                                                                 v10=dxfLine.toDouble();
1443                                                                 break;
1444                                                                 case 20:  // Start point/center of boundary line/arc
1445                                                                 dxfLine.replace( QRegExp(","), "." );
1446                                                                 v20=dxfLine.toDouble();
1447                                                                 break;
1448                                                                 case 11:  // End point of boundary line
1449                                                                 dxfLine.replace( QRegExp(","), "." );
1450                                                                 v11=dxfLine.toDouble();
1451                                                                 break;
1452                                                                 case 21:  // End point of boundary line
1453                                                                 dxfLine.replace( QRegExp(","), "." );
1454                                                                 v21=dxfLine.toDouble();
1455                                                                 if(nextObjectTyp==T_LINE) {
1456                                                                         int elnu=graphic->addLine(v10, v20, v11, v21, currentLayerNum, add);
1457                                                                         graphic->elementAt(elnu)->setFlag(E_TAGGED);
1458                                                                 }
1459                                                                 break;
1460                                                                 case 40:  // Radius of boundary entity
1461                                                                 dxfLine.replace( QRegExp(","), "." );
1462                                                                 v40=dxfLine.toDouble();
1463                                                                 break;
1464                                                                 case 50:  // Start angle
1465                                                                 dxfLine.replace( QRegExp(","), "." );
1466                                                                 v50=dxfLine.toDouble();
1467                                                                 break;
1468                                                                 case 51:  // End angle
1469                                                                 dxfLine.replace( QRegExp(","), "." );
1470                                                                 v51=dxfLine.toDouble();
1471                                                                 break;
1472                                                                 case 73:  // Counterclockwise?
1473                                                                 if(nextObjectTyp==T_ARC) {
1474                                                                         int elnu;
1475                                                                         if( mtCompFloat( v50, 0.0 ) && mtCompFloat( v51, 0.0 ) ) {
1476                                                                         elnu=graphic->addCircle(v10, v20, v40, 0.0, 360.0, (bool)dxfLine.toInt(), currentLayerNum, add);
1477                                                                         }
1478                                                                         else {
1479                                                                         elnu=graphic->addArc(v10, v20, v40, v50, v51, (bool)dxfLine.toInt(), currentLayerNum, add);
1480                                                                         }
1481                                                                         graphic->elementAt(elnu)->setFlag(E_TAGGED);
1482                                                                         //newEl = new RElement( graphic );
1483                                                                         //newEl->createArc(v10, v20, v40, v50, v51, (bool)dxfLine.toInt());
1484                                                                         //boundaryList.append(newEl);
1485                                                                 }
1486                                                                 break;
1487                                                                 case 41:  // Scale
1488                                                                 dxfLine.replace( QRegExp(","), "." );
1489                                                                 patternScale=dxfLine.toDouble();
1490                                                                 break;
1491                                                                 case 52:  // Angle
1492
1493                                                                 break;
1494                                                                 case 70:  // Solid (=1) or pattern (=0)
1495
1496                                                                 break;
1497                                                                 case 39:  // Thickness
1498                                                                 pen.setWidth(RS_FilterDXF::numberToWidth(dxfLine.toInt()));
1499                                                                 break;
1500                                                                 case 62:  // Color
1501                                                                 pen.setColor(RS_FilterDXF::numberToColor(dxfLine.toInt()));
1502                                                                 break;
1503                                                                 case 91:  // Number of boundary paths (loops)
1504                                                                 //numPaths=dxfLine.toInt();
1505                                                                 break;
1506                                                                 case 92:  // Typ of boundary
1507
1508                                                                 break;
1509                                                                 case 93:  // Number of edges in this boundary
1510                                                                 //numEdges=dxfLine.toInt();
1511                                                                 break;
1512                                                                 case 72:  // Edge typ
1513                                                                 switch(dxfLine.toInt()) {
1514                                                                         case 1: nextObjectTyp=T_LINE; break;
1515                                                                         case 2: nextObjectTyp=T_ARC;  break;
1516                                                                         default: break;
1517                                                                 }
1518                                                                 break;
1519
1520                                                                 default:
1521                                                                 break;
1522                                                         }
1523                                                         }
1524                                                 }
1525                                                 }while(dxfCode && code!=0);
1526
1527                                                 graphic->addHatching(patternScale,
1528                                                                                         patternName,
1529                                                                                         currentLayerNum,
1530                                                                                         add);
1531
1532                                                 graphic->editDelete(false);
1533
1534                                         }
1535                                 */
1536
1537                         }
1538                 }
1539 #warning "This will probably fail since it was expecting to be null on EOF"
1540                 while (!dxfLine.isEmpty() && dxfLine != "EOF");
1541
1542                 //graphic->terminateAction();
1543
1544                 //graphic->debugElements();
1545
1546                 ret = true;
1547         }
1548         else
1549         {
1550                 ret = false;
1551         }
1552
1553         return ret;
1554 }
1555
1556 /**
1557  * Resets  the whole object
1558  *   (base class too)
1559  */
1560 void RS_FilterDXF1::reset()
1561 {
1562         file.reset();
1563
1564         delBuffer();
1565         fBufP = 0;
1566         fSize = 0;
1567
1568         if (fPointer)
1569         {
1570                 fclose(fPointer);
1571                 fPointer = 0;
1572         }
1573 }
1574
1575 /**
1576  * Reset buffer pointer to the beginning of the buffer:
1577  */
1578 void RS_FilterDXF1::resetBufP()
1579 {
1580         fBufP = 0;
1581 }
1582
1583 /**
1584  * Set buffer pointer to the given index:
1585  */
1586 void RS_FilterDXF1::setBufP(int _fBufP)
1587 {
1588         if (_fBufP < (int)fSize)
1589                 fBufP = _fBufP;
1590 }
1591
1592 /**
1593  * delete buffer:
1594  */
1595 void RS_FilterDXF1::delBuffer()
1596 {
1597         if (fBuf)
1598         {
1599                 delete[] fBuf;
1600                 fBuf = 0;
1601         }
1602 }
1603
1604 /**
1605  * Remove any 13-characters in the buffer:
1606  */
1607 void RS_FilterDXF1::dos2unix()
1608 {
1609         char * src = fBuf, * dst = fBuf;
1610
1611         if (!fBuf)
1612                 return;
1613
1614         while (*src != '\0')
1615         {
1616                 if (*src == '\r')
1617                         dosFile = true;
1618                 else
1619                         *dst++ = *src;
1620
1621                 src++;
1622         }
1623
1624         *dst = '\0';
1625 }
1626
1627 // Get next line in the buffer:
1628 //   and overread ALL seperators
1629 //
1630 // return:  -Null-string: end of buffer
1631 //          -String which is the next line in buffer
1632 //
1633 QString RS_FilterDXF1::getBufLine()
1634 {
1635         char * ret;
1636         QString str;
1637
1638         if (fBufP >= (int)fSize)
1639                 return QString::null;
1640
1641         ret = &fBuf[fBufP];
1642
1643         // Move fBufP pointer to the next line
1644         while (fBufP < (int)fSize && fBuf[fBufP++] != '\0')
1645                 ;
1646
1647 //      str = QString::fromLocal8Bit(ret).stripWhiteSpace();
1648         str = QString::fromLocal8Bit(ret).simplified();
1649
1650 //    if (str.isNull())
1651 //    {
1652 //        return "";
1653 //    }
1654 //    else
1655 //    {
1656                 return str;
1657 //    }
1658 }
1659
1660
1661 // Get next line in the buffer:
1662 //   and overread ALL seperators
1663 //
1664 // return:  -Null-string: end of buffer
1665 //          -String which is the next line in buffer
1666 //
1667 char * RS_FilterDXF1::getBufLineCh()
1668 {
1669     char * ret;
1670
1671     if (fBufP >= (int)fSize)
1672         return 0;
1673
1674     ret = &fBuf[fBufP];
1675
1676     // Skip empty lines
1677     /*if (*ret == '\0' && noEmptyLines) {
1678         while (++fBufP < (int)fSize && fBuf[fBufP] == '\0')
1679             ;
1680         if (fBufP >= (int)fSize)
1681             return 0;
1682         ret = &fBuf[fBufP];
1683 }*/
1684
1685     // Move fBufP pointer to the next line
1686     while (fBufP < (int)fSize && fBuf[fBufP++] != '\0')
1687         ;
1688
1689     return ret;
1690 }
1691
1692
1693 // Copy buffer from a given string:
1694 //
1695 void RS_FilterDXF1::copyBufFrom(const char * _buf)
1696 {
1697     if (_buf)
1698     {
1699         fBuf = new char[strlen(_buf) + 16];
1700         strcpy(fBuf, _buf);
1701     }
1702 }
1703
1704
1705 // Go to the next '_lstr'-line in buffer:
1706 //
1707 // return: true:  line found
1708 //         false: end of buffer
1709 //
1710 bool RS_FilterDXF1::gotoBufLine(char * _lstr)
1711 {
1712     QString l;
1713
1714     do
1715     {
1716         l = getBufLine();
1717     }
1718     while (!l.isNull() && l!=_lstr);
1719
1720     if (!l.isNull())
1721         return true;
1722
1723     return false;
1724 }
1725
1726
1727 // Goto next line where the string _lstr appears:
1728 //
1729 // return: true:  string in line found
1730 //         false: end of buffer
1731 //
1732 //
1733 bool RS_FilterDXF1::gotoBufLineString(char * _lstr)
1734 {
1735     QString l;
1736
1737     do
1738     {
1739         l = getBufLine();
1740     }
1741     while (!l.isNull() && l.contains(_lstr));
1742
1743     if (!l.isNull())
1744         return true;
1745
1746     return false;
1747 }
1748
1749
1750 // Replace bynary Bytes (<32) by an other (given) byte:
1751 //
1752 void RS_FilterDXF1::replaceBinaryBytesBy(char _c)
1753 {
1754     int bc;
1755
1756     for(bc=0; bc<(int)fSize; ++bc)
1757     {
1758         if (fBuf[bc] < 32 && fBuf[bc] >= 0)
1759         {
1760             fBuf[bc] = _c;
1761         }
1762     }
1763 }
1764
1765
1766 // Separate buffer (change chars sc1 and sc2 in '\0'
1767 //
1768 void RS_FilterDXF1::separateBuf(char _c1,
1769                                 char _c2,
1770                                 char _c3,
1771                                 char _c4)
1772 {
1773     for(int bc=0; bc<(int)fSize; ++bc)
1774     {
1775         if (fBuf[bc] == _c1 || fBuf[bc] == _c2 ||
1776             fBuf[bc] == _c3 || fBuf[bc] == _c4)
1777         {
1778             fBuf[bc] = '\0';
1779         }
1780     }
1781 }
1782
1783
1784 // remove comment between '_fc' and '_lc'
1785 //   comments get replaced by '\0'
1786 //
1787 void RS_FilterDXF1::removeComment(char _fc, char _lc)
1788 {
1789     bool rem = false;   // Are we removing currrently?
1790     int bc;           // counter
1791
1792     for(bc=0; bc<(int)fSize; ++bc)
1793     {
1794         if (fBuf[bc] == _fc)
1795             rem = true;
1796
1797         if (fBuf[bc] == _lc)
1798         {
1799             fBuf[bc] = '\0';
1800             rem = false;
1801         }
1802
1803         if (rem)
1804             fBuf[bc] = '\0';
1805     }
1806 }
1807
1808 // Read file '_name' in buffer (buf)
1809 //
1810 // '_bNum' : Max number of Bytes
1811 //         : -1: All
1812 // return: true: successful
1813 //         false: file not found
1814 //
1815 bool RS_FilterDXF1::readFileInBuffer(char * _name, int _bNum)
1816 {
1817 //    file.setName(_name);
1818     file.setFileName(_name);
1819     return readFileInBuffer(_bNum);
1820 }
1821
1822 // Read file in buffer (buf)
1823 //
1824 // 'bNum' : Max number of Bytes
1825 //        : -1: All
1826 // return: true: successful
1827 //         false: file not found
1828 //
1829 bool RS_FilterDXF1::readFileInBuffer(int _bNum)
1830 {
1831         fPointer = fopen(name.toAscii().data(), "rb");
1832
1833         if (fPointer != NULL)
1834         {
1835 //              if (file.open(QIODevice::ReadOnly, fPointer))
1836                 if (file.open(fPointer, QIODevice::ReadOnly))
1837                 {
1838                         fSize = file.size();
1839
1840                         if (_bNum == -1)
1841                                 _bNum = fSize;
1842
1843                         fBuf = new char[_bNum + 16];
1844
1845 //                      file.readBlock(fBuf, _bNum);
1846                         file.read(fBuf, _bNum);
1847                         fBuf[_bNum] = '\0';
1848                         file.close();
1849                 }
1850
1851                 fclose(fPointer);
1852
1853                 // Convert 13/10 to 10
1854                 dos2unix();
1855                 fPointer = NULL;
1856
1857                 return true;
1858         }
1859
1860         return false;
1861 }
1862
1863
1864 // Decode a DXF string to the C-convention (special character \P is a \n)
1865 //
1866 void RS_FilterDXF1::strDecodeDxfString(QString & str)
1867 {
1868     if (str.isEmpty())
1869         return;
1870
1871     str.replace(QRegExp("%%c"), QChar(0xF8)); // Diameter
1872     str.replace(QRegExp("%%d"), QChar(0xB0)); // Degree
1873     str.replace(QRegExp("%%p"), QChar(0xB1)); // Plus/minus
1874     str.replace(QRegExp("\\\\[pP]"), QChar('\n'));
1875 }
1876
1877
1878 // Compare two double values:
1879 //
1880 // return: true: values are equal
1881 //         false: values are not equal
1882 //
1883 bool RS_FilterDXF1::mtCompFloat(double _v1, double _v2, double _tol)
1884 {
1885     double delta = _v2 - _v1;
1886
1887     if (delta > -_tol && delta < _tol)
1888         return true;
1889     else
1890         return false;
1891 }
1892
1893
1894 // EOF
1895