]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Add support of ModelAPI_AttributeRefAttrList
authorspo <sergey.pokhodenko@opencascade.com>
Wed, 15 Jun 2016 08:06:06 +0000 (11:06 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Fri, 17 Jun 2016 11:41:08 +0000 (14:41 +0300)
src/ModelHighAPI/ModelHighAPI.i
src/ModelHighAPI/ModelHighAPI_RefAttr.cpp
src/ModelHighAPI/ModelHighAPI_RefAttr.h
src/ModelHighAPI/ModelHighAPI_Tools.cpp
src/ModelHighAPI/ModelHighAPI_Tools.h
src/SketchAPI/SketchAPI.i

index 418a46baa48b97058195c4627b252608e5bd3023..03df07c00ca9e2f740557801ff420a708a901adc 100644 (file)
 %include "ModelHighAPI_Tools.h"
 
 %template(SelectionList) std::list<ModelHighAPI_Selection>;
+%template(RefAttrList) std::list<ModelHighAPI_RefAttr>;
index cb6574668e3df6a33ccfa8cebc8f7c7aacb6449b..4f00429c14ce22dcd6cfd0572d303d1c0b9327a3 100644 (file)
@@ -8,6 +8,7 @@
 #include "ModelHighAPI_RefAttr.h"
 
 #include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeRefAttrList.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Result.h>
 #include "ModelHighAPI_Interface.h"
@@ -58,3 +59,21 @@ void ModelHighAPI_RefAttr::fillAttribute(
 {
   boost::apply_visitor(fill_visitor(theAttribute), myValue);
 }
+
+//--------------------------------------------------------------------------------------
+struct append_visitor : boost::static_visitor<void>
+{
+  mutable std::shared_ptr<ModelAPI_AttributeRefAttrList> myAttribute;
+
+  append_visitor(const std::shared_ptr<ModelAPI_AttributeRefAttrList> & theAttribute)
+  : myAttribute(theAttribute) {}
+
+  void operator()(const std::shared_ptr<ModelAPI_Attribute>& theValue) const { myAttribute->append(theValue); }
+  void operator()(const std::shared_ptr<ModelAPI_Object>& theValue) const { myAttribute->append(theValue); }
+};
+
+void ModelHighAPI_RefAttr::appendToList(
+    const std::shared_ptr<ModelAPI_AttributeRefAttrList> & theAttribute) const
+{
+  boost::apply_visitor(append_visitor(theAttribute), myValue);
+}
index 6f2648e427bd439ea4da4c45758ac697ca5f3330..a2667cab244e7afea283c19f6d874b20e8f76082 100644 (file)
@@ -17,6 +17,7 @@
 //--------------------------------------------------------------------------------------
 class ModelAPI_Attribute;
 class ModelAPI_AttributeRefAttr;
+class ModelAPI_AttributeRefAttrList;
 class ModelAPI_Object;
 class ModelHighAPI_Interface;
 //--------------------------------------------------------------------------------------
@@ -47,6 +48,10 @@ public:
   MODELHIGHAPI_EXPORT
   virtual void fillAttribute(const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute) const;
 
+  /// Append to list attribute
+  MODELHIGHAPI_EXPORT
+  virtual void appendToList(const std::shared_ptr<ModelAPI_AttributeRefAttrList> & theAttribute) const;
+
 private:
   boost::variant<
     std::shared_ptr<ModelAPI_Attribute>,
index 9a6c10e97238d8b2c375441282f1416ea06f996e..9250494b128f5356883ca93bca3c18a7a551e69e 100644 (file)
@@ -93,6 +93,15 @@ void fillAttribute(const ModelHighAPI_RefAttr & theValue,
   theValue.fillAttribute(theAttribute);
 }
 
+//--------------------------------------------------------------------------------------
+void fillAttribute(const std::list<ModelHighAPI_RefAttr> & theValue,
+                   const std::shared_ptr<ModelAPI_AttributeRefAttrList> & theAttribute)
+{
+  theAttribute->clear();
+  for (auto it = theValue.begin(); it != theValue.end(); ++it)
+    it->appendToList(theAttribute);
+}
+
 //--------------------------------------------------------------------------------------
 void fillAttribute(const ModelHighAPI_Selection & theValue,
                    const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute)
index a0e44c6937fea1aa599d95897d3a0ce66bb50d96..ae35740a39108c8779212149c42c2b2780cc08e5 100644 (file)
@@ -77,6 +77,10 @@ MODELHIGHAPI_EXPORT
 void fillAttribute(const ModelHighAPI_RefAttr & theValue,
                    const std::shared_ptr<ModelAPI_AttributeRefAttr> & theAttribute);
 
+MODELHIGHAPI_EXPORT
+void fillAttribute(const std::list<ModelHighAPI_RefAttr> & theValue,
+                   const std::shared_ptr<ModelAPI_AttributeRefAttrList> & theAttribute);
+
 MODELHIGHAPI_EXPORT
 void fillAttribute(const ModelHighAPI_Selection & theValue,
                    const std::shared_ptr<ModelAPI_AttributeSelection> & theAttribute);
index 2c5fb703526d23543e8a048eb7db1595a47efc32..b515c2c746d47a5268a547f154bab4b0ec758097 100644 (file)
 %shared_ptr(SketchAPI_Sketch)
 %shared_ptr(SketchAPI_SketchEntity)
 
+// fix compilarion error: ‘res2’ was not declared in this scope
+%typemap(freearg) const std::list<ModelHighAPI_RefAttr> & {}
+
+%typemap(in) const std::list<ModelHighAPI_RefAttr> & (std::list<ModelHighAPI_RefAttr> temp) {
+  std::shared_ptr<ModelAPI_Attribute> * temp_attribute;
+  int newmem = 0;
+  if (PySequence_Check($input)) {
+    for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
+      PyObject * item = PySequence_GetItem($input, i);
+      if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_attribute, $descriptor(std::shared_ptr<ModelAPI_Attribute> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+        if (!temp_attribute) {
+          PyErr_SetString(PyExc_TypeError, "argument must be list of ModelHighAPI_RefAttr, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
+          return NULL;
+        }
+        temp.push_back(ModelHighAPI_RefAttr(*temp_attribute));
+        if (newmem & SWIG_CAST_NEW_MEMORY) {
+          delete temp_attribute;
+        }
+      }
+      Py_DECREF(item);
+    }
+    $1 = &temp;
+  } else {
+    PyErr_SetString(PyExc_ValueError, "argument must be list of ModelHighAPI_RefAttr, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
+    return NULL;
+  }
+}
+
 // all supported interfaces (the order is very important: base class first)
 %include "SketchAPI_SketchEntity.h"
 %include "SketchAPI_Circle.h"