]> SALOME platform Git repositories - modules/gui.git/blob - src/SalomeApp/SalomeApp_Application.cxx
Salome HOME
26df49c6c67ec9f26b0b3c5d8b67a6c90e8a5fb1
[modules/gui.git] / src / SalomeApp / SalomeApp_Application.cxx
1 // File:      SalomeApp_Application.cxx
2 // Created:   10/22/2004 3:23:45 PM
3 // Author:    Sergey LITONIN
4 // Copyright (C) CEA 2004
5
6 #include "SalomeApp_PyInterp.h" // WARNING! This include must be the first!
7
8 #include "SalomeApp_Application.h"
9
10 #include "SalomeApp_Study.h"
11 #include "SalomeApp_DataModel.h"
12 #include "SalomeApp_DataObject.h"
13 #include "SalomeApp_EventFilter.h"
14
15 #include "SalomeApp_StudyPropertiesDlg.h"
16
17 #include "SalomeApp_CheckFileDlg.h"
18
19 #include "LightApp_Application.h"
20 #include "LightApp_Preferences.h"
21 #include "LightApp_WidgetContainer.h"
22 #include "LightApp_SelectionMgr.h"
23
24 #include "STD_LoadStudiesDlg.h"
25
26 #include <SUIT_Tools.h>
27 #include <SUIT_Session.h>
28
29 #include <QtxMRUAction.h>
30
31 #include <OB_Browser.h>
32 #include <OB_ListItem.h>
33
34 #include <PythonConsole_PyConsole.h>
35
36 #include <SUIT_FileDlg.h>
37 #include <SUIT_MessageBox.h>
38 #include <SUIT_ResourceMgr.h>
39 #include <SUIT_ActionOperation.h>
40
41 #include <Utils_ORB_INIT.hxx>
42 #include <Utils_SINGLETON.hxx>
43 #include <SALOME_ModuleCatalog_impl.hxx>
44 #include <SALOME_LifeCycleCORBA.hxx>
45
46 #include <qmap.h>
47 #include <qaction.h>
48 #include <qcombobox.h>
49 #include <qlistbox.h>
50 #include <qregexp.h>
51
52 #include "SALOMEDS_StudyManager.hxx"
53 #include "SALOMEDS_SObject.hxx"
54
55 #include "SALOME_ListIteratorOfListIO.hxx"
56 #include "SALOME_ListIO.hxx"
57
58 #include "ToolsGUI_CatalogGeneratorDlg.h"
59 #include "ToolsGUI_RegWidget.h"
60
61 /*!Create new instance of SalomeApp_Application.*/
62 extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication()
63 {
64   return new SalomeApp_Application();
65 }
66
67 /*
68   Class       : SalomeApp_Application
69   Description : Application containing SalomeApp module or LightApp module
70 */
71
72 /*!Constructor.*/
73 SalomeApp_Application::SalomeApp_Application()
74 : LightApp_Application()
75 {
76 }
77
78 /*!Destructor.
79  *\li Destroy event filter.
80  */
81 SalomeApp_Application::~SalomeApp_Application()
82 {
83   SalomeApp_EventFilter::Destroy();
84 }
85
86 /*!Start application.*/
87 void SalomeApp_Application::start()
88 {
89   LightApp_Application::start();
90
91   SalomeApp_EventFilter::Init();
92 }
93
94 /*!Create actions:*/
95 void SalomeApp_Application::createActions()
96 {
97   LightApp_Application::createActions();
98
99   SUIT_Desktop* desk = desktop();
100   
101   //! Dump study
102   createAction( DumpStudyId, tr( "TOT_DESK_FILE_DUMP_STUDY" ), QIconSet(),
103                 tr( "MEN_DESK_FILE_DUMP_STUDY" ), tr( "PRP_DESK_FILE_DUMP_STUDY" ),
104                 0, desk, false, this, SLOT( onDumpStudy() ) );
105     
106   //! Load script
107   createAction( LoadScriptId, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), QIconSet(),
108                 tr( "MEN_DESK_FILE_LOAD_SCRIPT" ), tr( "PRP_DESK_FILE_LOAD_SCRIPT" ),
109                 0, desk, false, this, SLOT( onLoadScript() ) );
110
111   //! Properties
112   createAction( PropertiesId, tr( "TOT_DESK_PROPERTIES" ), QIconSet(),
113                 tr( "MEN_DESK_PROPERTIES" ), tr( "PRP_DESK_PROPERTIES" ),
114                 0, desk, false, this, SLOT( onProperties() ) );
115
116   //! Catalog Generator
117   createAction( CatalogGenId, tr( "TOT_DESK_CATALOG_GENERATOR" ),  QIconSet(),
118                 tr( "MEN_DESK_CATALOG_GENERATOR" ), tr( "PRP_DESK_CATALOG_GENERATOR" ),
119                 0, desk, false, this, SLOT( onCatalogGen() ) );
120
121   //! Registry Display
122   createAction( RegDisplayId, tr( "TOT_DESK_REGISTRY_DISPLAY" ),  QIconSet(),
123                 tr( "MEN_DESK_REGISTRY_DISPLAY" ), tr( "PRP_DESK_REGISTRY_DISPLAY" ),
124                 0, desk, false, this, SLOT( onRegDisplay() ) );
125
126   int fileMenu = createMenu( tr( "MEN_DESK_FILE" ), -1 );
127
128   createMenu( DumpStudyId, fileMenu, 10, -1 );
129   createMenu( separator(), fileMenu, -1, 15, -1 );
130   createMenu( LoadScriptId, fileMenu, 10, -1 );
131   createMenu( separator(), fileMenu, -1, 15, -1 );
132   createMenu( PropertiesId, fileMenu, 10, -1 );
133   createMenu( separator(), fileMenu, -1, 15, -1 );
134
135   int toolsMenu = createMenu( tr( "MEN_DESK_TOOLS" ), -1, -1, 50 );
136   createMenu( CatalogGenId, toolsMenu, 10, -1 );
137   createMenu( RegDisplayId, toolsMenu, 10, -1 );
138   createMenu( separator(), toolsMenu, -1, 15, -1 );
139 }
140
141 /*! Purpose : SLOT. Open new document with \a aName.*/
142 bool SalomeApp_Application::onOpenDoc( const QString& aName )
143 {
144   bool res = false, toOpen = true, isAlreadyOpen = false;
145
146   // Look among opened studies
147   if (activeStudy()) { // at least one study is opened
148     SUIT_Session* aSession = SUIT_Session::session();
149     QPtrList<SUIT_Application> aAppList = aSession->applications();
150     QPtrListIterator<SUIT_Application> it (aAppList);
151     SUIT_Application* aApp = 0;
152     // iterate on all applications
153     for (; (aApp = it.current()) && !isAlreadyOpen; ++it) {
154       if (aApp->activeStudy()->studyName() == aName) {
155         isAlreadyOpen = true; // Already opened, ask user what to do
156
157         // The document ... is already open.
158         // Do you want to reload it?
159         int aAnswer = SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"),
160                                              tr("QUE_DOC_ALREADYOPEN").arg(aName),
161                                              tr("BUT_YES"), tr("BUT_NO"), 1, 2, 2);
162         if (aAnswer == 1) { // reload
163           if (activeStudy()->studyName() == aName && aAppList.count() > 1) {
164             // Opened in THIS (active) application.
165             STD_Application* app1 = (STD_Application*)aAppList.at(0);
166             STD_Application* app2 = (STD_Application*)aAppList.at(1);
167             if (!app1 || !app2) {
168               // Error
169               return false;
170             }
171             if (app1->activeStudy()->studyName() == aName) {
172               // app1 is this application, we need another one
173               app1 = app2;
174             }
175             // Close document of this application. This application will be destroyed.
176             onCloseDoc(/*ask = */false);
177             // Open the file with another application, as this one will be destroyed.
178             return app1->onOpenDoc(aName);
179           } else {
180             // Opened in another application.
181             STD_Application* app = (STD_Application*)aApp;
182             if (app)
183               app->onCloseDoc(/*ask = */false);
184           }
185         } else { // do not reload
186           // OK, the study will not be reloaded, but we call
187           // CAM_Application::onOpenDoc( aName ) all the same.
188           // It will activate a desktop of the study <aName>.
189         }
190       }
191     }
192   }
193
194   // Look among unloaded studies
195   if (!isAlreadyOpen) {
196     std::vector<std::string> List = studyMgr()->GetOpenStudies();
197
198     QString studyName;
199     for (unsigned int ind = 0; ind < List.size() && !isAlreadyOpen; ind++) {
200       studyName = List[ind].c_str();
201       if (aName == studyName) {
202         // Already exists unloaded, ask user what to do
203         isAlreadyOpen = true;
204
205         // The document ... already exists in the study manager.
206         // Do you want to reload it?
207         int aAnswer = SUIT_MessageBox::warn2(desktop(), tr("WRN_WARNING"),
208                                              tr("QUE_DOC_ALREADYEXIST").arg(aName),
209                                              tr("BUT_YES"), tr("BUT_NO"), 1, 2, 2);
210         if (aAnswer == 1) {
211           _PTR(Study) aStudy = studyMgr()->GetStudyByName(aName.latin1());
212           if (aStudy)
213             studyMgr()->Close(aStudy);
214         } else {
215           toOpen = false;
216         }
217       }
218     }
219   }
220
221   if (toOpen)
222     res = CAM_Application::onOpenDoc( aName );
223
224   QAction* a = action( MRUId );
225   if ( a && a->inherits( "QtxMRUAction" ) )
226   {
227     QtxMRUAction* mru = (QtxMRUAction*)a;
228     if ( res )
229       mru->insert( aName );
230     else
231       mru->remove( aName );
232   }
233   return res;
234 }
235
236 /*!SLOT. Load document.*/
237 void SalomeApp_Application::onLoadDoc()
238 {
239   QString name, studyname, ext;
240
241   STD_LoadStudiesDlg aDlg( desktop(), TRUE);
242
243   std::vector<std::string> List = studyMgr()->GetOpenStudies();
244
245   SUIT_Session* aSession = SUIT_Session::session();
246   QPtrList<SUIT_Application> aAppList = aSession->applications();
247   SUIT_Application* aApp = 0;
248
249   for (unsigned int ind = 0; ind < List.size(); ind++) {
250      studyname = List[ind].c_str();
251      //Add to list only unloaded studies
252      bool isAlreadyOpen = false;
253      for ( QPtrListIterator<SUIT_Application> it( aAppList ); it.current() && !isAlreadyOpen; ++it )
254        {
255          aApp = it.current();
256          if(!aApp || !aApp->activeStudy()) continue;
257          if ( aApp->activeStudy()->studyName() == studyname ) isAlreadyOpen = true;
258        }
259
260      if ( !isAlreadyOpen ) aDlg.ListComponent->insertItem( studyname );
261   }
262
263   int retVal = aDlg.exec();
264   studyname = aDlg.ListComponent->currentText();
265
266   if (retVal == QDialog::Rejected)
267     return;
268
269   if ( studyname.isNull() || studyname.isEmpty() )
270     return;
271
272   name = studyname;
273   name.replace( QRegExp(":"), "/" );
274
275   if( LightApp_Application::onLoadDoc( name ) )
276   {
277      updateWindows();
278      updateViewManagers();
279      updateObjectBrowser(true);
280   }
281 }
282
283
284 /*!SLOT. Load document with \a aName.*/
285 bool SalomeApp_Application::onLoadDoc( const QString& aName )
286 {
287   return LightApp_Application::onLoadDoc( aName );
288 }
289
290 /*!SLOT. Copy objects to study maneger from selection maneger..*/
291 void SalomeApp_Application::onCopy()
292 {
293   SALOME_ListIO list;
294   LightApp_SelectionMgr* mgr = selectionMgr();
295   mgr->selectedObjects(list);
296   
297   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
298   if(study == NULL) return;
299   
300   _PTR(Study) stdDS = study->studyDS();
301   if(!stdDS) return;
302
303   SALOME_ListIteratorOfListIO it( list );
304   if(it.More())
305     {
306       _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
307       try {
308         studyMgr()->Copy(so);
309         onSelectionChanged();
310       }
311       catch(...) {
312       }
313     }
314 }
315
316 /*!SLOT. Paste objects to study maneger from selection manager.*/
317 void SalomeApp_Application::onPaste()
318 {
319   SALOME_ListIO list;
320   LightApp_SelectionMgr* mgr = selectionMgr();
321   mgr->selectedObjects(list);
322
323   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
324   if(study == NULL) return;
325
326   _PTR(Study) stdDS = study->studyDS();
327   if(!stdDS) return;
328
329   SALOME_ListIteratorOfListIO it( list );
330   if(it.More())
331     {
332       _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
333       try {
334         studyMgr()->Paste(so);
335         updateObjectBrowser( true );
336         updateActions(); //SRN: BugID IPAL9377, case 3
337       }
338       catch(...) {
339       }
340     }
341 }
342
343 /*!Sets enable or disable some actions on selection changed.*/
344 void SalomeApp_Application::onSelectionChanged()
345 {
346    SALOME_ListIO list;
347    LightApp_SelectionMgr* mgr = selectionMgr();
348    mgr->selectedObjects(list);
349
350    SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
351    if(study == NULL) return;
352
353    _PTR(Study) stdDS = study->studyDS();
354    if(!stdDS) return;
355
356    QAction* qaction;
357
358    SALOME_ListIteratorOfListIO it( list );
359    if(it.More() && list.Extent() == 1)
360    {
361       _PTR(SObject) so = stdDS->FindObjectID(it.Value()->getEntry());
362
363       qaction = action(EditCopyId);
364       if( so ) {
365         SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(so.get());
366         if ( aSO && studyMgr()->CanCopy(so) ) qaction->setEnabled(true);  
367         else qaction->setEnabled(false);
368       }
369       else qaction->setEnabled(false);
370
371       qaction = action(EditPasteId);
372       if( so ) {
373         SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(so.get());
374         if( aSO && studyMgr()->CanPaste(so) ) qaction->setEnabled(true);
375         qaction->setEnabled(false);
376       }
377       else qaction->setEnabled(false);
378    }
379    else {
380      qaction = action(EditCopyId);
381      qaction->setEnabled(false);
382      qaction = action(EditPasteId);
383      qaction->setEnabled(false);
384    }
385 }
386
387 /*!Delete references.*/
388 void SalomeApp_Application::onDeleteReferences()
389 {
390   SALOME_ListIO aList;
391   LightApp_SelectionMgr* mgr = selectionMgr();
392   mgr->selectedObjects(aList);
393
394   if (aList.Extent() < 1) return;
395
396   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
397   _PTR(Study) aStudyDS = aStudy->studyDS();
398   _PTR(StudyBuilder) aStudyBuilder = aStudyDS->NewBuilder();
399   _PTR(SObject) anObj;
400
401   for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() )
402     {
403       if ( it.Value()->hasEntry() )
404         {
405           _PTR(SObject) aSObject = aStudyDS->FindObjectID( it.Value()->getEntry() );
406           if ( aSObject->ReferencedObject(anObj) )
407             aStudyBuilder->RemoveReference(aSObject);
408         }
409     }
410
411   updateObjectBrowser();
412 }
413
414 /*!Private SLOT. */
415 void SalomeApp_Application::onOpenWith()
416 {
417   QApplication::setOverrideCursor( Qt::waitCursor );
418   SALOME_ListIO aList;
419   LightApp_SelectionMgr* mgr = selectionMgr();
420   mgr->selectedObjects(aList);
421   if (aList.Extent() != 1)
422     {
423       QApplication::restoreOverrideCursor();
424       return;
425     }
426   Handle(SALOME_InteractiveObject) aIObj = aList.First();
427   QString aModuleName(aIObj->getComponentDataType());
428   QString aModuleTitle = moduleTitle(aModuleName);
429   activateModule(aModuleTitle);
430   QApplication::restoreOverrideCursor();
431 }
432
433 //=======================================================================
434 // name    : createNewStudy
435 /*! Purpose : Create new study*/
436 //=======================================================================
437 SUIT_Study* SalomeApp_Application::createNewStudy()
438 {
439   SalomeApp_Study* aStudy = new SalomeApp_Study( this );
440
441   // Set up processing of major study-related events
442   connect( aStudy, SIGNAL( created( SUIT_Study* ) ), this, SLOT( onStudyCreated( SUIT_Study* ) ) );
443   connect( aStudy, SIGNAL( opened ( SUIT_Study* ) ), this, SLOT( onStudyOpened ( SUIT_Study* ) ) );
444   connect( aStudy, SIGNAL( saved  ( SUIT_Study* ) ), this, SLOT( onStudySaved  ( SUIT_Study* ) ) );
445   connect( aStudy, SIGNAL( closed ( SUIT_Study* ) ), this, SLOT( onStudyClosed ( SUIT_Study* ) ) );
446
447   return aStudy;
448 }
449
450 //=======================================================================
451 // name    : updateCommandsStatus
452 /*! Purpose : Enable/Disable menu items and toolbar buttons. Rebuild menu*/
453 //=======================================================================
454 void SalomeApp_Application::updateCommandsStatus()
455 {
456   LightApp_Application::updateCommandsStatus();
457
458   // Dump study menu
459   QAction* a = action( DumpStudyId );
460   if ( a )
461     a->setEnabled( activeStudy() );
462
463   // Load script menu
464   a = action( LoadScriptId );
465   if ( a )
466     a->setEnabled( activeStudy() );
467
468   a = action( PropertiesId );
469   if( a )
470     a->setEnabled( activeStudy() );
471
472   a = action(EditCopyId);
473   a->setEnabled(false);
474   a = action(EditPasteId);
475   a->setEnabled(false);
476 }
477
478 /*!Private SLOT. On dump study.*/
479 void SalomeApp_Application::onDumpStudy( )
480 {
481   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
482   if ( !appStudy ) return;
483   _PTR(Study) aStudy = appStudy->studyDS();
484
485   QStringList aFilters;
486   aFilters.append( tr( "PYTHON_FILES_FILTER" ) );
487
488   SalomeApp_CheckFileDlg* fd = new SalomeApp_CheckFileDlg( desktop(), false, tr("PUBLISH_IN_STUDY"), true, true);
489   fd->setCaption( tr( "TOT_DESK_FILE_DUMP_STUDY" ) );
490   fd->setFilters( aFilters );
491   fd->SetChecked(true);
492   fd->exec();
493   QString aFileName = fd->selectedFile();
494   bool toPublish = fd->IsChecked();
495   delete fd;
496
497   if(!aFileName.isEmpty()) {
498     QFileInfo aFileInfo(aFileName);
499     bool res = aStudy->DumpStudy( aFileInfo.dirPath( true ).latin1(), aFileInfo.baseName().latin1(), toPublish );
500     if ( !res )
501     SUIT_MessageBox::warn1 ( desktop(),
502                              QObject::tr("WRN_WARNING"),
503                              tr("WRN_DUMP_STUDY_FAILED"),
504                              QObject::tr("BUT_OK") );
505   }
506 }
507
508 /*!Private SLOT. On load script.*/
509 void SalomeApp_Application::onLoadScript( )
510 {
511   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( activeStudy() );
512   if ( !appStudy ) return;
513   _PTR(Study) aStudy = appStudy->studyDS();
514
515   if ( aStudy->GetProperties()->IsLocked() ) {
516     SUIT_MessageBox::warn1 ( desktop(),
517                              QObject::tr("WRN_WARNING"),
518                              QObject::tr("WRN_STUDY_LOCKED"),
519                              QObject::tr("BUT_OK") );
520     return;
521   }
522
523   QStringList filtersList;
524   filtersList.append(tr("PYTHON_FILES_FILTER"));
525   filtersList.append(tr("ALL_FILES_FILTER"));
526
527   QString aFile = SUIT_FileDlg::getFileName( desktop(), "", filtersList, tr( "TOT_DESK_FILE_LOAD_SCRIPT" ), true, true );
528
529   if ( !aFile.isEmpty() )
530   {
531     QString command = QString("execfile(\"%1\")").arg(aFile);
532
533     PythonConsole* pyConsole = pythonConsole();
534
535     if ( pyConsole )
536       pyConsole->exec( command );
537   }
538 }
539
540 /*!Gets file filter.
541  *\retval QString "(*.hdf)"
542  */
543 QString SalomeApp_Application::getFileFilter() const
544 {
545   return "(*.hdf)";
546 }
547
548 /*!Create window.*/
549 QWidget* SalomeApp_Application::createWindow( const int flag )
550 {
551   QWidget* wid = LightApp_Application::createWindow(flag);
552
553   SUIT_ResourceMgr* resMgr = resourceMgr();
554
555   if ( flag == WT_ObjectBrowser )
556   {
557     OB_Browser* ob = (OB_Browser*)wid;
558     connect( ob->listView(), SIGNAL( doubleClicked( QListViewItem* ) ), this, SLOT( onDblClick( QListViewItem* ) ) );
559     bool autoSize = resMgr->booleanValue( "ObjectBrowser", "auto_size", false );
560     for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
561     {
562       ob->addColumn( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), i );
563       ob->setColumnShown( i, resMgr->booleanValue( "ObjectBrowser",
564                                                    QString().sprintf( "visibility_column_%d", i ), true ) );
565     }
566     ob->setWidthMode( autoSize ? QListView::Maximum : QListView::Manual );
567   }
568   else if ( flag == WT_PyConsole )
569   {
570     delete wid;
571     wid = 0;
572     PythonConsole* pyCons = new PythonConsole( desktop(), new SalomeApp_PyInterp() );
573     pyCons->setCaption( tr( "PYTHON_CONSOLE" ) );
574     wid = pyCons;
575     //    pyCons->connectPopupRequest( this, SLOT( onConnectPopupRequest( SUIT_PopupClient*, QContextMenuEvent* ) ) );
576   }
577   return wid;
578 }
579
580 /*!Create preferences.*/
581 void SalomeApp_Application::createPreferences( LightApp_Preferences* pref )
582 {
583   LightApp_Application::createPreferences(pref);
584
585   if ( !pref )
586     return;
587
588   int salomeCat = pref->addPreference( tr( "PREF_CATEGORY_SALOME" ) );
589   int obTab = pref->addPreference( tr( "PREF_TAB_OBJBROWSER" ), salomeCat );
590   int defCols = pref->addPreference( tr( "PREF_GROUP_DEF_COLUMNS" ), obTab );
591   for ( int i = SalomeApp_DataObject::CT_Value; i <= SalomeApp_DataObject::CT_RefEntry; i++ )
592   {
593     pref->addPreference( tr( QString().sprintf( "OBJ_BROWSER_COLUMN_%d", i ) ), defCols,
594                          LightApp_Preferences::Bool, "ObjectBrowser", QString().sprintf( "visibility_column_%d", i ) );
595   }
596   pref->setItemProperty( defCols, "columns", 1 );
597
598   int objSetGroup = pref->addPreference( tr( "PREF_OBJ_BROWSER_SETTINGS" ), obTab );
599   pref->addPreference( tr( "PREF_AUTO_SIZE" ), objSetGroup, LightApp_Preferences::Bool, "ObjectBrowser", "auto_size" );
600 }
601
602 /*!Update desktop title.*/
603 void SalomeApp_Application::updateDesktopTitle() {
604   QString aTitle = applicationName();
605   QString aVer = applicationVersion();
606   if ( !aVer.isEmpty() )
607     aTitle += QString( " " ) + aVer;
608
609   if ( activeStudy() )
610   {
611     QString sName = SUIT_Tools::file( activeStudy()->studyName().stripWhiteSpace(), false );
612     if ( !sName.isEmpty() ) {
613       SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
614       if ( study ) {
615         _PTR(Study) stdDS = study->studyDS();
616         if(stdDS) {
617           if ( stdDS->GetProperties()->IsLocked() ) {
618             aTitle += QString( " - [%1 (%2)]").arg( sName ).arg( tr( "STUDY_LOCKED" ) );
619           } else {
620             aTitle += QString( " - [%1]" ).arg( sName );
621           }
622         }
623       }
624     }
625   }
626
627   desktop()->setCaption( aTitle );
628 }
629
630 /*!Gets CORBA::ORB_var*/
631 CORBA::ORB_var SalomeApp_Application::orb()
632 {
633   ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
634   static CORBA::ORB_var _orb = init( qApp->argc(), qApp->argv() );
635   return _orb;
636 }
637
638 /*!Create and return SALOMEDS_StudyManager.*/
639 SALOMEDSClient_StudyManager* SalomeApp_Application::studyMgr()
640 {
641   static SALOMEDSClient_StudyManager* _sm = new SALOMEDS_StudyManager();
642   return _sm;
643 }
644
645 /*!Create and return SALOME_NamingService.*/
646 SALOME_NamingService* SalomeApp_Application::namingService()
647 {
648   static SALOME_NamingService* _ns = new SALOME_NamingService( orb() );
649   return _ns;
650 }
651
652 /*!Create and return SALOME_LifeCycleCORBA.*/
653 SALOME_LifeCycleCORBA* SalomeApp_Application::lcc()
654 {
655   static SALOME_LifeCycleCORBA* _lcc = new SALOME_LifeCycleCORBA( namingService() );
656   return _lcc;
657 }
658
659 /*!Return default engine IOR for light modules*/
660 QString SalomeApp_Application::defaultEngineIOR()
661 {
662   /// Look for a default module engine (needed for CORBAless modules to use SALOMEDS persistence)
663   QString anIOR( "" );
664   CORBA::Object_ptr anEngine = namingService()->Resolve( "/SalomeAppEngine" );
665   if ( !CORBA::is_nil( anEngine ) )
666     anIOR = orb()->object_to_string( anEngine );
667   return anIOR;
668 }
669
670 /*!Private SLOT. On preferences.*/
671 void SalomeApp_Application::onProperties()
672 {
673   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
674   if( !study )
675     return;
676
677   _PTR(StudyBuilder) SB = study->studyDS()->NewBuilder();
678   SB->NewCommand();
679
680   SalomeApp_StudyPropertiesDlg aDlg( desktop() );
681   int res = aDlg.exec();
682   if( res==QDialog::Accepted && aDlg.isChanged() )
683     SB->CommitCommand();
684   else
685     SB->AbortCommand();
686
687   //study->updateCaptions();
688   updateDesktopTitle();
689   updateActions();
690 }
691
692 /*!Insert items in popup, which necessary for current application*/
693 void SalomeApp_Application::contextMenuPopup( const QString& type, QPopupMenu* thePopup, QString& title )
694 {
695   LightApp_Application::contextMenuPopup( type, thePopup, title );
696
697   OB_Browser* ob = objectBrowser();
698   if ( !ob || type != ob->popupClientType() )
699     return;
700
701   // Get selected objects
702   SALOME_ListIO aList;
703   LightApp_SelectionMgr* mgr = selectionMgr();
704   mgr->selectedObjects(aList);
705
706   // "Delete reference" item should appear only for invalid references
707
708   // Check if selected objects is invalid references
709   bool isInvalidRefs = true;
710
711   if ( aList.Extent() < 1 )
712     isInvalidRefs = false;
713
714   if ( isInvalidRefs )
715     {
716       SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(activeStudy());
717       _PTR(Study) aStudyDS = aStudy->studyDS();
718       _PTR(SObject) anObj;
719
720       for ( SALOME_ListIteratorOfListIO it( aList ); it.More() && isInvalidRefs; it.Next() )
721         {
722           if ( it.Value()->hasEntry() )
723             {
724               _PTR(SObject) aSObject = aStudyDS->FindObjectID( it.Value()->getEntry() );
725               SALOMEDS_SObject* aSO = dynamic_cast<SALOMEDS_SObject*>(aSObject.get());
726               if( aSO )
727                 if ( aSObject->ReferencedObject(anObj) == false || !QString(anObj->GetName().c_str()).isEmpty() )
728                   isInvalidRefs = false;
729             }
730         }
731     }
732
733   // Add "Delete refrence" item to popup
734   if ( isInvalidRefs )
735     {
736       thePopup->insertSeparator();
737       thePopup->insertItem( tr( "MEN_DELETE_REFERENCE" ), this, SLOT( onDeleteReferences() ) );
738       return;
739     }
740
741   // "Activate module" item should appear only if it's necessary
742   if (aList.Extent() != 1)
743     return;
744   Handle(SALOME_InteractiveObject) aIObj = aList.First();
745   QString aModuleName(aIObj->getComponentDataType());
746   QString aModuleTitle = moduleTitle(aModuleName);
747   CAM_Module* currentModule = activeModule();
748   if (currentModule && currentModule->moduleName() == aModuleTitle)
749     return;
750   thePopup->insertItem( tr( "MEN_OPENWITH" ), this, SLOT( onOpenWith() ) );
751
752 }
753
754 /*!Update obect browser:
755  1.if 'updateModels' true, update existing data models;
756  2. update "non-existing" (not loaded yet) data models;
757  3. update object browser if it existing */
758 void SalomeApp_Application::updateObjectBrowser( const bool updateModels )
759 {
760   // update existing data models (already loaded SComponents)
761   LightApp_Application::updateObjectBrowser(updateModels);
762
763   // update "non-existing" (not loaded yet) data models
764   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
765   if ( study )
766   {
767     _PTR(Study) stdDS = study->studyDS();
768     if( stdDS )
769     {
770       for ( _PTR(SComponentIterator) it ( stdDS->NewComponentIterator() ); it->More(); it->Next() ) 
771       {
772         _PTR(SComponent) aComponent ( it->Value() );
773
774         if ( aComponent->ComponentDataType() == "Interface Applicative" )
775           continue; // skip the magic "Interface Applicative" component
776
777         SalomeApp_DataModel::BuildTree( aComponent, study->root(), study, /*skipExisitng=*/true );
778       }
779     }
780   }
781
782   if ( objectBrowser() )
783   {
784     objectBrowser()->updateGeometry();
785     objectBrowser()->updateTree();
786   }
787 }
788
789 /*!Display Catalog Genenerator dialog */
790 void SalomeApp_Application::onCatalogGen()
791 {
792   ToolsGUI_CatalogGeneratorDlg aDlg( desktop() );
793   aDlg.exec();
794 }
795
796 /*!Display Registry Display dialog */
797 void SalomeApp_Application::onRegDisplay()
798 {
799   CORBA::ORB_var anOrb = orb();
800   ToolsGUI_RegWidget* regWnd = ToolsGUI_RegWidget::GetRegWidget( anOrb, desktop(), "Registry" );
801   regWnd->show();
802   regWnd->raise();
803   regWnd->setActiveWindow();
804 }
805
806 /*!find original object by double click on item */
807 void SalomeApp_Application::onDblClick( QListViewItem* it )
808 {
809   OB_ListItem* item = dynamic_cast<OB_ListItem*>( it );
810   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( activeStudy() );
811
812   if( study && item )
813   {
814     SalomeApp_DataObject* obj = dynamic_cast<SalomeApp_DataObject*>( item->dataObject() );
815     if( !obj )
816       return;
817
818     QString entry = obj->entry();
819     _PTR(SObject) sobj = study->studyDS()->FindObjectID( entry.latin1() ), ref;
820
821     if( sobj && sobj->ReferencedObject( ref ) )
822     {
823       entry = ref->GetID().c_str();
824       QListViewItemIterator anIt( item->listView() );
825       for( ; anIt.current(); anIt++ )
826       {
827         OB_ListItem* item = dynamic_cast<OB_ListItem*>( anIt.current() );
828         if( !item )
829           continue;
830
831         SalomeApp_DataObject* original = dynamic_cast<SalomeApp_DataObject*>( item->dataObject() );
832         if( original->entry()!=entry )
833           continue;
834
835         OB_Browser* br = objectBrowser();
836         br->setSelected( original );
837         SUIT_DataObject* p = original->parent();
838         while( p )
839         {
840           br->setOpen( p );
841           p = p->parent();
842         }
843         break;
844       }
845     }
846   }
847 }