Beginner : How to store DXF data

Use this forum to ask questions about how to do things in dxflib.

Moderator: andrew

Beginner : How to store DXF data

Postby tomate » Wed Jul 18, 2007 8:26 am

Hello,
First, I would like to Thank Andrew for Qcad. It is a really great software.
I am a nearly total beginner in C++ programming.
Starting with the "test" source code of dxflib, I am trying to store the datas of a dxf file composed of 217 lines.
So I modified test_creationclass.h this way :

Code: Select all
class Test_CreationClass : public DL_CreationAdapter {
public:
   int NbLine;
   double OLx1[500];
   double OLy1[500];
   double OLx2[500];
   double OLy2[500];

    Test_CreationClass();

    virtual void addLayer(const DL_LayerData& data);
    virtual void addPoint(const DL_PointData& data);
    virtual void addLine(const DL_LineData& data);
    virtual void addArc(const DL_ArcData& data);
    virtual void addCircle(const DL_CircleData& data);
    virtual void addPolyline(const DL_PolylineData& data);
    virtual void addVertex(const DL_VertexData& data);

    void printAttributes();
};


And test_creationclass.cpp this way :

Code: Select all
void Test_CreationClass::addLine(const DL_LineData& data) {
    printf("LINE     (%6.3f, %6.3f, %6.3f) (%6.3f, %6.3f, %6.3f)  ligne : %d\n",
           data.x1, data.y1, data.z1, data.x2, data.y2, data.z2, NbLine + 1);
   OLx1[NbLine]=data.x1;
   OLy1[NbLine]=data.y1;
   OLx2[NbLine]=data.x2;
   OLy2[NbLine]=data.y2;

   NbLine+=1;
   
}


But when I run it, it segfaults at the end, because of this :

Code: Select all
OLx1[NbLine]=data.x1;
OLy1[NbLine]=data.y1;
OLx2[NbLine]=data.x2;
OLy2[NbLine]=data.y2;


By further investigation, I saw that it jumps over the line 151 of the dxf file.

Would someone have an idea of what is happening ??
Thanks a lot.
tomate
Newbie Member
 
Posts: 5
Joined: Wed Jul 18, 2007 8:11 am
Location: France

Postby tomate » Wed Jul 18, 2007 8:52 am

Ooops, sorry. I found the problem. It was the last line of this ( in main.cpp ) :

Code: Select all
void testReading(char* file) {
    // Load DXF file into memory:
    std::cout << "Reading file " << file << "...\n";
    Test_CreationClass creationClass;
    DL_Dxf dxf;
    if (!dxf.in(file, &creationClass)) { // if file open failed
        std::cerr << file << " could not be opened.\n";
        return;
    }
   std::cout << "Nombre de lignes : " << creationClass.NbLine << "\n";
   std::cout << "Nombre de points : " << creationClass.NbLine + 1 << "\n";
}


Yes, you're right, I should stop programming right now, and find another hobby !
tomate
Newbie Member
 
Posts: 5
Joined: Wed Jul 18, 2007 8:11 am
Location: France


Return to dxflib 'How Do I' Questions

Who is online

Users browsing this forum: No registered users and 3 guests