From b4420ed305b264614abc3ad219a22e68f40983e6 Mon Sep 17 00:00:00 2001 From: adv Date: Fri, 27 Dec 2013 12:27:46 +0000 Subject: [PATCH] First realisation of Cascade classes. --- CMake/UsePyQt4EXT.cmake | 9 ++ src/HYDROPy/CAS/NCollection_Sequence.sip | 114 ++++++++++++++++++++++ src/HYDROPy/CAS/gp_XY.sip | 64 ++++++++++++ src/HYDROPy/CAS/gp_XYZ.sip | 75 ++++++++++++++ src/HYDROPy/CMakeLists.txt | 3 + src/HYDROPy/HYDROData.sip | 3 + src/HYDROPy/HYDROData_Bathymetry.sip | 118 ++--------------------- 7 files changed, 274 insertions(+), 112 deletions(-) create mode 100644 src/HYDROPy/CAS/NCollection_Sequence.sip create mode 100644 src/HYDROPy/CAS/gp_XY.sip create mode 100644 src/HYDROPy/CAS/gp_XYZ.sip diff --git a/CMake/UsePyQt4EXT.cmake b/CMake/UsePyQt4EXT.cmake index ce01b53a..6f13a939 100644 --- a/CMake/UsePyQt4EXT.cmake +++ b/CMake/UsePyQt4EXT.cmake @@ -103,6 +103,15 @@ MACRO(PYQT4_WRAP_SIP_EXT outfiles) LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyNCollection_Sequence0100Handle_HYDROData_Entity.cc) SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyNCollection_Sequence0100Handle_HYDROData_Entity.cc) + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyNCollection_Sequence0100gp_XYZ.cc) + SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyNCollection_Sequence0100gp_XYZ.cc) + + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPygp_XYZ.cc) + SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPygp_XYZ.cc) + + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPygp_XY.cc) + SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPygp_XY.cc) + ADD_CUSTOM_COMMAND( OUTPUT ${_output} COMMAND ${SIP_EXECUTABLE} ${PYQT_SIPFLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/${_input} diff --git a/src/HYDROPy/CAS/NCollection_Sequence.sip b/src/HYDROPy/CAS/NCollection_Sequence.sip new file mode 100644 index 00000000..12f90611 --- /dev/null +++ b/src/HYDROPy/CAS/NCollection_Sequence.sip @@ -0,0 +1,114 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +%ExportedHeaderCode +#include +%End + +// NCollection_Sequence is implemented as a Python list. +template +%MappedType NCollection_Sequence +{ +%TypeHeaderCode +#include +%End + +%ConvertFromTypeCode + // Create the list. + PyObject *l; + + if ((l = PyList_New(sipCpp->Length())) == NULL) + return NULL; + + // Set the list elements. + for (int i = 0; i < sipCpp->Length(); ++i) + { + TYPE *t = new TYPE(sipCpp->Value(i)); + PyObject *tobj; + + if ((tobj = sipConvertFromNewType(t, sipType_TYPE, sipTransferObj)) == NULL) + { + Py_DECREF(l); + delete t; + + return NULL; + } + + PyList_SET_ITEM(l, i, tobj); + } + + return l; +%End + +%ConvertToTypeCode + SIP_SSIZE_T len; + + // Check the type if that is all that is required. + if (sipIsErr == NULL) + { + if (!PySequence_Check(sipPy) || (len = PySequence_Size(sipPy)) < 0) + return 0; + + for (SIP_SSIZE_T i = 0; i < len; ++i) + { + PyObject *itm = PySequence_ITEM(sipPy, i); + bool ok = (itm && sipCanConvertToType(itm, sipType_TYPE, SIP_NOT_NONE)); + + Py_XDECREF(itm); + + if (!ok) + return 0; + } + + return 1; + } + + NCollection_Sequence *ql = new NCollection_Sequence; + len = PySequence_Size(sipPy); + + for (SIP_SSIZE_T i = 0; i < len; ++i) + { + PyObject *itm = PySequence_ITEM(sipPy, i); + int state; + TYPE *t = reinterpret_cast(sipConvertToType(itm, sipType_TYPE, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr)); + + Py_DECREF(itm); + + if (*sipIsErr) + { + sipReleaseType(t, sipType_TYPE, state); + + delete ql; + return 0; + } + + ql->Append(*t); + + sipReleaseType(t, sipType_TYPE, state); + } + + *sipCppPtr = ql; + + return sipGetState(sipTransferObj); +%End +}; + diff --git a/src/HYDROPy/CAS/gp_XY.sip b/src/HYDROPy/CAS/gp_XY.sip new file mode 100644 index 00000000..4c439a1d --- /dev/null +++ b/src/HYDROPy/CAS/gp_XY.sip @@ -0,0 +1,64 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +%ExportedHeaderCode +#include +%End + +class gp_XY +{ +%TypeHeaderCode +#include +%End + +public: + + //! Creates XY object with zero coordinates (0,0).
+ gp_XY(); + + //! a number pair defined by the XY coordinates
+ gp_XY(const double X,const double Y); + + //! modifies the coordinate of range Index
+ //! Index = 1 => X is modified
+ //! Index = 2 => Y is modified
+ //! Raises OutOfRange if Index != {1, 2}.
+ void SetCoord(const int Index,const double Xi) ; + //! Assigns the given value to the X coordinate of this number pair.
+ void SetX(const double X) ; + //! Assigns the given value to the Y coordinate of this number pair.
+ void SetY(const double Y) ; + + //! returns the coordinate of range Index :
+ //! Index = 1 => X is returned
+ //! Index = 2 => Y is returned
+ //! Raises OutOfRange if Index != {1, 2}.
+ double Coord(const int Index) const; + //! For this number pair, returns its coordinates X and Y.
+ void Coord(double& X,double& Y) const; + //! Returns the X coordinate of this number pair.
+ double X() const; + //! Returns the Y coordinate of this number pair.
+ double Y() const; + +}; + diff --git a/src/HYDROPy/CAS/gp_XYZ.sip b/src/HYDROPy/CAS/gp_XYZ.sip new file mode 100644 index 00000000..d5e1016a --- /dev/null +++ b/src/HYDROPy/CAS/gp_XYZ.sip @@ -0,0 +1,75 @@ +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +%ExportedHeaderCode +#include +%End + +class gp_XYZ +{ +%TypeHeaderCode +#include +%End + +public: + + //! Creates an XYZ object with zero co-ordinates (0,0,0)
+ gp_XYZ(); + + //! creates an XYZ with given coordinates
+ gp_XYZ(const double X,const double Y,const double Z); + + //! For this XYZ object, assigns
+ //! the values X, Y and Z to its three coordinates
+ void SetCoord(const double X,const double Y,const double Z) ; + + //! modifies the coordinate of range Index
+ //! Index = 1 => X is modified
+ //! Index = 2 => Y is modified
+ //! Index = 3 => Z is modified
+ //! Raises OutOfRange if Index != {1, 2, 3}.
+ void SetCoord(const int Index,const double Xi) ; + //! Assigns the given value to the X coordinate
+ void SetX(const double X) ; + //! Assigns the given value to the Y coordinate
+ void SetY(const double Y) ; + //! Assigns the given value to the Z coordinate
+ void SetZ(const double Z) ; + + //! returns the coordinate of range Index :
+ //! Index = 1 => X is returned
+ //! Index = 2 => Y is returned
+ //! Index = 3 => Z is returned
+ //!
+ //! Raises OutOfRange if Index != {1, 2, 3}.
+ double Coord(const int Index) const; + + void Coord(double& X,double& Y,double& Z) const; + //! Returns the X coordinate
+ double X() const; + //! Returns the Y coordinate
+ double Y() const; + //! Returns the Z coordinate
+ double Z() const; + +}; + diff --git a/src/HYDROPy/CMakeLists.txt b/src/HYDROPy/CMakeLists.txt index b30b6570..e60e547c 100644 --- a/src/HYDROPy/CMakeLists.txt +++ b/src/HYDROPy/CMakeLists.txt @@ -79,6 +79,9 @@ SET(_sip_files # HYDROData_Document.sip SET(_sip_files2 + CAS/gp_XY.sip + CAS/gp_XYZ.sip + CAS/NCollection_Sequence.sip HYDROData_SequenceOfObjects.sip HYDROData_Entity.sip HYDROData_IPolyline.sip diff --git a/src/HYDROPy/HYDROData.sip b/src/HYDROPy/HYDROData.sip index 530587c8..e0997fcf 100644 --- a/src/HYDROPy/HYDROData.sip +++ b/src/HYDROPy/HYDROData.sip @@ -51,6 +51,9 @@ See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com %Import QtGuimod.sip +%Include CAS/gp_XY.sip +%Include CAS/gp_XYZ.sip +%Include CAS/NCollection_Sequence.sip %Include HYDROData_SequenceOfObjects.sip %Include HYDROData_Entity.sip %Include HYDROData_IPolyline.sip diff --git a/src/HYDROPy/HYDROData_Bathymetry.sip b/src/HYDROPy/HYDROData_Bathymetry.sip index 6943e63d..75b918e3 100644 --- a/src/HYDROPy/HYDROData_Bathymetry.sip +++ b/src/HYDROPy/HYDROData_Bathymetry.sip @@ -22,20 +22,14 @@ %ExportedHeaderCode #include -#include -#include -%End - -%ModuleCode - -PyObject* convertToPythonAltitudeList( const HYDROData_Bathymetry::AltitudePoints& thePoints ); -HYDROData_Bathymetry::AltitudePoints convertFromPythonAltitudeList( PyObject* thePythonList ); - %End class HYDROData_Bathymetry : HYDROData_IAltitudeObject { + typedef gp_XYZ AltitudePoint; + typedef NCollection_Sequence AltitudePoints; + %ConvertToSubClassCode switch ( sipCpp->GetKind() ) { @@ -53,55 +47,6 @@ class HYDROData_Bathymetry : HYDROData_IAltitudeObject #include %End -%TypeCode - -PyObject* convertToPythonAltitudeList( const HYDROData_Bathymetry::AltitudePoints& thePoints ) -{ - int aListSize = thePoints.size(); - - PyObject* aPythonList = NULL; - if ( ( aPythonList = PyList_New( aListSize ) ) == NULL ) - return NULL; - - for ( int i = 0; i < aListSize; ++i ) - { - const HYDROData_Bathymetry::AltitudePoint& aPoint = thePoints.at( i ); - - PyObject* aTypleObj = Py_BuildValue( "(ddd)", aPoint.X(), aPoint.Y(), aPoint.Z() ); - - PyList_SET_ITEM( aPythonList, i, aTypleObj ); - } - - return aPythonList; -} - -HYDROData_Bathymetry::AltitudePoints convertFromPythonAltitudeList( PyObject* thePythonList ) -{ - HYDROData_Bathymetry::AltitudePoints aPoints; - if ( thePythonList == NULL ) - return aPoints; - - for ( int i = 0, n = PyList_GET_SIZE( thePythonList ); i < n; ++i ) - { - PyObject* aTypleObj = PyList_GET_ITEM( thePythonList, i ); - - double anArr[ 3 ]; - if ( !PyArg_ParseTuple( aTypleObj, "ddd", &anArr[ 0 ], &anArr[ 1 ], &anArr[ 2 ] ) ) - continue; - - HYDROData_Bathymetry::AltitudePoint aPoint; - aPoint.SetX( anArr[ 0 ] ); - aPoint.SetY( anArr[ 1 ] ); - aPoint.SetZ( anArr[ 2 ] ); - - aPoints.append( aPoint ); - } - - return aPoints; -} - -%End - public: // Public methods to work with Bathymetry altitudes. @@ -110,70 +55,19 @@ public: * \param thePoint the point to examine * \return altitude value */ - double GetAltitudeForPoint( const QPointF& thePoint ) const [double (const gp_XY&)]; - %MethodCode - - // The C++ API gets the gp_XY object, we convert it from QPointF. - gp_XY aPoint( a0->x(), a0->y() ); - - Py_BEGIN_ALLOW_THREADS - sipRes = sipSelfWasArg ? sipCpp->HYDROData_Bathymetry::GetAltitudeForPoint( aPoint ) : - sipCpp->GetAltitudeForPoint( aPoint ); - Py_END_ALLOW_THREADS - %End - - + double GetAltitudeForPoint( const gp_XY& thePoint ); /** * Replace current altitude points by new one. * \param thePoints the altitude points list */ - virtual void SetAltitudePoints( SIP_PYLIST ) [void (const HYDROData_Bathymetry::AltitudePoints&)] ; - %MethodCode - - // The C++ API takes a list of gp_XYZ objects, - // but we pass a list of python tuples. - - HYDROData_Bathymetry::AltitudePoints aPoints = - convertFromPythonAltitudeList( a0 ); - - Py_BEGIN_ALLOW_THREADS - sipSelfWasArg ? sipCpp->HYDROData_Bathymetry::SetAltitudePoints( aPoints ) : - sipCpp->SetAltitudePoints( aPoints ); - Py_END_ALLOW_THREADS - - %End - %VirtualCatcherCode - - PyObject* aPythonList = convertToPythonAltitudeList( a0 ); - if ( aPythonList != NULL ) - { - sipCallMethod( &sipIsErr, sipMethod, "O", aPythonList ); - Py_DECREF( aPythonList ); - } - - %End + virtual void SetAltitudePoints( const HYDROData_Bathymetry::AltitudePoints& ); /** * Returns altitude points list. * \return points list */ - SIP_PYLIST GetAltitudePoints() const [HYDROData_Bathymetry::AltitudePoints ()] ; - %MethodCode - - // The C++ API returns a list of gp_XYZ objects, - // we convert it to list of python tuples. - - HYDROData_Bathymetry::AltitudePoints aPoints; - - Py_BEGIN_ALLOW_THREADS - aPoints = sipSelfWasArg ? sipCpp->HYDROData_Bathymetry::GetAltitudePoints() : - sipCpp->GetAltitudePoints(); - Py_END_ALLOW_THREADS - - sipRes = convertToPythonAltitudeList( aPoints ); - - %End + HYDROData_Bathymetry::AltitudePoints GetAltitudePoints() const; /** * Remove all altitude points. -- 2.39.2