Salome HOME
Copyright update 2022
[modules/shaper.git] / src / SketchPlugin / Test / TestTrimPreview.py
1 # Copyright (C) 2018-2022  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 model.do()
39 model.end()
40
41 aSession = ModelAPI_Session.get()
42 aSketchFeature = featureToCompositeFeature(Sketch.feature())
43
44 # Create Trim feature for a line
45 aSession.startOperation()
46 aTrim = aSketchFeature.addFeature("SketchTrim")
47 aSelectedObj = aTrim.reference("SelectedObject")
48 aSelectedObj.setValue(SketchLine_1.feature())
49 aSelectedPoint = geomDataAPI_Point2D(aTrim.attribute("SelectedPoint"))
50 aSelectedPoint.setValue(50, 20)
51 aPreviewObj = aTrim.reference("PreviewObject")
52 aPreviewObj.setValue(SketchLine_1.feature())
53 aPreviewPoint = geomDataAPI_Point2D(aTrim.attribute("PreviewPoint"))
54 aPreviewPoint.setValue(aSelectedPoint.pnt())
55 assert(featureToPresentation(aTrim).getAISObject(None) is not None)
56 aSession.finishOperation()
57
58 model.testNbSubFeatures(Sketch, "SketchArc", 0)
59 model.testNbSubFeatures(Sketch, "SketchCircle", 1)
60 model.testNbSubFeatures(Sketch, "SketchLine", 4)
61 model.testNbSubFeatures(Sketch, "SketchConstraintCoincidence", 2)
62
63 # Create Trim feature for a circle to perform its substitution by an arc
64 aSession.startOperation()
65 aTrim = aSketchFeature.addFeature("SketchTrim")
66 aSelectedObj = aTrim.reference("SelectedObject")
67 aSelectedObj.setValue(SketchCircle_1.feature())
68 aSelectedPoint = geomDataAPI_Point2D(aTrim.attribute("SelectedPoint"))
69 aSelectedPoint.setValue(50, 0)
70 aPreviewObj = aTrim.reference("PreviewObject")
71 aPreviewObj.setValue(SketchCircle_1.feature())
72 aPreviewPoint = geomDataAPI_Point2D(aTrim.attribute("PreviewPoint"))
73 aPreviewPoint.setValue(aSelectedPoint.pnt())
74 assert(featureToPresentation(aTrim).getAISObject(None) is not None)
75 aSession.finishOperation()
76
77 model.testNbSubFeatures(Sketch, "SketchArc", 1)
78 model.testNbSubFeatures(Sketch, "SketchCircle", 0)
79 model.testNbSubFeatures(Sketch, "SketchLine", 4)
80 model.testNbSubFeatures(Sketch, "SketchConstraintCoincidence", 4)