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