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