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