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