Commit 99d30d59 by Christophe Geuzaine

explain how we could read STEP attributes (e.g. colors)

parent b6834e17
Pipeline #556 passed with stage
in 78 minutes 48 seconds
......@@ -1142,13 +1142,14 @@ if(ENABLE_OCC)
set(OCC_LIBS_REQUIRED
# subset of DataExchange
TKSTEP TKSTEP209 TKSTEPAttr TKSTEPBase TKIGES TKXSBase
# for STEP/IGES naming through XCAF - but this requires FreeType :-(
# TKXDESTEP TKXDEIGES TKXCAF TKLCAF TKVCAF TKCAF TKCDF TKService TKV3d
# ModelingAlgorithms
TKOffset TKFeat TKFillet TKBool TKShHealing TKMesh TKHLR TKBO TKPrim
TKTopAlgo TKGeomAlgo
# ModelingData
TKBRep TKGeomBase TKG3d TKG2d
# FoundationClasses
# TKAdvTools -- not necessary? (and removed from OCC 6.8)
TKMath TKernel)
list(LENGTH OCC_LIBS_REQUIRED NUM_OCC_LIBS_REQUIRED)
if(OCC_LIBS)
......
......@@ -93,6 +93,21 @@
#error "Gmsh requires OpenCASCADE >= 6.9"
#endif
// FIXME: This will be necessary to read STEP/IGES attributes (labels and
// colors), through XCAF. However this adds a ridiculous dependency to FreeType;
// so we cannot include this for now
#undef XCAF
#if defined(XCAF)
#include <Quantity_Color.hxx>
#include <TDocStd_Document.hxx>
#include <XCAFApp_Application.hxx>
#include <XCAFDoc_ShapeTool.hxx>
#include <XCAFDoc_DocumentTool.hxx>
#include <XCAFDoc_ColorTool.hxx>
#include <STEPCAFControl_Reader.hxx>
#include <IGESCAFControl_Reader.hxx>
#endif
OCC_Internals::OCC_Internals()
{
for(int i = 0; i < 6; i++) _maxTag[i] = 0;
......@@ -2508,6 +2523,44 @@ bool OCC_Internals::importShapes(const std::string &fileName, bool highestDimOnl
else if(format == "step" ||
split[2] == ".step" || split[2] == ".stp" ||
split[2] == ".STEP" || split[2] == ".STP"){
#if defined(XCAF)
// Initiate a dummy XCAF Application to handle the STEP XCAF Document
static Handle_XCAFApp_Application dummy_app = XCAFApp_Application::GetApplication();
// Create an XCAF Document to contain the STEP file itself
Handle_TDocStd_Document step_doc;
// Check if a STEP File is already open under this handle, if so, close it
// to prevent Segmentation Faults when trying to create a new document
if(dummy_app->NbDocuments() > 0){
dummy_app->GetDocument(1, step_doc);
dummy_app->Close(step_doc);
}
dummy_app->NewDocument("STEP-XCAF", step_doc);
STEPCAFControl_Reader reader;
if(reader.ReadFile(fileName.c_str()) != IFSelect_RetDone){
Msg::Error("Could not read file '%s'", fileName.c_str());
return false;
}
reader.Transfer(step_doc);
// Read in the shape(s) and the colours present in the STEP File
Handle_XCAFDoc_ShapeTool step_shape_contents = XCAFDoc_DocumentTool::ShapeTool(step_doc->Main());
Handle_XCAFDoc_ColorTool step_colour_contents = XCAFDoc_DocumentTool::ColorTool(step_doc->Main());
TDF_LabelSequence step_shapes;
step_shape_contents->GetShapes(step_shapes);
// List out the available colours in the STEP File as Colour Names
TDF_LabelSequence all_colours;
step_colour_contents->GetColors(all_colours);
Msg::Info("Number of colours in STEP File: ", all_colours.Length());
for(int i = 1; i <= all_colours.Length(); i++){
Quantity_Color col;
std::stringstream col_rgb;
step_colour_contents->GetColor(all_colours.Value(i),col);
col_rgb << " : (" << col.Red() << "," << col.Green() << "," << col.Blue() << ")";
Msg::Info("Colour [", i, "] = ", col.StringName(col.Name()), col_rgb.str().c_str());
}
// For the STEP File Reader in OCC, the 1st Shape contains the entire
// compound geometry as one shape
result = step_shape_contents->GetShape(step_shapes.Value(1));
#else
STEPControl_Reader reader;
if(reader.ReadFile(fileName.c_str()) != IFSelect_RetDone){
Msg::Error("Could not read file '%s'", fileName.c_str());
......@@ -2516,6 +2569,7 @@ bool OCC_Internals::importShapes(const std::string &fileName, bool highestDimOnl
reader.NbRootsForTransfer();
reader.TransferRoots();
result = reader.OneShape();
#endif
}
else if(format == "iges" ||
split[2] == ".iges" || split[2] == ".igs" ||
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment