From 7fe62f326596c6c6d25be8288851ff28bd465714 Mon Sep 17 00:00:00 2001 From: dbv Date: Mon, 15 Aug 2016 11:37:53 +0300 Subject: [PATCH] Issue #1648: Dump Python in the High Level Parameterized Geometry API Dump for FeaturesAPI_Recover --- src/FeaturesAPI/FeaturesAPI_Recover.cpp | 18 +++++ src/FeaturesAPI/FeaturesAPI_Recover.h | 4 + src/ModelHighAPI/ModelHighAPI.i | 95 +++++++++++++++++++++++ src/ModelHighAPI/ModelHighAPI_Dumper.cpp | 28 ++++++- src/ModelHighAPI/ModelHighAPI_Dumper.h | 6 ++ src/SketchAPI/SketchAPI.i | 97 ------------------------ 6 files changed, 149 insertions(+), 99 deletions(-) diff --git a/src/FeaturesAPI/FeaturesAPI_Recover.cpp b/src/FeaturesAPI/FeaturesAPI_Recover.cpp index 30b22e131..efc80327b 100644 --- a/src/FeaturesAPI/FeaturesAPI_Recover.cpp +++ b/src/FeaturesAPI/FeaturesAPI_Recover.cpp @@ -6,6 +6,7 @@ #include "FeaturesAPI_Recover.h" +#include #include #include @@ -54,6 +55,23 @@ void FeaturesAPI_Recover::setIsPersistent(bool thePersistent) // do not need to execute because on attribute changed it does everything anyway } +//================================================================================================== +void FeaturesAPI_Recover::dump(ModelHighAPI_Dumper& theDumper) const +{ + FeaturePtr aBase = feature(); + const std::string& aDocName = theDumper.name(aBase->document()); + + AttributeReferencePtr anAttrBaseFeature = aBase->reference(FeaturesPlugin_Recover::BASE_FEATURE()); + AttributeRefListPtr anAttrRecoveredEntities = aBase->reflist(FeaturesPlugin_Recover::RECOVERED_ENTITIES()); + AttributeBooleanPtr anAttrPersistent = aBase->boolean(FeaturesPlugin_Recover::PERSISTENT()); + + FeaturePtr aFeature = ModelAPI_Feature::feature(anAttrBaseFeature->value()); + + theDumper << aBase << " = model.addRecover(" << aDocName << ", " + << aFeature << ", " << anAttrRecoveredEntities << ", " + << anAttrPersistent << ")" << std::endl; +} + //================================================================================================= RecoverPtr addRecover(const std::shared_ptr& thePart, const ModelHighAPI_Reference& theBaseFeature, diff --git a/src/FeaturesAPI/FeaturesAPI_Recover.h b/src/FeaturesAPI/FeaturesAPI_Recover.h index 28c8e1804..e7f57d426 100644 --- a/src/FeaturesAPI/FeaturesAPI_Recover.h +++ b/src/FeaturesAPI/FeaturesAPI_Recover.h @@ -14,6 +14,7 @@ #include #include +class ModelHighAPI_Dumper; class ModelHighAPI_Reference; /// \class FeaturesAPI_Recover @@ -54,6 +55,9 @@ public: FEATURESAPI_EXPORT void setIsPersistent(bool thePersistent); + /// Dump wrapped feature + FEATURESAPI_EXPORT + virtual void dump(ModelHighAPI_Dumper& theDumper) const; }; /// Pointer on Recover object. diff --git a/src/ModelHighAPI/ModelHighAPI.i b/src/ModelHighAPI/ModelHighAPI.i index 39b0589a8..2ad5dc461 100644 --- a/src/ModelHighAPI/ModelHighAPI.i +++ b/src/ModelHighAPI/ModelHighAPI.i @@ -216,6 +216,101 @@ %template(RefAttrList) std::list; %template(RefList) std::list; +// fix compilarion error: ‘res*’ was not declared in this scope +%typemap(freearg) const std::list & {} +%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; + } +} + +%typemap(in) const std::list > & (std::list > temp) { + std::shared_ptr * temp_object; + std::shared_ptr * temp_interface; + 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_object, $descriptor(std::shared_ptr *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) { + if (!temp_object) { + PyErr_SetString(PyExc_TypeError, "argument must be list of ModelHighAPI_Interface or ModelAPI_Object."); + return NULL; + } + temp.push_back(*temp_object); + if (newmem & SWIG_CAST_NEW_MEMORY) { + delete temp_object; + } + } else + if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_interface, $descriptor(std::shared_ptr *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) { + if (!temp_interface) { + PyErr_SetString(PyExc_TypeError, "argument must be list of ModelHighAPI_Interface or ModelAPI_Object."); + return NULL; + } + temp.push_back((*temp_interface)->defaultResult()); + if (newmem & SWIG_CAST_NEW_MEMORY) { + delete temp_interface; + } + } + Py_DECREF(item); + } + $1 = &temp; + } else { + PyErr_SetString(PyExc_ValueError, "argument must be list of ModelHighAPI_Interface or ModelAPI_Object."); + return NULL; + } +} + +%typecheck(SWIG_TYPECHECK_POINTER) std::list >, const std::list >& { + std::shared_ptr * temp_object; + std::shared_ptr * temp_interface; + 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_object, $descriptor(std::shared_ptr *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) { + if (temp_object) { + $1 = 1; + } else { + $1 = 0; + break; + } + } else + if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_interface, $descriptor(std::shared_ptr *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) { + if (temp_interface) { + $1 = 1; + } else { + $1 = 0; + break; + } + } + Py_DECREF(item); + } + } else { + $1 = 0; + } +} + // all supported interfaces %include "ModelHighAPI_Double.h" %include "ModelHighAPI_Dumper.h" diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp index f5c859367..32dbc5776 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp @@ -434,10 +434,34 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const FeaturePtr& theEntity return *this; } +ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const ResultPtr& theResult) +{ + FeaturePtr aFeature = ModelAPI_Feature::feature(theResult); + int anIndex = 0; + std::list aResults = aFeature->results(); + for(std::list::const_iterator anIt = aResults.cbegin(); anIt != aResults.cend(); ++anIt, ++anIndex) { + if(theResult->isSame(*anIt)) { + break; + } + } + myDumpBuffer << name(aFeature) << ".result()[" << anIndex << "]"; + return *this; +} + ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const ObjectPtr& theObject) { - FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); - myDumpBuffer << name(aFeature); + FeaturePtr aFeature = std::dynamic_pointer_cast(theObject); + if(aFeature.get()) { + myDumpBuffer << name(aFeature); + return *this; + } + + ResultPtr aResult = std::dynamic_pointer_cast(theObject); + if(aResult.get()) { + *this << aResult; + return *this; + } + return *this; } diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.h b/src/ModelHighAPI/ModelHighAPI_Dumper.h index 481529b32..f7f0dcc3e 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.h +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.h @@ -38,10 +38,12 @@ class ModelAPI_Document; class ModelAPI_Entity; class ModelAPI_Feature; class ModelAPI_Object; +class ModelAPI_Result; typedef std::shared_ptr DocumentPtr; typedef std::shared_ptr EntityPtr; typedef std::shared_ptr FeaturePtr; +typedef std::shared_ptr ResultPtr; /**\class ModelHighAPI_Dumper * \ingroup CPPHighAPI @@ -158,6 +160,10 @@ public: MODELHIGHAPI_EXPORT ModelHighAPI_Dumper& operator<<(const FeaturePtr& theEntity); + /// Dump result + MODELHIGHAPI_EXPORT + ModelHighAPI_Dumper& operator<<(const ResultPtr& theResult); + /// Dump Attribute MODELHIGHAPI_EXPORT ModelHighAPI_Dumper& operator<<(const std::shared_ptr& theAttr); diff --git a/src/SketchAPI/SketchAPI.i b/src/SketchAPI/SketchAPI.i index 1be2156ed..eff688fa3 100644 --- a/src/SketchAPI/SketchAPI.i +++ b/src/SketchAPI/SketchAPI.i @@ -34,103 +34,6 @@ %shared_ptr(SketchAPI_Rotation) %shared_ptr(SketchAPI_Translation) -// TODO(spo): move typemaps into ModelHighAPI package - -// fix compilarion error: ‘res*’ was not declared in this scope -%typemap(freearg) const std::list & {} -%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; - } -} - -%typemap(in) const std::list > & (std::list > temp) { - std::shared_ptr * temp_object; - std::shared_ptr * temp_interface; - 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_object, $descriptor(std::shared_ptr *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) { - if (!temp_object) { - PyErr_SetString(PyExc_TypeError, "argument must be list of ModelHighAPI_Interface or ModelAPI_Object."); - return NULL; - } - temp.push_back(*temp_object); - if (newmem & SWIG_CAST_NEW_MEMORY) { - delete temp_object; - } - } else - if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_interface, $descriptor(std::shared_ptr *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) { - if (!temp_interface) { - PyErr_SetString(PyExc_TypeError, "argument must be list of ModelHighAPI_Interface or ModelAPI_Object."); - return NULL; - } - temp.push_back((*temp_interface)->defaultResult()); - if (newmem & SWIG_CAST_NEW_MEMORY) { - delete temp_interface; - } - } - Py_DECREF(item); - } - $1 = &temp; - } else { - PyErr_SetString(PyExc_ValueError, "argument must be list of ModelHighAPI_Interface or ModelAPI_Object."); - return NULL; - } -} - -%typecheck(SWIG_TYPECHECK_POINTER) std::list >, const std::list >& { - std::shared_ptr * temp_object; - std::shared_ptr * temp_interface; - 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_object, $descriptor(std::shared_ptr *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) { - if (temp_object) { - $1 = 1; - } else { - $1 = 0; - break; - } - } else - if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_interface, $descriptor(std::shared_ptr *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) { - if (temp_interface) { - $1 = 1; - } else { - $1 = 0; - break; - } - } - Py_DECREF(item); - } - } else { - $1 = 0; - } -} - // all supported interfaces (the order is very important according dependencies: base class first) %include "SketchAPI_SketchEntity.h" %include "SketchAPI_Point.h" -- 2.39.2