For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

Missing names and labels after reading the STEP File

Rene Roos's picture
Forums: 

I am importing STEP files and need the names and labels for following operations to guarantee associativity if the structure gets a design update.

Attached is a screen shot from CATIA V5 showing the Part and its geometries (catia_geometry_branch.png). The only label I can extract from the XCAFDoc_ShapeTool is the name and label of the Part itself, but the names and labels of the free shells are missing. Is this a limitation of the STEPCAFControl_Reader or is something wrong in my code given below? The geometry file is also attached. I am interested in these names: NS__Keeltower_port, NS__Keeltower_stb...

Function IMPORT STEP File
TopoDS_Shape load_step_file (const boost::filesystem::path& path_,
Handle_XCAFDoc_ShapeTool& xcafdoc_shape_tool_,
const std::string& length_unit_ ) {

static Handle_XCAFApp_Application dummy_app = XCAFApp_Application::GetApplication();

Handle_TDocStd_Document step_doc;

dummy_app->NewDocument ("STEP-XCAF",step_doc);;

// init and configure the reader
STEPCAFControl_Reader reader;
reader.SetColorMode(Standard_True);
reader.SetNameMode(Standard_True);
reader.SetLayerMode(Standard_True);
//Set unit system
Interface_Static::SetCVal("xstep.cascade.unit", length_unit_.c_str());

Standard_Integer stat = reader.ReadFile( (path_.string().c_str()) );

// Read in the shape(s) and the colors present in the STEP File
reader.Transfer(step_doc);
xcafdoc_shape_tool_ = XCAFDoc_DocumentTool::ShapeTool(step_doc->Main());

// Return the OCC geometry as one shape
TDF_LabelSequence step_shapes;
xcafdoc_shape_tool_->GetShapes(step_shapes);
return xcafdoc_shape_tool_->GetShape(step_shapes.Value(1));
} // end of load step file

Function EXTRACT NAMES and LABELS
pair<:string std::string=""> label_of_shape( const TopoDS_Shape& shell_,
const Handle_XCAFDoc_ShapeTool& xcafdoc_shape_tool_) {
// Extract the label of a certain shape
TDF_Label shape_label;
xcafdoc_shape_tool_->Search(shell_, shape_label);

Standard_CString cstring_name = "", cstring_label = "";
if ( !shape_label.IsNull() ) {
TCollection_AsciiString ascii_name, ascii_label;
TDF_Tool::Entry(shape_label, ascii_label);
Handle(TDataStd_Name) N;
shape_label.FindAttribute( TDataStd_Name::GetID(), N );
if (!N.IsNull ()) {
ascii_name = N->Get();
cstring_name = ascii_name.ToCString();
}
cstring_label = ascii_label.ToCString();
}

return std::make_pair(cstring_label, cstring_name);
} // end of get_label_of_shape