Salome HOME
Issue #2130: arc is done not as desired
[modules/shaper.git] / src / SketchPlugin / Test / TestMultiRotation.py
index 68a3b6a392cea8b78803a0c35b1a5d512d327809..905117ae394ef5908c7a39abbed283f7f8f2221b 100644 (file)
@@ -16,6 +16,7 @@
 from GeomDataAPI import *
 from ModelAPI import *
 import math
+from salome.shaper import model
 
 #=========================================================================
 # Auxiliary functions
@@ -25,9 +26,9 @@ def createSketch(theSketch):
     allFeatures = []
     # Create arc
     aSketchArc = theSketch.addFeature("SketchArc")
-    aCenter     = geomDataAPI_Point2D(aSketchArc.attribute("ArcCenter"))
-    aStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcStartPoint"))
-    aEndPoint   = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
+    aCenter     = geomDataAPI_Point2D(aSketchArc.attribute("center_point"))
+    aStartPoint = geomDataAPI_Point2D(aSketchArc.attribute("start_point"))
+    aEndPoint   = geomDataAPI_Point2D(aSketchArc.attribute("end_point"))
     aCenter.setValue(5., 5.)
     aStartPoint.setValue(10., 5.)
     aEndPoint.setValue(5., 10.)
@@ -35,6 +36,15 @@ def createSketch(theSketch):
     theSketch.execute()
     return allFeatures
     
+def createLine(theSketch):
+    aSketchLine = theSketch.addFeature("SketchLine")
+    aStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
+    aEndPoint   = geomDataAPI_Point2D(aSketchLine.attribute("EndPoint"))
+    aStartPoint.setValue(7., 5.)
+    aEndPoint.setValue(1., 3.)
+    theSketch.execute()
+    return aSketchLine
+    
 def checkRotation(theObjects, theNbObjects, theCenterX, theCenterY, theAngle):
     # Verify distances of the objects and the number of copies
     aFeatures = []
@@ -59,9 +69,9 @@ def checkRotation(theObjects, theNbObjects, theCenterX, theCenterY, theAngle):
             anAttributes.append('StartPoint')
             anAttributes.append('EndPoint')
         elif (feat.getKind() == "SketchArc"):
-            anAttributes.append('ArcCenter')
-            anAttributes.append('ArcStartPoint')
-            anAttributes.append('ArcEndPoint')
+            anAttributes.append('center_point')
+            anAttributes.append('start_point')
+            anAttributes.append('end_point')
             
         for attr in anAttributes:
             aPoint1 = geomDataAPI_Point2D(feat.attribute(attr))
@@ -105,6 +115,7 @@ aSession.finishOperation()
 aSession.startOperation()
 aFeaturesList = createSketch(aSketchFeature)
 aSession.finishOperation()
+assert(model.dof(aSketchFeature) == 5)
 #=========================================================================
 # Global variables
 #=========================================================================
@@ -112,6 +123,15 @@ CENTER_X = 0.
 CENTER_Y = 0.
 ANGLE = 30.
 #=========================================================================
+# Create rotation point
+#=========================================================================
+aSession.startOperation()
+aRotationPoint = aSketchFeature.addFeature("SketchPoint")
+aRotationPointPoint = geomDataAPI_Point2D(aRotationPoint.attribute("PointCoordinates"))
+aRotationPointPoint.setValue(CENTER_X, CENTER_Y)
+aSession.finishOperation()
+assert(model.dof(aSketchFeature) == 7)
+#=========================================================================
 # Create the Rotation constraint
 #=========================================================================
 aSession.startOperation()
@@ -125,14 +145,20 @@ for aFeature in aFeaturesList:
 aValueType = aMultiRotation.string("AngleType")
 aValueType.setValue("SingleValue")
 
-aCenter = geomDataAPI_Point2D(aMultiRotation.attribute("MultiRotationCenter"))
+aCenter = aMultiRotation.refattr("MultiRotationCenter")
+aCenter.setAttr(aRotationPointPoint)
+
 anAngle = aMultiRotation.real("MultiRotationAngle")
-aCenter.setValue(CENTER_X, CENTER_Y)
 anAngle.setValue(ANGLE)
+
+anAngle = aMultiRotation.string("AngleType")
+anAngle.setValue("SingleAngle")
+
 aNbCopies = aMultiRotation.integer("MultiRotationObjects")
-aNbCopies.setValue(1)
+aNbCopies.setValue(2)
 aMultiRotation.execute()
 aSession.finishOperation()
+assert(model.dof(aSketchFeature) == 7)
 #=========================================================================
 # Verify the objects are moved for the specified distance
 #=========================================================================
@@ -146,11 +172,62 @@ aNbCopies.setValue(3)
 aSession.finishOperation()
 aRotated = aMultiRotation.reflist("ConstraintEntityB")
 checkRotation(aRotated, aNbCopies.value(), CENTER_X, CENTER_Y, ANGLE)
+assert(model.dof(aSketchFeature) == 7)
+
+#=========================================================================
+# Create new feature and add it into the Rotation
+#=========================================================================
+aSession.startOperation()
+aLine = createLine(aSketchFeature)
+aSession.finishOperation()
+aSession.startOperation()
+aResult = modelAPI_ResultConstruction(aLine.lastResult())
+assert(aResult is not None)
+aRotList.append(aResult)
+aSession.finishOperation()
+checkRotation(aRotated, aNbCopies.value(), CENTER_X, CENTER_Y, ANGLE)
+assert(model.dof(aSketchFeature) == 11)
 #=========================================================================
-# TODO: improve test
-# 1. Add more features into Rotation
-# 2. Move one of initial features and check the Rotated is moved too
+# Move line and check the copies are moved too
 #=========================================================================
+aSession.startOperation()
+aStartPoint = geomDataAPI_Point2D(aLine.attribute("StartPoint"))
+aStartPoint.setValue(12., 5.)
+aSession.finishOperation()
+checkRotation(aRotated, aNbCopies.value(), CENTER_X, CENTER_Y, ANGLE)
+assert(model.dof(aSketchFeature) == 11)
+#=========================================================================
+# Change number of copies and verify Rotation
+#=========================================================================
+aSession.startOperation()
+aNbCopies.setValue(2)
+aSession.finishOperation()
+checkRotation(aRotated, aNbCopies.value(), CENTER_X, CENTER_Y, ANGLE)
+assert(model.dof(aSketchFeature) == 11)
+
+#=========================================================================
+# Remove a feature from the Rotation
+#=========================================================================
+aSession.startOperation()
+aRemoveIt = aRotList.object(0)
+aRotList.remove(aRemoveIt)
+aSession.finishOperation()
+checkRotation(aRotated, aNbCopies.value(), CENTER_X, CENTER_Y, ANGLE)
+assert(model.dof(aSketchFeature) == 11)
+
+#=========================================================================
+# Clear the list of rotated features
+#=========================================================================
+aSession.startOperation()
+aRotList.clear()
+checkRotation(aRotated, 1, CENTER_X, CENTER_Y, ANGLE)
+# Add line once again
+aRotList.append(aResult)
+aSession.finishOperation()
+checkRotation(aRotated, aNbCopies.value(), CENTER_X, CENTER_Y, ANGLE)
+assert(model.dof(aSketchFeature) == 11)
 #=========================================================================
 # End of test
 #=========================================================================
+
+assert(model.checkPythonDump())