Salome HOME
e36e3c26998e037642480ed913fb20c29556a4b4
[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     myActionsMgr->addCommand(aCommand);
295     myPartSetModule->featureCreated(aCommand);
296   }
297 }
298
299 /*
300  * Makes a signal/slot connections between Property Panel
301  * and given operation. The given operation becomes a
302  * current operation and previous operation if exists
303  */
304 void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
305 {
306   QPushButton* aOkBtn = myPropertyPanelDock->findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
307   connect(aOkBtn, SIGNAL(clicked()), theOperation, SLOT(commit()));
308   QPushButton* aCancelBtn = myPropertyPanelDock->findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
309   connect(aCancelBtn, SIGNAL(clicked()), theOperation, SLOT(abort()));
310
311   QAction* aCommand = 0;
312   if (isSalomeMode()) {
313     aCommand = salomeConnector()->command(theOperation->operationId());
314   } else {
315     XGUI_MainMenu* aMenu = myMainWindow->menuObject();
316     aCommand = aMenu->feature(theOperation->operationId());
317   }
318   //Abort operation on uncheck the command
319   connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
320 }
321
322 /*
323  * Saves document with given name.
324  */
325 void XGUI_Workshop::saveDocument(QString theName)
326 {
327   QApplication::restoreOverrideCursor();
328   boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
329   boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
330   aDoc->save(theName.toLatin1().constData());
331   QApplication::restoreOverrideCursor();
332 }
333
334 //******************************************************
335 void XGUI_Workshop::onExit()
336 {
337   boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
338   boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
339   if(aDoc->isModified()) {
340     int anAnswer = QMessageBox::question(
341         myMainWindow, tr("Save current file"),
342         tr("The document is modified, save before exit?"),
343         QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
344     if(anAnswer == QMessageBox::Save) {
345       onSave();
346     } else if (anAnswer == QMessageBox::Cancel) {
347       return;
348     }
349   }
350   qApp->exit();
351 }
352
353 //******************************************************
354 void XGUI_Workshop::onNew()
355 {
356   QApplication::setOverrideCursor(Qt::WaitCursor);
357   if (objectBrowser() == 0) {
358     createDockWidgets();
359     mySelector->connectViewers();
360   }
361   showObjectBrowser();
362   if (!isSalomeMode()) {
363     myMainWindow->showPythonConsole();
364     QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
365     aWnd->showMaximized();
366     updateCommandStatus();
367   }
368   QApplication::restoreOverrideCursor();
369 }
370
371 //******************************************************
372 void XGUI_Workshop::onOpen()
373 {
374   //save current file before close if modified
375   boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
376   boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
377   if(aDoc->isModified()) {
378     //TODO(sbh): re-launch the app?
379     int anAnswer = QMessageBox::question(
380         myMainWindow, tr("Save current file"),
381         tr("The document is modified, save before opening another?"),
382         QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
383     if(anAnswer == QMessageBox::Save) {
384       onSave();
385     } else if (anAnswer == QMessageBox::Cancel) {
386       return;
387     }
388     aDoc->close();
389     myCurrentFile = "";
390   }
391
392   //show file dialog, check if readable and open
393   myCurrentFile = QFileDialog::getOpenFileName(mainWindow());
394   if(myCurrentFile.isEmpty())
395     return;
396   QFileInfo aFileInfo(myCurrentFile);
397   if(!aFileInfo.exists() || !aFileInfo.isReadable()) {
398     QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
399     myCurrentFile = "";
400     return;
401   }
402   QApplication::setOverrideCursor(Qt::WaitCursor);
403   aDoc->load(myCurrentFile.toLatin1().constData());
404   QApplication::restoreOverrideCursor();
405   updateCommandStatus();
406 }
407
408 //******************************************************
409 void XGUI_Workshop::onSave()
410 {
411   if(myCurrentFile.isEmpty()) {
412     onSaveAs();
413     return;
414   }
415   saveDocument(myCurrentFile);
416   updateCommandStatus();
417 }
418
419 //******************************************************
420 void XGUI_Workshop::onSaveAs()
421 {
422   QString aTemp = myCurrentFile;
423   myCurrentFile = QFileDialog::getSaveFileName(mainWindow());
424   if(myCurrentFile.isEmpty()) {
425     myCurrentFile = aTemp;
426     return;
427   }
428   QFileInfo aFileInfo(myCurrentFile);
429   if(aFileInfo.exists() && !aFileInfo.isWritable()) {
430     QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to save the file."));
431     return;
432   }
433   onSave();
434 }
435
436 //******************************************************
437 void XGUI_Workshop::onUndo()
438 {
439   objectBrowser()->setCurrentIndex(QModelIndex());
440   boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
441   boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
442   aDoc->undo();
443   updateCommandStatus();
444 }
445
446 //******************************************************
447 void XGUI_Workshop::onRedo()
448 {
449   objectBrowser()->setCurrentIndex(QModelIndex());
450   boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
451   boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
452   aDoc->redo();
453   updateCommandStatus();
454 }
455
456 //******************************************************
457 XGUI_Module* XGUI_Workshop::loadModule(const QString& theModule)
458 {
459   QString libName = library(theModule);
460   if (libName.isEmpty()) {
461     qWarning(
462     qPrintable( tr( "Information about module \"%1\" doesn't exist." ).arg( theModule ) ));
463     return 0;
464   }
465
466   QString err;
467   CREATE_FUNC crtInst = 0;
468
469 #ifdef WIN32
470
471   HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
472   if (!modLib) {
473     LPVOID lpMsgBuf;
474     ::FormatMessage(
475         FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
476         0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
477     QString aMsg((char*) &lpMsgBuf);
478     err = QString("Failed to load  %1. %2").arg(libName).arg(aMsg);
479     ::LocalFree(lpMsgBuf);
480   } else {
481     crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
482     if (!crtInst) {
483       LPVOID lpMsgBuf;
484       ::FormatMessage(
485           FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
486               | FORMAT_MESSAGE_IGNORE_INSERTS,
487           0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
488       QString aMsg((char*) &lpMsgBuf);
489       err = QString("Failed to find  %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
490       ::LocalFree(lpMsgBuf);
491     }
492   }
493 #else
494   void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY );
495   if ( !modLib )
496   err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
497   else
498   {
499     crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
500     if ( !crtInst )
501     err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
502   }
503 #endif
504
505   XGUI_Module* aModule = crtInst ? crtInst(this) : 0;
506
507   if (!err.isEmpty()) {
508     if (mainWindow() && mainWindow()->isVisible())
509       QMessageBox::warning(mainWindow(), tr("Error"), err);
510     else
511       qWarning( qPrintable( err ));
512   }
513   return aModule;
514 }
515
516 //******************************************************
517 bool XGUI_Workshop::activateModule()
518 {
519   myPartSetModule = loadModule("PartSet");
520   if (!myPartSetModule)
521     return false;
522   myPartSetModule->createFeatures();
523   return true;
524 }
525
526 //******************************************************
527 void XGUI_Workshop::updateCommandStatus()
528 {
529   if (isSalomeMode()) // TODO: update commands in SALOME
530     return;
531   XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
532
533   QList<XGUI_Command*> aCommands = aMenuBar->features();
534   QList<XGUI_Command*>::const_iterator aIt;
535
536   boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
537   if (aMgr->hasRootDocument()) {
538     XGUI_Command* aUndoCmd;
539     XGUI_Command* aRedoCmd;
540     for (aIt = aCommands.constBegin(); aIt != aCommands.constEnd(); ++aIt) {
541       if ((*aIt)->id() == "UNDO_CMD")
542         aUndoCmd = (*aIt);
543       else if ((*aIt)->id() == "REDO_CMD")
544         aRedoCmd = (*aIt);
545       else // Enable all commands
546         (*aIt)->enable();
547     }
548     boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
549     aUndoCmd->setEnabled(aDoc->canUndo());
550     aRedoCmd->setEnabled(aDoc->canRedo());
551   } else {
552     for (aIt = aCommands.constBegin(); aIt != aCommands.constEnd(); ++aIt) {
553       if ((*aIt)->id() == "NEW_CMD")
554         (*aIt)->enable();
555       else if ((*aIt)->id() == "EXIT_CMD")
556         (*aIt)->enable();
557       else 
558         (*aIt)->disable();
559     }
560   }
561 }
562
563 //******************************************************
564 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
565 {
566   QDockWidget* aObjDock = new QDockWidget(theParent);
567   aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
568   aObjDock->setWindowTitle(tr("Object browser"));
569   myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
570   aObjDock->setWidget(myObjectBrowser);
571   return aObjDock;
572 }
573
574 //******************************************************
575 QDockWidget* XGUI_Workshop::createPropertyPanel(QWidget* theParent)
576 {
577   QDockWidget* aPropPanel = new QDockWidget(theParent);
578   aPropPanel->setWindowTitle(tr("Property Panel"));
579   QAction* aViewAct = aPropPanel->toggleViewAction();
580   aPropPanel->setObjectName(XGUI::PROP_PANEL);
581
582   QWidget* aContent = new QWidget(aPropPanel);
583   QVBoxLayout* aMainLay = new QVBoxLayout(aContent);
584   aMainLay->setContentsMargins(3, 3, 3, 3);
585   aPropPanel->setWidget(aContent);
586
587   QFrame* aFrm = new QFrame(aContent);
588   aFrm->setFrameStyle(QFrame::Sunken);
589   aFrm->setFrameShape(QFrame::Panel);
590   QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm);
591   aBtnLay->setContentsMargins(0, 0, 0, 0);
592   aMainLay->addWidget(aFrm);
593
594   QPushButton* aBtn = new QPushButton(QIcon(":pictures/button_help.png"), "", aFrm);
595   aBtn->setFlat(true);
596   aBtnLay->addWidget(aBtn);
597   aBtnLay->addStretch(1);
598   aBtn = new QPushButton(QIcon(":pictures/button_ok.png"), "", aFrm);
599   aBtn->setObjectName(XGUI::PROP_PANEL_OK);
600   aBtn->setFlat(true);
601   aBtnLay->addWidget(aBtn);
602   aBtn = new QPushButton(QIcon(":pictures/button_cancel.png"), "", aFrm);
603   aBtn->setObjectName(XGUI::PROP_PANEL_CANCEL);
604   aBtn->setFlat(true);
605   aBtnLay->addWidget(aBtn);
606
607   QWidget* aCustomWidget = new QWidget(aContent);
608   aCustomWidget->setObjectName(XGUI::PROP_PANEL_WDG);
609   aMainLay->addWidget(aCustomWidget);
610   aMainLay->addStretch(1);
611
612   return aPropPanel;
613 }
614
615 //******************************************************
616 void XGUI_Workshop::setPropertyPannelTitle(const QString& theTitle)
617 {
618   myPropertyPanelDock->setWindowTitle(theTitle);
619 }
620
621 //******************************************************
622 /*
623  * Creates dock widgets, places them in corresponding area
624  * and tabifies if necessary.
625  */
626 void XGUI_Workshop::createDockWidgets()
627 {
628   QMainWindow* aDesktop = isSalomeMode()? salomeConnector()->desktop() :
629                                           myMainWindow;
630   QDockWidget* aObjDock = createObjectBrowser(aDesktop);
631   aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
632   myPropertyPanelDock = createPropertyPanel(aDesktop);
633   aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanelDock);
634   hidePropertyPanel(); //<! Invisible by default
635   hideObjectBrowser();
636   aDesktop->tabifyDockWidget(aObjDock, myPropertyPanelDock);
637 }
638
639 //******************************************************
640 void XGUI_Workshop::showPropertyPanel()
641 {
642   QAction* aViewAct = myPropertyPanelDock->toggleViewAction();
643   //<! Restore ability to close panel from the window's menu
644   aViewAct->setEnabled(true);
645   myPropertyPanelDock->show();
646   myPropertyPanelDock->raise();
647 }
648
649 //******************************************************
650 void XGUI_Workshop::hidePropertyPanel()
651 {
652   QAction* aViewAct = myPropertyPanelDock->toggleViewAction();
653   //<! Do not allow to show empty property panel
654   aViewAct->setEnabled(false);
655   myPropertyPanelDock->hide();
656 }
657
658 //******************************************************
659 void XGUI_Workshop::showObjectBrowser()
660 {
661   myObjectBrowser->parentWidget()->show();
662 }
663
664 //******************************************************
665 void XGUI_Workshop::hideObjectBrowser()
666 {
667   myObjectBrowser->parentWidget()->hide();
668 }
669
670 //******************************************************
671 void XGUI_Workshop::onFeatureTriggered()
672 {
673   QAction* aCmd = dynamic_cast<QAction*>(sender());
674   if (aCmd) {
675     QString aId = salomeConnector()->commandId(aCmd);
676     if (!aId.isNull())
677       myPartSetModule->launchOperation(aId);
678   }
679 }
680
681 //******************************************************
682 XGUI_Displayer* XGUI_Workshop::displayer() const
683 {
684   // In SALOME viewer is accessible only when module is initialized
685   // and in SALOME mode myDisplayer object has to be created later (on demand)
686   if (!myDisplayer) {
687     XGUI_Workshop* that = (XGUI_Workshop*)this;
688     that->myDisplayer = isSalomeMode() ?
689       new XGUI_Displayer(salomeConnector()->AISContext()):
690       new XGUI_Displayer(myMainWindow->viewer()->AISContext());
691   }
692   return myDisplayer;
693 }
694
695 //******************************************************
696 void XGUI_Workshop::changeCurrentDocument()
697 {
698   QFeatureList aFeatures = objectBrowser()->selectedFeatures();
699   
700   // Set current document
701   if (aFeatures.size() > 0) {
702     FeaturePtr aFeature = aFeatures.first();
703
704     boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
705     boost::shared_ptr<ModelAPI_AttributeDocRef> aDocRef = aFeature->data()->docRef("PartDocument");
706     if (aDocRef)
707       aMgr->setCurrentDocument(aDocRef->value());
708   }
709 }
710
711 //******************************************************
712 void XGUI_Workshop::salomeViewerSelectionChanged()
713 {
714   emit salomeViewerSelection();
715 }