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