From c531ee1779b19699e87e2f80f46aa8e7b7fd4084 Mon Sep 17 00:00:00 2001 From: azv Date: Fri, 19 Aug 2016 16:41:38 +0300 Subject: [PATCH] Fix for ParametersPlugin unit tests --- src/ModelHighAPI/ModelHighAPI_Dumper.cpp | 22 ++++++++++++------- src/ModelHighAPI/ModelHighAPI_Dumper.h | 3 ++- src/ParametersAPI/ParametersAPI_Parameter.cpp | 2 +- .../Test/TestParameterChangeValue.py | 12 ++++++---- .../Test/TestParameterRename.py | 14 +++++++----- src/PythonAPI/Test/TestSketcherSetParallel.py | 2 +- 6 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp index 4bfd11a38..0c28e02ec 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp @@ -81,7 +81,9 @@ void ModelHighAPI_Dumper::clearNotDumped() myNotDumpedEntities.clear(); } -const std::string& ModelHighAPI_Dumper::name(const EntityPtr& theEntity, bool theSaveNotDumped) +const std::string& ModelHighAPI_Dumper::name(const EntityPtr& theEntity, + bool theSaveNotDumped, + bool theUseEntityName) { EntityNameMap::const_iterator aFound = myNames.find(theEntity); if (aFound != myNames.end()) @@ -112,14 +114,18 @@ const std::string& ModelHighAPI_Dumper::name(const EntityPtr& theEntity, bool th } // obtain default name for the feature - int aFullIndex = 0; - NbFeaturesMap::const_iterator aFIt = myFeatureCount.begin(); - for (; aFIt != myFeatureCount.end(); ++aFIt) { - std::map::const_iterator aFound = aFIt->second.find(aKind); - if (aFound != aFIt->second.end()) - aFullIndex += aFound->second; + if (theUseEntityName) + aDefaultName << aName; + else { + int aFullIndex = 0; + NbFeaturesMap::const_iterator aFIt = myFeatureCount.begin(); + for (; aFIt != myFeatureCount.end(); ++aFIt) { + std::map::const_iterator aFound = aFIt->second.find(aKind); + if (aFound != aFIt->second.end()) + aFullIndex += aFound->second; + } + aDefaultName << aKind << "_" << aFullIndex; } - aDefaultName << aKind << "_" << aFullIndex; // store names of results saveResultNames(aFeature); diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.h b/src/ModelHighAPI/ModelHighAPI_Dumper.h index 11b6775a8..ed2834f46 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.h +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.h @@ -84,9 +84,10 @@ public: /// Returns name of specified entity /// \param theEntity [in] named entity /// \param theSaveNotDumped [in] if \c true, the entity should be stored as not dumped (will be dumped automatically) + /// \param theUseEntityName [in] if \c true, the entity name should be used "as is" without changing default name /// \return name of the entity MODELHIGHAPI_EXPORT - const std::string& name(const EntityPtr& theEntity, bool theSaveNotDumped = true); + const std::string& name(const EntityPtr& theEntity, bool theSaveNotDumped = true, bool theUseEntityName = false); /// Returns name of parent composite feature for specified entity MODELHIGHAPI_EXPORT diff --git a/src/ParametersAPI/ParametersAPI_Parameter.cpp b/src/ParametersAPI/ParametersAPI_Parameter.cpp index d47448bce..03158e47d 100644 --- a/src/ParametersAPI/ParametersAPI_Parameter.cpp +++ b/src/ParametersAPI/ParametersAPI_Parameter.cpp @@ -42,7 +42,7 @@ void ParametersAPI_Parameter::dump(ModelHighAPI_Dumper& theDumper) const { FeaturePtr aBase = feature(); const std::string& aDocName = theDumper.name(aBase->document()); - const std::string& aParamName = theDumper.name(aBase, false); + const std::string& aParamName = theDumper.name(aBase, false, true); AttributeStringPtr anExpr = aBase->string(ParametersPlugin_Parameter::EXPRESSION_ID()); AttributeStringPtr aComment = aBase->string(ParametersPlugin_Parameter::COMMENT_ID()); diff --git a/src/ParametersPlugin/Test/TestParameterChangeValue.py b/src/ParametersPlugin/Test/TestParameterChangeValue.py index c78775aee..d9941dad1 100644 --- a/src/ParametersPlugin/Test/TestParameterChangeValue.py +++ b/src/ParametersPlugin/Test/TestParameterChangeValue.py @@ -99,8 +99,10 @@ class TestParameterRename(unittest.TestCase): aStartPoint = geomDataAPI_Point2D(anOY.attribute("StartPoint")) anEndPoint = geomDataAPI_Point2D(anOY.attribute("EndPoint")) aStartPoint.setValue(0., 0.) - anEndPoint.SetValue(0., 100.) - anOY.selection("External").selectSubShape("EDGE", "OY") + anEndPoint.setValue(0., 100.) + anOYRes = modelAPI_Result(self.aDocument.objectByName("Construction", "OY")) + anOY.selection("External").setValue(anOYRes, anOYRes.shape()) + anOY.execute() refattrB.setObject(modelAPI_ResultConstruction(anOY.firstResult())) value = aDistanceConstraint1.real("ConstraintValue") value.setText("x1 + 10.0") @@ -114,8 +116,10 @@ class TestParameterRename(unittest.TestCase): aStartPoint = geomDataAPI_Point2D(anOX.attribute("StartPoint")) anEndPoint = geomDataAPI_Point2D(anOX.attribute("EndPoint")) aStartPoint.setValue(0., 0.) - anEndPoint.SetValue(100., 0.) - anOX.selection("External").selectSubShape("EDGE", "OX") + anEndPoint.setValue(100., 0.) + anOXRes = modelAPI_Result(self.aDocument.objectByName("Construction", "OX")) + anOX.selection("External").setValue(anOXRes, anOXRes.shape()) + anOX.execute() refattrB.setObject(modelAPI_ResultConstruction(anOX.firstResult())) value = aDistanceConstraint2.real("ConstraintValue") value.setText("x1 + 20.0") diff --git a/src/ParametersPlugin/Test/TestParameterRename.py b/src/ParametersPlugin/Test/TestParameterRename.py index 795ce9fe7..3343e3b86 100644 --- a/src/ParametersPlugin/Test/TestParameterRename.py +++ b/src/ParametersPlugin/Test/TestParameterRename.py @@ -101,8 +101,10 @@ class TestParameterRename(unittest.TestCase): aStartPoint = geomDataAPI_Point2D(anOY.attribute("StartPoint")) anEndPoint = geomDataAPI_Point2D(anOY.attribute("EndPoint")) aStartPoint.setValue(0., 0.) - anEndPoint.SetValue(0., 100.) - anOY.selection("External").selectSubShape("EDGE", "OY") + anEndPoint.setValue(0., 100.) + anOYRes = modelAPI_Result(self.aDocument.objectByName("Construction", "OY")) + anOY.selection("External").setValue(anOYRes, anOYRes.shape()) + anOY.execute() refattrB.setObject(modelAPI_ResultConstruction(anOY.firstResult())) valueX = aDistanceConstraint1.real("ConstraintValue") valueX.setText("x1 + 10.0") @@ -116,8 +118,10 @@ class TestParameterRename(unittest.TestCase): aStartPoint = geomDataAPI_Point2D(anOX.attribute("StartPoint")) anEndPoint = geomDataAPI_Point2D(anOX.attribute("EndPoint")) aStartPoint.setValue(0., 0.) - anEndPoint.SetValue(100., 0.) - anOX.selection("External").selectSubShape("EDGE", "OX") + anEndPoint.setValue(100., 0.) + anOXRes = modelAPI_Result(self.aDocument.objectByName("Construction", "OX")) + anOX.selection("External").setValue(anOXRes, anOXRes.shape()) + anOX.execute() refattrB.setObject(modelAPI_ResultConstruction(anOX.firstResult())) valueY = aDistanceConstraint2.real("ConstraintValue") valueY.setText("x1 + 20.0") @@ -133,7 +137,7 @@ class TestParameterRename(unittest.TestCase): self.aCircleCenterX = valueX self.aCircleCenterY = valueY - sel.aCircleRadius = aRadiusConstraintAttr + self.aCircleRadius = aRadiusConstrAttr self.assertEqual(self.anCircleCentr.x(), 160.) self.assertEqual(self.anCircleCentr.y(), 170.) diff --git a/src/PythonAPI/Test/TestSketcherSetParallel.py b/src/PythonAPI/Test/TestSketcherSetParallel.py index 9e440ab32..859773b01 100644 --- a/src/PythonAPI/Test/TestSketcherSetParallel.py +++ b/src/PythonAPI/Test/TestSketcherSetParallel.py @@ -5,7 +5,7 @@ from TestSketcher import SketcherTestCase class SketcherSetParallel(SketcherTestCase): def runTest(self): l1 = self.sketch.addLine(0, 0, 0, 1) - l2 = self.sketch.addLine(0, 1, 1, 1) + l2 = self.sketch.addLine(0, 1, 1, 0) self.sketch.setParallel(l1, l2) model.do() -- 2.39.2