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