Salome HOME
Porting to SALOME_8.2.0
[modules/shaper.git] / src / SketchPlugin / Test / TestMultiTranslation.py
index b421c628d5d405a20a3c4ea5dfc7865f7999fc9c..0d3971e27e640289d955646ce9a345c258086c79 100644 (file)
@@ -4,9 +4,10 @@
         
     SketchPlugin_MultiTranslation
         static const std::string MY_CONSTRAINT_TRANSLATION_ID("SketchMultiTranslation");
-        data()->addAttribute(START_POINT_ID(), GeomDataAPI_Point2D::typeId());
-        data()->addAttribute(END_POINT_ID(), GeomDataAPI_Point2D::typeId());
-        data()->addAttribute(NUMBER_OF_COPIES_ID(), ModelAPI_AttributeInteger::typeId());
+        data()->addAttribute(VALUE_TYPE(), ModelAPI_AttributeString::typeId());
+        data()->addAttribute(START_POINT_ID(), ModelAPI_AttributeRefAttr::typeId());
+        data()->addAttribute(END_POINT_ID(), ModelAPI_AttributeRefAttr::typeId());
+        data()->addAttribute(NUMBER_OF_OBJECTS_ID(), ModelAPI_AttributeInteger::typeId());
         data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefList::typeId());
         data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefList::typeId());
         data()->addAttribute(TRANSLATION_LIST_ID(), ModelAPI_AttributeRefList::typeId());
@@ -33,7 +34,16 @@ def createSketch(theSketch):
     theSketch.execute()
     return allFeatures
     
-def checkTranslation(theObjects, theNbCopies, theDeltaX, theDeltaY):
+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 checkTranslation(theObjects, theNbObjects, theDeltaX, theDeltaY):
     # Verify distances of the objects and the number of copies
     aFeatures = []
     aSize = theObjects.size()
@@ -45,7 +55,7 @@ def checkTranslation(theObjects, theNbCopies, theDeltaX, theDeltaY):
     anInd = 0 
     for feat, next in zip(aFeatures[:-1], aFeatures[1:]):
         anInd = anInd + 1
-        if (anInd > theNbCopies):
+        if (anInd > theNbObjects-1):
             anInd = 0
             continue
         assert(feat.getKind() == next.getKind())
@@ -60,13 +70,13 @@ def checkTranslation(theObjects, theNbCopies, theDeltaX, theDeltaY):
             anAttributes.append('ArcEndPoint')
             
         for attr in anAttributes:
-            aPoint1 = geomDataAPI_Point2D(feat.attribute(attr))
-            aPoint2 = geomDataAPI_Point2D(next.attribute(attr))
-            aDiffX = aPoint2.x() - aPoint1.x() - theDeltaX
-            aDiffY = aPoint2.y() - aPoint1.y() - theDeltaY
-            assert(aDiffX**2 + aDiffY**2 < 1.e-15)
+             aPoint1 = geomDataAPI_Point2D(feat.attribute(attr))
+             aPoint2 = geomDataAPI_Point2D(next.attribute(attr))
+             aDiffX = aPoint2.x() - aPoint1.x() - theDeltaX
+             aDiffY = aPoint2.y() - aPoint1.y() - theDeltaY
+             assert(aDiffX**2 + aDiffY**2 < 1.e-15)
     # Check the number of copies is as planed
-    assert(anInd == theNbCopies)
+    assert(anInd == theNbObjects-1)
 
 
 #=========================================================================
@@ -106,6 +116,16 @@ DIR_Y = 10.
 DELTA_X = -5.
 DELTA_Y = 3.
 #=========================================================================
+# Create translation line
+#=========================================================================
+aSession.startOperation()
+aTransLine = aSketchFeature.addFeature("SketchLine")
+aTransLineStartPoint = geomDataAPI_Point2D(aTransLine.attribute("StartPoint"))
+aTransLineEndPoint = geomDataAPI_Point2D(aTransLine.attribute("EndPoint"))
+aTransLineStartPoint.setValue(START_X, START_Y)
+aTransLineEndPoint.setValue(START_X + DELTA_X, START_Y + DELTA_Y)
+aSession.finishOperation()
+#=========================================================================
 # Create the Translation constraint
 #=========================================================================
 aSession.startOperation()
