1 // SALOME SALOMEGUI : implementation of desktop and GUI kernel
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : QAD_Application.cxx
25 // Author : Nicolas REJNERI
30 \class QAD_Application QAD_Application.h
31 \brief Study manager for QAD-based application.
35 #include "QAD_Tools.h"
36 #include "QAD_Desktop.h"
37 #include "QAD_Application.h"
38 #include "QAD_MessageBox.h"
39 #include "QAD_Config.h"
40 #include "SALOMEGUI_AboutDlg.h"
41 #include "SALOME_Selection.h"
43 #include <SALOMEconfig.h>
44 #include CORBA_CLIENT_HEADER(SALOME_Exception)
47 #include <qapplication.h>
48 #include <qtranslator.h>
49 #include <qpopupmenu.h>
50 #include <qstatusbar.h>
57 #include <qfileinfo.h>
58 #include <qmessagebox.h>
60 // Open CASCADE Includes
61 #include <TCollection_AsciiString.hxx>
62 #include <TCollection_ExtendedString.hxx>
63 #include <Standard_Failure.hxx>
66 static bool checkPermission(QString fileName) {
67 if ( QFile::exists( fileName ) ) {
68 // if file exists - check it for writeability
69 if ( !QFileInfo( fileName ).isWritable() ) {
74 // if file doesn't exist - try to create it
76 if ( !qf.open( IO_WriteOnly ) ) {
87 QAD_Desktop* QAD_Application::desktop = 0;
90 Registers a new application object and
91 adds it to the desktop [ static ]
93 bool QAD_Application::addToDesktop( QAD_Application* app, SALOME_NamingService* name_service )
95 /* create CAF application */
96 if ( !app->initApp(name_service) )
99 /* create the only desktop */
100 if ( !app->getDesktop() )
102 app->createDesktop(name_service);
103 emit app->desktopCreated();
106 /* add application to the desktop */
107 desktop->addApplication( app );
112 Runs the application [ static ]
114 void QAD_Application::run()
116 /* at least one application must be on desktop */
117 QAD_ASSERT_DEBUG_ONLY ( desktop );
118 desktop->showDesktop();
123 Returns reference to main desktop [ static ]
125 QAD_Desktop* QAD_Application::getDesktop()
131 Returns standard Palette [ static ]
133 QPalette QAD_Application::getPalette(bool alternative)
135 /* $$$ ---> commented 20.09.2002 - application uses global palette but little changed if <alternative> is true
138 cg.setColor( QColorGroup::Foreground, Qt::black );
139 cg.setColor( QColorGroup::Button, QColor( 192, 192, 192) );
140 cg.setColor( QColorGroup::Light, Qt::white );
141 cg.setColor( QColorGroup::Midlight, QColor( 223, 223, 223) );
142 cg.setColor( QColorGroup::Dark, QColor( 96, 96, 96) );
143 cg.setColor( QColorGroup::Mid, QColor( 128, 128, 128) );
144 cg.setColor( QColorGroup::Text, Qt::black );
145 cg.setColor( QColorGroup::BrightText, Qt::white );
146 cg.setColor( QColorGroup::ButtonText, Qt::black );
147 cg.setColor( QColorGroup::Base, QColor( 255,255,220 ) );
148 cg.setColor( QColorGroup::Background, QColor( 192, 192, 192) );
149 cg.setColor( QColorGroup::Shadow, Qt::black );
150 cg.setColor( QColorGroup::Highlight, QColor( 0, 0, 128) );
151 cg.setColor( QColorGroup::HighlightedText, Qt::white );
153 cg.setColor( QColorGroup::Foreground, Qt::black );
154 cg.setColor( QColorGroup::Button, QColor( 192, 192, 192) );
155 cg.setColor( QColorGroup::Light, Qt::white );
156 cg.setColor( QColorGroup::Midlight, QColor( 220, 220, 220) );
157 cg.setColor( QColorGroup::Dark, QColor( 96, 96, 96) );
158 cg.setColor( QColorGroup::Mid, QColor( 128, 128, 128) );
159 cg.setColor( QColorGroup::Text, Qt::black );
160 cg.setColor( QColorGroup::BrightText, Qt::white );
161 cg.setColor( QColorGroup::ButtonText, Qt::black );
162 cg.setColor( QColorGroup::Base, QColor( 255,255,220 ) );
163 cg.setColor( QColorGroup::Background, QColor( 192, 192, 192) );
164 cg.setColor( QColorGroup::Shadow, Qt::black );
165 cg.setColor( QColorGroup::Highlight, QColor( 0, 0, 128) );
166 cg.setColor( QColorGroup::HighlightedText, Qt::white );
167 pal.setInactive( cg );
168 cg.setColor( QColorGroup::Foreground, QColor( 128, 128, 128) );
169 cg.setColor( QColorGroup::Button, QColor( 192, 192, 192) );
170 cg.setColor( QColorGroup::Light, Qt::white );
171 cg.setColor( QColorGroup::Midlight, QColor( 220, 220, 220) );
172 cg.setColor( QColorGroup::Dark, QColor( 96, 96, 96) );
173 cg.setColor( QColorGroup::Mid, QColor( 128, 128, 128) );
174 cg.setColor( QColorGroup::Text, Qt::black );
175 cg.setColor( QColorGroup::BrightText, Qt::white );
176 cg.setColor( QColorGroup::ButtonText, QColor( 128, 128, 128) );
177 cg.setColor( QColorGroup::Base, QColor( 255,255,220 ) );
178 cg.setColor( QColorGroup::Background, QColor( 192, 192, 192) );
179 cg.setColor( QColorGroup::Shadow, Qt::black );
180 cg.setColor( QColorGroup::Highlight, QColor( 0, 0, 128) );
181 cg.setColor( QColorGroup::HighlightedText, Qt::white );
182 pal.setDisabled( cg );
183 $$$ <--------------------------------------------------------------------- */
184 QPalette pal = QApplication::palette();
185 // $$$ --> this prevents qt bug - bag child window's icon drawing (not transparent)
186 // when it is maximized
187 pal.setColor(QPalette::Active, QColorGroup::Background, pal.active().button());
188 pal.setColor(QPalette::Inactive, QColorGroup::Background, pal.inactive().button());
189 pal.setColor(QPalette::Disabled, QColorGroup::Background, pal.disabled().button());
192 // alternative palette is used for Object Browser, PyEditor, Message and Help windows
193 QColorGroup cg = pal.active();
194 cg.setColor( QColorGroup::Highlight, QColor( 0, 0, 128) );
195 cg.setColor( QColorGroup::HighlightedText, Qt::white );
196 cg.setColor( QColorGroup::Base, QColor( 255,255,220 ) );
197 cg.setColor( QColorGroup::Text, Qt::black );
198 pal.setActive ( cg );
200 cg.setColor( QColorGroup::Highlight, QColor( 0, 0, 128) );
201 cg.setColor( QColorGroup::HighlightedText, Qt::white );
202 cg.setColor( QColorGroup::Base, QColor( 255,255,220 ) );
203 cg.setColor( QColorGroup::Text, Qt::black );
204 pal.setInactive( cg );
206 cg.setColor( QColorGroup::Highlight, QColor( 0, 0, 128) );
207 cg.setColor( QColorGroup::HighlightedText, Qt::white );
208 cg.setColor( QColorGroup::Base, QColor( 255,255,220 ) );
209 cg.setColor( QColorGroup::Text, Qt::black );
210 pal.setDisabled( cg );
218 QAD_Application::QAD_Application( const QString& format, const QString& description,
219 const QString& extension ) :
221 myStudyFormat( format ),
222 myStudyExtension( extension ),
223 myStudyDescription( description )
225 /* actions are stored in vectors only */
227 /* studies are managed by me */
228 myStudies.setAutoDelete( true );
230 /* load resources for all QAD */
231 QAD_ResourceMgr* resMgr = QAD_Desktop::getResourceManager();
232 if ( !resMgr ) resMgr = QAD_Desktop::createResourceManager();
234 resMgr->loadResources( "QAD", message );
235 resMgr->loadResources( "CLIENT", message );
237 /* set default icon */
238 myIcon = resMgr->loadPixmap( "CLIENT", tr("ICON_APP_DEFAULTICON") );
239 myName = tr("APP_DEFAULTTITLE");
241 /* We need to know that desktop is created in order
242 to have some additional internal initialization */
243 QAD_ASSERT( connect( this, SIGNAL(desktopCreated()), this,
244 SLOT(onDesktopCreated()) ));
250 QAD_Application::~QAD_Application ()
252 myEditActions.clear();
253 myViewActions.clear();
254 myHelpActions.clear();
255 QMap<int, QToolBar*>::Iterator it;
256 for ( it = myToolBars.begin(); it != myToolBars.end(); it++ ) {
263 Creates the main desktop( called once )
265 bool QAD_Application::createDesktop( SALOME_NamingService* name_service )
267 QAD_ASSERT_DEBUG_ONLY( !desktop );
268 desktop = new QAD_Desktop ( name_service );
269 return ( desktop != NULL );
273 Creates the actions provided by this application
276 void QAD_Application::createActions()
278 /* Basic application provides only Undo/Redo
279 functionalities which is disabled by default.
280 All others must be added by subclasses.
282 QAD_ResourceMgr* rmgr = QAD_Desktop::getResourceManager();
284 if ( !myEditActions.at( EditUndoId ) )
286 QActionP* editUndo = new QActionP( tr("TOT_APP_EDIT_UNDO"),
287 rmgr->loadPixmap( "QAD",
288 tr("ICON_APP_EDIT_UNDO") ),
289 tr("MEN_APP_EDIT_UNDO"),
290 CTRL+Key_Z, desktop );
291 editUndo->setStatusTip ( tr("PRP_APP_EDIT_UNDO") );
292 QAD_ASSERT ( connect( editUndo, SIGNAL( activated() ), this, SLOT( onUndo() )));
293 myEditActions.insert( EditUndoId, editUndo );
296 if ( !myEditActions.at( EditRedoId ) )
298 QActionP* editRedo = new QActionP ( tr("TOT_APP_EDIT_REDO"),
299 rmgr->loadPixmap( "QAD", tr("ICON_APP_EDIT_REDO") ),
300 tr("MEN_APP_EDIT_REDO"), CTRL+Key_Y, desktop );
301 editRedo->setStatusTip ( tr("PRP_APP_EDIT_REDO") );
302 QAD_ASSERT ( connect( editRedo, SIGNAL( activated() ), this, SLOT( onRedo() )));
303 myEditActions.insert( EditRedoId, editRedo );
306 if ( !myEditActions.at( EditCopyId ) )
308 QActionP* editCopy = new QActionP ( tr("TOT_APP_EDIT_COPY"),
309 rmgr->loadPixmap( "QAD",
310 tr("ICON_APP_EDIT_COPY") ),
311 tr("MEN_APP_EDIT_COPY"),
312 CTRL+Key_C, desktop );
313 editCopy->setStatusTip ( tr("PRP_APP_EDIT_COPY") );
314 QAD_ASSERT ( connect( editCopy, SIGNAL( activated() ), this, SLOT( onCopy() )));
315 myEditActions.insert( EditCopyId, editCopy );
318 if ( !myEditActions.at( EditPasteId ) )
320 QActionP* editPaste = new QActionP ( tr("TOT_APP_EDIT_PASTE"),
321 rmgr->loadPixmap( "QAD",
322 tr("ICON_APP_EDIT_PASTE") ),
323 tr("MEN_APP_EDIT_PASTE"),
324 CTRL+Key_V, desktop );
325 editPaste->setStatusTip ( tr("PRP_APP_EDIT_PASTE") );
326 QAD_ASSERT ( connect( editPaste, SIGNAL( activated() ), this, SLOT( onPaste() )));
327 myEditActions.insert( EditPasteId, editPaste );
329 // Update action state
334 Enables/disables the actions according to the
337 void QAD_Application::updateActions()
339 QAD_ASSERT_DEBUG_ONLY( !myEditActions.isEmpty() );
340 if ( myActiveStudy ) {
341 myEditActions.at( EditUndoId )->setEnabled( myActiveStudy->canUndo() );
342 myEditActions.at( EditRedoId )->setEnabled( myActiveStudy->canRedo() );
343 myEditActions.at( EditCopyId )->setEnabled( canCopy() );
344 myEditActions.at( EditPasteId )->setEnabled( canPaste() );
347 myEditActions.at( EditUndoId )->setEnabled( false );
348 myEditActions.at( EditRedoId )->setEnabled( false );
349 myEditActions.at( EditCopyId )->setEnabled( false );
350 myEditActions.at( EditPasteId )->setEnabled( false );
355 Returns the aplication name
357 const QString& QAD_Application::getApplicationName() const
363 Returns the application icon
365 const QPixmap& QAD_Application::getApplicationIcon() const
371 Returns the study description
373 const QString& QAD_Application::getStudyDescription() const
375 return myStudyDescription;
379 Returns the CAF study format
381 const QString& QAD_Application::getStudyFormat() const
383 return myStudyFormat;
387 Returns the extension of supported type of files
389 const QString& QAD_Application::getStudyExtension() const
391 return myStudyExtension;
395 Returns 'true' if study is opened
397 bool QAD_Application::isStudyOpened( const QString& studyName )
399 QString Name = QAD_Tools::getFileNameFromPath( studyName, true );
400 return (( getStudyByName( studyName ) != NULL ) || (getStudyByName( Name ) != NULL ));
404 Returns the study object by its name
406 QAD_Study* QAD_Application::getStudyByName( const QString& studyname )
408 for ( QAD_Study* study = myStudies.first(); study; study = myStudies.next() )
410 if ( (studyname.compare( study->getPath() ) == 0 ) ||
411 (studyname.compare( study->getTitle() ) == 0 ))
418 Returns vector of all opened studies
420 QList<QAD_Study>& QAD_Application::getStudies()
426 Adds the study to the list of opened studies
427 and set listeners for the study signals.
429 void QAD_Application::addStudy( QAD_Study* study )
431 if ( !study ) return;
433 QAD_ASSERT( connect(study,SIGNAL(docClosing(QAD_Study*)),desktop,
434 SLOT(onCloseStudy(QAD_Study*))) );
435 myStudies.append( study );
439 Removes the study from the list of opened studies
441 void QAD_Application::removeStudy( QAD_Study* study )
445 /* close and destroy */
446 if ( study == myActiveStudy )
448 myStudies.removeRef( study );
453 Activates 'About' dialog
455 void QAD_Application::helpAbout()
457 /* just calls QAD_Desktop::helpAbout() but can have own implementation */
458 getDesktop()->helpAbout();
462 Activates search in help
464 void QAD_Application::helpSearch()
466 /* just calls QAD_Desktop::helpSearch() but can have own implementation */
467 // getDesktop()->helpSearch();
471 Activates help contents
473 void QAD_Application::helpContents()
475 /* just calls QAD_Desktop::helpContents() but can have own implementation */
476 // getDesktop()->helpContents();
480 Customizes menu "File" for the active application
482 void QAD_Application::updateFilePopup( QPopupMenu* menu, bool add, int index )
487 /* ensure that 'add' command is followed by 'remove' */
488 static bool isAdded = false;
489 QAD_ASSERT_DEBUG_ONLY ( (add && !isAdded) || (!add && isAdded) );
492 onUpdateFileActions( menu, add, index );
496 Customizes menu "Edit" for the active application
498 void QAD_Application::updateEditPopup( QPopupMenu* menu, bool add, int index )
503 /* ensure that 'add' command is followed by 'remove' */
504 static bool isAdded = false;
505 QAD_ASSERT_DEBUG_ONLY ( (add && !isAdded) || (!add && isAdded) );
508 onUpdateEditActions( menu, add, index );
512 Customizes menu "View" for the active application
514 void QAD_Application::updateViewPopup( QPopupMenu* menu, bool add, int index )
519 /* ensure that 'add' command is followed by 'remove' */
520 static bool isAdded = false;
521 QAD_ASSERT_DEBUG_ONLY ( (add && !isAdded) || (!add && isAdded) );
524 onUpdateViewActions( menu, add, index );
528 Customizes menu "Help" for the active application
530 void QAD_Application::updateHelpPopup( QPopupMenu* menu, bool add, int index )
534 /* ensure that 'add' command is followed by 'remove' */
535 static bool isAdded = false;
536 QAD_ASSERT_DEBUG_ONLY ( (add && !isAdded) || (!add && isAdded) );
539 onUpdateHelpActions ( menu, add, index );
543 Customizes the main menu bar to add some new popup,
544 'Options' or 'Tools' for example.
546 void QAD_Application::updateMainMenu( QMenuBar* menubar, bool add, int index )
548 if ( !menubar ) return;
550 /* ensure that 'add' command is followed by 'remove' */
551 static bool isAdded = false;
552 QAD_ASSERT_DEBUG_ONLY ( (add && !isAdded) || (!add && isAdded) );
555 onUpdateMainMenuItems ( menubar, add, index );
559 Adds specific application buttons for standard toolbar
561 void QAD_Application::updateToolBars( bool add )
564 /* ensure that 'add' command is followed by 'remove' */
565 static bool isAdded = false;
566 QAD_ASSERT_DEBUG_ONLY ( (add && !isAdded) || (!add && isAdded) );
569 onUpdateToolBars ( add );
573 Customizes the status bar
575 void QAD_Application::updateStatusBar( QStatusBar* statusBar, bool add )
578 /* ensure that 'add' command is followed by 'remove' */
579 static bool isAdded = false;
580 QAD_ASSERT_DEBUG_ONLY ( (add && !isAdded) || (!add && isAdded) );
583 onUpdateStatusBar( statusBar, add );
587 Creates toolbar to be managed by QAD_Application
589 QToolBar* QAD_Application::createToolBar( int id,
590 const QString& label, Dock dock,
591 bool dockTop, bool dockBottom,
592 bool dockLeft, bool dockRight,
593 bool dockMinimized, bool dockTornOff )
596 if ( getDesktop() ) {
597 tb = new QToolBar( label, getDesktop(), 0 );
598 tb->setCloseMode( QDockWindow::Undocked );
599 getDesktop()->setDockEnabled( tb, DockTop, dockTop );
600 getDesktop()->setDockEnabled( tb, DockBottom, dockBottom );
601 getDesktop()->setDockEnabled( tb, DockLeft, dockLeft );
602 getDesktop()->setDockEnabled( tb, DockRight, dockRight );
603 getDesktop()->setDockEnabled( tb, DockMinimized, dockMinimized );
604 getDesktop()->setDockEnabled( tb, DockTornOff, dockTornOff );
605 getDesktop()->addDockWindow( tb, label, dock );
606 getDesktop()->setAppropriate( tb, false );
609 myToolBars.insert( id, tb);
617 void QAD_Application::removeToolBar( int id )
619 QToolBar* tb = myToolBars[ id ];
621 myToolBars.remove( id );
622 getDesktop()->removeDockWindow( tb );
630 QToolBar* QAD_Application::getToolBar( int id )
632 return myToolBars[ id ];
636 Gets all toolbars managed by QAD_Applica
638 QList<QToolBar> QAD_Application::getToolBars()
640 QList<QToolBar> toolbars;
641 QMap<int, QToolBar*>::Iterator it;
642 for ( it = myToolBars.begin(); it != myToolBars.end(); it++ )
643 toolbars.append( it.data() );
648 Called by 'updateMainMenu' when application is activated/deactivated.
649 Redefine to insert/remove the actions provided by the application
650 to the main menu at 'index'.
651 Returns the number of added/removed items.
653 int QAD_Application::onUpdateMainMenuItems ( QMenuBar* mb, bool add, int index )
659 Called by 'updateFilePopup' when application is activated/deactivated.
660 Redefine to insert/remove the actions provided by the application to
661 'File' menu of the desktop at 'index'.
662 Returns the number of added/removed items.
664 int QAD_Application::onUpdateFileActions ( QPopupMenu* popup, bool add, int index )
670 Called by 'updateEditPopup' when application is activated/deactivated.
671 Redefine to insert/remove the actions provided by the application to
672 'Edit' menu of the desktop at 'index'.
673 Returns the number of added/removed items.
675 int QAD_Application::onUpdateEditActions ( QPopupMenu* popup, bool add, int index )
677 QAD_ASSERT_DEBUG_ONLY( !myEditActions.isEmpty() );
678 QToolBar* tb = getDesktop()->getStdToolBar();
679 QActionP* undo = myEditActions.at( EditUndoId );
680 QActionP* redo = myEditActions.at( EditRedoId );
681 QActionP* copy = myEditActions.at( EditCopyId );
682 QActionP* paste = myEditActions.at( EditPasteId );
685 undo->addTo( popup );
687 redo->addTo( popup );
689 copy->addTo( popup );
691 paste->addTo( popup );
700 popup->removeItemAt(index);
701 popup->removeItemAt(index);
702 popup->removeItemAt(index);
703 popup->removeItemAt(index);
705 undo->removeFrom( tb );
706 redo->removeFrom( tb );
707 copy->removeFrom( tb );
708 paste->removeFrom( tb );
714 Called by 'updateViewPopup' when application is activated/deactivated.
715 Redefine to insert/remove the actions provided by the application to the
716 'View' menu of the desktop at 'index'.
717 Returns the number of added/removed items.
719 int QAD_Application::onUpdateViewActions ( QPopupMenu* popup, bool add, int index )
725 Called by 'updateHelpPopup' when application is activated/deactivated.
726 Redefine to insert/remove the actions provided by the application
727 to 'Help' menu of the desktop at 'index'.
728 Returns the number of added/removed items.
730 int QAD_Application::onUpdateHelpActions ( QPopupMenu* popup, bool add, int index )
736 Called by 'updateStatusBar' when application is activated/deactivated.
737 Redefine to customize status bar.
739 void QAD_Application::onUpdateStatusBar( QStatusBar* sb, bool activate )
744 Called by 'updateToolBars' when application is activated/deactivated.
745 Redefine to show your specific toolbars on the desktop.
747 void QAD_Application::onUpdateToolBars( bool activate )
749 QMap<int, QToolBar*>::Iterator it;
750 for ( it = myToolBars.begin(); it != myToolBars.end(); it++ ) {
751 activate ? it.data()->show() : it.data()->hide();
752 getDesktop()->setAppropriate( it.data(), activate );
756 //=======================================================================//
757 // Study management //
758 //=======================================================================//
760 Returns the active study
762 QAD_Study* QAD_Application::getActiveStudy() const
764 return myActiveStudy;
767 //=======================================================================//
768 // Operation management //
769 //=======================================================================//
771 Runs a new operation of class appointed
773 void QAD_Application::startOperation( QAD_Operation* op )
775 if ( op ) op->start();
779 //=======================================================================//
780 // Study management //
781 //=======================================================================//
785 QAD_Study* QAD_Application::newStudy()
787 QAD_Study* newStudy = 0;
788 QAD_ASSERT_DEBUG_ONLY( !myStudyMgr->_is_nil() );
789 QApplication::setOverrideCursor( Qt::waitCursor );
791 /* create QAD study*/
792 QString StudyName = getDesktop()->getNewStudyName();
794 CORBA::Object_var obj = getDesktop()->getNameService()->Resolve("/myStudyManager");
795 SALOMEDS::StudyManager_var myStudyMgr = SALOMEDS::StudyManager::_narrow(obj);
796 ASSERT(! CORBA::is_nil(myStudyMgr));
797 SALOMEDS::ListOfOpenStudies_var List = myStudyMgr->GetOpenStudies();
803 for (unsigned int ind = 0; ind < List->length();ind++) {
804 QString NameS = QAD_Tools::getFileNameFromPath( QString( List[ind] ), true );
805 if ( NameS.compare( StudyName ) == 0 ) {
806 StudyName = getDesktop()->getNewStudyName();
813 if (getStudyByName ( StudyName ) != NULL )
816 SALOMEDS::Study_var aStudy = myStudyMgr->NewStudy(getDesktop()->getNewStudyName());
817 newStudy = new QAD_Study( this, aStudy, getDesktop()->getNewStudyName());
822 SALOMEDS::Study_var aStudy = myStudyMgr->NewStudy(StudyName);
823 newStudy = new QAD_Study( this, aStudy, StudyName);
828 if ( newStudy->getResult() ) {
829 addStudy( newStudy );
832 onStudyActivated( newStudy );
834 /* customization on create ( called only once )*/
835 onStudyCreated( newStudy );
840 /* customization on show ( called only once ) */
841 onStudyShown( newStudy );
844 catch( Standard_Failure ) {
846 qApp->processEvents(); /* update desktop*/
847 QApplication::restoreOverrideCursor();
852 Loads the existed study in StudyManager
854 QAD_Study* QAD_Application::loadStudy( const QString& fileName )
856 /* connect CAF document to CAF application */
857 QAD_ASSERT_DEBUG_ONLY( !myStudyMgr->_is_nil() );
859 SALOMEDS::Study_var aStudy = myStudyMgr->GetStudyByName( fileName );
861 // SALOMEDS::ListOfOpenStudies_var List = myStudyMgr->GetOpenStudies();
862 // for (unsigned int ind = 0; ind < List->length();ind++) {
863 // MESSAGE ( " Study index : " << List[ind] )
864 // aStudy = myStudyMgr->GetStudyByName(List[ind]);
867 QAD_Study* loadStudy = 0;
868 QApplication::setOverrideCursor( Qt::waitCursor );
870 /* create QAD study */
871 loadStudy = new QAD_Study( this, aStudy, aStudy->Name() );
873 if ( loadStudy->getResult() ) {
874 addStudy( loadStudy );
877 onStudyActivated( loadStudy );
879 /* customisation on load ( called only once ) */
880 onStudyOpened( loadStudy );
885 /* customization on show ( called only once ) */
886 onStudyShown( loadStudy );
890 catch( Standard_Failure ) {
892 qApp->processEvents(); /* update desktop*/
893 QApplication::restoreOverrideCursor();
898 Opens the existed study
900 QAD_Study* QAD_Application::openStudy( const QString& fileName )
903 /* Qt uses UNIX-like slashes even on WIN platform */
904 QString name = QAD_Tools::unix2win( fileName );
906 QString name = fileName;
908 SALOMEDS::Study_var aStudy;
910 /* connect CAF document to CAF application */
911 QAD_ASSERT_DEBUG_ONLY( !myStudyMgr->_is_nil() );
913 QAD_Study* openStudy = 0;
914 QApplication::setOverrideCursor( Qt::waitCursor );
917 SALOMEDS::Study_var aStudy = myStudyMgr->Open((char*) name.latin1());
919 //MPV: name of the study is set in the study manager now
920 //NRI DEBUG : 11/02/2002
921 //aStudy->Name( QAD_Tools::getFileNameFromPath(name,true) );
923 /* create QAD study */
924 openStudy = new QAD_Study( this, aStudy, fileName );
926 if ( openStudy->getResult() ) {
927 addStudy( openStudy );
930 onStudyActivated( openStudy );
932 /* customisation on open ( called only once ) */
933 onStudyOpened( openStudy );
938 /* customization on show ( called only once ) */
939 onStudyShown( openStudy );
943 // Handle SALOME::SALOME_Exception raised by SALOMEDS::StudyMgr
944 // Ensure that null study is returned in case of errors
945 catch(SALOME::SALOME_Exception&) {
951 catch( Standard_Failure ) {
953 qApp->processEvents(); /* update desktop*/
954 QApplication::restoreOverrideCursor();
961 bool QAD_Application::saveStudy( QAD_Study* study )
963 bool MultiSave = QAD_CONFIG->getSetting("Desktop:MultiFileSave") == "true";
964 bool ASCIISave = QAD_CONFIG->getSetting("Desktop:ASCIISave") == "true";
966 QApplication::setOverrideCursor( Qt::waitCursor );
969 if (ASCIISave) myStudyMgr->SaveASCII(study->getStudyDocument(), MultiSave);
970 else myStudyMgr->Save(study->getStudyDocument(), MultiSave);
971 study->updateCaptions();
973 catch ( Standard_Failure ) {
976 qApp->processEvents(); /* update desktop*/
977 QApplication::restoreOverrideCursor();
982 Saves the study in a new file
984 bool QAD_Application::saveAsStudy( QAD_Study* study, const QString& fileName )
986 bool MultiSave = QAD_CONFIG->getSetting("Desktop:MultiFileSave") == "true";
987 bool ASCIISave = QAD_CONFIG->getSetting("Desktop:ASCIISave") == "true";
988 bool success = false;
990 /* Qt uses UNIX-like slashes even on WIN platform */
991 QString name = QAD_Tools::unix2win( fileName );
993 QString name = fileName;
995 if ( !name.isNull() )
997 /* check permission */
998 if (!checkPermission(name))
1000 QApplication::setOverrideCursor( Qt::waitCursor );
1001 TCollection_ExtendedString fileNameExt ( (char*) name.latin1() );
1003 /* save as StudyDS */
1004 if (ASCIISave) myStudyMgr->SaveAsASCII(name.latin1(), study->getStudyDocument(), MultiSave);
1005 else myStudyMgr->SaveAs(name.latin1(), study->getStudyDocument(), MultiSave);
1007 study->setTitle( fileName );
1008 study->updateCaptions();
1011 catch (Standard_Failure) {
1013 qApp->processEvents(); /* update desktop*/
1014 QApplication::restoreOverrideCursor();
1022 bool QAD_Application::closeStudy( QAD_Study* study, bool permanently /*=false*/ )
1024 bool success = true;
1025 /* close CAF document */
1026 QApplication::setOverrideCursor( Qt::waitCursor );
1029 SALOMEDS::Study_var aStudyDocument = study->getStudyDocument();
1032 onStudyClosed( study );
1035 removeStudy( study );
1038 myActiveStudy = myStudies.last();
1040 /* close application when the last study is closed */
1041 if ( myStudies.isEmpty() )
1042 emit appDeactivated ( this );
1047 myStudyMgr->Close( aStudyDocument );
1050 catch ( Standard_Failure )
1054 qApp->processEvents(); /* update desktop*/
1055 QApplication::restoreOverrideCursor();
1060 Undo operation on the active study.
1061 Calls undo( activeStudy ).
1063 bool QAD_Application::onUndo()
1065 bool ok = undo( myActiveStudy );
1066 updateActions(); /* enable/disable undo/redo */
1071 Undo operation on the given study
1073 bool QAD_Application::undo(QAD_Study* study)
1075 bool status = false;
1078 status = study->undo();
1084 Redo operation on the active study.
1085 Calls redo( myActiveStudy ).
1087 bool QAD_Application::onRedo()
1089 bool ok = redo( myActiveStudy );
1090 updateActions(); /* enable/disable undo/redo */
1095 Redo operation on the given study.
1097 bool QAD_Application::redo(QAD_Study* study)
1099 bool status = false;
1102 status = study->redo();
1108 Copies object to the pseudo-clipboard
1110 bool QAD_Application::onCopy()
1112 bool status = false;
1113 if ( myActiveStudy) {
1114 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1115 if ( Sel && Sel->IObjectCount() == 1 ) {
1116 SALOMEDS::SObject_var SO = myActiveStudy->getStudyDocument()->FindObjectID( Sel->firstIObject()->getEntry() );
1117 if ( !SO->_is_nil() ) {
1118 SALOMEDS::SComponent_var SComp = SALOMEDS::SComponent::_narrow( SO );
1119 if ( SComp->_is_nil() ) { // disable 'copy' operations for components
1120 status = myStudyMgr->Copy( SO );
1130 Pastes object from the pseudo-clipboard
1132 bool QAD_Application::onPaste()
1134 SALOMEDS::SObject_var aResult;
1135 if ( myActiveStudy) {
1136 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1137 if ( Sel && Sel->IObjectCount() == 1 ) {
1138 SALOMEDS::SObject_var SO = myActiveStudy->getStudyDocument()->FindObjectID( Sel->firstIObject()->getEntry() );
1139 if ( !SO->_is_nil() ) {
1141 aResult = myStudyMgr->Paste( SO );
1143 catch ( SALOMEDS::StudyBuilder::LockProtection& ) {
1144 myActiveStudy->updateObjBrowser( true );
1146 QAD_MessageBox::warn1 ((QWidget*)QAD_Application::getDesktop(),
1147 QObject::tr("WRN_WARNING"),
1148 QObject::tr("WRN_STUDY_LOCKED"),
1149 QObject::tr("BUT_OK"));
1152 myActiveStudy->updateObjBrowser( true );
1157 return aResult->_is_nil();
1161 Checks if it is possible to make 'copy' operation
1163 bool QAD_Application::canCopy()
1165 bool status = false;
1166 if ( myActiveStudy) {
1167 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1168 if ( Sel && Sel->IObjectCount() == 1 ) {
1169 SALOMEDS::SObject_var SO = myActiveStudy->getStudyDocument()->FindObjectID( Sel->firstIObject()->getEntry() );
1170 if ( !SO->_is_nil() ) {
1171 SALOMEDS::SComponent_var SComp = SALOMEDS::SComponent::_narrow( SO );
1172 if ( SComp->_is_nil() ) // disable copy for components
1173 status = myStudyMgr->CanCopy( SO );
1181 Checks if it is possible to make 'paste' operation
1183 bool QAD_Application::canPaste()
1185 bool status = false;
1186 if ( myActiveStudy) {
1187 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1188 if ( Sel && Sel->IObjectCount() == 1 ) {
1189 SALOMEDS::SObject_var SO = myActiveStudy->getStudyDocument()->FindObjectID( Sel->firstIObject()->getEntry() );
1190 if ( !SO->_is_nil() ) {
1191 status = myStudyMgr->CanPaste( SO );
1199 Called when the main desktop is created ( internal )
1201 void QAD_Application::onDesktopCreated()
1207 Called after creating the given study
1209 void QAD_Application::onStudyCreated(QAD_Study* study)
1214 Called after opening the given study
1216 void QAD_Application::onStudyOpened(QAD_Study* study)
1221 Called after the first showing of the given study
1223 void QAD_Application::onStudyShown( QAD_Study* study )
1228 Called when the given study is activated
1230 void QAD_Application::onStudyActivated(QAD_Study* study)
1232 // MESSAGE ("QAD_Application::onStudyActivated init. ");
1234 /* deactivate old study, activate new study*/
1236 /* NRI : init DEBUG IAP_001 */
1237 QAD_Study* oldActiveStudy = 0;
1238 if ( myActiveStudy != NULL )
1239 oldActiveStudy = myActiveStudy;
1240 /* NRI : end DEBUG IAP_001 */
1243 if ( myActiveStudy )
1244 onStudyDeactivated( myActiveStudy );
1246 myActiveStudy = study;
1248 // VSR : call app activate before informing modules that active study is changed ===>
1249 /* application activated */
1250 emit appActivated( this );
1253 onActiveStudyChanged( oldActiveStudy, myActiveStudy );
1254 // VSR : call app activate before informing modules that active study is changed <===
1258 Called when the given study is deactivated
1260 void QAD_Application::onStudyDeactivated(QAD_Study* study)
1262 // MESSAGE ("QAD_Application::onStudyDeactivated init. ");
1263 QAD_ASSERT_DEBUG_ONLY ( myActiveStudy == study );
1265 study->onStudyDeactivated();
1266 // MESSAGE ("QAD_Application::onStudyDeactivated done. ");
1270 Called before closing the given study
1272 void QAD_Application::onStudyClosed(QAD_Study* study)
1277 Called when the active study changed
1279 void QAD_Application::onActiveStudyChanged( QAD_Study* oldActiveStudy,
1280 QAD_Study* newActiveStudy )
1282 getDesktop()->onActiveStudyChanged();
1284 if ( oldActiveStudy )
1285 QAD_ASSERT( disconnect( oldActiveStudy, SIGNAL(docOperationTerminated( bool )),
1286 this, SLOT( onOperationTerminated( bool ) ) ));
1287 if ( newActiveStudy )
1288 QAD_ASSERT( connect( newActiveStudy, SIGNAL(docOperationTerminated( bool )),
1289 this, SLOT( onOperationTerminated( bool ) ) ));
1294 Called when the operation 'op' terminated [ protected slot ]
1296 void QAD_Application::onOperationTerminated( bool successfully )
1299 updateActions(); /* enable/disable undo/redo */
1303 Adds the specific items to context popup menu activated usually by MB3.
1304 Redefine to fill with desired items.
1306 void QAD_Application::onCreatePopup ()