
Mon, 09/06/2010 - 12:04
Hello OpenCascade users,
my name is Enrico and I am working on a small DXF file converter. Since OpenCascade has a nice DXF module I am giving a look at it. Unfortunately I am very little proficient with OCC and I am getting a little lost here. I hope that someone may shed some light on a couple of aspects.
Since I am working on the DXF and I need the info on layers, node names, shapes and so on, I am using the library to convert the DXF into an XCAF document. Basically I am doing this:
Handle(XSControl_WorkSession) WS = new XSControl_WorkSession;
DXFCAFControl_Reader reader ( WS, Standard_False );
reader.SetColorMode(Standard_True);
reader.SetNameMode(Standard_True);
IFSelect_ReturnStatus stat = reader.ReadFile((const Standard_CString)stp_fname.c_str());
this should return me the read dxf file. Then I am converting it into XCAF:
Handle(TDocStd_Document) doc;
Handle ( XCAFApp_Application ) anApp = XCAFApp_Application::GetApplication();
anApp->NewDocument("MDTV-XCAF", doc);
Handle(XCAFDoc_ColorTool) ColorTool = XCAFDoc_DocumentTool::ColorTool(doc->Main());
Handle(XCAFDoc_ShapeTool) ShapeTool = XCAFDoc_DocumentTool::ShapeTool(doc->Main());
Handle(XCAFDoc_LayerTool) LayerTool = XCAFDoc_DocumentTool::LayerTool(doc->Main());
TDF_Label dxfroot = doc->Main ();
recursiveDXFLabelReader (dxfroot, ShapeTool, LayerTool, root);
the last one call is a small recursive function that i wrote to retrieve the label hierarchy and convert the file:
void OCCReader::recursiveDXFLabelReader (TDF_Label &label, Handle_XCAFDoc_ShapeTool shapeTool, Handle_XCAFDoc_LayerTool layerTool, MyGraphNode parent)
{
Standard_Boolean b = layerTool->IsLayer (label);
if (b)
printf ("Found a layer\n");
Standard_Integer nChildren = label.NbChildren();
MyGraphNode thisNode = NULL;
TopoDS_Shape shape = shapeTool->GetShape (label);
if (shape.IsNull ()==false)
thisNode = convertGeoToMyGraph (shape);
// if there aren't geometries just build a group node to contain the informations
if (thisNode == NULL)
thisNode = groupNode::create();
Handle (TDataStd_Name) N;
Standard_ExtString str;
if (label.FindAttribute (TDataStd_Name::GetID(), N))
{
TCollection_ExtendedString name = N->Get ();
str = name.ToExtString ();
setName (thisNode, (const char*)str);
}
else
setName (thisNode, "NoName");
parent->addChild (thisNode);
for (Standard_Integer i=0; i
}
Ok, here are the problems right now:
I wish to have a struture like:
root
| - Layer1
| | - lay1geo01
| | - lay1geo02
|
| - Layer2
| | - lay2geo01
and so on... but travelling inside the graph with my funcion returns me a very very confused structure.
Also... i can't retrieve the correct names for the labels. I know the name of the nodes inside the file, but when i query the XCAF I cannot get any of them. My best guess is that i am doing wrong the name queries.
Any help will be welcome,
thanks
Mon, 09/06/2010 - 18:46
Hi Enrico,
As I know DXF file converter is a paid component based on Open CasCade - http://www.opencascade.org/support/products/dataex/dxf/.
So, I think you may directly contact the proprietor and ask the component support.
In this case you will get the best advise.
Good luck.
Sergey