1 ## Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 ## See http:##www.salome-platform.org/ or
18 ## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
22 TestProjectionIntoResult.py
23 Unit test of SketchPlugin_Projection class
26 from salome.shaper import model
29 #==============================================================================
31 #==============================================================================
33 # Project all features from 'theProjected' list.
34 # Argument 'theFailed' shows indices of projections which should fail because of validator
35 def testProjections(theDocument, theSketch, theProjected, theFailed):
36 # generate list of projected features
39 for type, name in theProjected:
40 proj = theSketch.addProjection(model.selection(type, name), True)
41 assert(bool(proj.feature().error() != '') == bool(ind in theFailed))
42 if proj.feature().error() != '':
43 if proj.createdFeature() is not None:
44 theDocument.removeFeature(proj.createdFeature().feature())
45 theDocument.removeFeature(proj.feature())
51 model.testNbSubShapes(theSketch, GeomAPI_Shape.EDGE, [len(edgeProj)])
53 # exclude some edges from result
57 proj.setIncludeToResult(False)
59 if num >= NB_TO_EXCLUDE:
62 model.testNbSubShapes(theSketch, GeomAPI_Shape.EDGE, [len(edgeProj) - num])
65 #==============================================================================
67 #==============================================================================
69 partSet = model.moduleDocument()
70 Part_1 = model.addPart(partSet)
71 Part_1_doc = Part_1.document()
72 Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
73 SketchCircle_1 = Sketch_1.addCircle(-187.9303398287678, -363.2915373234726, 182.2190183849013)
74 SketchArc_1 = Sketch_1.addArc(-229.9631763073051, -65.7360230979784, -105.4201011859997, -97.06956797196608, -326.3502666769664, 19.13032715412109, False)
75 SketchLine_1 = Sketch_1.addLine(-438.4308780225287, -71.00741660505224, 161.0737545348623, -582.1237015141244)
76 SketchPoint_1 = Sketch_1.addPoint(-446.0706301668712, -312.4620987423343)
78 Sketch_2 = model.addSketch(Part_1_doc, model.defaultPlane("YOZ"))
79 SketchLine_2 = Sketch_2.addLine(27.19276215608871, 61.51157581079401, 72.96621462024476, 0)
80 SketchLine_3 = Sketch_2.addLine(model.selection("EDGE", "PartSet/OZ"))
81 SketchLine_4 = Sketch_2.addLine(model.selection("EDGE", "PartSet/OY"))
82 SketchConstraintCoincidence_1 = Sketch_2.setCoincident(SketchLine_2.endPoint(), SketchLine_4.result())
83 SketchLine_5 = Sketch_2.addLine(72.96621462024476, 0, 0, 0)
84 SketchConstraintCoincidence_2 = Sketch_2.setCoincident(SketchLine_2.endPoint(), SketchLine_5.startPoint())
85 SketchConstraintCoincidence_3 = Sketch_2.setCoincident(SketchLine_3.startPoint(), SketchLine_5.endPoint())
86 SketchLine_6 = Sketch_2.addLine(0, 0, 0, 61.51157581079401)
87 SketchConstraintCoincidence_4 = Sketch_2.setCoincident(SketchLine_3.startPoint(), SketchLine_6.startPoint())
88 SketchConstraintCoincidence_5 = Sketch_2.setCoincident(SketchLine_6.endPoint(), SketchLine_3.result())
89 SketchLine_7 = Sketch_2.addLine(0, 61.51157581079401, 27.19276215608871, 61.51157581079401)
90 SketchConstraintCoincidence_6 = Sketch_2.setCoincident(SketchLine_6.endPoint(), SketchLine_7.startPoint())
91 SketchConstraintCoincidence_7 = Sketch_2.setCoincident(SketchLine_2.startPoint(), SketchLine_7.endPoint())
92 SketchConstraintHorizontal_1 = Sketch_2.setHorizontal(SketchLine_7.result())
94 Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("FACE", "Sketch_2/Face-SketchLine_7r-SketchLine_6r-SketchLine_5r-SketchLine_2r")], model.selection(), 100, 0)
97 #==============================================================================
99 #==============================================================================
101 aProjectedList = [("EDGE", "Sketch_1/SketchCircle_1_2"),
102 ("EDGE", "Sketch_1/SketchArc_1_2"),
103 ("EDGE", "Sketch_1/SketchLine_1"),
104 ("VERTEX", "Sketch_1/SketchPoint_1"),
106 ("VERTEX", "Sketch_1/SketchCircle_1_2__cc"),
107 ("VERTEX", "Sketch_1/SketchLine_1_EndVertex"),
108 ("VERTEX", "Sketch_1/SketchLine_1_StartVertex"),
109 ("VERTEX", "Sketch_1/SketchArc_1_2_StartVertex"),
110 ("VERTEX", "Sketch_1/SketchArc_1_2_EndVertex"),
111 ("VERTEX", "Sketch_1/SketchArc_1"),
113 ("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_5][Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_2][Extrusion_1_1/From_Face]"),
114 ("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_6][Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_5][Extrusion_1_1/From_Face]"),
115 ("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_7][Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_6][Extrusion_1_1/From_Face]"),
116 ("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_7][Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_2][Extrusion_1_1/From_Face]"),
117 ("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_5][Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_2][Extrusion_1_1/To_Face]"),
118 ("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_7][Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_2][Extrusion_1_1/To_Face]"),
119 ("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_7][Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_6][Extrusion_1_1/To_Face]"),
120 ("VERTEX", "[Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_6][Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_5][Extrusion_1_1/To_Face]"),
122 ("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_5][Extrusion_1_1/From_Face]"),
123 ("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_2][Extrusion_1_1/From_Face]"),
124 ("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_7][Extrusion_1_1/From_Face]"),
125 ("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_6][Extrusion_1_1/From_Face]"),
127 ("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_6][Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_5]"),
128 ("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_5][Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_2]"),
129 ("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_7][Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_2]"),
130 ("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_7][Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_6]"),
132 ("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_5][Extrusion_1_1/To_Face]"),
133 ("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_2][Extrusion_1_1/To_Face]"),
134 ("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_7][Extrusion_1_1/To_Face]"),
135 ("EDGE", "[Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_6][Extrusion_1_1/To_Face]")
138 # Test projection to the same plane
139 Sketch_3 = model.addSketch(Part_1_doc, model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_5"))
140 aFailedIDs = set([21, 29])
141 testProjections(Part_1_doc, Sketch_3, aProjectedList, aFailedIDs)
143 # Test projection to parallel plane
144 Sketch_4 = model.addSketch(Part_1_doc, model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_7"))
145 testProjections(Part_1_doc, Sketch_4, aProjectedList, aFailedIDs)
147 # Test projection to lower base of the prism
148 Sketch_5 = model.addSketch(Part_1_doc, model.selection("FACE", "Extrusion_1_1/From_Face"))
149 aFailedIDs = set([0, 1, 22, 23, 24, 25])
150 testProjections(Part_1_doc, Sketch_5, aProjectedList, aFailedIDs)
152 # Test projection to upper base of the prism
153 Sketch_6 = model.addSketch(Part_1_doc, model.selection("FACE", "Extrusion_1_1/To_Face"))
154 testProjections(Part_1_doc, Sketch_6, aProjectedList, aFailedIDs)
156 # Test projection to orthogonal side face of the prism
157 Sketch_7 = model.addSketch(Part_1_doc, model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_6"))
158 aFailedIDs = set([0, 1, 18, 20, 26, 28])
159 testProjections(Part_1_doc, Sketch_7, aProjectedList, aFailedIDs)
161 # Test projection to slope side face of the prism
162 Sketch_8 = model.addSketch(Part_1_doc, model.selection("FACE", "Extrusion_1_1/Generated_Face&Sketch_2/SketchLine_2"))
163 aFailedIDs = set([0, 1])
164 testProjections(Part_1_doc, Sketch_8, aProjectedList, aFailedIDs)