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