Salome HOME
Issue #126: Activate a part on current document changed event
[modules/shaper.git] / src / XGUI / XGUI_Workshop.cpp
1 #include "ModuleBase_IModule.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 "XGUI_SelectionMgr.h"
12 #include "XGUI_Selection.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 #include "XGUI_ContextMenuMgr.h"
23 #include "XGUI_ModuleConnector.h"
24 #include "XGUI_Preferences.h"
25
26 #include <ModelAPI_Events.h>
27 #include <ModelAPI_Session.h>
28 #include <ModelAPI_Feature.h>
29 #include <ModelAPI_Data.h>
30 #include <ModelAPI_AttributeDocRef.h>
31 #include <ModelAPI_Object.h>
32 #include <ModelAPI_Validator.h>
33 #include <ModelAPI_ResultConstruction.h>
34 #include <ModelAPI_ResultBody.h>
35
36 #include <PartSetPlugin_Part.h>
37
38 #include <Events_Loop.h>
39 #include <Events_Error.h>
40 #include <Events_LongOp.h>
41
42 #include <ModuleBase_Operation.h>
43 #include <ModuleBase_Operation.h>
44 #include <ModuleBase_OperationDescription.h>
45 #include <ModuleBase_SelectionValidator.h>
46 #include "ModuleBase_WidgetFactory.h"
47
48 #include <Config_Common.h>
49 #include <Config_FeatureMessage.h>
50 #include <Config_PointerMessage.h>
51 #include <Config_ModuleReader.h>
52
53 #include <QApplication>
54 #include <QFileDialog>
55 #include <QMessageBox>
56 #include <QMdiSubWindow>
57 #include <QPushButton>
58 #include <QDockWidget>
59 #include <QLayout>
60 #include <QTimer>
61
62 #ifdef _DEBUG
63 #include <QDebug>
64 #endif
65
66 #ifdef WIN32
67 #include <windows.h>
68 #else
69 #include <dlfcn.h>
70 #endif
71
72 QMap<QString, QString> XGUI_Workshop::myIcons;
73
74 QString XGUI_Workshop::featureIcon(const std::string& theId)
75 {
76   QString aId(theId.c_str());
77   if (myIcons.contains(aId))
78     return myIcons[aId];
79   return QString();
80 }
81
82 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
83     : QObject(),
84       myCurrentDir(QString()),
85       myModule(NULL),
86       mySalomeConnector(theConnector),
87       myPropertyPanel(0),
88       myObjectBrowser(0),
89       myDisplayer(0),
90       myUpdatePrefs(false),
91       myPartActivating(false)
92 {
93   myMainWindow = mySalomeConnector ? 0 : new XGUI_MainWindow();
94
95   myDisplayer = new XGUI_Displayer(this);
96
97   mySelector = new XGUI_SelectionMgr(this);
98   //connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateModuleCommands()));
99
100   myOperationMgr = new XGUI_OperationMgr(this);
101   myActionsMgr = new XGUI_ActionsMgr(this);
102   myErrorDlg = new XGUI_ErrorDialog(myMainWindow);
103   myContextMenuMgr = new XGUI_ContextMenuMgr(this);
104   connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
105           SLOT(onContextMenuCommand(const QString&, bool)));
106
107   myViewerProxy = new XGUI_ViewerProxy(this);
108   connect(myViewerProxy, SIGNAL(selectionChanged()), this, SLOT(updateCommandsOnViewSelection()));
109
110   myModuleConnector = new XGUI_ModuleConnector(this);
111
112   connect(myOperationMgr, SIGNAL(operationStarted()), SLOT(onOperationStarted()));
113   connect(myOperationMgr, SIGNAL(operationResumed()), SLOT(onOperationStarted()));
114   connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
115           SLOT(onOperationStopped(ModuleBase_Operation*)));
116   connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
117   connect(myOperationMgr, SIGNAL(operationStarted()), myActionsMgr, SLOT(update()));
118   connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)), myActionsMgr,
119           SLOT(update()));
120   connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&)));
121 }
122
123 //******************************************************
124 XGUI_Workshop::~XGUI_Workshop(void)
125 {
126 }
127
128 //******************************************************
129 void XGUI_Workshop::startApplication()
130 {
131   initMenu();
132   //Initialize event listening
133   Events_Loop* aLoop = Events_Loop::loop();
134   aLoop->registerListener(this, Events_Error::errorID());  //!< Listening application errors.
135   //TODO(sbh): Implement static method to extract event id [SEID]
136   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_FEATURE_LOADED));
137   // TODO Is it good to use non standard event within workshop?
138   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED));
139   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
140   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
141   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
142   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
143   aLoop->registerListener(this, Events_Loop::eventByName("LongOperation"));
144   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_PLUGIN_LOADED));
145   aLoop->registerListener(this, Events_Loop::eventByName("CurrentDocumentChanged"));
146
147   registerValidators();
148   activateModule();
149   if (myMainWindow) {
150     myMainWindow->show();
151     updateCommandStatus();
152   }
153   XGUI_Preferences::loadCustomProps();
154   onNew();
155 }
156
157 //******************************************************
158 void XGUI_Workshop::initMenu()
159 {
160   myContextMenuMgr->createActions();
161
162   if (isSalomeMode()) {
163     // Create only Undo, Redo commands
164     QAction* aAction = salomeConnector()->addEditCommand("UNDO_CMD", tr("Undo"),
165                                                          tr("Undo last command"),
166                                                          QIcon(":pictures/undo.png"),
167                                                          QKeySequence::Undo, false);
168     connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
169     aAction = salomeConnector()->addEditCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
170                                                 QIcon(":pictures/redo.png"), QKeySequence::Redo,
171                                                 false);
172     connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
173     salomeConnector()->addEditMenuSeparator();
174     return;
175   }
176   // File commands group
177   XGUI_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
178
179   XGUI_Command* aCommand;
180
181   aCommand = aGroup->addFeature("SAVE_CMD", tr("Save..."), tr("Save the document"),
182                                 QIcon(":pictures/save.png"), QKeySequence::Save);
183   aCommand->connectTo(this, SLOT(onSave()));
184   //aCommand->disable();
185
186   aCommand = aGroup->addFeature("UNDO_CMD", tr("Undo"), tr("Undo last command"),
187                                 QIcon(":pictures/undo.png"), QKeySequence::Undo);
188   aCommand->connectTo(this, SLOT(onUndo()));
189
190   aCommand = aGroup->addFeature("REDO_CMD", tr("Redo"), tr("Redo last command"),
191                                 QIcon(":pictures/redo.png"), QKeySequence::Redo);
192   aCommand->connectTo(this, SLOT(onRedo()));
193
194   aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
195                                 QIcon(":pictures/rebuild.png"));
196
197   aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
198                                 QIcon(":pictures/save.png"));
199   aCommand->connectTo(this, SLOT(onSaveAs()));
200   //aCommand->disable();
201
202   aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
203                                 QIcon(":pictures/open.png"), QKeySequence::Open);
204   aCommand->connectTo(this, SLOT(onOpen()));
205
206   //aCommand = aGroup->addFeature("NEW_CMD", tr("New"), tr("Create a new document"),
207   //                              QIcon(":pictures/new.png"), QKeySequence::New);
208   //aCommand->connectTo(this, SLOT(onNew()));
209
210   aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
211                                 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
212   aCommand->connectTo(this, SLOT(onPreferences()));
213
214   aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
215                                 QIcon(":pictures/close.png"), QKeySequence::Close);
216   aCommand->connectTo(this, SLOT(onExit()));
217   //FIXME: SBH's test action. Can be used for some GUI tests.
218 //  #ifdef _DEBUG
219 //    aCommand = aGroup->addFeature("TEST_CMD", "Test!", "Private debug button",
220 //                                  QIcon(":pictures/close.png"), QKeySequence(), true);
221 //    aCommand->connectTo(myMainWindow, SLOT(dockPythonConsole()));
222 //  #endif
223 }
224
225 //******************************************************
226 XGUI_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
227 {
228   XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
229   return aMenuBar->addWorkbench(theName);
230 }
231
232 //******************************************************
233 void XGUI_Workshop::processEvent(const Events_Message* theMessage)
234 {
235   //A message to start feature creation received.
236   if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURE_LOADED)) {
237     const Config_FeatureMessage* aFeatureMsg =
238         dynamic_cast<const Config_FeatureMessage*>(theMessage);
239     if (!aFeatureMsg->isInternal()) {
240       addFeature(aFeatureMsg);
241     }
242   }
243
244   // Process creation of Part
245   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
246     const ModelAPI_ObjectUpdatedMessage* aUpdMsg =
247         dynamic_cast<const ModelAPI_ObjectUpdatedMessage*>(theMessage);
248     onFeatureCreatedMsg(aUpdMsg);
249     if (myUpdatePrefs) {
250       if (mySalomeConnector)
251         mySalomeConnector->createPreferences();
252       myUpdatePrefs = false;
253     }
254   }
255   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED)) {
256     myUpdatePrefs = true;
257   }
258
259   // Redisplay feature
260   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
261     const ModelAPI_ObjectUpdatedMessage* aUpdMsg =
262         dynamic_cast<const ModelAPI_ObjectUpdatedMessage*>(theMessage);
263     onFeatureRedisplayMsg(aUpdMsg);
264   }
265
266   //Update property panel on corresponding message. If there is no current operation (no
267   //property panel), or received message has different feature to the current - do nothing.
268   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
269     const ModelAPI_ObjectUpdatedMessage* anUpdateMsg =
270         dynamic_cast<const ModelAPI_ObjectUpdatedMessage*>(theMessage);
271     onFeatureUpdatedMsg(anUpdateMsg);
272   }
273
274   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
275     const ModelAPI_ObjectDeletedMessage* aDelMsg =
276         dynamic_cast<const ModelAPI_ObjectDeletedMessage*>(theMessage);
277     onObjectDeletedMsg(aDelMsg);
278   }
279
280   else if (theMessage->eventID() == Events_LongOp::eventID()) {
281     if (Events_LongOp::isPerformed())
282       QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
283     //QTimer::singleShot(10, this, SLOT(onStartWaiting()));
284     else
285       QApplication::restoreOverrideCursor();
286   }
287
288   //An operation passed by message. Start it, process and commit.
289   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OPERATION_LAUNCHED)) {
290     const Config_PointerMessage* aPartSetMsg =
291         dynamic_cast<const Config_PointerMessage*>(theMessage);
292     //myPropertyPanel->cleanContent();
293     ModuleBase_Operation* anOperation = (ModuleBase_Operation*) aPartSetMsg->pointer();
294
295     if (myOperationMgr->startOperation(anOperation)) {
296       myPropertyPanel->updateContentWidget(anOperation->feature());
297       if (!anOperation->getDescription()->hasXmlRepresentation()) {
298         if (anOperation->commit())
299           updateCommandStatus();
300       }
301     }
302   }
303   else if (theMessage->eventID() == Events_Loop::loop()->eventByName("CurrentDocumentChanged")) {
304     // Find and Activate active part
305     if (myPartActivating)
306       return;
307     SessionPtr aMgr = ModelAPI_Session::get();
308     DocumentPtr aActiveDoc = aMgr->activeDocument();
309     DocumentPtr aDoc = aMgr->moduleDocument();
310     if (aActiveDoc == aDoc) {
311       activatePart(ResultPartPtr()); 
312       return;
313     }
314     std::string aGrpName = ModelAPI_ResultPart::group();
315     for (int i = 0; i < aDoc->size(aGrpName); i++) {
316       ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aDoc->object(aGrpName, i));
317       if (aPart->partDoc() == aActiveDoc) {
318         activatePart(aPart); // Activate a part which corresponds to active Doc
319         return;
320       }
321     }
322     // If not found then activate global document
323     activatePart(ResultPartPtr()); 
324
325   } else {
326     //Show error dialog if error message received.
327     const Events_Error* anAppError = dynamic_cast<const Events_Error*>(theMessage);
328     if (anAppError) {
329       emit errorOccurred(QString::fromLatin1(anAppError->description()));
330     }
331   }
332   if (!isSalomeMode()) {
333     SessionPtr aMgr = ModelAPI_Session::get();
334     if (aMgr->isModified() != myMainWindow->isModifiedState())
335       myMainWindow->setModifiedState(aMgr->isModified());
336   }
337 }
338
339
340 //******************************************************
341 void XGUI_Workshop::onStartWaiting()
342 {
343   if (Events_LongOp::isPerformed()) {
344     QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
345   }
346 }
347
348 //******************************************************
349 void XGUI_Workshop::onFeatureUpdatedMsg(const ModelAPI_ObjectUpdatedMessage* theMsg)
350 {
351   std::set<ObjectPtr> aFeatures = theMsg->objects();
352   if (myOperationMgr->hasOperation()) {
353     FeaturePtr aCurrentFeature = myOperationMgr->currentOperation()->feature();
354     std::set<ObjectPtr>::const_iterator aIt;
355     for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
356       ObjectPtr aNewFeature = (*aIt);
357       if (aNewFeature == aCurrentFeature) {
358         myPropertyPanel->updateContentWidget(aCurrentFeature);
359         break;
360       }
361     }
362   }
363   myOperationMgr->validateCurrentOperation();
364 }
365
366 //******************************************************
367 void XGUI_Workshop::onFeatureRedisplayMsg(const ModelAPI_ObjectUpdatedMessage* theMsg)
368 {
369   std::set<ObjectPtr> aObjects = theMsg->objects();
370   std::set<ObjectPtr>::const_iterator aIt;
371   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
372     ObjectPtr aObj = (*aIt);
373     if (!aObj->data() || !aObj->data()->isValid())
374       myDisplayer->erase(aObj, false);
375     else {
376       if (myDisplayer->isVisible(aObj))  // TODO VSV: Correction sketch drawing
377         myDisplayer->display(aObj, false);  // In order to update presentation
378       else {
379         if (myOperationMgr->hasOperation()) {
380           ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
381           if (aOperation->hasObject(aObj)) {  // Display only current operation results
382             myDisplayer->display(aObj, false);
383           }
384         }
385       }
386     }
387   }
388   myDisplayer->updateViewer();
389 }
390
391 //******************************************************
392 void XGUI_Workshop::onFeatureCreatedMsg(const ModelAPI_ObjectUpdatedMessage* theMsg)
393 {
394   std::set<ObjectPtr> aObjects = theMsg->objects();
395
396   std::set<ObjectPtr>::const_iterator aIt;
397   bool aHasPart = false;
398   bool isDisplayed = false;
399   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
400     ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(*aIt);
401     if (aPart) {
402       aHasPart = true;
403       // If a feature is created from the aplication's python console  
404       // it doesn't stored in the operation mgr and doesn't displayed
405     } else if (myOperationMgr->hasOperation()) {
406       ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
407       if (aOperation->hasObject(*aIt)) {  // Display only current operation results
408         myDisplayer->display(*aIt, false);
409         isDisplayed = true;
410       }
411     }
412   }
413   if (isDisplayed)
414     myDisplayer->updateViewer();
415   if (aHasPart) {
416     //The created part will be created in Object Browser later and we have to activate it
417     // only when it is created everywere
418     QTimer::singleShot(50, this, SLOT(activateLastPart()));
419   }
420 }
421
422 //******************************************************
423 void XGUI_Workshop::onObjectDeletedMsg(const ModelAPI_ObjectDeletedMessage* theMsg)
424 {
425   //std::set<ObjectPtr> aFeatures = theMsg->objects();
426 }
427
428 //******************************************************
429 void XGUI_Workshop::onOperationStarted()
430 {
431   ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
432   if (this->isSalomeMode()) 
433     aOperation->setNestedFeatures(mySalomeConnector->nestedActions(aOperation->id()));
434   else 
435     aOperation->setNestedFeatures(myActionsMgr->nestedCommands(aOperation->id()));
436   
437   if (aOperation->getDescription()->hasXmlRepresentation()) {  //!< No need for property panel
438     connectWithOperation(aOperation);
439
440     showPropertyPanel();
441     QString aXmlRepr = aOperation->getDescription()->xmlRepresentation();
442     ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(),
443                                                                  myModuleConnector);
444
445     myPropertyPanel->cleanContent();
446     aFactory.createWidget(myPropertyPanel->contentWidget());
447
448     QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
449     QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
450     ModuleBase_ModelWidget* aWidget;
451     for (; anIt != aLast; anIt++) {
452       aWidget = *anIt;
453       aWidget->setFeature(aOperation->feature());
454       QObject::connect(aWidget, SIGNAL(valuesChanged()), this, SLOT(onWidgetValuesChanged()));
455       // Init default values
456       if (!aOperation->isEditOperation() && !aWidget->isComputedDefault()) {
457         aWidget->storeValue();
458       }
459     }
460
461     myPropertyPanel->setModelWidgets(aWidgets);
462     myPropertyPanel->setWindowTitle(aOperation->getDescription()->description());
463   }
464   updateCommandStatus();
465 }
466
467 //******************************************************
468 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
469 {
470   //!< No need for property panel
471   updateCommandStatus();
472   hidePropertyPanel();
473   myPropertyPanel->cleanContent();
474 }
475
476 /*
477  *
478  */
479 void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage)
480 {
481   if (!theMessage) {
482 #ifdef _DEBUG
483     qDebug() << "XGUI_Workshop::addFeature: NULL message.";
484 #endif
485     return;
486   }
487   // Remember features icons
488   myIcons[QString::fromStdString(theMessage->id())] = QString::fromStdString(theMessage->icon());
489
490   //Find or create Workbench
491   QString aWchName = QString::fromStdString(theMessage->workbenchId());
492   QString aNestedFeatures = QString::fromStdString(theMessage->nestedFeatures());
493   bool isUsePropPanel = theMessage->isUseInput();
494   QString aFeatureId = QString::fromStdString(theMessage->id());
495   if (isSalomeMode()) {
496     QAction* aAction = salomeConnector()->addFeature(aWchName, aFeatureId,
497                                                      QString::fromStdString(theMessage->text()),
498                                                      QString::fromStdString(theMessage->tooltip()),
499                                                      QIcon(theMessage->icon().c_str()),
500                                                      QKeySequence(), isUsePropPanel);
501     salomeConnector()->setNestedActions(aFeatureId, aNestedFeatures.split(" ", QString::SkipEmptyParts));
502     myActionsMgr->addCommand(aAction);
503     myModule->featureCreated(aAction);
504   } else {
505
506     XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
507     XGUI_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
508     if (!aPage) {
509       aPage = addWorkbench(aWchName);
510     }
511     //Find or create Group
512     QString aGroupName = QString::fromStdString(theMessage->groupId());
513     XGUI_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
514     if (!aGroup) {
515       aGroup = aPage->addGroup(aGroupName);
516     }
517     // Check if hotkey sequence is already defined:
518     QKeySequence aHotKey = myActionsMgr->registerShortcut(
519         QString::fromStdString(theMessage->keysequence()));
520     // Create feature...
521     XGUI_Command* aCommand = aGroup->addFeature(aFeatureId,
522                                                 QString::fromStdString(theMessage->text()),
523                                                 QString::fromStdString(theMessage->tooltip()),
524                                                 QIcon(theMessage->icon().c_str()), aHotKey,
525                                                 isUsePropPanel);
526     aCommand->setNestedCommands(aNestedFeatures.split(" ", QString::SkipEmptyParts));
527     myActionsMgr->addCommand(aCommand);
528     myModule->featureCreated(aCommand);
529   }
530 }
531
532 /*
533  * Makes a signal/slot connections between Property Panel
534  * and given operation. The given operation becomes a
535  * current operation and previous operation if exists
536  */
537 void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
538 {
539   QAction* aCommand = 0;
540   if (isSalomeMode()) {
541     aCommand = salomeConnector()->command(theOperation->getDescription()->operationId());
542   } else {
543     XGUI_MainMenu* aMenu = myMainWindow->menuObject();
544     aCommand = aMenu->feature(theOperation->getDescription()->operationId());
545   }
546   //Abort operation on uncheck the command
547   if (aCommand)
548     connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
549 }
550
551 /*
552  * Saves document with given name.
553  */
554 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
555 {
556   QApplication::restoreOverrideCursor();
557   SessionPtr aMgr = ModelAPI_Session::get();
558   aMgr->save(theName.toLatin1().constData(), theFileNames);
559   QApplication::restoreOverrideCursor();
560 }
561
562 //******************************************************
563 void XGUI_Workshop::onExit()
564 {
565   SessionPtr aMgr = ModelAPI_Session::get();
566   if (aMgr->isModified()) {
567     int anAnswer = QMessageBox::question(
568         myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
569         QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
570     if (anAnswer == QMessageBox::Save) {
571       bool saved = onSave();
572       if (!saved) {
573         return;
574       }
575     } else if (anAnswer == QMessageBox::Cancel) {
576       return;
577     }
578   }
579   qApp->exit();
580 }
581
582 //******************************************************
583 void XGUI_Workshop::onNew()
584 {
585   QApplication::setOverrideCursor(Qt::WaitCursor);
586   if (objectBrowser() == 0) {
587     createDockWidgets();
588     mySelector->connectViewers();
589   }
590   myViewerProxy->connectToViewer();
591   showObjectBrowser();
592   if (!isSalomeMode()) {
593     myMainWindow->showPythonConsole();
594     QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
595     aWnd->showMaximized();
596     updateCommandStatus();
597   }
598   myContextMenuMgr->connectViewer();
599   QApplication::restoreOverrideCursor();
600 }
601
602 //******************************************************
603 void XGUI_Workshop::onOpen()
604 {
605   if(!myOperationMgr->abortOperation())
606     return;
607   //save current file before close if modified
608   SessionPtr aSession = ModelAPI_Session::get();
609   if (aSession->isModified()) {
610     //TODO(sbh): re-launch the app?
611     int anAnswer = QMessageBox::question(
612         myMainWindow, tr("Save current file"),
613         tr("The document is modified, save before opening another?"),
614         QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
615     if (anAnswer == QMessageBox::Save) {
616       onSave();
617     } else if (anAnswer == QMessageBox::Cancel) {
618       return;
619     }
620     aSession->moduleDocument()->close();
621     myCurrentDir = "";
622   }
623
624   //show file dialog, check if readable and open
625   myCurrentDir = QFileDialog::getExistingDirectory(mainWindow());
626   if (myCurrentDir.isEmpty())
627     return;
628   QFileInfo aFileInfo(myCurrentDir);
629   if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
630     QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
631     myCurrentDir = "";
632     return;
633   }
634   QApplication::setOverrideCursor(Qt::WaitCursor);
635   aSession->load(myCurrentDir.toLatin1().constData());
636   myObjectBrowser->rebuildDataTree();
637   displayAllResults();
638   updateCommandStatus();
639   myMainWindow->setCurrentDir(myCurrentDir);
640   QApplication::restoreOverrideCursor();
641 }
642
643 //******************************************************
644 bool XGUI_Workshop::onSave()
645 {
646   if(!myOperationMgr->abortOperation())
647     return false;
648   if (myCurrentDir.isEmpty()) {
649     return onSaveAs();
650   }
651   std::list<std::string> aFiles;
652   saveDocument(myCurrentDir, aFiles);
653   updateCommandStatus();
654   myMainWindow->setModifiedState(false);
655   return true;
656 }
657
658 //******************************************************
659 bool XGUI_Workshop::onSaveAs()
660 {
661   if(!myOperationMgr->abortOperation())
662     return false;
663   QFileDialog dialog(mainWindow());
664   dialog.setWindowTitle(tr("Select directory to save files..."));
665   dialog.setFileMode(QFileDialog::Directory);
666   dialog.setFilter(tr("Folders (*)"));
667   dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
668   dialog.setViewMode(QFileDialog::Detail);
669
670   if (!dialog.exec()) {
671     return false;
672   }
673   QString aTempDir = dialog.selectedFiles().first();
674   QDir aDir(aTempDir);
675   if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
676     int answer = QMessageBox::question(
677         myMainWindow,
678         //: Title of the dialog which asks user if he wants to save study in existing non-empty folder
679         tr("Save"),
680         tr("The folder already contains some files, save anyway?"),
681         QMessageBox::Save | QMessageBox::Cancel);
682     if (answer == QMessageBox::Cancel) {
683       return false;
684     }
685   }
686   myCurrentDir = aTempDir;
687   if (!isSalomeMode()) {
688     myMainWindow->setCurrentDir(myCurrentDir, false);
689     myMainWindow->setModifiedState(false);
690   }
691   return onSave();
692 }
693
694 //******************************************************
695 void XGUI_Workshop::onUndo()
696 {
697   objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
698   SessionPtr aMgr = ModelAPI_Session::get();
699   if (aMgr->isOperation())
700     operationMgr()->abortOperation();
701   aMgr->undo();
702   updateCommandStatus();
703 }
704
705 //******************************************************
706 void XGUI_Workshop::onRedo()
707 {
708   objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
709   SessionPtr aMgr = ModelAPI_Session::get();
710   if (aMgr->isOperation())
711     operationMgr()->abortOperation();
712   aMgr->redo();
713   updateCommandStatus();
714 }
715
716 //******************************************************
717 void XGUI_Workshop::onPreferences()
718 {
719   XGUI_Prefs aModif;
720   XGUI_Preferences::editPreferences(aModif);
721   if (aModif.size() > 0) {
722     QString aSection;
723     foreach (XGUI_Pref aPref, aModif)
724     {
725       aSection = aPref.first;
726       if (aSection == XGUI_Preferences::VIEWER_SECTION) {
727         if (!isSalomeMode())
728           myMainWindow->viewer()->updateFromResources();
729       } else if (aSection == XGUI_Preferences::MENU_SECTION) {
730         if (!isSalomeMode())
731           myMainWindow->menuObject()->updateFromResources();
732       }
733     }
734   }
735 }
736
737 //******************************************************
738 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
739 {
740   QString libName = QString::fromStdString(library(theModule.toStdString()));
741   if (libName.isEmpty()) {
742     qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
743     return 0;
744   }
745
746   QString err;
747   CREATE_FUNC crtInst = 0;
748
749 #ifdef WIN32
750   HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
751   if (!modLib) {
752     LPVOID lpMsgBuf;
753     ::FormatMessage(
754         FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
755         0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
756     QString aMsg((char*) &lpMsgBuf);
757     err = QString("Failed to load  %1. %2").arg(libName).arg(aMsg);
758     ::LocalFree(lpMsgBuf);
759   } else {
760     crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
761     if (!crtInst) {
762       LPVOID lpMsgBuf;
763       ::FormatMessage(
764           FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
765               | FORMAT_MESSAGE_IGNORE_INSERTS,
766           0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
767       QString aMsg((char*) &lpMsgBuf);
768       err = QString("Failed to find  %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
769       ::LocalFree(lpMsgBuf);
770     }
771   }
772 #else
773   void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
774   if ( !modLib ) {
775     err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
776   } else {
777     crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
778     if ( !crtInst ) {
779       err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
780     }
781   }
782 #endif
783
784   ModuleBase_IModule* aModule = crtInst ? crtInst(this) : 0;
785
786   if (!err.isEmpty()) {
787     if (mainWindow()) {
788       QMessageBox::warning(mainWindow(), tr("Error"), err);
789     } else {
790       qWarning(qPrintable(err));
791     }
792   }
793   return aModule;
794 }
795
796 //******************************************************
797 bool XGUI_Workshop::activateModule()
798 {
799   Config_ModuleReader aModuleReader;
800   QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
801   myModule = loadModule(moduleName);
802   if (!myModule)
803     return false;
804   myModule->createFeatures();
805   myActionsMgr->update();
806   return true;
807 }
808
809 //******************************************************
810 void XGUI_Workshop::updateCommandStatus()
811 {
812   QList<QAction*> aCommands;
813   if (isSalomeMode()) {  // update commands in SALOME mode
814     aCommands = salomeConnector()->commandList();
815   } else {
816     XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
817     foreach (XGUI_Command* aCmd, aMenuBar->features())
818       aCommands.append(aCmd);
819   }
820   SessionPtr aMgr = ModelAPI_Session::get();
821   if (aMgr->hasModuleDocument()) {
822     QAction* aUndoCmd;
823     QAction* aRedoCmd;
824     foreach(QAction* aCmd, aCommands)
825     {
826       QString aId = aCmd->data().toString();
827       if (aId == "UNDO_CMD")
828         aUndoCmd = aCmd;
829       else if (aId == "REDO_CMD")
830         aRedoCmd = aCmd;
831       else
832         // Enable all commands
833         aCmd->setEnabled(true);
834     }
835     aUndoCmd->setEnabled(aMgr->canUndo());
836     aRedoCmd->setEnabled(aMgr->canRedo());
837   } else {
838     foreach(QAction* aCmd, aCommands)
839     {
840       QString aId = aCmd->data().toString();
841       if (aId == "NEW_CMD")
842         aCmd->setEnabled(true);
843       else if (aId == "EXIT_CMD")
844         aCmd->setEnabled(true);
845       else
846         aCmd->setEnabled(false);
847     }
848   }
849   myActionsMgr->update();
850 }
851
852 //******************************************************
853 QList<QAction*> XGUI_Workshop::getModuleCommands() const
854 {
855   QList<QAction*> aCommands;
856   if (isSalomeMode()) {  // update commands in SALOME mode
857     aCommands = salomeConnector()->commandList();
858   } else {
859     XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
860     foreach(XGUI_Command* aCmd, aMenuBar->features())
861     {
862       aCommands.append(aCmd);
863     }
864   }
865   return aCommands;
866 }
867
868 //******************************************************
869 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
870 {
871   QDockWidget* aObjDock = new QDockWidget(theParent);
872   aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
873   aObjDock->setWindowTitle(tr("Object browser"));
874   aObjDock->setStyleSheet(
875       "::title { position: relative; padding-left: 5px; text-align: left center }");
876   myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
877   connect(myObjectBrowser, SIGNAL(activePartChanged(ObjectPtr)), this,
878           SLOT(changeCurrentDocument(ObjectPtr)));
879   aObjDock->setWidget(myObjectBrowser);
880
881   myContextMenuMgr->connectObjectBrowser();
882   return aObjDock;
883 }
884
885 //******************************************************
886 /*
887  * Creates dock widgets, places them in corresponding area
888  * and tabifies if necessary.
889  */
890 void XGUI_Workshop::createDockWidgets()
891 {
892   QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
893   QDockWidget* aObjDock = createObjectBrowser(aDesktop);
894   aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
895   myPropertyPanel = new XGUI_PropertyPanel(aDesktop);
896   myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
897   aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
898   hidePropertyPanel();  //<! Invisible by default
899   hideObjectBrowser();
900   aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
901
902   QPushButton* aOkBtn = myPropertyPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
903   connect(aOkBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onCommitOperation()));
904   QPushButton* aCancelBtn = myPropertyPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
905   connect(aCancelBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onAbortOperation()));
906 //TODO(sbh): KeyReleasedProblem
907   connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)), myOperationMgr,
908           SLOT(onKeyReleased(QKeyEvent*)));
909
910   connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), myOperationMgr,
911           SLOT(onWidgetActivated(ModuleBase_ModelWidget*)));
912   connect(myOperationMgr, SIGNAL(activateNextWidget(ModuleBase_ModelWidget*)), myPropertyPanel,
913           SLOT(onActivateNextWidget(ModuleBase_ModelWidget*)));
914   connect(myOperationMgr, SIGNAL(operationValidated(bool)), myPropertyPanel,
915           SLOT(setAcceptEnabled(bool)));
916
917 }
918
919 //******************************************************
920 void XGUI_Workshop::showPropertyPanel()
921 {
922   QAction* aViewAct = myPropertyPanel->toggleViewAction();
923   //<! Restore ability to close panel from the window's menu
924   aViewAct->setEnabled(true);
925   myPropertyPanel->show();
926   myPropertyPanel->raise();
927 }
928
929 //******************************************************
930 void XGUI_Workshop::hidePropertyPanel()
931 {
932   QAction* aViewAct = myPropertyPanel->toggleViewAction();
933   //<! Do not allow to show empty property panel
934   aViewAct->setEnabled(false);
935   myPropertyPanel->hide();
936 }
937
938 //******************************************************
939 void XGUI_Workshop::showObjectBrowser()
940 {
941   myObjectBrowser->parentWidget()->show();
942 }
943
944 //******************************************************
945 void XGUI_Workshop::hideObjectBrowser()
946 {
947   myObjectBrowser->parentWidget()->hide();
948 }
949
950 //******************************************************
951 void XGUI_Workshop::onFeatureTriggered()
952 {
953   QAction* aCmd = dynamic_cast<QAction*>(sender());
954   if (aCmd) {
955     QString aId = salomeConnector()->commandId(aCmd);
956     if (!aId.isNull())
957       myModule->launchOperation(aId);
958   }
959 }
960
961 //******************************************************
962 void XGUI_Workshop::changeCurrentDocument(ObjectPtr theObj)
963 {
964   SessionPtr aMgr = ModelAPI_Session::get();
965   if (theObj) {
966     ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(theObj);
967     if (aPart) {
968       DocumentPtr aPartDoc = aPart->partDoc();
969       if (aPartDoc) {
970         aMgr->setActiveDocument(aPartDoc);
971         return;
972       }
973     }
974   }
975   aMgr->setActiveDocument(aMgr->moduleDocument());
976 }
977
978 //******************************************************
979 void XGUI_Workshop::salomeViewerSelectionChanged()
980 {
981   emit salomeViewerSelection();
982 }
983
984 //**************************************************************
985 XGUI_SalomeViewer* XGUI_Workshop::salomeViewer() const
986 {
987   return mySalomeConnector->viewer();
988 }
989
990 //**************************************************************
991 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
992 {
993   QList<ObjectPtr> aObjects = mySelector->selection()->selectedObjects();
994   if ((theId == "ACTIVATE_PART_CMD") && (aObjects.size() > 0)) {
995     ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aObjects.first());
996     activatePart(aPart);
997   } else if (theId == "DEACTIVATE_PART_CMD")
998     activatePart(ResultPartPtr());
999   else if (theId == "DELETE_CMD")
1000     deleteObjects(aObjects);
1001   else if (theId == "SHOW_CMD")
1002     showObjects(aObjects, true);
1003   else if (theId == "HIDE_CMD")
1004     showObjects(aObjects, false);
1005   else if (theId == "SHOW_ONLY_CMD")
1006     showOnlyObjects(aObjects);
1007 }
1008
1009 //**************************************************************
1010 void XGUI_Workshop::onWidgetValuesChanged()
1011 {
1012   ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1013   FeaturePtr aFeature = anOperation->feature();
1014
1015   ModuleBase_ModelWidget* aSenderWidget = dynamic_cast<ModuleBase_ModelWidget*>(sender());
1016   //if (aCustom)
1017   //  aCustom->storeValue(aFeature);
1018
1019   const QList<ModuleBase_ModelWidget*>& aWidgets = myPropertyPanel->modelWidgets();
1020   QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
1021   for (; anIt != aLast; anIt++) {
1022     ModuleBase_ModelWidget* aCustom = *anIt;
1023     if (aCustom && (/*!aCustom->isInitialized(aFeature) ||*/aCustom == aSenderWidget)) {
1024       //aCustom->storeValue(aFeature);
1025       aCustom->storeValue();
1026     }
1027   }
1028 }
1029
1030 //**************************************************************
1031 void XGUI_Workshop::activatePart(ResultPartPtr theFeature)
1032 {
1033   if (!myPartActivating) {
1034     myPartActivating = true;
1035     if (theFeature)
1036       theFeature->activate();
1037     changeCurrentDocument(theFeature);
1038     myObjectBrowser->activatePart(theFeature);
1039     myPartActivating = false;
1040   }
1041 }
1042
1043 //**************************************************************
1044 void XGUI_Workshop::activateLastPart()
1045 {
1046   SessionPtr aMgr = ModelAPI_Session::get();
1047   DocumentPtr aDoc = aMgr->moduleDocument();
1048   std::string aGrpName = ModelAPI_ResultPart::group();
1049   ObjectPtr aLastPart = aDoc->object(aGrpName, aDoc->size(aGrpName) - 1);
1050   ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aLastPart);
1051   if (aPart)
1052     activatePart(aPart);
1053 }
1054
1055 //**************************************************************
1056 void XGUI_Workshop::deleteObjects(const QList<ObjectPtr>& theList)
1057 {
1058   QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1059   QMessageBox::StandardButton aRes = QMessageBox::warning(
1060       aDesktop, tr("Delete features"), tr("Seleted features will be deleted. Continue?"),
1061       QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
1062   // ToDo: definbe deleting method
1063   if (aRes == QMessageBox::Yes) {
1064     SessionPtr aMgr = ModelAPI_Session::get();
1065     aMgr->startOperation();
1066     foreach (ObjectPtr aObj, theList)
1067     {
1068       ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1069       if (aPart) {
1070         DocumentPtr aDoc = aPart->document();
1071         if (aDoc == aMgr->activeDocument()) {
1072           aDoc->close();
1073         }
1074         //aMgr->moduleDocument()->removeFeature(aPart->owner());
1075       } else {
1076         FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1077         if (aFeature)
1078           aObj->document()->removeFeature(aFeature);
1079       }
1080     }
1081     myDisplayer->updateViewer();
1082     aMgr->finishOperation();
1083   }
1084 }
1085
1086 //**************************************************************
1087 void XGUI_Workshop::showObjects(const QList<ObjectPtr>& theList, bool isVisible)
1088 {
1089   foreach (ObjectPtr aObj, theList)
1090   {
1091     ResultPtr aRes = boost::dynamic_pointer_cast<ModelAPI_Result>(aObj);
1092     if (aRes) {
1093       if (isVisible) {
1094         myDisplayer->display(aRes, false);
1095       } else {
1096         myDisplayer->erase(aRes, false);
1097       }
1098     }
1099   }
1100   myDisplayer->updateViewer();
1101 }
1102
1103 //**************************************************************
1104 void XGUI_Workshop::showOnlyObjects(const QList<ObjectPtr>& theList)
1105 {
1106   myDisplayer->eraseAll(false);
1107   showObjects(theList, true);
1108 }
1109
1110
1111 //**************************************************************
1112 void XGUI_Workshop::updateCommandsOnViewSelection()
1113 {
1114   SessionPtr aMgr = ModelAPI_Session::get();
1115   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
1116   XGUI_Selection* aSelection = mySelector->selection();
1117   if (aSelection->getSelected().size() == 0)
1118     return;
1119
1120   QList<QAction*> aActions = getModuleCommands();
1121   foreach(QAction* aAction, aActions)
1122   {
1123     QString aId = aAction->data().toString();
1124     std::list<ModelAPI_Validator*> aValidators;
1125     std::list<std::list<std::string> > anArguments;
1126     aFactory->validators(aId.toStdString(), aValidators, anArguments);
1127     std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
1128     for (; aValidator != aValidators.end(); aValidator++) {
1129       if (*aValidator) {
1130         const ModuleBase_SelectionValidator* aSelValidator =
1131             dynamic_cast<const ModuleBase_SelectionValidator*>(*aValidator);
1132         if (aSelValidator) {
1133           aAction->setEnabled(aSelValidator->isValid(aSelection));
1134         }
1135       }
1136     }
1137   }
1138 }
1139
1140 //**************************************************************
1141 void XGUI_Workshop::registerValidators() const
1142 {
1143   SessionPtr aMgr = ModelAPI_Session::get();
1144   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
1145 }
1146
1147 //**************************************************************
1148 void XGUI_Workshop::displayAllResults()
1149 {
1150   SessionPtr aMgr = ModelAPI_Session::get();
1151   DocumentPtr aRootDoc = aMgr->moduleDocument();
1152   displayDocumentResults(aRootDoc);
1153   for (int i = 0; i < aRootDoc->size(ModelAPI_ResultPart::group()); i++) {
1154     ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), i);
1155     ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1156     displayDocumentResults(aPart->partDoc());
1157   }
1158   myDisplayer->updateViewer();
1159 }
1160
1161 //**************************************************************
1162 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
1163 {
1164   if (!theDoc)
1165     return;
1166   displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
1167   displayGroupResults(theDoc, ModelAPI_ResultBody::group());
1168 }
1169
1170 //**************************************************************
1171 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
1172 {
1173   for (int i = 0; i < theDoc->size(theGroup); i++)
1174     myDisplayer->display(theDoc->object(theGroup, i), false);
1175 }