1 # Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
24 from salome.shaper import model
26 #-----------------------------------------------------------------------------
29 class FeaturesAddExtrusionFixture(unittest.TestCase):
34 partset = model.moduleDocument()
35 self.part = model.addPart(partset).document()
40 assert(model.checkPythonDump())
44 class FeaturesExtrusionFixture(FeaturesAddExtrusionFixture):
47 FeaturesAddExtrusionFixture.setUp(self)
49 sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
50 circle = sketch.addCircle(0, 0, 10)
53 base = sketch.selectFace()
54 self.extrusion = model.addExtrusion(self.part, base, 10, 0)
58 FeaturesAddExtrusionFixture.tearDown(self)
60 #-----------------------------------------------------------------------------
63 class FeaturesAddExtrusionTestCase(FeaturesAddExtrusionFixture):
65 def test_add_extrusion_by_face_and_size(self):
66 sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
67 circle = sketch.addCircle(0, 0, 10)
70 base = sketch.selectFace()
71 extrusion = model.addExtrusion(self.part, base, 10, 0)
74 self.assertEqual(extrusion.creationMethod().value(), "BySizes")
75 self.assertEqual(extrusion.toSize().value(), 10)
76 self.assertEqual(extrusion.fromSize().value(), 0)
77 self.assertEqual(extrusion.toObject().context(), None)
78 self.assertEqual(extrusion.toOffset().isInitialized(), False)
79 self.assertEqual(extrusion.fromObject().context(), None)
80 self.assertEqual(extrusion.fromOffset().isInitialized(), False)
82 def test_add_extrusion_by_face_and_planes(self):
84 base_sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
85 base_circle = base_sketch.addCircle(0, 0, 10)
87 to_plane = model.defaultPlane("XOY")
88 to_plane.origin().setZ(10)
89 to_sketch = model.addSketch(self.part, to_plane)
90 to_circle = to_sketch.addCircle(0, 0, 10)
92 from_plane = model.defaultPlane("XOY")
93 from_plane.origin().setZ(-10)
94 from_sketch = model.addSketch(self.part, from_plane)
95 from_circle = from_sketch.addCircle(0, 0, 10)
99 base = base_sketch.selectFace()
100 to_object = to_sketch.selectFace()[0]
101 from_object = from_sketch.selectFace()[0]
102 extrusion = model.addExtrusion(self.part, base,
106 self.assertEqual(extrusion.creationMethod().value(), "ByPlanesAndOffsets")
107 self.assertEqual(extrusion.toSize().isInitialized(), False)
108 self.assertEqual(extrusion.fromSize().isInitialized(), False)
109 # self.assertEqual(extrusion.getToObject().context(),
110 # to_sketch.result())
111 self.assertEqual(extrusion.toOffset().value(), 15)
112 # self.assertEqual(extrusion.getFromObject().context(),
113 # from_sketch.result())
114 self.assertEqual(extrusion.fromOffset().value(), 20)
117 class FeaturesExtrusionTestCase(FeaturesExtrusionFixture):
119 def test_extrusion_feature_calls(self):
120 # call method of the feature
121 self.assertEqual(self.extrusion.getKind(), "Extrusion")
123 def test_extrusion_get_attribute(self):
124 # call method of the feature
125 self.assertTrue(isinstance(self.extrusion.baseObjects(),
126 ModelAPI.ModelAPI_AttributeSelectionList))
127 self.assertTrue(isinstance(self.extrusion.creationMethod(),
128 ModelAPI.ModelAPI_AttributeString))
129 self.assertTrue(isinstance(self.extrusion.toSize(),
130 ModelAPI.ModelAPI_AttributeDouble))
131 self.assertTrue(isinstance(self.extrusion.fromSize(),
132 ModelAPI.ModelAPI_AttributeDouble))
133 self.assertTrue(isinstance(self.extrusion.toObject(),
134 ModelAPI.ModelAPI_AttributeSelection))
135 self.assertTrue(isinstance(self.extrusion.toOffset(),
136 ModelAPI.ModelAPI_AttributeDouble))
137 self.assertTrue(isinstance(self.extrusion.fromObject(),
138 ModelAPI.ModelAPI_AttributeSelection))
139 self.assertTrue(isinstance(self.extrusion.fromOffset(),
140 ModelAPI.ModelAPI_AttributeDouble))
142 def test_extrusion_set_sizes(self):
143 self.extrusion.setSizes(15, 20)
144 self.assertEqual(self.extrusion.creationMethod().value(), "BySizes")
145 self.assertEqual(self.extrusion.toSize().value(), 15)
146 self.assertEqual(self.extrusion.fromSize().value(), 20)
147 self.assertEqual(self.extrusion.toObject().context(), None)
148 self.assertEqual(self.extrusion.toOffset().isInitialized(), False)
149 self.assertEqual(self.extrusion.fromObject().context(), None)
150 self.assertEqual(self.extrusion.fromOffset().isInitialized(), False)
152 def test_extrusion_set_planes_and_offsets(self):
154 to_plane = model.defaultPlane("XOY")
155 to_plane.origin().setZ(10)
156 to_sketch = model.addSketch(self.part, to_plane)
157 to_circle = to_sketch.addCircle(0, 0, 10)
159 from_plane = model.defaultPlane("XOY")
160 from_plane.origin().setZ(-10)
161 from_sketch = model.addSketch(self.part, from_plane)
162 from_circle = from_sketch.addCircle(0, 0, 10)
166 to_object = to_sketch.selectFace()[0]
167 from_object = from_sketch.selectFace()[0]
169 self.part.moveFeature(self.extrusion.feature(), from_sketch.feature())
171 self.extrusion.setPlanesAndOffsets(to_object, 15, from_object, 20)
174 if __name__ == "__main__":
175 test_program = unittest.main(exit=False)
176 assert test_program.result.wasSuccessful(), "Test failed"