From: spo Date: Wed, 15 Jun 2016 08:06:06 +0000 (+0300) Subject: Add support of ModelAPI_AttributeRefAttrList X-Git-Tag: V_2.4.0~91^2~45 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=bf1a97439d96d3c3df5efbfa2fd320092c3a9a2d;p=modules%2Fshaper.git Add support of ModelAPI_AttributeRefAttrList --- diff --git a/src/ModelHighAPI/ModelHighAPI.i b/src/ModelHighAPI/ModelHighAPI.i index 418a46baa..03df07c00 100644 --- a/src/ModelHighAPI/ModelHighAPI.i +++ b/src/ModelHighAPI/ModelHighAPI.i @@ -118,3 +118,4 @@ %include "ModelHighAPI_Tools.h" %template(SelectionList) std::list; +%template(RefAttrList) std::list; diff --git a/src/ModelHighAPI/ModelHighAPI_RefAttr.cpp b/src/ModelHighAPI/ModelHighAPI_RefAttr.cpp index cb6574668..4f00429c1 100644 --- a/src/ModelHighAPI/ModelHighAPI_RefAttr.cpp +++ b/src/ModelHighAPI/ModelHighAPI_RefAttr.cpp @@ -8,6 +8,7 @@ #include "ModelHighAPI_RefAttr.h" #include +#include #include #include #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 +{ + mutable std::shared_ptr myAttribute; + + append_visitor(const std::shared_ptr & theAttribute) + : myAttribute(theAttribute) {} + + void operator()(const std::shared_ptr& theValue) const { myAttribute->append(theValue); } + void operator()(const std::shared_ptr& theValue) const { myAttribute->append(theValue); } +}; + +void ModelHighAPI_RefAttr::appendToList( + const std::shared_ptr & theAttribute) const +{ + boost::apply_visitor(append_visitor(theAttribute), myValue); +} diff --git a/src/ModelHighAPI/ModelHighAPI_RefAttr.h b/src/ModelHighAPI/ModelHighAPI_RefAttr.h index 6f2648e42..a2667cab2 100644 --- a/src/ModelHighAPI/ModelHighAPI_RefAttr.h +++ b/src/ModelHighAPI/ModelHighAPI_RefAttr.h @@ -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 & theAttribute) const; + /// Append to list attribute + MODELHIGHAPI_EXPORT + virtual void appendToList(const std::shared_ptr & theAttribute) const; + private: boost::variant< std::shared_ptr, diff --git a/src/ModelHighAPI/ModelHighAPI_Tools.cpp b/src/ModelHighAPI/ModelHighAPI_Tools.cpp index 9a6c10e97..9250494b1 100644 --- a/src/ModelHighAPI/ModelHighAPI_Tools.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Tools.cpp @@ -93,6 +93,15 @@ void fillAttribute(const ModelHighAPI_RefAttr & theValue, theValue.fillAttribute(theAttribute); } +//-------------------------------------------------------------------------------------- +void fillAttribute(const std::list & theValue, + const std::shared_ptr & 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 & theAttribute) diff --git a/src/ModelHighAPI/ModelHighAPI_Tools.h b/src/ModelHighAPI/ModelHighAPI_Tools.h index a0e44c693..ae35740a3 100644 --- a/src/ModelHighAPI/ModelHighAPI_Tools.h +++ b/src/ModelHighAPI/ModelHighAPI_Tools.h @@ -77,6 +77,10 @@ MODELHIGHAPI_EXPORT void fillAttribute(const ModelHighAPI_RefAttr & theValue, const std::shared_ptr & theAttribute); +MODELHIGHAPI_EXPORT +void fillAttribute(const std::list & theValue, + const std::shared_ptr & theAttribute); + MODELHIGHAPI_EXPORT void fillAttribute(const ModelHighAPI_Selection & theValue, const std::shared_ptr & theAttribute); diff --git a/src/SketchAPI/SketchAPI.i b/src/SketchAPI/SketchAPI.i index 2c5fb7035..b515c2c74 100644 --- a/src/SketchAPI/SketchAPI.i +++ b/src/SketchAPI/SketchAPI.i @@ -25,6 +25,34 @@ %shared_ptr(SketchAPI_Sketch) %shared_ptr(SketchAPI_SketchEntity) +// fix compilarion error: ‘res2’ was not declared in this scope +%typemap(freearg) const std::list & {} + +%typemap(in) const std::list & (std::list temp) { + std::shared_ptr * 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 *), 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"