Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A question about reading the block's xdata. #58

Open
ysx1993 opened this issue Feb 10, 2022 · 2 comments
Open

A question about reading the block's xdata. #58

ysx1993 opened this issue Feb 10, 2022 · 2 comments

Comments

@ysx1993
Copy link

ysx1993 commented Feb 10, 2022

I use QCadCam software to create a DXF file about CAM, and this DXF file contains some cam-related data, some of the data is in the block entity, and then I use dxflib to read this DXF file, the addXDataString() interface is used to retrieve CAM data from block entity, but use libdxfrw to read DXF file, DRW_Block.extData.size () is 0, why?
Snipaste_2022-02-10_16-00-19

@ysx1993
Copy link
Author

ysx1993 commented Feb 10, 2022

This is dxf file:
CAM_2022_02_08.zip

@ysx1993
Copy link
Author

ysx1993 commented Feb 10, 2022

libdxfrw codes:

#include <QCoreApplication>
#include <libdxfrw.h>
#include <QDebug>

class DxfFileReader : public DRW_Interface
{
public:
    void addHeader(const DRW_Header *data)
    {

    }
    void addLType(const DRW_LType &data)
    {
    }
    void addLayer(const DRW_Layer &data)
    {

    }
    void addDimStyle(const DRW_Dimstyle &data)
    {
    }
    void addVport(const DRW_Vport &data)
    {
    }
    void addTextStyle(const DRW_Textstyle &data)
    {
    }
    void addAppId(const DRW_AppId &data)
    {
    }
    void addBlock(const DRW_Block &data)
    {
        for (const std::shared_ptr<DRW_Variant> &extData : data.extData) {
            switch (extData->type()) {
            case DRW_Variant::STRING:
                qDebug() << extData->content.s->c_str();
                break;
            }
        }
    }
    void setBlock(const int handle)
    {

    }
    void endBlock()
    {

    }
    void addPoint(const DRW_Point &data)
    {
    }
    void addLine(const DRW_Line &data)
    {
        for (const std::shared_ptr<DRW_Variant> &extData : data.extData) {
            switch (extData->type()) {
            case DRW_Variant::STRING:
                qDebug() << extData->content.s->c_str();
                break;
            }
        }
    }
    void addRay(const DRW_Ray &data)
    {
    }
    void addXline(const DRW_Xline &data)
    {
    }
    void addArc(const DRW_Arc &data)
    {
    }
    void addCircle(const DRW_Circle &data)
    {
    }
    void addEllipse(const DRW_Ellipse &data)
    {
    }
    void addLWPolyline(const DRW_LWPolyline &data)
    {
    }
    void addPolyline(const DRW_Polyline &data)
    {
    }
    void addSpline(const DRW_Spline *data)
    {
    }
    void addKnot(const DRW_Entity &data)
    {
    }
    void addInsert(const DRW_Insert &data)
    {
    }
    void addTrace(const DRW_Trace &data)
    {
    }
    void add3dFace(const DRW_3Dface &data)
    {
    }
    void addSolid(const DRW_Solid &data)
    {
    }
    void addMText(const DRW_MText &data)
    {
    }
    void addText(const DRW_Text &data)
    {
    }
    void addDimAlign(const DRW_DimAligned *data)
    {
    }
    void addDimLinear(const DRW_DimLinear *data)
    {
    }
    void addDimRadial(const DRW_DimRadial *data)
    {
    }
    void addDimDiametric(const DRW_DimDiametric *data)
    {
    }
    void addDimAngular(const DRW_DimAngular *data)
    {
    }
    void addDimAngular3P(const DRW_DimAngular3p *data)
    {
    }
    void addDimOrdinate(const DRW_DimOrdinate *data)
    {
    }
    void addLeader(const DRW_Leader *data)
    {
    }
    void addHatch(const DRW_Hatch *data)
    {
    }
    void addViewport(const DRW_Viewport &data)
    {
    }
    void addImage(const DRW_Image *data)
    {
    }
    void linkImage(const DRW_ImageDef *data)
    {
    }
    void addComment(const char *comment)
    {
    }
    void addPlotSettings(const DRW_PlotSettings *data)
    {
    }
    void writeHeader(DRW_Header &data)
    {
    }
    void writeBlocks()
    {
    }
    void writeBlockRecords()
    {
    }
    void writeEntities()
    {
    }
    void writeLTypes()
    {
    }
    void writeLayers()
    {
    }
    void writeTextstyles()
    {
    }
    void writeVports()
    {
    }
    void writeDimstyles()
    {
    }
    void writeObjects()
    {
    }
    void writeAppId()
    {
    }
};

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    DxfFileReader reader;
    dxfRW dxfReader("C:/Users/ysx1993/Desktop/CAM_2022_02_08.dxf");
    dxfReader.read(&reader, true);

    return a.exec();
}

dxflib codes:

#include <QCoreApplication>
#include <dl_creationadapter.h>
#include <dl_dxf.h>
#include <QDebug>

class CreationAdapter : public DL_CreationAdapter {
public:
    void addBlock(const DL_BlockData &data)
    {
        qDebug() << data.name.c_str();
    }
    void addXDataString(int code, const std::string &value)
    {
        qDebug() << value.c_str();
    }
};

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    CreationAdapter adapter;
    DL_Dxf dxf;
    if (!dxf.in("C:/Users/ysx1993/Desktop/CAM_2022_02_08.dxf", &adapter))
        return 0;

    return a.exec();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant