Salome HOME
Introduce new syntax to openFiles() and saveFiles() Python callback functions, to... V8_2_0rc1
authorvsr <vsr@opencascade.com>
Wed, 30 Nov 2016 13:01:27 +0000 (16:01 +0300)
committervsr <vsr@opencascade.com>
Wed, 30 Nov 2016 13:01:27 +0000 (16:01 +0300)
src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataModelLight.cxx
src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx
src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.h
src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx
src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.h
tools/PyInterp/src/PyInterp_Utils.h

index 031e1124d4f6d8db99193e2130460e29520236c3..99e4222e00224399d8faab6577b5a22217dfd96f 100644 (file)
@@ -70,7 +70,7 @@ bool SALOME_PYQT_DataModelLight::open( const QString& theURL, CAM_Study* study,
 
   setModified( false );
   
-  return aModule->load(theListOfFiles);
+  return aModule->load(theListOfFiles, theURL);
   
 }
 
@@ -95,7 +95,7 @@ bool SALOME_PYQT_DataModelLight::save( QStringList& theListOfFiles)
 
   theListOfFiles.append(QString(aTmpDir.c_str()));
   int listSize = theListOfFiles.size();
-  aModule->save(theListOfFiles);
+  aModule->save(theListOfFiles, myStudyURL);
 
   setModified( false );
 
index ee19eb17305e931fa4951c9f2e381398af013abc..c1791289b815627573db8e0cf0c14ea3718587ef 100644 (file)
@@ -253,24 +253,27 @@ void SALOME_PYQT_ModuleLight::preferencesChanged( const QString& section, const
 /*!
   \brief Save module data. Called when user saves study.
   \param files output list of files where module stores data
+  \param url study URL
   \sa PyModuleHelper::save()
 */
-void SALOME_PYQT_ModuleLight::save( QStringList& files )
+void SALOME_PYQT_ModuleLight::save( QStringList& files, const QString& url )
 {
   // call helper
-  myHelper->save( files );
+  myHelper->save( files, url );
 }
 
 /*
- \brief Load module data. Called when user opens study 
- and activates module.
- \param files list of files where module data is stored
- \sa PyModuleHelper::load()
+  \brief Load module data. Called when user opens study 
+  and activates module.
+  \param files list of files where module data is stored
+  \param url study URL
+  \return \c true if loading has been finished successfully or \c false otherwise
+  \sa PyModuleHelper::load()
 */
-bool SALOME_PYQT_ModuleLight::load( const QStringList& files )
+bool SALOME_PYQT_ModuleLight::load( const QStringList& files, const QString& url )
 {
   // call helper
-  return myHelper->load( files );
+  return myHelper->load( files, url );
 }
 
 /*!
index 33942486fe822f594f28ae6c936248d23431d8a3..b0c9dd6e35d1f1c8ab9d8d2ac32c7e23e37391e1 100644 (file)
@@ -58,8 +58,8 @@ public:
   void            preferencesChanged( const QString&, const QString& );
 
   // persistence & dump python
-  void            save( QStringList& );
-  bool            load( const QStringList& );
+  void            save( QStringList&, const QString& );
+  bool            load( const QStringList&, const QString& );
   void            dumpPython( QStringList& );
 
   // drag-n-drop support
index 33ec8b991d150cf0f38da6e1266384c58683c5bc..2d9e7455058a81430fc58110460abb679ebd172c 100644 (file)
@@ -1374,8 +1374,9 @@ void PyModuleHelper::cloneView( SUIT_ViewWindow* view )
 /*!
   \brief Save module data. Called when user saves study.
   \param files output list of files where module stores data
+  \param url study URL
 */
-void PyModuleHelper::save( QStringList& files )
+void PyModuleHelper::save( QStringList& files, const QString& url )
 {
   FuncMsg fmsg( "PyModuleHelper::save()" );
 
@@ -1391,33 +1392,38 @@ void PyModuleHelper::save( QStringList& files )
   public:     
     SaveReq( PyInterp_Interp* _py_interp,
              PyModuleHelper*  _helper,
-             QStringList&     _files )
+             QStringList&     _files,
+             const QString&   _url )
       : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
         myHelper( _helper ) ,
-        myFiles( _files )
+        myFiles( _files ),
+        myUrl( _url )
     {}
   protected:
     virtual void execute()
     {
-      myHelper->internalSave( myFiles );
+      myHelper->internalSave( myFiles, myUrl );
     }
   private:
     PyModuleHelper* myHelper;
     QStringList&    myFiles;
+    QString         myUrl;
   };
   
   // Posting the request only if dispatcher is not busy!
   // Executing the request synchronously
   if ( !PyInterp_Dispatcher::Get()->IsBusy() )
-    PyInterp_Dispatcher::Get()->Exec( new SaveReq( myInterp, this, files ) );
+    PyInterp_Dispatcher::Get()->Exec( new SaveReq( myInterp, this, files, url ) );
 }
 
 /*
- \brief Load module data. Called when user opens study 
- and activates module.
- \param files list of files where module data is stored
+  \brief Load module data. Called when user opens study 
+  and activates module.
+  \param files list of files where module data is stored
+  \param url study URL
+  \return \c true if loading has been finished successfully or \c false otherwise
 */
-bool PyModuleHelper::load( const QStringList& files )
+bool PyModuleHelper::load( const QStringList& files, const QString& url )
 {
   FuncMsg fmsg( "PyModuleHelper::load()" );
 
@@ -1429,27 +1435,30 @@ bool PyModuleHelper::load( const QStringList& files )
     LoadReq( PyInterp_Interp* _py_interp,
              PyModuleHelper*  _helper,
              QStringList      _files,
+             const QString&   _url,
              bool&            _loaded )
       : PyInterp_LockRequest( _py_interp, 0, true ), // this request should be processed synchronously (sync == true)
         myHelper( _helper ) ,
         myFiles( _files ),
+        myUrl( _url ),
         myLoaded( _loaded )
     {}
   protected:
     virtual void execute()
     {
-      myHelper->internalLoad( myFiles, myLoaded );
+      myHelper->internalLoad( myFiles, myUrl, myLoaded );
     }
   private:
     PyModuleHelper* myHelper;
     QStringList     myFiles;
+    QString         myUrl;
     bool&           myLoaded;
   };
   
   // Posting the request only if dispatcher is not busy!
   // Executing the request synchronously
   if ( !PyInterp_Dispatcher::Get()->IsBusy() )
-    PyInterp_Dispatcher::Get()->Exec( new LoadReq( myInterp, this, files, loaded ) );
+    PyInterp_Dispatcher::Get()->Exec( new LoadReq( myInterp, this, files, url, loaded ) );
 
   return loaded;
 }
@@ -2421,8 +2430,9 @@ void PyModuleHelper::internalCloneView( SUIT_ViewWindow* view )
   \brief Module data saving callback function.
   \internal
   \param files output list of files where module stores data
+  \param url study URL
 */
-void PyModuleHelper::internalSave( QStringList& files )
+void PyModuleHelper::internalSave( QStringList& files, const QString& url )
 {
   FuncMsg fmsg( "--- PyModuleHelper::internalSave()" );
 
@@ -2434,9 +2444,16 @@ void PyModuleHelper::internalSave( QStringList& files )
 
   if ( PyObject_HasAttrString(myPyModule, (char*)"saveFiles") ) {
 
+    // try with two parameters (new syntax)
     PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"saveFiles",
-                                           (char*)"s", files.first().toLatin1().constData() ) );
-
+                                           (char*)"ss",
+                                           files.first().toLatin1().constData(),
+                                           url.toLatin1().constData() ) );
+    if ( !res )
+      // try with single parameter (old syntax)
+      res = PyObject_CallMethod( myPyModule, (char*)"saveFiles",
+                                 (char*)"s", files.first().toLatin1().constData() );
+    
     if ( !res ) {
       PyErr_Print();
     }
@@ -2465,9 +2482,10 @@ void PyModuleHelper::internalSave( QStringList& files )
   \brief Module data loading callback function.
   \internal
   \param files list of files where module data is stored
+  \param url study URL
   \param opened output success flag
 */
-void PyModuleHelper::internalLoad( const QStringList& files, bool& opened )
+void PyModuleHelper::internalLoad( const QStringList& files, const QString& url, bool& opened )
 {
   FuncMsg fmsg( "--- PyModuleHelper::internalLoad()" );
 
@@ -2484,13 +2502,22 @@ void PyModuleHelper::internalLoad( const QStringList& files, bool& opened )
   PyObjWrapper sipList( sipBuildResult( 0, "D", theList, sipType_QStringList, NULL ) );
 #endif
   if ( PyObject_HasAttrString(myPyModule , (char*)"openFiles") ) {
+
+    // try with two parameters (new syntax)
     PyObjWrapper res( PyObject_CallMethod( myPyModule, (char*)"openFiles",
-                                           (char*)"O", sipList.get()));
-    if( !res || !PyBool_Check( res )) {
+                                           (char*)"Os", sipList.get(),
+                                           url.toLatin1().constData() ) );
+
+    if ( !res )
+      // try with single parameter (old syntax)
+      res = PyObject_CallMethod( myPyModule, (char*)"openFiles",
+                                 (char*)"O", sipList.get() );
+
+    if ( !res || !PyBool_Check( res ) ) {
       PyErr_Print();
       opened = false;
     }
-    else{
+    else {
       opened = PyObject_IsTrue( res );
     }
   }
index d4948508030ae4ff20ca317a281079b27c8c7820..f8e0121590770650c2f8ad6a961a5c05544990a2 100644 (file)
@@ -97,8 +97,8 @@ public slots:
   void                       tryCloseView( SUIT_ViewWindow* );
   void                       closeView( SUIT_ViewWindow* );
   void                       cloneView( SUIT_ViewWindow* );
-  void                       save( QStringList& );
-  bool                       load( const QStringList& );
+  void                       save( QStringList&, const QString& );
+  bool                       load( const QStringList&, const QString& );
   void                       dumpPython( QStringList& files );
   bool                       isDraggable( const SUIT_DataObject* ) const;
   bool                       isDropAccepted( const SUIT_DataObject* ) const;
@@ -127,8 +127,8 @@ private:
   void                       internalTryCloseView( SUIT_ViewWindow* );
   void                       internalCloseView( SUIT_ViewWindow* );
   void                       internalCloneView( SUIT_ViewWindow* );
-  void                       internalSave( QStringList& );
-  void                       internalLoad( const QStringList&, bool& );
+  void                       internalSave( QStringList&, const QString& );
+  void                       internalLoad( const QStringList&, const QString&, bool& );
   void                       internalDumpPython( QStringList& );
   bool                       internalIsDraggable( LightApp_DataObject* );
   bool                       internalIsDropAccepted( LightApp_DataObject* );
index 8d6ce8c638acbc9b7dec862399d32a1e9b860aad..d47ff184697451fab277c7778f0c3da609aedc66 100644 (file)
@@ -101,6 +101,14 @@ public:
   {
     Py_XDECREF(myObject);
     myObject = theObjWrapper->myObject;
+    Py_XINCREF(myObject);
+    return *this;
+  }
+  PyObjWrapper& operator=(const PyObjWrapper& theObjWrapper)
+  {
+    Py_XDECREF(myObject);
+    myObject = theObjWrapper.myObject;
+    Py_XINCREF(myObject);
     return *this;
   }
 };