Salome HOME
Merge Python 3 porting: additional chnages.
authorrnv <rnv@opencascade.com>
Tue, 27 Jun 2017 16:07:30 +0000 (19:07 +0300)
committerrnv <rnv@opencascade.com>
Tue, 27 Jun 2017 16:07:30 +0000 (19:07 +0300)
16 files changed:
bin/appliskel/tests/salomeInstance/instances.py
bin/salome_utils.py
idl/SALOMEDS.idl
src/Basics/Basics_Utils.cxx
src/Basics/Basics_Utils.hxx
src/HDFPersist/HDFfile.cc
src/KERNEL_PY/salome_study.py
src/SALOMEDS/SALOMEDS_Client.cxx
src/SALOMEDS/SALOMEDS_Study.cxx
src/SALOMEDS/SALOMEDS_Study.hxx
src/SALOMEDS/SALOMEDS_Study_i.cxx
src/SALOMEDS/SALOMEDS_Study_i.hxx
src/SALOMEDS/Test/SALOMEDSTest_AttributeComment.cxx
src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx
src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx
src/SALOMESDS/TestSalomeSDS.py

index 50ecfa80d7b90528fb0cce416b08ec040495988a..02a52cc2e80ead9c0872a34db1abd3944801d1d4 100644 (file)
@@ -91,13 +91,13 @@ class TestLauncher(unittest.TestCase):
 
     # Connect to one instance
     import runConsole
