Salome HOME
c80c8a7aefc0f02908614c0abc7b7857f0f1b5b6
[modules/shaper.git] / src / XGUI / XGUI_Workshop.cpp
1 #include "XGUI_Module.h"
2 #include "XGUI_Constants.h"
3 #include "XGUI_Command.h"
4 #include "XGUI_MainMenu.h"
5 #include "XGUI_MainWindow.h"
6 #include "XGUI_MenuGroupPanel.h"
7 #include "XGUI_Tools.h"
8 #include "XGUI_Workbench.h"
9 #include "XGUI_Workshop.h"
10 #include "XGUI_Viewer.h"
11 #include "ModuleBase_WidgetFactory.h"
12 #include "XGUI_SelectionMgr.h"
13 #include "XGUI_ObjectsBrowser.h"
14 #include "XGUI_Displayer.h"
15 #include "XGUI_OperationMgr.h"
16 #include "XGUI_SalomeConnector.h"
17 #include "XGUI_SalomeViewer.h"
18 #include "XGUI_ActionsMgr.h"
19 #include "XGUI_ErrorDialog.h"
20 #include "XGUI_ViewerProxy.h"
21 #include "XGUI_PropertyPanel.h"
22
23 #include <Model_Events.h>
24 #include <ModelAPI_PluginManager.h>
25 #include <ModelAPI_Feature.h>
26 #include <ModelAPI_Data.h>
27 #include <ModelAPI_AttributeDocRef.h>
28
29 #include <Events_Loop.h>
30 #include <Events_Error.h>
31 #include <ModuleBase_Operation.h>
32 #include <ModuleBase_Operation.h>
33 #include <ModuleBase_OperationDescription.h>
34 #include <Config_FeatureMessage.h>
35 #include <Config_PointerMessage.h>
36
37 #include <QApplication>
38 #include <QFileDialog>
39 #include <QMessageBox>
40 #include <QMdiSubWindow>
41 #include <QPushButton>
42 #include <QDockWidget>
43 #include <QLayout>
44
45 #ifdef _DEBUG
46 #include <QDebug>
47 #endif
48
49 #ifdef WIN32
50 #include <windows.h>
51 #else
52 #include <dlfcn.h>
53 #endif
54
55 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
56   : QObject(),
57   myCurrentFile(QString()),
58   myPartSetModule(NULL),
59   mySalomeConnector(theConnector),
60   myPropertyPanel(0),
61   myObjectBrowser(0),
62   myDisplayer(0)
63 {
64   myMainWindow = mySalomeConnector? 0 : new XGUI_MainWindow();
65
66   myDisplayer = new XGUI_Displayer(this);
67
68   mySelector = new XGUI_SelectionMgr(this);
69   connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(changeCurrentDocument()));
70
71   myOperationMgr = new XGUI_OperationMgr(this);
72   myActionsMgr = new XGUI_ActionsMgr(this);
73   myErrorDlg = new XGUI_ErrorDialog(myMainWindow);
74
75   myViewerProxy = new XGUI_ViewerProxy(this);
76
77   connect(myOperationMgr, SIGNAL(operationStarted()),  this, SLOT(onOperationStarted()));
78   connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
79           this, SLOT(onOperationStopped(ModuleBase_Operation*)));
80   connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&)));
81 }
82
83 //******************************************************
84 XGUI_Workshop::~XGUI_Workshop(void)
85 {
86 }
87
88 //******************************************************
89 void XGUI_Workshop::startApplication()
90 {
91   initMenu();
92   //Initialize event listening
93   Events_Loop* aLoop = Events_Loop::loop();
94   aLoop->registerListener(this, Events_Error::errorID()); //!< Listening application errors.
95   //TODO(sbh): Implement static method to extract event id [SEID]
96   Events_ID aFeatureId = aLoop->eventByName(EVENT_FEATURE_LOADED);
97   aLoop->registerListener(this, aFeatureId);
98   Events_ID aPartSetId = aLoop->eventByName("PartSetModuleEvent");
99   aLoop->registerListener(this, aPartSetId);
100   Events_ID aFeatureUpdatedId = aLoop->eventByName(EVENT_FEATURE_UPDATED);
101   aLoop->registerListener(this, aFeatureUpdatedId);
102   activateModule();
103   if (myMainWindow) {
104     myMainWindow->show();
105     updateCommandStatus();
106   }
107   onNew();
108 }
109
110 //******************************************************
111 void XGUI_Workshop::initMenu()
112 {
113   if (isSalomeMode()) {
114     // Create only Undo, Redo commands
115     salomeConnector()->addEditCommand("UNDO_CMD", 
116                                       tr("Undo"), tr("Undo last command"),
117                                       QIcon(":pictures/undo.png"), 
118                                       false, this, SLOT(onUndo()),
119                                       QKeySequence::Undo);
120     salomeConnector()->addEditCommand("REDO_CMD", 
121                                       tr("Redo"), tr("Redo last command"),
122                                       QIcon(":pictures/redo.png"), 
123                                       false, this, SLOT(onRedo()),
124                                       QKeySequence::Redo);
125     salomeConnector()->addEditMenuSeparator();
126     return;
127   }
128   XGUI_Workbench* aPage = myMainWindow->menuObject()->generalPage();
129
130   // File commands group
131   XGUI_MenuGroupPanel* aGroup = aPage->addGroup("Default");
132
133   XGUI_Command* aCommand;
134
135   aCommand = aGroup->addFeature("SAVE_CMD", tr("Save..."), tr("Save the document"),
136                                 QIcon(":pictures/save.png"), QKeySequence::Save);
137   aCommand->connectTo(this, SLOT(onSave()));
138   //aCommand->disable();
139
140   aCommand = aGroup->addFeature("UNDO_CMD", tr("Undo"), tr("Undo last command"),
141                                 QIcon(":pictures/undo.png"), QKeySequence::Undo);
142   aCommand->connectTo(this, SLOT(onUndo()));
143
144   aCommand = aGroup->addFeature("REDO_CMD", tr("Redo"), tr("Redo last command"),
145                                 QIcon(":pictures/redo.png"), QKeySequence::Redo);
146   aCommand->connectTo(this, SLOT(onRedo()));
147
148   aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
149                                 QIcon(":pictures/rebuild.png"));
150
151   aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
152                                 QIcon(":pictures/save.png"));
153   aCommand->connectTo(this, SLOT(onSaveAs()));
154   //aCommand->disable();
155
156   aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
157                                 QIcon(":pictures/open.png"), QKeySequence::Open);
158   aCommand->connectTo(this, SLOT(onOpen()));
159
160   //aCommand = aGroup->addFeature("NEW_CMD", tr("New"), tr("Create a new document"),
161   //                              QIcon(":pictures/new.png"), QKeySequence::New);
162   //aCommand->connectTo(this, SLOT(onNew()));
163
164   aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
165                                 QIcon(":pictures/close.png"), QKeySequence::Close);
166   aCommand->connectTo(this, SLOT(onExit()));
167
168 }
169
170 //******************************************************
171 XGUI_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
172 {
173   XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
174   return aMenuBar->addWorkbench(theName);
175 }
176
177 //******************************************************
178 void XGUI_Workshop::processEvent(const Events_Message* theMessage)
179 {
180   static Events_ID aFeatureLoadedId = Events_Loop::loop()->eventByName(EVENT_FEATURE_LOADED);
181   if (theMessage->eventID() == aFeatureLoadedId) {
182     const Config_FeatureMessage* aFeatureMsg = dynamic_cast<const Config_FeatureMessage*>(theMessage);
183     addFeature(aFeatureMsg);
184     return;
185   }
186   static Events_ID aFeatureUpdatedId = Events_Loop::loop()->eventByName(EVENT_FEATURE_UPDATED);
187   if (theMessage->eventID() == aFeatureUpdatedId)
188   {
189     myPropertyPanel->updateContentWidget();
190   }
191   const Config_PointerMessage* aPartSetMsg = dynamic_cast<const Config_PointerMessage*>(theMessage);
192   if (aPartSetMsg) {
193     ModuleBase_Operation* anOperation =
194         (ModuleBase_Operation*)(aPartSetMsg->pointer());
195
196     if (myOperationMgr->startOperation(anOperation)) {
197       if (anOperation->getDescription()->xmlRepresentation().isEmpty()) {
198         anOperation->commit();
199         updateCommandStatus();
200       }
201     }
202     return;
203   }
204   const Events_Error* anAppError = dynamic_cast<const Events_Error*>(theMessage);
205   if (anAppError) {
206     emit errorOccurred(QString::fromLatin1(anAppError->description()));
207     myErrorDlg->show();
208     myErrorDlg->raise();
209     myErrorDlg->activateWindow();
210   }
211
212 }
213
214 //******************************************************
215 void XGUI_Workshop::onOperationStarted()
216 {
217   ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
218
219   if(!aOperation->getDescription()->xmlRepresentation().isEmpty()) { //!< No need for property panel
220     connectWithOperation(aOperation);
221
222     showPropertyPanel();
223
224     ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aOperation);
225     aFactory.createWidget(myPropertyPanel->contentWidget());
226     myPropertyPanel->setModelWidgets(aFactory.getWrappedWidgets());
227     myPropertyPanel->setWindowTitle(aOperation->getDescription()->description());
228   }
229 }
230
231 //******************************************************
232 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
233 {
234   ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
235
236   if(aOperation->getDescription()->xmlRepresentation().isEmpty()) { //!< No need for property panel
237     updateCommandStatus();
238   } else {
239     hidePropertyPanel();
240     updateCommandStatus();
241     myActionsMgr->restoreCommandState();
242   }
243 }
244
245 /*
246  *
247  */
248 void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage)
249 {
250   if (!theMessage) {
251 #ifdef _DEBUG
252     qDebug() << "XGUI_Workshop::addFeature: NULL message.";
253 #endif
254     return;
255   }
256   //Find or create Workbench
257   QString aWchName = QString::fromStdString(theMessage->workbenchId());
258   QString aNestedFeatures = QString::fromStdString(theMessage->nestedFeatures());
259   bool isUsePropPanel = theMessage->isUseInput();
260   if (isSalomeMode()) {
261     QString aId = QString::fromStdString(theMessage->id());
262     salomeConnector()->addFeature(aWchName,
263                                   QString::fromStdString(theMessage->id()),
264                                   aId,
265                                   QString::fromStdString(theMessage->tooltip()),
266                                   QIcon(theMessage->icon().c_str()),
267                                   isUsePropPanel, this, 
268                                   SLOT(onFeatureTriggered()), QKeySequence());
269     myActionsMgr->addCommand(aId, salomeConnector()->command(aId));
270     salomeConnector()->setNestedActions(aId, aNestedFeatures.split(" "));
271
272   } else {
273
274     XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
275     XGUI_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
276     if (!aPage) {
277       aPage = addWorkbench(aWchName);
278     }
279     //Find or create Group
280     QString aGroupName = QString::fromStdString(theMessage->groupId());
281     XGUI_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
282     if (!aGroup) {
283       aGroup = aPage->addGroup(aGroupName);
284     }
285     //Create feature...
286     XGUI_Command* aCommand = aGroup->addFeature(QString::fromStdString(theMessage->id()),
287                                                 QString::fromStdString(theMessage->text()),
288                                                 QString::fromStdString(theMessage->tooltip()),
289                                                 QIcon(theMessage->icon().c_str()),
290                                                 QKeySequence(), isUsePropPanel);
291     aCommand->setUnblockableCommands(aNestedFeatures.split(" "));
292     myActionsMgr->addCommand(aCommand);
293     myPartSetModule->featureCreated(aCommand);
294   }
295 }
296
297 /*
298  * Makes a signal/slot connections between Property Panel
299  * and given operation. The given operation becomes a
300  * current operation and previous operation if exists
301  */
302 void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
303 {
304   QPushButton* aOkBtn = myPropertyPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
305   connect(aOkBtn, SIGNAL(clicked()), theOperation, SLOT(commit()));
306   QPushButton* aCancelBtn = myPropertyPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
307   connect(aCancelBtn, SIGNAL(clicked()), theOperation, SLOT(abort()));
308
309   QAction* aCommand = 0;
310   if (isSalomeMode()) {
311     aCommand = salomeConnector()->command(theOperation->getDescription()->operationId());
312   } else {
313     XGUI_MainMenu* aMenu = myMainWindow->menuObject();
314     aCommand = aMenu->feature(theOperation->getDescription()->operationId());
315   }
316   //Abort operation on uncheck the command
317   connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
318 }
319
320 /*
321  * Saves document with given name.
322  */
323 void XGUI_Workshop::saveDocument(QString theName)
324 {
325   QApplication::restoreOverrideCursor();
326   boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
327   boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
328   aDoc->save(theName.toLatin1().constData());
329   QApplication::restoreOverrideCursor();
330 }
331
332 //******************************************************
333 void XGUI_Workshop::onExit()
334 {
335   boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
336   boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
337   if(aDoc->isModified()) {
338     int anAnswer = QMessageBox::question(
339         myMainWindow, tr("Save current file"),
340         tr("The document is modified, save before exit?"),
341         QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
342     if(anAnswer == QMessageBox::Save) {
343       onSave();
344     } else if (anAnswer == QMessageBox::Cancel) {
345       return;
346     }
347   }
348   qApp->exit();
349 }
350
351 //******************************************************
352 void XGUI_Workshop::onNew()
353 {
354   QApplication::setOverrideCursor(Qt::WaitCursor);
355   if (objectBrowser() == 0) {
356     createDockWidgets();
357     mySelector->connectViewers();
358   }
359   myViewerProxy->connectToViewer();
360   showObjectBrowser();
361   if (!isSalomeMode()) {
362     myMainWindow->showPythonConsole();
363     QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
364     aWnd->showMaximized();
365     updateCommandStatus();
366   }
367   QApplication::restoreOverrideCursor();
368 }
369
370 //******************************************************
371 void XGUI_Workshop::onOpen()
372 {
373   //save current file before close if modified
374   boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
375   boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
376   if(aDoc->isModified()) {
377     //TODO(sbh): re-launch the app?
378     int anAnswer = QMessageBox::question(
379         myMainWindow, tr("Save current file"),
380         tr("The document is modified, save before opening another?"),
381         QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
382     if(anAnswer == QMessageBox::Save) {
383       onSave();
384     } else if (anAnswer == QMessageBox::Cancel) {
385       return;
386     }
387     aDoc->close();
388     myCurrentFile = "";
389   }
390
391   //show file dialog, check if readable and open
392   myCurrentFile = QFileDialog::getOpenFileName(mainWindow());
393   if(myCurrentFile.isEmpty())
394     return;
395   QFileInfo aFileInfo(myCurrentFile);
396   if(!aFileInfo.exists() || !aFileInfo.isReadable()) {
397     QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
398     myCurrentFile = "";
399     return;
400   }
401   QApplication::setOverrideCursor(Qt::WaitCursor);
402   aDoc->load(myCurrentFile.toLatin1().constData());
403   QApplication::restoreOverrideCursor();
404   updateCommandStatus();
405 }
406
407 //******************************************************
408 void XGUI_Workshop::onSave()
409 {
410   if(myCurrentFile.isEmpty()) {
411     onSaveAs();
412     return;
413   }
414   saveDocument(myCurrentFile);
415   updateCommandStatus();
416 }
417
418 //******************************************************
419 void XGUI_Workshop::onSaveAs()
420 {
421   QString aTemp = myCurrentFile;
422   myCurrentFile = QFileDialog::getSaveFileName(mainWindow());
423   if(myCurrentFile.isEmpty()) {
424     myCurrentFile = aTemp;
425     return;
426   }
427   QFileInfo aFileInfo(myCurrentFile);
428   if(aFileInfo.exists() && !aFileInfo.isWritable()) {
429     QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to save the file."));
430     return;
431   }
432   onSave();
433 }
434
435 //******************************************************
436 void XGUI_Workshop::onUndo()
437 {
438   objectBrowser()->setCurrentIndex(QModelIndex());
439   boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
440   boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
441   aDoc->undo();
442   updateCommandStatus();
443 }
444
445 //******************************************************
446 void XGUI_Workshop::onRedo()
447 {
448   objectBrowser()->setCurrentIndex(QModelIndex());
449   boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
450   boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
451   aDoc->redo();
452   updateCommandStatus();
453 }
454
455 //******************************************************
456 XGUI_Module* XGUI_Workshop::loadModule(const QString& theModule)
457 {
458   QString libName = library(theModule);
459   if (libName.isEmpty()) {
460     qWarning(
461     qPrintable( tr( "Information about module \"%1\" doesn't exist." ).arg( theModule ) ));
462     return 0;
463   }
464
465   QString err;
466   CREATE_FUNC crtInst = 0;
467
468 #ifdef WIN32
469
470   HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
471   if (!modLib) {
472     LPVOID lpMsgBuf;
473     ::FormatMessage(
474         FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
475         0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
476     QString aMsg((char*) &lpMsgBuf);
477     err = QString("Failed to load  %1. %2").arg(libName).arg(aMsg);
478     ::LocalFree(lpMsgBuf);
479   } else {
480     crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
481     if (!crtInst) {
482       LPVOID lpMsgBuf;
483       ::FormatMessage(
484           FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
485               | FORMAT_MESSAGE_IGNORE_INSERTS,
486           0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
487       QString aMsg((char*) &lpMsgBuf);
488       err = QString("Failed to find  %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
489       ::LocalFree(lpMsgBuf);
490     }
491   }
492 #else
493   void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY );
494   if ( !modLib )
495   err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
496   else
497   {
498     crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
499     if ( !crtInst )
500     err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
501   }
502 #endif
503
504   XGUI_Module* aModule = crtInst ? crtInst(this) : 0;
505
506   if (!err.isEmpty()) {
507     if (mainWindow() && mainWindow()->isVisible())
508       QMessageBox::warning(mainWindow(), tr("Error"), err);
509     else
510       qWarning( qPrintable( err ));
511   }
512   return aModule;
513 }
514
515 //******************************************************
516 bool XGUI_Workshop::activateModule()
517 {
518   myPartSetModule = loadModule("PartSet");
519   if (!myPartSetModule)
520     return false;
521   myPartSetModule->createFeatures();
522   return true;
523 }
524
525 //******************************************************
526 void XGUI_Workshop::updateCommandStatus()
527 {
528   if (isSalomeMode()) // TODO: update commands in SALOME
529     return;
530   XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
531
532   QList<XGUI_Command*> aCommands = aMenuBar->features();
533   QList<XGUI_Command*>::const_iterator aIt;
534
535   boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
536   if (aMgr->hasRootDocument()) {
537     XGUI_Command* aUndoCmd;
538     XGUI_Command* aRedoCmd;
539     for (aIt = aCommands.constBegin(); aIt != aCommands.constEnd(); ++aIt) {
540       if ((*aIt)->id() == "UNDO_CMD")
541         aUndoCmd = (*aIt);
542       else if ((*aIt)->id() == "REDO_CMD")
543         aRedoCmd = (*aIt);
544       else // Enable all commands
545         (*aIt)->enable();
546     }
547     boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
548     aUndoCmd->setEnabled(aDoc->canUndo());
549     aRedoCmd->setEnabled(aDoc->canRedo());
550   } else {
551     for (aIt = aCommands.constBegin(); aIt != aCommands.constEnd(); ++aIt) {
552       if ((*aIt)->id() == "NEW_CMD")
553         (*aIt)->enable();
554       else if ((*aIt)->id() == "EXIT_CMD")
555         (*aIt)->enable();
556       else 
557         (*aIt)->disable();
558     }
559   }
560 }
561
562 //******************************************************
563 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
564 {
565   QDockWidget* aObjDock = new QDockWidget(theParent);
566   aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
567   aObjDock->setWindowTitle(tr("Object browser"));
568   myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
569   aObjDock->setWidget(myObjectBrowser);
570   return aObjDock;
571 }
572
573 //******************************************************
574 /*
575  * Creates dock widgets, places them in corresponding area
576  * and tabifies if necessary.
577  */
578 void XGUI_Workshop::createDockWidgets()
579 {
580   QMainWindow* aDesktop = isSalomeMode()? salomeConnector()->desktop() :
581                                           myMainWindow;
582   QDockWidget* aObjDock = createObjectBrowser(aDesktop);
583   aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
584   myPropertyPanel = new XGUI_PropertyPanel(aDesktop);
585   aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
586   hidePropertyPanel(); //<! Invisible by default
587   hideObjectBrowser();
588   aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
589 }
590
591 //******************************************************
592 void XGUI_Workshop::showPropertyPanel()
593 {
594   QAction* aViewAct = myPropertyPanel->toggleViewAction();
595   //<! Restore ability to close panel from the window's menu
596   aViewAct->setEnabled(true);
597   myPropertyPanel->show();
598   myPropertyPanel->raise();
599 }
600
601 //******************************************************
602 void XGUI_Workshop::hidePropertyPanel()
603 {
604   QAction* aViewAct = myPropertyPanel->toggleViewAction();
605   //<! Do not allow to show empty property panel
606   aViewAct->setEnabled(false);
607   myPropertyPanel->hide();
608 }
609
610 //******************************************************
611 void XGUI_Workshop::showObjectBrowser()
612 {
613   myObjectBrowser->parentWidget()->show();
614 }
615
616 //******************************************************
617 void XGUI_Workshop::hideObjectBrowser()
618 {
619   myObjectBrowser->parentWidget()->hide();
620 }
621
622 //******************************************************
623 void XGUI_Workshop::onFeatureTriggered()
624 {
625   QAction* aCmd = dynamic_cast<QAction*>(sender());
626   if (aCmd) {
627     QString aId = salomeConnector()->commandId(aCmd);
628     if (!aId.isNull())
629       myPartSetModule->launchOperation(aId);
630   }
631 }
632
633 //******************************************************
634 void XGUI_Workshop::changeCurrentDocument()
635 {
636   QFeatureList aFeatures = objectBrowser()->selectedFeatures();
637   
638   // Set current document
639   if (aFeatures.size() > 0) {
640     FeaturePtr aFeature = aFeatures.first();
641
642     boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
643     boost::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = aFeature->data()->docRef("PartDocument");
644     if (aDocRef)
645       aMgr->setCurrentDocument(aDocRef->value());
646   }
647 }
648
649 //******************************************************
650 void XGUI_Workshop::salomeViewerSelectionChanged()
651 {
652   emit salomeViewerSelection();
653 }
654
655
656 //**************************************************************
657 XGUI_SalomeViewer* XGUI_Workshop::salomeViewer() const 
658
659   return mySalomeConnector->viewer(); 
660 }