]> SALOME platform Git repositories - modules/shaper.git/blob - src/ParametersPlugin/Test/TestParameterChangeValue.py
Salome HOME
Added python dump checking for every unit test where it is useful.
[modules/shaper.git] / src / ParametersPlugin / Test / TestParameterChangeValue.py
1 """
2     TestParameterCreation.py
3     
4     class ParametersPlugin_Parameter
5     static const std::string MY_PARAMETER_ID("Parameter");
6     static const std::string MY_VARIABLE_ID("variable");
7     static const std::string MY_EXPRESSION_ID("expression");
8     
9     data()->addAttribute(ParametersPlugin_Parameter::VARIABLE_ID(),
10                          ModelAPI_AttributeString::typeId());
11     data()->addAttribute(ParametersPlugin_Parameter::EXPRESSION_ID(),
12                          ModelAPI_AttributeString::typeId());
13                          
14     class ModelAPI_ResultParameter
15     static const std::string MY_VALUE_ID("Value");
16     static const std::string MY_VALUE_ID("State");
17 """
18
19 #=========================================================================
20 # Initialization of the test
21 #=========================================================================
22 from GeomDataAPI import *
23 from ModelAPI import *
24 import math
25 import unittest
26 import model
27
28 __updated__ = "2015-04-27"
29
30 #=========================================================================
31 # Create several parameters and a feature.
32 # 1. Basic parameter definition:
33 #    x1 = 150.0, y1 = 200.0
34 # 2. Referencing between parameters:
35 #    x2 = x1 + y1 + 100.0
36 # 3. Referencing in feature SketchCircle
37 #    CircleCenter = (x1 + 10.0, x1 + 20.0), CircleRadius = x1
38 # 3. Change value
39 #    x1 = 200.0
40 #=========================================================================
41 class TestParameterRename(unittest.TestCase):
42     def setUp(self):
43         self.aSession = ModelAPI_Session.get()
44         self.aDocument = self.aSession.moduleDocument()
45         self.createParameters()
46         self.createFeature()
47
48     def tearDown(self):
49         assert(model.checkPythonDump())
50         self.aSession.closeAll()
51
52     def createParameters(self):
53         ltNames = ["x1", "y1", "x2"]
54         ltExpressions = ["150.", "200.", "x1 + y1 + 100.0"]
55         self.dtParams = {}
56         for name, expr in zip(ltNames, ltExpressions):
57             self.aSession.startOperation()
58             aParam = self.aDocument.addFeature("Parameter")
59             aParamName = aParam.string("variable")
60             aParamName.setValue(name)
61             aParamExpr = aParam.string("expression")
62             aParamExpr.setValue(expr)
63             self.dtParams[name] = aParam
64             self.aSession.finishOperation()
65         self.assertEqual(len(self.dtParams), len(ltNames))
66
67         aParam = self.dtParams["x2"]
68         aResultAttr = modelAPI_ResultParameter(aParam.firstResult())
69         self.assertEqual(aResultAttr.data().real("Value").value(), 450.)
70
71     def createFeature(self):
72         self.aSession.startOperation()
73         aSketchCommonFeature = self.aDocument.addFeature("Sketch")
74         aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
75         origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
76         origin.setValue(0, 0, 0)
77         dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
78         dirx.setValue(1, 0, 0)
79         norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
80         norm.setValue(0, 0, 1)
81         aSketchCircle = aSketchFeature.addFeature("SketchCircle")
82         anCircleCentr = geomDataAPI_Point2D(aSketchCircle.attribute("CircleCenter"))
83         aRadiusAttr = aSketchCircle.real("CircleRadius")
84         anCircleCentr.setText("x1 + 10.0", "x1 + 20.0")
85         aRadiusAttr.setText("x1")
86         self.aSession.finishOperation()
87
88         self.anCircleCentr = anCircleCentr
89         self.aRadiusAttr = aRadiusAttr
90
91         self.assertEqual(self.anCircleCentr.x(), 160.)
92         self.assertEqual(self.anCircleCentr.y(), 170.)
93         self.assertEqual(aRadiusAttr.value(), 150.)
94
95     def test_change_value(self):
96         aParam = self.dtParams["x1"]
97         aResultAttr = modelAPI_ResultParameter(aParam.firstResult())
98         self.aSession.startOperation()
99         aParam.string("expression").setValue("200.0")
100         self.aSession.finishOperation()
101
102         # Check value of the parameter 
103         self.assertEqual(aResultAttr.data().real("Value").value(), 200.)
104         # Check value of references
105         aParam = self.dtParams["x2"]
106         aResultAttr = modelAPI_ResultParameter(aParam.firstResult())
107         self.assertEqual(aResultAttr.data().real("Value").value(), 500.)
108         # Check value in the feature
109         self.assertEqual(self.anCircleCentr.x(), 210.)
110         self.assertEqual(self.anCircleCentr.y(), 220.)
111         self.assertEqual(self.aRadiusAttr.value(), 200.)
112
113 if __name__ == '__main__':
114     unittest.main()
115 #=========================================================================
116 # End of test
117 #=========================================================================