X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FParametersPlugin%2FTest%2FTestParameterCreation.py;h=2fca977bf2dacc615bd977d9ff35ba31c84e05a2;hb=09365c927ebe8d881de2eda7f96bc33a2d9511c8;hp=d775d7301d117af8a18a32e6f33b247754f53486;hpb=564df60468b225bbce2f1cc055299b47c3be9355;p=modules%2Fshaper.git diff --git a/src/ParametersPlugin/Test/TestParameterCreation.py b/src/ParametersPlugin/Test/TestParameterCreation.py index d775d7301..2fca977bf 100644 --- a/src/ParametersPlugin/Test/TestParameterCreation.py +++ b/src/ParametersPlugin/Test/TestParameterCreation.py @@ -1,16 +1,35 @@ +# Copyright (C) 2014-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 +# + """ TestParameterCreation.py - + class ParametersPlugin_Parameter static const std::string MY_PARAMETER_ID("Parameter"); static const std::string MY_VARIABLE_ID("variable"); static const std::string MY_EXPRESSION_ID("expression"); - + data()->addAttribute(ParametersPlugin_Parameter::VARIABLE_ID(), ModelAPI_AttributeString::typeId()); data()->addAttribute(ParametersPlugin_Parameter::EXPRESSION_ID(), ModelAPI_AttributeString::typeId()); - + class ModelAPI_ResultParameter static const std::string MY_VALUE_ID("Value"); static const std::string MY_VALUE_ID("State"); @@ -69,7 +88,7 @@ for name, expr in zip(ltNames, ltExpressions): assert(aResultAttr.data()) assert(aResultAttr.data().real("Value")) aResultValue = aResultAttr.data().real("Value").value() - print aResultValue, " == ", float(expr) + print(aResultValue, " == ", float(expr)) assert(aResultValue == float(expr)) # Check referencing between parameters @@ -114,18 +133,23 @@ assert (aTmValue == round(2 * math.pi, 6)) #========================================================================= # Use parameters to set radius of a circle : # 1. Create a circle (250., 250), r = 25. -# 2. Set a 'cr1' as text value of radius attribute +# 2. Create a radius constraint and set 'cr1' as text value of constraint #========================================================================= aSession.startOperation() aSketchCircle = aSketchFeature.addFeature("SketchCircle") -anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter")) -aRadiusAttr = aSketchCircle.real("CircleRadius") +anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("circle_center")) +aRadiusAttr = aSketchCircle.real("circle_radius") anCircleCentr.setValue(250., 250) aRadiusAttr.setValue(25.) aSession.finishOperation() # Apply parameter aSession.startOperation() -aRadiusAttr.setText("cr1") +aRadiusConstraint = aSketchFeature.addFeature("SketchConstraintRadius") +refattrA = aRadiusConstraint.refattr("ConstraintEntityA") +refattrA.setObject(modelAPI_ResultConstruction(aSketchCircle.lastResult())) +aRadiusConstrAttr = aRadiusConstraint.real("ConstraintValue") +aRadiusConstrAttr.setText("cr1") +aRadiusConstraint.execute() aSession.finishOperation() assert(aRadiusAttr.value() == 100.) #========================================================================= @@ -158,3 +182,6 @@ assert(aLengthAttr.value() == 250.) #========================================================================= # End of test #========================================================================= + +from salome.shaper import model +assert(model.checkPythonDump())