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