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