From 753e90a4b028a43d726fc9b13be119a2f725c447 Mon Sep 17 00:00:00 2001 From: mbs Date: Sat, 9 Dec 2023 22:21:12 +0000 Subject: [PATCH] [bos#35161][EDF](2023-T1) Automatic backup - initial commit --- src/LightApp/LightApp_Application.cxx | 24 +++++++++++++++++- src/LightApp/LightApp_DataModel.cxx | 22 ++++++++++++++-- src/LightApp/LightApp_DataModel.h | 2 +- src/LightApp/LightApp_Study.cxx | 33 ++++++++++++++++++++++-- src/LightApp/LightApp_Study.h | 4 ++- src/SUIT/SUIT_Study.cxx | 31 +++++++++++++++++++---- src/SUIT/SUIT_Study.h | 2 +- src/SalomeApp/SalomeApp_Study.cxx | 36 ++++++++++++++++++++++++--- src/SalomeApp/SalomeApp_Study.h | 2 +- 9 files changed, 138 insertions(+), 18 deletions(-) diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index f14da6ff2..7be6a4c19 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -224,6 +224,15 @@ #include +//--------------------------------------------------------- +#define USE_DEBUG +//#define MB_IGNORE_QT +//#define MB_FULL_DUMP +#define MBCLASSNAME "LightApp_Application" +#include "MBDebug.h" +// <-- insert includes for addtional debug headers here! +//--------------------------------------------------------- + #define ToolBarMarker 0 #define DockWidgetMarker 1 @@ -373,6 +382,7 @@ LightApp_Application::LightApp_Application() myPrefs( 0 ), myScreenHelper(new LightApp_FullScreenHelper()) { + DBG_FUN(); Q_INIT_RESOURCE( LightApp ); STD_TabDesktop* desk = new STD_TabDesktop(); @@ -485,6 +495,7 @@ LightApp_Application::LightApp_Application() */ LightApp_Application::~LightApp_Application() { + DBG_FUN(); savePreferences(); delete mySelMgr; delete myScreenHelper; @@ -494,6 +505,7 @@ LightApp_Application::~LightApp_Application() /*!Start application.*/ void LightApp_Application::start() { + DBG_FUN(); CAM_Application::start(); updateWindows(); @@ -511,6 +523,7 @@ void LightApp_Application::start() /*!Closeapplication.*/ void LightApp_Application::closeApplication() { + DBG_FUN(); #ifndef DISABLE_QTXWEBBROWSER QProcess::startDetached( "HelpBrowser", QStringList() << QString( "--remove=%1" ).arg( QApplication::instance()->applicationPid() ) ); @@ -2219,6 +2232,7 @@ void LightApp_Application::onStudyCreated( SUIT_Study* theStudy ) */ void LightApp_Application::onStudyOpened( SUIT_Study* theStudy ) { + DBG_FUN(); SUIT_DataObject* aRoot = 0; if ( theStudy && theStudy->root() ) { @@ -2250,9 +2264,12 @@ void LightApp_Application::onStudyOpened( SUIT_Study* theStudy ) /*!Protected SLOT. On study saved.*/ void LightApp_Application::onStudySaved( SUIT_Study* s ) { + DBG_FUN(); QtxMRUAction* mru = ::qobject_cast( action( MRUId ) ); - if ( mru && s ) + if ( mru && s ) { + MSGEL("...adding [" << s->studyName().toStdString() << "] to MRU"); mru->insert( s->studyName() ); + } emit studySaved(); } @@ -2260,6 +2277,7 @@ void LightApp_Application::onStudySaved( SUIT_Study* s ) /*!Protected SLOT. On study closed.*/ void LightApp_Application::onStudyClosed( SUIT_Study* /*s*/ ) { + DBG_FUN(); /* disconnect( this, SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ), this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ) ); @@ -2288,6 +2306,7 @@ void LightApp_Application::onDesktopActivated() void LightApp_Application::studyOpened( SUIT_Study* s ) { + DBG_FUN(); CAM_Application::studyOpened( s ); updateWindows(); @@ -2296,6 +2315,7 @@ void LightApp_Application::studyOpened( SUIT_Study* s ) void LightApp_Application::studySaved( SUIT_Study* s ) { + DBG_FUN(); CAM_Application::studyOpened( s ); SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); if ( aResMgr && activeStudy() ) { @@ -4971,6 +4991,8 @@ void LightApp_Application::onWCDestroyed( QObject* ob ) void LightApp_Application::onMRUActivated( const QString& name ) { + DBG_FUN(); + ARG(name); SUIT_Session* s = SUIT_Session::session(); if ( s && s->activeApplication() == this ) onOpenDoc( name ); diff --git a/src/LightApp/LightApp_DataModel.cxx b/src/LightApp/LightApp_DataModel.cxx index 2729b4d5a..e057671aa 100644 --- a/src/LightApp/LightApp_DataModel.cxx +++ b/src/LightApp/LightApp_DataModel.cxx @@ -34,12 +34,22 @@ #include #include +//--------------------------------------------------------- +#define USE_DEBUG +//#define MB_IGNORE_QT +//#define MB_FULL_DUMP +#define MBCLASSNAME "LightApp_DataModel" +#include "MBDebug.h" +// <-- insert includes for addtional debug headers here! +//--------------------------------------------------------- + /*! Constructor */ LightApp_DataModel::LightApp_DataModel( CAM_Module* theModule ) : CAM_DataModel( theModule ) { + DBG_FUN(); myGroupId = 0; if( module() ) myGroupId = qHash( module()->name() ); @@ -50,6 +60,7 @@ LightApp_DataModel::LightApp_DataModel( CAM_Module* theModule ) */ LightApp_DataModel::~LightApp_DataModel() { + DBG_FUN(); } /*! @@ -57,6 +68,7 @@ LightApp_DataModel::~LightApp_DataModel() */ bool LightApp_DataModel::open( const QString&, CAM_Study*, QStringList ) { + DBG_FUN(); emit opened(); //TODO: is it really needed? to be removed maybe... return true; } @@ -66,6 +78,7 @@ bool LightApp_DataModel::open( const QString&, CAM_Study*, QStringList ) */ bool LightApp_DataModel::save( QStringList& ) { + DBG_FUN(); emit saved(); return true; } @@ -73,9 +86,12 @@ 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(); + DBG_FUN(); + ARG(isBackup); + if (!isBackup) + emit saved(); return true; } @@ -93,6 +109,7 @@ bool LightApp_DataModel::dumpPython( const QString&, CAM_Study*, bool, QStringLi */ bool LightApp_DataModel::close() { + DBG_FUN(); emit closed(); return true; } @@ -119,6 +136,7 @@ void LightApp_DataModel::updateWidgets() */ void LightApp_DataModel::update( LightApp_DataObject*, LightApp_Study* ) { + DBG_FUN(); // san: Previously modelRoot was casted to LightApp_ModuleObject*, // BUT this is incorrect: in full SALOME the model root has different type. // Hopefully LightApp_DataObject* is sufficient here. diff --git a/src/LightApp/LightApp_DataModel.h b/src/LightApp/LightApp_DataModel.h index 98f9d71aa..23d2c29e6 100644 --- a/src/LightApp/LightApp_DataModel.h +++ b/src/LightApp/LightApp_DataModel.h @@ -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*, diff --git a/src/LightApp/LightApp_Study.cxx b/src/LightApp/LightApp_Study.cxx index 222b2ae04..b08fd5d3e 100644 --- a/src/LightApp/LightApp_Study.cxx +++ b/src/LightApp/LightApp_Study.cxx @@ -36,12 +36,22 @@ #include +//--------------------------------------------------------- +#define USE_DEBUG +//#define MB_IGNORE_QT +//#define MB_FULL_DUMP +#define MBCLASSNAME "LightApp_Study" +#include "MBDebug.h" +// <-- insert includes for addtional debug headers here! +//--------------------------------------------------------- + /*! Constructor. */ LightApp_Study::LightApp_Study( SUIT_Application* app ) : CAM_Study( app ) { + DBG_FUN(); // HDF persistence myDriver = new LightApp_HDFDriver(); //myDriver = new LightApp_Driver(); @@ -52,6 +62,7 @@ LightApp_Study::LightApp_Study( SUIT_Application* app ) */ LightApp_Study::~LightApp_Study() { + DBG_FUN(); delete myDriver; myDriver = 0; } @@ -60,6 +71,8 @@ LightApp_Study::~LightApp_Study() */ bool LightApp_Study::createDocument( const QString& theStr ) { + DBG_FUN(); + ARG(theStr); // create myRoot setRoot( new LightApp_RootObject( this ) ); @@ -75,6 +88,8 @@ bool LightApp_Study::createDocument( const QString& theStr ) */ bool LightApp_Study::openDocument( const QString& theFileName ) { + DBG_FUN(); + ARG(theFileName); myDriver->ClearDriverContents(); // create files for models from theFileName if( !openStudyData(theFileName, 0)) // 0 means persistence file @@ -104,6 +119,8 @@ bool LightApp_Study::openDocument( const QString& theFileName ) */ bool LightApp_Study::loadDocument( const QString& theStudyName ) { + DBG_FUN(); + ARG(theStudyName); myDriver->ClearDriverContents(); if( !openStudyData(theStudyName, 0)) // 0 means persistence file return false; @@ -134,8 +151,11 @@ 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*/ ) { + DBG_FUN(); + ARG(theFileName); + ARG(isBackup); SUIT_ResourceMgr* resMgr = application()->resourceMgr(); if( !resMgr ) return false; @@ -190,7 +210,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 - if ( res ) + if ( res && !isBackup) emit saved( this ); return res; @@ -201,6 +221,7 @@ bool LightApp_Study::saveDocumentAs( const QString& theFileName ) */ bool LightApp_Study::saveDocument() { + DBG_FUN(); ModelList list; dataModels( list ); myDriver->ClearDriverContents(); @@ -229,6 +250,8 @@ bool LightApp_Study::saveDocument() */ void LightApp_Study::closeDocument(bool permanently) { + DBG_FUN(); + ARG(permanently); // Inform everybody that this study is going to close when it's most safe to, // i.e. in the very beginning emit closed( this ); @@ -328,6 +351,10 @@ void LightApp_Study::addComponent(const CAM_DataModel* /*dm*/) */ void LightApp_Study::saveModuleData(QString theModuleName, int type, QStringList theListOfFiles) { + DBG_FUN(); + ARG(theModuleName); + ARG(type); + ARG(theListOfFiles); int aNb = theListOfFiles.count(); if ( aNb == 0 ) return; @@ -364,6 +391,8 @@ void LightApp_Study::openModuleData(QString theModuleName, int /*type*/, QString */ bool LightApp_Study::saveStudyData( const QString& theFileName, int /*type*/ ) { + DBG_FUN(); + ARG(theFileName); ModelList list; dataModels( list ); SUIT_ResourceMgr* resMgr = application()->resourceMgr(); if( !resMgr ) diff --git a/src/LightApp/LightApp_Study.h b/src/LightApp/LightApp_Study.h index 1569d467d..d3a5ca953 100644 --- a/src/LightApp/LightApp_Study.h +++ b/src/LightApp/LightApp_Study.h @@ -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/SUIT_Study.cxx b/src/SUIT/SUIT_Study.cxx index 054287882..b1009a501 100644 --- a/src/SUIT/SUIT_Study.cxx +++ b/src/SUIT/SUIT_Study.cxx @@ -28,6 +28,15 @@ #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 ); } diff --git a/src/SUIT/SUIT_Study.h b/src/SUIT/SUIT_Study.h index 5ea1ad479..b61821ab9 100644 --- a/src/SUIT/SUIT_Study.h +++ b/src/SUIT/SUIT_Study.h @@ -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(); diff --git a/src/SalomeApp/SalomeApp_Study.cxx b/src/SalomeApp/SalomeApp_Study.cxx index 96aa82adc..6d9746051 100644 --- a/src/SalomeApp/SalomeApp_Study.cxx +++ b/src/SalomeApp/SalomeApp_Study.cxx @@ -60,6 +60,15 @@ #include #include CORBA_SERVER_HEADER(SALOME_Exception) +//--------------------------------------------------------- +#define USE_DEBUG +//#define MB_IGNORE_QT +//#define MB_FULL_DUMP +#define MBCLASSNAME "SalomeApp_Study" +#include "MBDebug.h" +// <-- insert includes for addtional debug headers here! +//--------------------------------------------------------- + //#define NOTIFY_BY_EVENT class ObserverEvent : public QEvent @@ -391,6 +400,7 @@ private: SalomeApp_Study::SalomeApp_Study( SUIT_Application* app ) : LightApp_Study( app ), myObserver( 0 ) { + DBG_FUN(); myStudyDS = SalomeApp_Application::getStudy(); } @@ -399,6 +409,7 @@ SalomeApp_Study::SalomeApp_Study( SUIT_Application* app ) */ SalomeApp_Study::~SalomeApp_Study() { + DBG_FUN(); if ( myObserver ) { PortableServer::ObjectId_var oid = myObserver->_default_POA()->servant_to_id( myObserver ); myObserver->_default_POA()->deactivate_object( oid.in() ); @@ -447,6 +458,8 @@ _PTR(Study) SalomeApp_Study::studyDS() const */ bool SalomeApp_Study::createDocument( const QString& theStr ) { + DBG_FUN(); + ARG(theStr); MESSAGE( "createDocument" ); setStudyName( QString::fromUtf8(myStudyDS->URL().c_str()) ); @@ -477,6 +490,8 @@ bool SalomeApp_Study::createDocument( const QString& theStr ) */ bool SalomeApp_Study::openDocument( const QString& theFileName ) { + DBG_FUN(); + ARG(theFileName); MESSAGE( "openDocument" ); // read HDF file @@ -547,6 +562,8 @@ bool SalomeApp_Study::openDocument( const QString& theFileName ) */ bool SalomeApp_Study::loadDocument( const QString& theStudyName ) { + DBG_FUN(); + ARG(theStudyName); MESSAGE( "loadDocument" ); setRoot( new SalomeApp_RootObject( this ) ); // create myRoot @@ -595,10 +612,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*/ ) { + DBG_FUN(); + ARG(theFileName); + ARG(isBackup); + 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 +632,7 @@ bool SalomeApp_Study::saveDocumentAs( const QString& theFileName ) if ( LightApp_DataModel* aModel = dynamic_cast( 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); @@ -630,7 +651,7 @@ bool SalomeApp_Study::saveDocumentAs( const QString& theFileName ) res = res && saveStudyData(theFileName, 0); // 0 means persistence file - if ( res ) + if ( res && !isBackup) emit saved( this ); return res; @@ -641,6 +662,7 @@ bool SalomeApp_Study::saveDocumentAs( const QString& theFileName ) */ bool SalomeApp_Study::saveDocument() { + DBG_FUN(); bool store = application()->resourceMgr()->booleanValue( "Study", "store_visual_state", true ); if ( store ) SalomeApp_VisualState( (SalomeApp_Application*)application() ).storeState(); @@ -683,6 +705,7 @@ bool SalomeApp_Study::saveDocument() */ void SalomeApp_Study::closeDocument(bool permanently) { + DBG_FUN(); LightApp_Study::closeDocument(permanently); // close SALOMEDS document @@ -721,6 +744,11 @@ bool SalomeApp_Study::dump( const QString& theFileName, bool isMultiFile, bool toSaveGUI ) { + DBG_FUN(); + ARG(theFileName); + ARG(toPublish); + ARG(isMultiFile); + ARG(toSaveGUI); int savePoint = 0; _PTR(AttributeParameter) ap; _PTR(IParameters) ip = ClientFactory::getIParameters(ap); diff --git a/src/SalomeApp/SalomeApp_Study.h b/src/SalomeApp/SalomeApp_Study.h index 38c6c0012..9f1bb7556 100644 --- a/src/SalomeApp/SalomeApp_Study.h +++ b/src/SalomeApp/SalomeApp_Study.h @@ -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); -- 2.39.2