Salome HOME
Fix compilation error on Linux. Part III.
[modules/shaper.git] / src / PythonAPI / model / roots.py
index b1e392855533b3c43950f6ad0042f9e876d11a60..5f1c294bf13214e7acae6202a80d53cbca385f4e 100644 (file)
@@ -5,23 +5,27 @@ Copyright (C) 2014-20xx CEA/DEN, EDF R&D
 
 import ModelAPI
 
-from .tools import get_value, convert_to_underscore
+from model import tools
 
 
 class Feature(ModelAPI.ModelAPI_Feature):
     """Base class of user-defined Python features."""
 
     def __init__(self):
+        """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
         ModelAPI.ModelAPI_Feature.__init__(self)
 
-    def addRealInput (self, inputid):
+    def addRealInput(self, inputid):
+        """F.addRealInput(str) -- add real attribute"""
         self.data().addAttribute(inputid,
                                  ModelAPI.ModelAPI_AttributeDouble_typeId())
 
-    def getRealInput (self, inputid):
+    def getRealInput(self, inputid):
+        """F.getRealInput(str) -- get real value of the attribute"""
         return self.data().real(inputid).value()
 
-    def addResult (self, result):
+    def addResult(self, result):
+        """F.addResult(ModelAPI_Result) -- add ModelAPI_Result shape as a result"""
         shape = result.shape()
         body = self.document().createBody(self.data())
         body.store(shape)
@@ -32,21 +36,18 @@ class Interface():
     """Base class of high level Python interfaces to features."""
 
     def __init__(self, feature):
+        """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
         self._feature = feature
-        self._attribute_white_list = [
-            "getKind",
-            ]
 
     def __getattr__(self, name):
         """Process missing attributes.
 
         Add get*() methods for access feature attributes.
-        Redirect some missing attributes to the feature.
         """
         if name.startswith("get"):
             possible_names = [
                 "_" + name[3:],
-                "_" + convert_to_underscore(name[3:]),
+                "_" + tools.convert_to_underscore(name[3:]),
                 ]
             for possible_name in possible_names:
                 if hasattr(self, possible_name):
@@ -54,21 +55,49 @@ class Interface():
                         return getattr(self, possible_name)
                     return getter
 
-        if name in self._attribute_white_list:
-            return getattr(self._feature, name)
+        raise AttributeError()
 
-        return object.__getattribute__(self, name)
+    def _fillAttribute(self, attribute, value):
+        """Fill ModelAPI_Attribute* with value."""
+        tools.fill_attribute(attribute, value)
 
     def feature(self):
         """Return ModelAPI_Feature."""
         return self._feature
 
+    def getKind(self):
+        """Return the unique kind of the feature"""
+        return self._feature.getKind()
+
+    def results(self):
+        """Return current results of the feature"""
+        return self._feature.results()
+
+    def firstResult(self):
+        """Return the first result in the list of results"""
+        return self._feature.firstResult()
+
+    def lastResult(self):
+        """Return the last result in the list of results"""
+        return self._feature.lastResult()
+
     def setRealInput(self, inputid, value):
+        """I.setRealInput(str, float) -- set real value to the attribute"""
         self._feature.data().real(inputid).setValue(value)
 
     def areInputValid(self):
+        """I.areInputValid() -> True or False validation result"""
         validators = ModelAPI.ModelAPI_Session.get().validators()
         return validators.validate(self._feature)
 
     def execute(self):
-        self._feature.execute()
+        """I.execute() -- validate and execute the feature.
+
+        Raises RuntimeError if validation fails.
+        """
+        if self.areInputValid():
+            self._feature.execute()
+        else:
+            raise RuntimeError("Can not execute %s: %s" %
+                               (self._feature.getKind(), self._feature.error())
+                               )