Salome HOME
updated copyright message
[modules/shaper.git] / src / SketchPlugin / Test / TestMultiRotation.py
index 2afda371697834187d41e8c319458e9652672948..abc6842e48e8dc0b8929bcd108ea5e46ab352c39 100644 (file)
@@ -1,7 +1,26 @@
+# 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
+#
+
 """
     TestMultiRotation.py
     Unit test of SketchPlugin_MultiRotation class
-        
+
     SketchPlugin_MultiRotation
         static const std::string MY_CONSTRAINT_ROTATION_ID("SketchMultiRotation");
         data()->addAttribute(ANGLE_TYPE(), ModelAPI_AttributeString::typeId());
@@ -16,6 +35,7 @@
 from GeomDataAPI import *
 from ModelAPI import *
 import math
+from salome.shaper import model
 
 #=========================================================================
 # Auxiliary functions
@@ -25,16 +45,16 @@ 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.)
     allFeatures.append(aSketchArc)
     theSketch.execute()
     return allFeatures
-    
+
 def createLine(theSketch):
     aSketchLine = theSketch.addFeature("SketchLine")
     aStartPoint = geomDataAPI_Point2D(aSketchLine.attribute("StartPoint"))
@@ -43,7 +63,7 @@ def createLine(theSketch):
     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 = []
@@ -52,26 +72,26 @@ def checkRotation(theObjects, theNbObjects, theCenterX, theCenterY, theAngle):
         feat = ModelAPI_Feature.feature(theObjects.object(i))
         assert(feat is not None)
         aFeatures.append(feat)
-        
+
     cosA = math.cos(theAngle * math.pi / 180.)
-        
-    anInd = 0 
+
+    anInd = 0
     for feat, next in zip(aFeatures[:-1], aFeatures[1:]):
         anInd = anInd + 1
         if (anInd > theNbObjects-1):
             anInd = 0
             continue
         assert(feat.getKind() == next.getKind())
-        
+
         anAttributes = []
         if (feat.getKind() == "SketchLine"):
             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))
             aPoint2 = geomDataAPI_Point2D(next.attribute(attr))
@@ -114,6 +134,7 @@ aSession.finishOperation()
 aSession.startOperation()
 aFeaturesList = createSketch(aSketchFeature)
 aSession.finishOperation()
+assert(model.dof(aSketchFeature) == 5)
 #=========================================================================
 # Global variables
 #=========================================================================
@@ -125,9 +146,10 @@ ANGLE = 30.
 #=========================================================================
 aSession.startOperation()
 aRotationPoint = aSketchFeature.addFeature("SketchPoint")
-aRotationPointPoint = geomDataAPI_Point2D(aRotationPoint.attribute("PointCoordindates"))
+aRotationPointPoint = geomDataAPI_Point2D(aRotationPoint.attribute("PointCoordinates"))
 aRotationPointPoint.setValue(CENTER_X, CENTER_Y)
 aSession.finishOperation()
+assert(model.dof(aSketchFeature) == 7)
 #=========================================================================
 # Create the Rotation constraint
 #=========================================================================
@@ -155,6 +177,7 @@ aNbCopies = aMultiRotation.integer("MultiRotationObjects")
 aNbCopies.setValue(2)
 aMultiRotation.execute()
 aSession.finishOperation()
+assert(model.dof(aSketchFeature) == 7)
 #=========================================================================
 # Verify the objects are moved for the specified distance
 #=========================================================================
@@ -168,6 +191,7 @@ 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
@@ -181,6 +205,7 @@ assert(aResult is not None)
 aRotList.append(aResult)
 aSession.finishOperation()
 checkRotation(aRotated, aNbCopies.value(), CENTER_X, CENTER_Y, ANGLE)
+assert(model.dof(aSketchFeature) == 11)
 #=========================================================================
 # Move line and check the copies are moved too
 #=========================================================================
@@ -189,6 +214,7 @@ 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
 #=========================================================================
@@ -196,6 +222,7 @@ 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
@@ -205,6 +232,7 @@ 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
@@ -216,9 +244,9 @@ checkRotation(aRotated, 1, CENTER_X, CENTER_Y, ANGLE)
 aRotList.append(aResult)
 aSession.finishOperation()
 checkRotation(aRotated, aNbCopies.value(), CENTER_X, CENTER_Y, ANGLE)
+assert(model.dof(aSketchFeature) == 11)
 #=========================================================================
 # End of test
 #=========================================================================
 
-import model
 assert(model.checkPythonDump())