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