Salome HOME
Add ConnectorAPI
[modules/shaper.git] / src / PythonAPI / model / tools.py
index fe300d990b670624bb0f96875af5a2afca6c03c3..cde3e64bff00c02d05527e91e42706416b2f41bb 100644 (file)
@@ -20,10 +20,20 @@ def convert_to_underscore(name):
 
 
 class Selection:
-    """Class for storing selection."""
+    """Class for selection.
+
+    Selection() -> empty selection
+    Selection(name, type) -> selection initialized with arguments:
+        - name -- topological name
+        - type -- type of the object
+    Selection(context, shape) -> selection initialized with arguments:
+        - context -- ModelAPI_Result object
+        - shape -- GeomAPI_Shape shape
+    """
 
     def __init__(self, *args):
-        """Initialize selection."""
+        """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
+
         if not args:
             self.args = (None, None)
             return
@@ -52,13 +62,16 @@ def fill_attribute(attribute, value):
     """
     if (isinstance(attribute, ModelAPI.ModelAPI_AttributeBoolean) or
         isinstance(attribute, ModelAPI.ModelAPI_AttributeDocRef) or
-        isinstance(attribute, ModelAPI.ModelAPI_AttributeInteger) or
-        isinstance(attribute, ModelAPI.ModelAPI_AttributeReference) or
-        isinstance(attribute, ModelAPI.ModelAPI_AttributeString)
+        isinstance(attribute, ModelAPI.ModelAPI_AttributeReference)
         ):
         attribute.setValue(value)
 
-    elif isinstance(attribute, ModelAPI.ModelAPI_AttributeDouble):
+    elif isinstance(attribute, ModelAPI.ModelAPI_AttributeString):
+        attribute.setValue(str(value))
+
+    elif (isinstance(attribute, ModelAPI.ModelAPI_AttributeDouble) or
+          isinstance(attribute, ModelAPI.ModelAPI_AttributeInteger)
+          ):
         if isinstance(value, basestring):
             attribute.setText(value)
         else:
@@ -73,9 +86,9 @@ def fill_attribute(attribute, value):
         assert(isinstance(value, ModelAPI.ModelAPI_Attribute) or
                isinstance(value, ModelAPI.ModelAPI_Object))
         if isinstance(value, ModelAPI.ModelAPI_Attribute):
-            attrubute.setAttr(value)
+            attribute.setAttr(value)
         elif isinstance(value, ModelAPI.ModelAPI_Object):
-            attrubute.setObject(value)
+            attribute.setObject(value)
 
     elif isinstance(attribute, ModelAPI.ModelAPI_AttributeRefList):
         attribute.clear()
@@ -87,6 +100,16 @@ def fill_attribute(attribute, value):
             assert(isinstance(item, ModelAPI.ModelAPI_Object))
             attribute.append(item)
 
+    elif isinstance(attribute, ModelAPI.ModelAPI_AttributeRefAttrList):
+        attribute.clear()
+        if not value:
+            return
+
+        assert(isinstance(value, collections.Iterable))
+        for item in value:
+            assert(isinstance(item, ModelAPI.ModelAPI_Attribute))
+            attribute.append(item)
+
     elif isinstance(attribute, ModelAPI.ModelAPI_AttributeSelection):
         if value is None:
             attribute.setValue(None, None)