From 7fc1263ea0d94986475f96e209061e9a199118be Mon Sep 17 00:00:00 2001 From: azv Date: Thu, 18 Oct 2018 15:05:36 +0300 Subject: [PATCH] Issue #2621: Dump with geometrical selection Use a tuple instead of GeomAPI_Pnt in model.selection() commands. --- src/ModelHighAPI/ModelHighAPI.i | 41 +++++++++++++++++++++ src/ModelHighAPI/ModelHighAPI_Dumper.cpp | 6 ++- src/ModelHighAPI/ModelHighAPI_Selection.cpp | 14 +++++++ src/ModelHighAPI/ModelHighAPI_Selection.h | 6 +++ 4 files changed, 65 insertions(+), 2 deletions(-) diff --git a/src/ModelHighAPI/ModelHighAPI.i b/src/ModelHighAPI/ModelHighAPI.i index 2d4b6a8c8..1876d8ee2 100644 --- a/src/ModelHighAPI/ModelHighAPI.i +++ b/src/ModelHighAPI/ModelHighAPI.i @@ -344,6 +344,47 @@ } } +%typemap(in) const std::list & (std::list 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, const std::list& { + double * temp_object; + std::shared_ptr * 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" diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp index c005a8e46..07260dcf2 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp @@ -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() && diff --git a/src/ModelHighAPI/ModelHighAPI_Selection.cpp b/src/ModelHighAPI/ModelHighAPI_Selection.cpp index 025314d22..20e834a63 100644 --- a/src/ModelHighAPI/ModelHighAPI_Selection.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Selection.cpp @@ -58,6 +58,20 @@ ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType, { } +ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType, + const std::list& theSubShapeInnerPoint) +: myVariantType(VT_TypeInnerPointPair) +{ + double aCoordinates[3] = { 0.0, 0.0, 0.0 }; + double* aCIt = aCoordinates; + std::list::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(theType, anInnerPoint); +} + ModelHighAPI_Selection::ModelHighAPI_Selection(const std::string& theType, const std::string& theContextName, const int theIndex) : myVariantType(VT_WeakNamingPair) diff --git a/src/ModelHighAPI/ModelHighAPI_Selection.h b/src/ModelHighAPI/ModelHighAPI_Selection.h index 8612a8125..209aa4d95 100644 --- a/src/ModelHighAPI/ModelHighAPI_Selection.h +++ b/src/ModelHighAPI/ModelHighAPI_Selection.h @@ -24,6 +24,7 @@ //-------------------------------------------------------------------------------------- #include "ModelHighAPI.h" +#include #include #include #include @@ -75,6 +76,11 @@ public: ModelHighAPI_Selection(const std::string& theType, const std::shared_ptr& theSubShapeInnerPoint); + /// Constructor for sub-shape by inner point coordinates given by a tuple + MODELHIGHAPI_EXPORT + ModelHighAPI_Selection(const std::string& theType, + const std::list& theSubShapeInnerPoint); + /// Constructor for sub-shape by weak naming identifier MODELHIGHAPI_EXPORT -- 2.39.2