]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Cascade ascii string added for SIP.
authoradv <adv@opencascade.com>
Mon, 30 Dec 2013 08:17:14 +0000 (08:17 +0000)
committeradv <adv@opencascade.com>
Mon, 30 Dec 2013 08:17:14 +0000 (08:17 +0000)
CMake/UsePyQt4EXT.cmake
src/HYDROPy/CAS/TCollection_AsciiString.sip [new file with mode: 0644]
src/HYDROPy/CMakeLists.txt
src/HYDROPy/HYDROData.sip
src/HYDROPy/HYDROData_Bathymetry.sip

index 6f13a939139ca41d1ec1288f4af94f9a3a19443c..361a9feff69f9ecd57fb42f7942d7cfaa76ad326 100644 (file)
@@ -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 (file)
index 0000000..037fa59
--- /dev/null
@@ -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 <TCollection_AsciiString.hxx>
+%End
+
+%MappedType TCollection_AsciiString
+{
+%TypeHeaderCode
+#include <NCollection_Sequence.hxx>
+%End
+
+%TypeCode
+#include <qtextcodec.h>
+%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<uint> 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
+  
+};
+
index e60e547c24365834a35ba4ce168190ce41cb891a..6b7043498cc2c493c1357d86e4a8bb4d3cbebd28 100644 (file)
@@ -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
index e0997fcf617b69619e108ffe5eb5c08c8ab5a97a..5d2b1f22a824bffdf481f08e53b4d541ca3f0966 100644 (file)
@@ -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
index 75b918e3e246f049aabf1fda6c14ae5d79fe1846..349318a679dc1e316f2b02630aed237344d01356 100644 (file)
@@ -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: