]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/Test/TestTrimPreview.py
Salome HOME
[Code coverage SketchPlugin]: Increase coverage for Distance, Trim and Split 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 assert(featureToPresentation(aTrim).getAISObject(None) is not None)
54 aSession.finishOperation()
55
56 model.testNbSubFeatures(Sketch, "SketchArc", 0)
57 model.testNbSubFeatures(Sketch, "SketchCircle", 1)
58 model.testNbSubFeatures(Sketch, "SketchLine", 4)
59 model.testNbSubFeatures(Sketch, "SketchConstraintCoincidence", 2)
60
61 # Create Trim feature for a circle to perform its substitution by an arc
62 aSession.startOperation()
63 aTrim = aSketchFeature.addFeature("SketchTrim")
64 aSelectedObj = aTrim.reference("SelectedObject")
65 aSelectedObj.setValue(SketchCircle_1.feature())
66 aSelectedPoint = geomDataAPI_Point2D(aTrim.attribute("SelectedPoint"))
67 aSelectedPoint.setValue(50, 0)
68 aPreviewObj = aTrim.reference("PreviewObject")
69 aPreviewObj.setValue(SketchCircle_1.feature())
70 aPreviewPoint = geomDataAPI_Point2D(aTrim.attribute("PreviewPoint"))
71 aPreviewPoint.setValue(aSelectedPoint.pnt())
72 assert(featureToPresentation(aTrim).getAISObject(None) is not None)
73 aSession.finishOperation()
74
75 model.testNbSubFeatures(Sketch, "SketchArc", 1)
76 model.testNbSubFeatures(Sketch, "SketchCircle", 0)
77 model.testNbSubFeatures(Sketch, "SketchLine", 4)
78 model.testNbSubFeatures(Sketch, "SketchConstraintCoincidence", 4)