sketch.selectFace(circle.result()),
10, 0)
+ self.assertEqual(extrusion.getCreationMethod(), "BySizes")
+ self.assertEqual(extrusion.getToSize(), 10)
+ self.assertEqual(extrusion.getFromSize(), 0)
+ self.assertEqual(extrusion.getToObject().context(), None)
+ self.assertEqual(extrusion.getToOffset(), 0)
+ self.assertEqual(extrusion.getFromObject().context(), None)
+ self.assertEqual(extrusion.getFromOffset(), 0)
+
def test_add_extrusion_by_face_and_planes(self):
# base
base_sketch = model.addSketch(self.part, model.defaultPlane("XOY"))
to_sketch, 15,
from_sketch, 20)
+ self.assertEqual(extrusion.getCreationMethod(), "ByPlanesAndOffsets")
+ self.assertEqual(extrusion.getToSize(), 0)
+ self.assertEqual(extrusion.getFromSize(), 0)
+# self.assertEqual(extrusion.getToObject().context(),
+# to_sketch.result())
+ self.assertEqual(extrusion.getToOffset(), 15)
+# self.assertEqual(extrusion.getFromObject().context(),
+# from_sketch.result())
+ self.assertEqual(extrusion.getFromOffset(), 20)
+
class FeaturesExtrusionTestCase(FeaturesExtrusionFixture):
# call method of the feature
self.assertEqual(self.extrusion.getKind(), "Extrusion")
+ def test_extrusion_get_attribute(self):
+ # call method of the feature
+ self.assertTrue(isinstance(self.extrusion.getBase(),
+ ModelAPI.ModelAPI_AttributeSelectionList))
+ self.assertTrue(isinstance(self.extrusion.getCreationMethod(),
+ basestring))
+ self.assertTrue(isinstance(self.extrusion.getToSize(), float))
+ self.assertTrue(isinstance(self.extrusion.getFromSize(), float))
+ self.assertTrue(isinstance(self.extrusion.getToObject(),
+ ModelAPI.ModelAPI_AttributeSelection))
+ self.assertTrue(isinstance(self.extrusion.getToOffset(), float))
+ self.assertTrue(isinstance(self.extrusion.getFromObject(),
+ ModelAPI.ModelAPI_AttributeSelection))
+ self.assertTrue(isinstance(self.extrusion.getFromOffset(), float))
+
def test_extrusion_set_sizes(self):
self.extrusion.setSize(15, 20)
+ self.assertEqual(self.extrusion.getCreationMethod(), "BySizes")
+ self.assertEqual(self.extrusion.getToSize(), 15)
+ self.assertEqual(self.extrusion.getFromSize(), 20)
+ self.assertEqual(self.extrusion.getToObject().context(), None)
+ self.assertEqual(self.extrusion.getToOffset(), 0)
+ self.assertEqual(self.extrusion.getFromObject().context(), None)
+ self.assertEqual(self.extrusion.getFromOffset(), 0)
def test_extrusion_set_planes_and_offsets(self):
# base
import ModelAPI
+from .tools import get_value, convert_to_underscore
class Feature(ModelAPI.ModelAPI_Feature):
def __getattr__(self, name):
"""Process missing attributes.
+ Add get*() methods for access feature attributes.
Redirect missing attributes to the feature.
"""
+ if name.startswith("get"):
+ possible_names = [
+ "_" + name[3:],
+ "_" + convert_to_underscore(name[3:]),
+ ]
+ for possible_name in possible_names:
+ if hasattr(self, possible_name):
+ def getter():
+ return get_value(getattr(self, possible_name))
+ return getter
+
return self._feature.__getattribute__(name)
def setRealInput (self, inputid, value):
--- /dev/null
+"""Common tools for other modules.
+Author: Sergey Pokhodenko
+Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+"""
+
+import re
+import ModelAPI
+
+def convert_to_underscore(name):
+ """Convert CamelCase to underscore_case."""
+ s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
+ return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
+
+def get_value(attribute):
+ """Return simple type value from ModelAPI attribute if possible.
+
+ ModelAPI_AttributeDouble -> double
+ ModelAPI_AttributeString -> str
+ """
+ if (isinstance(attribute, ModelAPI.ModelAPI_AttributeDouble) or
+ isinstance(attribute, ModelAPI.ModelAPI_AttributeString)):
+ return attribute.value()
+
+ print type(attribute)
+ return attribute