Salome HOME
Fix for the #1757 with full split of the selected sketch-face.
[modules/shaper.git] / src / SketchPlugin / Test / TestTrimLine02.py
1 ## Copyright (C) 2014-2017  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 from ModelGeomAlgo import ModelGeomAlgo_Point2D
26 from salome.shaper import geom
27 import math
28
29 TOLERANCE = 1.e-7
30
31 SketchLineId = 'SketchLine'
32 SketchConstraintCoincidenceId = 'SketchConstraintCoincidence'
33
34 aSession = ModelAPI_Session.get()
35 model.begin()
36 partSet = model.moduleDocument()
37 Part = model.addPart(partSet)
38 Part_doc = Part.document()
39
40 # Test1:begin split on arc with coincident point and intersection line : smaller part
41 Sketch = model.addSketch(Part_doc, model.defaultPlane("XOZ"))
42 # Test of inverted Arc
43 SketchLine_1 = Sketch.addLine(10, 80, 40, 10)
44 SketchLine_2 = Sketch.addLine(40, 10, 70, 80)
45 SketchLine_3 = Sketch.addLine(70, 80, 100, 10)
46 SketchLine_4 = Sketch.addLine(100, 10, 130, 80)
47
48 SketchLine_intersecting = Sketch.addLine(10, 50, 130, 50)
49
50 SketchConstraintCoincidence_1_1 = Sketch.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
51 SketchConstraintCoincidence_1_2 = Sketch.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
52 SketchConstraintCoincidence_1_3 = Sketch.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint())
53
54 GeomPoint = geom.Pnt2d(40, 50)
55
56 #check number of features before trim
57 Sketch_feature = featureToCompositeFeature(Sketch.feature())
58 idList_before = []
59 for index in range(Sketch_feature.numberOfSubs()):
60   idList_before.append(Sketch_feature.subFeature(index).getKind())
61
62 assert(idList_before.count(SketchLineId) == 5)
63 assert(idList_before.count(SketchConstraintCoincidenceId) == 3)
64
65 #perform trim
66 SketchTrim = Sketch.addTrim(SketchLine_intersecting, GeomPoint)
67 SketchTrim.execute()
68 model.do()
69
70 #check number of features after trim
71 SketchFeatures = featureToCompositeFeature(Sketch.feature())
72 idList_after = []
73
74 LinesList = FeatureList()
75 for SubIndex in range(SketchFeatures.numberOfSubs()):
76     SubFeature = SketchFeatures.subFeature(SubIndex)
77     idList_after.append(SubFeature.getKind())
78     if SubFeature.getKind() == SketchLineId:
79       LinesList.append(SubFeature)
80
81 assert(idList_after.count(SketchLineId) == 6)
82 assert(idList_after.count(SketchConstraintCoincidenceId) == 5)
83
84
85 #check lines intersection to the source line
86 SketchLine_intersecting_1 = Sketch.addLine(15, 55, 15, 40)
87 SketchLine_intersecting_2 = Sketch.addLine(40, 55, 40, 40)
88 SketchLine_intersecting_3 = Sketch.addLine(70, 55, 70, 40)
89 SketchLine_intersecting_4 = Sketch.addLine(100, 55, 100, 40)
90 SketchLine_intersecting_5 = Sketch.addLine(125, 55, 125, 40)
91
92 Intersection_Points_1 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_1.feature(), LinesList)
93 Intersection_Points_2 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_2.feature(), LinesList)
94 Intersection_Points_3 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_3.feature(), LinesList)
95 Intersection_Points_4 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_4.feature(), LinesList)
96 Intersection_Points_5 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_intersecting_5.feature(), LinesList)
97
98 assert(len(Intersection_Points_1) == 1)
99 assert(len(Intersection_Points_2) == 0)
100 assert(len(Intersection_Points_3) == 1)
101 assert(len(Intersection_Points_4) == 1)
102 assert(len(Intersection_Points_5) == 1)
103
104 #check if line points are the same
105
106 model.end()
107
108 assert(model.checkPythonDump())