Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / SketchPlugin / Test / TestTrimCircle01.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 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 SketchLine = Sketch.addLine(30, 75, 75, 30)
46 SketchLine_intersecting = Sketch.addLine(10, 55, 90, 55)
47 Sketch_features = featureToCompositeFeature(Sketch.feature())
48 assert (Sketch_features.numberOfSubs() == 3)
49
50 Circle_Points = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchCircle.feature(), FeatureList([SketchLine_intersecting.feature()]))
51 assert(len(Circle_Points) == 2)
52
53 ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting.feature()]))
54
55 Sketch_features = featureToCompositeFeature(Sketch.feature())
56 assert (Sketch_features.numberOfSubs() == 2)
57
58 assert (len(Circle_Points) == 2)
59 if Circle_Points[0].x() < Circle_Points[1].x():
60   GeomPoint = Circle_Points[0]
61 else:
62   GeomPoint = Circle_Points[1]
63
64
65 #check number of features before trim
66 Sketch_feature = featureToCompositeFeature(Sketch.feature())
67 idList_before = []
68 for index in range(Sketch_feature.numberOfSubs()):
69   idList_before.append(Sketch_feature.subFeature(index).getKind())
70
71 assert(idList_before.count(SketchCircleId) == 1)
72 assert(idList_before.count(SketchArcId) == 0)
73 assert(idList_before.count(SketchLineId) == 1)
74 assert(idList_before.count(SketchConstraintCoincidenceId) == 0)
75
76 #perform trim
77 SketchTrim = Sketch.addTrim(SketchCircle, Sketch.to2D(GeomPoint))
78 SketchTrim.execute()
79 model.do()
80
81 #check number of features after trim
82 SketchFeatures = featureToCompositeFeature(Sketch.feature())
83 idList_after = []
84 for SubIndex in range(SketchFeatures.numberOfSubs()):
85     SubFeature = SketchFeatures.subFeature(SubIndex)
86     idList_after.append(SubFeature.getKind())
87     if SubFeature.getKind() == SketchArcId:
88       SketchArc = SubFeature
89
90 assert(idList_after.count(SketchCircleId) == 0)
91 assert(idList_after.count(SketchArcId) == 1)
92 assert(idList_after.count(SketchLineId) == 1)
93 assert(idList_after.count(SketchConstraintCoincidenceId) == 2)
94
95
96 #check arc position intersections of created arc to an additional line
97 SketchLine_intersecting_1 = Sketch.addLine(0, 0, 50, 50)
98 SketchLine_intersecting_2 = Sketch.addLine(50, 50, 100, 100)
99
100 Intersection_Points_1 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_1.feature()]))
101 Intersection_Points_2 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchLine_intersecting_2.feature()]))
102
103 assert(len(Intersection_Points_1) == 0)
104 assert(len(Intersection_Points_2) == 1)
105
106 #add point for check
107 SketchPoint = Sketch.addPoint(GeomPoint.x(), GeomPoint.y())
108 Intersection_Points_3 = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchArc, FeatureList([SketchPoint.feature()]))
109 assert(len(Intersection_Points_3) == 0)
110
111 model.end()
112
113 assert(model.checkPythonDump())