Salome HOME
updated copyright message
[modules/shaper.git] / src / SketchPlugin / Test / TestConstraintPerpendicular.py
index 8f8f253de9204ebcf9fe0614cf42d9bcc30b8390..b419965f73ce9180a2758a3883fe9874b714e4cf 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
+#
+
 """
     TestConstraintPerpendicular.py
     Unit test of SketchPlugin_ConstraintPerpendicular class
-    
+
     SketchPlugin_Constraint
         static const std::string MY_CONSTRAINT_VALUE("ConstraintValue");
         static const std::string MY_FLYOUT_VALUE_PNT("ConstraintFlyoutValuePnt");
         static const std::string MY_ENTITY_B("ConstraintEntityB");
         static const std::string MY_ENTITY_C("ConstraintEntityC");
         static const std::string MY_ENTITY_D("ConstraintEntityD");
-        
+
     SketchPlugin_ConstraintPerpendicular
         static const std::string MY_CONSTRAINT_PERPENDICULAR_ID("SketchConstraintPerpendicular");
-        data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type());
-        data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::type());
-        data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::type()); 
+        data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
+        data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId());
+        data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::typeId());
 """
 from GeomDataAPI import *
 from ModelAPI import *
+from salome.shaper import model
+
 #=========================================================================
 # Initialization of the test
 #=========================================================================
 
-__updated__ = "2014-07-29"
+__updated__ = "2014-10-28"
 
-aPluginManager = ModelAPI_PluginManager.get()
-aDocument = aPluginManager.rootDocument()
+aSession = ModelAPI_Session.get()
+aDocument = aSession.moduleDocument()
 #=========================================================================
 # Creation of a sketch
 #=========================================================================
-aDocument.startOperation()
-aSketchFeature = aDocument.addFeature("Sketch")
-aSketchFeatureData = aSketchFeature.data()
-origin = geomDataAPI_Point(aSketchFeatureData.attribute("Origin"))
+aSession.startOperation()
+aSketchCommonFeature = aDocument.addFeature("Sketch")
+aSketchFeature = featureToCompositeFeature(aSketchCommonFeature)
+origin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
 origin.setValue(0, 0, 0)
-dirx = geomDataAPI_Dir(aSketchFeatureData.attribute("DirX"))
+dirx = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
 dirx.setValue(1, 0, 0)
-diry = geomDataAPI_Dir(aSketchFeatureData.attribute("DirY"))
-diry.setValue(0, 1, 0)
-norm = geomDataAPI_Dir(aSketchFeatureData.attribute("Norm"))
+norm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
 norm.setValue(0, 0, 1)
-aDocument.finishOperation()
+aSession.finishOperation()
 #=========================================================================
 # Create two lines which are already perpendicular
 #=========================================================================
-aDocument.startOperation()
-aSketchReflist = aSketchFeatureData.reflist("Features")
+aSession.startOperation()
 # line A
-aSketchLineA = aDocument.addFeature("SketchLine")
-aSketchReflist.append(aSketchLineA)
-aLineAStartPoint = geomDataAPI_Point2D(
-    aSketchLineA.data().attribute("StartPoint"))
-aLineAEndPoint = geomDataAPI_Point2D(
-    aSketchLineA.data().attribute("EndPoint"))
-aSketchLineB = aDocument.addFeature("SketchLine")
+aSketchLineA = aSketchFeature.addFeature("SketchLine")
+aLineAStartPoint = geomDataAPI_Point2D(aSketchLineA.attribute("StartPoint"))
+aLineAEndPoint = geomDataAPI_Point2D(aSketchLineA.attribute("EndPoint"))
 aLineAStartPoint.setValue(0., 25)
 aLineAEndPoint.setValue(85., 25)
 # line B
-aSketchReflist.append(aSketchLineB)
-aLineBStartPoint = geomDataAPI_Point2D(
-    aSketchLineB.data().attribute("StartPoint"))
-aLineBEndPoint = geomDataAPI_Point2D(
-    aSketchLineB.data().attribute("EndPoint"))
+aSketchLineB = aSketchFeature.addFeature("SketchLine")
+aLineBStartPoint = geomDataAPI_Point2D(aSketchLineB.attribute("StartPoint"))
+aLineBEndPoint = geomDataAPI_Point2D(aSketchLineB.attribute("EndPoint"))
 aLineBStartPoint.setValue(25., 40.)
 aLineBEndPoint.setValue(25., 125.)
