Salome HOME
Issue #1648: Dump Python in the High Level Parameterized Geometry API
authordbv <dbv@opencascade.com>
Mon, 15 Aug 2016 08:37:53 +0000 (11:37 +0300)
committerdbv <dbv@opencascade.com>
Mon, 15 Aug 2016 11:03:15 +0000 (14:03 +0300)
Dump for FeaturesAPI_Recover

src/FeaturesAPI/FeaturesAPI_Recover.cpp
src/FeaturesAPI/FeaturesAPI_Recover.h
src/ModelHighAPI/ModelHighAPI.i
src/ModelHighAPI/ModelHighAPI_Dumper.cpp
src/ModelHighAPI/ModelHighAPI_Dumper.h
src/SketchAPI/SketchAPI.i

index 30b22e13172d08cac58228ca2660cd55e313f1a1..efc80327bd5a25daba989a2bed38fbb88546f77d 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "FeaturesAPI_Recover.h"
 
+#include <ModelHighAPI_Dumper.h>
 #include <ModelHighAPI_Reference.h>
 #include <ModelHighAPI_Tools.h>
 
@@ -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<ModelAPI_Document>& thePart,
   const ModelHighAPI_Reference& theBaseFeature,
index 28c8e180488c4135d90b185bc6afb7691a03a022..e7f57d4262cae2747e5555218ecae4a95185a382 100644 (file)
@@ -14,6 +14,7 @@
 #include <ModelHighAPI_Interface.h>
 #include <ModelHighAPI_Macro.h>
 
+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.
index 39b0589a87e0baa7071d524a8acd8c6ef7f5fa5e..2ad5dc461571a9b09b04abed28a3e974c014463a 100644 (file)
 %template(RefAttrList) std::list<ModelHighAPI_RefAttr>;
 %template(RefList) std::list<ModelHighAPI_Reference>;
 
+// fix compilarion error: ‘res*’ was not declared in this scope
+%typemap(freearg) const std::list<ModelHighAPI_RefAttr> & {}
+%typemap(freearg) const std::list<std::shared_ptr<ModelAPI_Object> > & {}
+
+%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;
+  }
+}
+
+%typemap(in) const std::list<std::shared_ptr<ModelAPI_Object> > & (std::list<std::shared_ptr<ModelAPI_Object> > temp) {
+  std::shared_ptr<ModelAPI_Object> * temp_object;
+  std::shared_ptr<ModelHighAPI_Interface> * 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<ModelAPI_Object> *), 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<ModelHighAPI_Interface> *), 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<std::shared_ptr<ModelAPI_Object> >, const std::list<std::shared_ptr<ModelAPI_Object> >& {
+  std::shared_ptr<ModelAPI_Object> * temp_object;
+  std::shared_ptr<ModelHighAPI_Interface> * 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<ModelAPI_Object> *), 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<ModelHighAPI_Interface> *), 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"
index f5c8593679225e8b853ab6a9896091e5b641c588..32dbc5776b8cc15b5c563ed86eec5162598ddb6c 100644 (file)
@@ -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<ResultPtr> aResults = aFeature->results();
+  for(std::list<ResultPtr>::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<ModelAPI_Feature>(theObject);
+  if(aFeature.get()) {
+    myDumpBuffer << name(aFeature);
+    return *this;
+  }
+
+  ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+  if(aResult.get()) {
+    *this << aResult;
+    return *this;
+  }
+
   return *this;
 }
 
index 481529b32255b89e3c797d049d407bfb6442e0ae..f7f0dcc3e5c192126f9aaee79dc6d29ca7e02c47 100644 (file)
@@ -38,10 +38,12 @@ class ModelAPI_Document;
 class ModelAPI_Entity;
 class ModelAPI_Feature;
 class ModelAPI_Object;
+class ModelAPI_Result;
 
 typedef std::shared_ptr<ModelAPI_Document> DocumentPtr;
 typedef std::shared_ptr<ModelAPI_Entity>   EntityPtr;
 typedef std::shared_ptr<ModelAPI_Feature>  FeaturePtr;
+typedef std::shared_ptr<ModelAPI_Result> 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<ModelAPI_Attribute>& theAttr);
index 1be2156ed81a4a6976d383c992a36daa9fdc7390..eff688fa31f3a9ffb5c19aa8b5c0b601a23eeeb1 100644 (file)
 %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<ModelHighAPI_RefAttr> & {}
-%typemap(freearg) const std::list<std::shared_ptr<ModelAPI_Object> > & {}
-
-%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;
-  }
-}
-
-%typemap(in) const std::list<std::shared_ptr<ModelAPI_Object> > & (std::list<std::shared_ptr<ModelAPI_Object> > temp) {
-  std::shared_ptr<ModelAPI_Object> * temp_object;
-  std::shared_ptr<ModelHighAPI_Interface> * 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<ModelAPI_Object> *), 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<ModelHighAPI_Interface> *), 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<std::shared_ptr<ModelAPI_Object> >, const std::list<std::shared_ptr<ModelAPI_Object> >& {
-  std::shared_ptr<ModelAPI_Object> * temp_object;
-  std::shared_ptr<ModelHighAPI_Interface> * 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<ModelAPI_Object> *), 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<ModelHighAPI_Interface> *), 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"