]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #2971: Naming issue in a group when loading a dump file
authorazv <azv@opencascade.com>
Mon, 21 Oct 2019 08:02:46 +0000 (11:02 +0300)
committervsv <vsv@opencascade.com>
Wed, 6 Nov 2019 08:27:38 +0000 (11:27 +0300)
* Make "ParentFeature" attribute the last for all Sketch entities for backward compatibility.
* Add new HDF test to check the dumping to Python works.

19 files changed:
src/Model/Model_AttributeDocRef.cpp
src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp
src/SketchPlugin/SketchPlugin_Line.cpp
src/SketchPlugin/SketchPlugin_Line.h
src/SketchPlugin/SketchPlugin_Point.cpp
src/SketchPlugin/SketchPlugin_Point.h
src/SketchPlugin/SketchPlugin_SketchEntity.cpp
src/SketchPlugin/SketchPlugin_SketchEntity.h
src/SketchPlugin/SketchPlugin_Split.cpp
src/SketchPlugin/SketchPlugin_Trim.cpp
src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp
test.hdfs/CMakeLists.txt
test.hdfs/Test2971.py [new file with mode: 0644]
test.hdfs/delta_p.py
test.hdfs/roselend.py
test.hdfs/te_fluide.py
test.hdfs/te_solide.py
test.hdfs/test_hdf.py
test.hdfs/usine.py

index d57938e8034ad675b6bcda77685fc7476f0f960e..2b8c4091a7e6862962283c1b17d93c0b1ac17f22 100644 (file)
@@ -46,6 +46,7 @@ Model_AttributeDocRef::Model_AttributeDocRef(TDF_Label& theLabel)
   if (!myIsInitialized) {
     int aNewID = Model_Application::getApplication()->generateDocumentId();
     myID = TDataStd_Integer::Set(theLabel, aNewID);
+    myIsInitialized = true;
   }
 }
 
index adba1299442d7961196cb8c66ad60685982a18f3..fc73000c04b2fb1753ed3a6e2dc68ef128244d02 100644 (file)
@@ -20,6 +20,7 @@
 #include <ModelHighAPI_FeatureStore.h>
 
 #include <ModelAPI_Tools.h>
+#include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_ResultPart.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_AttributeBoolean.h>
@@ -198,6 +199,8 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) {
     // do not dump a type of ConstraintAngle, because it can be changed due dumping
     if (anAttr->id() == "AngleType") {
       return "";
+    } else if (anAttr->id() == "LocationType") {
+      return "__notinitialized__";
     }
     if (anAttr->text().empty())
       aResult<<anAttr->value();
@@ -273,7 +276,7 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) {
     }
   } else if (aType == ModelAPI_AttributeRefList::typeId()) {
     AttributeRefListPtr anAttr =
-      std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttr);
+        std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttr);
     // for sketch sub-features the empty values may be skipped and order is not important
     bool isSketchFeatures = anAttr->id() == "Features" &&
       std::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->owner())->getKind() == "Sketch";
@@ -316,6 +319,12 @@ std::string ModelHighAPI_FeatureStore::dumpAttr(const AttributePtr& theAttr) {
       }
     }
   } else if (aType == ModelAPI_AttributeIntArray::typeId()) {
+    if (theAttr->id() == "Color") {
+      ResultConstructionPtr aResConstr =
+          std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theAttr->owner());
+      if (aResConstr.get())
+        return "__notinitialized__";
+    }
     AttributeIntArrayPtr anAttr =
       std::dynamic_pointer_cast<ModelAPI_AttributeIntArray>(theAttr);
     for(int a = 0; a < anAttr->size(); a++)
@@ -391,9 +400,15 @@ std::string ModelHighAPI_FeatureStore::dumpShape(std::shared_ptr<GeomAPI_Shape>&
     aResult<<": "<<aCount<<std::endl;
   }
   // output the main characteristics
