Salome HOME
Merge branch 'V9_2_2_BR'
[modules/shaper.git] / src / SketchPlugin / Test / TestTrimCircle05.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 SketchPointId = 'SketchPoint'
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 SketchPoint_1 = Sketch.addPoint(70, 50)
45 SketchPoint_2 = Sketch.addPoint(30, 50)
46 SketchPoint_3 = Sketch.addPoint(50, 70)
47 SketchPoint_4 = Sketch.addPoint(50, 30)
48
49 #coincidence point to circle
50 SketchConstraintCoincidence_1_1 = Sketch.setCoincident(SketchPoint_1.results()[0], SketchCircle.results()[1])
51 SketchConstraintCoincidence_1_2 = Sketch.setCoincident(SketchPoint_2.results()[0], SketchCircle.results()[1])
52
53 #coincidence circle to point
54 SketchConstraintCoincidence_1_3 = Sketch.setCoincident(SketchCircle.results()[1], SketchPoint_3.results()[0])
55 SketchConstraintCoincidence_1_4 = Sketch.setCoincident(SketchCircle.results()[1], SketchPoint_4.results()[0])
56
57 Sketch_features = featureToCompositeFeature(Sketch.feature())
58 assert (Sketch_features.numberOfSubs() == 9)
59 #intersection points on circle to prepare a trim selection point
60 SketchLine_intersecting = Sketch.addLine(10, 60, 90, 60)
61 Circle_Points = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchCircle.feature(), FeatureList([SketchLine_intersecting.feature()]))
62 assert(len(Circle_Points) == 2)
63 ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting.feature()]))
64 Sketch_features = featureToCompositeFeature(Sketch.feature())
65 assert (Sketch_features.numberOfSubs() == 9)
66
67 assert (len(Circle_Points) == 2)
68 if Circle_Points[0].x() < Circle_Points[1].x():
69   GeomPoint = Circle_Points[0]
70 else:
71   GeomPoint = Circle_Points[1]
72
73 #check number of features before trim
74 Sketch_feature = featureToCompositeFeature(Sketch.feature())
75 idList_before = []
76 for index in range(Sketch_feature.numberOfSubs()):
77   idList_before.append(Sketch_feature.subFeature(index).getKind())
78
79 assert(idList_before.count(SketchCircleId) == 1)
80 assert(idList_before.count(SketchArcId) == 0)
81 assert(idList_before.count(SketchPointId) == 4)
82 assert(idList_before.count(SketchConstraintCoincidenceId) == 4)
83
84 #perform trim
85 SketchTrim = Sketch.addTrim(SketchCircle, Sketch.to2D(GeomPoint))
86 SketchTrim.execute()
87 model.do()
88
89 #check number of features after trim
90 SketchFeatures = featureToCompositeFeature(Sketch.feature())
91 idList_after = []
92 for SubIndex in range(SketchFeatures.numberOfSubs()):
93     SubFeature = SketchFeatures.subFeature(SubIndex)
94     idList_after.append(SubFeature.getKind())
95     if SubFeature.getKind() == SketchArcId:
96       SketchArc = SubFeature
97
98 assert(idList_after.count(SketchCircleId) == 0)
99 assert(idList_after.count(SketchArcId) == 1)
100 assert(idList_after.count(SketchPointId) == 4)
101 assert(idList_after.count(SketchConstraintCoincidenceId) == 4)
102
103
104 #check arc position intersections of created arc to an additional line
105 SketchLine_intersecting_1 = Sketch.addLine(0, 0, 100, 100)
106 SketchLine_intersecting_2 = Sketch.addLine(0, 100, 100, 0)
107
108 Intersection_Points_1 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_1.feature()]))
109 Intersection_Points_2 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_2.feature()]))
110
111 assert(len(Intersection_Points_1) == 2)
112 assert(len(Intersection_Points_2) == 1)
113
114 #add point for check
115 SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y())
116 Intersection_Points_3 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchPoint.feature()]))
117 assert(len(Intersection_Points_3) == 0)
118
119 model.end()
120
121 assert(model.checkPythonDump())