]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/Test/TestTrimPreview.py
Salome HOME
[Code coverage SketchPlugin]: Increase coverage of Arc, Split and Trim features
[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 # 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 model.do()
37 model.end()
38
39 aSession = ModelAPI_Session.get()
40 aSketchFeature = featureToCompositeFeature(Sketch.feature())
41
42 # Create Trim feature for a line
43 aSession.startOperation()
44 aTrim = aSketchFeature.addFeature("SketchTrim")
45 aSelectedObj = aTrim.reference("SelectedObject")
46 aSelectedObj.setValue(SketchLine_1.feature())
47 aSelectedPoint = geomDataAPI_Point2D(aTrim.attribute("SelectedPoint"))
48 aSelectedPoint.setValue(50, 20)
49 aPreviewObj = aTrim.reference("PreviewObject")
50 aPreviewObj.setValue(SketchLine_1.feature())
51 aPreviewPoint = geomDataAPI_Point2D(aTrim.attribute("PreviewPoint"))
52 aPreviewPoint.setValue(aSelectedPoint.pnt())
53 aSession.finishOperation()
54
55 model.testNbSubFeatures(Sketch, "SketchArc", 0)
56 model.testNbSubFeatures(Sketch, "SketchCircle", 1)
57 model.testNbSubFeatures(Sketch, "SketchLine", 4)
58 model.testNbSubFeatures(Sketch, "SketchConstraintCoincidence", 2)
59
60 # Create Trim feature for a circle to perform its substitution by an arc
61 aSession.startOperation()
62 aTrim = aSketchFeature.addFeature("SketchTrim")
63 aSelectedObj = aTrim.reference("SelectedObject")
64 aSelectedObj.setValue(SketchCircle_1.feature())
65 aSelectedPoint = geomDataAPI_Point2D(aTrim.attribute("SelectedPoint"))
66 aSelectedPoint.setValue(50, 0)
67 aPreviewObj = aTrim.reference("PreviewObject")
68 aPreviewObj.setValue(SketchCircle_1.feature())
69 aPreviewPoint = geomDataAPI_Point2D(aTrim.attribute("PreviewPoint"))
70 aPreviewPoint.setValue(aSelectedPoint.pnt())
71 aSession.finishOperation()
72
73 model.testNbSubFeatures(Sketch, "SketchArc", 1)
74 model.testNbSubFeatures(Sketch, "SketchCircle", 0)
75 model.testNbSubFeatures(Sketch, "SketchLine", 4)
76 model.testNbSubFeatures(Sketch, "SketchConstraintCoincidence", 4)