Salome HOME
Update copyrights
[modules/shaper.git] / src / SketchPlugin / Test / TestTrimArc01.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 SketchArcId = 'SketchArc'
32 SketchConstraintCoincidenceId = 'SketchConstraintCoincidence'
33 SketchConstraintEqualId = 'SketchConstraintEqual'
34
35 aSession = ModelAPI_Session.get()
36 model.begin()
37 partSet = model.moduleDocument()
38 Part = model.addPart(partSet)
39 Part_doc = Part.document()
40
41 # Test1:begin split on arc with coincident point and intersection line : smaller part
42 Sketch = model.addSketch(Part_doc, model.defaultPlane("XOY"))
43 SketchArc = Sketch.addArc(50, 50, 30, 50, 50, 70, False)
44 SketchLine = Sketch.addLine(32, 20, 82, 70)
45 SketchLine_intersecting = Sketch.addLine(10, 40, 90, 40)
46 Sketch_features = featureToCompositeFeature(Sketch.feature())
47 assert (Sketch_features.numberOfSubs() == 3)
48
49 Arc_Points = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc.feature(), FeatureList([SketchLine_intersecting.feature()]))
50 assert(len(Arc_Points) == 2)
51
52 ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting.feature()]))
53
54 Sketch_features = featureToCompositeFeature(Sketch.feature())
55 assert (Sketch_features.numberOfSubs() == 2)
56
57 assert (len(Arc_Points) == 2)
58 if Arc_Points[0].x() < Arc_Points[1].x():
59   GeomPoint = Arc_Points[0]
60 else:
61   GeomPoint = Arc_Points[1]
62
63 #check number of features before trim
64 Sketch_feature = featureToCompositeFeature(Sketch.feature())
65 idList_before = []
66 for index in range(Sketch_feature.numberOfSubs()):
67   idList_before.append(Sketch_feature.subFeature(index).getKind())
68
69 assert(idList_before.count(SketchArcId) == 1)
70 assert(idList_before.count(SketchLineId) == 1)
71 assert(idList_before.count(SketchConstraintCoincidenceId) == 0)
72
73 #perform trim
74 SketchTrim = Sketch.addTrim(SketchArc, Sketch.to2D(GeomPoint))
75 SketchTrim.execute()
76 model.do()
77
78 #check number of features after trim
79 SketchFeatures = featureToCompositeFeature(Sketch.feature())
80 idList_after = []
81 for SubIndex in range(SketchFeatures.numberOfSubs()):
82     SubFeature = SketchFeatures.subFeature(SubIndex)
83     idList_after.append(SubFeature.getKind())
84     if SubFeature.getKind() == SketchArcId:
85       SketchArc = SubFeature
86
87 assert(idList_after.count(SketchArcId) == 1)
88 assert(idList_after.count(SketchLineId) == 1)
89 assert(idList_after.count(SketchConstraintCoincidenceId) == 1)
90
91
92 #check arc position intersections of created arc to an additional line
93 SketchLine_intersecting_1 = Sketch.addLine(50, 50, 25, 25)
94 SketchLine_intersecting_2 = Sketch.addLine(50, 50, 75, 25)
95 SketchLine_intersecting_3 = Sketch.addLine(50, 50, 75, 75)
96 SketchLine_intersecting_4 = Sketch.addLine(50, 50, 25, 75)
97
98 Intersection_Points_1 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_1.feature()]))
99 Intersection_Points_2 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_2.feature()]))
100 Intersection_Points_3 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_3.feature()]))
101 Intersection_Points_4 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_4.feature()]))
102
103 assert(len(Intersection_Points_1) == 0)
104 assert(len(Intersection_Points_2) == 1)
105 assert(len(Intersection_Points_3) == 1)
106 assert(len(Intersection_Points_4) == 0)
107
108 #add point for check
109 SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y())
110 Intersection_Points_5 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchPoint.feature()]))
111 assert(len(Intersection_Points_5) == 0)
112
113 model.end()
114
115 assert(model.checkPythonDump())