From: adv Date: Mon, 30 Dec 2013 08:17:14 +0000 (+0000) Subject: Cascade ascii string added for SIP. X-Git-Tag: BR_hydro_v_0_7~9 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b481ebbedb40b2c63e396993ecf60c737305ce1b;p=modules%2Fhydro.git Cascade ascii string added for SIP. --- diff --git a/CMake/UsePyQt4EXT.cmake b/CMake/UsePyQt4EXT.cmake index 6f13a939..361a9fef 100644 --- a/CMake/UsePyQt4EXT.cmake +++ b/CMake/UsePyQt4EXT.cmake @@ -112,6 +112,9 @@ MACRO(PYQT4_WRAP_SIP_EXT outfiles) LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPygp_XY.cc) SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPygp_XY.cc) + LIST(APPEND _output ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyTCollection_AsciiString.cc) + SET(${outfiles} ${${outfiles}} ${CMAKE_CURRENT_BINARY_DIR}/sipHYDROPyTCollection_AsciiString.cc) + ADD_CUSTOM_COMMAND( OUTPUT ${_output} COMMAND ${SIP_EXECUTABLE} ${PYQT_SIPFLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/${_input} diff --git a/src/HYDROPy/CAS/TCollection_AsciiString.sip b/src/HYDROPy/CAS/TCollection_AsciiString.sip new file mode 100644 index 00000000..037fa59b --- /dev/null +++ b/src/HYDROPy/CAS/TCollection_AsciiString.sip @@ -0,0 +1,147 @@ +// 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 + +%MappedType TCollection_AsciiString +{ +%TypeHeaderCode +#include +%End + +%TypeCode +#include +%End + +%ConvertToTypeCode + if (sipIsErr == NULL) +#if PY_MAJOR_VERSION < 3 + return (sipPy == Py_None || PyString_Check(sipPy) || PyUnicode_Check(sipPy)); +#else + return (sipPy == Py_None || PyUnicode_Check(sipPy)); +#endif + + if (sipPy == Py_None) + { + // None is the only way to create a null (as opposed to empty) string. + *sipCppPtr = new TCollection_AsciiString(); + + return sipGetState(sipTransferObj); + } + +#if PY_MAJOR_VERSION < 3 + if ( PyString_Check( sipPy ) ) + { + *sipCppPtr = new TCollection_AsciiString( PyString_AS_STRING( sipPy ) ); + + return sipGetState(sipTransferObj); + } +#endif + + QString aQStr; + +// Function qpycore_PyObject_AsQString() +#if defined(Py_UNICODE_WIDE) +#if QT_VERSION >= 0x040200 + aQStr = QString::fromUcs4((const uint *)PyUnicode_AS_UNICODE(sipPy), + PyUnicode_GET_SIZE(sipPy)); +#else + // Note that this code doesn't handle code points greater than 0xffff very + // well. + + Py_UNICODE *ucode = PyUnicode_AS_UNICODE(sipPy); + SIP_SSIZE_T len = PyUnicode_GET_SIZE(sipPy); + + for (SIP_SSIZE_T i = 0; i < len; ++i) + aQStr.append((uint)ucode[i]); +#endif +#else + aQStr = QString::fromUtf16((const ushort *)PyUnicode_AS_UNICODE(sipPy), + PyUnicode_GET_SIZE(sipPy)); +#endif + + TCollection_AsciiString aResStr; + if( !aQStr.isNull() ) + { + QTextCodec* codec = QTextCodec::codecForName( "latin1" ); // alias for ISO-8859-1 + if( codec ) + { + QByteArray str = codec->fromUnicode( aQStr ); + aResStr = TCollection_AsciiString( (Standard_CString)str.constData() ); + } + else + aResStr = TCollection_AsciiString( aQStr.toLatin1().data() ); + } + + *sipCppPtr = new TCollection_AsciiString( aResStr ); + + return sipGetState(sipTransferObj); +%End + +%ConvertFromTypeCode + QString aQStr; + + QTextCodec* codec = QTextCodec::codecForName( "latin1" ); // alias for ISO-8859-1 + if ( !sipCpp->IsEmpty() ) + { + aQStr = codec ? codec->toUnicode( (char*)sipCpp->ToCString(), sipCpp->Length() ) : + QString( (char*)sipCpp->ToCString() ); + } + + PyObject *obj; + +#if defined(Py_UNICODE_WIDE) +#if QT_VERSION >= 0x040200 + QVector ucs4 = aQStr.toUcs4(); + + if ((obj = PyUnicode_FromUnicode(NULL, ucs4.size())) == NULL) + return NULL; + + memcpy(PyUnicode_AS_UNICODE(obj), ucs4.constData(), + ucs4.size() * sizeof (Py_UNICODE)); +#else + // Note that this code doesn't handle code points greater than 0xffff very + // well. + + if ((obj = PyUnicode_FromUnicode(NULL, aQStr.length())) == NULL) + return NULL; + + Py_UNICODE *pyu = PyUnicode_AS_UNICODE(obj); + + for (int i = 0; i < aQStr.length(); ++i) + *pyu++ = (aQStr.at(i)).unicode(); +#endif +#else + if ((obj = PyUnicode_FromUnicode(NULL, aQStr.length())) == NULL) + return NULL; + + memcpy(PyUnicode_AS_UNICODE(obj), aQStr.utf16(), + aQStr.length() * sizeof (Py_UNICODE)); +#endif + + return obj; +%End + +}; + diff --git a/src/HYDROPy/CMakeLists.txt b/src/HYDROPy/CMakeLists.txt index e60e547c..6b704349 100644 --- a/src/HYDROPy/CMakeLists.txt +++ b/src/HYDROPy/CMakeLists.txt @@ -81,6 +81,7 @@ SET(_sip_files SET(_sip_files2 CAS/gp_XY.sip CAS/gp_XYZ.sip + CAS/TCollection_AsciiString.sip CAS/NCollection_Sequence.sip HYDROData_SequenceOfObjects.sip HYDROData_Entity.sip diff --git a/src/HYDROPy/HYDROData.sip b/src/HYDROPy/HYDROData.sip index e0997fcf..5d2b1f22 100644 --- a/src/HYDROPy/HYDROData.sip +++ b/src/HYDROPy/HYDROData.sip @@ -53,6 +53,7 @@ See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com %Include CAS/gp_XY.sip %Include CAS/gp_XYZ.sip +%Include CAS/TCollection_AsciiString.sip %Include CAS/NCollection_Sequence.sip %Include HYDROData_SequenceOfObjects.sip %Include HYDROData_Entity.sip diff --git a/src/HYDROPy/HYDROData_Bathymetry.sip b/src/HYDROPy/HYDROData_Bathymetry.sip index 75b918e3..349318a6 100644 --- a/src/HYDROPy/HYDROData_Bathymetry.sip +++ b/src/HYDROPy/HYDROData_Bathymetry.sip @@ -84,7 +84,7 @@ public: * \param theFileName the path to file * \return \c true if file has been successfully read */ - bool ImportFromFile( const QString& theFileName ); + bool ImportFromFile( const TCollection_AsciiString& theFileName ); protected: