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

bool RS_FilterDXF::fileExport ( RS_Graphic g,
const RS_String &  file,
RS2::FormatType  type 
) [virtual]

Implementation of the method used for RS_Export to communicate with this filter.

Parameters:
file Full path to the DXF file that will be written.

Implements RS_FilterInterface.

Definition at line 1201 of file rs_filterdxf.cpp.

References RS_Graphic::blockAt(), RS2::BorderLineX2, DL_WriterA::close(), RS_Graphic::countBlocks(), RS_Graphic::countLayers(), DL_Writer::dxfEOF(), DL_WriterA::dxfHex(), DL_WriterA::dxfString(), RS2::EntityImage, RS_EntityContainer::firstEntity(), RS2::FormatDXF, RS2::FormatDXF12, RS_Image::getFile(), RS_Image::getHandle(), RS_Block::getName(), graphic, DL_Writer::handle(), RS_Graphic::layerAt(), RS2::LineByBlock, RS_EntityContainer::nextEntity(), RS2::NoPen, DL_Dxf::out(), RS2::ResolveAll, RS2::ResolveNone, DL_Writer::sectionBlocks(), DL_Writer::sectionEnd(), DL_Writer::sectionEntities(), DL_Writer::sectionTables(), DL_Writer::tableAppid(), DL_Writer::tableEnd(), DL_Writer::tableLayers(), DL_Writer::tableLineTypes(), writeAppid(), writeBlock(), DL_Dxf::writeBlockRecord(), DL_Dxf::writeDimStyle(), writeEntity(), DL_Dxf::writeHeader(), writeImageDef(), writeLayer(), writeLineType(), DL_Dxf::writeObjects(), DL_Dxf::writeObjectsEnd(), DL_Dxf::writeStyle(), DL_Dxf::writeUcs(), writeVariables(), DL_Dxf::writeView(), and DL_Dxf::writeVPort().

                                                                                      {
    //std::cout << "RS_FilterDXF::fileExport\n";

    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);

    // 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);
            //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->dxfString(0, "ENDTAB");
    }

    // 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)!='*' &&
        //        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;
}


Generated by  Doxygen 1.6.0   Back to index