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