]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_Workshop.cpp
Salome HOME
Merge branch 'master' of newgeom:newgeom
[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 bool XGUI_Workshop::isActiveOperationAborted()
563 {
564   if(!myOperationMgr->hasOperation())
565     return true;
566   return myOperationMgr->abortOperation();
567 }
568
569 //******************************************************
570 void XGUI_Workshop::onExit()
571 {
572   SessionPtr aMgr = ModelAPI_Session::get();
573   if (aMgr->isModified()) {
574     int anAnswer = QMessageBox::question(
575         myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
576         QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
577     if (anAnswer == QMessageBox::Save) {
578       bool saved = onSave();
579       if (!saved) {
580         return;
581       }
582     } else if (anAnswer == QMessageBox::Cancel) {
583       return;
584     }
585   }
586   qApp->exit();
587 }
588
589 //******************************************************
590 void XGUI_Workshop::onNew()
591 {
592   QApplication::setOverrideCursor(Qt::WaitCursor);
593   if (objectBrowser() == 0) {
594     createDockWidgets();
595     mySelector->connectViewers();
596   }
597   myViewerProxy->connectToViewer();
598   showObjectBrowser();
599   if (!isSalomeMode()) {
600     myMainWindow->showPythonConsole();
601     QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
602     aWnd->showMaximized();
603     updateCommandStatus();
604   }
605   myContextMenuMgr->connectViewer();
606   QApplication::restoreOverrideCursor();
607 }
608
609 //******************************************************
610 void XGUI_Workshop::onOpen()
611 {
612   if(!isActiveOperationAborted())
613     return;
614   //save current file before close if modified
615   SessionPtr aSession = ModelAPI_Session::get();
616   if (aSession->isModified()) {
617     //TODO(sbh): re-launch the app?
618     int anAnswer = QMessageBox::question(
619         myMainWindow, tr("Save current file"),
620         tr("The document is modified, save before opening another?"),
621         QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
622     if (anAnswer == QMessageBox::Save) {
623       onSave();
624     } else if (anAnswer == QMessageBox::Cancel) {
625       return;
626     }
627     aSession->moduleDocument()->close();
628     myCurrentDir = "";
629   }
630
631   //show file dialog, check if readable and open
632   myCurrentDir = QFileDialog::getExistingDirectory(mainWindow());
633   if (myCurrentDir.isEmpty())
634     return;
635   QFileInfo aFileInfo(myCurrentDir);
636   if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
637     QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
638     myCurrentDir = "";
639     return;
640   }
641   QApplication::setOverrideCursor(Qt::WaitCursor);
642   aSession->load(myCurrentDir.toLatin1().constData());
643   myObjectBrowser->rebuildDataTree();
644   displayAllResults();
645   updateCommandStatus();
646   QApplication::restoreOverrideCursor();
647 }
648
649 //******************************************************
650 bool XGUI_Workshop::onSave()
651 {
652   if(!isActiveOperationAborted())
653     return false;
654   if (myCurrentDir.isEmpty()) {
655     return onSaveAs();
656   }
657   std::list<std::string> aFiles;
658   saveDocument(myCurrentDir, aFiles);
659   updateCommandStatus();
660   myMainWindow->setModifiedState(false);
661   return true;
662 }
663
664 //******************************************************
665 bool XGUI_Workshop::onSaveAs()
666 {
667   if(!isActiveOperationAborted())
668     return false;
669   QFileDialog dialog(mainWindow());
670   dialog.setWindowTitle(tr("Select directory to save files..."));
671   dialog.setFileMode(QFileDialog::Directory);
672   dialog.setFilter(tr("Folders (*)"));
673   dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
674   dialog.setViewMode(QFileDialog::Detail);
675
676   if (!dialog.exec()) {
677     return false;
678   }
679   QString aTempDir = dialog.selectedFiles().first();
680   QDir aDir(aTempDir);
681   if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
682     int answer = QMessageBox::question(
683         myMainWindow,
684         //: Title of the dialog which asks user if he wants to save study in existing non-empty folder
685         tr("Save"),
686         tr("The folder already contains some files, save anyway?"),
687         QMessageBox::Save | QMessageBox::Cancel);
688     if (answer == QMessageBox::Cancel) {
689       return false;
690     }
691   }
692   myCurrentDir = aTempDir;
693   if (!isSalomeMode()) {
694     myMainWindow->setCurrentDir(myCurrentDir, false);
695     myMainWindow->setModifiedState(false);
696   }
697   return onSave();
698 }
699
700 //******************************************************
701 void XGUI_Workshop::onUndo()
702 {
703   objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
704   SessionPtr aMgr = ModelAPI_Session::get();
705   if (aMgr->isOperation())
706     operationMgr()->abortOperation();
707   aMgr->undo();
708   updateCommandStatus();
709 }
710
711 //******************************************************
712 void XGUI_Workshop::onRedo()
713 {
714   objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
715   SessionPtr aMgr = ModelAPI_Session::get();
716   if (aMgr->isOperation())
717     operationMgr()->abortOperation();
718   aMgr->redo();
719   updateCommandStatus();
720 }
721
722 //******************************************************
723 void XGUI_Workshop::onPreferences()
724 {
725   XGUI_Prefs aModif;
726   XGUI_Preferences::editPreferences(aModif);
727   if (aModif.size() > 0) {
728     QString aSection;
729     foreach (XGUI_Pref aPref, aModif)
730     {
731       aSection = aPref.first;
732       if (aSection == XGUI_Preferences::VIEWER_SECTION) {
733         if (!isSalomeMode())
734           myMainWindow->viewer()->updateFromResources();
735       } else if (aSection == XGUI_Preferences::MENU_SECTION) {
736         if (!isSalomeMode())
737           myMainWindow->menuObject()->updateFromResources();
738       }
739     }
740   }
741 }
742
743 //******************************************************
744 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
745 {
746   QString libName = QString::fromStdString(library(theModule.toStdString()));
747   if (libName.isEmpty()) {
748     qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
749     return 0;
750   }
751
752   QString err;
753   CREATE_FUNC crtInst = 0;
754
755 #ifdef WIN32
756   HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
757   if (!modLib) {
758     LPVOID lpMsgBuf;
759     ::FormatMessage(
760         FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
761         0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
762     QString aMsg((char*) &lpMsgBuf);
763     err = QString("Failed to load  %1. %2").arg(libName).arg(aMsg);
764     ::LocalFree(lpMsgBuf);
765   } else {
766     crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
767     if (!crtInst) {
768       LPVOID lpMsgBuf;
769       ::FormatMessage(
770           FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
771               | FORMAT_MESSAGE_IGNORE_INSERTS,
772           0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
773       QString aMsg((char*) &lpMsgBuf);
774       err = QString("Failed to find  %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
775       ::LocalFree(lpMsgBuf);
776     }
777   }
778 #else
779   void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
780   if ( !modLib ) {
781     err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
782   } else {
783     crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
784     if ( !crtInst ) {
785       err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
786     }
787   }
788 #endif
789
790   ModuleBase_IModule* aModule = crtInst ? crtInst(this) : 0;
791
792   if (!err.isEmpty()) {
793     if (mainWindow()) {
794       QMessageBox::warning(mainWindow(), tr("Error"), err);
795     } else {
796       qWarning(qPrintable(err));
797     }
798   }
799   return aModule;
800 }
801
802 //******************************************************
803 bool XGUI_Workshop::activateModule()
804 {
805   Config_ModuleReader aModuleReader;
806   QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
807   myModule = loadModule(moduleName);
808   if (!myModule)
809     return false;
810   myModule->createFeatures();
811   myActionsMgr->update();
812   return true;
813 }
814
815 //******************************************************
816 void XGUI_Workshop::updateCommandStatus()
817 {
818   QList<QAction*> aCommands;
819   if (isSalomeMode()) {  // update commands in SALOME mode
820     aCommands = salomeConnector()->commandList();
821   } else {
822     XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
823     foreach (XGUI_Command* aCmd, aMenuBar->features())
824       aCommands.append(aCmd);
825   }
826   SessionPtr aMgr = ModelAPI_Session::get();
827   if (aMgr->hasModuleDocument()) {
828     QAction* aUndoCmd;
829     QAction* aRedoCmd;
830     foreach(QAction* aCmd, aCommands)
831     {
832       QString aId = aCmd->data().toString();
833       if (aId == "UNDO_CMD")
834         aUndoCmd = aCmd;
835       else if (aId == "REDO_CMD")
836         aRedoCmd = aCmd;
837       else
838         // Enable all commands
839         aCmd->setEnabled(true);
840     }
841     aUndoCmd->setEnabled(aMgr->canUndo());
842     aRedoCmd->setEnabled(aMgr->canRedo());
843   } else {
844     foreach(QAction* aCmd, aCommands)
845     {
846       QString aId = aCmd->data().toString();
847       if (aId == "NEW_CMD")
848         aCmd->setEnabled(true);
849       else if (aId == "EXIT_CMD")
850         aCmd->setEnabled(true);
851       else
852         aCmd->setEnabled(false);
853     }
854   }
855   myActionsMgr->update();
856 }
857
858 //******************************************************
859 QList<QAction*> XGUI_Workshop::getModuleCommands() const
860 {
861   QList<QAction*> aCommands;
862   if (isSalomeMode()) {  // update commands in SALOME mode
863     aCommands = salomeConnector()->commandList();
864   } else {
865     XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
866     foreach(XGUI_Command* aCmd, aMenuBar->features())
867     {
868       aCommands.append(aCmd);
869     }
870   }
871   return aCommands;
872 }
873
874 //******************************************************
875 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
876 {
877   QDockWidget* aObjDock = new QDockWidget(theParent);
878   aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
879   aObjDock->setWindowTitle(tr("Object browser"));
880   aObjDock->setStyleSheet(
881       "::title { position: relative; padding-left: 5px; text-align: left center }");
882   myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
883   connect(myObjectBrowser, SIGNAL(activePartChanged(ObjectPtr)), this,
884           SLOT(changeCurrentDocument(ObjectPtr)));
885   aObjDock->setWidget(myObjectBrowser);
886
887   myContextMenuMgr->connectObjectBrowser();
888   return aObjDock;
889 }
890
891 //******************************************************
892 /*
893  * Creates dock widgets, places them in corresponding area
894  * and tabifies if necessary.
895  */
896 void XGUI_Workshop::createDockWidgets()
897 {
898   QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
899   QDockWidget* aObjDock = createObjectBrowser(aDesktop);
900   aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
901   myPropertyPanel = new XGUI_PropertyPanel(aDesktop);
902   myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
903   aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
904   hidePropertyPanel();  //<! Invisible by default
905   hideObjectBrowser();
906   aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
907
908   QPushButton* aOkBtn = myPropertyPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
909   connect(aOkBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onCommitOperation()));
910   QPushButton* aCancelBtn = myPropertyPanel->findChild<QPushButton*>(XGUI::PROP_PANEL_CANCEL);
911   connect(aCancelBtn, SIGNAL(clicked()), myOperationMgr, SLOT(onAbortOperation()));
912 //TODO(sbh): KeyReleasedProblem
913   connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)), myOperationMgr,
914           SLOT(onKeyReleased(QKeyEvent*)));
915
916   connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), myOperationMgr,
917           SLOT(onWidgetActivated(ModuleBase_ModelWidget*)));
918   connect(myOperationMgr, SIGNAL(activateNextWidget(ModuleBase_ModelWidget*)), myPropertyPanel,
919           SLOT(onActivateNextWidget(ModuleBase_ModelWidget*)));
920   connect(myOperationMgr, SIGNAL(operationValidated(bool)), myPropertyPanel,
921           SLOT(setAcceptEnabled(bool)));
922
923 }
924
925 //******************************************************
926 void XGUI_Workshop::showPropertyPanel()
927 {
928   QAction* aViewAct = myPropertyPanel->toggleViewAction();
929   //<! Restore ability to close panel from the window's menu
930   aViewAct->setEnabled(true);
931   myPropertyPanel->show();
932   myPropertyPanel->raise();
933 }
934
935 //******************************************************
936 void XGUI_Workshop::hidePropertyPanel()
937 {
938   QAction* aViewAct = myPropertyPanel->toggleViewAction();
939   //<! Do not allow to show empty property panel
940   aViewAct->setEnabled(false);
941   myPropertyPanel->hide();
942 }
943
944 //******************************************************
945 void XGUI_Workshop::showObjectBrowser()
946 {
947   myObjectBrowser->parentWidget()->show();
948 }
949
950 //******************************************************
951 void XGUI_Workshop::hideObjectBrowser()
952 {
953   myObjectBrowser->parentWidget()->hide();
954 }
955
956 //******************************************************
957 void XGUI_Workshop::onFeatureTriggered()
958 {
959   QAction* aCmd = dynamic_cast<QAction*>(sender());
960   if (aCmd) {
961     QString aId = salomeConnector()->commandId(aCmd);
962     if (!aId.isNull())
963       myModule->launchOperation(aId);
964   }
965 }
966
967 //******************************************************
968 void XGUI_Workshop::changeCurrentDocument(ObjectPtr theObj)
969 {
970   SessionPtr aMgr = ModelAPI_Session::get();
971   if (theObj) {
972     ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(theObj);
973     if (aPart) {
974       DocumentPtr aPartDoc = aPart->partDoc();
975       if (aPartDoc) {
976         aMgr->setActiveDocument(aPartDoc);
977         return;
978       }
979     }
980   }
981   aMgr->setActiveDocument(aMgr->moduleDocument());
982 }
983
984 //******************************************************
985 void XGUI_Workshop::salomeViewerSelectionChanged()
986 {
987   emit salomeViewerSelection();
988 }
989
990 //**************************************************************
991 XGUI_SalomeViewer* XGUI_Workshop::salomeViewer() const
992 {
993   return mySalomeConnector->viewer();
994 }
995
996 //**************************************************************
997 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
998 {
999   QList<ObjectPtr> aObjects = mySelector->selection()->selectedObjects();
1000   if ((theId == "ACTIVATE_PART_CMD") && (aObjects.size() > 0)) {
1001     ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aObjects.first());
1002     activatePart(aPart);
1003   } else if (theId == "DEACTIVATE_PART_CMD")
1004     activatePart(ResultPartPtr());
1005   else if (theId == "DELETE_CMD")
1006     deleteObjects(aObjects);
1007   else if (theId == "SHOW_CMD")
1008     showObjects(aObjects, true);
1009   else if (theId == "HIDE_CMD")
1010     showObjects(aObjects, false);
1011   else if (theId == "SHOW_ONLY_CMD")
1012     showOnlyObjects(aObjects);
1013 }
1014
1015 //**************************************************************
1016 void XGUI_Workshop::onWidgetValuesChanged()
1017 {
1018   ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
1019   FeaturePtr aFeature = anOperation->feature();
1020
1021   ModuleBase_ModelWidget* aSenderWidget = dynamic_cast<ModuleBase_ModelWidget*>(sender());
1022   //if (aCustom)
1023   //  aCustom->storeValue(aFeature);
1024
1025   const QList<ModuleBase_ModelWidget*>& aWidgets = myPropertyPanel->modelWidgets();
1026   QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
1027   for (; anIt != aLast; anIt++) {
1028     ModuleBase_ModelWidget* aCustom = *anIt;
1029     if (aCustom && (/*!aCustom->isInitialized(aFeature) ||*/aCustom == aSenderWidget)) {
1030       //aCustom->storeValue(aFeature);
1031       aCustom->storeValue();
1032     }
1033   }
1034 }
1035
1036 //**************************************************************
1037 void XGUI_Workshop::activatePart(ResultPartPtr theFeature)
1038 {
1039   if (!myPartActivating) {
1040     myPartActivating = true;
1041     if (theFeature)
1042       theFeature->activate();
1043     changeCurrentDocument(theFeature);
1044     myObjectBrowser->activatePart(theFeature);
1045     myPartActivating = false;
1046   }
1047 }
1048
1049 //**************************************************************
1050 void XGUI_Workshop::activateLastPart()
1051 {
1052   SessionPtr aMgr = ModelAPI_Session::get();
1053   DocumentPtr aDoc = aMgr->moduleDocument();
1054   std::string aGrpName = ModelAPI_ResultPart::group();
1055   ObjectPtr aLastPart = aDoc->object(aGrpName, aDoc->size(aGrpName) - 1);
1056   ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aLastPart);
1057   if (aPart)
1058     activatePart(aPart);
1059 }
1060
1061 //**************************************************************
1062 void XGUI_Workshop::deleteObjects(const QList<ObjectPtr>& theList)
1063 {
1064   QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1065   QMessageBox::StandardButton aRes = QMessageBox::warning(
1066       aDesktop, tr("Delete features"), tr("Seleted features will be deleted. Continue?"),
1067       QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
1068   // ToDo: definbe deleting method
1069   if (aRes == QMessageBox::Yes) {
1070     SessionPtr aMgr = ModelAPI_Session::get();
1071     aMgr->startOperation();
1072     foreach (ObjectPtr aObj, theList)
1073     {
1074       ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1075       if (aPart) {
1076         DocumentPtr aDoc = aPart->document();
1077         if (aDoc == aMgr->activeDocument()) {
1078           aDoc->close();
1079         }
1080         //aMgr->moduleDocument()->removeFeature(aPart->owner());
1081       } else {
1082         FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
1083         if (aFeature)
1084           aObj->document()->removeFeature(aFeature);
1085       }
1086     }
1087     myDisplayer->updateViewer();
1088     aMgr->finishOperation();
1089   }
1090 }
1091
1092 //**************************************************************
1093 void XGUI_Workshop::showObjects(const QList<ObjectPtr>& theList, bool isVisible)
1094 {
1095   foreach (ObjectPtr aObj, theList)
1096   {
1097     ResultPtr aRes = boost::dynamic_pointer_cast<ModelAPI_Result>(aObj);
1098     if (aRes) {
1099       if (isVisible) {
1100         myDisplayer->display(aRes, false);
1101       } else {
1102         myDisplayer->erase(aRes, false);
1103       }
1104     }
1105   }
1106   myDisplayer->updateViewer();
1107 }
1108
1109 //**************************************************************
1110 void XGUI_Workshop::showOnlyObjects(const QList<ObjectPtr>& theList)
1111 {
1112   myDisplayer->eraseAll(false);
1113   showObjects(theList, true);
1114 }
1115
1116
1117 //**************************************************************
1118 void XGUI_Workshop::updateCommandsOnViewSelection()
1119 {
1120   SessionPtr aMgr = ModelAPI_Session::get();
1121   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
1122   XGUI_Selection* aSelection = mySelector->selection();
1123   if (aSelection->getSelected().size() == 0)
1124     return;
1125
1126   QList<QAction*> aActions = getModuleCommands();
1127   foreach(QAction* aAction, aActions)
1128   {
1129     QString aId = aAction->data().toString();
1130     std::list<ModelAPI_Validator*> aValidators;
1131     std::list<std::list<std::string> > anArguments;
1132     aFactory->validators(aId.toStdString(), aValidators, anArguments);
1133     std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
1134     for (; aValidator != aValidators.end(); aValidator++) {
1135       if (*aValidator) {
1136         const ModuleBase_SelectionValidator* aSelValidator =
1137             dynamic_cast<const ModuleBase_SelectionValidator*>(*aValidator);
1138         if (aSelValidator) {
1139           aAction->setEnabled(aSelValidator->isValid(aSelection));
1140         }
1141       }
1142     }
1143   }
1144 }
1145
1146 //**************************************************************
1147 void XGUI_Workshop::registerValidators() const
1148 {
1149   SessionPtr aMgr = ModelAPI_Session::get();
1150   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
1151 }
1152
1153 //**************************************************************
1154 void XGUI_Workshop::displayAllResults()
1155 {
1156   SessionPtr aMgr = ModelAPI_Session::get();
1157   DocumentPtr aRootDoc = aMgr->moduleDocument();
1158   displayDocumentResults(aRootDoc);
1159   for (int i = 0; i < aRootDoc->size(ModelAPI_ResultPart::group()); i++) {
1160     ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), i);
1161     ResultPartPtr aPart = boost::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1162     displayDocumentResults(aPart->partDoc());
1163   }
1164   myDisplayer->updateViewer();
1165 }
1166
1167 //**************************************************************
1168 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
1169 {
1170   if (!theDoc)
1171     return;
1172   displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
1173   displayGroupResults(theDoc, ModelAPI_ResultBody::group());
1174 }
1175
1176 //**************************************************************
1177 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
1178 {
1179   for (int i = 0; i < theDoc->size(theGroup); i++)
1180     myDisplayer->display(theDoc->object(theGroup, i), false);
1181 }