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