Salome HOME
Update copyrights
[modules/shaper.git] / src / SketchPlugin / Test / TestFilletInteracting.py
index 0ba4b06fd8840de94f29f8c6cbdd7ae9a43a7ff4..85d58b9474c04aa47a4142ec1bfaf19c2cbd997e 100644 (file)
@@ -1,3 +1,22 @@
+# Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+#
+# 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
+#
+
 """
     TestFilletInteracting.py
     Unit test of SketchPlugin_Fillet feature.
@@ -7,6 +26,7 @@
 from GeomAPI import *
 from GeomDataAPI import *
 from ModelAPI import *
+from SketchAPI import *
 import math
 import unittest
 from salome.shaper import model
@@ -14,15 +34,15 @@ from salome.shaper import model
 __updated__ = "2017-03-06"
 
 def isArcLineSmooth(theArc, theLine, theTolerance):
-  aCenter = geomDataAPI_Point2D(theArc.attribute("ArcCenter"))
-  aDistance = distancePointLine(aCenter, theLine)
+  aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
+  aDistance = model.distancePointLine(aCenter, theLine)
   aRadius = arcRadius(theArc)
   return math.fabs(aRadius - aDistance) < theTolerance
 
 def isArcArcSmooth(theArc1, theArc2, theTolerance):
-  aCenter1 = geomDataAPI_Point2D(theArc1.attribute("ArcCenter"))
-  aCenter2 = geomDataAPI_Point2D(theArc2.attribute("ArcCenter"))
-  aDistance = distancePointPoint(aCenter1, aCenter2)
+  aCenter1 = geomDataAPI_Point2D(theArc1.attribute("center_point"))
+  aCenter2 = geomDataAPI_Point2D(theArc2.attribute("center_point"))
+  aDistance = model.distancePointPoint(aCenter1, aCenter2)
   aRadius1 = arcRadius(theArc1)
   aRadius2 = arcRadius(theArc2)
   aRadSum = aRadius1 + aRadius2
@@ -30,21 +50,9 @@ def isArcArcSmooth(theArc1, theArc2, theTolerance):
   return math.fabs(aDistance - aRadSum) < theTolerance or math.fabs(aDistance - aRadDiff) < theTolerance
 
 def arcRadius(theArc):
-  aCenter = geomDataAPI_Point2D(theArc.attribute("ArcCenter"))
-  aStart = geomDataAPI_Point2D(theArc.attribute("ArcStartPoint"))
-  return distancePointPoint(aCenter, aStart)
-
-def distancePointPoint(thePoint1, thePoint2):
-  return math.hypot(thePoint1.x() - thePoint2.x(), thePoint1.y() - thePoint2.y())
-
-def distancePointLine(thePoint, theLine):
-  aLineStart = geomDataAPI_Point2D(theLine.attribute("StartPoint"))
-  aLineEnd = geomDataAPI_Point2D(theLine.attribute("EndPoint"))
-  aLength = distancePointPoint(aLineStart, aLineEnd)
-  aDir1x, aDir1y = aLineEnd.x() - aLineStart.x(), aLineEnd.y() - aLineStart.y()
-  aDir2x, aDir2y = thePoint.x() - aLineStart.x(), thePoint.y() - aLineStart.y()
-  aCross = aDir1x * aDir2y - aDir1y * aDir2x
-  return math.fabs(aCross) / aLength
+  aCenter = geomDataAPI_Point2D(theArc.attribute("center_point"))
+  aStart = geomDataAPI_Point2D(theArc.attribute("start_point"))
+  return model.distancePointPoint(aCenter, aStart)
 
 
 
@@ -58,7 +66,7 @@ class TestFilletInteracting(unittest.TestCase):
 
   def tearDown(self):
     model.end()
-    assert(model.checkPythonDump())
+    self.assertTrue(model.checkPythonDump())
     model.reset()
 
 
@@ -114,7 +122,6 @@ class TestFilletInteracting(unittest.TestCase):
     return [aFeatureA, aFeatureB]
 
 
-  @unittest.expectedFailure
   def test_fillet_two_lines(self):
     """ Test 1. Fillet on two connected lines
     """
@@ -165,14 +172,14 @@ class TestFilletInteracting(unittest.TestCase):
     self.checkNbFeatures("SketchConstraintTangent", 0) # no tangencies should not be created
     self.checkNbFeatures("SketchFillet", 1) # fillet feature should still exist. it should be wrong
 
-    model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
-    model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [2])
-    model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [4])
+    # sketch is invalid, so, no results at all
+    model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [])
+    model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [])
+    model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [])
 
     # remove fillet for correct python dump
     self.myDocument.removeFeature(aFillet.feature())
 
-  @unittest.expectedFailure
   def test_fillet_arc_line(self):
     """ Test 3. Fillet on connected arc and line
     """
@@ -201,7 +208,6 @@ class TestFilletInteracting(unittest.TestCase):
     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
 
-  @unittest.expectedFailure
   def test_fillet_two_arcs(self):
     """ Test 4. Fillet on two connected arcs
     """
@@ -230,7 +236,6 @@ class TestFilletInteracting(unittest.TestCase):
     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
 
-  @unittest.expectedFailure
   def test_fillet_with_horizontal_vertical(self):
     """ Test 5. Fillet on two connected lines in case of Horizontal or Vertical constraints applied
     """
@@ -266,7 +271,6 @@ class TestFilletInteracting(unittest.TestCase):
     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
 
-  @unittest.expectedFailure
   def test_fillet_with_orthogonal(self):
     """ Test 6. Fillet on two connected lines in case of Perpendicular constraint applied
     """
@@ -300,7 +304,6 @@ class TestFilletInteracting(unittest.TestCase):
     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
 
-  @unittest.expectedFailure
   def test_fillet_with_parallel(self):
     """ Test 7. Fillet on two connected lines in case of Parallel constraint applied
     """
@@ -337,7 +340,6 @@ class TestFilletInteracting(unittest.TestCase):
     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [4])
     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [8])
 
-  @unittest.expectedFailure
   def test_fillet_with_equal_lines(self):
     """ Test 8. Fillet on two connected lines in case of Equal constraint applied
     """
@@ -354,7 +356,7 @@ class TestFilletInteracting(unittest.TestCase):
     model.do()
     self.checkDOF()
     self.mySketch.setFillet(aSketchLineA.startPoint())
-    self.myDOF += 2
+    self.myDOF += 2 # Equal has been removed
     model.do()
     self.checkFillet()
     self.checkDOF()
@@ -371,7 +373,6 @@ class TestFilletInteracting(unittest.TestCase):
     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
 
-  @unittest.expectedFailure
   def test_fillet_with_equal_arcs(self):
     """ Test 9. Fillet on two connected arcs in case of Equal constraint applied
     """
@@ -388,7 +389,7 @@ class TestFilletInteracting(unittest.TestCase):
     model.do()
     self.checkDOF()
     self.mySketch.setFillet(aSketchArc1.endPoint())
-    self.myDOF += 1
+    self.myDOF += 2 # Equal has been removed
     model.do()
     self.checkFillet()
     self.checkDOF()
@@ -405,7 +406,6 @@ class TestFilletInteracting(unittest.TestCase):
     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
 
-  @unittest.expectedFailure
   def test_fillet_with_length(self):
     """ Test 10. Fillet on two connected lines in case of Length constraint applied
     """
@@ -422,7 +422,7 @@ class TestFilletInteracting(unittest.TestCase):
     model.do()
     self.checkDOF()
     self.mySketch.setFillet(aSketchLineA.startPoint())
-    self.myDOF += 2
+    self.myDOF += 1
     model.do()
     self.checkFillet()
     self.checkDOF()
@@ -430,16 +430,16 @@ class TestFilletInteracting(unittest.TestCase):
     self.collectFeatures()
     self.checkNbFeatures("SketchLine", 2)
     self.checkNbFeatures("SketchArc", 1)
-    self.checkNbFeatures("SketchConstraintCoincidence", 2)
+    self.checkNbFeatures("SketchConstraintCoincidence", 4) # Additionally 2 coincidences for apex with fillet objects
     self.checkNbFeatures("SketchConstraintTangent", 2)
     self.checkNbFeatures("SketchConstraintLength", 0) # Length constraint expected to be removed
+    self.checkNbFeatures("SketchConstraintDistance", 1) # Distance constraint should appear instead of Length
     self.checkNbFeatures("SketchFillet", 0)
 
     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
 
-  @unittest.expectedFailure
   def test_fillet_with_radius(self):
     """ Test 11. Fillet on connected arc and line in case of Radius constraint is applied to arc
     """
@@ -473,26 +473,41 @@ class TestFilletInteracting(unittest.TestCase):
     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
 
-  @unittest.expectedFailure
   def test_fillet_with_distance(self):
     """ Test 12. Fillet on two connected lines in case of Distance constraint applied
     """
-    aSketchLineA = self.mySketch.addLine(10., 10., 20., 10.)
-    aSketchLineB = self.mySketch.addLine(10., 10., 10., 20.)
-    self.myDOF += 8
+    aSketchLineA = self.mySketch.addLine(20, 20, 70, 20)
+    aSketchLineB = self.mySketch.addLine(70, 20, 70, 53.16624790355412)
+    aSketchLineC = self.mySketch.addLine(70, 53.16624790355412, 20, 20)
+    self.myDOF += 12
+    model.do()
     self.checkDOF()
-    self.mySketch.setCoincident(aSketchLineA.startPoint(), aSketchLineB.startPoint())
-    self.myDOF -= 2
+    # coincidences
+    self.mySketch.setCoincident(aSketchLineA.endPoint(), aSketchLineB.startPoint())
+    self.mySketch.setCoincident(aSketchLineB.endPoint(), aSketchLineC.startPoint())
+    self.mySketch.setCoincident(aSketchLineA.startPoint(), aSketchLineC.endPoint())
+    self.myDOF -= 6
     model.do()
     self.checkDOF()
-    # third line to apply Distance constraints
-    aSketchLineC = self.mySketch.addLine(10., 0., 20., 5.)
-    self.myDOF += 4
-    self.mySketch.setDistance(aSketchLineB.startPoint(), aSketchLineC.result(), 10.)
-    self.mySketch.setDistance(aSketchLineB.endPoint(), aSketchLineC.result(), 5.)
+    # other constraints
+    self.mySketch.setHorizontal(aSketchLineA.result())
+    self.mySketch.setVertical(aSketchLineB.result())
     self.myDOF -= 2
     model.do()
     self.checkDOF()
+    # construction point
+    aProjection = self.mySketch.addProjection(model.selection("VERTEX", "Origin"), False)
+    aSketchPoint = SketchAPI_Point(aProjection.createdFeature())
+    model.do()
+    # distances
+    self.mySketch.setLength(aSketchLineA.result(), 50)
+    self.mySketch.setDistance(aSketchLineA.startPoint(), aSketchLineC.startPoint(), 60, True)
+    self.mySketch.setHorizontalDistance(aSketchPoint.coordinates(), aSketchLineA.startPoint(), 20)
+    self.mySketch.setVerticalDistance(aSketchPoint.coordinates(), aSketchLineC.endPoint(), 20)
+    self.myDOF -= 4
+    model.do()
+    self.checkDOF()
+
     self.mySketch.setFillet(aSketchLineA.startPoint())
     self.myDOF += 1
     model.do()
@@ -502,16 +517,20 @@ class TestFilletInteracting(unittest.TestCase):
     self.collectFeatures()
     self.checkNbFeatures("SketchLine", 3)
     self.checkNbFeatures("SketchArc", 1)
-    self.checkNbFeatures("SketchConstraintCoincidence", 2)
+    self.checkNbFeatures("SketchConstraintCoincidence", 6) # Additionally 2 coincidences for apex with fillet objects
+    self.checkNbFeatures("SketchConstraintHorizontal", 1)
+    self.checkNbFeatures("SketchConstraintVertical", 1)
     self.checkNbFeatures("SketchConstraintTangent", 2)
-    self.checkNbFeatures("SketchConstraintDistance", 1) # only one Distance should be left
+    self.checkNbFeatures("SketchConstraintLength", 0) # Length translated to Distance
+    self.checkNbFeatures("SketchConstraintDistance", 2) # Length translated to Distance
+    self.checkNbFeatures("SketchConstraintDistanceHorizontal", 1)
+    self.checkNbFeatures("SketchConstraintDistanceVertical", 1)
     self.checkNbFeatures("SketchFillet", 0)
 
     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.FACE, [0])
     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [4])
     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [8])
 
-  @unittest.expectedFailure
   def test_fillet_with_fixed_point(self):
     """ Test 13. Fillet on two connected lines in case of Fixed constraint applied to the fillet point
     """
@@ -528,7 +547,7 @@ class TestFilletInteracting(unittest.TestCase):
     model.do()
     self.checkDOF()
     self.mySketch.setFillet(aSketchLineA.startPoint())
-    self.myDOF += 1
+    self.myDOF += 3 # Fixed constraint has been removed
     model.do()
     self.checkFillet()
     self.checkDOF()
@@ -545,7 +564,6 @@ class TestFilletInteracting(unittest.TestCase):
     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
 
-  @unittest.expectedFailure
   def test_fillet_with_fixed_line(self):
     """ Test 14. Fillet on two connected lines in case of Fixed constraint applied to one of lines
     """
@@ -579,7 +597,6 @@ class TestFilletInteracting(unittest.TestCase):
     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.EDGE, [3])
     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
 
-  @unittest.expectedFailure
   def test_fillet_with_angle(self):
     """ Test 15. Fillet on two connected lines in case of Perpendicular constraint applied
     """
@@ -614,6 +631,6 @@ class TestFilletInteracting(unittest.TestCase):
     model.testNbSubShapes(self.mySketch, GeomAPI_Shape.VERTEX, [6])
 
 
-# TODO: Remove unittest.expectedFailure if the Tangency in PlaneGCS will be updated
-if __name__ == '__main__':
-  unittest.main()
+if __name__ == "__main__":
+    test_program = unittest.main(exit=False)
+    assert test_program.result.wasSuccessful(), "Test failed"