]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
start traversing the document at the 'Shapes' label;
authormbs <martin.bernhard@opencascade.com>
Wed, 17 May 2023 13:48:22 +0000 (14:48 +0100)
committermbs <martin.bernhard@opencascade.com>
Wed, 17 May 2023 13:48:22 +0000 (14:48 +0100)
avoid accidently overwriting already added shapes in the ShapeColor map of the result body

src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp

index b6b2332362e1d862e162a5a79e0c3525d99abd4d..0882b6348e93e3818c650412b098129e12eba49a 100644 (file)
@@ -111,8 +111,8 @@ std::shared_ptr<GeomAPI_Shape> 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<GeomAPI_Shape> 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<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)};
@@ -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<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();
       }
@@ -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<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()) {