3 Reading DXF Files

Figure 1: dxflib parses DXF files
and calls functions in your class. In those functions you can for example add
the entities to a vector or list of entities.
Implementing the Creation Interface
Your C++ class that handles DXF entities has to be derived from
DL_CreationInterface or DL_CreationAdapter. In most cases DL_CreationAdapter
is more convenient because it doesn't force you to implement all
functions.
class MyDxfFilter : public DL_CreationAdapter { virtual void addLine(const DL_LineData& d); ... }
The implementation of the functions in your class will typically add
the entities to a container of entities or use the information in another
way.
void MyDxfFilter::addLine(const DL_LineData& d) { std::cout << "Line: " << d.x1 << "/" << d.y1 << " " << d.x2 << "/" << d.y2 << std::endl; }
When reading a DXF file you simply pass on a reference to an object of
your class to the parser.
MyDxfFilter f;
DL_Dxf* dxf = new DL_Dxf();
if (!dxf->in("drawing.dxf", &f)) {
std::cerr << "drawing.dxf could not be opened.\n";
}
delete dxf;
|