Salome HOME
[bos#35161][EDF](2023-T1) Automatic backup
authormbs <martin.bernhard@opencascade.com>
Sat, 9 Dec 2023 22:21:12 +0000 (22:21 +0000)
committermbs <martin.bernhard@opencascade.com>
Mon, 19 Feb 2024 17:12:38 +0000 (17:12 +0000)
Added temporary debug files. To be removed again when task is finished.

restore study flags after backup

always restore its URL after having backed up a study

removed DEBUG macros

src/LightApp/LightApp_Application.cxx
src/LightApp/LightApp_DataModel.cxx
src/LightApp/LightApp_DataModel.h
src/LightApp/LightApp_Study.cxx
src/LightApp/LightApp_Study.h
src/SUIT/MBDebug.h [new file with mode: 0644]
src/SUIT/SUIT_Study.cxx
src/SUIT/SUIT_Study.h
src/SalomeApp/SalomeApp_Study.cxx
src/SalomeApp/SalomeApp_Study.h

index b1cb7e3bb7700699c931795ffa780757d9cd333a..d86509cc7f6d8ed850dd0fb831b42654572f16c9 100644 (file)
@@ -2251,8 +2251,9 @@ void LightApp_Application::onStudyOpened( SUIT_Study* theStudy )
 void LightApp_Application::onStudySaved( SUIT_Study* s )
 {
   QtxMRUAction* mru = ::qobject_cast<QtxMRUAction*>( action( MRUId ) );
-  if ( mru && s )
+  if ( mru && s ) {
     mru->insert( s->studyName() );
+  }
 
   emit studySaved();
 }
index b8509939298cff352e1ae21685148b6589db468b..3c2f50c54489e7d00c9d5170bd6ef21f21939a44 100644 (file)
@@ -34,6 +34,7 @@
 #include <SUIT_DataBrowser.h>
 #include <SUIT_DataObject.h>
 
+
 /*!
   Constructor
 */
@@ -73,9 +74,10 @@ bool LightApp_DataModel::save( QStringList& )
 /*!
   Emit saved()
 */
-bool LightApp_DataModel::saveAs( const QString&, CAM_Study*, QStringList& )
+bool LightApp_DataModel::saveAs( const QString&, CAM_Study*, QStringList&, bool isBackup/*=false*/ )
 {
-  emit saved();
+  if (!isBackup)
+    emit saved();
   return true;
 }
 
index 859d1d0d75ec99c9f7a856ce96703d3ba1e59e43..882a8486d3d51ff6e7a71bd33dd54bd4b0887abc 100644 (file)
@@ -53,7 +53,7 @@ public:
 
   virtual bool                        open( const QString&, CAM_Study*, QStringList );
   virtual bool                        save( QStringList& );
-  virtual bool                        saveAs( const QString&, CAM_Study*, QStringList& );
+  virtual bool                        saveAs( const QString&, CAM_Study*, QStringList&, bool isBackup=false );
   virtual bool                        close();
   virtual bool                        dumpPython( const QString&,
                                                  CAM_Study*,
index 9aa9403316083dccaba1b99ec4add421919f854f..48bef22a8d7037b32b485b9c1eab0410b213495b 100644 (file)
@@ -36,6 +36,7 @@
 
 #include <set>
 
+
 /*!
   Constructor.
 */
@@ -134,7 +135,7 @@ bool LightApp_Study::loadDocument( const QString& theStudyName )
 /*!
   Saves document
 */
-bool LightApp_Study::saveDocumentAs( const QString& theFileName )
+bool LightApp_Study::saveDocumentAs( const QString& theFileName, bool isBackup/*=false*/ )
 {
   SUIT_ResourceMgr* resMgr = application()->resourceMgr();
   if( !resMgr )
@@ -190,7 +191,7 @@ bool LightApp_Study::saveDocumentAs( const QString& theFileName )
   bool res = saveStudyData(theFileName, 0); // 0 means persistence file
   res = res && CAM_Study::saveDocumentAs( theFileName );
   //SRN: BugID IPAL9377, removed usage of uninitialized variable <res>
-  if ( res )
+  if ( res && !isBackup)
     emit saved( this );
 
   return res;
index a51e5904dd6d7d9851ee4c8619afbd6828fbafe3..1da4d77178d60932fdb02256907ad334184c5942 100644 (file)
@@ -76,10 +76,12 @@ public:
   virtual bool        loadDocument( const QString& ); 
 
   virtual bool        saveDocument();
-  virtual bool        saveDocumentAs( const QString& );
+  virtual bool        saveDocumentAs( const QString& , bool isBackup=false );
 
   virtual void        closeDocument(bool permanently = true);
 
+  virtual bool        dump( const QString&, bool, bool, bool ) { return false; }
+
   virtual bool        isSaved()  const;
   virtual bool        isModified() const;
 
diff --git a/src/SUIT/MBDebug.h b/src/SUIT/MBDebug.h
new file mode 100644 (file)
index 0000000..800d812
--- /dev/null
@@ -0,0 +1,313 @@
+#ifndef MBDebug_HeaderFile\r
+#define MBDebug_HeaderFile\r
+\r
+//---------------------------------------------------------------\r
+// Usage of the logging facilities:\r
+//\r
+//  (1) At the beginning of each class file to be debugged, there\r
+//      should be a static string variable defined with the name\r
+//      of the class. Then, include the "MBDebug.h" header file.\r
+//\r
+//      //---------------------------------------------------------\r
+//      #define USE_DEBUG\r
+//      //#define MB_IGNORE_QT\r
+//      //#define MB_FULL_DUMP\r
+//      #define MBCLASSNAME "ClassName"\r
+//      #include "MBDebug.h"\r
+//      // <-- insert includes for addtional debug headers here!\r
+//      //---------------------------------------------------------\r
+//\r
+//  (2) At the beginning of each class method, call the DBG_FUN\r
+//      macro.\r
+//\r
+//      int ClassName::MyMethod(int x)\r
+//      {\r
+//        DBG_FUN();\r
+//        ...\r
+//      }\r
+//\r
+//      NOTE: For static methods, call the DBG_FUNC() macro!!\r
+//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\r
+//  This debugging/logging class is a "header-only" solution and\r
+//  does NOT require any additional implementation (.cpp) file!\r
+//---------------------------------------------------------------\r
+\r
+#include <iostream>\r
+#include <string>\r
+#include <locale>\r
+#include <codecvt>\r
+#include <list>\r
+#include <map>\r
+#include <set>\r
+#include <vector>\r
+#include <mutex>\r
+#include <thread>\r
+#ifndef MB_IGNORE_QT\r
+# include <QString>\r
+# include <QStringList>\r
+#endif\r
+\r
+static std::mutex mtx;\r
+\r
+//---------------------------------------------------------------\r
+//     Set the debug flags dependent on the preprocessor definitions\r
+//---------------------------------------------------------------\r
+#ifdef USE_DEBUG\r
+#      define MBS_DEBUG_FLAG           MBDebug::DF_DEBUG\r
+#else\r
+#      define MBS_DEBUG_FLAG           0\r
+#endif /*DEBUG*/ \r
+\r
+#define        MBS_DBG_FLAGS                   (MBS_DEBUG_FLAG)\r
+\r
+\r
+//---------------------------------------------------------------\r
+//     Define the global debug macros\r
+//---------------------------------------------------------------\r
+#define DLOG                                                   MBDebug::LogPrint()\r
+#define RETURN(var)                            { RET(var); return (var); }\r
+\r
+#ifdef USE_DEBUG\r
+\r
+# define DBG_FUN()                             MBDebug _dbg(MBCLASSNAME, __FUNCTION__, MBS_DBG_FLAGS, (void*)this)\r
+# define DBG_FUNC()                            MBDebug _dbg(MBCLASSNAME, __FUNCTION__, MBS_DBG_FLAGS)\r
+# define DBG_FUNB(blk)         MBDebug _dbg(MBCLASSNAME, blk, MBS_DBG_FLAGS)\r
+#      define MSGEL(txt)                               MBDebug::LogPrint() <<  ":" << txt << std::endl\r
+#      define PRINT(txt)                               MBDebug::LogPrint() << txt\r
+#      define SHOW2(var,typ)           do { PRINT(std::this_thread::get_id()); DumpVar(#var,(typ)(var)); } while (0)\r
+#      define SHOW(var)                                do { PRINT(std::this_thread::get_id()); DumpVar(#var,var); } while (0)\r
+#      define ARG(var)                                 do { PRINT(std::this_thread::get_id() << ":in:"); DumpVar(#var,var); } while (0)\r
+#      define ARG2(var,typ)            do { PRINT(std::this_thread::get_id() << ":in:"); DumpVar(#var,(typ)(var)); } while (0)\r
+#      define RET(var)                                 do { PRINT(std::this_thread::get_id() << ":out:"); DumpVar(#var,var); } while (0)\r
+#      define MSG(txt)                                 MBDebug::LogPrint() << std::this_thread::get_id() << ":" << txt\r
+\r
+#else  /*!USE_DEBUG*/ \r
+\r
+#      define DBG_FUN()\r
+#      define DBG_FUNC()\r
+#      define DBG_FUNB(blk)\r
+#      define MSGEL(txt)\r
+#      define PRINT(txt)\r
+#      define SHOW2(var,typ)\r
+#      define SHOW(var)\r
+#      define ARG(var)\r
+#      define ARG2(var,typ)\r
+#      define RET(var)\r
+#      define MSG(txt)\r
+\r
+#endif /*USE_DEBUG*/ \r
+\r
+\r
+//---------------------------------------------------------------\r
+//     Declare the debugging and profiling class\r
+//---------------------------------------------------------------\r
+class MBDebug\r
+{\r
+public:\r
+       enum {\r
+               DF_NONE                 = 0x00,         // no debug\r
+               DF_DEBUG                = 0x01          // debug a function\r
+       };\r
+\r
+       MBDebug(const char* aClassName, const char* aFuncName, const short aFlag, void* aThis=NULL)\r
+       :mClassName(aClassName),mFuncName(aFuncName),mThis(aThis),mFlags((unsigned char)aFlag)\r
+  {\r
+       if (mFlags & (DF_DEBUG))\r
+       {\r
+      std::lock_guard<std::mutex> lck(mtx);\r
+               std::cout << std::this_thread::get_id() << ":{ENTER: " << mClassName + "::" + mFuncName;\r
+               if (mThis) std::cout << "(this=" << mThis << ")";\r
+               std::cout << std::endl;\r
+       }\r
+  }\r
+       virtual ~MBDebug()\r
+  {\r
+       if (mFlags & (DF_DEBUG))\r
+    {\r
+      std::lock_guard<std::mutex> lck(mtx);\r
+               std::cout << std::this_thread::get_id() << ":}LEAVE: " << mClassName << "::" << mFuncName << std::endl;\r
+    }\r
+  }\r
+\r
+       // Log file output management\r
+       static std::ostream&    LogPrint()      { return std::cout; }\r
+\r
+private:\r
+       std::string                     mClassName;     // Name of class to be debugged\r
+       std::string                     mFuncName;      // Name of function to be debugged\r
+       void*                           mThis;            // The "this" pointer to the class being debugged\r
+       unsigned char           mFlags;                 // Debug mode flags\r
+};\r
+\r
+\r
+\r
+#define YesNo(b)       (b ? "Yes" : "No")\r
+\r
+\r
+\r
+inline std::string w2s(std::wstring ws)\r
+{\r
+       using convert_typeX = std::codecvt_utf8<wchar_t>;\r
+       std::wstring_convert<convert_typeX, wchar_t> converterX;\r
+       return(converterX.to_bytes(ws));\r
+}\r
+\r
+// Primitive types\r
+inline void DumpVar(const char *szName, char value)\r
+{\r
+  std::lock_guard<std::mutex> lck(mtx);\r
+       DLOG << "[chr]: " << szName << "='" << value << "'" << std::endl;\r
+}\r
+\r
+inline void DumpVar(const char *szName, bool value)\r
+{\r
+  std::lock_guard<std::mutex> lck(mtx);\r
+       DLOG << "[bool]: " << szName << "=" << (value ? "true" : "false") << std::endl;\r
+}\r
+\r
+inline void DumpVar(const char *szName, short value)\r
+{\r
+  std::lock_guard<std::mutex> lck(mtx);\r
+       DLOG  << "[shrt]: " << szName << "=" << value << std::endl;\r
+}\r
+\r
+inline void DumpVar(const char *szName, int value)\r
+{\r
+  std::lock_guard<std::mutex> lck(mtx);\r
+       DLOG << "[int]: " << szName << "=" << value << std::endl;\r
+}\r
+\r
+inline void DumpVar(const char *szName, long value)\r
+{\r
+  std::lock_guard<std::mutex> lck(mtx);\r
+       DLOG << "[long]: " << szName << "=" << value << std::endl;\r
+}\r
+\r
+inline void DumpVar(const char *szName, double value)\r
+{\r
+  std::lock_guard<std::mutex> lck(mtx);\r
+       DLOG << "[dbl]: " << szName << "=" << value << std::endl;\r
+}\r
+\r
+inline void DumpVar(const char *szName, unsigned char value)\r
+{\r
+  std::lock_guard<std::mutex> lck(mtx);\r
+       DLOG << "[byte]: " << szName << "=0x" << std::hex << value << std::dec << std::endl;\r
+}\r
+\r
+inline void DumpVar(const char *szName, unsigned short value)\r
+{\r
+  std::lock_guard<std::mutex> lck(mtx);\r
+       DLOG << "[word]: " << szName << "=0x" << std::hex << value << std::dec << std::endl;\r
+}\r
+\r
+inline void DumpVar(const char *szName, unsigned int value)\r
+{\r
+  std::lock_guard<std::mutex> lck(mtx);\r
+       DLOG << "[uint]: " << szName << "=0x" << std::hex << value << std::dec << std::endl;\r
+}\r
+\r
+inline void DumpVar(const char *szName, unsigned long value)\r
+{\r
+  std::lock_guard<std::mutex> lck(mtx);\r
+       DLOG << "[dword]: " << szName << "=0x" << std::hex << value << std::dec << std::endl;\r
+}\r
+\r
+inline void DumpVar(const char *szName, const char* value)\r
+{\r
+  std::lock_guard<std::mutex> lck(mtx);\r
+       DLOG << "[str]: " << szName << "=\"" << (value ? value : "") << "\"" << std::endl;\r
+}\r
+\r
+inline void DumpVar(const char *szName, const std::string &value)\r
+{\r
+  std::lock_guard<std::mutex> lck(mtx);\r
+       DLOG << "[Str]: " << szName << "=\"" << value << "\"" << std::endl;\r
+}\r
+\r
+inline void DumpVar(const char *szName, const std::wstring &value)\r
+{\r
+  std::lock_guard<std::mutex> lck(mtx);\r
+       DLOG << "[WStr]: " << szName << "=\"" << w2s(value) << "\"" << std::endl;\r
+}\r
+\r
+#ifndef MB_IGNORE_QT\r
+inline void DumpVar(const char *szName, const QString &value)\r
+{\r
+  std::lock_guard<std::mutex> lck(mtx);\r
+       DLOG << "[QStr]: " << szName << "=\"" << value.toStdString() << "\"" << std::endl;\r
+}\r
+\r
+inline void DumpVar(const char *szName, const QStringList &value)\r
+{\r
+  std::lock_guard<std::mutex> lck(mtx);\r
+       DLOG << "[QStrLst]: " << szName << "=[len=" << value.length() << "] {";\r
+  bool first = true;\r
+  QStringList::const_iterator it = value.constBegin();\r
+  for ( ; it != value.constEnd(); ++it)\r
+  {\r
+    DLOG << (first ? "" : ",") << "\"" << (*it).toStdString() << "\"";\r
+    first = false;\r
+  }\r
+  DLOG << "}" << std::endl;\r
+}\r
+#endif\r
+\r
+inline void DumpVar(const char *szName, const void* value)\r
+{\r
+  std::lock_guard<std::mutex> lck(mtx);\r
+       DLOG << "[ptr]: " << szName << "=" << value << std::endl;\r
+}\r
+\r
+\r
+// Collection of primitive types\r
+inline void DumpVar(const char *szName, const std::set<int> &values)\r
+{\r
+  std::lock_guard<std::mutex> lck(mtx);\r
+       DLOG << "[intSet]: " << szName << "={" << values.size() << "}[";\r
+       bool bFirst = true;\r
+       for (auto it=values.cbegin(); it!=values.cend(); ++it) {\r
+               DLOG << (bFirst ? "" : ",") << *it;\r
+    bFirst = false;\r
+  }\r
+       DLOG << "]" << std::endl;\r
+}\r
+\r
+inline void DumpVar(const char *szName, const std::vector<int> &values)\r
+{\r
+  std::lock_guard<std::mutex> lck(mtx);\r
+       DLOG << "[intVect]: " << szName << "={" << values.size() << "}[";\r
+       bool bFirst = true;\r
+       for (auto it=values.cbegin(); it!=values.cend(); ++it) {\r
+               DLOG << (bFirst ? "" : ",") << *it;\r
+    bFirst = false;\r
+  }\r
+       DLOG << "]" << std::endl;\r
+}\r
+\r
+inline void DumpVar(const char *szName, const std::list<bool>& values)\r
+{\r
+  std::lock_guard<std::mutex> lck(mtx);\r
+       DLOG << "[boolList]: " << szName << "={" << values.size() << "}[";\r
+       bool bFirst = true;\r
+       for (auto it=values.cbegin(); it!=values.cend(); ++it) {\r
+               DLOG << (bFirst ? "" : ",") << (*it ? "Y" : "N");\r
+    bFirst = false;\r
+  }\r
+       DLOG << "]" << std::endl;\r
+}\r
+\r
+inline void DumpVar(const char *szName, const std::list<std::string> &values)\r
+{\r
+  std::lock_guard<std::mutex> lck(mtx);\r
+       DLOG << "[strLst]: " << szName << "={" << values.size() << "}[";\r
+       bool bFirst = true;\r
+       for (auto it=values.cbegin(); it!=values.cend(); ++it) {\r
+               DLOG << (bFirst ? "\"" : ", \"") << *it << "\"";\r
+    bFirst = false;\r
+  }\r
+       DLOG << "]" << std::endl;\r
+}\r
+\r
+#endif // MBDebug_HeaderFile\r
+\r
index 5f62d04be8e1383bdb9f1ba0ff3ecf13596812d2..04cebe76158b58856a72589d5bfa602578b08c1f 100644 (file)
 #include "SUIT_MessageBox.h"
 #include "SUIT_Application.h"
 
+//---------------------------------------------------------
+#define USE_DEBUG
+//#define MB_IGNORE_QT
+//#define MB_FULL_DUMP
+#define MBCLASSNAME "SUIT_Study"
+#include "MBDebug.h"
+// <-- insert includes for addtional debug headers here!
+//---------------------------------------------------------
+
 /*!\class SUIT_Study
  * Support study management. Object management. Operation management.
  */
@@ -41,9 +50,11 @@ myIsSaved( false ),
 myIsModified( false ),
 myBlockChangeState( false )
 {
+  DBG_FUN();
   static int _id = 0;
 
   myId = ++_id;
+  SHOW(myId);
 
   myRoot = new SUIT_DataObject();
 }
@@ -51,6 +62,7 @@ myBlockChangeState( false )
 /*!Destructor.*/
 SUIT_Study::~SUIT_Study()
 {
+  DBG_FUN();
   delete myRoot;
   myRoot = 0;
 }
@@ -142,11 +154,19 @@ bool SUIT_Study::openDocument( const QString& fileName )
 /*!
  * Save document as \a fileName. Set file name.
  */
-bool SUIT_Study::saveDocumentAs( const QString& fileName )
-{
-  myName = fileName;
-  myIsSaved = true;
-  myIsModified = false;
+bool SUIT_Study::saveDocumentAs( const QString& fileName, bool isBackup/*=false*/ )
+{
+  DBG_FUN();
+  ARG(fileName);
+  ARG(isBackup);
+  if (!isBackup) {
+    myName = fileName;
+    myIsSaved = true;
+    myIsModified = false;
+  }
+  SHOW(myName);
+  SHOW(myIsSaved);
+  SHOW(myIsModified);
 
   return true;
 }
@@ -156,6 +176,7 @@ bool SUIT_Study::saveDocumentAs( const QString& fileName )
  */
 bool SUIT_Study::saveDocument()
 {
+  DBG_FUN();
   return saveDocumentAs( myName );
 }
 
index 40cc14732ba2ebe23d2489b0ff4b53d0332b167b..fb9b7c25c063f3eb1bc8fb0960f5ef991775a4f2 100644 (file)
@@ -60,7 +60,7 @@ public:
   virtual bool      createDocument( const QString& );
 
   bool              saveDocument();
-  virtual bool      saveDocumentAs( const QString& );
+  virtual bool      saveDocumentAs( const QString& , bool isBackup=false );
 
   virtual void      update();
 
index d7f15aacc9402d5f3ec2590df941f548dd997ab7..d610ff9fb0ec9024f187c2ed161bc3ec1ffbb072 100644 (file)
@@ -60,6 +60,7 @@
 #include <SALOMEconfig.h>
 #include CORBA_SERVER_HEADER(SALOME_Exception)
 
+
 //#define NOTIFY_BY_EVENT
 
 class ObserverEvent : public QEvent
@@ -595,10 +596,14 @@ bool SalomeApp_Study::loadDocument( const QString& theStudyName )
   Saves document
   \param theFileName - name of file
 */
-bool SalomeApp_Study::saveDocumentAs( const QString& theFileName )
+bool SalomeApp_Study::saveDocumentAs( const QString& theFileName, bool isBackup/*=false*/ )
 {
+  bool wasSaved = isSaved();
+  bool wasModified = isModified();
+  std::string oldName = (studyDS() ? studyDS()->Name() : "");
+  std::string oldURL = (studyDS() ? studyDS()->URL() : "");
   bool store = application()->resourceMgr()->booleanValue( "Study", "store_visual_state", false );
-  if ( store )
+  if ( store && !isBackup )
     SalomeApp_VisualState( (SalomeApp_Application*)application() ).storeState();
 
   ModelList list; dataModels( list );
@@ -611,7 +616,7 @@ bool SalomeApp_Study::saveDocumentAs( const QString& theFileName )
     if ( LightApp_DataModel* aModel = 
          dynamic_cast<LightApp_DataModel*>( it.next() ) ) {
       listOfFiles.clear();
-      aModel->saveAs( theFileName, this, listOfFiles );
+      aModel->saveAs( theFileName, this, listOfFiles, isBackup );
       if ( !listOfFiles.isEmpty() )
         saveModuleData(aModel->module()->name(), 0, // 0 means persistence file
                        listOfFiles);
@@ -626,13 +631,26 @@ bool SalomeApp_Study::saveDocumentAs( const QString& theFileName )
   bool isMultiFile = resMgr->booleanValue( "Study", "multi_file", false );
   bool isAscii = resMgr->booleanValue( "Study", "ascii_file", false );
   bool res = studyDS()->SaveAs( theFileName.toUtf8().data(), isMultiFile, isAscii )
-    && CAM_Study::saveDocumentAs( theFileName );
+    && CAM_Study::saveDocumentAs( theFileName, isBackup );
 
   res = res && saveStudyData(theFileName, 0); // 0 means persistence file
 
-  if ( res )
+  if ( res && !isBackup)
     emit saved( this );
 
+  if (isBackup)
+  {
+    // Restore the isSaved and isModified flag after having done backup
+    setIsSaved(wasSaved);
+    setIsModified(wasModified);
+    // If the document hasn't been saved before, reset here its name and URL
+    if (studyDS())
+    {
+      studyDS()->URL(oldURL);
+      studyDS()->Name(oldName);
+    }
+  }
+
   return res;
 }
 
index 39cee0aaea282164ad62b26cc9625ea858e26c46..d14f9295b37c9e568bd9d7c6865a6872c55f56af 100644 (file)
@@ -50,7 +50,7 @@ public:
   virtual bool        loadDocument( const QString& );
 
   virtual bool        saveDocument();
-  virtual bool        saveDocumentAs( const QString& );
+  virtual bool        saveDocumentAs( const QString& , bool isBackup=false );
 
   virtual void        closeDocument(bool permanently = true);