-  if (GeomAlgoAPI_ShapeTools::volume(theShape) > 1.e-5) {
-    aResult<<"Volume: "<<
-      std::fixed<<setprecision(3)<<GeomAlgoAPI_ShapeTools::volume(theShape)<<std::endl;
+  double aVolume = GeomAlgoAPI_ShapeTools::volume(theShape);
+  if (aVolume > 1.e-5) {
+    aResult<<"Volume: ";
+    // volumes of too huge shapes write in the scientific format
+    if (aVolume >= 1.e5)
+      aResult<<std::scientific<<setprecision(7);
+    else
+      aResult<<std::fixed<<setprecision(3);
+    aResult<<aVolume<<std::endl;
   }
   std::shared_ptr<GeomAPI_Pnt> aCenter = GeomAlgoAPI_ShapeTools::centreOfMass(theShape);
   aResult<<"Center of mass: ";
index e5284719311c0f2beed9b62948160717992e536f..f01a332f296b0b90d751165547938b937376df3f 100644 (file)
@@ -47,9 +47,6 @@ void SketchPlugin_Line::initAttributes()
   /// new attributes should be added to end of the feature in order to provide
   /// correct attribute values in previous saved studies
   data()->addAttribute(LENGTH_ID(), ModelAPI_AttributeDouble::typeId());
-
-  data()->addAttribute(PARENT_ID(), ModelAPI_AttributeReference::typeId());
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), PARENT_ID());
 }
 
 void SketchPlugin_Line::initDerivedClassAttributes()
index 73ad4310799662ccbf1bee3177ee8a018e7a3fb9..7a23944ae6260d0ab8714a83579e07ea033e931a 100644 (file)
@@ -63,13 +63,6 @@ class SketchPlugin_Line : public SketchPlugin_SketchEntity,
     return MY_LENGTH;
   }
 
-  /// Reference to the parent feature
-  inline static const std::string& PARENT_ID()
-  {
-    static const std::string& MY_PARENT_ID("ParentFeature");
-    return MY_PARENT_ID;
-  }
-
   /// Returns the kind of a feature
   SKETCHPLUGIN_EXPORT virtual const std::string& getKind();
 
index 9a6358053132ae4e99bf59bebef0c80de454c46b..c53006489726c728a5ac5c6877c996b4b90cc6dd 100644 (file)
@@ -22,7 +22,6 @@
 
 #include <ModelAPI_Data.h>
 #include <ModelAPI_ResultConstruction.h>
-#include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_Validator.h>
 #include <ModelAPI_Session.h>
@@ -42,9 +41,6 @@ void SketchPlugin_Point::initDerivedClassAttributes()
   data()->addAttribute(SketchPlugin_Point::COORD_ID(), GeomDataAPI_Point2D::typeId());
   data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId());
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
-
-  data()->addAttribute(PARENT_ID(), ModelAPI_AttributeReference::typeId());
-  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), PARENT_ID());
 }
 
 void SketchPlugin_Point::execute()
index 5111ce0a8922e0e8f47d5a373b89f054efbbfd48..1cdcae05f39ddb505170bedc42e94cb4fe169a23 100644 (file)
@@ -44,12 +44,6 @@ class SketchPlugin_Point : public SketchPlugin_SketchEntity
     static const std::string MY_COORD_ID("PointCoordinates");
     return MY_COORD_ID;
   }
-  /// Reference to the parent feature
-  inline static const std::string& PARENT_ID()
-  {
-    static const std::string& MY_PARENT_ID("ParentFeature");
-    return MY_PARENT_ID;
-  }
   /// Returns the kind of a feature
   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
   {
index 86dcae365f978a8bb2cdd490cb21da6a4eceec9a..89d70db0d61193b38f0068811110558eadfe143a 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "SketchPlugin_SketchEntity.h"
 
+#include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
 
@@ -38,4 +39,8 @@ void SketchPlugin_SketchEntity::initAttributes()
   anAttr->setIsArgument(false);
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(),
     SketchPlugin_SketchEntity::COPY_ID());
+
+  anAttr = data()->addAttribute(PARENT_ID(), ModelAPI_AttributeReference::typeId());
+  anAttr->setIsArgument(false);
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), PARENT_ID());
 }
index cae07149d584e95a8f10981f29115882bea2069e..b181565a7bc1f633b6b300c1d787c687ed749f68 100644 (file)
@@ -65,6 +65,13 @@ class SketchPlugin_SketchEntity : public SketchPlugin_Feature //, public GeomAPI
     return MY_COPY_ID;
   }
 