-aDocument.finishOperation()
+aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 8)
 #=========================================================================
 # Make a constraint to keep the length of the line constant
 # to prevent perpendicular constraint collapsing line to point
 #=========================================================================
-aDocument.startOperation()
-aLengthConstraint = aDocument.addFeature("SketchConstraintLength")
-aSketchReflist.append(aLengthConstraint)
-aLengthConstraintData = aLengthConstraint.data()
-refattrA = aLengthConstraintData.refattr("ConstraintEntityA")
-aResultA = modelAPI_ResultConstruction(aSketchLineA.firstResult())
-assert (aResultA is not None)
-refattrA.setObject(aResultA)
-aDocument.finishOperation()
+aSession.startOperation()
+for eachFeature in [aSketchLineA, aSketchLineB]:
+    aLengthConstraint = aSketchFeature.addFeature("SketchConstraintLength")
+    eachRefattr = aLengthConstraint.refattr("ConstraintEntityA")
+    eachResult = modelAPI_ResultConstruction(eachFeature.firstResult())
+    assert (eachResult is not None)
+    eachRefattr.setObject(eachResult)
+    aLengthConstraint.execute()
+aSession.finishOperation()
+
 # Coordinates of lines should not be changed after this constraint
 assert (aLineAStartPoint.x() == 0)
 assert (aLineAStartPoint.y() == 25)
@@ -87,64 +101,50 @@ assert (aLineBStartPoint.x() == 25)
 assert (aLineBStartPoint.y() == 40)
 assert (aLineBEndPoint.x() == 25)
 assert (aLineBEndPoint.y() == 125)
+assert (model.dof(aSketchFeature) == 6)
 #=========================================================================
 # Link lines with perpendicular constraint
 #=========================================================================
-aDocument.startOperation()
-aParallelConstraint = aDocument.addFeature("SketchConstraintParallel")
-aSketchReflist.append(aParallelConstraint)
-aConstraintData = aParallelConstraint.data()
-refattrA = aConstraintData.refattr("ConstraintEntityA")
-refattrB = aConstraintData.refattr("ConstraintEntityB")
-# aResultA is already defined for the length constraint
+aSession.startOperation()
+aPerpendicularConstraint = aSketchFeature.addFeature("SketchConstraintPerpendicular")
+refattrA = aPerpendicularConstraint.refattr("ConstraintEntityA")
+refattrB = aPerpendicularConstraint.refattr("ConstraintEntityB")
+aResultA = modelAPI_ResultConstruction(aSketchLineA.firstResult())
 aResultB = modelAPI_ResultConstruction(aSketchLineB.firstResult())
+assert (aResultA is not None)
 assert (aResultB is not None)
 refattrA.setObject(aResultA)
 refattrB.setObject(aResultB)
-aDocument.finishOperation()
+aPerpendicularConstraint.execute()
+aSession.finishOperation()
+assert (model.dof(aSketchFeature) == 5)
 #=========================================================================
 # Check values and move one constrainted object
 #=========================================================================
-# print "Check values and move one constrainted object"
-# print "assert (aLineAStartPoint.x() == %d)" % aLineAStartPoint.x()
-# print "assert (aLineAStartPoint.y() == %d)" % aLineAStartPoint.y()
-# print "assert (aLineAEndPoint.x() == %d)" % aLineAEndPoint.x()
-# print "assert (aLineAEndPoint.y() == %d)" % aLineAEndPoint.y()
-# print "assert (aLineBStartPoint.x() == %d)" % aLineBStartPoint.x()
-# print "assert (aLineBStartPoint.y() == %d)" % aLineBStartPoint.y()
-# print "assert (aLineBEndPoint.x() == %d)" % aLineBEndPoint.x()
-# print "assert (aLineBEndPoint.y() == %d)" % aLineBEndPoint.y()
+aLineBStartPointPrev = (aLineBStartPoint.x(),aLineBStartPoint.y())
+aLineBEndPointPrev = (aLineBEndPoint.x(),aLineBEndPoint.y())
 deltaX = deltaY = 5.
 # move line without rotation,
 # check that reference's line points are not changed also
