Handle_XCAFDoc_ShapeTool shapeTool = XCAFDoc_DocumentTool::ShapeTool(mainLabel);
Handle_XCAFDoc_ColorTool colorTool = XCAFDoc_DocumentTool::ColorTool(mainLabel);
Handle(XCAFDoc_MaterialTool) materialTool = XCAFDoc_DocumentTool::MaterialTool(mainLabel);
- // traverse the labels recursively to set attributes on shapes
- setShapeAttributes(shapeTool, colorTool, materialTool, mainLabel,
+ // traverse the labels recursively to set attributes on shapes (starting with the "Shapes" label)
+ setShapeAttributes(shapeTool, colorTool, materialTool, XCAFDoc_DocumentTool::ShapesLabel(mainLabel),
TopLoc_Location(),theResultBody,theMaterialShape,false);
std::shared_ptr<GeomAPI_Shape> ageom = setGeom(shapeTool,mainLabel,theError);
Quantity_Color aCol;
if (theColorTool->GetColor(theLabel, XCAFDoc_ColorGen, aCol)) {
double r = aCol.Red(), g = aCol.Green(), b = aCol.Blue();
- std::vector<int> ColRGB = {int(r*255),int(g*255),int(b*255)};
- theResultBody->addShapeColor(aShapeName, ColRGB);
+ std::vector<int> aColRGB = {int(r*255),int(g*255),int(b*255)};
+ theResultBody->addShapeColor(aShapeName, aColRGB);
} else if (theColorTool->GetColor(theLabel, XCAFDoc_ColorSurf, aCol)) {
double r = aCol.Red(), g = aCol.Green(), b = aCol.Blue();
std::vector<int> aColRGB = {int(r*255),int(g*255),int(b*255)};
theColorTool->GetColor(aXp2.Current(), XCAFDoc_ColorSurf, aCol) ||
theColorTool->GetColor(aXp2.Current(), XCAFDoc_ColorCurv, aCol)) {
double aR = aCol.Red(), aG = aCol.Green(), aB = aCol.Blue();
- TopoDS_Face aFace = TopoDS::Face(aXp2.Current());
std::vector<int> aColRGB = {int(aR*255),int(aG*255),int(aB*255)};
- std::wstringstream aNameFace;
+ std::wstring aNameFace;
TopoDS_Shape aShapeface = aXp2.Current();
if (!theLoc.IsIdentity()){
aShapeface.Move(theLoc);
}
- aShapeGeom->setImpl(new TopoDS_Shape(aShapeface));
- theResultBody->addShapeColor(
- theResultBody->addShapeName(aShapeGeom , aNameFace.str()), aColRGB);
+ // Create a new shape pointer to avoid changes on the shape map
+ std::shared_ptr<GeomAPI_Shape> aFaceGeom(new GeomAPI_Shape);
+ aFaceGeom->setImpl(new TopoDS_Shape(aShapeface));
+ theResultBody->addShapeColor(theResultBody->addShapeName(aFaceGeom , aNameFace), aColRGB);
}
aXp2.Next();
}
} else {
if (!theShapeTool->IsReference(theLabel) ){
TopoDS_Shape aShape = theShapeTool->GetShape(theLabel);
-
- std::shared_ptr<GeomAPI_Shape> aShapeGeom(new GeomAPI_Shape);
- if (!theLoc.IsIdentity()){
- aShape.Move(theLoc);
+ if (!aShape.IsNull())
+ {
+ std::shared_ptr<GeomAPI_Shape> aShapeGeom(new GeomAPI_Shape);
+ if (!theLoc.IsIdentity()){
+ aShape.Move(theLoc);
+ }
+ aShapeGeom->setImpl(new TopoDS_Shape(aShape));
+ aShapeName = theResultBody->addShapeName(aShapeGeom, aShapeName);
}
- aShapeGeom->setImpl(new TopoDS_Shape(aShape));
- aShapeName = theResultBody->addShapeName(aShapeGeom, aShapeName);
}
for(TDF_ChildIterator anIt(theLabel); anIt.More(); anIt.Next()) {