Salome HOME
Merge branch 'Pre_2.8.0_development'
[modules/shaper.git] / src / SketchPlugin / Test / TestTrimLine01.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 SketchConstraintCoincidenceId = 'SketchConstraintCoincidence'
33
34 aSession = ModelAPI_Session.get()
35 model.begin()
36 partSet = model.moduleDocument()
37 Part = model.addPart(partSet)
38 Part_doc = Part.document()
39
40 # Test1:begin split on arc with coincident point and intersection line : smaller part
41 Sketch = model.addSketch(Part_doc, model.defaultPlane("XOY"))
42 # Test of inverted Arc
43 SketchLine_1 = Sketch.addLine(200, 20, 20, 70)
44 SketchLine_2 = Sketch.addLine(20, 70, 90, 150)
45 SketchLine_3 = Sketch.addLine(-10, 190, 90, 50)
46
47 SketchLine_intersecting = Sketch.addLine(-30, 85, 50, 85)
48
49 SketchConstraintCoincidence_1_1 = Sketch.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
50 SketchConstraintCoincidence_1_2 = Sketch.setCoincident(SketchLine_1.results()[0], SketchLine_3.endPoint())
51
52 Sketch_features = featureToCompositeFeature(Sketch.feature())
53 assert (Sketch_features.numberOfSubs() == 6)
54
55 Intersection_Point = ModelGeomAlgo_Point2D.getSetOfPntIntersectedShape(SketchLine_2.feature(), FeatureList([SketchLine_intersecting.feature()]))
56 assert(len(Intersection_Point) == 1)
57
58 ModelAPI.removeFeaturesAndReferences(FeatureSet([SketchLine_intersecting.feature()]))
59
60 Sketch_features = featureToCompositeFeature(Sketch.feature())
61 assert (Sketch_features.numberOfSubs() == 5)
62
63 GeomPoint = Intersection_Point[0]
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(SketchLineId) == 3)
72 assert(idList_before.count(SketchConstraintCoincidenceId) == 2)
73
74 #perform trim
75 SketchTrim = Sketch.addTrim(SketchLine_2, Sketch.to2D(GeomPoint))
76 SketchTrim.execute()
77 model.do()
78
79 #check number of features after trim
80 SketchFeatures = featureToCompositeFeature(Sketch.feature())
81 idList_after = []
82 for SubIndex in range(SketchFeatures.numberOfSubs()):
83     SubFeature = SketchFeatures.subFeature(SubIndex)
84     idList_after.append(SubFeature.getKind())
85
86 assert(idList_after.count(SketchLineId) == 3)
87 assert(idList_after.count(SketchConstraintCoincidenceId) == 2)
88
89 model.end()
90
91 assert(model.checkPythonDump())