]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Workshop.cpp
Salome HOME
Issue #6 uncheck only one aborted operation, not all nested stack
[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   //A message to start feature creation received.
181   static Events_ID aFeatureLoadedId = Events_Loop::loop()->eventByName(EVENT_FEATURE_LOADED);
182   if (theMessage->eventID() == aFeatureLoadedId) {
183     const Config_FeatureMessage* aFeatureMsg = dynamic_cast<const Config_FeatureMessage*>(theMessage);
184     addFeature(aFeatureMsg);
185     return;
186   }
187   //Update property panel on corresponding message. If there is no current operation (no
188   //property panel), or received message has different feature to the current - do nothing.
189   static Events_ID aFeatureUpdatedId = Events_Loop::loop()->eventByName(EVENT_FEATURE_UPDATED);
190   if (theMessage->eventID() == aFeatureUpdatedId && myOperationMgr->hasOperation())
191   {
192     const Model_FeatureUpdatedMessage* anUpdateMsg =
193         dynamic_cast<const Model_FeatureUpdatedMessage*>(theMessage);
194     boost::shared_ptr<ModelAPI_Feature> aNewFeature = anUpdateMsg->feature();
195     boost::shared_ptr<ModelAPI_Feature> aCurrentFeature = myOperationMgr->currentOperation()->feature();
196     if(aNewFeature == aCurrentFeature) {
197       myPropertyPanel->updateContentWidget(aCurrentFeature);
198     }
199   }
200   //An operation passed by message. Start it, process and commit.
201   const Config_PointerMessage* aPartSetMsg = dynamic_cast<const Config_PointerMessage*>(theMessage);
202   if (aPartSetMsg) {
203     ModuleBase_Operation* anOperation =
204         (ModuleBase_Operation*)(aPartSetMsg->pointer());
205
206     if (myOperationMgr->startOperation(anOperation)) {
207       if (anOperation->getDescription()->xmlRepresentation().isEmpty()) {
208         anOperation->commit();
209         updateCommandStatus();
210       }
211     }
212     return;
213   }
214   //Show error dialog if error message received.
215   const Events_Error* anAppError = dynamic_cast<const Events_Error*>(theMessage);
216   if (anAppError) {
217     emit errorOccurred(QString::fromLatin1(anAppError->description()));
218     myErrorDlg->show();
219     myErrorDlg->raise();
220     myErrorDlg->activateWindow();
221   }
222
223 }
224
225 //******************************************************
226 void XGUI_Workshop::onOperationStarted()
227 {
228   ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
229
230   if(!aOperation->getDescription()->xmlRepresentation().isEmpty()) { //!< No need for property panel
231     connectWithOperation(aOperation);
232
233     showPropertyPanel();
234
235     ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aOperation);
236     QWidget* aContent = myPropertyPanel->contentWidget();
237     qDeleteAll(aContent->children());
238     aFactory.createWidget(aContent);
239     myPropertyPanel->setModelWidgets(aFactory.getModelWidgets());
240     myPropertyPanel->setWindowTitle(aOperation->getDescription()->description());
241   }
242 }
243
244 //******************************************************
245 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
246 {
247   ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
248
249   //!< No need for property panel
250   updateCommandStatus();
251   hidePropertyPanel();
252   if(myOperationMgr->operationsCount() > 1) {
253     myActionsMgr->updateAction(theOperation->getDescription()->operationId());
254     return;
255   }
256   if(!aOperation->getDescription()->xmlRepresentation().isEmpty()) { 
257     myActionsMgr->restoreCommandState();
258   }
259 }
260
261 /*
262  *
263  */
264 void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage)
265 {
266   if (!theMessage) {
267 #ifdef _DEBUG
268     qDebug() << "XGUI_Workshop::addFeature: NULL message.";
269 #endif
270     return;
271   }
272   //Find or create Workbench
273   QString aWchName = QString::fromStdString(theMessage->workbenchId());
274   QString aNestedFeatures = QString::fromStdString(theMessage->nestedFeatures());
275   bool isUsePropPanel = theMessage->isUseInput();
276   if (isSalomeMode()) {
277     QString aId = QString::fromStdString(theMessage->id());
278     salomeConnector()->addFeature(aWchName,
279                                   QString::fromStdString(theMessage->id()),
280                                   aId,
281                                   QString::fromStdString(theMessage->tooltip()),
282                                   QIcon(theMessage->icon().c_str()),
283                                   isUsePropPanel, this, 
284                                   SLOT(onFeatureTriggered()), QKeySequence());
285     myActionsMgr->addCommand(aId, salomeConnector()->command(aId));
286     salomeConnector()->setNestedActions(aId, aNestedFeatures.split(" "));
287
288   } else {
289
290     XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
291     XGUI_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
292     if (!aPage) {
293       aPage = addWorkbench(aWchName);
294     }
295     //Find or create Group
296     QString aGroupName = QString::fromStdString(theMessage->groupId());
297     XGUI_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
298     if (!aGroup) {
299       aGroup = aPage->addGroup(aGroupName);
300     }
301     //Create feature...
302     XGUI_Command* aCommand = aGroup->addFeature(QString::fromStdString(theMessage->id()),
303                                                 QString::fromStdString(theMessage->text()),
304                                                 QString::fromStdString(theMessage->tooltip()),
305                                                 QIcon(theMessage->icon().c_str()),
306                                                 QKeySequence(), isUsePropPanel);
307     aCommand->setUnblockableCommands(aNestedFeatures.split(" "));
308     myActionsMgr->addCommand(aCommand);
309     myPartSetModule->featureCreated(aCommand);
310   }
311 }
312
313 /*
314  * Makes a signal/slot connections between Property Panel
315  * and given operation. The given operation becomes a
316  * current operation and previous operation if exists
317  */
318 void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
319 {
320   QPushButton* aOkBtn = myPropertyPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
321   connect(aOkBtn, SIGNAL(clicked()), theOperation, SLOT(commit()));
322   QPushButton* aCancelBtn = myPropertyPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
323   connect(aCancelBtn, SIGNAL(clicked()), theOperation, SLOT(abort()));
324
325   QAction* aCommand = 0;
326   if (isSalomeMode()) {
327     aCommand = salomeConnector()->command(theOperation->getDescription()->operationId());
328   } else {
329     XGUI_MainMenu* aMenu = myMainWindow->menuObject();
330     aCommand = aMenu->feature(theOperation->getDescription()->operationId());
331   }
332   //Abort operation on uncheck the command
333   connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
334 }
335
336 /*
337  * Saves document with given name.
338  */
339 void XGUI_Workshop::saveDocument(QString theName)
340 {
341   QApplication::restoreOverrideCursor();
342   boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
343   boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
344   aDoc->save(theName.toLatin1().constData());
345   QApplication::restoreOverrideCursor();
346 }
347
348 //******************************************************
349 void XGUI_Workshop::onExit()
350 {
351   boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
352   boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
353   if(aDoc->isModified()) {
354     int anAnswer = QMessageBox::question(
355         myMainWindow, tr("Save current file"),
356         tr("The document is modified, save before exit?"),
357         QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
358     if(anAnswer == QMessageBox::Save) {
359       onSave();
360     } else if (anAnswer == QMessageBox::Cancel) {
361       return;
362     }
363   }
364   qApp->exit();
365 }
366
367 //******************************************************
368 void XGUI_Workshop::onNew()
369 {
370   QApplication::setOverrideCursor(Qt::WaitCursor);
371   if (objectBrowser() == 0) {
372     createDockWidgets();
373     mySelector->connectViewers();
374   }
375   myViewerProxy->connectToViewer();
376   showObjectBrowser();
377   if (!isSalomeMode()) {
378     myMainWindow->showPythonConsole();
379     QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
380     aWnd->showMaximized();
381     updateCommandStatus();
382   }
383   QApplication::restoreOverrideCursor();
384 }
385
386 //******************************************************
387 void XGUI_Workshop::onOpen()
388 {
389   //save current file before close if modified
390   boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
391   boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
392   if(aDoc->isModified()) {
393     //TODO(sbh): re-launch the app?
394     int anAnswer = QMessageBox::question(
395         myMainWindow, tr("Save current file"),
396         tr("The document is modified, save before opening another?"),
397         QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
398     if(anAnswer == QMessageBox::Save) {
399       onSave();
400     } else if (anAnswer == QMessageBox::Cancel) {
401       return;
402     }
403     aDoc->close();
404     myCurrentFile = "";
405   }
406
407   //show file dialog, check if readable and open
408   myCurrentFile = QFileDialog::getOpenFileName(mainWindow());
409   if(myCurrentFile.isEmpty())
410     return;
411   QFileInfo aFileInfo(myCurrentFile);
412   if(!aFileInfo.exists() || !aFileInfo.isReadable()) {
413     QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
414     myCurrentFile = "";
415     return;
416   }
417   QApplication::setOverrideCursor(Qt::WaitCursor);
418   aDoc->load(myCurrentFile.toLatin1().constData());
419   QApplication::restoreOverrideCursor();
420   updateCommandStatus();
421 }
422
423 //******************************************************
424 void XGUI_Workshop::onSave()
425 {
426   if(myCurrentFile.isEmpty()) {
427     onSaveAs();
428     return;
429   }
430   saveDocument(myCurrentFile);
431   updateCommandStatus();
432 }
433
434 //******************************************************
435 void XGUI_Workshop::onSaveAs()
436 {
437   QString aTemp = myCurrentFile;
438   myCurrentFile = QFileDialog::getSaveFileName(mainWindow());
439   if(myCurrentFile.isEmpty()) {
440     myCurrentFile = aTemp;
441     return;
442   }
443   QFileInfo aFileInfo(myCurrentFile);
444   if(aFileInfo.exists() && !aFileInfo.isWritable()) {
445     QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to save the file."));
446     return;
447   }
448   onSave();
449 }
450
451 //******************************************************
452 void XGUI_Workshop::onUndo()
453 {
454   objectBrowser()->setCurrentIndex(QModelIndex());
455   boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
456   boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
457   aDoc->undo();
458   updateCommandStatus();
459 }
460
461 //******************************************************
462 void XGUI_Workshop::onRedo()
463 {
464   objectBrowser()->setCurrentIndex(QModelIndex());
465   boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
466   boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
467   aDoc->redo();
468   updateCommandStatus();
469 }
470
471 //******************************************************
472 XGUI_Module* XGUI_Workshop::loadModule(const QString& theModule)
473 {
474   QString libName = library(theModule);
475   if (libName.isEmpty()) {
476     qWarning(
477     qPrintable( tr( "Information about module \"%1\" doesn't exist." ).arg( theModule ) ));
478     return 0;
479   }
480
481   QString err;
482   CREATE_FUNC crtInst = 0;
483
484 #ifdef WIN32
485
486   HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
487   if (!modLib) {
488     LPVOID lpMsgBuf;
489     ::FormatMessage(
490         FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
491         0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
492     QString aMsg((char*) &lpMsgBuf);
493     err = QString("Failed to load  %1. %2").arg(libName).arg(aMsg);
494     ::LocalFree(lpMsgBuf);
495   } else {
496     crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
497     if (!crtInst) {
498       LPVOID lpMsgBuf;
499       ::FormatMessage(
500           FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
501               | FORMAT_MESSAGE_IGNORE_INSERTS,
502           0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
503       QString aMsg((char*) &lpMsgBuf);
504       err = QString("Failed to find  %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
505       ::LocalFree(lpMsgBuf);
506     }
507   }
508 #else
509   void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY );
510   if ( !modLib )
511   err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
512   else
513   {
514     crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
515     if ( !crtInst )
516     err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
517   }
518 #endif
519
520   XGUI_Module* aModule = crtInst ? crtInst(this) : 0;
521
522   if (!err.isEmpty()) {
523     if (mainWindow() && mainWindow()->isVisible())
524       QMessageBox::warning(mainWindow(), tr("Error"), err);
525     else
526       qWarning( qPrintable( err ));
527   }
528   return aModule;
529 }
530
531 //******************************************************
532 bool XGUI_Workshop::activateModule()
533 {
534   myPartSetModule = loadModule("PartSet");
535   if (!myPartSetModule)
536     return false;
537   myPartSetModule->createFeatures();
538   return true;
539 }
540
541 //******************************************************
542 void XGUI_Workshop::updateCommandStatus()
543 {
544   if (isSalomeMode()) // TODO: update commands in SALOME
545     return;
546   XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
547
548   QList<XGUI_Command*> aCommands = aMenuBar->features();
549   QList<XGUI_Command*>::const_iterator aIt;
550
551   boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
552   if (aMgr->hasRootDocument()) {
553     XGUI_Command* aUndoCmd;
554     XGUI_Command* aRedoCmd;
555     for (aIt = aCommands.constBegin(); aIt != aCommands.constEnd(); ++aIt) {
556       if ((*aIt)->id() == "UNDO_CMD")
557         aUndoCmd = (*aIt);
558       else if ((*aIt)->id() == "REDO_CMD")
559         aRedoCmd = (*aIt);
560       else // Enable all commands
561         (*aIt)->enable();
562     }
563     boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
564     aUndoCmd->setEnabled(aDoc->canUndo());
565     aRedoCmd->setEnabled(aDoc->canRedo());
566   } else {
567     for (aIt = aCommands.constBegin(); aIt != aCommands.constEnd(); ++aIt) {
568       if ((*aIt)->id() == "NEW_CMD")
569         (*aIt)->enable();
570       else if ((*aIt)->id() == "EXIT_CMD")
571         (*aIt)->enable();
572       else 
573         (*aIt)->disable();
574     }
575   }
576 }
577
578 //******************************************************
579 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
580 {
581   QDockWidget* aObjDock = new QDockWidget(theParent);
582   aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
583   aObjDock->setWindowTitle(tr("Object browser"));
584   myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
585   aObjDock->setWidget(myObjectBrowser);
586   return aObjDock;
587 }
588
589 //******************************************************
590 /*
591  * Creates dock widgets, places them in corresponding area
592  * and tabifies if necessary.
593  */
594 void XGUI_Workshop::createDockWidgets()
595 {
596   QMainWindow* aDesktop = isSalomeMode()? salomeConnector()->desktop() :
597                                           myMainWindow;
598   QDockWidget* aObjDock = createObjectBrowser(aDesktop);
599   aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
600   myPropertyPanel = new XGUI_PropertyPanel(aDesktop);
601   aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
602   hidePropertyPanel(); //<! Invisible by default
603   hideObjectBrowser();
604   aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
605 }
606
607 //******************************************************
608 void XGUI_Workshop::showPropertyPanel()
609 {
610   QAction* aViewAct = myPropertyPanel->toggleViewAction();
611   //<! Restore ability to close panel from the window's menu
612   aViewAct->setEnabled(true);
613   myPropertyPanel->show();
614   myPropertyPanel->raise();
615 }
616
617 //******************************************************
618 void XGUI_Workshop::hidePropertyPanel()
619 {
620   QAction* aViewAct = myPropertyPanel->toggleViewAction();
621   //<! Do not allow to show empty property panel
622   aViewAct->setEnabled(false);
623   myPropertyPanel->hide();
624 }
625
626 //******************************************************
627 void XGUI_Workshop::showObjectBrowser()
628 {
629   myObjectBrowser->parentWidget()->show();
630 }
631
632 //******************************************************
633 void XGUI_Workshop::hideObjectBrowser()
634 {
635   myObjectBrowser->parentWidget()->hide();
636 }
637
638 //******************************************************
639 void XGUI_Workshop::onFeatureTriggered()
640 {
641   QAction* aCmd = dynamic_cast<QAction*>(sender());
642   if (aCmd) {
643     QString aId = salomeConnector()->commandId(aCmd);
644     if (!aId.isNull())
645       myPartSetModule->launchOperation(aId);
646   }
647 }
648
649 //******************************************************
650 void XGUI_Workshop::changeCurrentDocument()
651 {
652   QFeatureList aFeatures = objectBrowser()->selectedFeatures();
653   
654   // Set current document
655   if (aFeatures.size() > 0) {
656     FeaturePtr aFeature = aFeatures.first();
657
658     boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
659     boost::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = aFeature->data()->docRef("PartDocument");
660     if (aDocRef)
661       aMgr->setCurrentDocument(aDocRef->value());
662   }
663 }
664
665 //******************************************************
666 void XGUI_Workshop::salomeViewerSelectionChanged()
667 {
668   emit salomeViewerSelection();
669 }
670
671
672 //**************************************************************
673 XGUI_SalomeViewer* XGUI_Workshop::salomeViewer() const 
674
675   return mySalomeConnector->viewer(); 
676 }