Salome HOME
Issue #948 Wrong display after Sketch edition
[modules/shaper.git] / src / XGUI / XGUI_WorkshopListener.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 #include "XGUI_WorkshopListener.h"
4 #include "XGUI_Workshop.h"
5 #include "XGUI_Displayer.h"
6 #include "XGUI_ErrorMgr.h"
7 #include "XGUI_OperationMgr.h"
8 #include "XGUI_SalomeConnector.h"
9 #include "XGUI_ActionsMgr.h"
10 #include "XGUI_PropertyPanel.h"
11 #include "XGUI_ModuleConnector.h"
12 #include "XGUI_QtEvents.h"
13
14 #include <AppElements_Workbench.h>
15 #include <AppElements_Command.h>
16 #include <AppElements_MainMenu.h>
17 #include <AppElements_MainWindow.h>
18 #include <AppElements_MenuGroupPanel.h>
19 #include <AppElements_Button.h>
20
21 #include <ModuleBase_IModule.h>
22
23 #include <ModelAPI_Object.h>
24 #include <ModelAPI_Events.h>
25 #include <ModelAPI_Session.h>
26 #include <ModelAPI_Result.h>
27 #include <ModelAPI_Feature.h>
28 #include <ModelAPI_Data.h>
29 #include <ModelAPI_ResultBody.h>
30 #include <ModelAPI_ResultCompSolid.h>
31 #include <ModelAPI_Tools.h>
32
33 #include <Events_Loop.h>
34 #include <Events_Error.h>
35 #include <Events_LongOp.h>
36
37 #include <ModuleBase_IWorkshop.h>
38
39 #include <ModuleBase_Operation.h>
40 #include <ModuleBase_OperationDescription.h>
41 #include <ModuleBase_OperationFeature.h>
42 #include <ModuleBase_Tools.h>
43 #include <ModuleBase_IViewer.h>
44 #include <ModuleBase_FilterFactory.h>
45
46 #include <Config_FeatureMessage.h>
47 #include <Config_PointerMessage.h>
48 #include <Config_SelectionFilterMessage.h>
49 #include <Config_Keywords.h>
50
51 #include <QApplication>
52 #include <QMainWindow>
53 #include <QThread>
54 #include <QAction>
55
56 #ifdef _DEBUG
57 #include <QDebug>
58 #include <iostream>
59 #endif
60
61 //#define DEBUG_FEATURE_CREATED
62 //#define DEBUG_FEATURE_REDISPLAY
63 //#define DEBUG_FEATURE_UPDATED
64 //#define DEBUG_RESULT_COMPSOLID
65
66 #ifdef DEBUG_FEATURE_REDISPLAY
67 const std::string DebugFeatureKind = "Extrusion";
68 #endif
69
70 XGUI_WorkshopListener::XGUI_WorkshopListener(ModuleBase_IWorkshop* theWorkshop)
71   : myWorkshop(theWorkshop),
72     myUpdatePrefs(false)
73 {
74   XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
75   //connect(anOperationMgr, SIGNAL(nestedStateChanged(const std::string&, const bool)),
76   //        this, SLOT(onNestedStateChanged(const std::string&, const bool)));
77 }
78
79 //******************************************************
80 XGUI_WorkshopListener::~XGUI_WorkshopListener(void)
81 {
82 }
83
84 //******************************************************
85 void XGUI_WorkshopListener::initializeEventListening()
86 {
87   //Initialize event listening
88   Events_Loop* aLoop = Events_Loop::loop();
89   aLoop->registerListener(this, Events_Error::errorID());  //!< Listening application errors.
90   aLoop->registerListener(this, Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
91   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED));
92   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
93   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
94   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
95   aLoop->registerListener(this, Events_LongOp::eventID());
96   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_PLUGIN_LOADED));
97   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SELFILTER_LOADED));
98   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_ERROR_CHANGED));
99
100   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED));
101   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED));
102 }
103
104 //******************************************************
105 void XGUI_WorkshopListener::processEvent(const std::shared_ptr<Events_Message>& theMessage)
106 {
107   if (QApplication::instance()->thread() != QThread::currentThread()) {
108     #ifdef _DEBUG
109     std::cout << "XGUI_Workshop::processEvent: " << "Working in another thread." << std::endl;
110     #endif
111     SessionPtr aMgr = ModelAPI_Session::get();
112     PostponeMessageQtEvent* aPostponeEvent = new PostponeMessageQtEvent(theMessage);
113     QApplication::postEvent(this, aPostponeEvent);
114     return;
115   }
116
117   //A message to start feature creation received.
118   if (theMessage->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
119     std::shared_ptr<Config_FeatureMessage> aFeatureMsg =
120        std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
121     if (!aFeatureMsg->isInternal()) {
122       addFeature(aFeatureMsg);
123     }
124   }
125   // Process creation of Part
126   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
127     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
128         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
129     onFeatureCreatedMsg(aUpdMsg);
130     if (myUpdatePrefs) {
131       XGUI_SalomeConnector* aSalomeConnector = workshop()->salomeConnector();
132       if (aSalomeConnector)
133         aSalomeConnector->createPreferences();
134       myUpdatePrefs = false;
135     }
136   }
137   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED)) {
138     myUpdatePrefs = true;
139   }
140   // Redisplay feature
141   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
142     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
143         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
144     onFeatureRedisplayMsg(aUpdMsg);
145   }
146   //Update property panel on corresponding message. If there is no current operation (no
147   //property panel), or received message has different feature to the current - do nothing.
148   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
149     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
150         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
151     onFeatureUpdatedMsg(anUpdateMsg);
152   } else if (theMessage->eventID() == Events_LongOp::eventID()) {
153     if (Events_LongOp::isPerformed()) {
154       QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
155     } else {
156       QApplication::restoreOverrideCursor();
157     }
158   }
159   //An operation passed by message. Start it, process and commit.
160   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OPERATION_LAUNCHED)) {
161     std::shared_ptr<Config_PointerMessage> aPartSetMsg =
162         std::dynamic_pointer_cast<Config_PointerMessage>(theMessage);
163     //myPropertyPanel->cleanContent();
164     ModuleBase_Operation* anOperation = (ModuleBase_Operation*) aPartSetMsg->pointer();
165     XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
166
167     if (anOperationMgr->startOperation(anOperation)) {
168       ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
169       if (aFOperation)
170         workshop()->propertyPanel()->updateContentWidget(aFOperation->feature());
171       if (!anOperation->getDescription()->hasXmlRepresentation()) {
172         if (anOperation->commit())
173           workshop()->updateCommandStatus();
174       }
175     }
176   } 
177   else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_SELFILTER_LOADED)) {
178     std::shared_ptr<Config_SelectionFilterMessage> aMsg = 
179       std::dynamic_pointer_cast<Config_SelectionFilterMessage>(theMessage);
180     if (aMsg) {
181       ModuleBase_FilterFactory* aFactory = myWorkshop->selectionFilters();
182       if (!aMsg->attributeId().empty()) {
183         aFactory->assignFilter(aMsg->selectionFilterId(), aMsg->featureId(), aMsg->attributeId(),
184                                aMsg->parameters());
185       }
186     }
187   } else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)) {
188     // the viewer's update context will not happens until viewer updated is emitted
189       workshop()->displayer()->enableUpdateViewer(false);
190   } else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)) {
191     // the viewer's update context is unblocked, the viewer's update works
192     XGUI_Displayer* aDisplayer = workshop()->displayer();
193     aDisplayer->enableUpdateViewer(true);
194     aDisplayer->updateViewer();
195   } else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_OBJECT_ERROR_CHANGED)) {
196     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
197         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
198     std::set<ObjectPtr> aObjects = aUpdMsg->objects();
199
200     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
201                                               (workshop()->operationMgr()->currentOperation());
202     bool aFeatureChanged = false;
203     if(aFOperation ) {
204       FeaturePtr aFeature = aFOperation->feature();
205       if (aFeature.get()) {
206         std::set<ObjectPtr>::const_iterator aIt;
207         for (aIt = aObjects.begin(); aIt != aObjects.end() && !aFeatureChanged; ++aIt) {
208           aFeatureChanged = ModelAPI_Feature::feature(*aIt) == aFeature;
209         }
210       }
211       if (aFeatureChanged)
212         workshop()->operationMgr()->onValidateOperation();
213     }
214   } else {
215     //Show error dialog if error message received.
216     std::shared_ptr<Events_Error> anAppError = std::dynamic_pointer_cast<Events_Error>(theMessage);
217     if (anAppError) {
218       emit errorOccurred(QString::fromLatin1(anAppError->description()));
219     }
220     return;
221   }
222   if (!workshop()->isSalomeMode()) {
223     SessionPtr aMgr = ModelAPI_Session::get();
224     AppElements_MainWindow* aMainWindow = workshop()->mainWindow();
225     if (aMgr->isModified() != aMainWindow->isModifiedState())
226       aMainWindow->setModifiedState(aMgr->isModified());
227   }
228 }
229
230 //******************************************************
231 void XGUI_WorkshopListener::onFeatureUpdatedMsg(
232                                      const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
233 {
234 #ifdef DEBUG_FEATURE_UPDATED
235   std::set<ObjectPtr> aObjects = theMsg->objects();
236   std::set<ObjectPtr>::const_iterator aIt;
237   QStringList anInfo;
238   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
239     anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
240   }
241   QString anInfoStr = anInfo.join(";\t");
242   qDebug(QString("onFeatureUpdatedMsg: %1, %2").arg(aObjects.size()).arg(anInfoStr).toStdString().c_str());
243 #endif
244   std::set<ObjectPtr> aFeatures = theMsg->objects();
245   XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
246   if (anOperationMgr->hasOperation()) {
247     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
248                                                       (anOperationMgr->currentOperation());
249     if (aFOperation) {
250       FeaturePtr aCurrentFeature = aFOperation->feature();
251       std::set<ObjectPtr>::const_iterator aIt;
252       for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
253         ObjectPtr aNewFeature = (*aIt);
254         if (aNewFeature == aCurrentFeature) {
255           workshop()->propertyPanel()->updateContentWidget(aCurrentFeature);
256           break;
257         }
258       }
259     }
260   }
261   //anOperationMgr->onValidateOperation();
262
263   //if (myObjectBrowser)
264   //  myObjectBrowser->processEvent(theMsg);
265 }
266
267 //******************************************************
268 void XGUI_WorkshopListener::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
269 {
270   std::set<ObjectPtr> aObjects = theMsg->objects();
271   std::set<ObjectPtr>::const_iterator aIt;
272
273 #ifdef DEBUG_FEATURE_REDISPLAY
274   QStringList anInfo;
275   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
276     anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
277   }
278   QString anInfoStr = anInfo.join(";\t");
279   qDebug(QString("onFeatureRedisplayMsg: %1, %2").arg(aObjects.size()).arg(anInfoStr).toStdString().c_str());
280 #endif
281
282   XGUI_Workshop* aWorkshop = workshop();
283   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
284   bool aFirstVisualizedBody = false;
285
286   bool aRedisplayed = false;
287   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
288     ObjectPtr aObj = (*aIt);
289
290     // Hide the object if it is invalid or concealed one
291     bool aHide = !aObj->data() || !aObj->data()->isValid() || 
292       aObj->isDisabled() || (!aObj->isDisplayed());
293     if (!aHide) { // check that this is not hidden result
294       ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
295       aHide = aRes && aRes->isConcealed();
296     }
297 #ifdef DEBUG_RESULT_COMPSOLID
298     ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
299     if (aRes.get()) {
300       ResultCompSolidPtr aCompSolidRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aRes);
301       if (aCompSolidRes.get()) {
302           qDebug(QString("COMPSOLID, numberOfSubs = %1").arg(aCompSolidRes->numberOfSubs()).toStdString().c_str());
303       }
304       if (ModelAPI_Tools::compSolidOwner(aRes))
305         qDebug("COMPSOLID sub-object");
306     }
307 #endif
308     #ifdef DEBUG_FEATURE_REDISPLAY
309       QString anObjInfo = ModuleBase_Tools::objectInfo((aObj));
310       FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
311       if (aFeature.get()) {
312         std::string aKind = aFeature->getKind();
313         if (aKind == DebugFeatureKind) {
314           qDebug(QString("visible=%1, hide=%2 : display= %2").arg(aDisplayer->isVisible(aObj))
315                                             .arg(aHide).arg(anObjInfo).toStdString().c_str());
316         }
317       }
318     #endif
319     if (aHide) {
320       aRedisplayed = aDisplayer->erase(aObj, false) || aRedisplayed;
321       #ifdef DEBUG_FEATURE_REDISPLAY
322         // Redisplay the visible object or the object of the current operation
323         bool isVisibleObject = aDisplayer->isVisible(aObj);
324
325         QString anObjInfo = ModuleBase_Tools::objectInfo((aObj));
326         //qDebug(QString("visible=%1 : erase  = %2").arg(isVisibleObject).arg(anObjInfo).toStdString().c_str());
327       #endif
328     }
329     else {
330       // Redisplay the visible object or the object of the current operation
331       bool isVisibleObject = aDisplayer->isVisible(aObj);
332       #ifdef DEBUG_FEATURE_REDISPLAY
333         QString anObjInfo = ModuleBase_Tools::objectInfo((aObj));
334         //qDebug(QString("visible=%1 : display= %2").arg(isVisibleObject).arg(anObjInfo).toStdString().c_str());
335       #endif
336
337       if (isVisibleObject)  { // redisplay visible object
338         //displayObject(aObj);  // In order to update presentation
339         // in order to avoid the check whether the object can be redisplayed, the exact method
340         // of redisplay is called. This modification is made in order to have the line is updated
341         // by creation of a horizontal constraint on the line by preselection
342         if (ModelAPI_Tools::hasSubResults(std::dynamic_pointer_cast<ModelAPI_Result>(aObj))) {
343           aRedisplayed = aDisplayer->erase(aObj, false) || aRedisplayed;
344         }
345         else {
346           aRedisplayed = aDisplayer->redisplay(aObj, false) || aRedisplayed;
347           // Deactivate object of current operation from selection
348           aWorkshop->deactivateActiveObject(aObj, false);
349         }
350       } else { // display object if the current operation has it
351         if (displayObject(aObj, aFirstVisualizedBody)) {
352           aRedisplayed = true;
353           // Deactivate object of current operation from selection
354           aWorkshop->deactivateActiveObject(aObj, false);
355         }
356       }
357     }
358   }
359   if (aRedisplayed) {
360     if (aFirstVisualizedBody)
361       myWorkshop->viewer()->fitAll();
362     customizeCurrentObject();
363     aDisplayer->updateViewer();
364   }
365 }
366 //******************************************************
367 void XGUI_WorkshopListener::onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
368 {
369   std::set<ObjectPtr> aObjects = theMsg->objects();
370   std::set<ObjectPtr>::const_iterator aIt;
371 #ifdef DEBUG_FEATURE_CREATED
372   QStringList anInfo;
373   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
374     anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
375   }
376   QString anInfoStr = anInfo.join(";\t");
377   qDebug(QString("onFeatureCreatedMsg: %1, %2").arg(aObjects.size()).arg(anInfoStr).toStdString().c_str());
378 #endif
379
380   bool aFirstVisualizedBody = false;
381
382   //bool aHasPart = false;
383   bool aDisplayed = false;
384   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
385     ObjectPtr anObject = *aIt;
386
387 #ifdef DEBUG_RESULT_COMPSOLID
388     ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
389     if (aRes.get()) {
390       ResultCompSolidPtr aCompSolidRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aRes);
391       if (aCompSolidRes.get()) {
392           qDebug(QString("COMPSOLID, numberOfSubs = %1").arg(aCompSolidRes->numberOfSubs()).toStdString().c_str());
393       }
394       if (ModelAPI_Tools::compSolidOwner(aRes))
395         qDebug("COMPSOLID sub-object");
396     }
397 #endif
398     // the validity of the data should be checked here in order to avoid display of the objects,
399     // which were created, then deleted, but flush for the creation event happens after that
400     // we should not display disabled objects
401     bool aHide = !anObject->data()->isValid() || 
402                  anObject->isDisabled() ||
403                  !anObject->isDisplayed();
404     if (!aHide) {
405       // setDisplayed has to be called in order to synchronize internal state of the object 
406       // with list of displayed objects
407       if (myWorkshop->module()->canDisplayObject(anObject)) {
408         anObject->setDisplayed(true);
409         aDisplayed = displayObject(*aIt, aFirstVisualizedBody);
410       } else 
411         anObject->setDisplayed(false);
412     }
413   }
414
415   //if (myObjectBrowser)
416   //  myObjectBrowser->processEvent(theMsg);
417   if (aDisplayed) {
418     if (aFirstVisualizedBody)
419       myWorkshop->viewer()->fitAll();
420     customizeCurrentObject();
421     workshop()->displayer()->updateViewer();
422   }
423   //if (aHasPart) { // TODO: Avoid activate last part on loading of document
424   //  activateLastPart();
425   //}
426 }
427
428 /*void XGUI_WorkshopListener::onNestedStateChanged(const std::string& theFeatureId, const bool theState)
429 {
430   XGUI_Workshop* aWorkshop = workshop();
431
432   //one button is used for all features, which can have nested actions, so it is obtained from
433   // the action manager
434   //bool aActionToBeUpdated = aWorkshop->isFeatureOfNested(theFeatureId);
435   if (aWorkshop->isSalomeMode()) {
436     XGUI_SalomeConnector* aSalomeConnector = aWorkshop->salomeConnector();
437     XGUI_ActionsMgr* anActionsMgr = aWorkshop->actionsMgr();
438     if (aSalomeConnector->isFeatureOfNested(anActionsMgr->action(theFeatureId.c_str())))
439       aActionToBeUpdated = true;
440   } else {
441     AppElements_MainMenu* aMenuBar = aWorkshop->mainWindow()->menuObject();
442     AppElements_Command* aCommand = aMenuBar->feature(theFeatureId.c_str());
443     if (aCommand && aCommand->button()->additionalButtonWidget())
444       aActionToBeUpdated = true;
445   }
446   if (aActionToBeUpdated) {
447     QAction* anAcceptAllAction = aWorkshop->actionsMgr()->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL);
448     anAcceptAllAction->setEnabled(theState);
449   }
450 }*/
451
452 bool XGUI_WorkshopListener::event(QEvent * theEvent)
453 {
454   PostponeMessageQtEvent* aPostponedEv = dynamic_cast<PostponeMessageQtEvent*>(theEvent);
455   if (aPostponedEv) {
456     std::shared_ptr<Events_Message> aEventPtr = aPostponedEv->postponedMessage();
457     processEvent(aEventPtr);
458     return true;
459   }
460   return false;
461 }
462
463 void XGUI_WorkshopListener::addFeature(const std::shared_ptr<Config_FeatureMessage>& theMessage)
464 {
465   if (!theMessage) {
466 #ifdef _DEBUG
467     qDebug() << "XGUI_WorkshopListener::addFeature: NULL message.";
468 #endif
469     return;
470   }
471   ActionInfo aFeatureInfo;
472   aFeatureInfo.initFrom(theMessage);
473
474   XGUI_Workshop* aWorkshop = workshop();
475
476   QString aWchName = QString::fromStdString(theMessage->workbenchId());
477   QStringList aNestedFeatures =
478       QString::fromStdString(theMessage->nestedFeatures()).split(" ", QString::SkipEmptyParts);
479   QString aDocKind = QString::fromStdString(theMessage->documentKind());
480   QList<QAction*> aNestedActList;
481   bool isColumnButton = !aNestedFeatures.isEmpty();
482   if (isColumnButton) {
483     QString aNestedActions = QString::fromStdString(theMessage->actionsWhenNested());
484     XGUI_OperationMgr* anOperationMgr = aWorkshop->operationMgr();
485     XGUI_ActionsMgr* anActionsMgr = aWorkshop->actionsMgr();
486     if (aNestedActions.contains(FEATURE_WHEN_NESTED_ACCEPT)) {
487       QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL);
488       connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(commitAllOperations()));
489       aNestedActList << anAction;
490     }
491     if (aNestedActions.contains(FEATURE_WHEN_NESTED_ABORT)) {
492       QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll, NULL);
493       connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(abortAllOperations()));
494       aNestedActList << anAction;
495     }
496   }
497
498   if (aWorkshop->isSalomeMode()) {
499     XGUI_SalomeConnector* aSalomeConnector = aWorkshop->salomeConnector();
500     QAction* aAction;
501     if (isColumnButton) {
502       aAction = aSalomeConnector->addFeatureOfNested(aWchName, aFeatureInfo, aNestedActList);
503     } else {
504       //Issue #650: in the SALOME mode the tooltip should be same as text
505       aFeatureInfo.toolTip = aFeatureInfo.text;
506       aAction = aSalomeConnector->addFeature(aWchName, aFeatureInfo);
507     }
508     aSalomeConnector->setNestedActions(aFeatureInfo.id, aNestedFeatures);
509     aSalomeConnector->setDocumentKind(aFeatureInfo.id, aDocKind);
510
511     aWorkshop->actionsMgr()->addCommand(aAction);
512     aWorkshop->module()->actionCreated(aAction);
513   } else {
514     //Find or create Workbench
515     AppElements_MainMenu* aMenuBar = aWorkshop->mainWindow()->menuObject();
516     AppElements_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
517     if (!aPage) {
518       aPage = aWorkshop->addWorkbench(aWchName);
519     }
520     //Find or create Group
521     QString aGroupName = QString::fromStdString(theMessage->groupId());
522     AppElements_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
523     if (!aGroup) {
524       aGroup = aPage->addGroup(aGroupName);
525     }
526     // Check if hotkey sequence is already defined:
527     XGUI_ActionsMgr* anActionsMgr = aWorkshop->actionsMgr();
528     QKeySequence aHotKey = anActionsMgr->registerShortcut(aFeatureInfo.shortcut);
529     if(aHotKey != aFeatureInfo.shortcut) {
530       aFeatureInfo.shortcut = aHotKey;
531     }
532     // Create feature...
533     AppElements_Command* aCommand = aGroup->addFeature(aFeatureInfo,
534                                                        aDocKind,
535                                                        aNestedFeatures);
536     // Enrich created button with accept/abort buttons if necessary
537     AppElements_Button* aButton = aCommand->button();
538     if (aButton->isColumnButton()) {
539       aButton->setAdditionalButtons(aNestedActList);
540     }
541     aWorkshop->actionsMgr()->addCommand(aCommand);
542     aWorkshop->module()->actionCreated(aCommand);
543   }
544 }
545
546
547 //**************************************************************
548 bool XGUI_WorkshopListener::displayObject(ObjectPtr theObj, bool& theFirstVisualizedBody)
549 {
550 #ifdef DEBUG_RESULT_COMPSOLID
551   ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObj);
552   if (aRes.get() && (ModelAPI_Tools::hasSubResults(aRes) || ModelAPI_Tools::compSolidOwner(aRes))) {
553     ResultCompSolidPtr aCompSolidRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aRes);
554     if (aCompSolidRes.get()) {
555       qDebug("COMPSOLID: displayObject");
556     }
557   }
558 #endif
559
560   bool aDisplayed = false;
561   XGUI_Workshop* aWorkshop = workshop();
562   // do not display the object if it has sub objects. They should be displayed separately.
563   if (!aWorkshop->module()->canDisplayObject(theObj) ||
564       ModelAPI_Tools::hasSubResults(std::dynamic_pointer_cast<ModelAPI_Result>(theObj)))
565     return aDisplayed;
566
567   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
568   ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObj);
569   if (aBody.get() != NULL) {
570     int aNb = aDisplayer->objectsCount();
571     aDisplayed = aDisplayer->display(theObj, false);
572     if (aNb == 0)
573       theFirstVisualizedBody = true;
574   } else 
575     aDisplayed = aDisplayer->display(theObj, false);
576
577   return aDisplayed;
578 }
579
580 bool XGUI_WorkshopListener::customizeCurrentObject()
581 {
582   bool aCustomized = false;
583   XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
584   if (anOperationMgr->hasOperation()) {
585     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
586                                                       (anOperationMgr->currentOperation());
587     if (aFOperation) {
588       FeaturePtr aCurrentFeature = aFOperation->feature();
589       if (aCurrentFeature.get())
590         aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature, false);
591     }
592   }
593   return aCustomized;
594 }
595
596 XGUI_Workshop* XGUI_WorkshopListener::workshop() const
597 {
598   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
599   return aConnector->workshop();
600 }