Salome HOME
Copyright update 2022
[modules/shaper.git] / src / SketchPlugin / Test / TestTrimCircle03.py
1 # Copyright (C) 2014-2022  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 SketchCircleId = 'SketchCircle'
33 SketchConstraintCoincidenceId = 'SketchConstraintCoincidence'
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 circle with coincident point and intersection line : smaller part
42 Sketch = model.addSketch(Part_doc, model.defaultPlane("XOY"))
43 SketchCircle = Sketch.addCircle(50, 50, 20)
44 SketchLine_1 = Sketch.addLine(70, 50, 80, 80)
45 SketchLine_2 = Sketch.addLine(80, 80, 50, 70)
46
47 SketchConstraintCoincidence_1_1 = Sketch.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
48 SketchConstraintCoincidence_1_2 = Sketch.setCoincident(SketchLine_1.startPoint(), SketchCircle.results()[1])
49 SketchConstraintCoincidence_1_3 = Sketch.setCoincident(SketchLine_2.endPoint(), SketchCircle.results()[1])
50
51
52 Sketch_features = featureToCompositeFeature(Sketch.feature())
53 assert (Sketch_features.numberOfSubs() == 6)
54 #intersection points on circle to prepare a trim selection point
55 SketchLine_intersecting = Sketch.addLine(10, 60, 90, 60)
56 Circle_Points = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchCircle.feature(), FeatureList([SketchLine_intersecting.feature()]))
57 assert(len(Circle_Points) == 2)
58 ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting.feature()]))
59 Sketch_features = featureToCompositeFeature(Sketch.feature())
60 assert (Sketch_features.numberOfSubs() == 6)
61
62 assert (len(Circle_Points) == 2)
63 if Circle_Points[0].x() < Circle_Points[1].x():
64   GeomPoint = Circle_Points[0]
65 else:
66   GeomPoint = Circle_Points[1]
67
68 #check number of features before trim
69 Sketch_feature = featureToCompositeFeature(Sketch.feature())
70 idList_before = []
71 for index in range(Sketch_feature.numberOfSubs()):
72   idList_before.append(Sketch_feature.subFeature(index).getKind())
73
74 assert(idList_before.count(SketchCircleId) == 1)
75 assert(idList_before.count(SketchArcId) == 0)
76 assert(idList_before.count(SketchLineId) == 2)
77 assert(idList_before.count(SketchConstraintCoincidenceId) == 3)
78
79 #perform trim
80 SketchTrim = Sketch.addTrim(SketchCircle, Sketch.to2D(GeomPoint))
81 SketchTrim.execute()
82 model.do()
83
84 #check number of features after trim
85 SketchFeatures = featureToCompositeFeature(Sketch.feature())
86 idList_after = []
87 for SubIndex in range(SketchFeatures.numberOfSubs()):
88     SubFeature = SketchFeatures.subFeature(SubIndex)
89     idList_after.append(SubFeature.getKind())
90     if SubFeature.getKind() == SketchArcId:
91       SketchArc = SubFeature
92
93 assert(idList_after.count(SketchCircleId) == 0)
94 assert(idList_after.count(SketchArcId) == 1)
95 assert(idList_after.count(SketchLineId) == 2)
96 assert(idList_after.count(SketchConstraintCoincidenceId) == 3)
97
98
99 #check arc position intersections of created arc to an additional line
100 SketchLine_intersecting_1 = Sketch.addLine(0, 0, 50, 50)
101 SketchLine_intersecting_2 = Sketch.addLine(50, 50, 100, 100)
102
103 Intersection_Points_1 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_1.feature()]))
104 Intersection_Points_2 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_2.feature()]))
105
106 assert(len(Intersection_Points_1) == 0)
107 assert(len(Intersection_Points_2) == 1)
108
109 #add point for check
110 SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y())
111 Intersection_Points_3 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchPoint.feature()]))
112 assert(len(Intersection_Points_3) == 0)
113
114 model.end()
115
116 assert(model.checkPythonDump())