Salome HOME
ResultPrs should not be shown if it is empty.
[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 #ifndef HAVE_SALOME
15 #include <AppElements_Workbench.h>
16 #include <AppElements_Command.h>
17 #include <AppElements_MainMenu.h>
18 #include <AppElements_MainWindow.h>
19 #include <AppElements_MenuGroupPanel.h>
20 #include <AppElements_Button.h>
21 #endif
22
23 #include <ModuleBase_IModule.h>
24
25 #include <ModelAPI_Object.h>
26 #include <ModelAPI_Events.h>
27 #include <ModelAPI_Session.h>
28 #include <ModelAPI_Result.h>
29 #include <ModelAPI_Feature.h>
30 #include <ModelAPI_Data.h>
31 #include <ModelAPI_ResultBody.h>
32 #include <ModelAPI_ResultCompSolid.h>
33 #include <ModelAPI_Tools.h>
34
35 #include <Events_Loop.h>
36 #include <Events_Error.h>
37 #include <Events_LongOp.h>
38
39 #include <ModuleBase_IWorkshop.h>
40
41 #include <ModuleBase_Operation.h>
42 #include <ModuleBase_OperationDescription.h>
43 #include <ModuleBase_OperationFeature.h>
44 #include <ModuleBase_Tools.h>
45 #include <ModuleBase_IViewer.h>
46 #include <ModuleBase_FilterFactory.h>
47
48 #include <Config_FeatureMessage.h>
49 #include <Config_PointerMessage.h>
50 #include <Config_SelectionFilterMessage.h>
51 #include <Config_Keywords.h>
52
53 #include <QApplication>
54 #include <QMainWindow>
55 #include <QThread>
56 #include <QAction>
57
58 #ifdef _DEBUG
59 #include <QDebug>
60 #include <iostream>
61 #endif
62
63 //#define DEBUG_FEATURE_CREATED
64 //#define DEBUG_FEATURE_REDISPLAY
65 //#define DEBUG_FEATURE_UPDATED
66 //#define DEBUG_RESULT_COMPSOLID
67
68 #ifdef DEBUG_FEATURE_REDISPLAY
69 const std::string DebugFeatureKind = "Extrusion";
70 #endif
71
72 XGUI_WorkshopListener::XGUI_WorkshopListener(ModuleBase_IWorkshop* theWorkshop)
73   : myWorkshop(theWorkshop),
74     myUpdatePrefs(false)
75 {
76   XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
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   } else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_OBJECT_ERROR_CHANGED)) {
195     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
196         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
197     std::set<ObjectPtr> anObjects = aUpdMsg->objects();
198
199     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
200                                               (workshop()->operationMgr()->currentOperation());
201     bool aFeatureChanged = false;
202     if(aFOperation ) {
203       FeaturePtr aFeature = aFOperation->feature();
204       if (aFeature.get()) {
205         std::set<ObjectPtr>::const_iterator aIt;
206         for (aIt = anObjects.begin(); aIt != anObjects.end() && !aFeatureChanged; ++aIt) {
207           aFeatureChanged = ModelAPI_Feature::feature(*aIt) == aFeature;
208         }
209       }
210       if (aFeatureChanged)
211         workshop()->operationMgr()->onValidateOperation();
212     }
213   } else {
214     //Show error dialog if error message received.
215     std::shared_ptr<Events_Error> anAppError = std::dynamic_pointer_cast<Events_Error>(theMessage);
216     if (anAppError) {
217       emit errorOccurred(QString::fromLatin1(anAppError->description()));
218     }
219     return;
220   }
221 #ifndef HAVE_SALOME
222     SessionPtr aMgr = ModelAPI_Session::get();
223     AppElements_MainWindow* aMainWindow = workshop()->mainWindow();
224     if (aMgr->isModified() != aMainWindow->isModifiedState())
225       aMainWindow->setModifiedState(aMgr->isModified());
226 #endif
227 }
228
229 //******************************************************
230 void XGUI_WorkshopListener::onFeatureUpdatedMsg(
231                                      const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
232 {
233 #ifdef DEBUG_FEATURE_UPDATED
234   std::set<ObjectPtr> anObjects = theMsg->objects();
235   std::set<ObjectPtr>::const_iterator aIt;
236   QStringList anInfo;
237   for (aIt = anObjects.begin(); aIt != anObjects.end(); ++aIt) {
238     anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
239   }
240   QString anInfoStr = anInfo.join(";\t");
241   qDebug(QString("onFeatureUpdatedMsg: %1, %2").arg(anObjects.size()).arg(anInfoStr).toStdString().c_str());
242 #endif
243   std::set<ObjectPtr> aFeatures = theMsg->objects();
244   XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
245   if (anOperationMgr->hasOperation()) {
246     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
247                                                       (anOperationMgr->currentOperation());
248     if (aFOperation) {
249       FeaturePtr aCurrentFeature = aFOperation->feature();
250       std::set<ObjectPtr>::const_iterator aIt;
251       for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
252         ObjectPtr aNewFeature = (*aIt);
253         if (aNewFeature == aCurrentFeature) {
254           workshop()->propertyPanel()->updateContentWidget(aCurrentFeature);
255           break;
256         }
257       }
258     }
259   }
260   //anOperationMgr->onValidateOperation();
261
262   //if (myObjectBrowser)
263   //  myObjectBrowser->processEvent(theMsg);
264 }
265
266 //******************************************************
267 void XGUI_WorkshopListener::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
268 {
269   std::set<ObjectPtr> anObjects = theMsg->objects();
270   std::set<ObjectPtr>::const_iterator aIt;
271
272 #ifdef DEBUG_FEATURE_REDISPLAY
273   QStringList anInfo;
274   for (aIt = anObjects.begin(); aIt != anObjects.end(); ++aIt) {
275     anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
276   }
277   QString anInfoStr = anInfo.join(";\t");
278   qDebug(QString("onFeatureRedisplayMsg: %1, %2").arg(anObjects.size()).arg(anInfoStr).toStdString().c_str());
279 #endif
280
281   XGUI_Workshop* aWorkshop = workshop();
282   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
283   bool aFirstVisualizedBody = false;
284
285   bool aRedisplayed = false;
286   //std::list<ObjectPtr> aHiddenObjects;
287   for (aIt = anObjects.begin(); aIt != anObjects.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       // Hide the presentation with an empty shape. But isDisplayed state of the object should not
298       // be changed to the object becomes visible when the shape becomes not empty
299       if (!aHide && aRes.get())
300         aHide = !aRes->shape().get() || aRes->shape()->isNull();
301     }
302
303 #ifdef DEBUG_RESULT_COMPSOLID
304     ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
305     if (aRes.get()) {
306       ResultCompSolidPtr aCompSolidRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aRes);
307       if (aCompSolidRes.get()) {
308           qDebug(QString("COMPSOLID, numberOfSubs = %1").arg(aCompSolidRes->numberOfSubs()).toStdString().c_str());
309       }
310       if (ModelAPI_Tools::compSolidOwner(aRes))
311         qDebug("COMPSOLID sub-object");
312     }
313 #endif
314     #ifdef DEBUG_FEATURE_REDISPLAY
315       QString anObjInfo = ModuleBase_Tools::objectInfo((aObj));
316       FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
317       if (aFeature.get()) {
318         std::string aKind = aFeature->getKind();
319         if (aKind == DebugFeatureKind) {
320           qDebug(QString("visible=%1, hide=%2 : display= %2").arg(aDisplayer->isVisible(aObj))
321                                             .arg(aHide).arg(anObjInfo).toStdString().c_str());
322         }
323       }
324     #endif
325     if (aHide) {
326       //we should provide objects which are hidden in the viewer, e.g. sketch always should visualizes
327       // all sub-features, if some features are to be hidden, sould be proposed may be to removed #1223
328       //aHiddenObjects.push_back(aObj);
329       aRedisplayed = aDisplayer->erase(aObj, false) || aRedisplayed;
330       #ifdef DEBUG_FEATURE_REDISPLAY
331         // Redisplay the visible object or the object of the current operation
332         bool isVisibleObject = aDisplayer->isVisible(aObj);
333
334         QString anObjInfo = ModuleBase_Tools::objectInfo((aObj));
335         //qDebug(QString("visible=%1 : erase  = %2").arg(isVisibleObject).arg(anObjInfo).toStdString().c_str());
336       #endif
337     }
338     else {
339       // Redisplay the visible object or the object of the current operation
340       bool isVisibleObject = aDisplayer->isVisible(aObj);
341       #ifdef DEBUG_FEATURE_REDISPLAY
342         QString anObjInfo = ModuleBase_Tools::objectInfo((aObj));
343         //qDebug(QString("visible=%1 : display= %2").arg(isVisibleObject).arg(anObjInfo).toStdString().c_str());
344       #endif
345
346       if (isVisibleObject)  { // redisplay visible object
347         //displayObject(aObj);  // In order to update presentation
348         // in order to avoid the check whether the object can be redisplayed, the exact method
349         // of redisplay is called. This modification is made in order to have the line is updated
350         // by creation of a horizontal constraint on the line by preselection
351         if (ModelAPI_Tools::hasSubResults(std::dynamic_pointer_cast<ModelAPI_Result>(aObj))) {
352           aRedisplayed = aDisplayer->erase(aObj, false) || aRedisplayed;
353         }
354         else {
355           aRedisplayed = aDisplayer->redisplay(aObj, false) || aRedisplayed;
356           // Deactivate object of current operation from selection
357           aWorkshop->deactivateActiveObject(aObj, false);
358         }
359       } else { // display object if the current operation has it
360         if (displayObject(aObj, aFirstVisualizedBody)) {
361           aRedisplayed = true;
362           // Deactivate object of current operation from selection
363           aWorkshop->deactivateActiveObject(aObj, false);
364         }
365       }
366     }
367   }
368   // this processing should be moved in another place in order to do not cause problems in
369   // flush messages chain
370   //if (aHiddenObjects.size() > 0)
371   //  myWorkshop->module()->processHiddenObject(aHiddenObjects);
372
373   bool isCustomized = customizeCurrentObject(anObjects, aRedisplayed);
374   if (aRedisplayed || isCustomized) {
375     //VSV FitAll updated viewer by it self
376     if (aFirstVisualizedBody)
377       myWorkshop->viewer()->fitAll();
378     else 
379       aDisplayer->updateViewer();
380   }
381 }
382 //******************************************************
383 void XGUI_WorkshopListener::onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
384 {
385   std::set<ObjectPtr> anObjects = theMsg->objects();
386   std::set<ObjectPtr>::const_iterator aIt;
387 #ifdef DEBUG_FEATURE_CREATED
388   QStringList anInfo;
389   for (aIt = anObjects.begin(); aIt != anObjects.end(); ++aIt) {
390     anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
391   }
392   QString anInfoStr = anInfo.join(";\t");
393   qDebug(QString("onFeatureCreatedMsg: %1, %2").arg(anObjects.size()).arg(anInfoStr).toStdString().c_str());
394 #endif
395
396   bool aFirstVisualizedBody = false;
397
398   //bool aHasPart = false;
399   bool aDisplayed = false;
400   for (aIt = anObjects.begin(); aIt != anObjects.end(); ++aIt) {
401     ObjectPtr anObject = *aIt;
402
403 #ifdef DEBUG_RESULT_COMPSOLID
404     ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
405     if (aRes.get()) {
406       ResultCompSolidPtr aCompSolidRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aRes);
407       if (aCompSolidRes.get()) {
408           qDebug(QString("COMPSOLID, numberOfSubs = %1").arg(aCompSolidRes->numberOfSubs()).toStdString().c_str());
409       }
410       if (ModelAPI_Tools::compSolidOwner(aRes))
411         qDebug("COMPSOLID sub-object");
412     }
413 #endif
414     // the validity of the data should be checked here in order to avoid display of the objects,
415     // which were created, then deleted, but flush for the creation event happens after that
416     // we should not display disabled objects
417     bool aHide = !anObject->data()->isValid() || 
418                  anObject->isDisabled() ||
419                  !anObject->isDisplayed();
420     if (!aHide) { // check that this is not hidden result
421       ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
422       bool isConcealed = aRes && aRes->isConcealed();
423       aHide = aRes && aRes->isConcealed();
424       // Hide the presentation with an empty shape. But isDisplayed state of the object should not
425       // be changed to the object becomes visible when the shape becomes not empty
426       if (!aHide && aRes.get())
427         aHide = !aRes->shape().get() || aRes->shape()->isNull();
428     }
429     if (!aHide) {
430       // setDisplayed has to be called in order to synchronize internal state of the object 
431       // with list of displayed objects
432       if (myWorkshop->module()->canDisplayObject(anObject)) {
433         anObject->setDisplayed(true);
434         aDisplayed = displayObject(*aIt, aFirstVisualizedBody);
435       } else 
436         anObject->setDisplayed(false);
437     }
438   }
439
440   bool isCustomized = customizeCurrentObject(anObjects, aDisplayed);
441
442   //if (myObjectBrowser)
443   //  myObjectBrowser->processEvent(theMsg);
444   if (aDisplayed) {
445     //VSV FitAll updated viewer by it self
446     if (aFirstVisualizedBody)
447       myWorkshop->viewer()->fitAll();
448     else
449       workshop()->displayer()->updateViewer();
450   }
451   //if (aHasPart) { // TODO: Avoid activate last part on loading of document
452   //  activateLastPart();
453   //}
454 }
455
456 bool XGUI_WorkshopListener::event(QEvent * theEvent)
457 {
458   PostponeMessageQtEvent* aPostponedEv = dynamic_cast<PostponeMessageQtEvent*>(theEvent);
459   if (aPostponedEv) {
460     std::shared_ptr<Events_Message> aEventPtr = aPostponedEv->postponedMessage();
461     processEvent(aEventPtr);
462     return true;
463   }
464   return false;
465 }
466
467 void XGUI_WorkshopListener::addFeature(const std::shared_ptr<Config_FeatureMessage>& theMessage)
468 {
469   if (!theMessage) {
470 #ifdef _DEBUG
471     qDebug() << "XGUI_WorkshopListener::addFeature: NULL message.";
472 #endif
473     return;
474   }
475   ActionInfo aFeatureInfo;
476   aFeatureInfo.initFrom(theMessage);
477
478   XGUI_Workshop* aWorkshop = workshop();
479
480   QString aWchName = QString::fromStdString(theMessage->workbenchId());
481   QStringList aNestedFeatures =
482       QString::fromStdString(theMessage->nestedFeatures()).split(" ", QString::SkipEmptyParts);
483   QString aDocKind = QString::fromStdString(theMessage->documentKind());
484   QList<QAction*> aNestedActList;
485   bool isColumnButton = !aNestedFeatures.isEmpty();
486   if (isColumnButton) {
487     QString aNestedActions = QString::fromStdString(theMessage->actionsWhenNested());
488     XGUI_OperationMgr* anOperationMgr = aWorkshop->operationMgr();
489     XGUI_ActionsMgr* anActionsMgr = aWorkshop->actionsMgr();
490     if (aNestedActions.contains(FEATURE_WHEN_NESTED_ACCEPT)) {
491       QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL);
492       connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(commitAllOperations()));
493       aNestedActList << anAction;
494     }
495     if (aNestedActions.contains(FEATURE_WHEN_NESTED_ABORT)) {
496       QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll, NULL);
497       connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(abortAllOperations()));
498       aNestedActList << anAction;
499     }
500   }
501
502 #ifdef HAVE_SALOME
503   XGUI_SalomeConnector* aSalomeConnector = aWorkshop->salomeConnector();
504   QAction* aAction;
505   if (isColumnButton) {
506     aAction = aSalomeConnector->addFeatureOfNested(aWchName, aFeatureInfo, aNestedActList);
507   } else {
508     //Issue #650: in the SALOME mode the tooltip should be same as text
509     aFeatureInfo.toolTip = aFeatureInfo.text;
510     aAction = aSalomeConnector->addFeature(aWchName, aFeatureInfo);
511   }
512   aSalomeConnector->setNestedActions(aFeatureInfo.id, aNestedFeatures);
513   aSalomeConnector->setDocumentKind(aFeatureInfo.id, aDocKind);
514
515   aWorkshop->actionsMgr()->addCommand(aAction);
516   aWorkshop->module()->actionCreated(aAction);
517 #else 
518   //Find or create Workbench
519   AppElements_MainMenu* aMenuBar = aWorkshop->mainWindow()->menuObject();
520   AppElements_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
521   if (!aPage) {
522     aPage = aWorkshop->addWorkbench(aWchName);
523   }
524   //Find or create Group
525   QString aGroupName = QString::fromStdString(theMessage->groupId());
526   AppElements_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
527   if (!aGroup) {
528     aGroup = aPage->addGroup(aGroupName);
529   }
530   // Check if hotkey sequence is already defined:
531   XGUI_ActionsMgr* anActionsMgr = aWorkshop->actionsMgr();
532   QKeySequence aHotKey = anActionsMgr->registerShortcut(aFeatureInfo.shortcut);
533   if(aHotKey != aFeatureInfo.shortcut) {
534     aFeatureInfo.shortcut = aHotKey;
535   }
536   // Create feature...
537   AppElements_Command* aCommand = aGroup->addFeature(aFeatureInfo,
538                                                       aDocKind,
539                                                       aNestedFeatures);
540   // Enrich created button with accept/abort buttons if necessary
541   AppElements_Button* aButton = aCommand->button();
542   if (aButton->isColumnButton()) {
543     aButton->setAdditionalButtons(aNestedActList);
544   }
545   aWorkshop->actionsMgr()->addCommand(aCommand);
546   aWorkshop->module()->actionCreated(aCommand);
547 #endif
548 }
549
550
551 //**************************************************************
552 bool XGUI_WorkshopListener::displayObject(ObjectPtr theObj, bool& theFirstVisualizedBody)
553 {
554 #ifdef DEBUG_RESULT_COMPSOLID
555   ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObj);
556   if (aRes.get() && (ModelAPI_Tools::hasSubResults(aRes) || ModelAPI_Tools::compSolidOwner(aRes))) {
557     ResultCompSolidPtr aCompSolidRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aRes);
558     if (aCompSolidRes.get()) {
559       qDebug("COMPSOLID: displayObject");
560     }
561   }
562 #endif
563
564   bool aDisplayed = false;
565   XGUI_Workshop* aWorkshop = workshop();
566   // do not display the object if it has sub objects. They should be displayed separately.
567   if (!aWorkshop->module()->canDisplayObject(theObj) ||
568       ModelAPI_Tools::hasSubResults(std::dynamic_pointer_cast<ModelAPI_Result>(theObj)))
569     return aDisplayed;
570
571   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
572   ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObj);
573   if (aBody.get() != NULL) {
574     int aNb = aDisplayer->objectsCount();
575     aDisplayed = aDisplayer->display(theObj, false);
576     if (aNb == 0)
577       theFirstVisualizedBody = true;
578   } else 
579     aDisplayed = aDisplayer->display(theObj, false);
580
581   return aDisplayed;
582 }
583
584 bool XGUI_WorkshopListener::customizeCurrentObject(const std::set<ObjectPtr>& theObjects,
585                                                    bool theForceRedisplay)
586 {
587   XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
588   FeaturePtr aCurrentFeature;
589   if (anOperationMgr->hasOperation()) {
590     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
591                                                       (anOperationMgr->currentOperation());
592     if (aFOperation) {
593       aCurrentFeature = aFOperation->feature();
594     }
595   }
596
597   bool aCustomized = false;
598   if (aCurrentFeature.get()) {
599     // the customize presentation should be redisplayed if force redislayed is true or
600     // if a list of message objects contains the operation feature for case when
601     // the feature is hidden, but arguments of the feature are modified
602     // e.g. extrusion is hidden(h=0) but sketch is chosen
603     if (theForceRedisplay || theObjects.find(aCurrentFeature) != theObjects.end()) {
604       aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature,
605                                            ModuleBase_IModule::CustomizeArguments, false);
606       aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature,
607                                            ModuleBase_IModule::CustomizeResults, false);
608       aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature,
609                                            ModuleBase_IModule::CustomizeHighlightedObjects, false);
610     }
611   }
612   return aCustomized;
613 }
614
615 XGUI_Workshop* XGUI_WorkshopListener::workshop() const
616 {
617   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
618   return aConnector->workshop();
619 }