Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / BuildPlugin / Test / TestVertex.py
1 ## Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 ##
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.
7 ##
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.
12 ##
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
16 ##
17 ## See http:##www.salome-platform.org/ or
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 ##
20
21 # Initialization of the test
22 from ModelAPI import *
23 from GeomDataAPI import *
24 from GeomAlgoAPI import *
25 from GeomAPI import *
26
27 import random
28
29 def createPoint(theSketchFeature):
30     aSketchPointFeature = theSketchFeature.addFeature("SketchPoint")
31     aPointCoordinates = geomDataAPI_Point2D(aSketchPointFeature.attribute("PointCoordinates"))
32     aPointCoordinates.setValue(random.uniform(0, 100), random.uniform(0, 100))
33     return aSketchPointFeature
34
35 # Get document
36 aSession = ModelAPI_Session.get()
37 aDocument = aSession.moduleDocument()
38
39 # Create a part
40 aSession.startOperation()
41 aPartFeature = aDocument.addFeature("Part")
42 aSession.finishOperation()
43 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
44 aPart = aPartResult.partDoc()
45
46 # Create a sketch
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)
55
56 # Create points
57 aNumOfPoints = 10
58 aPoints = []
59 for i in range(aNumOfPoints):
60     aSession.startOperation()
61     aSketchPointFeature = createPoint(aSketchFeature)
62     aSession.finishOperation()
63     aPoints.append(aSketchPointFeature.firstResult().shape())
64 aSession.finishOperation()
65 aSketchResult = aSketchFeature.firstResult()
66
67 # Create vertices
68 aSession.startOperation()
69 aVertexFeature = aPart.addFeature("Vertex")
70 aBaseObjectsList = aVertexFeature.selectionList("base_objects")
71
72 for aPoint in aPoints:
73     aBaseObjectsList.append(aSketchResult, aPoint)
74 aSession.finishOperation()
75
76 # Test results
77 assert (len(aVertexFeature.results()) == aNumOfPoints)
78
79 from salome.shaper import model
80 assert(model.checkPythonDump())