-    port = all_instances[len(all_instances)/2].get_port()
+    port = all_instances[len(all_instances)//2].get_port()
     print("Connect to instance running on port", port)
     self.__connectToInstance(port)
 
     # Connect to another instance
     import runConsole
-    port = all_instances[len(all_instances)/4].get_port()
+    port = all_instances[len(all_instances)//4].get_port()
     print("Connect to instance running on port", port)
     self.__connectToInstance(port)
 
index 603b8168ce64d533acd0f7251d2b5cfcf97567df..5c229733082bc92d7146b690169d7c4831d30e76 100644 (file)
@@ -56,10 +56,9 @@ def _try_bool( arg ):
     are supported.
     If <arg> does not represent a boolean, an exception is raised.
     """
-    import types
-    if type( arg ) == bool  :
+    if isinstance(arg, bool)  :
         return arg
-    elif type( arg ) == bytes  :
+    elif isinstance(arg, (str, bytes)):
         v = str( arg ).lower()
         if   v in [ "yes", "y", "true"  ]: return True
         elif v in [ "no",  "n", "false" ]: return False
index bc22b3d339437d8859e606cefd945c9eadf4b7d1..eb14c2fa06516d9e39bbef8b5e82b59354aa745d 100644 (file)
@@ -41,7 +41,7 @@ module SALOMEDS
 {
 /*! \brief Name of the file in which the %Study is saved.
 */
-  typedef string URLPath;
+  typedef wstring URLPath;
 
 /*! \brief Main identifier of an object in %SALOME application
 */
@@ -55,6 +55,8 @@ module SALOMEDS
 */
   typedef string SalomeReference;
 
+//! List of file names
+  typedef sequence<string> ListOfFileNames;
 //! List of modification dates of a study
   typedef sequence<string> ListOfDates ;
 //! An unbounded sequence of strings
@@ -125,6 +127,7 @@ module SALOMEDS
 
 */
     SComponent NewComponent(in string ComponentDataType) raises(LockProtection);
+
 /*! \brief Definition of the instance to the %SComponent
 
     Defines the instance to the %SComponent.
@@ -246,8 +249,7 @@ module SALOMEDS
       \param anObject The %SObject which will be identified
       \param theGUID GUID has the following format "00000000-0000-0000-0000-000000000000"
 */
-
-     void SetGUID(in SObject anObject, in string theGUID) raises(LockProtection);
+    void SetGUID(in SObject anObject, in string theGUID) raises(LockProtection);
 /*!
 Searches for a definite %SObject with a definite GUID and returns True if it finds it.
 
@@ -402,7 +404,10 @@ Searches for a definite %SObject with a definite GUID and returns True if it fin
 
    This is equivalent to the methods setName() & getName()
 */
-    readonly attribute string Name; // equivalent to getName()
+    attribute wstring Name; // equivalent to getName()
+
+/*! \brief  Indicate the file where the %study has been saved
+*/
 
 //! Sequence containing %SObjects
     typedef sequence<SObject> ListOfSObject;
@@ -518,7 +523,7 @@ Searches for a definite %SObject with a definite GUID and returns True if it fin
 
 /*! \brief  Indicate the file where the %study has been saved
 */
-    attribute string URL;
+    attribute wstring URL;
 
 /*! \brief List of %SObjects
 
index 73b4e800ee4bb566668877cfd708cee55bbd86ac..97d6c0b5fbb247d508ded5b24980f8caebaa6e4f 100644 (file)
@@ -106,6 +106,36 @@ namespace Kernel_Utils
     return guid;
   }
 
+  const wchar_t* decode(const char* encoded)
+  {
+    setlocale(LC_ALL, "");
+    size_t length = strlen(encoded) + sizeof(char);
+    wchar_t* decoded = new wchar_t[length];
+    memset( decoded, '\0', length);
+    mbstowcs(decoded, encoded, length);
+    return decoded;
+  }
+
+  const wchar_t* decode_s(std::string encoded)
+  {
+    return decode(encoded.c_str());
+  }
+
+  const char* encode(const wchar_t* decoded)
+  {
+    setlocale(LC_ALL, "");
+    size_t length = std::wcslen(decoded) + sizeof(wchar_t);
+    char* encoded = new char[length];
+    memset( encoded, '\0', length);
+    wcstombs(encoded, decoded, length);
+    return encoded;
+  }
+
+  std::string encode_s(const wchar_t* decoded)
+  {
+    return std::string(encode(decoded));
+  }
+
 #ifndef WIN32
   void print_traceback()
   {
index 5843afb7524c41a3232040f01c2e5edd05bb84ed..cef9dc3fc7947e38626166404276100f09b84683 100644 (file)
@@ -56,6 +56,11 @@ namespace Kernel_Utils
     ObjectdID       //!< Global usage object identifier ID
   };
 
+  const wchar_t* decode(const char* encoded);
+  const wchar_t* decode_s(std::string encoded);
+  const char* encode(const wchar_t* decoded);
+  std::string encode_s(const wchar_t* decoded);
+
   //! Get predefined GUID
   BASICS_EXPORT std::string GetGUID( GUIDtype );
 #ifndef WIN32
index 71b44e1129f2cce3f186d5d1ae171b75c5c0e62a..d372e460c2dc61d0a9872c0125e50684b48f4379 100644 (file)
@@ -58,29 +58,36 @@ void HDFfile::CreateOnDisk()
 
 void HDFfile::OpenOnDisk(hdf_access_mode access_mode)
 {
-  _access_mode = access_mode;
+       _access_mode = access_mode;
+       std::string msgerr;
 
-  switch (_access_mode)
-    {
-    case HDF_RDWR :
-      if (access(_name,F_OK))
+       switch (_access_mode)
        {
-         if ((_id = HDFfileCreate(_name)) < 0) 
-           throw HDFexception("Can't open HDF file");
+       case HDF_RDWR:
+               if (access(_name, F_OK))
+               {
+                       if ((_id = HDFfileCreate(_name)) < 0) {
+                               msgerr = "Can't create HDF in RW mode file" + std::string(_name);
+                               throw HDFexception(msgerr.c_str());
+                       }
+               }
+               else if ((_id = HDFfileOpen(_name, _access_mode)) < 0) {
+                       msgerr = "Can't open HDF in RW mode file " + std::string(_name);
+                       throw HDFexception(msgerr.c_str());
+               }
+               break;
+
+       case HDF_RDONLY:
+               if ((_id = HDFfileOpen(_name, _access_mode)) < 0) {
+                       msgerr = "Can't open HDF in RO mode file " + std::string(_name);
+                       throw HDFexception(msgerr.c_str());
+               }
+               break;
+
+       default:
+               msgerr = "Can't open HDF file " + std::string(_name) + " : bad acces option";
+               throw HDFexception(msgerr.c_str());
        }
-      else
-       if ((_id = HDFfileOpen(_name,_access_mode)) < 0)
-         throw HDFexception("Can't open HDF file");
-      break;
-      
-    case HDF_RDONLY :
-      if ((_id = HDFfileOpen(_name,_access_mode)) < 0)
-       throw HDFexception("Can't open HDF file");
-      break;
-      
-    default :
-      throw HDFexception("Can't open HDF file : bad acces option");
-    }
 }
 
 void HDFfile::CloseOnDisk()
index be6d72f2932813be3890a65822f28c816087d088..5626aecdf8b13c3722364f03b1a79d6014d43d8e 100755 (executable)
@@ -302,7 +302,9 @@ def salome_study_init(theStudyPath=None):
         pass
 
     import types
-    if theStudyPath and type(theStudyPath) == types.StringType:
+    if theStudyPath and isinstance(theStudyPath, (str, bytes)):
+        if isinstance(theStudyPath, bytes):
+            theStudyPath = str(theStudyPath, 'UTF8')
         openStudy(theStudyPath)
 
     myStudyName = myStudy._get_Name()
index 12662b5f1890af59745057ad31cfa99044d718b6..db0f0e245137dd402820f221519ff99754ed7ec0 100644 (file)
@@ -30,6 +30,7 @@
 #include CORBA_SERVER_HEADER(SALOMEDS)
 #include "SALOMEDS_AttributeName_i.hxx"
 #include "SALOME_KernelServices.hxx"
+#include "Basics_Utils.hxx"
 #include "utilities.h"
 #include "HDFOI.hxx"
 
@@ -192,7 +193,7 @@ static void Test()
   DumpStudy();
   
   // Save as
-  myStudy->SaveAs("/home/edeville/Study1.hdf", false, false);
+  myStudy->SaveAs(Kernel_Utils::decode("/home/edeville/Study1.hdf"), false, false);
 
   // Get Persistent Reference of the study test
   name = myStudy->GetPersistentReference();
index 0583c10cacbac8fc165140fbcb3cd25b51b0a0f5..86629e27142cfb4d9cb0a410b318bbf2327ff5ff 100644 (file)
@@ -125,8 +125,9 @@ bool SALOMEDS_Study::Open(const std::string& theStudyUrl)
 {
   if(CORBA::is_nil(_corba_impl))
     return false;
-
-  if (!_corba_impl->Open(theStudyUrl.c_str()))
+  std::wstring wtheStudyUrl = std::wstring(theStudyUrl.begin(), theStudyUrl.end());
+  
+  if (!_corba_impl->Open( (wchar_t*)wtheStudyUrl.c_str() ) )
     return false;
 
   return true;
@@ -145,7 +146,7 @@ bool SALOMEDS_Study::SaveAs(const std::string& theUrl, bool theMultiFile, bool t
   if(CORBA::is_nil(_corba_impl))
     return false;
 
-  return _corba_impl->SaveAs((char*)theUrl.c_str(), theMultiFile, theASCII);
+  return _corba_impl->SaveAs(Kernel_Utils::decode_s(theUrl), theMultiFile, theASCII);
 }
 
 SALOMEDS_Driver_i* GetDriver(const SALOMEDSImpl_SObject& theObject, CORBA::ORB_ptr orb)
@@ -497,10 +498,19 @@ std::string SALOMEDS_Study::Name()
     SALOMEDS::Locker lock;
     aName = _local_impl->Name();
   }
-  else aName = _corba_impl->Name();
+  else aName = Kernel_Utils::encode_s(_corba_impl->Name());
   return aName;
 }
 
+void SALOMEDS_Study::Name(const std::string& theName)
+{
+  if (_isLocal) {
+    SALOMEDS::Locker lock;
+    _local_impl->Name(theName);
+  }
+  else _corba_impl->Name(Kernel_Utils::decode_s(theName));
+}
+
 bool SALOMEDS_Study::IsSaved()
 {
   bool isSaved;
@@ -549,7 +559,8 @@ std::string SALOMEDS_Study::URL()
     SALOMEDS::Locker lock;
     aURL = _local_impl->URL();
   }
-  else aURL = _corba_impl->URL();
+  else 
+      aURL = Kernel_Utils::encode_s(_corba_impl->URL());
   return aURL;
 }
 
@@ -559,7 +570,7 @@ void SALOMEDS_Study::URL(const std::string& url)
     SALOMEDS::Locker lock;
     _local_impl->URL(url);
   }
-  else _corba_impl->URL((char*)url.c_str());
+  else _corba_impl->URL(Kernel_Utils::decode_s(url));
 }
 
 std::vector<_PTR(SObject)> SALOMEDS_Study::FindDependances(const _PTR(SObject)& theSO)
index 4f3b6db1fcb544d28f9b92875d01ab64e14f9ff7..affbad4fcb48764803aaa502b04c844f1f4bc7c8 100644 (file)
@@ -80,6 +80,7 @@ public:
   virtual _PTR(SComponentIterator) NewComponentIterator();
   virtual _PTR(StudyBuilder) NewBuilder();
   virtual std::string Name();
+  virtual void  Name(const std::string& name);
   virtual bool IsSaved();
   virtual void  IsSaved(bool save);
   virtual bool IsModified();
index 1ac5ee0a3123f6eafcf71cd408c019e6745d09b1..19abf1b64cd4e0a6278636dc4c9590f72c802073 100644 (file)
@@ -372,7 +372,7 @@ void SALOMEDS_Study_i::Clear()
  *  Purpose  : Open a Study from it's persistent reference
  */
 //============================================================================
-bool SALOMEDS_Study_i::Open(const char* aUrl)
+bool SALOMEDS_Study_i::Open(const wchar_t* aWUrl)
   throw(SALOME::SALOME_Exception)
 {
   if (!_closed)
@@ -382,7 +382,8 @@ bool SALOMEDS_Study_i::Open(const char* aUrl)
 
   Unexpect aCatch(SalomeException);
   MESSAGE("Begin of SALOMEDS_Study_i::Open");
-
+  
+  std::string aUrl = Kernel_Utils::encode_s(aWUrl);
   bool res = _impl->Open(std::string(aUrl));
 
   // update desktop title with new study name
@@ -411,11 +412,13 @@ CORBA::Boolean SALOMEDS_Study_i::Save(CORBA::Boolean theMultiFile, CORBA::Boolea
  *  Purpose  : Save a study to the persistent reference aUrl
  */
 //============================================================================
-CORBA::Boolean SALOMEDS_Study_i::SaveAs(const char* aUrl, CORBA::Boolean theMultiFile, CORBA::Boolean theASCII)
+CORBA::Boolean SALOMEDS_Study_i::SaveAs(const wchar_t* aWUrl, CORBA::Boolean theMultiFile, CORBA::Boolean theASCII)
 {
   SALOMEDS::Locker lock;
   if (_closed)
     throw SALOMEDS::Study::StudyInvalidReference();
+  
+  std::string aUrl = Kernel_Utils::encode_s(aWUrl);
   return _impl->SaveAs(std::string(aUrl), _factory, theMultiFile, theASCII);
 }
 
@@ -832,11 +835,23 @@ SALOMEDS::StudyBuilder_ptr SALOMEDS_Study_i::NewBuilder()
  *  Purpose  : get study name
  */
 //============================================================================
-char* SALOMEDS_Study_i::Name()
+wchar_t* SALOMEDS_Study_i::Name()
 {
   SALOMEDS::Locker lock; 
   // Name is specified as IDL attribute: user exception cannot be raised
-  return CORBA::string_dup(_impl->Name().c_str());
+  return CORBA::wstring_dup(Kernel_Utils::decode_s(_impl->Name()));
+}
+
+//============================================================================
+/*! Function : Name
+ *  Purpose  : set study name
+ */
+//============================================================================
+void SALOMEDS_Study_i::Name(const wchar_t* wname)
+{
+  SALOMEDS::Locker lock;
+  // Name is specified as IDL attribute: user exception cannot be raised
+  _impl->Name(Kernel_Utils::encode_s(wname));
 }
 
 //============================================================================
@@ -899,11 +914,11 @@ void SALOMEDS_Study_i::Modified()
  *  Purpose  : get URL of the study (persistent reference of the study)
  */
 //============================================================================
-char* SALOMEDS_Study_i::URL()
+wchar_t* SALOMEDS_Study_i::URL()
 {
-  SALOMEDS::Locker lock; 
+  SALOMEDS::Locker lock;
   // URL is specified as IDL attribute: user exception cannot be raised
-  return CORBA::string_dup(_impl->URL().c_str());
+  return CORBA::wstring_dup(Kernel_Utils::decode_s(_impl->URL()));
 }
 
 //============================================================================
@@ -911,11 +926,11 @@ char* SALOMEDS_Study_i::URL()
  *  Purpose  : set URL of the study (persistent reference of the study)
  */
 //============================================================================
-void SALOMEDS_Study_i::URL(const char* url)
+void SALOMEDS_Study_i::URL(const wchar_t* wurl)
 {
   SALOMEDS::Locker lock; 
   // URL is specified as IDL attribute: user exception cannot be raised
-  _impl->URL(std::string((char*)url));
+  _impl->URL(Kernel_Utils::encode_s(wurl));
 
   // update desktop title with new study name
   NameChanged();
index 232b0fb4cadfaaae13362c299e5f5bd91402d9fe..d1c3d7f22eb546f915d980acaa785fa7aba609cb 100644 (file)
@@ -76,7 +76,7 @@ public:
     \param char* arguments, the study URL
     \return Study_ptr arguments
   */
-  virtual bool Open(const char* aStudyUrl) throw (SALOME::SALOME_Exception);
+  virtual bool Open(const wchar_t* aStudyUrl) throw (SALOME::SALOME_Exception);
 
   //! method to save a Study
   virtual CORBA::Boolean Save(CORBA::Boolean theMultiFile, CORBA::Boolean theASCII);
@@ -85,7 +85,7 @@ public:
   /*!
     \param char* arguments, the new URL of the study
   */
-  virtual CORBA::Boolean SaveAs(const char* aUrl, CORBA::Boolean theMultiFile, CORBA::Boolean theASCII);
+  virtual CORBA::Boolean SaveAs(const wchar_t* aUrl, CORBA::Boolean theMultiFile, CORBA::Boolean theASCII);
 
   //! method to copy the object
   /*!
@@ -202,7 +202,13 @@ public:
   /*!
     \return char* arguments, the study name
   */
-  virtual char* Name();
+  virtual wchar_t* Name();
+
+  //! method to set study name
+  /*!
+    \param name char* arguments, the study name
+  */
+  virtual void Name(const wchar_t* name);
 
   //! method to get if study has been saved
   /*!
@@ -229,13 +235,13 @@ public:
   /*!
     \return char* arguments, the study URL 
   */
-  virtual char* URL();
+  virtual wchar_t* URL();
 
  //! method to set URL of the study
   /*!
     \param url char* arguments, the study URL
   */
-  virtual void  URL(const char* url);
+  virtual void URL(const wchar_t* url);
 
   static void IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute);
 
index 455bde6b1ff39e48cb77bfc9633208a6c92afd05..07f9e976b68ea663a9c9eb480024dca83fa36ba0 100755 (executable)
@@ -25,6 +25,8 @@
  * Use code of SALOMEDS_AttributeComment.cxx
  */
 
+//#include "Basics_Utils.hxx"
+
 void SALOMEDSTest::testAttributeComment()
 {
   //Create Study
index c76daf90883852431f1c47723b37a2dab274b1a9..773f16e5fa3354676d9a6a6fa3fac726c5c572c6 100644 (file)
@@ -1583,6 +1583,17 @@ std::string SALOMEDSImpl_Study::Name()
   return Kernel_Utils::GetBaseName( _name, false );
 }
 
+//============================================================================
+/*! Function : Name
+ *  Purpose  : set study name
+ */
+//============================================================================
+void SALOMEDSImpl_Study::Name(const std::string& name)
+{
+  _errorCode = "";
+  _name = name;
+}
+
 //============================================================================
 /*! Function : IsSaved
  *  Purpose  : get if study has been saved
index f1c1d23ba124cce9f562517b9222640dff297df7..9ed178cf6dbb80d6c991ab970bdc812319b9338d 100644 (file)
@@ -195,6 +195,9 @@ public:
  
   //! method to get study name
   virtual std::string Name();
+
+  //! method to set study name
+  virtual void  Name(const std::string& name);
   
   //! method to get if study has been saved
   virtual bool IsSaved();
index a4302f27cb3d5bd6f684e3d4ef48d4a48d48ee6d..e00a5ed7787005490c38ad502fb920d12b6809c2 100644 (file)
@@ -48,7 +48,7 @@ def work(t):
     import TestSalomeSDSHelper0
     import os,subprocess
     fname=os.path.splitext(TestSalomeSDSHelper0.__file__)[0]+".py"
-    proc=subprocess.Popen(["python",fname],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
+    proc = subprocess.Popen(["python3", fname], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     out,err=proc.communicate()
     if proc.returncode!=0:
       print(out)