Page 1 of 1

Reading DXF: how to assign a line to a layer ?

Posted: Mon Jun 24, 2013 6:20 pm
by rekoru
I have a DXF file with lines assigned to several layers. I would like to determine a layer for each line object in a DXF file. As there is no layer info in DL_LineData struct, I hoped to get the line->layer affiliation info using order of addLine() and addLayer() calls. I wrote simple test app and discovered that all addLayer() calls during execution of DL_Dxf::in() happen before first addLine call(). How to check to which layer a line belongs to?

Re: Reading DXF: how to assign a line to a layer ?

Posted: Mon Jun 24, 2013 7:32 pm
by andrew
Layers are reported through the DL_CreationInterface using the function DL_CreationInterface::addLayer(...). All layers that are reported through that interface are typically stored in a list or map of layers.

The current layer is part of the current entity attributes. You can get the current attributes by calling
DL_Attributes getAttributes()
of your implementation of the DL_CreationInterface.

When an entity is reported, for example a line entity though DL_CreationInterface::addLine(...), you can get information about the layer it is on (as well as other attributes) through the attributes member variable:
MyImporter::addLine(const DL_LineData& data) {
    std::out << "line is on layer " << getAttributes().getLayer();
}

Re: Reading DXF: how to assign a line to a layer ?

Posted: Mon Jun 24, 2013 8:04 pm
by rekoru
I missed whole attributes thing. But now my sample works exactly as I need to :) Thank you very much!