⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rs_filterdxf.cpp

📁 Linux下一个开源的CAD软件
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    if (leader!=NULL) {        leader->addVertex(v);    }}/** * Implementation of the method which handles hatch entities. */void RS_FilterDXF::addHatch(const DL_HatchData& data) {    RS_DEBUG->print("RS_FilterDXF::addHatch()");    hatch = new RS_Hatch(currentContainer,                         RS_HatchData(data.solid,                                      data.scale,                                      data.angle,                                      RS_String(data.pattern.c_str())));    setEntityAttributes(hatch, attributes);    currentContainer->addEntity(hatch);}/** * Implementation of the method which handles hatch loops. */void RS_FilterDXF::addHatchLoop(const DL_HatchLoopData& /*data*/) {    RS_DEBUG->print("RS_FilterDXF::addHatchLoop()");    if (hatch!=NULL) {        hatchLoop = new RS_EntityContainer(hatch);        hatchLoop->setLayer(NULL);        hatch->addEntity(hatchLoop);    }}/** * Implementation of the method which handles hatch edge entities. */void RS_FilterDXF::addHatchEdge(const DL_HatchEdgeData& data) {    RS_DEBUG->print("RS_FilterDXF::addHatchEdge()");    if (hatchLoop!=NULL) {        RS_Entity* e = NULL;        switch (data.type) {        case 1:            RS_DEBUG->print("RS_FilterDXF::addHatchEdge(): "                            "line: %f,%f %f,%f",                            data.x1, data.y1, data.x2, data.y2);            e = new RS_Line(hatchLoop,                            RS_LineData(RS_Vector(data.x1, data.y1),                                        RS_Vector(data.x2, data.y2)));            break;        case 2:            if (data.ccw && data.angle1<1.0e-6 && data.angle2>2*M_PI-1.0e-6) {                e = new RS_Circle(hatchLoop,                                  RS_CircleData(RS_Vector(data.cx, data.cy),                                                data.radius));            } else {                if (data.ccw) {                    e = new RS_Arc(                            hatchLoop,                            RS_ArcData(RS_Vector(data.cx, data.cy),                                       data.radius,                                       RS_Math::correctAngle(data.angle1),                                       RS_Math::correctAngle(data.angle2),                                       false));                } else {                    e = new RS_Arc(                            hatchLoop,                            RS_ArcData(RS_Vector(data.cx, data.cy),                                       data.radius,                                       RS_Math::correctAngle(2*M_PI-data.angle1),                                       RS_Math::correctAngle(2*M_PI-data.angle2),                                       true));                }            }            break;        default:            break;        }        if (e!=NULL) {            e->setLayer(NULL);            hatchLoop->addEntity(e);        }    }}/** * Implementation of the method which handles image entities. */void RS_FilterDXF::addImage(const DL_ImageData& data) {    RS_DEBUG->print("RS_FilterDXF::addImage");    RS_Vector ip(data.ipx, data.ipy);    RS_Vector uv(data.ux, data.uy);    RS_Vector vv(data.vx, data.vy);    RS_Vector size(data.width, data.height);    RS_Image* image =        new RS_Image(            currentContainer,            RS_ImageData(RS_String(data.ref.c_str()).toInt(NULL, 16),                         ip, uv, vv,                         size,                         RS_String(""),                         data.brightness,                         data.contrast,                         data.fade));    setEntityAttributes(image, attributes);    currentContainer->addEntity(image);}/** * Implementation of the method which links image entities to image files. */void RS_FilterDXF::linkImage(const DL_ImageDefData& data) {    RS_DEBUG->print("RS_FilterDXF::linkImage");    int handle = RS_String(data.ref.c_str()).toInt(NULL, 16);    RS_String sfile(data.file.c_str());    RS_FileInfo fiDxf(file);    RS_FileInfo fiBitmap(sfile);    // try to find the image file:    // first: absolute path:    if (!fiBitmap.exists()) {        RS_DEBUG->print("File %s doesn't exist.",                        (const char*)QFile::encodeName(sfile));        // try relative path:        RS_String f1 = fiDxf.dirPath(true) + "/" + sfile;        if (RS_FileInfo(f1).exists()) {            sfile = f1;        } else {            RS_DEBUG->print("File %s doesn't exist.", (const char*)QFile::encodeName(f1));            // try drawing path:            RS_String f2 = fiDxf.dirPath(true) + "/" + fiBitmap.fileName();            if (RS_FileInfo(f2).exists()) {                sfile = f2;            } else {                RS_DEBUG->print("File %s doesn't exist.", (const char*)QFile::encodeName(f2));            }        }    }    // Also link images in subcontainers (e.g. inserts):    for (RS_Entity* e=graphic->firstEntity(RS2::ResolveNone);            e!=NULL; e=graphic->nextEntity(RS2::ResolveNone)) {        if (e->rtti()==RS2::EntityImage) {            RS_Image* img = (RS_Image*)e;            if (img->getHandle()==handle) {                img->setFile(sfile);                RS_DEBUG->print("image found: %s", (const char*)QFile::encodeName(img->getFile()));                img->update();            }        }    }    // update images in blocks:    for (uint i=0; i<graphic->countBlocks(); ++i) {        RS_Block* b = graphic->blockAt(i);        for (RS_Entity* e=b->firstEntity(RS2::ResolveNone);                e!=NULL; e=b->nextEntity(RS2::ResolveNone)) {            if (e->rtti()==RS2::EntityImage) {                RS_Image* img = (RS_Image*)e;                if (img->getHandle()==handle) {                    img->setFile(sfile);                    RS_DEBUG->print("image in block found: %s",                                    (const char*)QFile::encodeName(img->getFile()));                    img->update();                }            }        }    }    RS_DEBUG->print("linking image: OK");}/** * Finishes a hatch entity. */void RS_FilterDXF::endEntity() {    RS_DEBUG->print("RS_FilterDXF::endEntity");    if (hatch!=NULL) {        RS_DEBUG->print("hatch->update()");        if (hatch->validate()) {            hatch->update();        } else {            graphic->removeEntity(hatch);            RS_DEBUG->print(RS_Debug::D_ERROR,                            "RS_FilterDXF::endEntity(): updating hatch failed: invalid hatch area");        }        hatch=NULL;    }}/** * Sets a vector variable from the DXF file. */void RS_FilterDXF::setVariableVector(const char* key,                                     double v1, double v2, double v3, int code) {    RS_DEBUG->print("RS_FilterDXF::setVariableVector");    // update document's variable list:    if (currentContainer->rtti()==RS2::EntityGraphic) {        ((RS_Graphic*)currentContainer)->addVariable(RS_String(key),                RS_Vector(v1, v2, v3), code);    }}/** * Sets a string variable from the DXF file. */void RS_FilterDXF::setVariableString(const char* key,                                     const char* value, int code) {    RS_DEBUG->print("RS_FilterDXF::setVariableString");    // update local DXF variable list:    variables.add(RS_String(key), RS_String(value), code);    // update document's variable list:    if (currentContainer->rtti()==RS2::EntityGraphic) {        ((RS_Graphic*)currentContainer)->addVariable(RS_String(key),                RS_String(value), code);    }}/** * Sets an int variable from the DXF file. */void RS_FilterDXF::setVariableInt(const char* key, int value, int code) {    RS_DEBUG->print("RS_FilterDXF::setVariableInt");    // update document's variable list:    if (currentContainer->rtti()==RS2::EntityGraphic) {        ((RS_Graphic*)currentContainer)->addVariable(RS_String(key),                value, code);    }}/** * Sets a double variable from the DXF file. */void RS_FilterDXF::setVariableDouble(const char* key, double value, int code) {    RS_DEBUG->print("RS_FilterDXF::setVariableDouble");    // update document's variable list:    if (currentContainer->rtti()==RS2::EntityGraphic) {        ((RS_Graphic*)currentContainer)->addVariable(RS_String(key),                value, code);    }}/** * Implementation of the method used for RS_Export to communicate * with this filter. * * @param file Full path to the DXF file that will be written. */bool RS_FilterDXF::fileExport(RS_Graphic& g, const RS_String& file, RS2::FormatType type) {    RS_DEBUG->print("RS_FilterDXF::fileExport: exporting file '%s'...",                    (const char*)QFile::encodeName(file));    RS_DEBUG->print("RS_FilterDXF::fileExport: file type '%d'", (int)type);    this->graphic = &g;    // check if we can write to that directory:#ifndef Q_OS_WIN    RS_String path = RS_FileInfo(file).dirPath(true);    if (RS_FileInfo(path).isWritable()==false) {        RS_DEBUG->print("RS_FilterDXF::fileExport: can't write file: "                        "no permission");        return false;    }    //#endif    // set version for DXF filter:    DL_Codes::version exportVersion;    if (type==RS2::FormatDXF12) {        exportVersion = DL_Codes::AC1009;    } else {        exportVersion = DL_Codes::AC1015;    }    //DL_WriterA* dw = dxf.out(file, VER_R12);    DL_WriterA* dw = dxf.out((const char*)QFile::encodeName(file), exportVersion);    if (dw==NULL) {        RS_DEBUG->print("RS_FilterDXF::fileExport: can't write file");        return false;    }    // Header    RS_DEBUG->print("writing headers...");    dxf.writeHeader(*dw);    // Variables    RS_DEBUG->print("writing variables...");    writeVariables(*dw);    // Section TABLES    RS_DEBUG->print("writing tables...");    dw->sectionTables();    // VPORT:    dxf.writeVPort(*dw);    // Line types:    RS_DEBUG->print("writing line types...");    int numLT = (int)RS2::BorderLineX2-(int)RS2::LineByBlock;    if (type==RS2::FormatDXF12) {        numLT-=2;    }    dw->tableLineTypes(numLT);    for (int t=(int)RS2::LineByBlock; t<=(int)RS2::BorderLineX2; ++t) {        if ((RS2::LineType)t!=RS2::NoPen) {            writeLineType(*dw, (RS2::LineType)t);        }    }    dw->tableEnd();    // Layers:    RS_DEBUG->print("writing layers...");    dw->tableLayers(graphic->countLayers());    for (uint i=0; i<graphic->countLayers(); ++i) {        RS_Layer* l = graphic->layerAt(i);        writeLayer(*dw, l);    }    dw->tableEnd();    // STYLE:    RS_DEBUG->print("writing styles...");    dxf.writeStyle(*dw);    // VIEW:    RS_DEBUG->print("writing views...");    dxf.writeView(*dw);    // UCS:    RS_DEBUG->print("writing ucs...");    dxf.writeUcs(*dw);    // Appid:    RS_DEBUG->print("writing appid...");    dw->tableAppid(1);    writeAppid(*dw, "ACAD");    dw->tableEnd();    // DIMSTYLE:    RS_DEBUG->print("writing dim styles...");    dxf.writeDimStyle(*dw,                      graphic->getVariableDouble("$DIMASZ", 2.5),                      graphic->getVariableDouble("$DIMEXE", 1.25),                      graphic->getVariableDouble("$DIMEXO", 0.625),                      graphic->getVariableDouble("$DIMGAP", 0.625),                      graphic->getVariableDouble("$DIMTXT", 2.5));    // BLOCK_RECORD:    if (type==RS2::FormatDXF) {        RS_DEBUG->print("writing block records...");        dxf.writeBlockRecord(*dw);        for (uint i=0; i<graphic->countBlocks(); ++i) {            RS_Block* blk = graphic->blockAt(i);			dxf.writeBlockRecord(*dw, 			    std::string((const char*)blk->getName().local8Bit()));			/*			// v2.0.4.9..:            //writeBlock(*dw, blk);            dw->dxfString(  0, "BLOCK_RECORD");            //dw.dxfHex(5, 0x1F);            dw->handle();            dw->dxfHex(330, 1);            dw->dxfString(100, "AcDbSymbolTableRecord");            dw->dxfString(100, "AcDbBlockTableRecord");            dw->dxfString(  2, blk->getName().local8Bit());            dw->dxfHex(340, 0);			*/        }    	dw->tableEnd();    }    // end of tables:    RS_DEBUG->print("writing end of section TABLES...");    dw->sectionEnd();    // Section BLOCKS:    RS_DEBUG->print("writing blocks...");    dw->sectionBlocks();    if (type==RS2::FormatDXF) {        RS_Block b1(graphic, RS_BlockData("*Model_Space",                                          RS_Vector(0.0,0.0), false));        writeBlock(*dw, &b1);        RS_Block b2(graphic, RS_BlockData("*Paper_Space",                                          RS_Vector(0.0,0.0), false));        writeBlock(*dw, &b2);        RS_Block b3(graphic, RS_BlockData("*Paper_Space0",                                          RS_Vector(0.0,0.0), false));        writeBlock(*dw, &b3);    }    for (uint i=0; i<graphic->countBlocks(); ++i) {        RS_Block* blk = graphic->blockAt(i);        // Save block if it's not a model or paper space:        // Careful: other blocks with * / $ exist        //if (blk->getName().at(0)!='*' &&

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -