From 5c8f7ba108c5e500913c24612c1ea695b443ba7e Mon Sep 17 00:00:00 2001 From: jfa Date: Thu, 23 Jun 2005 11:11:13 +0000 Subject: [PATCH] Application::onLoadDoc() method implementation (for VISU batchmode tests) --- src/Qtx/QtxMainWindow.cxx | 4 +-- src/STD/STD_Application.cxx | 46 ++++++++++++++++++++++--- src/STD/STD_Application.h | 3 ++ src/SUIT/SUIT_Application.cxx | 6 ++++ src/SUIT/SUIT_Application.h | 10 ++++-- src/SUIT/SUIT_Session.cxx | 6 ++-- src/SalomeApp/SalomeApp_Application.cxx | 28 +++++++++++++++ src/SalomeApp/SalomeApp_Application.h | 3 ++ src/SalomeApp/SalomeApp_Study.cxx | 7 ++-- 9 files changed, 99 insertions(+), 14 deletions(-) diff --git a/src/Qtx/QtxMainWindow.cxx b/src/Qtx/QtxMainWindow.cxx index f48012050..ad5c5141c 100644 --- a/src/Qtx/QtxMainWindow.cxx +++ b/src/Qtx/QtxMainWindow.cxx @@ -58,8 +58,8 @@ bool QtxMainWindow::Filter::eventFilter( QObject* o, QEvent* e ) QtxMainWindow::QtxMainWindow( QWidget* parent, const char* name, WFlags f ) : QMainWindow( parent, name, f ), -myMenuBar( 0 ), -myStatusBar( 0 ) +myMenuBar( NULL ), +myStatusBar( NULL ) { } diff --git a/src/STD/STD_Application.cxx b/src/STD/STD_Application.cxx index 946f0285a..072ef0738 100755 --- a/src/STD/STD_Application.cxx +++ b/src/STD/STD_Application.cxx @@ -231,10 +231,11 @@ bool STD_Application::onOpenDoc( const QString& aName ) if ( !activeStudy() ) { // if no study - open in current desktop - createEmptyStudy(); - res = activeStudy()->openDocument( aName ); - updateDesktopTitle(); - updateCommandsStatus(); + // jfa 21.06.2005:createEmptyStudy(); + // jfa 21.06.2005:res = activeStudy()->openDocument( aName ); + // jfa 21.06.2005:updateDesktopTitle(); + // jfa 21.06.2005:updateCommandsStatus(); + res = useFile( aName ); // jfa 21.06.2005 } else { @@ -261,6 +262,43 @@ bool STD_Application::onOpenDoc( const QString& aName ) return res; } +bool STD_Application::onLoadDoc( const QString& aName ) +{ + bool res = true; + if ( !activeStudy() ) + { + // if no study - load in current desktop + res = useStudy( aName ); + } + else + { + // if study exists - load in new desktop. Check: is the same file is loaded? + SUIT_Session* aSession = SUIT_Session::session(); + QPtrList aAppList = aSession->applications(); + bool isAlreadyOpen = false; + SUIT_Application* aApp = 0; + for ( QPtrListIterator it( aAppList ); it.current() && !isAlreadyOpen; ++it ) + { + aApp = it.current(); + if ( aApp->activeStudy()->studyName() == aName ) + isAlreadyOpen = true; + } + if ( !isAlreadyOpen ) + { + // temporary commented because of "pure virtual method called" execution error. + // current state of code is not right, but works somehow. + // SALOMEDS::Study of the first found application is replaced by the new one, + // while normally the new study must be used by a new application + //jfa tmp:aApp = startApplication( 0, 0 ); + if ( aApp ) + res = aApp->useStudy( aName ); + } + else + aApp->desktop()->setActiveWindow(); + } + return res; +} + void STD_Application::beforeCloseDoc( SUIT_Study* ) { } diff --git a/src/STD/STD_Application.h b/src/STD/STD_Application.h index e5fecef17..069854332 100755 --- a/src/STD/STD_Application.h +++ b/src/STD/STD_Application.h @@ -78,6 +78,9 @@ public slots: virtual void onOpenDoc(); virtual bool onOpenDoc( const QString& ); + //virtual void onLoadDoc(); + virtual bool onLoadDoc( const QString& ); + virtual void onExit(); virtual void onCopy(); diff --git a/src/SUIT/SUIT_Application.cxx b/src/SUIT/SUIT_Application.cxx index 4acf370ac..7d5b6d99c 100755 --- a/src/SUIT/SUIT_Application.cxx +++ b/src/SUIT/SUIT_Application.cxx @@ -59,6 +59,12 @@ bool SUIT_Application::useFile( const QString& theFileName ) createEmptyStudy(); if ( activeStudy() ) return activeStudy()->openDocument( theFileName ); + return false; +} + +bool SUIT_Application::useStudy( const QString& theName ) +{ + return false; } void SUIT_Application::createEmptyStudy() diff --git a/src/SUIT/SUIT_Application.h b/src/SUIT/SUIT_Application.h index 804c65f2a..7d67c9f48 100755 --- a/src/SUIT/SUIT_Application.h +++ b/src/SUIT/SUIT_Application.h @@ -50,8 +50,11 @@ public: //! Shows the application's main widget. For non GUI application must be redefined. virtual void start(); - //! Loads document into active Study. If Study is empty - creates it. - virtual bool useFile( const QString& ); + //! Opens document into active Study. If Study is empty - creates it. + virtual bool useFile( const QString& theFileName); + + //! Loads document into active Study. If Study is empty - creates it. + virtual bool useStudy( const QString& theName); //! Creates new empty Study if active Study = 0 virtual void createEmptyStudy(); @@ -127,7 +130,8 @@ private: //! This function must return a new application instance. extern "C" { - typedef SUIT_Application* (*APP_CREATE_FUNC)( int, char** ); + //jfa 22.06.2005:typedef SUIT_Application* (*APP_CREATE_FUNC)( int, char** ); + typedef SUIT_Application* (*APP_CREATE_FUNC)(); } #define APP_CREATE_NAME "createApplication" diff --git a/src/SUIT/SUIT_Session.cxx b/src/SUIT/SUIT_Session.cxx index 9dcef329a..082d49add 100755 --- a/src/SUIT/SUIT_Session.cxx +++ b/src/SUIT/SUIT_Session.cxx @@ -66,7 +66,8 @@ SUIT_Application* SUIT_Session::startApplication( const QString& name, int args, return 0; } - myAppLibs.insert( appName, libHandle ); + if (!myAppLibs.contains(appName) || !myAppLibs[appName]) // jfa 22.06.2005 + myAppLibs.insert( appName, libHandle ); APP_CREATE_FUNC crtInst = 0; @@ -90,7 +91,8 @@ SUIT_Application* SUIT_Session::startApplication( const QString& name, int args, myResMgr->loadLanguage(); } - SUIT_Application* anApp = crtInst( args, argv ); + //jfa 22.06.2005:SUIT_Application* anApp = crtInst( args, argv ); + SUIT_Application* anApp = crtInst(); if ( !anApp ) { SUIT_MessageBox::warn1(0, tr( "Error" ), tr( "Can not find function %1. %2").arg( APP_CREATE_NAME ).arg( lastError() ), tr( "Ok" ) ); diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index 3f9eb7c30..1432fffd6 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -524,6 +524,22 @@ bool SalomeApp_Application::onOpenDoc( const QString& aName ) return res; } +bool SalomeApp_Application::onLoadDoc( const QString& aName ) +{ + bool res = CAM_Application::onLoadDoc( aName ); + + /*jfa tmp:QAction* a = action( MRUId ); + if ( a && a->inherits( "QtxMRUAction" ) ) + { + QtxMRUAction* mru = (QtxMRUAction*)a; + if ( res ) + mru->insert( aName ); + else + mru->remove( aName ); + }*/ + return res; +} + void SalomeApp_Application::onSelection() { onSelectionChanged(); @@ -641,6 +657,18 @@ void SalomeApp_Application::onOpenWith() QApplication::restoreOverrideCursor(); } +bool SalomeApp_Application::useStudy(const QString& theName) +{ + createEmptyStudy(); + SalomeApp_Study* aStudy = dynamic_cast(activeStudy()); + bool res = false; + if (aStudy) + res = aStudy->loadDocument( theName ); + updateDesktopTitle(); + updateCommandsStatus(); + return res; +} + void SalomeApp_Application::setActiveStudy( SUIT_Study* study ) { CAM_Application::setActiveStudy( study ); diff --git a/src/SalomeApp/SalomeApp_Application.h b/src/SalomeApp/SalomeApp_Application.h index 5c220cfef..1999ef00e 100644 --- a/src/SalomeApp/SalomeApp_Application.h +++ b/src/SalomeApp/SalomeApp_Application.h @@ -65,6 +65,8 @@ public: virtual CAM_Module* loadModule( const QString& ); virtual bool activateModule( const QString& ); + virtual bool useStudy( const QString& ); + SalomeApp_SelectionMgr* selectionMgr() const; LogWindow* logWindow(); @@ -115,6 +117,7 @@ public slots: virtual void onOpenDoc(); virtual void onHelpAbout(); virtual bool onOpenDoc( const QString& ); + virtual bool onLoadDoc( const QString& ); virtual void onCopy(); virtual void onPaste(); diff --git a/src/SalomeApp/SalomeApp_Study.cxx b/src/SalomeApp/SalomeApp_Study.cxx index 0d6c28ae5..aa812a974 100644 --- a/src/SalomeApp/SalomeApp_Study.cxx +++ b/src/SalomeApp/SalomeApp_Study.cxx @@ -120,16 +120,17 @@ bool SalomeApp_Study::loadDocument( const QString& theStudyName ) if ( aComponent->ComponentDataType() == "Interface Applicative" ) continue; // skip the magic "Interface Applicative" component - + SalomeApp_DataModel::BuildTree( aComponent, root(), this ); } // TODO: potentially unsafe call, since base study's openDocument() might try to access the file directly - to be improved + //bool res = true; bool res = CAM_Study::openDocument( theStudyName ); - emit opened( this ); + //emit opened( this ); - return res; + return res; } //======================================================================= -- 2.30.2