Salome HOME
Issue #1302 Restricting preselection to the first argument only: mirror feature has...
[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_ResultGroup.h>
33 #include <ModelAPI_ResultCompSolid.h>
34 #include <ModelAPI_Tools.h>
35
36 #include <Events_Loop.h>
37 #include <Events_Error.h>
38 #include <Events_LongOp.h>
39
40 #include <ModuleBase_IWorkshop.h>
41
42 #include <ModuleBase_Operation.h>
43 #include <ModuleBase_OperationDescription.h>
44 #include <ModuleBase_OperationFeature.h>
45 #include <ModuleBase_Tools.h>
46 #include <ModuleBase_IViewer.h>
47 #include <ModuleBase_FilterFactory.h>
48
49 #include <Config_FeatureMessage.h>
50 #include <Config_PointerMessage.h>
51 #include <Config_SelectionFilterMessage.h>
52 #include <Config_Keywords.h>
53
54 #include <QApplication>
55 #include <QMainWindow>
56 #include <QThread>
57 #include <QAction>
58
59 #ifdef _DEBUG
60 #include <QDebug>
61 #include <iostream>
62 #endif
63
64 //#define DEBUG_FEATURE_CREATED
65 //#define DEBUG_FEATURE_REDISPLAY
66 //#define DEBUG_FEATURE_UPDATED
67 //#define DEBUG_RESULT_COMPSOLID
68
69 #ifdef DEBUG_FEATURE_REDISPLAY
70 const std::string DebugFeatureKind = "Extrusion";
71 #endif
72
73 XGUI_WorkshopListener::XGUI_WorkshopListener(ModuleBase_IWorkshop* theWorkshop)
74   : myWorkshop(theWorkshop),
75     myUpdatePrefs(false)
76 {
77   XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
78 }
79
80 //******************************************************
81 XGUI_WorkshopListener::~XGUI_WorkshopListener(void)
82 {
83 }
84
85 //******************************************************
86 void XGUI_WorkshopListener::initializeEventListening()
87 {
88   //Initialize event listening
89   Events_Loop* aLoop = Events_Loop::loop();
90   aLoop->registerListener(this, Events_Error::errorID());  //!< Listening application errors.
91   aLoop->registerListener(this, Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
92   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED));
93   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
94   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
95   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
96   aLoop->registerListener(this, Events_LongOp::eventID());
97   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_PLUGIN_LOADED));
98   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SELFILTER_LOADED));
99   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_ERROR_CHANGED));
100
101   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED));
102   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED));
103 }
104
105 //******************************************************
106 void XGUI_WorkshopListener::processEvent(const std::shared_ptr<Events_Message>& theMessage)
107 {
108   if (QApplication::instance()->thread() != QThread::currentThread()) {
109     #ifdef _DEBUG
110     std::cout << "XGUI_Workshop::processEvent: " << "Working in another thread." << std::endl;
111     #endif
112     SessionPtr aMgr = ModelAPI_Session::get();
113     PostponeMessageQtEvent* aPostponeEvent = new PostponeMessageQtEvent(theMessage);
114     QApplication::postEvent(this, aPostponeEvent);
115     return;
116   }
117
118   //A message to start feature creation received.
119   if (theMessage->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
120     std::shared_ptr<Config_FeatureMessage> aFeatureMsg =
121        std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
122     if (!aFeatureMsg->isInternal()) {
123       addFeature(aFeatureMsg);
124     }
125   }
126   // Process creation of Part
127   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
128     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
129         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
130     onFeatureCreatedMsg(aUpdMsg);
131     if (myUpdatePrefs) {
132       XGUI_SalomeConnector* aSalomeConnector = workshop()->salomeConnector();
133       if (aSalomeConnector)
134         aSalomeConnector->createPreferences();
135       myUpdatePrefs = false;
136     }
137   }
138   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED)) {
139     myUpdatePrefs = true;
140   }
141   // Redisplay feature
142   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
143     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
144         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
145     onFeatureRedisplayMsg(aUpdMsg);
146   }
147   //Update property panel on corresponding message. If there is no current operation (no
148   //property panel), or received message has different feature to the current - do nothing.
149   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
150     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
151         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
152     onFeatureUpdatedMsg(anUpdateMsg);
153   } else if (theMessage->eventID() == Events_LongOp::eventID()) {
154     if (Events_LongOp::isPerformed()) {
155       QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
156     } else {
157       QApplication::restoreOverrideCursor();
158     }
159   }
160   //An operation passed by message. Start it, process and commit.
161   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OPERATION_LAUNCHED)) {
162     std::shared_ptr<Config_PointerMessage> aPartSetMsg =
163         std::dynamic_pointer_cast<Config_PointerMessage>(theMessage);
164     //myPropertyPanel->cleanContent();
165     ModuleBase_Operation* anOperation = (ModuleBase_Operation*) aPartSetMsg->pointer();
166     XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
167
168     if (anOperationMgr->startOperation(anOperation)) {
169       ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
170       if (aFOperation)
171         workshop()->propertyPanel()->updateContentWidget(aFOperation->feature());
172       if (!anOperation->getDescription()->hasXmlRepresentation()) {
173         if (anOperation->commit())
174           workshop()->updateCommandStatus();
175       }
176     }
177   } 
178   else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_SELFILTER_LOADED)) {
179     std::shared_ptr<Config_SelectionFilterMessage> aMsg = 
180       std::dynamic_pointer_cast<Config_SelectionFilterMessage>(theMessage);
181     if (aMsg) {
182       ModuleBase_FilterFactory* aFactory = myWorkshop->selectionFilters();
183       if (!aMsg->attributeId().empty()) {
184         aFactory->assignFilter(aMsg->selectionFilterId(), aMsg->featureId(), aMsg->attributeId(),
185                                aMsg->parameters());
186       }
187     }
188   } else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)) {
189     // the viewer's update context will not happens until viewer updated is emitted
190       workshop()->displayer()->enableUpdateViewer(false);
191   } else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)) {
192     // the viewer's update context is unblocked, the viewer's update works
193     XGUI_Displayer* aDisplayer = workshop()->displayer();
194     aDisplayer->enableUpdateViewer(true);
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> anObjects = 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 = anObjects.begin(); aIt != anObjects.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 #ifndef HAVE_SALOME
223     SessionPtr aMgr = ModelAPI_Session::get();
224     AppElements_MainWindow* aMainWindow = workshop()->mainWindow();
225     if (aMgr->isModified() != aMainWindow->isModifiedState())
226       aMainWindow->setModifiedState(aMgr->isModified());
227 #endif
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> anObjects = theMsg->objects();
236   std::set<ObjectPtr>::const_iterator aIt;
237   QStringList anInfo;
238   for (aIt = anObjects.begin(); aIt != anObjects.end(); ++aIt) {
239     anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
240   }
241   QString anInfoStr = anInfo.join(";\t");
242   qDebug(QString("onFeatureUpdatedMsg: %1, %2").arg(anObjects.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> anObjects = theMsg->objects();
271   std::set<ObjectPtr>::const_iterator aIt;
272
273 #ifdef DEBUG_FEATURE_REDISPLAY
274   QStringList anInfo;
275   for (aIt = anObjects.begin(); aIt != anObjects.end(); ++aIt) {
276     anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
277   }
278   QString anInfoStr = anInfo.join(";\t");
279   qDebug(QString("onFeatureRedisplayMsg: %1, %2").arg(anObjects.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   //std::list<ObjectPtr> aHiddenObjects;
288   for (aIt = anObjects.begin(); aIt != anObjects.end(); ++aIt) {
289     ObjectPtr aObj = (*aIt);
290
291     // Hide the object if it is invalid or concealed one
292     bool aHide = !aObj->data() || !aObj->data()->isValid() || 
293       aObj->isDisabled() || (!aObj->isDisplayed());
294     if (!aHide) { // check that this is not hidden result
295       ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
296       aHide = aRes && aRes->isConcealed();
297
298       // Hide the presentation with an empty shape. But isDisplayed state of the object should not
299       // be changed to the object becomes visible when the shape becomes not empty
300       if (!aHide && aRes.get())
301         aHide = !aRes->shape().get() || aRes->shape()->isNull();
302     }
303
304 #ifdef DEBUG_RESULT_COMPSOLID
305     ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
306     if (aRes.get()) {
307       ResultCompSolidPtr aCompSolidRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aRes);
308       if (aCompSolidRes.get()) {
309           qDebug(QString("COMPSOLID, numberOfSubs = %1").arg(aCompSolidRes->numberOfSubs()).toStdString().c_str());
310       }
311       if (ModelAPI_Tools::compSolidOwner(aRes))
312         qDebug("COMPSOLID sub-object");
313     }
314 #endif
315     #ifdef DEBUG_FEATURE_REDISPLAY
316       QString anObjInfo = ModuleBase_Tools::objectInfo((aObj));
317       FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
318       if (aFeature.get()) {
319         std::string aKind = aFeature->getKind();
320         if (aKind == DebugFeatureKind) {
321           qDebug(QString("visible=%1, hide=%2 : display= %2").arg(aDisplayer->isVisible(aObj))
322                                             .arg(aHide).arg(anObjInfo).toStdString().c_str());
323         }
324       }
325     #endif
326     if (aHide) {
327       //we should provide objects which are hidden in the viewer, e.g. sketch always should visualizes
328       // all sub-features, if some features are to be hidden, sould be proposed may be to removed #1223
329       //aHiddenObjects.push_back(aObj);
330       aRedisplayed = aDisplayer->erase(aObj, false) || aRedisplayed;
331       #ifdef DEBUG_FEATURE_REDISPLAY
332         // Redisplay the visible object or the object of the current operation
333         bool isVisibleObject = aDisplayer->isVisible(aObj);
334
335         QString anObjInfo = ModuleBase_Tools::objectInfo((aObj));
336         //qDebug(QString("visible=%1 : erase  = %2").arg(isVisibleObject).arg(anObjInfo).toStdString().c_str());
337       #endif
338     }
339     else {
340       // Redisplay the visible object or the object of the current operation
341       bool isVisibleObject = aDisplayer->isVisible(aObj);
342       #ifdef DEBUG_FEATURE_REDISPLAY
343         QString anObjInfo = ModuleBase_Tools::objectInfo((aObj));
344         //qDebug(QString("visible=%1 : display= %2").arg(isVisibleObject).arg(anObjInfo).toStdString().c_str());
345       #endif
346
347       if (isVisibleObject)  { // redisplay visible object
348         //displayObject(aObj);  // In order to update presentation
349         // in order to avoid the check whether the object can be redisplayed, the exact method
350         // of redisplay is called. This modification is made in order to have the line is updated
351         // by creation of a horizontal constraint on the line by preselection
352         if (ModelAPI_Tools::hasSubResults(std::dynamic_pointer_cast<ModelAPI_Result>(aObj))) {
353           aRedisplayed = aDisplayer->erase(aObj, false) || aRedisplayed;
354         }
355         else {
356           aRedisplayed = aDisplayer->redisplay(aObj, false) || aRedisplayed;
357           // Deactivate object of current operation from selection
358           aWorkshop->deactivateActiveObject(aObj, false);
359         }
360       } else { // display object if the current operation has it
361         if (displayObject(aObj, aFirstVisualizedBody)) {
362           aRedisplayed = true;
363           // Deactivate object of current operation from selection
364           aWorkshop->deactivateActiveObject(aObj, false);
365         }
366       }
367     }
368   }
369   // this processing should be moved in another place in order to do not cause problems in
370   // flush messages chain
371   //if (aHiddenObjects.size() > 0)
372   //  myWorkshop->module()->processHiddenObject(aHiddenObjects);
373
374   bool isCustomized = customizeCurrentObject(anObjects, aRedisplayed);
375   if (aRedisplayed || isCustomized) {
376     //VSV FitAll updated viewer by it self
377     if (aFirstVisualizedBody)
378       myWorkshop->viewer()->fitAll();
379     else 
380       aDisplayer->updateViewer();
381   }
382 }
383 //******************************************************
384 void XGUI_WorkshopListener::onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
385 {
386   std::set<ObjectPtr> anObjects = theMsg->objects();
387   std::set<ObjectPtr>::const_iterator aIt;
388 #ifdef DEBUG_FEATURE_CREATED
389   QStringList anInfo;
390   for (aIt = anObjects.begin(); aIt != anObjects.end(); ++aIt) {
391     anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
392   }
393   QString anInfoStr = anInfo.join(";\t");
394   qDebug(QString("onFeatureCreatedMsg: %1, %2").arg(anObjects.size()).arg(anInfoStr).toStdString().c_str());
395 #endif
396
397   bool aFirstVisualizedBody = false;
398
399   //bool aHasPart = false;
400   bool aDisplayed = false;
401   for (aIt = anObjects.begin(); aIt != anObjects.end(); ++aIt) {
402     ObjectPtr anObject = *aIt;
403
404 #ifdef DEBUG_RESULT_COMPSOLID
405     ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
406     if (aRes.get()) {
407       ResultCompSolidPtr aCompSolidRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aRes);
408       if (aCompSolidRes.get()) {
409           qDebug(QString("COMPSOLID, numberOfSubs = %1").arg(aCompSolidRes->numberOfSubs()).toStdString().c_str());
410       }
411       if (ModelAPI_Tools::compSolidOwner(aRes))
412         qDebug("COMPSOLID sub-object");
413     }
414 #endif
415     // the validity of the data should be checked here in order to avoid display of the objects,
416     // which were created, then deleted, but flush for the creation event happens after that
417     // we should not display disabled objects
418     bool aHide = !anObject->data()->isValid() || 
419                  anObject->isDisabled() ||
420                  !anObject->isDisplayed();
421     if (!aHide) { // check that this is not hidden result
422       ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
423       bool isConcealed = aRes && aRes->isConcealed();
424       aHide = aRes && aRes->isConcealed();
425       // Hide the presentation with an empty shape. But isDisplayed state of the object should not
426       // be changed to the object becomes visible when the shape becomes not empty
427       if (!aHide && aRes.get())
428         aHide = !aRes->shape().get() || aRes->shape()->isNull();
429     }
430     if (!aHide) {
431       // setDisplayed has to be called in order to synchronize internal state of the object 
432       // with list of displayed objects
433       if (myWorkshop->module()->canDisplayObject(anObject)) {
434         anObject->setDisplayed(true);
435         aDisplayed = displayObject(*aIt, aFirstVisualizedBody);
436       } else 
437         anObject->setDisplayed(false);
438     }
439   }
440
441   bool isCustomized = customizeCurrentObject(anObjects, aDisplayed);
442
443   //if (myObjectBrowser)
444   //  myObjectBrowser->processEvent(theMsg);
445   if (aDisplayed) {
446     //VSV FitAll updated viewer by it self
447     if (aFirstVisualizedBody)
448       myWorkshop->viewer()->fitAll();
449     else
450       workshop()->displayer()->updateViewer();
451   }
452   //if (aHasPart) { // TODO: Avoid activate last part on loading of document
453   //  activateLastPart();
454   //}
455 }
456
457 bool XGUI_WorkshopListener::event(QEvent * theEvent)
458 {
459   PostponeMessageQtEvent* aPostponedEv = dynamic_cast<PostponeMessageQtEvent*>(theEvent);
460   if (aPostponedEv) {
461     std::shared_ptr<Events_Message> aEventPtr = aPostponedEv->postponedMessage();
462     processEvent(aEventPtr);
463     return true;
464   }
465   return false;
466 }
467
468 void XGUI_WorkshopListener::addFeature(const std::shared_ptr<Config_FeatureMessage>& theMessage)
469 {
470   if (!theMessage) {
471 #ifdef _DEBUG
472     qDebug() << "XGUI_WorkshopListener::addFeature: NULL message.";
473 #endif
474     return;
475   }
476   ActionInfo aFeatureInfo;
477   aFeatureInfo.initFrom(theMessage);
478
479   XGUI_Workshop* aWorkshop = workshop();
480
481   QString aWchName = QString::fromStdString(theMessage->workbenchId());
482   QStringList aNestedFeatures =
483       QString::fromStdString(theMessage->nestedFeatures()).split(" ", QString::SkipEmptyParts);
484   QString aDocKind = QString::fromStdString(theMessage->documentKind());
485   QList<QAction*> aNestedActList;
486   bool isColumnButton = !aNestedFeatures.isEmpty();
487   if (isColumnButton) {
488     QString aNestedActions = QString::fromStdString(theMessage->actionsWhenNested());
489     XGUI_OperationMgr* anOperationMgr = aWorkshop->operationMgr();
490     XGUI_ActionsMgr* anActionsMgr = aWorkshop->actionsMgr();
491     if (aNestedActions.contains(FEATURE_WHEN_NESTED_ACCEPT)) {
492       QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL);
493       connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(commitAllOperations()));
494       aNestedActList << anAction;
495     }
496     if (aNestedActions.contains(FEATURE_WHEN_NESTED_ABORT)) {
497       QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll, NULL);
498       connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(abortAllOperations()));
499       aNestedActList << anAction;
500     }
501   }
502
503 #ifdef HAVE_SALOME
504   XGUI_SalomeConnector* aSalomeConnector = aWorkshop->salomeConnector();
505   QAction* aAction;
506   if (isColumnButton) {
507     aAction = aSalomeConnector->addFeatureOfNested(aWchName, aFeatureInfo, aNestedActList);
508   } else {
509     //Issue #650: in the SALOME mode the tooltip should be same as text
510     aFeatureInfo.toolTip = aFeatureInfo.text;
511     aAction = aSalomeConnector->addFeature(aWchName, aFeatureInfo);
512   }
513   aSalomeConnector->setNestedActions(aFeatureInfo.id, aNestedFeatures);
514   aSalomeConnector->setDocumentKind(aFeatureInfo.id, aDocKind);
515
516   aWorkshop->actionsMgr()->addCommand(aAction);
517   aWorkshop->module()->actionCreated(aAction);
518 #else 
519   //Find or create Workbench
520   AppElements_MainMenu* aMenuBar = aWorkshop->mainWindow()->menuObject();
521   AppElements_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
522   if (!aPage) {
523     aPage = aWorkshop->addWorkbench(aWchName);
524   }
525   //Find or create Group
526   QString aGroupName = QString::fromStdString(theMessage->groupId());
527   AppElements_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
528   if (!aGroup) {
529     aGroup = aPage->addGroup(aGroupName);
530   }
531   // Check if hotkey sequence is already defined:
532   XGUI_ActionsMgr* anActionsMgr = aWorkshop->actionsMgr();
533   QKeySequence aHotKey = anActionsMgr->registerShortcut(aFeatureInfo.shortcut);
534   if(aHotKey != aFeatureInfo.shortcut) {
535     aFeatureInfo.shortcut = aHotKey;
536   }
537   // Create feature...
538   AppElements_Command* aCommand = aGroup->addFeature(aFeatureInfo,
539                                                       aDocKind,
540                                                       aNestedFeatures);
541   // Enrich created button with accept/abort buttons if necessary
542   AppElements_Button* aButton = aCommand->button();
543   if (aButton->isColumnButton()) {
544     aButton->setAdditionalButtons(aNestedActList);
545   }
546   aWorkshop->actionsMgr()->addCommand(aCommand);
547   aWorkshop->module()->actionCreated(aCommand);
548 #endif
549 }
550
551
552 //**************************************************************
553 bool XGUI_WorkshopListener::displayObject(ObjectPtr theObj, bool& theFirstVisualizedBody)
554 {
555 #ifdef DEBUG_RESULT_COMPSOLID
556   ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObj);
557   if (aRes.get() && (ModelAPI_Tools::hasSubResults(aRes) || ModelAPI_Tools::compSolidOwner(aRes))) {
558     ResultCompSolidPtr aCompSolidRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aRes);
559     if (aCompSolidRes.get()) {
560       qDebug("COMPSOLID: displayObject");
561     }
562   }
563 #endif
564
565   bool aDisplayed = false;
566   XGUI_Workshop* aWorkshop = workshop();
567   // do not display the object if it has sub objects. They should be displayed separately.
568   if (!aWorkshop->module()->canDisplayObject(theObj) ||
569       ModelAPI_Tools::hasSubResults(std::dynamic_pointer_cast<ModelAPI_Result>(theObj)))
570     return aDisplayed;
571
572   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
573   ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObj);
574   if (aBody.get() != NULL) {
575     int aNb = aDisplayer->objectsCount();
576     aDisplayed = aDisplayer->display(theObj, false);
577     if (aNb == 0)
578       theFirstVisualizedBody = true;
579   } else {
580     aDisplayed = aDisplayer->display(theObj, false);
581     if (aDisplayed) {
582       ResultPtr aGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(theObj);
583       if (aGroup.get() != NULL) {
584         std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aGroup);
585           theFirstVisualizedBody = aShapePtr.get() != NULL;
586       }
587     }
588   }
589   return aDisplayed;
590 }
591
592 bool XGUI_WorkshopListener::customizeCurrentObject(const std::set<ObjectPtr>& theObjects,
593                                                    bool theForceRedisplay)
594 {
595   XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
596   FeaturePtr aCurrentFeature;
597   if (anOperationMgr->hasOperation()) {
598     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
599                                                       (anOperationMgr->currentOperation());
600     if (aFOperation) {
601       aCurrentFeature = aFOperation->feature();
602     }
603   }
604
605   bool aCustomized = false;
606   if (aCurrentFeature.get()) {
607     // the customize presentation should be redisplayed if force redislayed is true or
608     // if a list of message objects contains the operation feature for case when
609     // the feature is hidden, but arguments of the feature are modified
610     // e.g. extrusion is hidden(h=0) but sketch is chosen
611     if (theForceRedisplay || theObjects.find(aCurrentFeature) != theObjects.end()) {
612       aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature,
613                                            ModuleBase_IModule::CustomizeArguments, false);
614       aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature,
615                                            ModuleBase_IModule::CustomizeResults, false);
616       aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature,
617                                            ModuleBase_IModule::CustomizeHighlightedObjects, false);
618     }
619   }
620   return aCustomized;
621 }
622
623 XGUI_Workshop* XGUI_WorkshopListener::workshop() const
624 {
625   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
626   return aConnector->workshop();
627 }