1 # Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 # Initialization of the test
21 from ModelAPI import *
22 from GeomDataAPI import *
23 from GeomAlgoAPI import *
28 def createLine(theSketchFeature):
29 aSketchLineFeature = theSketchFeature.addFeature("SketchLine")
30 aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
31 aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
32 aSketchLineStartPoint.setValue(random.uniform(0, 100), random.uniform(0, 100))
33 aSketchLineEndPoint.setValue(random.uniform(0, 100), random.uniform(0, 100))
36 aSession = ModelAPI_Session.get()
37 aDocument = aSession.moduleDocument()
40 aSession.startOperation()
41 aPartFeature = aDocument.addFeature("Part")
42 aSession.finishOperation()
43 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
44 aPart = aPartResult.partDoc()
47 aSession.startOperation()
48 aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
49 anOrigin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
50 anOrigin.setValue(0, 0, 0)
51 aDirX = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
52 aDirX.setValue(1, 0, 0)
53 aNorm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
54 aNorm.setValue(0, 0, 1)
58 for i in range(aNumOfLines):
59 createLine(aSketchFeature)
60 aSession.finishOperation()
61 aSketchResult = aSketchFeature.firstResult()
62 aSketchShape = aSketchResult.shape()
65 aSession.startOperation()
66 anEdgeFeature = aPart.addFeature("Edge")
67 aBaseObjectsList = anEdgeFeature.selectionList("base_objects")
68 aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE)
69 while aShapeExplorer.more():
70 aBaseObjectsList.append(aSketchResult, aShapeExplorer.current())
72 aSession.finishOperation()
75 assert (len(anEdgeFeature.results()) == aNumOfLines)
77 # Test edge building on edge of another result
78 aSession.startOperation()
79 aBox = aPart.addFeature("Box")
80 aBox.string("CreationMethod").setValue("BoxByDimensions")
81 aBox.real("dx").setValue(50)
82 aBox.real("dy").setValue(50)
83 aBox.real("dz").setValue(50)
84 aSession.finishOperation()
85 aBoxResult = aBox.firstResult()
86 aBoxShape = aBoxResult.shape()
89 aSession.startOperation()
90 anEdgeFeature2 = aPart.addFeature("Edge")
91 aBaseObjectsList = anEdgeFeature2.selectionList("base_objects")
92 aShapeExplorer = GeomAPI_ShapeExplorer(aBoxShape, GeomAPI_Shape.EDGE)
94 while aShapeExplorer.more():
95 # keep unique shapes only
96 aCurrent = aShapeExplorer.current()
99 if s.isSame(aCurrent):
103 aShapes.append(aCurrent)
104 aShapeExplorer.next()
107 aBaseObjectsList.append(aBoxResult, s)
108 aSession.finishOperation()
111 assert (len(anEdgeFeature2.results()) == 12)
113 # Check Edge feature failed on incorrect input
114 aSession.startOperation()
115 anEdgeFeature3 = aPart.addFeature("Edge")
116 aBaseObjectsList = anEdgeFeature3.selectionList("base_objects")
117 aBaseObjectsList.append(aSketchResult, None)
118 aSession.finishOperation()
119 assert (len(anEdgeFeature3.results()) == 0)
121 aSession.startOperation()
122 aBaseObjectsList.clear()
123 aShapeExplorer = GeomAPI_ShapeExplorer(aBoxShape, GeomAPI_Shape.VERTEX)
124 aShape = aShapeExplorer.current()
125 aBaseObjectsList.append(aBoxResult, aShape)
126 aSession.finishOperation()
127 assert (len(anEdgeFeature3.results()) == 0)
129 aSession.startOperation()
130 aBaseObjectsList.clear()
131 aShapeExplorer = GeomAPI_ShapeExplorer(aBoxShape, GeomAPI_Shape.FACE)
132 aShape = aShapeExplorer.current()
133 aBaseObjectsList.append(aBoxResult, aShape)
134 aSession.finishOperation()
135 assert (len(anEdgeFeature3.results()) == 0)
137 # remove failed feature
138 aSession.startOperation()
139 aPart.removeFeature(anEdgeFeature3)
140 aSession.finishOperation()
142 from salome.shaper import model
143 assert(model.checkPythonDump())