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

📄 rs_filterdxf.cpp

📁 Linux下一个开源的CAD软件
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        //        blk->getName().at(0)!='$') {        writeBlock(*dw, blk);        //}    }    dw->sectionEnd();    // Section ENTITIES:    RS_DEBUG->print("writing section ENTITIES...");    dw->sectionEntities();    for (RS_Entity* e=graphic->firstEntity(RS2::ResolveNone);            e!=NULL;            e=graphic->nextEntity(RS2::ResolveNone)) {        writeEntity(*dw, e);    }    RS_DEBUG->print("writing end of section ENTITIES...");    dw->sectionEnd();    if (type==RS2::FormatDXF) {        RS_DEBUG->print("writing section OBJECTS...");        dxf.writeObjects(*dw);        // IMAGEDEF's from images in entities and images in blocks        RS_StringList written;        for (uint i=0; i<graphic->countBlocks(); ++i) {            RS_Block* block = graphic->blockAt(i);            for (RS_Entity* e=block->firstEntity(RS2::ResolveAll);                    e!=NULL;                    e=block->nextEntity(RS2::ResolveAll)) {                if (e->rtti()==RS2::EntityImage) {                    RS_Image* img = ((RS_Image*)e);                    if (written.contains(file)==0 && img->getHandle()!=0) {                        writeImageDef(*dw, img);                        written.append(img->getFile());                    }                }            }        }        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 (written.contains(file)==0 && img->getHandle()!=0) {                    writeImageDef(*dw, img);                    written.append(img->getFile());                }            }        }        RS_DEBUG->print("writing end of section OBJECTS...");        dxf.writeObjectsEnd(*dw);    }    RS_DEBUG->print("writing EOF...");    dw->dxfEOF();    RS_DEBUG->print("close..");    dw->close();    delete dw;    // check if file was actually written (strange world of windoze xp):    if (RS_FileInfo(file).exists()==false) {        RS_DEBUG->print("RS_FilterDXF::fileExport: file could not be written");        return false;    }    return true;}/** * Writes all known variable settings to the DXF file. */void RS_FilterDXF::writeVariables(DL_WriterA& dw) {    RS_DictIterator<RS_Variable> it(graphic->getVariableDict());    for (; it.current(); ++it) {        // exclude variables that are not known to DXF 12:        if (!DL_Dxf::checkVariable(it.currentKey().latin1(), dxf.getVersion())) {            continue;        }        if (it.currentKey()!="$ACADVER" && it.currentKey()!="$HANDSEED") {            dw.dxfString(9, (const char*) it.currentKey());            switch (it.current()->getType()) {            case RS2::VariableVoid:                break;            case RS2::VariableInt:                dw.dxfInt(it.current()->getCode(), it.current()->getInt());                break;            case RS2::VariableDouble:                dw.dxfReal(it.current()->getCode(), it.current()->getDouble());                break;            case RS2::VariableString:                dw.dxfString(it.current()->getCode(),                             (const char*) it.current()->getString());                break;            case RS2::VariableVector:                dw.dxfReal(it.current()->getCode(),                           it.current()->getVector().x);                dw.dxfReal(it.current()->getCode()+10,                           it.current()->getVector().y);                if (isVariableTwoDimensional(it.currentKey())==false) {                    dw.dxfReal(it.current()->getCode()+20,                               it.current()->getVector().z);                }                break;            }        }    }    dw.sectionEnd();}/** * Writes one layer to the DXF file. * * @todo Add support for unicode layer names */void RS_FilterDXF::writeLayer(DL_WriterA& dw, RS_Layer* l) {    if (l==NULL) {		RS_DEBUG->print(RS_Debug::D_WARNING, 			"RS_FilterDXF::writeLayer: layer is NULL");        return;    }    RS_DEBUG->print("RS_FilterDXF::writeLayer %s", l->getName().latin1());    dxf.writeLayer(        dw,        DL_LayerData((const char*)l->getName().local8Bit(),                     l->isFrozen() + (l->isLocked()<<2)),        DL_Attributes(std::string(""),                      colorToNumber(l->getPen().getColor()),                      widthToNumber(l->getPen().getWidth()),                      (const char*)lineTypeToName(                          l->getPen().getLineType()).local8Bit()));    RS_DEBUG->print("RS_FilterDXF::writeLayer end");}/** * Writes a line type to the DXF file. */void RS_FilterDXF::writeLineType(DL_WriterA& dw, RS2::LineType t) {    dxf.writeLineType(        dw,        DL_LineTypeData((const char*)lineTypeToName(t).local8Bit(), 0));}/** * Writes an application id to the DXF file. * * @param appid Application ID (e.g. "QCad"). */void RS_FilterDXF::writeAppid(DL_WriterA& dw, const char* appid) {    dxf.writeAppid(dw, appid);}/** * Writes a block (just the definition, not the entities in it). */void RS_FilterDXF::writeBlock(DL_WriterA& dw, RS_Block* blk) {    if (blk==NULL) {        RS_DEBUG->print(RS_Debug::D_WARNING,			"RS_FilterDXF::writeBlock: Block is NULL");        return;    }    RS_DEBUG->print("writing block: %s", (const char*)blk->getName().local8Bit());    dxf.writeBlock(dw,                   DL_BlockData((const char*)blk->getName().local8Bit(), 0,                                blk->getBasePoint().x,                                blk->getBasePoint().y,                                blk->getBasePoint().z));    for (RS_Entity* e=blk->firstEntity(RS2::ResolveNone);            e!=NULL;            e=blk->nextEntity(RS2::ResolveNone)) {        writeEntity(dw, e);    }    dxf.writeEndBlock(dw, (const char*)blk->getName().local8Bit());}/** * Writes the given entity to the DXF file. */void RS_FilterDXF::writeEntity(DL_WriterA& dw, RS_Entity* e) {    writeEntity(dw, e, getEntityAttributes(e));}/** * Writes the given entity to the DXF file. */void RS_FilterDXF::writeEntity(DL_WriterA& dw, RS_Entity* e,                               const DL_Attributes& attrib) {    if (e==NULL || e->getFlag(RS2::FlagUndone)) {        return;    }    RS_DEBUG->print("writing Entity");    switch (e->rtti()) {    case RS2::EntityPoint:        writePoint(dw, (RS_Point*)e, attrib);        break;    case RS2::EntityLine:        writeLine(dw, (RS_Line*)e, attrib);        break;    case RS2::EntityPolyline:        writePolyline(dw, (RS_Polyline*)e, attrib);        break;    case RS2::EntitySpline:        writeSpline(dw, (RS_Spline*)e, attrib);        break;    case RS2::EntityVertex:        break;    case RS2::EntityCircle:        writeCircle(dw, (RS_Circle*)e, attrib);        break;    case RS2::EntityArc:        writeArc(dw, (RS_Arc*)e, attrib);        break;    case RS2::EntityEllipse:        writeEllipse(dw, (RS_Ellipse*)e, attrib);        break;    case RS2::EntityInsert:        writeInsert(dw, (RS_Insert*)e, attrib);        break;    case RS2::EntityText:        writeText(dw, (RS_Text*)e, attrib);        break;    case RS2::EntityDimAligned:    case RS2::EntityDimAngular:    case RS2::EntityDimLinear:    case RS2::EntityDimRadial:    case RS2::EntityDimDiametric:        writeDimension(dw, (RS_Dimension*)e, attrib);        break;    case RS2::EntityDimLeader:        writeLeader(dw, (RS_Leader*)e, attrib);        break;    case RS2::EntityHatch:        writeHatch(dw, (RS_Hatch*)e, attrib);        break;    case RS2::EntityImage:        writeImage(dw, (RS_Image*)e, attrib);        break;    case RS2::EntitySolid:        writeSolid(dw, (RS_Solid*)e, attrib);        break;#ifndef RS_NO_COMPLEX_ENTITIES    case RS2::EntityContainer:        writeEntityContainer(dw, (RS_EntityContainer*)e, attrib);        break;#endif    default:        break;    }}/** * Writes the given Point entity to the file. */void RS_FilterDXF::writePoint(DL_WriterA& dw, RS_Point* p,                              const DL_Attributes& attrib) {    dxf.writePoint(        dw,        DL_PointData(p->getPos().x,                     p->getPos().y,                     0.0),        attrib);}/** * Writes the given Line( entity to the file. */void RS_FilterDXF::writeLine(DL_WriterA& dw, RS_Line* l,                             const DL_Attributes& attrib) {    dxf.writeLine(        dw,        DL_LineData(l->getStartpoint().x,                    l->getStartpoint().y,                    0.0,                    l->getEndpoint().x,                    l->getEndpoint().y,                    0.0),        attrib);}/** * Writes the given polyline entity to the file. */void RS_FilterDXF::writePolyline(DL_WriterA& dw,                                 RS_Polyline* l,                                 const DL_Attributes& attrib) {	int count = l->count();	if (l->isClosed()==false) {		count++;	}	dxf.writePolyline(        dw,        DL_PolylineData(count,                        0, 0,                        l->isClosed()*0x1),        attrib);    bool first = true;    RS_Entity* nextEntity = 0;    RS_AtomicEntity* ae = NULL;	RS_Entity* lastEntity = l->lastEntity(RS2::ResolveNone);    for (RS_Entity* v=l->firstEntity(RS2::ResolveNone);            v!=NULL;            v=nextEntity) {        nextEntity = l->nextEntity(RS2::ResolveNone);        if (!v->isAtomic()) {            continue;        }        ae = (RS_AtomicEntity*)v;        double bulge=0.0;        		// Write vertex:        if (first) {            if (v->rtti()==RS2::EntityArc) {                bulge = ((RS_Arc*)v)->getBulge();            }            dxf.writeVertex(dw,                            DL_VertexData(ae->getStartpoint().x,                                          ae->getStartpoint().y,                                          0.0,										  bulge));            first = false;        }        //if (dxf.getVersion()==VER_R12) {            if (nextEntity!=NULL) {                if (nextEntity->rtti()==RS2::EntityArc) {                    bulge = ((RS_Arc*)nextEntity)->getBulge();                }				else {					bulge = 0.0;				}            }        /*} else {            if (v->rtti()==RS2::EntityArc) {                bulge = ((RS_Arc*)v)->getBulge();            }        }*/		if (l->isClosed()==false || v!=lastEntity) {        	dxf.writeVertex(dw,                        DL_VertexData(ae->getEndpoint().x,                                      ae->getEndpoint().y,                                      0.0,                                      bulge));		}    }    dxf.writePolylineEnd(dw);}/** * Writes the given spline entity to the file. */void RS_FilterDXF::writeSpline(DL_WriterA& dw,                               RS_Spline* s,                               const DL_Attributes& attrib) {    // split spline into atomic entities for DXF R12:    if (dxf.getVersion()==VER_R12) {        writeAtomicEntities(dw, s, attrib, RS2::ResolveNone);        return;    }    if (s->getNumberOfControlPoints() < s->getDegree()+1) {        RS_DEBUG->print(RS_Debug::D_ERROR, "RS_FilterDXF::writeSpline: "                        "Discarding spline: not enough control points given.");        return;    }    // Number of control points:    int numCtrl = s->getNumberOfControlPoints();    // Number of knots (= number of control points + spline degree + 1)    int numKnots = numCtrl + s->getDegree() + 1;    int flags;    if (s->isClosed()) {        flags = 11;    } else {        flags = 8;    }    // write spline header:    dxf.writeSpline(        dw,        DL_SplineData(s->getDegree(),                      numKnots,                      numCtrl,                      flags),        attrib);    // write spline knots:    RS_ValueList<RS_Vector> cp = s->getControlPoints();    RS_ValueList<RS_Vector>::iterator it;    int k = s->getDegree()+1;

⌨️ 快捷键说明

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