dxf转pdf linux,通过dxflib库读取DXF文件

#include /@@**

* Default constructor.

*/

Test_CreationClass::Test_CreationClass() {}

/@@**

* Sample implementation of the method which handles layers.

*/

void Test_CreationClass::addLayer(const DL_LayerData& data) {

printf("LAYER: %s flags: %d\n", data.name.c_str(), data.flags);

printAttributes();

}

/@@**

* Sample implementation of the method which handles point entities.

*/

void Test_CreationClass::addPoint(const DL_PointData& data) {

printf("POINT (%6.3f, %6.3f, %6.3f)\n",

data.x, data.y, data.z);

printAttributes();

}

/@@**

* Sample implementation of the method which handles line entities.

*/

void Test_CreationClass::addLine(const DL_LineData& data) {

printf("LINE (%6.3f, %6.3f, %6.3f) (%6.3f, %6.3f, %6.3f)\n",

data.x1, data.y1, data.z1, data.x2, data.y2, data.z2);

printAttributes();

}

/@@**

* Sample implementation of the method which handles arc entities.

*/

void Test_CreationClass::addArc(const DL_ArcData& data) {

printf("ARC (%6.3f, %6.3f, %6.3f) %6.3f, %6.3f, %6.3f\n",

data.cx, data.cy, data.cz,

data.radius, data.angle1, data.angle2);

printAttributes();

}

/@@**

* Sample implementation of the method which handles circle entities.

*/

void Test_CreationClass::addCircle(const DL_CircleData& data) {

printf("CIRCLE (%6.3f, %6.3f, %6.3f) %6.3f\n",

data.cx, data.cy, data.cz,

data.radius);

printAttributes();

}

/@@**

* Sample implementation of the method which handles polyline entities.

*/

void Test_CreationClass::addPolyline(const DL_PolylineData& data) {

printf("POLYLINE \n");

printf("flags: %d\n", (int)data.flags);

printAttributes();

}

/@@**

* Sample implementation of the method which handles vertices.

*/

void Test_CreationClass::addVertex(const DL_VertexData& data) {

printf("VERTEX (%6.3f, %6.3f, %6.3f) %6.3f\n",

data.x, data.y, data.z,

data.bulge);

printAttributes();

}

void Test_CreationClass::add3dFace(const DL_3dFaceData& data) {

printf("3DFACE\n");

for (int i=0; i<4; i++) {

printf(" corner %d: %6.3f %6.3f %6.3f\n",

i, data.x[i], data.y[i], data.z[i]);

}

printAttributes();

}

void Test_CreationClass::printAttributes() {

printf(" Attributes: Layer: %s, ", attributes.getLayer().c_str());

printf(" Color: ");

if (attributes.getColor()==256){

printf("BYLAYER");

} else if (attributes.getColor()==0) {

printf("BYBLOCK");

} else {

printf("%d", attributes.getColor());

}

printf(" Width: ");

if (attributes.getWidth()==-1) {

printf("BYLAYER");

} else if (attributes.getWidth()==-2) {

printf("BYBLOCK");

} else if (attributes.getWidth()==-3) {

printf("DEFAULT");

} else {

printf("%d", attributes.getWidth());

}

printf(" Type: %s\n", attributes.getLinetype().c_str());

}

```

main文件中大家直接调用testReading函数就可以了

```cpp

void testReading(char* file) {

// Load DXF file into memory:

std::cout << "Reading file " << file << "...\n";

Test_CreationClass* creationClass = new Test_CreationClass();

DL_Dxf* dxf = new DL_Dxf();

if (!dxf->in(file, creationClass)) { // if file open failed

std::cerr << file << " could not be opened.\n";

return;

}

delete dxf;

delete creationClass;

}

```

大家运行一下代码应该可以得到dxf文件的数据,运行结果如下:

![](https://b04.ickimg.com/202004/4211ef4455e209d7fc1db19bc72e2709.png)

需要注意的是,如果大家的工程和build文件夹不在一起的话,可能会提示你.dxf文件找不到,你需要把等待读取的.dxf文件放到build文件夹中。

最后附上代码地址:https://github.com/sixsmall/dxflib-dxf.git

你可能感兴趣的:(dxf转pdf,linux)