Salome HOME
f1b617d851568117d410c7d8164e82df3c01aa15
[modules/shaper.git] / src / XGUI / XGUI_Workshop.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 //#include "XGUI_Constants.h"
4 #include "XGUI_Tools.h"
5 #include "XGUI_Workshop.h"
6 #include "XGUI_SelectionMgr.h"
7 #include "XGUI_Selection.h"
8 #include "XGUI_ObjectsBrowser.h"
9 #include "XGUI_Displayer.h"
10 #include "XGUI_OperationMgr.h"
11 #include "XGUI_SalomeConnector.h"
12 #include "XGUI_ActionsMgr.h"
13 #include "XGUI_ErrorDialog.h"
14 #include "XGUI_ColorDialog.h"
15 #include "XGUI_ViewerProxy.h"
16 #include "XGUI_PropertyPanel.h"
17 #include "XGUI_ContextMenuMgr.h"
18 #include "XGUI_ModuleConnector.h"
19 #include <XGUI_QtEvents.h>
20 #include <XGUI_HistoryMenu.h>
21
22 #include <AppElements_Workbench.h>
23 #include <AppElements_Viewer.h>
24 #include <AppElements_Command.h>
25 #include <AppElements_MainMenu.h>
26 #include <AppElements_MainWindow.h>
27 #include <AppElements_MenuGroupPanel.h>
28 #include <AppElements_Button.h>
29
30 #include <ModuleBase_IModule.h>
31 #include <ModuleBase_Preferences.h>
32
33 #include <ModelAPI_Events.h>
34 #include <ModelAPI_Session.h>
35 #include <ModelAPI_Feature.h>
36 #include <ModelAPI_Data.h>
37 #include <ModelAPI_AttributeDocRef.h>
38 #include <ModelAPI_Object.h>
39 #include <ModelAPI_Validator.h>
40 #include <ModelAPI_ResultGroup.h>
41 #include <ModelAPI_ResultConstruction.h>
42 #include <ModelAPI_ResultBody.h>
43 #include <ModelAPI_AttributeIntArray.h>
44 #include <ModelAPI_ResultParameter.h>
45
46 //#include <PartSetPlugin_Part.h>
47
48 #include <Events_Loop.h>
49 #include <Events_Error.h>
50 #include <Events_LongOp.h>
51
52 #include <ModuleBase_Operation.h>
53 #include <ModuleBase_Operation.h>
54 #include <ModuleBase_OperationDescription.h>
55 #include <ModuleBase_SelectionValidator.h>
56 #include <ModuleBase_WidgetFactory.h>
57 #include <ModuleBase_Tools.h>
58 #include <ModuleBase_IViewer.h>
59 #include <ModuleBase_FilterFactory.h>
60 #include <ModuleBase_PageBase.h>
61 #include <ModuleBase_Tools.h>
62
63 #include <Config_Common.h>
64 #include <Config_FeatureMessage.h>
65 #include <Config_PointerMessage.h>
66 #include <Config_ModuleReader.h>
67 #include <Config_PropManager.h>
68 #include <Config_SelectionFilterMessage.h>
69
70 #include <QApplication>
71 #include <QFileDialog>
72 #include <QMessageBox>
73 #include <QMdiSubWindow>
74 #include <QPushButton>
75 #include <QDockWidget>
76 #include <QLayout>
77 #include <QThread>
78 #include <QObject>
79 #include <QMenu>
80 #include <QToolButton>
81 #include <QAction>
82
83 #ifdef _DEBUG
84 #include <QDebug>
85 #include <iostream>
86 #endif
87
88 #ifdef WIN32
89 #include <windows.h>
90 #else
91 #include <dlfcn.h>
92 #endif
93
94 //#define DEBUG_FEATURE_CREATED
95 //#define DEBUG_FEATURE_REDISPLAY
96
97
98 XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
99     : QObject(),
100       myCurrentDir(QString()),
101       myModule(NULL),
102       mySalomeConnector(theConnector),
103       myPropertyPanel(0),
104       myObjectBrowser(0),
105       myDisplayer(0),
106       myUpdatePrefs(false),
107       myPartActivating(false),
108       myIsLoadingData(false)
109 {
110   myMainWindow = mySalomeConnector ? 0 : new AppElements_MainWindow();
111
112   myDisplayer = new XGUI_Displayer(this);
113
114   mySelector = new XGUI_SelectionMgr(this);
115   //connect(mySelector, SIGNAL(selectionChanged()), this, SLOT(updateModuleCommands()));
116
117   myOperationMgr = new XGUI_OperationMgr(this);
118   myActionsMgr = new XGUI_ActionsMgr(this);
119   myErrorDlg = new XGUI_ErrorDialog(myMainWindow);
120   myContextMenuMgr = new XGUI_ContextMenuMgr(this);
121   connect(myContextMenuMgr, SIGNAL(actionTriggered(const QString&, bool)), this,
122           SLOT(onContextMenuCommand(const QString&, bool)));
123
124   myViewerProxy = new XGUI_ViewerProxy(this);
125   connect(myViewerProxy, SIGNAL(selectionChanged()),
126           myActionsMgr,  SLOT(updateOnViewSelection()));
127
128   myModuleConnector = new XGUI_ModuleConnector(this);
129
130   connect(myOperationMgr, SIGNAL(operationStarted(ModuleBase_Operation*)), 
131           SLOT(onOperationStarted(ModuleBase_Operation*)));
132   connect(myOperationMgr, SIGNAL(operationResumed(ModuleBase_Operation*)),
133           SLOT(onOperationResumed(ModuleBase_Operation*)));
134   connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
135           SLOT(onOperationStopped(ModuleBase_Operation*)));
136   connect(myOperationMgr, SIGNAL(operationCommitted(ModuleBase_Operation*)), 
137           SLOT(onOperationCommitted(ModuleBase_Operation*)));
138   connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)), 
139           SLOT(onOperationAborted(ModuleBase_Operation*)));
140   connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
141   connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&)));
142 }
143
144 //******************************************************
145 XGUI_Workshop::~XGUI_Workshop(void)
146 {
147   delete myDisplayer;
148 }
149
150 //******************************************************
151 void XGUI_Workshop::startApplication()
152 {
153   initMenu();
154
155   Config_PropManager::registerProp("Plugins", "default_path", "Default Path",
156                                    Config_Prop::Directory, "");
157
158   //Initialize event listening
159   Events_Loop* aLoop = Events_Loop::loop();
160   aLoop->registerListener(this, Events_Error::errorID());  //!< Listening application errors.
161   aLoop->registerListener(this, Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
162   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED));
163   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
164   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
165   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
166   aLoop->registerListener(this, Events_LongOp::eventID());
167   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_PLUGIN_LOADED));
168   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TOSHOW));
169   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TOHIDE));
170   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SELFILTER_LOADED));
171
172   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED));
173   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED));
174
175   registerValidators();
176
177   // Calling of  loadCustomProps before activating module is required
178   // by Config_PropManger to restore user-defined path to plugins
179   ModuleBase_Preferences::loadCustomProps();
180   activateModule();
181   if (myMainWindow) {
182     myMainWindow->show();
183     updateCommandStatus();
184   }
185   
186   onNew();
187
188   emit applicationStarted();
189 }
190
191 //******************************************************
192 void XGUI_Workshop::initMenu()
193 {
194   myContextMenuMgr->createActions();
195
196   if (isSalomeMode()) {
197     // Create only Undo, Redo commands
198     QAction* aAction = salomeConnector()->addDesktopCommand("UNDO_CMD", tr("Undo"),
199                                                          tr("Undo last command"),
200                                                          QIcon(":pictures/undo.png"),
201                                                          QKeySequence::Undo, false, "MEN_DESK_EDIT");
202     connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onUndo()));
203     addHistoryMenu(aAction, SIGNAL(updateUndoHistory(const QList<ActionInfo>&)), SLOT(onUndo(int)));
204
205     aAction = salomeConnector()->addDesktopCommand("REDO_CMD", tr("Redo"), tr("Redo last command"),
206                                                 QIcon(":pictures/redo.png"), QKeySequence::Redo,
207                                                 false, "MEN_DESK_EDIT");
208     connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRedo()));
209     addHistoryMenu(aAction, SIGNAL(updateRedoHistory(const QList<ActionInfo>&)), SLOT(onRedo(int)));
210
211     salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
212     aAction = salomeConnector()->addDesktopCommand("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
213                                                 QIcon(":pictures/rebuild.png"), QKeySequence(),
214                                                 false, "MEN_DESK_EDIT");
215     connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onRebuild()));
216     salomeConnector()->addDesktopMenuSeparator("MEN_DESK_EDIT");
217
218     aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Export NewGeom..."), tr("Export the current document into a NewGeom file"),
219                                                 QIcon(), QKeySequence(),
220                                                 false, "MEN_DESK_FILE");
221     connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onSaveAs()));
222
223     aAction = salomeConnector()->addDesktopCommand("OPEN_CMD", tr("Import NewGeom..."), tr("Import a NewGeom file"),
224                                                 QIcon(), QKeySequence(),
225                                                 false, "MEN_DESK_FILE");
226     connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onOpen()));
227     salomeConnector()->addDesktopMenuSeparator("MEN_DESK_FILE");
228
229     return;
230   }
231   // File commands group
232   AppElements_MenuGroupPanel* aGroup = myMainWindow->menuObject()->generalPage();
233
234   AppElements_Command* aCommand;
235
236   aCommand = aGroup->addFeature("SAVE_CMD", tr("Save..."), tr("Save the document"),
237                                 QIcon(":pictures/save.png"), QKeySequence::Save);
238   aCommand->connectTo(this, SLOT(onSave()));
239   //aCommand->disable();
240
241   QString aUndoId = "UNDO_CMD";
242   aCommand = aGroup->addFeature(aUndoId, tr("Undo"), tr("Undo last command"),
243                                 QIcon(":pictures/undo.png"), QKeySequence::Undo);
244   aCommand->connectTo(this, SLOT(onUndo()));
245   AppElements_Button* aUndoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aUndoId));
246   addHistoryMenu(aUndoButton,
247                  SIGNAL(updateUndoHistory(const QList<ActionInfo>&)),
248                  SLOT(onUndo(int)));
249
250   QString aRedoId = "REDO_CMD";
251   aCommand = aGroup->addFeature(aRedoId, tr("Redo"), tr("Redo last command"),
252                                 QIcon(":pictures/redo.png"), QKeySequence::Redo);
253   aCommand->connectTo(this, SLOT(onRedo()));
254   AppElements_Button* aRedoButton = qobject_cast<AppElements_Button*>(aGroup->widget(aRedoId));
255   addHistoryMenu(aRedoButton,
256                  SIGNAL(updateRedoHistory(const QList<ActionInfo>&)),
257                  SLOT(onRedo(int)));
258
259   aCommand = aGroup->addFeature("REBUILD_CMD", tr("Rebuild"), tr("Rebuild data objects"),
260     QIcon(":pictures/rebuild.png"), QKeySequence());
261   aCommand->connectTo(this, SLOT(onRebuild()));
262
263   aCommand = aGroup->addFeature("SAVEAS_CMD", tr("Save as..."), tr("Save the document into a file"),
264                                 QIcon(":pictures/save.png"), QKeySequence());
265   aCommand->connectTo(this, SLOT(onSaveAs()));
266   //aCommand->disable();
267
268   aCommand = aGroup->addFeature("OPEN_CMD", tr("Open..."), tr("Open a new document"),
269                                 QIcon(":pictures/open.png"), QKeySequence::Open);
270   aCommand->connectTo(this, SLOT(onOpen()));
271
272   //aCommand = aGroup->addFeature("NEW_CMD", tr("New"), tr("Create a new document"),
273   //                              QIcon(":pictures/new.png"), QKeySequence::New);
274   //aCommand->connectTo(this, SLOT(onNew()));
275
276   aCommand = aGroup->addFeature("PREF_CMD", tr("Preferences"), tr("Edit preferences"),
277                                 QIcon(":pictures/preferences.png"), QKeySequence::Preferences);
278   aCommand->connectTo(this, SLOT(onPreferences()));
279
280   aCommand = aGroup->addFeature("EXIT_CMD", tr("Exit"), tr("Exit application"),
281                                 QIcon(":pictures/close.png"), QKeySequence::Close);
282   aCommand->connectTo(this, SLOT(onExit()));
283   //FIXME: SBH's test action. Can be used for some GUI tests.
284 //  #ifdef _DEBUG
285 //    aCommand = aGroup->addFeature("TEST_CMD", "Test!", "Private debug button",
286 //                                  QIcon(":pictures/close.png"), QKeySequence(), true);
287 //    aCommand->connectTo(myMainWindow, SLOT(dockPythonConsole()));
288 //  #endif
289 }
290
291 //******************************************************
292 AppElements_Workbench* XGUI_Workshop::addWorkbench(const QString& theName)
293 {
294   AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
295   return aMenuBar->addWorkbench(theName);
296 }
297
298 //******************************************************
299 void XGUI_Workshop::processEvent(const std::shared_ptr<Events_Message>& theMessage)
300 {
301   if (QApplication::instance()->thread() != QThread::currentThread()) {
302     #ifdef _DEBUG
303     std::cout << "XGUI_Workshop::processEvent: " << "Working in another thread." << std::endl;
304     #endif
305     SessionPtr aMgr = ModelAPI_Session::get();
306     PostponeMessageQtEvent* aPostponeEvent = new PostponeMessageQtEvent(theMessage);
307     QApplication::postEvent(this, aPostponeEvent);
308     return;
309   }
310
311   //A message to start feature creation received.
312   if (theMessage->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
313     std::shared_ptr<Config_FeatureMessage> aFeatureMsg =
314        std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
315     if (!aFeatureMsg->isInternal()) {
316       addFeature(aFeatureMsg);
317     }
318   }
319   // Process creation of Part
320   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
321     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
322         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
323     onFeatureCreatedMsg(aUpdMsg);
324     if (myUpdatePrefs) {
325       if (mySalomeConnector)
326         mySalomeConnector->createPreferences();
327       myUpdatePrefs = false;
328     }
329   }
330   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED)) {
331     myUpdatePrefs = true;
332   }
333   // Redisplay feature
334   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
335     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
336         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
337     onFeatureRedisplayMsg(aUpdMsg);
338   }
339   //Update property panel on corresponding message. If there is no current operation (no
340   //property panel), or received message has different feature to the current - do nothing.
341   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
342     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
343         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
344     onFeatureUpdatedMsg(anUpdateMsg);
345   } else if (theMessage->eventID() == Events_LongOp::eventID()) {
346     if (Events_LongOp::isPerformed()) {
347       QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
348     } else {
349       QApplication::restoreOverrideCursor();
350     }
351   } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TOSHOW)) {
352     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
353         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
354     const std::set<ObjectPtr>& aObjList = anUpdateMsg->objects();
355     QObjectPtrList aList;
356     std::set<ObjectPtr>::const_iterator aIt;
357     for (aIt = aObjList.cbegin(); aIt != aObjList.cend(); ++aIt)
358       aList.append(*aIt);
359     showObjects(aList, true);
360   } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TOHIDE)) {
361     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
362         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
363     const std::set<ObjectPtr>& aObjList = anUpdateMsg->objects();
364     QObjectPtrList aList;
365     std::set<ObjectPtr>::const_iterator aIt;
366     for (aIt = aObjList.cbegin(); aIt != aObjList.cend(); ++aIt)
367       aList.append(*aIt);
368     showObjects(aList, false);
369   }
370   //An operation passed by message. Start it, process and commit.
371   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OPERATION_LAUNCHED)) {
372     std::shared_ptr<Config_PointerMessage> aPartSetMsg =
373         std::dynamic_pointer_cast<Config_PointerMessage>(theMessage);
374     //myPropertyPanel->cleanContent();
375     ModuleBase_Operation* anOperation = (ModuleBase_Operation*) aPartSetMsg->pointer();
376
377     if (myOperationMgr->startOperation(anOperation)) {
378       myPropertyPanel->updateContentWidget(anOperation->feature());
379       if (!anOperation->getDescription()->hasXmlRepresentation()) {
380         if (anOperation->commit())
381           updateCommandStatus();
382       }
383     }
384   } 
385   else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_SELFILTER_LOADED)) {
386     std::shared_ptr<Config_SelectionFilterMessage> aMsg = 
387       std::dynamic_pointer_cast<Config_SelectionFilterMessage>(theMessage);
388     if (aMsg) {
389       ModuleBase_FilterFactory* aFactory = moduleConnector()->selectionFilters();
390       if (!aMsg->attributeId().empty()) {
391         aFactory->assignFilter(aMsg->selectionFilterId(), aMsg->featureId(), aMsg->attributeId(),
392                                aMsg->parameters());
393       }
394     }
395   } else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)) {
396     // the viewer's update context will not happens until viewer updated is emitted
397     myDisplayer->enableUpdateViewer(false);
398   } else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)) {
399     // the viewer's update context is unblocked, the viewer's update works
400     myDisplayer->enableUpdateViewer(true);
401   } else {
402     //Show error dialog if error message received.
403     std::shared_ptr<Events_Error> anAppError = std::dynamic_pointer_cast<Events_Error>(theMessage);
404     if (anAppError) {
405       emit errorOccurred(QString::fromLatin1(anAppError->description()));
406     }
407     return;
408   }
409   if (!isSalomeMode()) {
410     SessionPtr aMgr = ModelAPI_Session::get();
411     if (aMgr->isModified() != myMainWindow->isModifiedState())
412       myMainWindow->setModifiedState(aMgr->isModified());
413   }
414 }
415
416 //******************************************************
417 QMainWindow* XGUI_Workshop::desktop() const
418 {
419   return isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
420 }
421
422 //******************************************************
423 void XGUI_Workshop::onStartWaiting()
424 {
425   if (Events_LongOp::isPerformed()) {
426     QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
427   }
428 }
429
430 //******************************************************
431 void XGUI_Workshop::onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
432 {
433   std::set<ObjectPtr> aFeatures = theMsg->objects();
434   if (myOperationMgr->hasOperation()) {
435     FeaturePtr aCurrentFeature = myOperationMgr->currentOperation()->feature();
436     std::set<ObjectPtr>::const_iterator aIt;
437     for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
438       ObjectPtr aNewFeature = (*aIt);
439       if (aNewFeature == aCurrentFeature) {
440         myPropertyPanel->updateContentWidget(aCurrentFeature);
441         break;
442       }
443     }
444   }
445   myOperationMgr->onValidateOperation();
446   //if (myObjectBrowser)
447   //  myObjectBrowser->processEvent(theMsg);
448 }
449
450 //******************************************************
451 void XGUI_Workshop::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
452 {
453   std::set<ObjectPtr> aObjects = theMsg->objects();
454   std::set<ObjectPtr>::const_iterator aIt;
455
456 #ifdef DEBUG_FEATURE_REDISPLAY
457   QStringList anInfo;
458   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
459     anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
460   }
461   QString anInfoStr = anInfo.join(", ");
462   qDebug(QString("onFeatureRedisplayMsg: %1, %2").arg(aObjects.size()).arg(anInfoStr).toStdString().c_str());
463 #endif
464
465   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
466     ObjectPtr aObj = (*aIt);
467
468     // Hide the object if it is invalid or concealed one
469     bool aHide = !aObj->data() || !aObj->data()->isValid() || 
470       aObj->isDisabled() || (!aObj->isDisplayed());
471     if (!aHide) { // check that this is not hidden result
472       ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
473       aHide = aRes && aRes->isConcealed();
474     }
475     if (aHide)
476       myDisplayer->erase(aObj, false);
477     else {
478       // Redisplay the visible object or the object of the current operation
479       bool isVisibleObject = myDisplayer->isVisible(aObj);
480       #ifdef DEBUG_FEATURE_REDISPLAY
481       //QString anObjInfo = ModuleBase_Tools::objectInfo((aObj));
482       //qDebug(QString("visible=%1 : display= %2").arg(isVisibleObject).arg(anObjInfo).toStdString().c_str());
483       #endif
484
485       if (isVisibleObject)  { // redisplay visible object
486         //displayObject(aObj);  // In order to update presentation
487         // in order to avoid the check whether the object can be redisplayed, the exact method
488         // of redisplay is called. This modification is made in order to have the line is updated
489         // by creation of a horizontal constraint on the line by preselection
490         myDisplayer->redisplay(aObj, false);
491         if (myOperationMgr->hasOperation()) {
492           ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
493           if (!aOperation->isEditOperation() &&
494               aOperation->hasObject(aObj) && myDisplayer->isActive(aObj))
495             myDisplayer->deactivate(aObj);
496         }
497       } else { // display object if the current operation has it
498         if (displayObject(aObj)) {
499           ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
500           if (aOperation && aOperation->hasObject(aObj)) {
501             ModuleBase_Operation* aOperation = myOperationMgr->currentOperation();
502             #ifdef DEBUG_FEATURE_REDISPLAY
503               QString anObjInfo = ModuleBase_Tools::objectInfo((aObj));
504               qDebug(QString("  display object = %1").arg(anObjInfo).toStdString().c_str());
505             #endif
506             // Deactivate object of current operation from selection
507             if (myDisplayer->isActive(aObj))
508               myDisplayer->deactivate(aObj);
509           }
510         }
511       }
512     }
513   }
514   myDisplayer->updateViewer();
515 }
516
517 //******************************************************
518 void XGUI_Workshop::onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
519 {
520   std::set<ObjectPtr> aObjects = theMsg->objects();
521   std::set<ObjectPtr>::const_iterator aIt;
522 #ifdef DEBUG_FEATURE_CREATED
523   QStringList anInfo;
524   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
525     anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
526   }
527   QString anInfoStr = anInfo.join(", ");
528   qDebug(QString("onFeatureCreatedMsg: %1, %2").arg(aObjects.size()).arg(anInfoStr).toStdString().c_str());
529 #endif
530
531   //bool aHasPart = false;
532   bool isDisplayed = false;
533   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
534     ObjectPtr anObject = *aIt;
535     // the validity of the data should be checked here in order to avoid display of the objects,
536     // which were created, then deleted, but flush for the creation event happens after that
537     if (!anObject->data() || !anObject->data()->isValid())
538       continue;
539     //ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aIt);
540     //if (aPart) {
541       //aHasPart = true;
542       // If a feature is created from the aplication's python console  
543       // it doesn't stored in the operation mgr and doesn't displayed
544     //} else {
545     isDisplayed = displayObject(*aIt);
546     //}
547   }
548   //if (myObjectBrowser)
549   //  myObjectBrowser->processEvent(theMsg);
550   if (isDisplayed)
551     myDisplayer->updateViewer();
552   //if (aHasPart) { // TODO: Avoid activate last part on loading of document
553   //  activateLastPart();
554   //}
555 }
556
557 //******************************************************
558 void XGUI_Workshop::onOperationStarted(ModuleBase_Operation* theOperation)
559 {
560   setNestedFeatures(theOperation);
561
562   if (theOperation->getDescription()->hasXmlRepresentation()) {  //!< No need for property panel
563     connectWithOperation(theOperation);
564     setPropertyPanel(theOperation);
565   }
566   updateCommandStatus();
567
568   myModule->operationStarted(theOperation);
569 }
570
571 //******************************************************
572 void XGUI_Workshop::onOperationResumed(ModuleBase_Operation* theOperation)
573 {
574   setNestedFeatures(theOperation);
575
576   if (theOperation->getDescription()->hasXmlRepresentation()) {  //!< No need for property panel
577     // connectWithOperation(theOperation); already connected
578     setPropertyPanel(theOperation);
579   }
580   updateCommandStatus();
581
582   myModule->operationResumed(theOperation);
583 }
584
585
586 //******************************************************
587 void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
588 {
589   ModuleBase_ISelection* aSel = mySelector->selection();
590   QObjectPtrList aObj = aSel->selectedPresentations();
591   //!< No need for property panel
592   updateCommandStatus();
593   hidePropertyPanel();
594   myPropertyPanel->cleanContent();
595
596   // Activate objects created by current operation 
597   // in order to clean selection modes
598   // the deactivation should be pefromed in the same place, where the mode is activated,
599   // e.g. activation in the current widget activation, deactivation - in the widget's deactivation
600   //QIntList aModes;
601   //myDisplayer->activateObjects(aModes);
602   myModule->operationStopped(theOperation);
603
604   // if the operation is nested, do not deactivate objects
605   //if (myOperationMgr->operationsCount() == 0) {
606     // Activate selection mode for all objects
607   QIntList aModes;
608   // TODO: check on OCC_6.9.0
609   // the module current active modes should not be deactivated in order to save the objects selected
610   // the deactivate object in the mode of selection leads to the object is deselected in the viewer.
611   // But, in OCC_6.8.0 this deselection does not happened automatically. It is necessary to call
612   // ClearOutdatedSelection, but this method has an error in the realization, which should be fixed in
613   // the OCC_6.9.0 release. Moreother, it is possible that ClearOutdatedSelection will be called inside
614   // Deactivate method of AIS_InteractiveContext. In this case, we need not call it.
615   module()->activeSelectionModes(aModes);
616   myDisplayer->activateObjects(aModes);
617   //}
618 }
619
620
621 void XGUI_Workshop::onOperationCommitted(ModuleBase_Operation* theOperation)
622 {
623   myModule->operationCommitted(theOperation);
624 }
625
626 void XGUI_Workshop::onOperationAborted(ModuleBase_Operation* theOperation)
627 {
628   myModule->operationAborted(theOperation);
629 }
630
631 void XGUI_Workshop::setNestedFeatures(ModuleBase_Operation* theOperation)
632 {
633   if (this->isSalomeMode()) 
634     theOperation->setNestedFeatures(mySalomeConnector->nestedActions(theOperation->id()));
635   else 
636     theOperation->setNestedFeatures(myActionsMgr->nestedCommands(theOperation->id()));
637 }
638
639 void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation)
640 {
641   showPropertyPanel();
642   QString aXmlRepr = theOperation->getDescription()->xmlRepresentation();
643   ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(),
644                                                                 myModuleConnector);
645
646   myPropertyPanel->cleanContent();
647   aFactory.createWidget(myPropertyPanel->contentWidget());
648
649   QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
650   foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
651     bool isStoreValue = !theOperation->isEditOperation() &&
652                         !aWidget->getDefaultValue().empty() &&
653                         !aWidget->isComputedDefault();
654     aWidget->setFeature(theOperation->feature(), isStoreValue);
655     aWidget->enableFocusProcessing();
656   }
657   
658   myPropertyPanel->setModelWidgets(aWidgets);
659   theOperation->setPropertyPanel(myPropertyPanel);
660
661   myModule->propertyPanelDefined(theOperation);
662
663   myPropertyPanel->setWindowTitle(theOperation->getDescription()->description());
664 }
665
666 bool XGUI_Workshop::event(QEvent * theEvent)
667 {
668   PostponeMessageQtEvent* aPostponedEv = dynamic_cast<PostponeMessageQtEvent*>(theEvent);
669   if (aPostponedEv) {
670     std::shared_ptr<Events_Message> aEventPtr = aPostponedEv->postponedMessage();
671     processEvent(aEventPtr);
672     return true;
673   }
674   return false;
675 }
676
677 /*
678  *
679  */
680 void XGUI_Workshop::addFeature(const std::shared_ptr<Config_FeatureMessage>& theMessage)
681 {
682   if (!theMessage) {
683 #ifdef _DEBUG
684     qDebug() << "XGUI_Workshop::addFeature: NULL message.";
685 #endif
686     return;
687   }
688   ActionInfo aFeatureInfo;
689   aFeatureInfo.initFrom(theMessage);
690
691   QString aWchName = QString::fromStdString(theMessage->workbenchId());
692   QStringList aNestedFeatures =
693       QString::fromStdString(theMessage->nestedFeatures()).split(" ", QString::SkipEmptyParts);
694   QString aDocKind = QString::fromStdString(theMessage->documentKind());
695   QList<QAction*> aNestedActList;
696   bool isColumnButton = !aNestedFeatures.isEmpty();
697   if (isColumnButton) {
698     QString aNestedActions = QString::fromStdString(theMessage->actionsWhenNested());
699     if (aNestedActions.contains("accept")) {
700       QAction* anAction = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL);
701       connect(anAction, SIGNAL(triggered()), myOperationMgr, SLOT(commitAllOperations()));
702       aNestedActList << anAction;
703     }
704     if (aNestedActions.contains("abort")) {
705       QAction* anAction = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll, NULL);
706       connect(anAction, SIGNAL(triggered()), myOperationMgr, SLOT(abortAllOperations()));
707       aNestedActList << anAction;
708     }
709   }
710
711   if (isSalomeMode()) {
712     QAction* aAction;
713     if (isColumnButton) {
714       aAction = salomeConnector()->addNestedFeature(aWchName, aFeatureInfo, aNestedActList);
715     } else {
716       aAction = salomeConnector()->addFeature(aWchName, aFeatureInfo);
717     }
718     salomeConnector()->setNestedActions(aFeatureInfo.id, aNestedFeatures);
719     salomeConnector()->setDocumentKind(aFeatureInfo.id, aDocKind);
720
721     myActionsMgr->addCommand(aAction);
722     myModule->actionCreated(aAction);
723   } else {
724     //Find or create Workbench
725     AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
726     AppElements_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
727     if (!aPage) {
728       aPage = addWorkbench(aWchName);
729     }
730     //Find or create Group
731     QString aGroupName = QString::fromStdString(theMessage->groupId());
732     AppElements_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
733     if (!aGroup) {
734       aGroup = aPage->addGroup(aGroupName);
735     }
736     // Check if hotkey sequence is already defined:
737     QKeySequence aHotKey = myActionsMgr->registerShortcut(aFeatureInfo.shortcut);
738     if(aHotKey != aFeatureInfo.shortcut) {
739       aFeatureInfo.shortcut = aHotKey;
740     }
741     // Create feature...
742     AppElements_Command* aCommand = aGroup->addFeature(aFeatureInfo,
743                                                        aDocKind,
744                                                        aNestedFeatures);
745     // Enrich created button with accept/abort buttons if necessary
746     AppElements_Button* aButton = aCommand->button();
747     if (aButton->isColumnButton()) {
748       aButton->setAdditionalButtons(aNestedActList);
749     }
750     myActionsMgr->addCommand(aCommand);
751     myModule->actionCreated(aCommand);
752   }
753 }
754
755 /*
756  * Makes a signal/slot connections between Property Panel
757  * and given operation. The given operation becomes a
758  * current operation and previous operation if exists
759  */
760 void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
761 {
762   QAction* aCommand = 0;
763   if (isSalomeMode()) {
764     aCommand = salomeConnector()->command(theOperation->getDescription()->operationId());
765   } else {
766     AppElements_MainMenu* aMenu = myMainWindow->menuObject();
767     FeaturePtr aFeature = theOperation->feature();
768     if(aFeature)
769       aCommand = aMenu->feature(QString::fromStdString(aFeature->getKind()));
770   }
771   //Abort operation on uncheck the command
772   if (aCommand) {
773     connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
774   }
775 }
776
777 /*
778  * Saves document with given name.
779  */
780 void XGUI_Workshop::saveDocument(const QString& theName, std::list<std::string>& theFileNames)
781 {
782   QApplication::restoreOverrideCursor();
783   SessionPtr aMgr = ModelAPI_Session::get();
784   aMgr->save(theName.toLatin1().constData(), theFileNames);
785   QApplication::restoreOverrideCursor();
786 }
787
788 bool XGUI_Workshop::isActiveOperationAborted()
789 {
790   return myOperationMgr->abortAllOperations();
791 }
792
793 //******************************************************
794 void XGUI_Workshop::onExit()
795 {
796   SessionPtr aMgr = ModelAPI_Session::get();
797   if (aMgr->isModified()) {
798     int anAnswer = QMessageBox::question(
799         myMainWindow, tr("Save current file"), tr("The document is modified, save before exit?"),
800         QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
801     if (anAnswer == QMessageBox::Save) {
802       bool saved = onSave();
803       if (!saved) {
804         return;
805       }
806     } else if (anAnswer == QMessageBox::Cancel) {
807       return;
808     }
809   }
810   qApp->exit();
811 }
812
813 //******************************************************
814 void XGUI_Workshop::onNew()
815 {
816   QApplication::setOverrideCursor(Qt::WaitCursor);
817   if (objectBrowser() == 0) {
818     createDockWidgets();
819     mySelector->connectViewers();
820   }
821   myViewerProxy->connectToViewer();
822   showObjectBrowser();
823   if (!isSalomeMode()) {
824     myMainWindow->showPythonConsole();
825     QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
826     aWnd->showMaximized();
827     updateCommandStatus();
828   }
829   myContextMenuMgr->connectViewer();
830   QApplication::restoreOverrideCursor();
831 }
832
833 //******************************************************
834 void XGUI_Workshop::onOpen()
835 {
836   if(!isActiveOperationAborted())
837     return;
838   //save current file before close if modified
839   SessionPtr aSession = ModelAPI_Session::get();
840   if (aSession->isModified()) {
841     //TODO(sbh): re-launch the app?
842     int anAnswer = QMessageBox::question(
843         myMainWindow, tr("Save current file"),
844         tr("The document is modified, save before opening another?"),
845         QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Cancel);
846     if (anAnswer == QMessageBox::Save) {
847       onSave();
848     } else if (anAnswer == QMessageBox::Cancel) {
849       return;
850     }
851     aSession->closeAll();
852     myCurrentDir = "";
853   }
854
855   //show file dialog, check if readable and open
856   myCurrentDir = QFileDialog::getExistingDirectory(mainWindow());
857   if (myCurrentDir.isEmpty())
858     return;
859   QFileInfo aFileInfo(myCurrentDir);
860   if (!aFileInfo.exists() || !aFileInfo.isReadable()) {
861     QMessageBox::critical(myMainWindow, tr("Warning"), tr("Unable to open the file."));
862     myCurrentDir = "";
863     return;
864   }
865   QApplication::setOverrideCursor(Qt::WaitCursor);
866   myIsLoadingData = true;
867   aSession->load(myCurrentDir.toLatin1().constData());
868   myObjectBrowser->rebuildDataTree();
869   displayAllResults();
870   updateCommandStatus();
871   myIsLoadingData = false;
872   QApplication::restoreOverrideCursor();
873 }
874
875 //******************************************************
876 bool XGUI_Workshop::onSave()
877 {
878   if(!isActiveOperationAborted())
879     return false;
880   if (myCurrentDir.isEmpty()) {
881     return onSaveAs();
882   }
883   std::list<std::string> aFiles;
884   saveDocument(myCurrentDir, aFiles);
885   updateCommandStatus();
886   if (!isSalomeMode())
887     myMainWindow->setModifiedState(false);
888   return true;
889 }
890
891 //******************************************************
892 bool XGUI_Workshop::onSaveAs()
893 {
894   if(!isActiveOperationAborted())
895     return false;
896   QFileDialog dialog(mainWindow());
897   dialog.setWindowTitle(tr("Select directory to save files..."));
898   dialog.setFileMode(QFileDialog::Directory);
899   dialog.setFilter(tr("Folders (*)"));
900   dialog.setOptions(QFileDialog::HideNameFilterDetails | QFileDialog::ShowDirsOnly);
901   dialog.setViewMode(QFileDialog::Detail);
902
903   if (!dialog.exec()) {
904     return false;
905   }
906   QString aTempDir = dialog.selectedFiles().first();
907   QDir aDir(aTempDir);
908   if (aDir.exists() && !aDir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).isEmpty()) {
909     int answer = QMessageBox::question(
910         myMainWindow,
911         //: Title of the dialog which asks user if he wants to save study in existing non-empty folder
912         tr("Save"),
913         tr("The folder already contains some files, save anyway?"),
914         QMessageBox::Save | QMessageBox::Cancel);
915     if (answer == QMessageBox::Cancel) {
916       return false;
917     }
918   }
919   myCurrentDir = aTempDir;
920   if (!isSalomeMode()) {
921     myMainWindow->setCurrentDir(myCurrentDir, false);
922     myMainWindow->setModifiedState(false);
923   }
924   return onSave();
925 }
926
927 //******************************************************
928 void XGUI_Workshop::onUndo(int theTimes)
929 {
930   objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
931   SessionPtr aMgr = ModelAPI_Session::get();
932   if (aMgr->isOperation())
933     operationMgr()->onAbortOperation();
934   for (int i = 0; i < theTimes; ++i) {
935     aMgr->undo();
936   }
937   updateCommandStatus();
938 }
939
940 //******************************************************
941 void XGUI_Workshop::onRedo(int theTimes)
942 {
943   // the viewer update should be blocked in order to avoid the features blinking. For the created
944   // feature a results are created, the flush of the created signal caused the viewer redisplay for
945   // each created result. After a redisplay signal is flushed. So, the viewer update is blocked until
946   // redo of all possible objects happens
947   bool isUpdateEnabled = myDisplayer->enableUpdateViewer(false);
948
949   objectBrowser()->treeView()->setCurrentIndex(QModelIndex());
950   SessionPtr aMgr = ModelAPI_Session::get();
951   if (aMgr->isOperation())
952     operationMgr()->onAbortOperation();
953   for (int i = 0; i < theTimes; ++i) {
954     aMgr->redo();
955   }
956   updateCommandStatus();
957
958   // unblock the viewer update functionality and make update on purpose
959   myDisplayer->enableUpdateViewer(isUpdateEnabled);
960   myDisplayer->updateViewer();
961 }
962
963 //******************************************************
964 void XGUI_Workshop::onRebuild()
965 {
966   SessionPtr aMgr = ModelAPI_Session::get();
967   bool aWasOperation = aMgr->isOperation(); // keep this value
968   if (!aWasOperation) {
969     aMgr->startOperation("Rebuild");
970   }
971   static const Events_ID aRebuildEvent = Events_Loop::loop()->eventByName("Rebuild");
972   Events_Loop::loop()->send(std::shared_ptr<Events_Message>(
973     new Events_Message(aRebuildEvent, this)));
974   if (!aWasOperation) {
975     aMgr->finishOperation();
976   }
977   updateCommandStatus();
978 }
979
980 //******************************************************
981 void XGUI_Workshop::onPreferences()
982 {
983   ModuleBase_Prefs aModif;
984   ModuleBase_Preferences::editPreferences(aModif);
985   if (aModif.size() > 0) {
986     QString aSection;
987     foreach (ModuleBase_Pref aPref, aModif)
988     {
989       aSection = aPref.first;
990       if (aSection == ModuleBase_Preferences::VIEWER_SECTION) {
991         if (!isSalomeMode())
992           myMainWindow->viewer()->updateFromResources();
993       } else if (aSection == ModuleBase_Preferences::MENU_SECTION) {
994         if (!isSalomeMode())
995           myMainWindow->menuObject()->updateFromResources();
996       }
997     }
998   }
999 }
1000
1001 //******************************************************
1002 ModuleBase_IModule* XGUI_Workshop::loadModule(const QString& theModule)
1003 {
1004   QString libName = QString::fromStdString(library(theModule.toStdString()));
1005   if (libName.isEmpty()) {
1006     qWarning(qPrintable(tr("Information about module \"%1\" doesn't exist.").arg(theModule)));
1007     return 0;
1008   }
1009
1010   QString err;
1011   CREATE_FUNC crtInst = 0;
1012
1013 #ifdef WIN32
1014   HINSTANCE modLib = ::LoadLibrary((LPTSTR) qPrintable(libName));
1015   if (!modLib) {
1016     LPVOID lpMsgBuf;
1017     ::FormatMessage(
1018         FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
1019         0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1020     QString aMsg((char*) &lpMsgBuf);
1021     err = QString("Failed to load  %1. %2").arg(libName).arg(aMsg);
1022     ::LocalFree(lpMsgBuf);
1023   } else {
1024     crtInst = (CREATE_FUNC) ::GetProcAddress(modLib, CREATE_MODULE);
1025     if (!crtInst) {
1026       LPVOID lpMsgBuf;
1027       ::FormatMessage(
1028           FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
1029               | FORMAT_MESSAGE_IGNORE_INSERTS,
1030           0, ::GetLastError(), 0, (LPTSTR) & lpMsgBuf, 0, 0);
1031       QString aMsg((char*) &lpMsgBuf);
1032       err = QString("Failed to find  %1 function. %2").arg( CREATE_MODULE).arg(aMsg);
1033       ::LocalFree(lpMsgBuf);
1034     }
1035   }
1036 #else
1037   void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
1038   if ( !modLib ) {
1039     err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
1040   } else {
1041     crtInst = (CREATE_FUNC)dlsym( modLib, CREATE_MODULE );
1042     if ( !crtInst ) {
1043       err = QString( "Failed to find function %1. %2" ).arg( CREATE_MODULE ).arg( dlerror() );
1044     }
1045   }
1046 #endif
1047
1048   ModuleBase_IModule* aModule = crtInst ? crtInst(myModuleConnector) : 0;
1049
1050   if (!err.isEmpty()) {
1051     if (mainWindow()) {
1052       Events_Error::send(err.toStdString());
1053     } else {
1054       qWarning(qPrintable(err));
1055     }
1056   }
1057   return aModule;
1058 }
1059
1060 //******************************************************
1061 bool XGUI_Workshop::activateModule()
1062 {
1063   Config_ModuleReader aModuleReader;
1064   QString moduleName = QString::fromStdString(aModuleReader.getModuleName());
1065   myModule = loadModule(moduleName);
1066   if (!myModule)
1067     return false;
1068
1069   connect(myDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
1070     myModule, SLOT(onObjectDisplayed(ObjectPtr, AISObjectPtr)));
1071   connect(myDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
1072     myModule, SLOT(onBeforeObjectErase(ObjectPtr, AISObjectPtr)));
1073
1074   myModule->createFeatures();
1075   myActionsMgr->update();
1076   return true;
1077 }
1078
1079 //******************************************************
1080 void XGUI_Workshop::updateCommandStatus()
1081 {
1082   QList<QAction*> aCommands;
1083   if (isSalomeMode()) {  // update commands in SALOME mode
1084     aCommands = salomeConnector()->commandList();
1085   } else {
1086     AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
1087     foreach (AppElements_Command* aCmd, aMenuBar->features())
1088       aCommands.append(aCmd);
1089   }
1090   SessionPtr aMgr = ModelAPI_Session::get();
1091   if (aMgr->hasModuleDocument()) {
1092     QAction *aUndoCmd, *aRedoCmd;
1093     foreach(QAction* aCmd, aCommands) {
1094       QString aId = aCmd->data().toString();
1095       if (aId == "UNDO_CMD")
1096         aUndoCmd = aCmd;
1097       else if (aId == "REDO_CMD")
1098         aRedoCmd = aCmd;
1099       else
1100         // Enable all commands
1101         aCmd->setEnabled(true);
1102     }
1103
1104     aUndoCmd->setEnabled(myModule->canUndo());
1105     aRedoCmd->setEnabled(myModule->canRedo());
1106     updateHistory();
1107   } else {
1108     foreach(QAction* aCmd, aCommands) {
1109       QString aId = aCmd->data().toString();
1110       if (aId == "NEW_CMD")
1111         aCmd->setEnabled(true);
1112       else if (aId == "EXIT_CMD")
1113         aCmd->setEnabled(true);
1114       else
1115         aCmd->setEnabled(false);
1116     }
1117   }
1118   myActionsMgr->update();
1119   emit commandStatusUpdated();
1120 }
1121
1122 void XGUI_Workshop::updateHistory()
1123 {
1124   std::list<std::string> aUndoList = ModelAPI_Session::get()->undoList();
1125   QList<ActionInfo> aUndoRes = processHistoryList(aUndoList);
1126   emit updateUndoHistory(aUndoRes);
1127
1128   std::list<std::string> aRedoList = ModelAPI_Session::get()->redoList();
1129   QList<ActionInfo> aRedoRes = processHistoryList(aRedoList);
1130   emit updateRedoHistory(aRedoRes);
1131 }
1132
1133 //******************************************************
1134 QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
1135 {
1136   QDockWidget* aObjDock = new QDockWidget(theParent);
1137   aObjDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1138   aObjDock->setWindowTitle(tr("Object browser"));
1139   aObjDock->setStyleSheet(
1140       "::title { position: relative; padding-left: 5px; text-align: left center }");
1141   myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
1142   myObjectBrowser->setDataModel(myModule->dataModel());
1143   myModule->customizeObjectBrowser(myObjectBrowser);
1144   aObjDock->setWidget(myObjectBrowser);
1145
1146   myContextMenuMgr->connectObjectBrowser();
1147   return aObjDock;
1148 }
1149
1150 //******************************************************
1151 /*
1152  * Creates dock widgets, places them in corresponding area
1153  * and tabifies if necessary.
1154  */
1155 void XGUI_Workshop::createDockWidgets()
1156 {
1157   QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1158   QDockWidget* aObjDock = createObjectBrowser(aDesktop);
1159   aDesktop->addDockWidget(Qt::LeftDockWidgetArea, aObjDock);
1160   myPropertyPanel = new XGUI_PropertyPanel(aDesktop);
1161   myPropertyPanel->setupActions(myActionsMgr);
1162   myPropertyPanel->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea | Qt::BottomDockWidgetArea);
1163   aDesktop->addDockWidget(Qt::LeftDockWidgetArea, myPropertyPanel);
1164   hidePropertyPanel();  ///<! Invisible by default
1165   hideObjectBrowser();
1166   aDesktop->tabifyDockWidget(aObjDock, myPropertyPanel);
1167   myPropertyPanel->installEventFilter(myOperationMgr);
1168
1169   QAction* aOkAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
1170   connect(aOkAct, SIGNAL(triggered()), myOperationMgr, SLOT(onCommitOperation()));
1171   QAction* aCancelAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::Abort);
1172   connect(aCancelAct, SIGNAL(triggered()), myOperationMgr, SLOT(onAbortOperation()));
1173   connect(myPropertyPanel, SIGNAL(noMoreWidgets()), myModule, SLOT(onNoMoreWidgets()));
1174   connect(myPropertyPanel, SIGNAL(keyReleased(QKeyEvent*)),
1175           myOperationMgr,  SLOT(onKeyReleased(QKeyEvent*)));
1176   connect(myOperationMgr,  SIGNAL(validationStateChanged(bool)),
1177           aOkAct,          SLOT(setEnabled(bool)));
1178   QAction* aAcceptAllAct = myActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll);
1179   connect(myOperationMgr,  SIGNAL(nestedStateChanged(bool)),
1180           aAcceptAllAct,   SLOT(setEnabled(bool)));
1181
1182 }
1183
1184 //******************************************************
1185 void XGUI_Workshop::showPropertyPanel()
1186 {
1187   QAction* aViewAct = myPropertyPanel->toggleViewAction();
1188   ///<! Restore ability to close panel from the window's menu
1189   aViewAct->setEnabled(true);
1190   myPropertyPanel->show();
1191   myPropertyPanel->raise();
1192 }
1193
1194 //******************************************************
1195 void XGUI_Workshop::hidePropertyPanel()
1196 {
1197   QAction* aViewAct = myPropertyPanel->toggleViewAction();
1198   ///<! Do not allow to show empty property panel
1199   aViewAct->setEnabled(false);
1200   myPropertyPanel->hide();
1201 }
1202
1203 //******************************************************
1204 void XGUI_Workshop::showObjectBrowser()
1205 {
1206   myObjectBrowser->parentWidget()->show();
1207 }
1208
1209 //******************************************************
1210 void XGUI_Workshop::hideObjectBrowser()
1211 {
1212   myObjectBrowser->parentWidget()->hide();
1213 }
1214
1215 //******************************************************
1216 void XGUI_Workshop::onFeatureTriggered()
1217 {
1218   QAction* aCmd = dynamic_cast<QAction*>(sender());
1219   if (aCmd) {
1220     QString aId = salomeConnector()->commandId(aCmd);
1221     if (!aId.isNull())
1222       myModule->launchOperation(aId);
1223   }
1224 }
1225
1226 //******************************************************
1227 void XGUI_Workshop::salomeViewerSelectionChanged()
1228 {
1229   emit salomeViewerSelection();
1230 }
1231
1232 //**************************************************************
1233 ModuleBase_IViewer* XGUI_Workshop::salomeViewer() const
1234 {
1235   return mySalomeConnector->viewer();
1236 }
1237
1238 //**************************************************************
1239 void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
1240 {
1241   QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1242   if (theId == "DELETE_CMD")
1243     deleteObjects();
1244   else if (theId == "COLOR_CMD")
1245     changeColor(aObjects);
1246   else if (theId == "SHOW_CMD")
1247     showObjects(aObjects, true);
1248   else if (theId == "HIDE_CMD")
1249     showObjects(aObjects, false);
1250   else if (theId == "SHOW_ONLY_CMD")
1251     showOnlyObjects(aObjects);
1252   else if (theId == "SHADING_CMD")
1253     setDisplayMode(aObjects, XGUI_Displayer::Shading);
1254   else if (theId == "WIREFRAME_CMD")
1255     setDisplayMode(aObjects, XGUI_Displayer::Wireframe);
1256   else if (theId == "HIDEALL_CMD")
1257     myDisplayer->eraseAll();
1258 }
1259
1260 //**************************************************************
1261 void XGUI_Workshop::deleteObjects()
1262 {
1263   ModuleBase_IModule* aModule = module();
1264   // 1. allow the module to delete objects, do nothing if it has succeed
1265   if (aModule->deleteObjects()) {
1266     updateCommandStatus();
1267     return;
1268   }
1269
1270   if (!isActiveOperationAborted())
1271     return;
1272   QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
1273   bool hasResult = false;
1274   bool hasFeature = false;
1275   bool hasParameter = false;
1276   ModuleBase_Tools::checkObjects(anObjects, hasResult, hasFeature, hasParameter);
1277   if (!(hasFeature || hasParameter))
1278     return;
1279
1280   // 1. start operation
1281   QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text();
1282   aDescription += tr(" %1");
1283   QStringList aObjectNames;
1284   foreach (ObjectPtr aObj, anObjects) {
1285     if (!aObj->data().get())
1286       continue;
1287     aObjectNames << QString::fromStdString(aObj->data()->name());
1288   }
1289   aDescription = aDescription.arg(aObjectNames.join(", "));
1290
1291   SessionPtr aMgr = ModelAPI_Session::get();
1292   aMgr->startOperation(aDescription.toStdString());
1293   // 2. close the documents of the removed parts if the result part is in a list of selected objects
1294   foreach (ObjectPtr aObj, anObjects)
1295   {
1296     ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
1297     if (aPart) {
1298       DocumentPtr aDoc = aObj->document();
1299       if (aDoc == aMgr->activeDocument()) {
1300         aDoc->close();
1301       }
1302     }
1303   }
1304   // 3. delete objects
1305   QMainWindow* aDesktop = isSalomeMode() ? salomeConnector()->desktop() : myMainWindow;
1306   std::set<FeaturePtr> anIgnoredFeatures;
1307   if (deleteFeatures(anObjects, anIgnoredFeatures, aDesktop, true)) {
1308     myDisplayer->updateViewer();
1309     aMgr->finishOperation();
1310     updateCommandStatus();
1311   }
1312   else {
1313     aMgr->abortOperation();
1314   }
1315 }
1316
1317 //**************************************************************
1318 bool XGUI_Workshop::deleteFeatures(const QObjectPtrList& theList,
1319                                    std::set<FeaturePtr> theIgnoredFeatures,
1320                                    QWidget* theParent,
1321                                    const bool theAskAboutDeleteReferences)
1322 {
1323   // 1. find all referenced features
1324   std::set<FeaturePtr> aRefFeatures;
1325   foreach (ObjectPtr aObj, theList) {
1326     FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
1327     if (aFeature.get() != NULL) {
1328       aObj->document()->refsToFeature(aFeature, aRefFeatures, false);
1329     }
1330   }
1331   // 2. warn about the references remove, break the delete operation if the user chose it
1332   if (theAskAboutDeleteReferences && !aRefFeatures.empty()) {
1333     QStringList aRefNames;
1334     std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
1335                                          aLast = aRefFeatures.end();
1336     for (; anIt != aLast; anIt++) {
1337       aRefNames.append((*anIt)->name().c_str());
1338     }
1339     QString aNames = aRefNames.join(", ");
1340
1341     QMessageBox::StandardButton aRes = QMessageBox::warning(
1342         theParent, tr("Delete features"),
1343         QString(tr("Selected features are used in the following features: %1.\
1344 These features will be deleted also. Would you like to continue?")).arg(aNames),
1345         QMessageBox::No | QMessageBox::Yes, QMessageBox::No);
1346     if (aRes != QMessageBox::Yes)
1347       return false;
1348   }
1349
1350   // 3. remove referenced features
1351   std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
1352                                        aLast = aRefFeatures.end();
1353   for (; anIt != aLast; anIt++) {
1354     FeaturePtr aFeature = (*anIt);
1355     DocumentPtr aDoc = aFeature->document();
1356     if (theIgnoredFeatures.find(aFeature) == theIgnoredFeatures.end())
1357       aDoc->removeFeature(aFeature);
1358   }
1359
1360   // 4. remove the parameter features
1361   foreach (ObjectPtr aObj, theList) {
1362     FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
1363     if (aFeature) {
1364       DocumentPtr aDoc = aObj->document();
1365       if (theIgnoredFeatures.find(aFeature) == theIgnoredFeatures.end())
1366         aDoc->removeFeature(aFeature);
1367     }
1368   }
1369   return true;
1370 }
1371
1372 bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
1373 {
1374   bool isFoundResultType = false;
1375   foreach(ObjectPtr anObj, theObjects)
1376   {
1377     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1378     if (aResult.get() == NULL)
1379       continue;
1380
1381     isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
1382     if (isFoundResultType)
1383       break;
1384   }
1385   return isFoundResultType;
1386 }
1387
1388 //**************************************************************
1389 bool XGUI_Workshop::canChangeColor() const
1390 {
1391   QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
1392
1393   std::set<std::string> aTypes;
1394   aTypes.insert(ModelAPI_ResultGroup::group());
1395   aTypes.insert(ModelAPI_ResultConstruction::group());
1396   aTypes.insert(ModelAPI_ResultBody::group());
1397   aTypes.insert(ModelAPI_ResultPart::group());
1398
1399   return hasResults(aObjects, aTypes);
1400 }
1401
1402 void setColor(ResultPtr theResult, std::vector<int>& theColor)
1403 {
1404   if (!theResult.get())
1405     return;
1406
1407   AttributeIntArrayPtr aColorAttr = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
1408   if (aColorAttr.get() != NULL) {
1409     if (!aColorAttr->size()) {
1410       aColorAttr->setSize(3);
1411     }
1412     aColorAttr->setValue(0, theColor[0]);
1413     aColorAttr->setValue(1, theColor[1]);
1414     aColorAttr->setValue(2, theColor[2]);
1415   }
1416 }
1417
1418 //**************************************************************
1419 void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
1420 {
1421   AttributeIntArrayPtr aColorAttr;
1422   // 1. find the current color of the object. This is a color of AIS presentation
1423   // The objects are iterated until a first valid color is found 
1424   std::vector<int> aColor;
1425   foreach(ObjectPtr anObject, theObjects) {
1426     if (anObject->groupName() == ModelAPI_ResultPart::group()) {
1427       ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(anObject);
1428       DocumentPtr aPartDoc = aPart->partDoc();
1429       // the document should be checked on null, because in opened document if the part
1430       // has not been activated yet, the part document is empty
1431       if (!aPartDoc.get()) {
1432         emit errorOccurred(QString::fromLatin1("Color can not be changed on a part with an empty document"));
1433       }
1434       else {
1435         if (aPartDoc->size(ModelAPI_ResultBody::group()) > 0) {
1436           ObjectPtr aObject = aPartDoc->object(ModelAPI_ResultBody::group(), 0);
1437           ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObject);
1438           if (aBody.get()) {
1439             std::string aSection, aName, aDefault;
1440             aBody->colorConfigInfo(aSection, aName, aDefault);
1441             if (!aSection.empty() && !aName.empty()) {
1442               aColor = Config_PropManager::color(aSection, aName, aDefault);
1443             }
1444           }
1445         }
1446       }
1447     }
1448     else {
1449       AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
1450       if (anAISObj.get()) {
1451         aColor.resize(3);
1452         anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
1453       }
1454     }
1455     if (!aColor.empty())
1456       break;
1457   }
1458   if (aColor.size() != 3)
1459     return;
1460
1461   // 2. show the dialog to change the value
1462   XGUI_ColorDialog* aDlg = new XGUI_ColorDialog(mainWindow());
1463   aDlg->setColor(aColor);
1464   aDlg->move(QCursor::pos());
1465   bool isDone = aDlg->exec() == QDialog::Accepted;
1466   if (!isDone)
1467     return;
1468
1469   bool isRandomColor = aDlg->isRandomColor();
1470
1471   // 3. abort the previous operation and start a new one
1472   SessionPtr aMgr = ModelAPI_Session::get();
1473   bool aWasOperation = aMgr->isOperation(); // keep this value
1474   if (!aWasOperation) {
1475     QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text();
1476     aMgr->startOperation(aDescription.toStdString());
1477   }
1478
1479   // 4. set the value to all results
1480   foreach(ObjectPtr anObj, theObjects) {
1481     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
1482     if (aResult.get() != NULL) {
1483       if (aResult->groupName() == ModelAPI_ResultPart::group()) {
1484         ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aResult);
1485         DocumentPtr aPartDoc = aPart->partDoc();
1486         // the document should be checked on null, because in opened document if the part
1487         // has not been activated yet, the part document is empty
1488         if (aPartDoc.get()) {
1489           for (int i = 0; i < aPartDoc->size(ModelAPI_ResultBody::group()); i++) {
1490             ObjectPtr aObject = aPartDoc->object(ModelAPI_ResultBody::group(), i);
1491             ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aObject);
1492             std::vector<int> aColorResult = aDlg->getColor();
1493             setColor(aBody, aColorResult);
1494           }
1495         }
1496       }
1497       else {
1498         std::vector<int> aColorResult = aDlg->getColor();
1499         setColor(aResult, aColorResult);
1500       }
1501     }
1502   }
1503   if (!aWasOperation)
1504     aMgr->finishOperation();
1505   updateCommandStatus();
1506 }
1507
1508 //**************************************************************
1509 void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
1510 {
1511   foreach (ObjectPtr aObj, theList) {
1512     if (isVisible) {
1513       aObj->setDisplayed(true);
1514       //displayObject(aObj);
1515     } else {
1516       aObj->setDisplayed(false);
1517       //myDisplayer->erase(aObj, false);
1518     }
1519   }
1520   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1521   //myDisplayer->updateViewer();
1522 }
1523
1524 //**************************************************************
1525 void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList)
1526 {
1527   myDisplayer->showOnly(theList);
1528 }
1529
1530
1531 //**************************************************************
1532 void XGUI_Workshop::registerValidators() const
1533 {
1534   SessionPtr aMgr = ModelAPI_Session::get();
1535   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
1536 }
1537
1538 //**************************************************************
1539 void XGUI_Workshop::displayAllResults()
1540 {
1541   SessionPtr aMgr = ModelAPI_Session::get();
1542   DocumentPtr aRootDoc = aMgr->moduleDocument();
1543   displayDocumentResults(aRootDoc);
1544   for (int i = 0; i < aRootDoc->size(ModelAPI_ResultPart::group()); i++) {
1545     ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultPart::group(), i);
1546     ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObject);
1547     displayDocumentResults(aPart->partDoc());
1548   }
1549   myDisplayer->updateViewer();
1550 }
1551
1552 //**************************************************************
1553 void XGUI_Workshop::displayDocumentResults(DocumentPtr theDoc)
1554 {
1555   if (!theDoc)
1556     return;
1557   displayGroupResults(theDoc, ModelAPI_ResultConstruction::group());
1558   displayGroupResults(theDoc, ModelAPI_ResultBody::group());
1559 }
1560
1561 //**************************************************************
1562 void XGUI_Workshop::displayGroupResults(DocumentPtr theDoc, std::string theGroup)
1563 {
1564   for (int i = 0; i < theDoc->size(theGroup); i++) 
1565     theDoc->object(theGroup, i)->setDisplayed(true);
1566     //displayObject(theDoc->object(theGroup, i));
1567   Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1568 }
1569
1570 //**************************************************************
1571 void XGUI_Workshop::setDisplayMode(const QObjectPtrList& theList, int theMode)
1572 {
1573   foreach(ObjectPtr aObj, theList) {
1574     myDisplayer->setDisplayMode(aObj, (XGUI_Displayer::DisplayMode)theMode, false);
1575   }
1576   if (theList.size() > 0)
1577     myDisplayer->updateViewer();
1578 }
1579
1580 //**************************************************************
1581 void XGUI_Workshop::closeDocument()
1582 {
1583   ModuleBase_Operation* anOperation = operationMgr()->currentOperation();
1584   while (anOperation) {
1585     anOperation->abort();
1586     anOperation = operationMgr()->currentOperation();
1587   }
1588   myDisplayer->closeLocalContexts();
1589   myDisplayer->eraseAll();
1590   objectBrowser()->clearContent();
1591
1592   SessionPtr aMgr = ModelAPI_Session::get();
1593   aMgr->closeAll();
1594   objectBrowser()->clearContent();
1595 }
1596
1597 //**************************************************************
1598 bool XGUI_Workshop::displayObject(ObjectPtr theObj)
1599 {
1600   if (!myModule->canDisplayObject(theObj))
1601     return false;
1602
1603   ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObj);
1604   if (aBody.get() != NULL) {
1605     int aNb = myDisplayer->objectsCount();
1606     myDisplayer->display(theObj, false);
1607     if (aNb == 0)
1608       viewer()->fitAll();
1609   } else if (!(myIsLoadingData || myPartActivating))
1610     myDisplayer->display(theObj, false);
1611
1612   return true;
1613 }
1614
1615 void XGUI_Workshop::addHistoryMenu(QObject* theObject, const char* theSignal, const char* theSlot)
1616 {
1617   XGUI_HistoryMenu* aMenu = NULL;
1618   if (isSalomeMode()) {
1619     QAction* anAction = qobject_cast<QAction*>(theObject);
1620     if (!anAction)
1621       return;
1622     aMenu = new XGUI_HistoryMenu(anAction);
1623   } else {
1624     QToolButton* aButton =  qobject_cast<QToolButton*>(theObject);
1625     aMenu = new XGUI_HistoryMenu(aButton);
1626   }
1627   connect(this, theSignal, aMenu, SLOT(setHistory(const QList<ActionInfo>&)));
1628   connect(aMenu, SIGNAL(actionSelected(int)), this, theSlot);
1629 }
1630
1631 QList<ActionInfo> XGUI_Workshop::processHistoryList(const std::list<std::string>& theList) const
1632 {
1633   QList<ActionInfo> aResult;
1634   std::list<std::string>::const_iterator it = theList.cbegin();
1635   for (; it != theList.cend(); it++) {
1636     QString anId = QString::fromStdString(*it);
1637     bool isEditing = anId.endsWith(ModuleBase_Operation::EditSuffix());
1638     if (isEditing) {
1639       anId.chop(ModuleBase_Operation::EditSuffix().size());
1640     }
1641     ActionInfo anInfo;
1642     QAction* aContextMenuAct = myContextMenuMgr->actionByName(anId);
1643     if (aContextMenuAct) {
1644       anInfo.initFrom(aContextMenuAct);
1645     } else {
1646       anInfo = myActionsMgr->actionInfoById(anId);
1647     }
1648     if (isEditing) {
1649       anInfo.text = anInfo.text.prepend("Modify ");
1650     }
1651     aResult << anInfo;
1652   }
1653   return aResult;
1654 }