Salome HOME
c4bb13798441639e4ecd4b0799a8e88a09beea4b
[modules/shaper.git] / src / SketchPlugin / Test / TestSplitPreview.py
1 ## Copyright (C) 2018-20xx  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 from salome.shaper import model
22
23 from ModelAPI import *
24 from GeomDataAPI import *
25
26 # base sketch
27 model.begin()
28 partSet = model.moduleDocument()
29 Part = model.addPart(partSet)
30 Part_doc = Part.document()
31 Sketch = model.addSketch(Part_doc, model.defaultPlane("XOY"))
32 SketchLine_1 = Sketch.addLine(0, 20, 100, 20)
33 SketchLine_2 = Sketch.addLine(20, 0, 20, 40)
34 SketchLine_3 = Sketch.addLine(80, 0, 80, 40)
35 SketchCircle_1 = Sketch.addCircle(50, 50, 50)
36 SketchPoint_1 = Sketch.addPoint(20, 20)
37 SketchConstraintCoincidence_1 = Sketch.setCoincident(SketchPoint_1.coordinates(), SketchLine_2.result())
38 SketchConstraintCoincidence_2 = Sketch.setCoincident(SketchPoint_1.coordinates(), SketchLine_1.result())
39 SketchPoint_2 = Sketch.addPoint(80, 20)
40 SketchConstraintCoincidence_3 = Sketch.setCoincident(SketchPoint_2.coordinates(), SketchLine_1.result())
41 SketchConstraintCoincidence_4 = Sketch.setCoincident(SketchPoint_2.coordinates(), SketchLine_3.result())
42 SketchPoint_3 = Sketch.addPoint(20, 10)
43 SketchConstraintCoincidence_5 = Sketch.setCoincident(SketchPoint_3.coordinates(), SketchCircle_1.results()[1])
44 SketchConstraintCoincidence_6 = Sketch.setCoincident(SketchPoint_3.coordinates(), SketchLine_2.result())
45 SketchPoint_4 = Sketch.addPoint(80, 10)
46 SketchConstraintCoincidence_7 = Sketch.setCoincident(SketchPoint_4.coordinates(), SketchCircle_1.results()[1])
47 SketchConstraintCoincidence_8 = Sketch.setCoincident(SketchPoint_4.coordinates(), SketchLine_3.result())
48 model.do()
49 model.end()
50
51 aSession = ModelAPI_Session.get()
52 aSketchFeature = featureToCompositeFeature(Sketch.feature())
53
54 # Create Split feature for a line
55 aSession.startOperation()
56 aSplit = aSketchFeature.addFeature("SketchSplit")
57 aSelectedObj = aSplit.reference("SelectedObject")
58 aSelectedObj.setValue(SketchLine_1.feature())
59 aSelectedPoint = geomDataAPI_Point2D(aSplit.attribute("SelectedPoint"))
60 aSelectedPoint.setValue(50, 20)
61 aPreviewObj = aSplit.reference("PreviewObject")
62 aPreviewObj.setValue(SketchLine_1.feature())
63 aPreviewPoint = geomDataAPI_Point2D(aSplit.attribute("PreviewPoint"))
64 aPreviewPoint.setValue(aSelectedPoint.pnt())
65 assert(featureToPresentation(aSplit).getAISObject(None) is not None)
66 aSession.finishOperation()
67
68 model.testNbSubFeatures(Sketch, "SketchArc", 0)
69 model.testNbSubFeatures(Sketch, "SketchCircle", 1)
70 model.testNbSubFeatures(Sketch, "SketchLine", 5)
71 model.testNbSubFeatures(Sketch, "SketchConstraintCoincidence", 12)
72
73 # Create Split feature for a circle to perform its substitution by an arc
74 aSession.startOperation()
75 aSplit = aSketchFeature.addFeature("SketchSplit")
76 aSelectedObj = aSplit.reference("SelectedObject")
77 aSelectedObj.setValue(SketchCircle_1.feature())
78 aSelectedPoint = geomDataAPI_Point2D(aSplit.attribute("SelectedPoint"))
79 aSelectedPoint.setValue(50, 0)
80 aPreviewObj = aSplit.reference("PreviewObject")
81 aPreviewObj.setValue(SketchCircle_1.feature())
82 aPreviewPoint = geomDataAPI_Point2D(aSplit.attribute("PreviewPoint"))
83 aPreviewPoint.setValue(aSelectedPoint.pnt())
84 assert(featureToPresentation(aSplit).getAISObject(None) is not None)
85 aSession.finishOperation()
86
87 model.testNbSubFeatures(Sketch, "SketchArc", 2)
88 model.testNbSubFeatures(Sketch, "SketchCircle", 0)
89 model.testNbSubFeatures(Sketch, "SketchLine", 5)
90 model.testNbSubFeatures(Sketch, "SketchConstraintCoincidence", 16)