Logo Search packages:      
Sourcecode: qcad version File versions  Download package

bool RS_FilterDXF1::readFromBuffer (  ) 

Reads a dxf1 file from buffer.

if(!add) graphic->clearLayers();

Definition at line 94 of file rs_filterdxf1.cpp.

References RS_Graphic::activateLayer(), RS_EntityContainer::addEntity(), RS_Graphic::addLayer(), RS_Graphic::addVariable(), RS_Leader::addVertex(), RS_Math::correctAngle(), RS2::Exact, RS2::FlagByLayer, RS_VectorSolutions::get(), RS_Graphic::getActiveLayer(), RS_Information::getIntersection(), graphic, RS2::HAlignCenter, RS2::HAlignLeft, RS2::HAlignRight, RS2::LeftToRight, RS2::LineByLayer, RS_FilterDXF::nameToLineType(), RS_FilterDXF::numberToColor(), RS_FilterDXF::numberToWidth(), resetBufP(), RS_Document::setActivePen(), RS_Pen::setColor(), RS_Pen::setLineType(), RS_Layer::setPen(), RS_Vector::setPolar(), RS_Pen::setWidth(), RS_Leader::update(), RS_DimRadial::update(), RS_DimAngular::update(), RS_DimAligned::update(), RS_DimLinear::update(), RS_Vector::valid, RS2::VAlignBottom, RS2::WidthByLayer, RS_Vector::x, and RS_Vector::y.

