Salome HOME
Update copyrights
[modules/shaper.git] / src / BuildPlugin / Test / TestEdge.py
index 648aa57d8208189781516ad99aaab76aa62eb8f6..83d163b5ee8294165367bcc39dace57b9495eecf 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
+#
+
 # Initialization of the test
 from ModelAPI import *
 from GeomDataAPI import *
@@ -55,5 +74,70 @@ aSession.finishOperation()
 # Test results
 assert (len(anEdgeFeature.results()) == aNumOfLines)
 
-import model
+# Test edge building on edge of another result
+aSession.startOperation()
+aBox = aPart.addFeature("Box")
+aBox.string("CreationMethod").setValue("BoxByDimensions")
+aBox.real("dx").setValue(50)
+aBox.real("dy").setValue(50)
+aBox.real("dz").setValue(50)
+aSession.finishOperation()
+aBoxResult = aBox.firstResult()
+aBoxShape = aBoxResult.shape()
+
+# Create edges
+aSession.startOperation()
+anEdgeFeature2 = aPart.addFeature("Edge")
+aBaseObjectsList = anEdgeFeature2.selectionList("base_objects")
+aShapeExplorer = GeomAPI_ShapeExplorer(aBoxShape, GeomAPI_Shape.EDGE)
+aShapes = []
+while aShapeExplorer.more():
+    # keep unique shapes only
+    aCurrent = aShapeExplorer.current()
+    isNewShape = True
+    for s in aShapes:
+        if s.isSame(aCurrent):
+            isNewShape = False
+            break
+    if isNewShape:
+        aShapes.append(aCurrent)
+    aShapeExplorer.next()
+
+for s in aShapes:
+    aBaseObjectsList.append(aBoxResult, s)
+aSession.finishOperation()
+
+# Test results
+assert (len(anEdgeFeature2.results()) == 12)
+
+# Check Edge feature failed on incorrect input
+aSession.startOperation()
+anEdgeFeature3 = aPart.addFeature("Edge")
+aBaseObjectsList = anEdgeFeature3.selectionList("base_objects")
+aBaseObjectsList.append(aSketchResult, None)
+aSession.finishOperation()
+assert (len(anEdgeFeature3.results()) == 0)
+
+aSession.startOperation()
+aBaseObjectsList.clear()
+aShapeExplorer = GeomAPI_ShapeExplorer(aBoxShape, GeomAPI_Shape.VERTEX)
+aShape = aShapeExplorer.current()
+aBaseObjectsList.append(aBoxResult, aShape)
+aSession.finishOperation()
+assert (len(anEdgeFeature3.results()) == 0)
+
+aSession.startOperation()
+aBaseObjectsList.clear()
+aShapeExplorer = GeomAPI_ShapeExplorer(aBoxShape, GeomAPI_Shape.FACE)
+aShape = aShapeExplorer.current()
+aBaseObjectsList.append(aBoxResult, aShape)
+aSession.finishOperation()
+assert (len(anEdgeFeature3.results()) == 0)
+
+# remove failed feature
+aSession.startOperation()
+aPart.removeFeature(anEdgeFeature3)
+aSession.finishOperation()
+
+from salome.shaper import model
 assert(model.checkPythonDump())