-aLineAStartPoint.setValue(aLineAStartPoint.x() + deltaX,
-                          aLineAStartPoint.y() + deltaY)
-aLineAEndPoint.setValue(aLineAEndPoint.x() + deltaX,
-                        aLineAEndPoint.y() + deltaY)
-# print "move line without rotation"
-# print "assert (aLineAStartPoint.x() == %d)" % aLineAStartPoint.x()
-# print "assert (aLineAStartPoint.y() == %d)" % aLineAStartPoint.y()
-# print "assert (aLineAEndPoint.x() == %d)" % aLineAEndPoint.x()
-# print "assert (aLineAEndPoint.y() == %d)" % aLineAEndPoint.y()
-# print "assert (aLineBStartPoint.x() == %d)" % aLineBStartPoint.x()
-# print "assert (aLineBStartPoint.y() == %d)" % aLineBStartPoint.y()
-# print "assert (aLineBEndPoint.x() == %d)" % aLineBEndPoint.x()
-# print "assert (aLineBEndPoint.y() == %d)" % aLineBEndPoint.y()
-
-# rotate line, check that reference's line points are moved also
-aLineAStartPoint.setValue(aLineAStartPoint.x() + deltaX,
-                          aLineAStartPoint.y() + deltaY)
-aLineAEndPoint.setValue(aLineAEndPoint.x() - deltaX,
-                        aLineAEndPoint.y() - deltaY)
-# print "Rotate line, check that reference's line points are moved also"
-# print "assert (aLineAStartPoint.x() == %d)" % aLineAStartPoint.x()
-# print "assert (aLineAStartPoint.y() == %d)" % aLineAStartPoint.y()
-# print "assert (aLineAEndPoint.x() == %d)" % aLineAEndPoint.x()
-# print "assert (aLineAEndPoint.y() == %d)" % aLineAEndPoint.y()
-# print "assert (aLineBStartPoint.x() == %d)" % aLineBStartPoint.x()
-# print "assert (aLineBStartPoint.y() == %d)" % aLineBStartPoint.y()
-# print "assert (aLineBEndPoint.x() == %d)" % aLineBEndPoint.x()
-# print "assert (aLineBEndPoint.y() == %d)" % aLineBEndPoint.y()
+aSession.startOperation()
+aLineAStartPoint.setValue(aLineAStartPoint.x() + deltaX, aLineAStartPoint.y() + deltaY)
+aLineAEndPoint.setValue(aLineAEndPoint.x() + deltaX, aLineAEndPoint.y() + deltaY)
+aSession.finishOperation()
+assert (aLineBStartPointPrev == (aLineBStartPoint.x(), aLineBStartPoint.y()))
+assert (aLineBEndPointPrev   == (aLineBEndPoint.x(),   aLineBEndPoint.y()))
+aLineBStartPointPrev = (aLineBStartPoint.x(),aLineBStartPoint.y())
+aLineBEndPointPrev = (aLineBEndPoint.x(),aLineBEndPoint.y())
+# rotate line,
+# check that reference's line points are moved also
+aSession.startOperation()
+aLineAStartPoint.setValue(aLineAStartPoint.x() + deltaX, aLineAStartPoint.y() + deltaY)
+aLineAEndPoint.setValue(aLineAEndPoint.x() - deltaX, aLineAEndPoint.y() - deltaY)
+aSession.finishOperation()
+assert (aLineBStartPointPrev != (aLineBStartPoint.x(), aLineBStartPoint.y()))
+assert (aLineBEndPointPrev   != (aLineBEndPoint.x(),   aLineBEndPoint.y()))
+assert (model.dof(aSketchFeature) == 5)
 #=========================================================================
 # End of test
 #=========================================================================
+
+assert(model.checkPythonDump())