Salome HOME
updated copyright message
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI_FeatureStore.cpp
index 58e32136f2cd9decca891e655dcaf325fbd8b13a..97523e429ee19d62ca0159376a03c8773cc9d0b9 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
 #include <GeomDataAPI_Point.h>
 #include <GeomDataAPI_Point2D.h>
 #include <GeomAlgoAPI_ShapeTools.h>
+#include <GeomAPI_ShapeExplorer.h>
 #include <GeomAPI_Pnt.h>
 
 #include <Locale_Convert.h>
 
-#include <TopoDS_Shape.hxx>
-#include <TopExp_Explorer.hxx>
-
 #include <ios>
 #include <cmath>
+#include <sstream>
+#include <iomanip>
 
 #define PRECISION 6
 #define TOLERANCE (1.e-7)
@@ -241,7 +241,12 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) {
   } else if (aType == ModelAPI_AttributeString::typeId()) {
     AttributeStringPtr anAttr = std::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttr);
     // do not dump solver DOF for sketch as it may be changed unexpectedly
-    if(anAttr->id() == "SolverDOF") {
+    if (anAttr->id() == "SolverDOF") {
+      return "";
+    }
+    // do not dump file path for Image as it is changed after DumpPython
+    if (aFeatOwner->getKind() == "ImportImage" &&
+        anAttr->id() == "file_path") {
       return "";
     }
     aResult<<anAttr->value();
@@ -398,19 +403,17 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) {
 }
 
 std::string ModelHighAPI_FeatureStore::dumpShape(std::shared_ptr<GeomAPI_Shape>& theShape) {
-  TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
-  if (aShape.IsNull()) {
+  if (theShape->isNull()) {
     return "null";
   }
   std::ostringstream aResult;
   // output the number of shapes of different types
-  TopAbs_ShapeEnum aType = TopAbs_COMPOUND;
-  for(; aType <= TopAbs_VERTEX; aType = TopAbs_ShapeEnum((int)aType + 1)) {
-    TopExp_Explorer anExp(aShape, aType);
+  GeomAPI_Shape::ShapeType aType = GeomAPI_Shape::COMPOUND;
+  for (; aType <= GeomAPI_Shape::VERTEX; aType = GeomAPI_Shape::ShapeType((int)aType + 1)) {
+    GeomAPI_ShapeExplorer anExp(theShape, aType);
     int aCount = 0;
-    for(; anExp.More(); anExp.Next()) aCount++;
-    TopAbs::Print(aType, aResult);
-    aResult<<": "<<aCount<<std::endl;
+    for (; anExp.more(); anExp.next()) aCount++;
+    aResult << anExp.current()->shapeTypeStr().c_str() <<  ": " << aCount << std::endl;
   }
   // output the main characteristics
   double aVolume = GeomAlgoAPI_ShapeTools::volume(theShape);
@@ -423,6 +426,16 @@ std::string ModelHighAPI_FeatureStore::dumpShape(std::shared_ptr<GeomAPI_Shape>&
       aResult<<std::fixed<<std::setprecision(3);
     aResult<<aVolume<<std::endl;
   }
+  double anArea = GeomAlgoAPI_ShapeTools::area(theShape);
+  if (anArea > 1.e-5) {
+    aResult << "Area: ";
+    // volumes of too huge shapes write in the scientific format
+    if (anArea >= 1.e5)
+      aResult << std::scientific << std::setprecision(7);
+    else
+      aResult << std::fixed << std::setprecision(3);
+    aResult << anArea << std::endl;
+  }
   std::shared_ptr<GeomAPI_Pnt> aCenter = GeomAlgoAPI_ShapeTools::centreOfMass(theShape);
   aResult<<"Center of mass: ";
   double aCenterVals[3] = {aCenter->x(), aCenter->y(), aCenter->z()};