From: mbs Date: Wed, 17 May 2023 13:48:22 +0000 (+0100) Subject: start traversing the document at the 'Shapes' label; X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f733a38c4770c1088c39eb9397c8e35424a4e4b9;p=modules%2Fshaper.git start traversing the document at the 'Shapes' label; avoid accidently overwriting already added shapes in the ShapeColor map of the result body --- diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp index b6b233236..0882b6348 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp @@ -111,8 +111,8 @@ std::shared_ptr readAttributes(STEPCAFControl_Reader &theReader, 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 ageom = setGeom(shapeTool,mainLabel,theError); @@ -270,8 +270,8 @@ void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &theShapeTool, Quantity_Color aCol; if (theColorTool->GetColor(theLabel, XCAFDoc_ColorGen, aCol)) { double r = aCol.Red(), g = aCol.Green(), b = aCol.Blue(); - std::vector ColRGB = {int(r*255),int(g*255),int(b*255)}; - theResultBody->addShapeColor(aShapeName, ColRGB); + std::vector 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 aColRGB = {int(r*255),int(g*255),int(b*255)}; @@ -289,16 +289,16 @@ void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &theShapeTool, 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 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 aFaceGeom(new GeomAPI_Shape); + aFaceGeom->setImpl(new TopoDS_Shape(aShapeface)); + theResultBody->addShapeColor(theResultBody->addShapeName(aFaceGeom , aNameFace), aColRGB); } aXp2.Next(); } @@ -306,13 +306,15 @@ void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &theShapeTool, } else { if (!theShapeTool->IsReference(theLabel) ){ TopoDS_Shape aShape = theShapeTool->GetShape(theLabel); - - std::shared_ptr aShapeGeom(new GeomAPI_Shape); - if (!theLoc.IsIdentity()){ - aShape.Move(theLoc); + if (!aShape.IsNull()) + { + std::shared_ptr 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()) {