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