From: azv Date: Mon, 21 Oct 2019 08:02:46 +0000 (+0300) Subject: Issue #2971: Naming issue in a group when loading a dump file X-Git-Tag: V9_5_0a1~167^2~26 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4ddacde2a835dcba71074928bd8412e8ae9de57f;p=modules%2Fshaper.git Issue #2971: Naming issue in a group when loading a dump file * Make "ParentFeature" attribute the last for all Sketch entities for backward compatibility. * Add new HDF test to check the dumping to Python works. --- diff --git a/src/Model/Model_AttributeDocRef.cpp b/src/Model/Model_AttributeDocRef.cpp index d57938e80..2b8c4091a 100644 --- a/src/Model/Model_AttributeDocRef.cpp +++ b/src/Model/Model_AttributeDocRef.cpp @@ -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; } } diff --git a/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp b/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp index adba12994..fc73000c0 100644 --- a/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp +++ b/src/ModelHighAPI/ModelHighAPI_FeatureStore.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -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<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(theAttr); + std::dynamic_pointer_cast(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(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(theAttr->owner()); + if (aResConstr.get()) + return "__notinitialized__"; + } AttributeIntArrayPtr anAttr = std::dynamic_pointer_cast(theAttr); for(int a = 0; a < anAttr->size(); a++) @@ -391,9 +400,15 @@ std::string ModelHighAPI_FeatureStore::dumpShape(std::shared_ptr& aResult<<": "< 1.e-5) { - aResult<<"Volume: "<< - std::fixed< 1.e-5) { + aResult<<"Volume: "; + // volumes of too huge shapes write in the scientific format + if (aVolume >= 1.e5) + aResult< aCenter = GeomAlgoAPI_ShapeTools::centreOfMass(theShape); aResult<<"Center of mass: "; diff --git a/src/SketchPlugin/SketchPlugin_Line.cpp b/src/SketchPlugin/SketchPlugin_Line.cpp index e52847193..f01a332f2 100644 --- a/src/SketchPlugin/SketchPlugin_Line.cpp +++ b/src/SketchPlugin/SketchPlugin_Line.cpp @@ -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() diff --git a/src/SketchPlugin/SketchPlugin_Line.h b/src/SketchPlugin/SketchPlugin_Line.h index 73ad43107..7a23944ae 100644 --- a/src/SketchPlugin/SketchPlugin_Line.h +++ b/src/SketchPlugin/SketchPlugin_Line.h @@ -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(); diff --git a/src/SketchPlugin/SketchPlugin_Point.cpp b/src/SketchPlugin/SketchPlugin_Point.cpp index 9a6358053..c53006489 100644 --- a/src/SketchPlugin/SketchPlugin_Point.cpp +++ b/src/SketchPlugin/SketchPlugin_Point.cpp @@ -22,7 +22,6 @@ #include #include -#include #include #include #include @@ -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() diff --git a/src/SketchPlugin/SketchPlugin_Point.h b/src/SketchPlugin/SketchPlugin_Point.h index 5111ce0a8..1cdcae05f 100644 --- a/src/SketchPlugin/SketchPlugin_Point.h +++ b/src/SketchPlugin/SketchPlugin_Point.h @@ -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() { diff --git a/src/SketchPlugin/SketchPlugin_SketchEntity.cpp b/src/SketchPlugin/SketchPlugin_SketchEntity.cpp index 86dcae365..89d70db0d 100644 --- a/src/SketchPlugin/SketchPlugin_SketchEntity.cpp +++ b/src/SketchPlugin/SketchPlugin_SketchEntity.cpp @@ -19,6 +19,7 @@ #include "SketchPlugin_SketchEntity.h" +#include #include #include @@ -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()); } diff --git a/src/SketchPlugin/SketchPlugin_SketchEntity.h b/src/SketchPlugin/SketchPlugin_SketchEntity.h index cae07149d..b181565a7 100644 --- a/src/SketchPlugin/SketchPlugin_SketchEntity.h +++ b/src/SketchPlugin/SketchPlugin_SketchEntity.h @@ -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() { diff --git a/src/SketchPlugin/SketchPlugin_Split.cpp b/src/SketchPlugin/SketchPlugin_Split.cpp index a8f054eb8..b0a5658ff 100644 --- a/src/SketchPlugin/SketchPlugin_Split.cpp +++ b/src/SketchPlugin/SketchPlugin_Split.cpp @@ -1160,8 +1160,7 @@ FeaturePtr SketchPlugin_Split::splitClosed(FeaturePtr& theSplitFeature, const std::set& aRefs = aBaseFeature->data()->refsToMe(); std::list aRefsToParent; for (std::set::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::iterator aRef = aRefsToParent.begin(); diff --git a/src/SketchPlugin/SketchPlugin_Trim.cpp b/src/SketchPlugin/SketchPlugin_Trim.cpp index b7d0535db..2957e0315 100644 --- a/src/SketchPlugin/SketchPlugin_Trim.cpp +++ b/src/SketchPlugin/SketchPlugin_Trim.cpp @@ -1061,8 +1061,7 @@ FeaturePtr SketchPlugin_Trim::trimClosed(const std::shared_ptr& t const std::set& aRefs = aBaseFeature->data()->refsToMe(); std::list aRefsToParent; for (std::set::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::iterator aRef = aRefsToParent.begin(); diff --git a/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp b/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp index 2c4d8eed3..4bac7dd1f 100644 --- a/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp @@ -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(); } } } diff --git a/test.hdfs/CMakeLists.txt b/test.hdfs/CMakeLists.txt index 58c6c48bd..a8e5ca417 100644 --- a/test.hdfs/CMakeLists.txt +++ b/test.hdfs/CMakeLists.txt @@ -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 index 000000000..a1d81d595 --- /dev/null +++ b/test.hdfs/Test2971.py @@ -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)) diff --git a/test.hdfs/delta_p.py b/test.hdfs/delta_p.py index 24452f836..4487731e7 100644 --- a/test.hdfs/delta_p.py +++ b/test.hdfs/delta_p.py @@ -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]) diff --git a/test.hdfs/roselend.py b/test.hdfs/roselend.py index e0533c354..875d48f43 100644 --- a/test.hdfs/roselend.py +++ b/test.hdfs/roselend.py @@ -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]) diff --git a/test.hdfs/te_fluide.py b/test.hdfs/te_fluide.py index 25ea15af0..75870c392 100644 --- a/test.hdfs/te_fluide.py +++ b/test.hdfs/te_fluide.py @@ -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]) diff --git a/test.hdfs/te_solide.py b/test.hdfs/te_solide.py index 5d4470428..7b588d6fb 100644 --- a/test.hdfs/te_solide.py +++ b/test.hdfs/te_solide.py @@ -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]) diff --git a/test.hdfs/test_hdf.py b/test.hdfs/test_hdf.py index 9dbc1578c..1ae49db9c 100644 --- a/test.hdfs/test_hdf.py +++ b/test.hdfs/test_hdf.py @@ -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__": diff --git a/test.hdfs/usine.py b/test.hdfs/usine.py index 278c08aab..ddd087684 100644 --- a/test.hdfs/usine.py +++ b/test.hdfs/usine.py @@ -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])