Salome HOME
Issue #803: Put all the python modules in the same python package newgeom
[modules/shaper.git] / src / BuildPlugin / Test / TestEdge.py
1 # Initialization of the test
2 from ModelAPI import *
3 from GeomDataAPI import *
4 from GeomAlgoAPI import *
5 from GeomAPI import *
6
7 import random
8
9 def createLine(theSketchFeature):
10     aSketchLineFeature = theSketchFeature.addFeature("SketchLine")
11     aSketchLineStartPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("StartPoint"))
12     aSketchLineEndPoint = geomDataAPI_Point2D(aSketchLineFeature.attribute("EndPoint"))
13     aSketchLineStartPoint.setValue(random.uniform(0, 100), random.uniform(0, 100))
14     aSketchLineEndPoint.setValue(random.uniform(0, 100), random.uniform(0, 100))
15
16 # Get document
17 aSession = ModelAPI_Session.get()
18 aDocument = aSession.moduleDocument()
19
20 # Create a part
21 aSession.startOperation()
22 aPartFeature = aDocument.addFeature("Part")
23 aSession.finishOperation()
24 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
25 aPart = aPartResult.partDoc()
26
27 # Create a sketch
28 aSession.startOperation()
29 aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
30 anOrigin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
31 anOrigin.setValue(0, 0, 0)
32 aDirX = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
33 aDirX.setValue(1, 0, 0)
34 aNorm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
35 aNorm.setValue(0, 0, 1)
36
37 # Create lines
38 aNumOfLines = 10
39 for i in range(aNumOfLines):
40     createLine(aSketchFeature)
41 aSession.finishOperation()
42 aSketchResult = aSketchFeature.firstResult()
43 aSketchShape = aSketchResult.shape()
44
45 # Create edges
46 aSession.startOperation()
47 anEdgeFeature = aPart.addFeature("Edge")
48 aBaseObjectsList = anEdgeFeature.selectionList("base_objects")
49 aShapeExplorer = GeomAPI_ShapeExplorer(aSketchShape, GeomAPI_Shape.EDGE)
50 while aShapeExplorer.more():
51     aBaseObjectsList.append(aSketchResult, aShapeExplorer.current())
52     aShapeExplorer.next()
53 aSession.finishOperation()
54
55 # Test results
56 assert (len(anEdgeFeature.results()) == aNumOfLines)
57
58 from salome.shaper import model
59 assert(model.checkPythonDump())