@@ -115,19 +135,22 @@ for aFeature in aFeaturesList:
     aResult = modelAPI_ResultConstruction(aFeature.lastResult())
     assert(aResult is not None)
     aTransList.append(aResult)
-aStartPoint = geomDataAPI_Point2D(aMultiTranslation.attribute("MultiTranslationStartPoint"))
-aEndPoint = geomDataAPI_Point2D(aMultiTranslation.attribute("MultiTranslationEndPoint"))
-aStartPoint.setValue(START_X, START_Y)
-aEndPoint.setValue(START_X + DIR_X, START_Y + DIR_Y)
-aNbCopies = aMultiTranslation.integer("MultiTranslationCopies")
-aNbCopies.setValue(1)
+
+aValueType = aMultiTranslation.string("ValueType")
+aValueType.setValue("SingleValue")
+aStartPoint = aMultiTranslation.refattr("MultiTranslationStartPoint")
+aEndPoint = aMultiTranslation.refattr("MultiTranslationEndPoint")
+aStartPoint.setAttr(aTransLineStartPoint)
+aEndPoint.setAttr(aTransLineEndPoint)
+aNbCopies = aMultiTranslation.integer("MultiTranslationObjects")
+aNbCopies.setValue(2)
 aMultiTranslation.execute()
 aSession.finishOperation()
 #=========================================================================
 # Verify the objects are moved for the specified distance
 #=========================================================================
 aTranslated = aMultiTranslation.reflist("ConstraintEntityB")
-checkTranslation(aTranslated, aNbCopies.value(), DIR_X, DIR_Y)
+checkTranslation(aTranslated, aNbCopies.value(), DELTA_X, DELTA_Y)
 #=========================================================================
 # Change number of copies and verify translation
 #=========================================================================
@@ -135,12 +158,58 @@ aSession.startOperation()
 aNbCopies.setValue(3)
 aSession.finishOperation()
 aTranslated = aMultiTranslation.reflist("ConstraintEntityB")
-checkTranslation(aTranslated, aNbCopies.value(), DIR_X, DIR_Y)
+checkTranslation(aTranslated, aNbCopies.value(), DELTA_X, DELTA_Y)
+
 #=========================================================================
-# TODO: improve test
-# 1. Add more features into translation
-# 2. Move one of initial features and check the translated is moved too
+# 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)
+aTransList.append(aResult)
+aSession.finishOperation()
+checkTranslation(aTranslated, aNbCopies.value(), DELTA_X, DELTA_Y)
+#=========================================================================
+# Move line and check the copies are moved too
+#=========================================================================
+aSession.startOperation()
+aStartPoint = geomDataAPI_Point2D(aLine.attribute("StartPoint"))
+aStartPoint.setValue(12., 5.)
+aSession.finishOperation()
+checkTranslation(aTranslated, aNbCopies.value(), DELTA_X, DELTA_Y)
+#=========================================================================
+# Change number of copies and verify Rotation
+#=========================================================================
+aSession.startOperation()
+aNbCopies.setValue(2)
+aSession.finishOperation()
+checkTranslation(aTranslated, aNbCopies.value(), DELTA_X, DELTA_Y)
+
+#=========================================================================
+# Remove a feature from the Rotation
+#=========================================================================
+aSession.startOperation()
+aRemoveIt = aTransList.object(0)
+aTransList.remove(aRemoveIt)
+aSession.finishOperation()
+checkTranslation(aTranslated, aNbCopies.value(), DELTA_X, DELTA_Y)
+
+#=========================================================================
+# Clear the list of rotated features
+#=========================================================================
+aSession.startOperation()
+aTransList.clear()
+checkTranslation(aTranslated, 1, DELTA_X, DELTA_Y)
+# Add line once again
+aTransList.append(aResult)
+aSession.finishOperation()
+checkTranslation(aTranslated, aNbCopies.value(), DELTA_X, DELTA_Y)
 #=========================================================================
 # End of test
 #=========================================================================
+
+import model
+assert(model.checkPythonDump())