Salome HOME
clear data when new study from button new
authorPaul RASCLE <paul.rascle@edf.fr>
Sun, 10 Nov 2019 14:51:42 +0000 (15:51 +0100)
committerPaul RASCLE <paul.rascle@edf.fr>
Sun, 10 Nov 2019 14:55:50 +0000 (15:55 +0100)
src/HYDROData/HYDROData_Document.cxx
src/HYDROGUI/HYDROGUI_DataModel.cxx
src/HYDROGUI/HYDROGUI_DataModel.h
src/HYDROGUI/HYDROGUI_Module.cxx

index ddbc99338e9dc15e6a06fbe4a2698b2aaee90750..d522a34c88e25834db4d8135fa481d818bd86def 100644 (file)
@@ -37,6 +37,9 @@
 #include <QTextStream>
 #include <QColor>
 
+//#define _DEVDEBUG_
+#include "HYDRO_trace.hxx"
+
 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Document,MMgt_TShared)
 
 #define PYTHON_DOC_NAME "hydro_doc"
@@ -63,6 +66,7 @@ Handle(HYDROData_Document) HYDROData_Document::Document()
   Handle(HYDROData_Document) aResult = 
     HYDROData_Application::GetApplication()->GetDocument();
   if (aResult.IsNull()) {
+    DEBTRACE("new HYDROData_Document");
     aResult = new HYDROData_Document();
     HYDROData_Application::GetApplication()->AddDocument(aResult);
   }
@@ -103,6 +107,7 @@ bool HYDROData_Document::HasDocument()
 
 Data_DocError HYDROData_Document::Load(const char* theFileName)
 {
+  DEBTRACE("Load");
   Handle(TDocStd_Document) aResult;
   TCollection_ExtendedString aPath ((const Standard_CString)theFileName);
   PCDM_ReaderStatus aStatus = (PCDM_ReaderStatus) -1;
@@ -155,6 +160,7 @@ Data_DocError HYDROData_Document::Load(const char* theFileName)
 
 Data_DocError HYDROData_Document::Save(const char* theFileName)
 {
+  DEBTRACE("Save");
   TCollection_ExtendedString aPath ((const Standard_CString)theFileName);
   PCDM_StoreStatus aStatus;
   try {
@@ -187,6 +193,7 @@ Data_DocError HYDROData_Document::Save(const char* theFileName)
 
 void HYDROData_Document::Close()
 {
+  DEBTRACE("Close");
   myDoc->Close();
   HYDROData_Application::GetApplication()->RemoveDocument(this);
 }
@@ -282,6 +289,7 @@ void HYDROData_Document::SetCountDelaunay( int nbDelaunay) const
 bool HYDROData_Document::DumpToPython( const QString& thePyScriptPath,
                                        const bool     theIsMultiFile ) const
 {
+  DEBTRACE("DumpToPython");
   // Try to open the file
   QFile aFile( thePyScriptPath );
   if ( !aFile.open( QIODevice::WriteOnly | QFile::Text ) )
@@ -344,6 +352,7 @@ QStringList HYDROData_Document::DumpToPython( const QString& thePyScriptPath,
                                               MapOfTreatedObjects& theTreatedObjects,
                                               const bool           theIsMultiFile ) const
 {
+  DEBTRACE("DumpToPython");
   QString aDocName = GetDocPyName();
 
   // Append document in to the map of treated objects to prevent names overlaping
@@ -377,6 +386,7 @@ bool HYDROData_Document::dumpPartitionToPython( QFile&               theFile,
                                                 MapOfTreatedObjects& theTreatedObjects,
                                                 const ObjectKind&    theObjectKind ) const
 {
+  DEBTRACE("dumpPartitionToPython");
   if ( !theFile.isOpen() )
     return false;
 
@@ -746,6 +756,7 @@ HYDROData_SequenceOfObjects HYDROData_Document::CollectAllObjects( const ObjectK
 
 HYDROData_Document::HYDROData_Document()
 {
+  DEBTRACE("HYDROData_Document");
   HYDROData_Application::GetApplication()->NewDocument("BinOcaf", myDoc);
   myDoc->SetUndoLimit(UNDO_LIMIT);
   NewID(); // needed to have at least one attribute in initial document to avoid errors
@@ -758,6 +769,7 @@ HYDROData_Document::HYDROData_Document()
 
 HYDROData_Document::HYDROData_Document(const Handle(TDocStd_Document)& theDoc)
 {
+  DEBTRACE("HYDROData_Document");
   myDoc = theDoc;
   myTransactionsAfterSave = 0;
   myLX = -1;
@@ -768,6 +780,7 @@ HYDROData_Document::HYDROData_Document(const Handle(TDocStd_Document)& theDoc)
 
 HYDROData_Document::~HYDROData_Document()
 {
+  DEBTRACE("~HYDROData_Document");
 }
 
 int HYDROData_Document::NewID()
index e9e8bc4559106cc0c8b8e95ad22b624ff4796297..8f3178629fb188c5ff9719fa74500636f5272b0f 100644 (file)
 #include <HYDROData_ShapesGroup.h>
 #endif
 
+//#define _DEVDEBUG_
+#include "HYDRO_trace.hxx"
+
 static HYDROData_SequenceOfObjects myCopyingObjects;
 
 const int ENTRY_COLUMN = 2;
 
 
 HYDROGUI_DataModel::HYDROGUI_DataModel( CAM_Module* theModule )
-: LightApp_DataModel( theModule )
+: LightApp_DataModel( theModule ), myIsAboutToClose(false)
 {
+  DEBTRACE("HYDROGUI_DataModel");
   update( module()->application()->activeStudy()->id() );
 }
 
 HYDROGUI_DataModel::~HYDROGUI_DataModel()
 {
+  DEBTRACE("~HYDROGUI_DataModel");
 }
 
 bool HYDROGUI_DataModel::create( CAM_Study* theStudy )
 {
+  DEBTRACE("create");
     bool status = LightApp_DataModel::create( theStudy );
     if ( status )
         updateDocument();
@@ -102,6 +108,7 @@ bool HYDROGUI_DataModel::open( const QString& theURL,
                                CAM_Study* theStudy,
                                QStringList theFileList )
 {
+  DEBTRACE("open");
   LightApp_DataModel::open( theURL, theStudy, theFileList );
   const int aStudyId = theStudy->id();
 
@@ -154,6 +161,7 @@ bool HYDROGUI_DataModel::open( const QString& theURL,
 
 bool HYDROGUI_DataModel::save( QStringList& theFileList )
 {
+  DEBTRACE("save");
   if( !module()->application()->activeStudy() )
     return false;
   
@@ -203,23 +211,33 @@ bool HYDROGUI_DataModel::saveAs( const QString& theURL,
                                  CAM_Study*,
                                  QStringList& theFileList )
 {
+  DEBTRACE("saveAs");
   myStudyURL = theURL;
   return save( theFileList );
 }
 
 bool HYDROGUI_DataModel::close()
 {
+  DEBTRACE("close");
+  myIsAboutToClose = true;
   HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
   if ( aModule )
       aModule->clearCache();
   return true;
 }
 
+bool HYDROGUI_DataModel::isAboutToClose()
+{
+  DEBTRACE("isAboutToClose " << myIsAboutToClose);
+  return myIsAboutToClose;
+}
+
 bool HYDROGUI_DataModel::dumpPython( const QString& theURL,
                                      CAM_Study*     theStudy,
                                      bool           isMultiFile,
                                      QStringList&   theListOfFiles )
 {
+  DEBTRACE("dumpPython");
   LightApp_DataModel::dumpPython( theURL, theStudy, isMultiFile, theListOfFiles );
 
   int aStudyId = theStudy->id();
@@ -254,6 +272,7 @@ bool HYDROGUI_DataModel::isSaved() const
 
 void HYDROGUI_DataModel::update( const int theStudyId )
 {
+  DEBTRACE("update");
   LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( module()->application() );
   if( !anApp )
     return;
@@ -629,6 +648,7 @@ CAM_DataObject* HYDROGUI_DataModel::createRootModuleObject( SUIT_DataObject* the
 
 void HYDROGUI_DataModel::updateModel()
 {
+  DEBTRACE("updateModel");
   HYDROGUI_Module* aModule = dynamic_cast<HYDROGUI_Module*>( module() );
   if( aModule )
     update( aModule->getStudyId() );
@@ -1351,6 +1371,7 @@ bool HYDROGUI_DataModel::rename( Handle(HYDROData_Entity) theEntity, const QStri
 
 void HYDROGUI_DataModel::updateDocument()
 {
+  DEBTRACE("updateDocument");
     // Sets the default strickler coefficient from preferences to document.
     Handle(HYDROData_Document) aDoc = getDocument();
     SUIT_ResourceMgr* resMgr = module()->application()->resourceMgr();
index 2b7d92176c7bd94a8f5b232b6fcd805d6d783f3f..e1a4a7cadb5016b1e8e8899417b64366ff7d6585 100644 (file)
@@ -86,6 +86,7 @@ public:
    * Close the model and remove data. Reimplemented.
    */
   virtual bool close();
+  virtual bool isAboutToClose();
 
   /**
    * Dump study data to Python script. Reimplemented.
@@ -387,6 +388,7 @@ protected:
 protected:
   QString myStudyURL; ///< the saved/opened document URL
   QByteArray myStates;
+  bool myIsAboutToClose;
 };
 
 #endif 
index 40cc9237ae54da5369a22654357fbebca147e34d..dc41e3e12e3c1ca7921d68d7b585000379b19538 100755 (executable)
 #include <QStatusBar>
 #include <QCursor>
 
+//#define _DEVDEBUG_
+#include "HYDRO_trace.hxx"
+
 static int ViewManagerId = 0;
 
 extern "C" HYDRO_EXPORT CAM_Module* createModule()
@@ -128,20 +131,24 @@ HYDROGUI_Module::HYDROGUI_Module()
   myIsUpdateEnabled( true ),
   myOverview( 0 )
 {
+  DEBTRACE("HYDROGUI_Module::HYDROGUI_Module()");
 }
 
 HYDROGUI_Module::~HYDROGUI_Module()
 {
+  DEBTRACE("HYDROGUI_Module::~HYDROGUI_Module()");
 }
 
 int HYDROGUI_Module::getStudyId() const
 {
+  DEBTRACE("HYDROGUI_Module::getStudyId()");
   LightApp_Application* anApp = getApp();
   return anApp ? anApp->activeStudy()->id() : 0;
 }
 
 void HYDROGUI_Module::initialize( CAM_Application* theApp )
 {
+  DEBTRACE("HYDROGUI_Module::initialize");
   LightApp_Module::initialize( theApp );
 
   createActions();
@@ -163,6 +170,7 @@ void HYDROGUI_Module::initialize( CAM_Application* theApp )
 
 bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
 {
+  DEBTRACE("HYDROGUI_Module::activateModule");
   bool aRes = LightApp_Module::activateModule( theStudy );
 
   LightApp_Application* anApp = getApp();
@@ -271,6 +279,7 @@ bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy )
 
 bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
 {
+  DEBTRACE("HYDROGUI_Module::deactivateModule");
   /* Issues ## 68, 88.
   ViewManagerMapIterator anIter( myViewManagerMap );
   while( anIter.hasNext() )
@@ -322,11 +331,20 @@ bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy )
 
   myViewManagerMap.clear();
 
-  return LightApp_Module::deactivateModule( theStudy );
+  bool ret = LightApp_Module::deactivateModule( theStudy );
+  HYDROGUI_DataModel* aModel = getDataModel();
+  if (aModel->isAboutToClose())
+  {
+    Handle(HYDROData_Document) aDoc = HYDROData_Document::Document();
+    if (!aDoc.IsNull())
+      aDoc->Close();
+  }
+  return ret;
 }
 
 void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
 {
+  DEBTRACE("HYDROGUI_Module::windows");
   static bool inWindows = false;
   if( inWindows )
     return;
@@ -353,6 +371,7 @@ void HYDROGUI_Module::windows( QMap<int, int>& theMap ) const
 
 void HYDROGUI_Module::viewManagers( QStringList& theTypesList ) const
 {
+  DEBTRACE("HYDROGUI_Module::viewManagers");
   theTypesList << GraphicsView_Viewer::Type() << OCCViewer_Viewer::Type();
 }
 
@@ -905,6 +924,7 @@ void HYDROGUI_Module::contextMenuPopup( const QString& theClient,
 
 void HYDROGUI_Module::createPreferences()
 {
+  DEBTRACE("HYDROGUI_Module::createPreferences");
   int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
   int CursorGroup = addPreference( tr( "PREF_GROUP_CURSOR" ), genTab );
 
@@ -965,6 +985,7 @@ void HYDROGUI_Module::createPreferences()
 
 void HYDROGUI_Module::preferencesChanged( const QString& theSection, const QString& thePref )
 {
+    DEBTRACE("HYDROGUI_Module::preferencesChanged");
     SUIT_ResourceMgr* resMgr = application()->resourceMgr();
     if ( theSection == "preferences" && thePref == "default_strickler_coefficient" )
     {
@@ -1033,6 +1054,7 @@ QCursor HYDROGUI_Module::getPrefEditCursor() const
 
 void HYDROGUI_Module::update( const int flags )
 {
+  DEBTRACE("HYDROGUI_Module::update");
   if ( !isUpdateEnabled() )
     return;
 
@@ -1103,6 +1125,7 @@ void HYDROGUI_Module::update( const int flags )
 
 void HYDROGUI_Module::updateCommandsStatus()
 {
+  DEBTRACE("HYDROGUI_Module::updateCommandsStatus");
   LightApp_Module::updateCommandsStatus();
 
   updateUndoRedoControls();
@@ -1119,26 +1142,31 @@ void HYDROGUI_Module::selectionChanged()
 
 HYDROGUI_DataModel* HYDROGUI_Module::getDataModel() const
 {
+  //DEBTRACE("HYDROGUI_Module::getDataModel()");
   return (HYDROGUI_DataModel*)dataModel();
 }
 
 HYDROGUI_Displayer* HYDROGUI_Module::getDisplayer() const
 {
+  //DEBTRACE("HYDROGUI_Module::getDisplayer()");
   return myDisplayer;
 }
 
 HYDROGUI_OCCDisplayer* HYDROGUI_Module::getOCCDisplayer() const
 {
+  DEBTRACE("HYDROGUI_Module::getOCCDisplayer");
   return myOCCDisplayer;
 }
 
 HYDROGUI_VTKPrsDisplayer* HYDROGUI_Module::getVTKDisplayer() const
 {
+  DEBTRACE("HYDROGUI_Module::getVTKDisplayer");
   return myVTKDisplayer;
 }
 
 SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
 {
+  DEBTRACE("HYDROGUI_Module::getViewManager");
   if( myViewManagerMap.contains( theId ) )
   {
     return myViewManagerMap[ theId ].first;
@@ -1148,6 +1176,7 @@ SUIT_ViewManager* HYDROGUI_Module::getViewManager( const int theId ) const
 
 GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
 {
+  DEBTRACE("HYDROGUI_Module::getViewer");
   if( myViewManagerMap.contains( theId ) )
   {
     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
@@ -1161,6 +1190,7 @@ GraphicsView_Viewer* HYDROGUI_Module::getViewer( const int theId ) const
 
 OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
 {
+  DEBTRACE("HYDROGUI_Module::getOCCViewer");
   if( myViewManagerMap.contains( theId ) )
   {
     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
@@ -1174,6 +1204,7 @@ OCCViewer_Viewer* HYDROGUI_Module::getOCCViewer( const int theId ) const
 
 SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
 {
+  DEBTRACE("HYDROGUI_Module::getVTKViewer");
   if( myViewManagerMap.contains( theId ) )
   {
     ViewManagerInfo anInfo = myViewManagerMap[ theId ];
@@ -1187,6 +1218,7 @@ SVTK_Viewer* HYDROGUI_Module::getVTKViewer( const int theId ) const
 
 int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
 {
+  DEBTRACE("HYDROGUI_Module::getViewManagerId");
   ViewManagerMapIterator anIter( myViewManagerMap );
   while( anIter.hasNext() )
   {
@@ -1200,6 +1232,7 @@ int HYDROGUI_Module::getViewManagerId( SUIT_ViewManager* theViewManager )
 
 HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewManager* theViewManager )
 {
+  DEBTRACE("HYDROGUI_Module::getViewManagerRole");
   int anId = getViewManagerId( theViewManager );
   if( anId != -1 )
   {
@@ -1212,6 +1245,7 @@ HYDROGUI_Module::ViewManagerRole HYDROGUI_Module::getViewManagerRole( SUIT_ViewM
 void HYDROGUI_Module::setViewManagerRole( SUIT_ViewManager* theViewManager,
                                           const ViewManagerRole theRole )
 {
+  DEBTRACE("HYDROGUI_Module::setViewManagerRole");
   int anId = getViewManagerId( theViewManager );
   if( anId != -1 )
   {
@@ -1289,6 +1323,7 @@ void HYDROGUI_Module::setObjectVisible( const int theViewId,
 void HYDROGUI_Module::setIsToUpdate( const Handle(HYDROData_Entity)& theObject,
                                      const bool theState )
 {
+  DEBTRACE("HYDROGUI_Module::setIsToUpdate");
   if( !theObject.IsNull() )
   {
     // Process OCC shapes
@@ -1567,11 +1602,13 @@ void HYDROGUI_Module::updateVTKZRange( const int theViewId, double theRange[] )
 
 void HYDROGUI_Module::clearCache()
 {
+    DEBTRACE("HYDROGUI_Module::clearCache");
     myObjectStateMap.clear();
 }
 
 CAM_DataModel* HYDROGUI_Module::createDataModel()
 {
+  DEBTRACE("HYDROGUI_Module::createDataModel");
   return new HYDROGUI_DataModel( this );
 }
 
@@ -1649,6 +1686,7 @@ bool HYDROGUI_Module::eventFilter( QObject* theObj, QEvent* theEvent )
 
 void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
 {
+  DEBTRACE("HYDROGUI_Module::onViewManagerAdded");
   LightApp_Module::onViewManagerAdded( theViewManager );
 
   if( theViewManager->getType() == GraphicsView_Viewer::Type() )
@@ -1684,6 +1722,7 @@ void HYDROGUI_Module::onViewManagerAdded( SUIT_ViewManager* theViewManager )
 
 void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
 {
+  DEBTRACE("HYDROGUI_Module::onViewManagerRemoved");
   LightApp_Module::onViewManagerRemoved( theViewManager );
 
   createSelector( theViewManager ); // replace the default selector
@@ -1719,6 +1758,7 @@ void HYDROGUI_Module::onViewManagerRemoved( SUIT_ViewManager* theViewManager )
 
 void HYDROGUI_Module::onViewCreated( SUIT_ViewWindow* theViewWindow )
 {
+  DEBTRACE("HYDROGUI_Module::onViewCreated");
   if( theViewWindow && theViewWindow->inherits( "GraphicsView_ViewFrame" ) )
   {
     if( GraphicsView_ViewFrame* aViewFrame = dynamic_cast<GraphicsView_ViewFrame*>( theViewWindow ) )
@@ -1806,6 +1846,7 @@ void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
                                     const bool theIsForced, 
                                     const bool theDoFitAll )
 {
+  DEBTRACE("HYDROGUI_Module::updateViewer");
   QList<int> aViewManagerIdList;
 
   // currently, all views are updated
@@ -1831,6 +1872,7 @@ void HYDROGUI_Module::updateViewer( HYDROGUI_AbstractDisplayer* theDisplayer,
 
 void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
 {
+  DEBTRACE("HYDROGUI_Module::createSelector");
   if( !theViewManager )
     return;
 
@@ -1875,6 +1917,7 @@ void HYDROGUI_Module::createSelector( SUIT_ViewManager* theViewManager )
 
 bool HYDROGUI_Module::setUpdateEnabled( const bool theState )
 {
+  DEBTRACE("HYDROGUI_Module::setUpdateEnabled");
   bool aPrevState = myIsUpdateEnabled;
   myIsUpdateEnabled = theState;
   return aPrevState;
@@ -1887,6 +1930,7 @@ bool HYDROGUI_Module::isUpdateEnabled() const
 
 QStringList HYDROGUI_Module::storeSelection() const
 {
+  DEBTRACE("HYDROGUI_Module::storeSelection");
   QStringList anEntryList;
   if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
   {
@@ -1907,6 +1951,7 @@ QStringList HYDROGUI_Module::storeSelection() const
 
 void HYDROGUI_Module::restoreSelection( const QStringList& theEntryList )
 {
+  DEBTRACE("HYDROGUI_Module::restoreSelection");
   if( LightApp_SelectionMgr* aSelectionMgr = getApp()->selectionMgr() )
   {
     SUIT_DataOwnerPtrList aList( true );
@@ -1951,6 +1996,7 @@ void HYDROGUI_Module::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent*
  */
 QStack<HYDROGUI_Operation*>& HYDROGUI_Module::getActiveOperations()
 {
+  DEBTRACE("HYDROGUI_Module::getActiveOperations");
   return myActiveOperationMap;
 }
 
@@ -2121,6 +2167,7 @@ void HYDROGUI_Module::setObjectRemoved( const Handle(HYDROData_Entity)& theObjec
 
 void HYDROGUI_Module::onViewActivated( SUIT_ViewManager* theMgr )
 {
+  DEBTRACE("HYDROGUI_Module::onViewActivated");
   if( !theMgr )
     return;