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