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