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