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