]> SALOME platform Git repositories - modules/shaper.git/blob - src/BuildPlugin/Test/TestVertex.py
Salome HOME
Tests for Build plug-in features.
[modules/shaper.git] / src / BuildPlugin / Test / TestVertex.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 createPoint(theSketchFeature):
10     aSketchPointFeature = theSketchFeature.addFeature("SketchPoint")
11     aPointCoordindates = geomDataAPI_Point2D(aSketchPointFeature.attribute("PointCoordindates"))
12     aPointCoordindates.setValue(random.uniform(0, 100), random.uniform(0, 100))
13     return aSketchPointFeature
14
15 # Get document
16 aSession = ModelAPI_Session.get()
17 aDocument = aSession.moduleDocument()
18
19 # Create a part
20 aSession.startOperation()
21 aPartFeature = aDocument.addFeature("Part")
22 aSession.finishOperation()
23 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
24 aPart = aPartResult.partDoc()
25
26 # Create a sketch
27 aSession.startOperation()
28 aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
29 anOrigin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
30 anOrigin.setValue(0, 0, 0)
31 aDirX = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
32 aDirX.setValue(1, 0, 0)
33 aNorm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
34 aNorm.setValue(0, 0, 1)
35
36 # Create points
37 aNumOfPoints = 10
38 aPoints = []
39 for i in range(aNumOfPoints):
40     aSession.startOperation()
41     aSketchPointFeature = createPoint(aSketchFeature)
42     aSession.finishOperation()
43     aPoints.append(aSketchPointFeature.firstResult().shape())
44 aSession.finishOperation()
45 aSketchResult = aSketchFeature.firstResult()
46
47 # Create vertices
48 aSession.startOperation()
49 aVertexFeature = aPart.addFeature("Vertex")
50 aBaseObjectsList = aVertexFeature.selectionList("base_objects")
51
52 for aPoint in aPoints:
53     aBaseObjectsList.append(aSketchResult, aPoint)
54 aSession.finishOperation()
55
56 # Test results
57 assert (len(aVertexFeature.results()) == aNumOfPoints)