Referenced by fileImport().

                                   {
    RS_DEBUG->print( "\nDXF: Read from buffer" );

    bool      ret;                    // returned value
    RS_String   dxfLine;                // A line in the dxf file
    RS_String   dxfCode;                // A Code in the dxf file as string
    int       code=-1;                // Dxf-code as number
    double    vx1=0.0, vy1=0.0;       // Start point
    double    vx2=0.0, vy2=0.0;       // End point
    double    vcx=0.0, vcy=0.0;       // Centre
    double    vcr=0.0;                // Radius
    double    va1=0.0, va2=0.0;       // Start / End Angle
    //double    vab=0.0,                // Bulge
    //           vpx=0.0, vpy=0.0;       // First Polyline point
    //double    ax=0.0, ay=0.0;         // Current coordinate
    //bool      plClose=false;          // Polyline closed-flag
    RS_String lastLayer;              // Last used layer name (test adding only
    //   if the new layer!=lastLayer)
    //int       currentLayerNum=0;      // Current layer number
    RS_Layer* currentLayer=0;         // Pointer to current layer
    //QList<RGraphic> blockList;        // List of blocks
    //blockList.setAutoDelete( true );
    //bool      oldColorNumbers=false;  // use old color numbers (qcad<1.5.3)
    RS_Pen pen;

    ///if(!add) graphic->clearLayers();

    //graphic->addLayer(DEF_DEFAULTLAYER);

    //RS_DEBUG->print( "\nDefault layer added" );

    // Loaded graphics without unit information: load as unit less:
    //graphic->setUnit( None );

    RS_DEBUG->print( "\nUnit set" );

    resetBufP();

    if(fBuf) {

        RS_DEBUG->print( "\nBuffer OK" );
        RS_DEBUG->print( "\nBuffer: " );
        RS_DEBUG->print( fBuf );

        do {
            dxfLine=getBufLine();
            pen = RS_Pen(RS_Color(RS2::FlagByLayer), RS2::WidthByLayer, RS2::LineByLayer);

            RS_DEBUG->print( "\ndxfLine: " );
            RS_DEBUG->print( dxfLine );

            // $-Setting in the header of DXF found
            //
            if( dxfLine &&
                    dxfLine[0]=='$' ) {


                // Units:
                //
                if( dxfLine=="$INSUNITS" ) {
                    if(dxfCode=getBufLine()) {
                        if( dxfCode.toInt()==70 ) {
                            if( dxfLine=getBufLine() ) {
                                graphic->addVariable("$INSUNITS", dxfLine, 70);
                                /*
                                            switch( dxfLine.toInt() ) {
                                              case  0: graphic->setUnit( RS2::None );       break;
                                              case  1: graphic->setUnit( RS2::Inch );       break;
                                              case  2: graphic->setUnit( RS2::Foot );       break;
                                              case  3: graphic->setUnit( RS2::Mile );       break;
                                              case  4: graphic->setUnit( RS2::Millimeter ); break;
                                              case  5: graphic->setUnit( RS2::Centimeter ); break;
                                              case  6: graphic->setUnit( RS2::Meter );      break;
                                              case  7: graphic->setUnit( RS2::Kilometer );  break;
                                              case  8: graphic->setUnit( RS2::Microinch );  break;
                                              case  9: graphic->setUnit( RS2::Mil );        break;
                                              case 10: graphic->setUnit( RS2::Yard );       break;
                                              case 11: graphic->setUnit( RS2::Angstrom );   break;
                                              case 12: graphic->setUnit( RS2::Nanometer );  break;
                                              case 13: graphic->setUnit( RS2::Micron );     break;
                                              case 14: graphic->setUnit( RS2::Decimeter );  break;
                                              case 15: graphic->setUnit( RS2::Decameter );  break;
                                              case 16: graphic->setUnit( RS2::Hectometer ); break;
                                              case 17: graphic->setUnit( RS2::Gigameter );  break;
                                              case 18: graphic->setUnit( RS2::Astro );      break;
                                              case 19: graphic->setUnit( RS2::Lightyear );  break;
                                              case 20: graphic->setUnit( RS2::Parsec );     break;
                                            }

                                            graphic->setDimensionUnit( graphic->getUnit() );
                                            //graphic->setGridUnit( graphic->getUnit() );
                                */
                            }
                        }
                    }
                }

                // Dimenison Units:
                //
                else if( dxfLine=="$DIMALT" ) {
                    if(dxfCode=getBufLine()) {
                        if( dxfCode.toInt()==70 ) {
                            if( dxfLine=getBufLine() ) {
                                graphic->addVariable("$DIMALT", dxfLine, 70);
                                /*
                                            switch( dxfLine.toInt() ) {
                                              case  0: graphic->setDimensionUnit( RS2::None );       break;
                                              case  1: graphic->setDimensionUnit( RS2::Inch );       break;
                                              case  2: graphic->setDimensionUnit( RS2::Foot );       break;
                                              case  3: graphic->setDimensionUnit( RS2::Mile );       break;
                                              case  4: graphic->setDimensionUnit( RS2::Millimeter ); break;
                                              case  5: graphic->setDimensionUnit( RS2::Centimeter ); break;
                                              case  6: graphic->setDimensionUnit( RS2::Meter );      break;
                                              case  7: graphic->setDimensionUnit( RS2::Kilometer );  break;
                                              case  8: graphic->setDimensionUnit( RS2::Microinch );  break;
                                              case  9: graphic->setDimensionUnit( RS2::Mil );        break;
                                              case 10: graphic->setDimensionUnit( RS2::Yard );       break;
                                              case 11: graphic->setDimensionUnit( RS2::Angstrom );   break;
                                              case 12: graphic->setDimensionUnit( RS2::Nanometer );  break;
                                              case 13: graphic->setDimensionUnit( RS2::Micron );     break;
                                              case 14: graphic->setDimensionUnit( RS2::Decimeter );  break;
                                              case 15: graphic->setDimensionUnit( RS2::Decameter );  break;
                                              case 16: graphic->setDimensionUnit( RS2::Hectometer ); break;
                                              case 17: graphic->setDimensionUnit( RS2::Gigameter );  break;
                                              case 18: graphic->setDimensionUnit( RS2::Astro );      break;
                                              case 19: graphic->setDimensionUnit( RS2::Lightyear );  break;
                                              case 20: graphic->setDimensionUnit( RS2::Parsec );     break;
                                            }
                                */
                            }
                        }
                    }
                }

                // Dimension Format:
                //
                /*else if( dxfLine=="$DIMLUNIT" ) {
                  if(dxfCode=getBufLine()) {
                    if( dxfCode.toInt()==70 ) {
                      if( dxfLine=getBufLine() ) {
                        switch( dxfLine.toInt() ) {
                          case 1: graphic->setDimensionFormat( Scientific ); break;
                          case 2:
                          case 3: graphic->setDimensionFormat( Decimal ); break;
                          case 4:
                          case 5: graphic->setDimensionFormat( Fractional ); break;
                          default: break;
                        }
                      }
                    }
                  }
            }*/

                // Dimension Arrow Size:
                //
                else if( dxfLine=="$DIMASZ" ) {
                    if(dxfCode=getBufLine()) {
                        if( dxfCode.toInt()==40 ) {
                            if( dxfLine=getBufLine() ) {
                                graphic->addVariable("$DIMASZ", dxfLine, 40);
                                //graphic->setDimensionArrowSize( dxfLine.toDouble() );
                            }
                        }
                    }
                }

                // Dimension Scale:
                //
                /*
                else if( dxfLine=="$DIMSCALE" ) {
                  if(dxfCode=getBufLine()) {
                    if( dxfCode.toInt()==40 ) {
                      if( dxfLine=getBufLine() ) {
                        graphic->setDimensionScale( dxfLine.toDouble() );
                      }
                    }
                  }
            }
                */

                // Dimension Text Height:
                //







                else if( dxfLine=="$DIMTXT" ) {
                    if(dxfCode=getBufLine()) {
                        if( dxfCode.toInt()==40 ) {
                            if( dxfLine=getBufLine() ) {
                                graphic->addVariable("$DIMTXT", dxfLine, 40);
                                //graphic->setDimensionTextHeight( dxfLine.toDouble() );
                            }
                        }
                    }
                }

                // Dimension exactness:
                //







                else if( dxfLine=="$DIMRND" ) {
                    if(dxfCode=getBufLine()) {
                        if( dxfCode.toInt()==40 ) {
                            if( dxfLine=getBufLine() ) {
                                graphic->addVariable("$DIMRND", dxfLine, 40);
                                //if( dxfLine.toDouble()>0.000001 ) {
                                //graphic->setDimensionExactness( dxfLine.toDouble() );
                            }
                            //}
                        }
                    }
                }

                // Dimension over length:
                //







                else if( dxfLine=="$DIMEXE" ) {
                    if(dxfCode=getBufLine()) {
                        if( dxfCode.toInt()==40 ) {
                            if( dxfLine=getBufLine() ) {
                                graphic->addVariable("$DIMEXE", dxfLine, 40);
                                //graphic->setDimensionOverLength( dxfLine.toDouble() );
                            }
                        }
                    }
                }

                // Dimension under length:
                //







                else if( dxfLine=="$DIMEXO" ) {
                    if(dxfCode=getBufLine()) {
                        if( dxfCode.toInt()==40 ) {
                            if( dxfLine=getBufLine() ) {
                                graphic->addVariable("$DIMEXO", dxfLine, 40);
                                //graphic->setDimensionUnderLength( dxfLine.toDouble() );
                            }
                        }
                    }
                }


                // Angle dimension format:
                //







                else if( dxfLine=="$DIMAUNIT" ) {
                    if(dxfCode=getBufLine()) {
                        if( dxfCode.toInt()==70 ) {
                            if( dxfLine=getBufLine() ) {
                                graphic->addVariable("$DIMAUNIT", dxfLine, 70);
                                /*
                                            switch( dxfLine.toInt() ) {
                                              case 0: graphic->setAngleDimensionFormat( DecimalDegrees ); break;
                                              case 1: graphic->setAngleDimensionFormat( DegreesMinutesSeconds ); break;
                                              case 2: graphic->setAngleDimensionFormat( Gradians ); break;
                                              case 3: graphic->setAngleDimensionFormat( Radians ); break;
                                              case 4: graphic->setAngleDimensionFormat( Surveyor ); break;
                                              default: break;
                                            }
                                */
                            }
                        }
                    }
                }

                // Angle dimension exactness:
                //
                else if( dxfLine=="$DIMADEC" ) {
                    if(dxfCode=getBufLine()) {
                        if( dxfCode.toInt()==70 ) {
                            if( dxfLine=getBufLine() ) {
                                graphic->addVariable("$DIMADEC", dxfLine, 70);
                                //graphic->setAngleDimensionExactness( RS_Math::pow(0.1, dxfLine.toInt()) );
                            }
                        }
                    }
                }

                // Grid x/y:
                //







                else if( dxfLine=="$GRIDUNIT" ) {
                    if(dxfCode=getBufLine()) {
                        if( dxfCode.toInt()==10 ) {
                            if (dxfLine=getBufLine()) {
                                double x = atof(dxfLine);
                                if (dxfLine=getBufLine()) {
                                    double y = atof(dxfLine);

                                    graphic->addVariable("$GRIDUNIT", RS_Vector(x,y), 10);
                                }
                            }
                        }
                    }
                }
                /*
                            double gx=dxfLine.toDouble();
                            if (gx<0.0001) gx=0.0001;
                            graphic->setMinGridX(gx);
                            graphic->setGridFormat( Fractional );

                            for( double q=0.00000001; q<=100000.0; q*=10.0 ) {
                              if( mtCompFloat(gx, q, q/1000.0) ) {
                                graphic->setGridFormat( Decimal );
                                break;
                              }
                            }

                          }
                        }
                      }
                      if(dxfCode=getBufLine()) {
                        if( dxfCode.toInt()==20 ) {
                          if( dxfLine=getBufLine() ) {
                            double gy=dxfLine.toDouble();
                            if (gy<0.0001) gy=0.0001;
                            graphic->setMinGridY(gy);
                          }
                        }
                      }
                */

                // Page limits min x/y:
                //
                /*else if( dxfLine=="$PLIMMIN" ) {
                  if(dxfCode=getBufLine()) {
                    if( dxfCode.toInt()==10 ) {
                      if( dxfLine=getBufLine() ) {
                        graphic->setPageOriginX( dxfLine.toDouble() );
                      }
                    }
                  }
                  if(dxfCode=getBufLine()) {
                    if( dxfCode.toInt()==20 ) {
                      if( dxfLine=getBufLine() ) {
                        graphic->setPageOriginY( dxfLine.toDouble() );
                      }
                    }
                  }
            }
                */

                // Page limits min x/y:
                //
                /*
                      else if( dxfLine=="$PLIMMAX" ) {
                        if(dxfCode=getBufLine()) {
                          if( dxfCode.toInt()==10 ) {
                            if( dxfLine=getBufLine() ) {
                              graphic->setPageSizeX( dxfLine.toDouble() - graphic->getPageOriginX() );
                            }
                          }
                        }
                        if(dxfCode=getBufLine()) {
                          if( dxfCode.toInt()==20 ) {
                            if( dxfLine=getBufLine() ) {
                              graphic->setPageSizeY( dxfLine.toDouble() - graphic->getPageOriginY() );
                            }
                          }
                        }
                      }
                */

                // Paper space scale:
                //
                /*
                      else if( dxfLine=="$PSVPSCALE" ) {
                        if(dxfCode=getBufLine()) {
                          if( dxfCode.toInt()==40 ) {
                            if( dxfLine=getBufLine() ) {
                              graphic->setPaperSpace( dxfLine.toDouble() );
                            }
                          }
                        }
                      }
                */

            }

            // Entity
            //
            else if(dxfLine &&
                    dxfLine[0]>='A' && dxfLine[0]<='Z') {

                if(dxfLine=="EOF") {
                    // End of file reached
                    //
                }

                // ------
                // Layer:
                // ------


                else if(dxfLine=="LAYER") {
                    currentLayer=0;
                    do {
                        dxfCode=getBufLine();
                        if(dxfCode)
                            code=dxfCode.toInt();
                        if(dxfCode && code!=0) {
                            dxfLine=getBufLine();
                            if(dxfLine) {
                                switch(code) {
                                case  2:  // Layer name
                                                      if (dxfLine=="(null)" || dxfLine=="default") {
                                                            dxfLine = "0";
                                                      }
                                    graphic->addLayer(new RS_Layer(dxfLine));
                                    graphic->activateLayer(dxfLine);
                                    currentLayer = graphic->getActiveLayer();
                                    lastLayer=dxfLine;
                                    break;
                                case 70:  // Visibility
                                    /*
                                    if(dxfLine.toInt()&5) {
                                      if(currentLayerNum>=0 && currentLayerNum<DEF_MAXLAYERS) {
                                        graphic->layer[currentLayerNum].DelFlag(Y_VISIBLE);
                                      }
                                }
                                    */
                                    break;
                                case  6:  // style
                                    //if(currentLayer)
                                    //currentLayer->setStyle( graphic->nameToStyle(dxfLine) );
                                    pen.setLineType(RS_FilterDXF::nameToLineType(dxfLine));
                                    break;
                                case 39:  // Thickness
                                    //if(currentLayer) currentLayer->setWidth(dxfLine.toInt());
                                    pen.setWidth(RS_FilterDXF::numberToWidth(dxfLine.toInt()));
                                    break;
                                case 62:  // Color
                                    pen.setColor(RS_FilterDXF::numberToColor(dxfLine.toInt()));
                                    //if(currentLayer) {
                                    //    currentLayer->setColor( graphic->numberToColor(dxfLine.toInt(), !oldColorNumbers));
                                    //}
                                    break;
                                default:
                                    break;
                                }
                            }
                        }
                    } while(dxfCode && code!=0);
                    if (currentLayer) {
                        currentLayer->setPen(pen);
                    }
                    //graphic->setStyle("CONTINOUS");
                    //graphic->setWidth(0);
                    //graphic->setColor(0, false);
                }

                // ------
                // Point:
                // ------


                else if(dxfLine=="POINT") {
                    do {
                        dxfCode=getBufLine();
                        if(dxfCode)
                            code=dxfCode.toInt();
                        if(dxfCode && code!=0) {
                            dxfLine=getBufLine();
                            if(dxfLine) {
                                switch(code) {
                                case  6:  // style
                                    pen.setLineType(RS_FilterDXF::nameToLineType(dxfLine));
                                    break;
                                case  8:  // Layer
                                    //if(dxfLine!=lastLayer) {
                                                      if (dxfLine=="(null)" || dxfLine=="default") {
                                                            dxfLine = "0";
                                                      }
                                    graphic->activateLayer(dxfLine);
                                    //lastLayer=dxfLine;
                                    //}
                                    break;
                                case 10:  // X1
                                    dxfLine.replace( QRegExp(","), "." );
                                    vx1 = dxfLine.toDouble();
                                    break;
                                case 20:  // Y1
                                    dxfLine.replace( QRegExp(","), "." );
                                    vy1 = dxfLine.toDouble();
                                    break;
                                case 39:  // Thickness
                                    pen.setWidth(RS_FilterDXF::numberToWidth(dxfLine.toInt()));
                                    break;
                                case 62:  // Color
                                    pen.setColor(RS_FilterDXF::numberToColor(dxfLine.toInt()));
                                    break;
                                default:
                                    break;
                                }
                            }
                        }
                    } while(dxfCode && code!=0);
                    graphic->setActivePen(pen);
                    graphic->addEntity(new RS_Point(graphic,
                                                    RS_PointData(RS_Vector(vx1, vy1))));
                }

                // -----
                // Line:
                // -----
                else if(dxfLine=="LINE") {
                    do {
                        dxfCode=getBufLine();

                        if(dxfCode)
                            code=dxfCode.toInt();
                        if(dxfCode && code!=0) {

                            dxfLine=getBufLine();

                            if(dxfLine) {
                                switch(code) {
                                case  6:  // style
                                    pen.setLineType(RS_FilterDXF::nameToLineType(dxfLine));
                                    break;
                                case  8:  // Layer
                                    //if(dxfLine!=lastLayer) {
                                                      if (dxfLine=="(null)" || dxfLine=="default") {
                                                            dxfLine = "0";
                                                      }
                                    graphic->activateLayer(dxfLine);
                                    //lastLayer=dxfLine;
                                    //}
                                    break;
                                case 10:  // X1
                                    dxfLine.replace( QRegExp(","), "." );
                                    vx1 = dxfLine.toDouble();
                                    break;
                                case 20:  // Y1
                                    dxfLine.replace( QRegExp(","), "." );
                                    vy1 = dxfLine.toDouble();
                                    break;
                                case 11:  // X2
                                    dxfLine.replace( QRegExp(","), "." );
                                    vx2 = dxfLine.toDouble();
                                    break;
                                case 21:  // Y2
                                    dxfLine.replace( QRegExp(","), "." );
                                    vy2 = dxfLine.toDouble();
                                    break;
                                case 39:  // Thickness
                                    pen.setWidth(RS_FilterDXF::numberToWidth(dxfLine.toInt()));
                                    break;
                                case 62:  // Color
                                    pen.setColor(RS_FilterDXF::numberToColor(dxfLine.toInt()));
                                    break;
                                default:
                                    break;
                                }
                            }
                        }
                    } while(dxfCode && code!=0);

                    //if(!mtCompFloat(vx1, vx2) || !mtCompFloat(vy1, vy2)) {
                    //graphic->addLine(vx1, vy1, vx2, vy2, currentLayerNum, add);
                    graphic->setActivePen(pen);
                    graphic->addEntity(new RS_Line(graphic,
                                                   RS_LineData(RS_Vector(vx1, vy1), RS_Vector(vx2, vy2))));
                    //}
                }


                // ----
                // Arc:
                // ----







                else if(dxfLine=="ARC") {
                    do {
                        dxfCode=getBufLine();
                        if(dxfCode)
                            code=dxfCode.toInt();
                        if(dxfCode && code!=0) {
                            dxfLine=getBufLine();
                            if(dxfLine) {
                                switch(code) {
                                case  6:  // style
                                    pen.setLineType(RS_FilterDXF::nameToLineType(dxfLine));
                                    break;
                                case  8:  // Layer
                                    //if(dxfLine!=lastLayer) {
                                                      if (dxfLine=="(null)" || dxfLine=="default") {
                                                            dxfLine = "0";
                                                      }
                                    graphic->activateLayer(dxfLine);
                                    //lastLayer=dxfLine;
                                    //}
                                    break;
                                case 10:  // Centre X
                                    dxfLine.replace( QRegExp(","), "." );
                                    vcx = dxfLine.toDouble();
                                    break;
                                case 20:  // Centre Y
                                    dxfLine.replace( QRegExp(","), "." );
                                    vcy = dxfLine.toDouble();
                                    break;
                                case 40:  // Radius
                                    dxfLine.replace( QRegExp(","), "." );
                                    vcr = dxfLine.toDouble();
                                    break;
                                case 50:  // Start Angle
                                    dxfLine.replace( QRegExp(","), "." );
                                    va1 = RS_Math::correctAngle(dxfLine.toDouble()/ARAD);
                                    break;
                                case 51:  // End Angle
                                    dxfLine.replace( QRegExp(","), "." );
                                    va2 = RS_Math::correctAngle(dxfLine.toDouble()/ARAD);
                                    break;
                                case 39:  // Thickness
                                    pen.setWidth(RS_FilterDXF::numberToWidth(dxfLine.toInt()));
                                    break;
                                case 62:  // Color
                                    pen.setColor(RS_FilterDXF::numberToColor(dxfLine.toInt()));
                                    break;
                                default:
                                    break;
                                }
                            }
                        }
                    } while(dxfCode && code!=0);
                    //if(vcr>0.0 && !mtCompFloat(va1, va2)) {
                    //  graphic->addArc(vcx, vcy, vcr, va1, va2, false, currentLayerNum, add);
                    //}
                    graphic->setActivePen(pen);
                    graphic->addEntity(new RS_Arc(graphic,
                                                  RS_ArcData(RS_Vector(vcx, vcy),
                                                             vcr, va1, va2, false)));
                }

                // -------
                // Circle:
                // -------
                else if(dxfLine=="CIRCLE") {
                    do {
                        dxfCode=getBufLine();
                        if(dxfCode)
                            code=dxfCode.toInt();
                        if(dxfCode && code!=0) {
                            dxfLine=getBufLine();
                            if(dxfLine) {
                                switch(code) {
                                case  6:  // style
                                    pen.setLineType(RS_FilterDXF::nameToLineType(dxfLine));
                                    break;
                                case  8:  // Layer
                                    //if(dxfLine!=lastLayer) {
                                                      if (dxfLine=="(null)" || dxfLine=="default") {
                                                            dxfLine = "0";
                                                      }
                                    graphic->activateLayer(dxfLine);
                                    //lastLayer=dxfLine;
                                    //}
                                    break;
                                case 10:  // Centre X
                                    dxfLine.replace( QRegExp(","), "." );
                                    vcx = dxfLine.toDouble();
                                    break;
                                case 20:  // Centre Y
                                    dxfLine.replace( QRegExp(","), "." );
                                    vcy = dxfLine.toDouble();
                                    break;
                                case 40:  // Radius
                                    dxfLine.replace( QRegExp(","), "." );
                                    vcr = dxfLine.toDouble();
                                    break;
                                case 39:  // Thickness
                                    pen.setWidth(RS_FilterDXF::numberToWidth(dxfLine.toInt()));
                                    break;
                                case 62:  // Color
                                    pen.setColor(RS_FilterDXF::numberToColor(dxfLine.toInt()));
                                    break;
                                default:
                                    break;
                                }
                            }
                        }
                    } while(dxfCode && code!=0);
                    /*if(vcr>0.0) {
                      graphic->addCircle(vcx, vcy, vcr, 0.0, 360.0, false, currentLayerNum, add);
                }*/
                    graphic->setActivePen(pen);
                    graphic->addEntity(new RS_Circle(graphic,
                                                     RS_CircleData(RS_Vector(vcx, vcy),
                                                                   vcr)));
                }


                // ------
                // Hatch:
                // ------
                /*
                if(dxfLine=="HATCH") {
                  do {
                    dxfCode=getBufLine();
                    if(dxfCode) code=dxfCode.toInt();
                    if(dxfCode && code!=0) {
                      dxfLine=getBufLine();
                      if(dxfLine) {
                        switch(code) {
                          case  8:  // Layer
                          //  if(dxfLine!=lastLayer) {
                                                      if (dxfLine=="(null)" || dxfLine=="default") {
                                                            dxfLine = "0";
                                                      }
                              graphic->activateLayer(dxfLine);
                              //lastLayer=dxfLine;
                            //}
                            break;
                          case 10:  // X1
                            vx1 = dxfLine.toDouble();
                            break;
                          case 20:  // Y1
                            vy1 = dxfLine.toDouble();
                            //graphic->Vec[vc].CreatePoint(vy1, vx1, currentLayerNum);
                            //if(vc<vElements-1) ++vc;
                            break;
                          case 11:  // X2
                            vx2 = dxfLine.toDouble();
                            break;
                          case 21:  // Y2
                            vy2 = dxfLine.toDouble();
                            //graphic->Vec[vc].CreatePoint(vy2, vx2, currentLayerNum);
                            //if(vc<vElements-1) ++vc;
                            break;
                          default:
                            break;
                        }
                      }
                    }
                  }while(dxfCode && code!=0);
                  / *
                  if(!mt.CompFloat(vx1, vx2) || !mt.CompFloat(vy1, vy2)) {
                    graphic->Vec[vc].CreateLine(vx1, vy1, vx2, vy2, currentLayerNum);
                    if(vc<vElements-1) ++vc;
                  }
                  if(++updProgress==1000) {
                    np->getStateWin()->UpdateProgressBar((int)(pcFact*vc)+25);
                    updProgress=0;
                  }
                  * /
            }
                */


                // -----
                // Text:
                // -----
                else if(dxfLine=="TEXT") {

                    RS_String vtext;          // the text
                    char  vtextStyle[256];  // text style (normal_ro, cursive_ri, normal_st, ...)
                    double vheight=10.0;     // text height
                    double vtextAng=0.0;     // text angle
                    //double vradius=0.0;      // text radius
                    //double vletterspace=2.0; // Text letter space
                    //double vwordspace=6.0;   // Text wordspace
                    RS_String vfont;         // font "normal", "cursive", ...
                    RS2::HAlign vhalign=RS2::HAlignLeft;
                    // alignment (0=left, 1=center, 2=right)
                    //int   vattachement=7;   // 1=top left, 2, 3, 4, 5, 6, 7, 8, 9=bottom right
                    //uint  vfl=0;            // special flags
                    bool  codeSeven=false;  // Have we found a code seven?

                    vtextStyle[0] = '\0';
                    vfont="normal";

                    do {
                        dxfCode=getBufLine();
                        if(dxfCode)
                            code=dxfCode.toInt();
                        if(dxfCode && code!=0) {
                            if(code!=1 && code!=3 && code!=7)
                                dxfLine=getBufLine();
                            if(dxfLine || code==1 || code==3 || code==7) {

                                switch(code) {

                                case  1:  // Text itself
                                    vtext=getBufLine();
                                    strDecodeDxfString(vtext);
                                    break;

                                case  3:  // Text parts (always 250 chars)
                                    vtext=getBufLine();
                                    break;

                                case  6:  // style
                                    pen.setLineType(RS_FilterDXF::nameToLineType(dxfLine));
                                    break;

                                case  7:  
                                                    // Text style (normal_ro#50.0, 
                                                      //    cursive_ri#20.0, normal_st)
                                    qstrncpy(vtextStyle, getBufLine(), 249);

                                    // get font typ:
                                    //
                                    {
                                        char dummy[256];
                                        sscanf(vtextStyle, "%[^_#\n]", dummy);
                                        vfont=dummy;
                                    }

                                    // get text style:
                                    //
                                    /*
                                                               if(strstr(vtextStyle, "_ro"))
                                                                   vfl=vfl|E_ROUNDOUT;
                                                               else if(strstr(vtextStyle, "_ri"))
                                                                   vfl=vfl|E_ROUNDIN;
                                                               else
                                                                   vfl=vfl|E_STRAIGHT;
                                    */
                                                      

                                    /*if(strstr(vtextStyle, "_fix")) {
                                        vfl=vfl|E_FIXEDWIDTH;
                                }*/

                                    // get radius, letterspace, wordspace:
                                    //
                                    {
                                        char *ptr;  // pointer to value
                                        ptr = strchr(vtextStyle, '#');
                                        if(ptr) {
                                            // Parse radius
                                            /*if(vfl&E_ROUNDOUT || vfl&E_ROUNDIN) {
                                                ++ptr;
                                                if(ptr[0]) {
                                                    sscanf(ptr, "%lf", &vradius);
                                                }
                                                ptr = strchr(ptr, '#');
                                        }*/
                                            /*if(ptr) {
                                                // Parse letter space:
                                                ++ptr;
                                                if(ptr[0]) {
                                                    sscanf(ptr, "%lf", &vletterspace);
                                                }
                                                // Parse word space:
                                                ptr = strchr(ptr, '#');
                                                if(ptr) {
                                                    ++ptr;
                                                    if(ptr[0]) {
                                                        sscanf(ptr, "%lf", &vwordspace);
                                                    }
                                                }
                                        }*/
                                        }
                                    }
                                    codeSeven=true;
                                    break;

                                case  8:  // Layer
                                    //if(dxfLine!=lastLayer) {
                                                      if (dxfLine=="(null)" || dxfLine=="default") {
                                                            dxfLine = "0";
                                                      }
                                    graphic->activateLayer(dxfLine);
                                    //lastLayer=dxfLine;
                                    //}
                                    break;

                                case 10:  // X1
                                    dxfLine.replace( QRegExp(","), "." );
                                    vx1 = dxfLine.toDouble();
                                    break;
                                case 20:  // Y1
                                    dxfLine.replace( QRegExp(","), "." );
                                    vy1 = dxfLine.toDouble();
                                    break;
                                case 40:  // height
                                    dxfLine.replace( QRegExp(","), "." );
                                    vheight = dxfLine.toDouble();
                                    /*if(!codeSeven) {
                                        vletterspace = vheight*0.2;
                                        vwordspace = vheight*0.6;
                                }*/
                                    break;
                                case 50:  // angle
                                    dxfLine.replace( QRegExp(","), "." );
                                    vtextAng = dxfLine.toDouble() / ARAD;
                                    break;
                                case 72:  {// alignment
                                        //if(!mtext) {
                                        int v = dxfLine.toInt();
                                        if(v==1)
                                            vhalign = RS2::HAlignCenter;
                                        else if(v==2)
                                            vhalign = RS2::HAlignRight;
                                        else
                                            vhalign = RS2::HAlignLeft;
                                        //}
                                    }
                                    break;
                                case 39:  // Thickness
                                    pen.setWidth(RS_FilterDXF::numberToWidth(dxfLine.toInt()));
                                    break;
                                case 62:  // Color
                                    pen.setColor(RS_FilterDXF::numberToColor(dxfLine.toInt()));
                                    break;
                                default:
                                    break;
                                }
                            }
                        }
                    } while(dxfCode && code!=0);
                    char* i=strchr(vtextStyle, '#');
                    if (i!=NULL) {
                        i[0] = '\0';
                    }
                    graphic->addEntity(
                        new RS_Text(graphic,
                                    RS_TextData(
                                        RS_Vector(vx1, vy1),
                                        vheight,
                                        100.0,
                                        RS2::VAlignBottom,
                                        vhalign,
                                        RS2::LeftToRight,
                                        RS2::Exact,
                                        1.0,
                                        vtext,
                                        vtextStyle,
                                        vtextAng
                                    )
                                   )
                    );
                }

                // ----------
                // Dimension:
                // ----------
                else if(dxfLine=="DIMENSION") {
                    int typ=1;
                    double v10=0.0, v20=0.0;
                    double v13=0.0, v23=0.0;
                    double v14=0.0, v24=0.0;
                    double v15=0.0, v25=0.0;
                    double v16=0.0, v26=0.0;
                    double v40=0.0, v50=0.0;
                    RS_String dimText;
                    do {
                        dxfCode=getBufLine();
                        if(dxfCode) {
                            code=dxfCode.toInt();
                        }
                        if(dxfCode && code!=0) {
                            dxfLine=getBufLine();
                            if(dxfLine) {
                                switch(code) {
                                case  1:  // Text (if any)
                                    dimText=dxfLine;

                                    // Mend unproper savings of older versions:
                                    if(dimText==" " || dimText==";;")
                                        dimText="";

                                    //else dimText.replace(QRegExp("%%c"), "");
                                    else
                                        strDecodeDxfString(dimText);
                                    break;
                                case  6:  // style
                                    pen.setLineType(RS_FilterDXF::nameToLineType(dxfLine));
                                    break;
                                case  8:  // Layer
                                    //if(dxfLine!=lastLayer) {
                                                      if (dxfLine=="(null)" || dxfLine=="default") {
                                                            dxfLine = "0";
                                                      }
                                    graphic->activateLayer(dxfLine);
                                    //lastLayer=dxfLine;
                                    //}
                                    break;
                                case 10:  // line position x
                                    dxfLine.replace( QRegExp(","), "." );
                                    v10 = dxfLine.toDouble();
                                    break;
                                case 20:  // line position y
                                    dxfLine.replace( QRegExp(","), "." );
                                    v20 = dxfLine.toDouble();
                                    break;
                                case 13:  // X1
                                    dxfLine.replace( QRegExp(","), "." );
                                    v13 = dxfLine.toDouble();
                                    break;
                                case 23:  // Y1
                                    dxfLine.replace( QRegExp(","), "." );
                                    v23 = dxfLine.toDouble();
                                    break;
                                case 14:  // X2
                                    dxfLine.replace( QRegExp(","), "." );
                                    v14 = dxfLine.toDouble();
                                    break;
                                case 24:  // Y2
                                    dxfLine.replace( QRegExp(","), "." );
                                    v24 = dxfLine.toDouble();
                                    break;
                                case 15:  // X3
                                    dxfLine.replace( QRegExp(","), "." );
                                    v15 = dxfLine.toDouble();
                                    break;
                                case 25:  // Y3
                                    dxfLine.replace( QRegExp(","), "." );
                                    v25 = dxfLine.toDouble();
                                    break;
                                case 16:  // X4
                                    dxfLine.replace( QRegExp(","), "." );
                                    v16 = dxfLine.toDouble();
                                    break;
                                case 26:  // Y4
                                    dxfLine.replace( QRegExp(","), "." );
                                    v26 = dxfLine.toDouble();
                                    break;
                                case 40:
                                    dxfLine.replace( QRegExp(","), "." );
                                    v40 = dxfLine.toDouble();
                                    break;
                                case 50:
                                    dxfLine.replace( QRegExp(","), "." );
                                    v50 = dxfLine.toDouble();
                                    break;
                                case 70:  // Typ
                                    typ = dxfLine.toInt();
                                    break;
                                case 39:  // Thickness
                                    pen.setWidth(RS_FilterDXF::numberToWidth(dxfLine.toInt()));
                                    break;
                                case 62:  // Color
                                    pen.setColor(RS_FilterDXF::numberToColor(dxfLine.toInt()));
                                    break;

                                default:
                                    break;
                                }
                            }
                        }
                    } while(dxfCode && code!=0);
                              
                    //double dist;

                    // Remove Bit values:
                    if(typ>=128) {
                        typ-=128;   // Location of Text
                              }
                    if(typ>= 64) {
                        typ-= 64;   // Ordinate
                              }

                    switch(typ) {
                        // Horiz. / vert.:
                    case 0: {
                            RS_DimLinear* d =
                                new RS_DimLinear(
                                    graphic,
                                    RS_DimensionData(
                                        RS_Vector(v10, v20),
                                        RS_Vector(0.0, 0.0),
                                        RS2::VAlignBottom,
                                        RS2::HAlignCenter,
                                        RS2::Exact,
                                        1.0,
                                        dimText,
                                        "ISO-25",
                                        0.0
                                    ),
                                    RS_DimLinearData(
                                        RS_Vector(v13, v23),
                                        RS_Vector(v14, v24),
                                        v50/ARAD,
                                        0.0
                                    )
                                );
                            d->update();
                            graphic->addEntity(d);
                        }
                        break;

                        // Aligned:
                    case 1: {
                            double angle =
                                RS_Vector(v13, v23).angleTo(RS_Vector(v10,v20));
                            double dist =
                                RS_Vector(v13, v23).distanceTo(RS_Vector(v10,v20));

                            RS_Vector defP;
                            defP.setPolar(dist, angle);
                            defP+=RS_Vector(v14, v24);

                            RS_DimAligned* d =
                                new RS_DimAligned(
                                    graphic,
                                    RS_DimensionData(
                                        defP,
                                        RS_Vector(0.0, 0.0),
                                        RS2::VAlignBottom,
                                        RS2::HAlignCenter,
                                        RS2::Exact,
                                        1.0,
                                        dimText,
                                        "ISO-25",
                                        0.0
                                    ),
                                    RS_DimAlignedData(
                                        RS_Vector(v13, v23),
                                        RS_Vector(v14, v24)
                                    )
                                );
                            d->update();
                            graphic->addEntity(d);
                        }
                        break;

                        // Angle:
                    case 2: {
                            RS_Line tl1(NULL,
                                        RS_LineData(RS_Vector(v13, v23),
                                                    RS_Vector(v14, v24)));
                            RS_Line tl2(NULL,
                                        RS_LineData(RS_Vector(v10, v20),
                                                    RS_Vector(v15, v25)));

                            RS_VectorSolutions s;
                            //bool inters=false;
                            //tmpEl1.getIntersection(&tmpEl2,
                            //                       &inters, &vcx, &vcy, 0,0,0,0, false);
                            s = RS_Information::getIntersection(
                                    &tl1, &tl2, false);

                            if (s.get(0).valid) {
                                vcx = s.get(0).x;
                                vcy = s.get(0).y;
                                //vcr = RS_Vector(vcx, vcy).distanceTo(v16, v26);

                                /*if(RS_Vector(vcx,vcy).distanceTo(v13,v23)<vcr) {
                                    va1 = tl1.getAngle1();
                            } else {
                                    va1 = tl2.getAngle2();
                            }

                                if(RS_Vector(vcx,vcy).distanceTo(v10,v20)<vcr) {
                                    va2 = tl2.getAngle1();
                            } else {
                                    va2 = tl2.getAngle2();
                            }
                                */
                                /*
                                graphic->addDimension(vcx, vcy, va1, va2,
                                               mtGetDistance(vcx, vcy, v13, v23),
                                               mtGetDistance(vcx, vcy, v10, v20),
                                                      vcr,
                                                      E_ROUNDOUT,
                                                      currentLayerNum,
                                                      add);
                                */
                                //RS_Vector dp4;
                                //dp4.setPolar();
                                RS_DimAngular* d =
                                    new RS_DimAngular(
                                        graphic,
                                        RS_DimensionData(
                                            RS_Vector(v10, v20),
                                            RS_Vector(0.0, 0.0),
                                            RS2::VAlignBottom,
                                            RS2::HAlignCenter,
                                            RS2::Exact,
                                            1.0,
                                            dimText,
                                            "ISO-25",
                                            0.0
                                        ),
                                        RS_DimAngularData(
                                            RS_Vector(v13, v23),
                                            RS_Vector(vcx, vcy),
                                            RS_Vector(vcx, vcy),
                                            RS_Vector(v16, v26)
                                        )
                                    );
                                d->update();
                                graphic->addEntity(d);
                            }
                        }
                        break;

                        // Radius:
                    case 4: {
                            /*
                                                graphic->addDimension(v10, v20, v15, v25,
                                                                    0.0, 0.0,
                                                                                      v40,
                                                                                      E_STRAIGHT|E_RADIUS,
                                                                                      currentLayerNum,
                                                                                      add);
                                                                              */

                            double ang =
                                RS_Vector(v10, v20)
                                .angleTo(RS_Vector(v15, v25));
                            RS_Vector v2;
                            v2.setPolar(v40, ang);
                            RS_DimRadial* d =
                                new RS_DimRadial(
                                    graphic,
                                    RS_DimensionData(
                                        RS_Vector(v10, v20),
                                        RS_Vector(0.0, 0.0),
                                        RS2::VAlignBottom,
                                        RS2::HAlignCenter,
                                        RS2::Exact,
                                        1.0,
                                        dimText,
                                        "ISO-25",
                                        0.0
                                    ),
                                    RS_DimRadialData(
                                        RS_Vector(v10, v20) + v2,
                                        0.0
                                    )
                                );
                            d->update();
                            graphic->addEntity(d);
                        }
                        break;

                        // Arrow:
                    case 7: {
                            /*
                                           graphic->addDimension(v13, v23, v14, v24,
                                                                 0.0, 0.0, 0.0,
                                                                 E_STRAIGHT|E_ARROW,
                                                                 currentLayerNum,
                                                                 add);
                            */
                                          /*
                            double ang =
                                RS_Vector(v10, v20)
                                .angleTo(RS_Vector(v15, v25));
                            RS_Vector v2;
                            v2.setPolar(v40, ang);
                            RS_DimDiametric* d =
                                new RS_DimDiametric(
                                    graphic,
                                    RS_DimensionData(
                                        RS_Vector(v10, v20),
                                        RS_Vector(0.0, 0.0),
                                        RS2::VAlignBottom,
                                        RS2::HAlignCenter,
                                        RS2::Exact,
                                        1.0,
                                        dimText,
                                        "ISO-25",
                                        0.0
                                    ),
                                    RS_DimDiametricData(
                                        RS_Vector(v10, v20) + v2,
                                        0.0
                                    )
                                );
                            d->update();
                            graphic->addEntity(d);
                                          */
                                          RS_LeaderData data(true);
                                          RS_Leader* d = 
                                                new RS_Leader(graphic, data);
                                          d->addVertex(RS_Vector(v14, v24));
                                          d->addVertex(RS_Vector(v10, v20));
                                          d->update();
                                          graphic->addEntity(d);
                        }
                        break;
                    }
                    //graphic->elementCurrent()->setText(dimText);
                }



                // ---------
                // Hatching:
                // ---------
                /*
                      else if(dxfLine=="HATCH") {
                        RS_String patternName="45";
                        double patternScale=1.0;
                        //int numPaths=1;
                        //int numEdges=1;
                        int nextObjectTyp=T_LINE;
                        double v10=0.0, v20=0.0,
                              v11=0.0, v21=0.0,
                              v40=0.0, v50=0.0,
                              v51=0.0;
                        do {
                          dxfCode=getBufLine();
                          if(dxfCode) code=dxfCode.toInt();
                          if(dxfCode && code!=0) {
                            dxfLine=getBufLine();
                            if(dxfLine) {
                              switch(code) {
                                case  2:
                                  patternName = dxfLine;
                                  break;
                                case  6:  // style
                                  pen.setLineType(RS_FilterDXF::nameToLineType(dxfLine));
                                  break;
                                case  8:  // Layer
                                //  if(dxfLine!=lastLayer) {
                                                      if (dxfLine=="(null)" || dxfLine=="default") {
                                                            dxfLine = "0";
                                                      }
                                    graphic->activateLayer(dxfLine);
                                    //lastLayer=dxfLine;
                                  //}
                                  break;
                                case 10:  // Start point/center of boundary line/arc
                                  dxfLine.replace( QRegExp(","), "." );
                                  v10=dxfLine.toDouble();
                                  break;
                                case 20:  // Start point/center of boundary line/arc
                                  dxfLine.replace( QRegExp(","), "." );
                                  v20=dxfLine.toDouble();
                                  break;
                                case 11:  // End point of boundary line
                                  dxfLine.replace( QRegExp(","), "." );
                                  v11=dxfLine.toDouble();
                                  break;
                                case 21:  // End point of boundary line
                                  dxfLine.replace( QRegExp(","), "." );
                                  v21=dxfLine.toDouble();
                                  if(nextObjectTyp==T_LINE) {
                                    int elnu=graphic->addLine(v10, v20, v11, v21, currentLayerNum, add);
                                    graphic->elementAt(elnu)->setFlag(E_TAGGED);
                                  }
                                  break;
                                case 40:  // Radius of boundary entity
                                  dxfLine.replace( QRegExp(","), "." );
                                  v40=dxfLine.toDouble();
                                  break;
                                case 50:  // Start angle
                                  dxfLine.replace( QRegExp(","), "." );
                                  v50=dxfLine.toDouble();
                                  break;
                                case 51:  // End angle
                                  dxfLine.replace( QRegExp(","), "." );
                                  v51=dxfLine.toDouble();
                                  break;
                                case 73:  // Counterclockwise?
                                  if(nextObjectTyp==T_ARC) {
                                    int elnu;
                                    if( mtCompFloat( v50, 0.0 ) && mtCompFloat( v51, 0.0 ) ) {
                                      elnu=graphic->addCircle(v10, v20, v40, 0.0, 360.0, (bool)dxfLine.toInt(), currentLayerNum, add);
                                    }
                                    else {
                                      elnu=graphic->addArc(v10, v20, v40, v50, v51, (bool)dxfLine.toInt(), currentLayerNum, add);
                                    }
                                    graphic->elementAt(elnu)->setFlag(E_TAGGED);
                                    //newEl = new RElement( graphic );
                                    //newEl->createArc(v10, v20, v40, v50, v51, (bool)dxfLine.toInt());
                                    //boundaryList.append(newEl);
                                  }
                                  break;
                                case 41:  // Scale
                                  dxfLine.replace( QRegExp(","), "." );
                                  patternScale=dxfLine.toDouble();
                                  break;
                                case 52:  // Angle

                                  break;
                                case 70:  // Solid (=1) or pattern (=0)

                                  break;
                                case 39:  // Thickness
                                  pen.setWidth(RS_FilterDXF::numberToWidth(dxfLine.toInt()));
                                  break;
                                case 62:  // Color
                                  pen.setColor(RS_FilterDXF::numberToColor(dxfLine.toInt()));
                                  break;
                                case 91:  // Number of boundary paths (loops)
                                  //numPaths=dxfLine.toInt();
                                  break;
                                case 92:  // Typ of boundary

                                  break;
                                case 93:  // Number of edges in this boundary
                                  //numEdges=dxfLine.toInt();
                                  break;
                                case 72:  // Edge typ
                                  switch(dxfLine.toInt()) {
                                    case 1: nextObjectTyp=T_LINE; break;
                                    case 2: nextObjectTyp=T_ARC;  break;
                                    default: break;
                                  }
                                  break;

                                default:
                                  break;
                              }
                            }
                          }
                        }while(dxfCode && code!=0);

                        graphic->addHatching(patternScale,
                                             patternName,
                                             currentLayerNum,
                                             add);

                        graphic->editDelete(false);

                      }
                */

            }
        }
        while(dxfLine && dxfLine!="EOF");

        //graphic->terminateAction();

        //graphic->debugElements();

        ret=true;
    } else {
        ret=false;
    }

    return ret;
}


Generated by  Doxygen 1.6.0   Back to index