Salome HOME
updated copyright message
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_STEPImportXCAF.cpp
index b77defd1467483e10eed5967bcf3c0cc5b61bf35..6fa5b5b5b106a173f59998e5ba82cf454caef92d 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -40,6 +40,7 @@
 #include <TopoDS.hxx>
 #include <Transfer_TransientProcess.hxx>
 #include <TransferBRep.hxx>
+#include <TopTools_IndexedMapOfShape.hxx>
 
 #include <XCAFApp_Application.hxx>
 #include <XCAFDoc_DocumentTool.hxx>
 #include <XCAFDoc_ShapeTool.hxx>
 #include <XSControl_TransferReader.hxx>
 #include <XSControl_WorkSession.hxx>
+#include <XCAFDoc_ColorTool.hxx>
+#include <XCAFDoc_MaterialTool.hxx>
 
 #include <Locale_Convert.h>
 
+// read geometry
+std::shared_ptr<GeomAPI_Shape> setGeom(const Handle(XCAFDoc_ShapeTool) &shapeTool,
+  const TDF_Label &theLabel,
+  std::string& theError);
+
+/// read attributs for  label
+void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &theShapeTool,
+  const Handle(XCAFDoc_ColorTool) &theColorTool,
+  const Handle(XCAFDoc_MaterialTool) &TheMaterialTool,
+  const TDF_Label &theLabel,
+  const TopLoc_Location &theLoc,
+  std::shared_ptr<ModelAPI_ResultBody> theResultBody,
+  std::map< std::wstring, std::list<std::wstring>> &theMaterialShape,
+  bool theIsRef);
+
+// store Materiel for theShapeLabel in the map theMaterialShape
+void storeMaterial(std::shared_ptr<ModelAPI_ResultBody> theResultBody,
+  const Handle(Standard_Transient) &theEnti,
+  const TopTools_IndexedMapOfShape &theIndices,
+  const Handle(Transfer_TransientProcess) &theTP,
+  const TDF_Label &theShapeLabel,
+  std::map< std::wstring, std::list<std::wstring>> &theMaterialShape);
+
 //=============================================================================
 TopoDS_Shape getShape(const Handle(Standard_Transient) &theEnti,
                       const Handle(Transfer_TransientProcess) &theTP)
