+# Copyright (C) 2014-2023 CEA, EDF
+#
+# 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");
class TestParameterRename(unittest.TestCase):
def setUp(self):
self.aSession = ModelAPI_Session.get()
- self.aDocument = self.aSession.moduleDocument()
+ model.begin()
+ partSet = self.aSession.moduleDocument()
+ Part = model.addPart(partSet)
+ model.end()
+ self.aDocument = Part.document()
self.createParameters()
self.createFeature()
pass
def createParameters(self):
- ltNames = ["x1", "y1", "x2"]
- ltExpressions = ["150.", "200.", "x1 + y1 + 100.0"]
+ ltNames = ["x1", "y1", "x2", "n", "px"]
+ ltExpressions = ["150.", "200.", "x1 + y1 + 100.0", "5", "50"]
self.dtParams = {}
for name, expr in zip(ltNames, ltExpressions):
self.aSession.startOperation()
anEndPoint = geomDataAPI_Point2D(anOY.attribute("EndPoint"))
aStartPoint.setValue(0., 0.)
anEndPoint.setValue(0., 100.)
- anOYRes = modelAPI_Result(self.aDocument.objectByName("Construction", "OY"))
- anOY.selection("External").setValue(anOYRes, anOYRes.shape())
+ anOY.selection("External").selectSubShape("EDGE", "PartSet/OY")
anOY.execute()
refattrB.setObject(modelAPI_ResultConstruction(anOY.firstResult()))
valueX = aDistanceConstraint1.real("ConstraintValue")
anEndPoint = geomDataAPI_Point2D(anOX.attribute("EndPoint"))
aStartPoint.setValue(0., 0.)
anEndPoint.setValue(100., 0.)
- anOXRes = modelAPI_Result(self.aDocument.objectByName("Construction", "OX"))
- anOX.selection("External").setValue(anOXRes, anOXRes.shape())
+ anOX.selection("External").selectSubShape("EDGE", "PartSet/OX")
anOX.execute()
refattrB.setObject(modelAPI_ResultConstruction(anOX.firstResult()))
valueY = aDistanceConstraint2.real("ConstraintValue")
self.assertEqual(self.anCircleCentr.y(), 170.)
self.assertEqual(aRadiusAttr.value(), 150.)
+ # add a line and rotate it around origin
+ self.aSession.startOperation()
+ aSketchLine = aSketchFeature.addFeature("SketchLine")
+ aStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
+ aEndPoint = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
+ aStartPoint.setText("px", "0")
+ aEndPoint.setValue(0., 0.)
+ self.aSession.finishOperation()
+ self.aSession.startOperation()
+ aEndPoint.move(100., 0.)
+ self.aSession.finishOperation()
+
+ self.aSession.startOperation()
+ aMultiRotation = aSketchFeature.addFeature("SketchMultiRotation")
+ aMultiRotation.reflist("MultiRotationList").append(aSketchLine.lastResult())
+ aMultiRotation.refattr("MultiRotationCenter").setAttr(anCircleCentr)
+ aMultiRotation.real("MultiRotationAngle").setValue(60.0)
+ aMultiRotation.string("AngleType").setValue("SingleAngle")
+ aMultiRotation.boolean("MultiRotationReversed").setValue(False)
+ aMultiRotation.integer("MultiRotationObjects").setText("n")
+ self.aSession.finishOperation()
+
+ self.aMultiRotCopies = aMultiRotation.integer("MultiRotationObjects")
+
+ # create 3D point
+ self.aSession.startOperation()
+ aPoint3D = self.aDocument.addFeature("Point")
+ aPoint3D.string("creation_method").setValue("by_xyz")
+ aCoords = geomDataAPI_Point(aPoint3D.attribute("point3d"))
+ aCoords.setText("px", "0", "0")
+ self.aSession.finishOperation()
+
+ self.aPoint2D = aStartPoint
+ self.aPoint3D = aCoords
+
def test_rename(self):
# Rename
aParam = self.dtParams["x1"]
aResultAttr.data().setName("a1")
self.aSession.finishOperation()
- # Check rename in the parameter
+ # Check rename in the parameter
self.assertEqual(aParam.name(), "a1")
self.assertEqual(aParam.string("variable").value(), "a1")
self.assertEqual(aResultAttr.data().name(), "a1")
self.assertEqual(self.anCircleCentr.y(), 170.)
self.assertEqual(self.aRadiusAttr.value(), 150.)
+ def test_rename_integer(self):
+ # rename integer parameter
+ aParam = self.dtParams["n"]
+ aResultAttr = modelAPI_ResultParameter(aParam.firstResult())
+ self.aSession.startOperation()
+ aResultAttr.data().setName("m")
+ self.aSession.finishOperation()
+
+ # Check rename in the parameter
+ self.assertEqual(aParam.name(), "m")
+ self.assertEqual(aParam.string("variable").value(), "m")
+ self.assertEqual(aResultAttr.data().name(), "m")
+
+ # Check rename in feature
+ self.assertEqual(self.aMultiRotCopies.text(), "m")
+ # Check corresponding value
+ self.assertEqual(self.aMultiRotCopies.value(), 5)
+
+ def test_rename_point(self):
+ # rename parameter in point coordinates
+ aParam = self.dtParams["px"]
+ aResultAttr = modelAPI_ResultParameter(aParam.firstResult())
+ self.aSession.startOperation()
+ aResultAttr.data().setName("p")
+ self.aSession.finishOperation()
+
+ # Check rename in the parameter
+ self.assertEqual(aParam.name(), "p")
+ self.assertEqual(aParam.string("variable").value(), "p")
+ self.assertEqual(aResultAttr.data().name(), "p")
+
+ # Check rename in feature
+ self.assertEqual(self.aPoint2D.textX(), "p")
+ self.assertEqual(self.aPoint3D.textX(), "p")
+ # Check corresponding value
+ self.assertEqual(self.aPoint2D.x(), 50.)
+ self.assertEqual(self.aPoint3D.x(), 50.)
+
def test_rename_not_unique(self):
# Rename to not unique name
aParam = self.dtParams["x1"]
self.assertEqual(self.anCircleCentr.y(), 170.)
self.assertEqual(self.aRadiusAttr.value(), 150.)
-if __name__ == '__main__':
- unittest.main(exit=False)
+
+if __name__ == "__main__":
+ test_program = unittest.main(exit=False)
+ assert test_program.result.wasSuccessful(), "Test failed"
#=========================================================================
# End of test
#=========================================================================