+  /// Reference to the parent feature if exist
+  inline static const std::string& PARENT_ID()
+  {
+    static const std::string& MY_PARENT_ID("ParentFeature");
+    return MY_PARENT_ID;
+  }
+
   /// Width of the auxiliary line
   inline static const int SKETCH_LINE_WIDTH_AUXILIARY()
   {
index a8f054eb8eb5b5948606ac09f3fde632c5f2ab8b..b0a5658ffef5145a4ee4c13906f34caa50aed772 100644 (file)
@@ -1160,8 +1160,7 @@ FeaturePtr SketchPlugin_Split::splitClosed(FeaturePtr& theSplitFeature,
     const std::set<AttributePtr>& aRefs = aBaseFeature->data()->refsToMe();
     std::list<AttributePtr> aRefsToParent;
     for (std::set<AttributePtr>::const_iterator aRef = aRefs.begin(); aRef != aRefs.end(); ++aRef) {
-      if ((*aRef)->id() == SketchPlugin_Line::PARENT_ID() ||
-          (*aRef)->id() == SketchPlugin_Point::PARENT_ID())
+      if ((*aRef)->id() == SketchPlugin_SketchEntity::PARENT_ID())
         aRefsToParent.push_back(*aRef);
     }
     for (std::list<AttributePtr>::iterator aRef = aRefsToParent.begin();
index b7d0535dbda926736024358be4e355e0f6a20c59..2957e031573500609257d190e2295300248c2712 100644 (file)
@@ -1061,8 +1061,7 @@ FeaturePtr SketchPlugin_Trim::trimClosed(const std::shared_ptr<GeomAPI_Pnt2d>& t
     const std::set<AttributePtr>& aRefs = aBaseFeature->data()->refsToMe();
     std::list<AttributePtr> aRefsToParent;
     for (std::set<AttributePtr>::const_iterator aRef = aRefs.begin(); aRef != aRefs.end(); ++aRef) {
-      if ((*aRef)->id() == SketchPlugin_Line::PARENT_ID() ||
-          (*aRef)->id() == SketchPlugin_Point::PARENT_ID())
+      if ((*aRef)->id() == SketchPlugin_SketchEntity::PARENT_ID())
         aRefsToParent.push_back(*aRef);
     }
     for (std::list<AttributePtr>::iterator aRef = aRefsToParent.begin();
index 2c4d8eed34c4ba26b201246f51442f8a96a4b7ce..4bac7dd1fda160092024b66cad9bc7fc5ed99d92 100644 (file)
@@ -76,15 +76,9 @@ static void getPointOwnerAndParent(const AttributeRefAttrPtr theRefAttr,
   if (thePoint) {
     theOwner = ModelAPI_Feature::feature(thePoint->owner());
     if (theOwner) {
-      std::string aParentRefID;
-      if (theOwner->getKind() == SketchPlugin_Line::ID())
-        aParentRefID = SketchPlugin_Line::PARENT_ID();
-      else if (theOwner->getKind() == SketchPlugin_Point::ID())
-        aParentRefID = SketchPlugin_Point::PARENT_ID();
-      if (!aParentRefID.empty()) {
-        AttributeReferencePtr aParentRef = theOwner->reference(aParentRefID);
-        theParent = aParentRef ? ModelAPI_Feature::feature(aParentRef->value()) : FeaturePtr();
-      }
+      AttributeReferencePtr aParentRef =
+          theOwner->reference(SketchPlugin_SketchEntity::PARENT_ID());
+      theParent = aParentRef ? ModelAPI_Feature::feature(aParentRef->value()) : FeaturePtr();
     }
   }
 }
index 58c6c48bdd8e02ef1972320cb588b8cd07628b64..a8e5ca417ead1a93deff2523f8c6711d831e2f74 100644 (file)
@@ -41,7 +41,8 @@ if (EXISTS ${RESTRICTED_ROOT_DIR})
     GET_FILENAME_COMPONENT(aTestName ${eachFilePath} NAME_WE)
     # Check corresponding ".py" file with reference data exists
     IF(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${aTestName}.py")
-      MESSGAGE(WARNING "File ${aTestName}.py containing reference data does not exist")
+      MESSAGE(WARNING "File ${aTestName}.py containing reference data does not exist")
+      continue()
     ENDIF()
 
     # Add "SubprojectName_" prefix
diff --git a/test.hdfs/Test2971.py b/test.hdfs/Test2971.py
new file mode 100644 (file)
index 0000000..a1d81d5
--- /dev/null
@@ -0,0 +1,33 @@
+# Copyright (C) 2019  CEA/DEN, EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+if __name__ == "__main__":
+  parts = locals()
+  for key in list(parts.keys()):
+    if key.startswith("Part_"):
+      part = parts[key]
+      model.testNbResults(part, 1)
+      model.testNbSubResults(part, [0])
+      model.testNbSubShapes(part, GeomAPI_Shape.SOLID, [12])
+      model.testNbSubShapes(part, GeomAPI_Shape.FACE, [103])
+      model.testNbSubShapes(part, GeomAPI_Shape.EDGE, [475])
+      model.testNbSubShapes(part, GeomAPI_Shape.VERTEX, [950])
+      model.testResultsVolumes(part, [6487764903.02328777])
+
+  assert(model.checkPythonDump(model.ModelHighAPI.CHECK_NAMING))
index 24452f83617039932c35e7a57dd482a6866a1dc5..4487731e73b4a43148dfcbcb987b2bf99a1334c4 100644 (file)
@@ -18,6 +18,7 @@
 #
 
 if __name__ == "__main__":
+  aPartFeature = locals()["Part_1"]
   model.testNbResults(aPartFeature, 1)
   model.testNbSubResults(aPartFeature, [0])
   model.testNbSubShapes(aPartFeature, GeomAPI_Shape.SOLID, [319])
index e0533c3541b007ec94779b3a7df20a73dbf57256..875d48f4313f8b5fbda096ee7689d698b145a765 100644 (file)
@@ -18,6 +18,7 @@
 #
 
 if __name__ == "__main__":
+  aPartFeature = locals()["Part_1"]
   model.testNbResults(aPartFeature, 1)
   model.testNbSubResults(aPartFeature, [0])
   model.testNbSubShapes(aPartFeature, GeomAPI_Shape.SOLID, [32])
index 25ea15af0f932e720aef846d473c1adf26dee735..75870c392cf9ee788695ae7d635ade619508dfc8 100644 (file)
@@ -18,6 +18,7 @@
 #
 
 if __name__ == "__main__":
+  aPartFeature = locals()["Part_1"]
   model.testNbResults(aPartFeature, 1)
   model.testNbSubResults(aPartFeature, [0])
   model.testNbSubShapes(aPartFeature, GeomAPI_Shape.SOLID, [30])
index 5d44704289d8a23508ba72a644ed71fd13516a6f..7b588d6fbd14a694269935c3b5e534b9468f42e5 100644 (file)
@@ -18,6 +18,7 @@
 #
 
 if __name__ == "__main__":
+  aPartFeature = locals()["Part_1"]
   model.testNbResults(aPartFeature, 1)
   model.testNbSubResults(aPartFeature, [0])
   model.testNbSubShapes(aPartFeature, GeomAPI_Shape.SOLID, [48])
index 9dbc1578c1e771fc390ff85edb1096aa019ff787..1ae49db9cd25b02d046d1ac666a1ce8c25ad7157 100644 (file)
@@ -55,7 +55,7 @@ class TestHDF(unittest.TestCase):
 
   def test_hdf_file(self):
     self.assertTrue(self.partSet.size("Parts") > 0)
-    aPartsList = []
+    aPartsList = dict()
     for aPartIndex in range(self.partSet.size("Parts")):
       self.session.startOperation()
       aPart = ModelAPI.modelAPI_ResultPart(ModelAPI.objectToResult(self.partSet.object("Parts", aPartIndex)))
@@ -63,8 +63,10 @@ class TestHDF(unittest.TestCase):
       self.session.finishOperation()
 
       aPartFeature = PartSetAPI.PartSetAPI_Part(self.partSet.currentFeature(True))
-      # check reference data
-      exec(open(self.reffile, "rb").read())
+      aPartsList["Part_{}".format(aPartIndex+1)] = aPartFeature
+
+    # check reference data
+    exec(open(self.reffile, "rb").read(), globals(), aPartsList)
 
 
 if __name__ == "__main__":
index 278c08aab107bb102d2c82a39a9798dbe484469a..ddd087684a43da9dd9399bfbc47d749b4c0c4c6a 100644 (file)
@@ -18,6 +18,7 @@
 #
 
 if __name__ == "__main__":
+  aPartFeature = locals()["Part_1"]
   model.testNbResults(aPartFeature, 1)
   model.testNbSubResults(aPartFeature, [0])
   model.testNbSubShapes(aPartFeature, GeomAPI_Shape.SOLID, [186])