]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #2621: Dump with geometrical selection
authorazv <azv@opencascade.com>
Thu, 18 Oct 2018 12:05:36 +0000 (15:05 +0300)
committerazv <azv@opencascade.com>
Thu, 18 Oct 2018 12:05:36 +0000 (15:05 +0300)
Use a tuple instead of GeomAPI_Pnt in model.selection() commands.

src/ModelHighAPI/ModelHighAPI.i
src/ModelHighAPI/ModelHighAPI_Dumper.cpp
src/ModelHighAPI/ModelHighAPI_Selection.cpp
src/ModelHighAPI/ModelHighAPI_Selection.h

index 2d4b6a8c86f76a7606de2653f564ce24f995436d..1876d8ee2023f0fcbb07e8632e3ea849ec7463ae 100644 (file)
   }
 }
 
+%typemap(in) const std::list<double> & (std::list<double> temp) {
+  double * temp_attribute;
+  int newmem = 0;
+  if (PyTuple_Check($input)) {
+    for (Py_ssize_t i = 0; i < PyTuple_Size($input); ++i) {
+      PyObject * item = PySequence_GetItem($input, i);
+      if (PyNumber_Check(item)) {
+        temp.push_back((double)PyFloat_AsDouble(item));
+      } else {
+        PyErr_SetString(PyExc_TypeError, "argument must double value.");
+        return NULL;
+      }
+      Py_DECREF(item);
+    }
+    $1 = &temp;
+  } else {
+    PyErr_SetString(PyExc_ValueError, "argument must be a tuple of double values.");
+    return NULL;
+  }
+}
+
+%typecheck(SWIG_TYPECHECK_POINTER) std::list<double>, const std::list<double>& {
+  double * temp_object;
+  std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
+  int newmem = 0;
+  if (PyTuple_Check($input)) {
+    for (Py_ssize_t i = 0; i < PyTuple_Size($input); ++i) {
+      PyObject * item = PySequence_GetItem($input, i);
+      if (PyNumber_Check(item)) {
+        $1 = 1;
+      } else {
+        $1 = 0;
+        break;
+      }
+      Py_DECREF(item);
+    }
+  } else {
+    $1 = 0;
+  }
+}
+
 // all supported interfaces
 %include "ModelHighAPI_Double.h"
 %include "ModelHighAPI_Dumper.h"
index c005a8e4698064ebbc7f2b4b39190de826c681ef..07260dcf26708b2d45e138c8245493f4ff6b8210 100644 (file)
@@ -1091,8 +1091,10 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
       anIndex = anOutput.str();
     }
 
-    myDumpBuffer << anIndex << "\", ";
-    *this << aMiddlePoint;
+    myDumpBuffer << anIndex << "\", ("
+                 << aMiddlePoint->x() << ", "
+                 << aMiddlePoint->y() << ", "
+                 << aMiddlePoint->z() << ")";
     aStandardDump = false;
   } else if (theAttrSelect->isWeakNaming() ||
     (myWeakNamingSelection && aShape.get() && theAttrSelect->context().get() &&
index 025314d220d892737052dd43adbf215d56485e35..20e834a6335461bcd240109d1e94b69b90388662 100644 (file)
@@ -58,6 +58,20 @@ ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType,
 {
 }
 
+ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType,
+                                               const std::list<double>& theSubShapeInnerPoint)
+: myVariantType(VT_TypeInnerPointPair)
+{
+  double aCoordinates[3] = { 0.0, 0.0, 0.0 };
+  double* aCIt = aCoordinates;
+  std::list<double>::const_iterator aPIt = theSubShapeInnerPoint.begin();
+  for (; aPIt != theSubShapeInnerPoint.end(); ++aPIt, ++aCIt)
+    *aCIt = *aPIt;
+
+  GeomPointPtr anInnerPoint(new GeomAPI_Pnt(aCoordinates[0], aCoordinates[1], aCoordinates[2]));
+  myTypeInnerPointPair = std::pair<std::string, GeomPointPtr>(theType, anInnerPoint);
+}
+
 ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType,
   const std::string& theContextName, const int theIndex)
   : myVariantType(VT_WeakNamingPair)
index 8612a81256884465f831bd860368418fe0b8c861..209aa4d95cf316b016308adc48b2191c8ca4d5ec 100644 (file)
@@ -24,6 +24,7 @@
 //--------------------------------------------------------------------------------------
 #include "ModelHighAPI.h"
 
+#include <list>
 #include <memory>
 #include <string>
 #include <utility>
@@ -75,6 +76,11 @@ public:
   ModelHighAPI_Selection(const std::string& theType,
                          const std::shared_ptr<GeomAPI_Pnt>& theSubShapeInnerPoint);
 
+  /// Constructor for sub-shape by inner point coordinates given by a tuple
+  MODELHIGHAPI_EXPORT
+  ModelHighAPI_Selection(const std::string& theType,
+                         const std::list<double>& theSubShapeInnerPoint);
+
 
   /// Constructor for sub-shape by weak naming identifier
   MODELHIGHAPI_EXPORT