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