@@ -89,13 +115,12 @@ std::shared_ptr<GeomAPI_Shape> readAttributes(STEPCAFControl_Reader &theReader,
   setShapeAttributes(shapeTool, colorTool, materialTool, mainLabel,
                      TopLoc_Location(),theResultBody,theMaterialShape,false);
 
-  std::shared_ptr<GeomAPI_Shape> ageom =  setgeom(shapeTool,mainLabel,theError);
+  std::shared_ptr<GeomAPI_Shape> ageom =  setGeom(shapeTool,mainLabel,theError);
 
   STEPControl_Reader aReader = theReader.ChangeReader();
 
   // BEGIN: reading materials of sub-shapes from file
-  if ( theIsMaterials )
-  {
+  if (theIsMaterials) {
     TopTools_IndexedMapOfShape anIndices;
     TopExp::MapShapes(ageom->impl<TopoDS_Shape>(), anIndices);
 
@@ -120,8 +145,8 @@ std::shared_ptr<GeomAPI_Shape> readAttributes(STEPCAFControl_Reader &theReader,
 }
 
 //=============================================================================
-std::shared_ptr<GeomAPI_Shape> setgeom(const Handle(XCAFDoc_ShapeTool) &theShapeTool,
-                                       const TDF_Label &theLabel,
+std::shared_ptr<GeomAPI_Shape> setGeom(const Handle(XCAFDoc_ShapeTool) &theShapeTool,
+                                       const TDF_Label& /*theLabel*/,
                                        std::string& theError)
 {
   BRep_Builder aB;
@@ -141,7 +166,7 @@ std::shared_ptr<GeomAPI_Shape> setgeom(const Handle(XCAFDoc_ShapeTool) &theShape
     aGeomShape->setImpl(new TopoDS_Shape(shape));
     return aGeomShape;
   } else {
-    for (Standard_Integer i=1; i<aFrshapes.Length(); i++) {
+    for (Standard_Integer i=1; i<=aFrshapes.Length(); i++) {
       TopoDS_Shape aS = theShapeTool->GetShape(aFrshapes.Value(i));
       TDF_Label aLabel = theShapeTool->FindShape(aS, Standard_False);
       if ( (!aLabel.IsNull()) && (theShapeTool->IsShape(aLabel)) ) {
@@ -149,7 +174,7 @@ std::shared_ptr<GeomAPI_Shape> setgeom(const Handle(XCAFDoc_ShapeTool) &theShape
           if (aS.IsNull()) {
             continue;
           } else {
-            if (!theShapeTool->IsReference(aLabel) ){
+            if (aS.ShapeType() != TopAbs_SOLID && !theShapeTool->IsReference(aLabel)){
               for(TDF_ChildIterator anIt(aLabel); anIt.More(); anIt.Next()) {
                 aB.Add(aCompound, theShapeTool->GetShape(anIt.Value()) );
               }
@@ -163,10 +188,8 @@ std::shared_ptr<GeomAPI_Shape> setgeom(const Handle(XCAFDoc_ShapeTool) &theShape
 
     TopoDS_Shape aShape = aCompound;
     // Check if any BRep entity has been read, there must be at least a vertex
-    if ( !TopExp_Explorer( aShape, TopAbs_VERTEX ).More() )
-    {
+    if (!TopExp_Explorer( aShape, TopAbs_VERTEX ).More()) {
       theError = "No geometrical data in the imported file.";
-      std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
       aGeomShape->setImpl(new TopoDS_Shape());
       return aGeomShape;
     }
@@ -215,7 +238,7 @@ void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &theShapeTool,
     TopoDS_Shape aShape = theShapeTool->GetShape(theLabel);
 
     std::shared_ptr<GeomAPI_Shape> aShapeGeom(new GeomAPI_Shape);
-    if (!theLoc.IsIdentity()){
+    if (!theLoc.IsIdentity()) {
         aShape.Move(theLoc);
     }
     aShapeGeom->setImpl(new TopoDS_Shape(aShape));
@@ -254,17 +277,17 @@ void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &theShapeTool,
       std::vector<int> aColRGB = {int(r*255),int(g*255),int(b*255)};
       theResultBody->addShapeColor(aShapeName, aColRGB);
     } else if (theColorTool->GetColor(theLabel, XCAFDoc_ColorCurv, aCol)) {
-     double aR = aCol.Red(), aG = aCol.Green(), aB = aCol.Blue();
-     std::vector<int> aColRGB = {int(aR*255),int(aG*255),int(aB*255)};
+      double aR = aCol.Red(), aG = aCol.Green(), aB = aCol.Blue();
+      std::vector<int> aColRGB = {int(aR*255),int(aG*255),int(aB*255)};
       theResultBody->addShapeColor(aShapeName, aColRGB);
     }
     // check explicit coloring of boundary entities
     if (aDim == 3) {
       TopExp_Explorer aXp2(aShape, TopAbs_FACE);
-      while(aXp2.More()) {
+      while (aXp2.More()) {
         if (theColorTool->GetColor(aXp2.Current(), XCAFDoc_ColorGen, aCol) ||
-           theColorTool->GetColor(aXp2.Current(), XCAFDoc_ColorSurf, aCol) ||
-           theColorTool->GetColor(aXp2.Current(), XCAFDoc_ColorCurv, aCol)) {
+          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)};
@@ -280,23 +303,6 @@ void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &theShapeTool,
         aXp2.Next();
       }
     }
-    if (aDim == 2) {
-      TopExp_Explorer aXp1(aShape, TopAbs_EDGE);
-      while(aXp1.More()) {
-        if (theColorTool->GetColor(aXp1.Current(), XCAFDoc_ColorGen, aCol) ||
-           theColorTool->GetColor(aXp1.Current(), XCAFDoc_ColorSurf, aCol) ||
-           theColorTool->GetColor(aXp1.Current(), XCAFDoc_ColorCurv, aCol)) {
-           double aR = aCol.Red(), aG = aCol.Green(), aB = aCol.Blue();
-           std::vector<int> aColRGB = {int(aR*255),int(aG*255),int(aB*255)};
-           std::wstringstream aNameEdge;
-           aNameEdge << L"Edge_"<< aShapeName;
-           aShapeGeom->setImpl(new TopoDS_Shape(aXp1.Current() ));
-           theResultBody->addShapeColor(
-           theResultBody->addShapeName(aShapeGeom , aNameEdge.str()), aColRGB);
-        }
-        aXp1.Next();
-      }
-    }
   } else {
     if (!theShapeTool->IsReference(theLabel) ){
       TopoDS_Shape aShape = theShapeTool->GetShape(theLabel);
@@ -321,7 +327,7 @@ void storeMaterial( std::shared_ptr<ModelAPI_ResultBody>    theResultBody,
                     const Handle(Standard_Transient)        &theEnti,
                     const TopTools_IndexedMapOfShape        &theIndices,
                     const Handle(Transfer_TransientProcess) &theTP,
-                    const TDF_Label                         &theShapeLabel,
+                    const TDF_Label                         &/*theShapeLabel*/,
                     std::map< std::wstring, std::list<std::wstring>> &theMaterialShape )
 {
   // Treat Product Definition Shape only.
@@ -406,4 +412,3 @@ void storeMaterial( std::shared_ptr<ModelAPI_ResultBody>    theResultBody,
     }
   }
 }
-