Salome HOME
Update copyrights
[modules/shaper.git] / src / BuildPlugin / Test / TestVertex.py
1 # Copyright (C) 2014-2019  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 email : webmaster.salome@opencascade.com
18 #
19
20 # Initialization of the test
21 from ModelAPI import *
22 from GeomDataAPI import *
23 from GeomAlgoAPI import *
24 from GeomAPI import *
25
26 import random
27
28 def createPoint(theSketchFeature):
29     aSketchPointFeature = theSketchFeature.addFeature("SketchPoint")
30     aPointCoordinates = geomDataAPI_Point2D(aSketchPointFeature.attribute("PointCoordinates"))
31     aPointCoordinates.setValue(random.uniform(0, 100), random.uniform(0, 100))
32     return aSketchPointFeature
33
34 # Get document
35 aSession = ModelAPI_Session.get()
36 aDocument = aSession.moduleDocument()
37
38 # Create a part
39 aSession.startOperation()
40 aPartFeature = aDocument.addFeature("Part")
41 aSession.finishOperation()
42 aPartResult = modelAPI_ResultPart(aPartFeature.firstResult())
43 aPart = aPartResult.partDoc()
44
45 # Create a sketch
46 aSession.startOperation()
47 aSketchFeature = featureToCompositeFeature(aPart.addFeature("Sketch"))
48 anOrigin = geomDataAPI_Point(aSketchFeature.attribute("Origin"))
49 anOrigin.setValue(0, 0, 0)
50 aDirX = geomDataAPI_Dir(aSketchFeature.attribute("DirX"))
51 aDirX.setValue(1, 0, 0)
52 aNorm = geomDataAPI_Dir(aSketchFeature.attribute("Norm"))
53 aNorm.setValue(0, 0, 1)
54
55 # Create points
56 aNumOfPoints = 10
57 aPoints = []
58 for i in range(aNumOfPoints):
59     aSession.startOperation()
60     aSketchPointFeature = createPoint(aSketchFeature)
61     aSession.finishOperation()
62     aPoints.append(aSketchPointFeature.firstResult().shape())
63 aSession.finishOperation()
64 aSketchResult = aSketchFeature.firstResult()
65
66 # Create vertices
67 aSession.startOperation()
68 aVertexFeature = aPart.addFeature("Vertex")
69 aBaseObjectsList = aVertexFeature.selectionList("base_objects")
70
71 for aPoint in aPoints:
72     aBaseObjectsList.append(aSketchResult, aPoint)
73 aSession.finishOperation()
74
75 # Test results
76 assert (len(aVertexFeature.results()) == aNumOfPoints)
77
78 # Check Vertex feature failed on incorrect input
79 aSession.startOperation()
80 aVertexFeature2 = aPart.addFeature("Vertex")
81 aBaseObjectsList = aVertexFeature2.selectionList("base_objects")
82 aBaseObjectsList.append(aSketchResult, None)
83 aSession.finishOperation()
84 assert (len(aVertexFeature2.results()) == 0)
85
86 aSession.startOperation()
87 aLine = aSketchFeature.addFeature("SketchLine")
88 geomDataAPI_Point2D(aLine.attribute("StartPoint")).setValue(0, 0)
89 geomDataAPI_Point2D(aLine.attribute("EndPoint")).setValue(100, 100)
90 aSession.finishOperation()
91 aSession.startOperation()
92 aBaseObjectsList.clear()
93 aBaseObjectsList.append(aSketchResult, aLine.lastResult().shape())
94 aSession.finishOperation()
95 assert (len(aVertexFeature2.results()) == 0)
96
97 # remove failed feature
98 aSession.startOperation()
99 aPart.removeFeature(aVertexFeature2)
100 aPart.setCurrentFeature(aVertexFeature, True)
101 aSession.finishOperation()
102
103 from salome.shaper import model
104 assert(model.checkPythonDump())