Salome HOME
Issue #1412: Activate selection mode FACES for sketcher only in operations with selector
[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_MainWindow.h>
16 #endif
17
18 #include <ModuleBase_IModule.h>
19
20 #include <ModelAPI_Object.h>
21 #include <ModelAPI_Events.h>
22 #include <ModelAPI_Session.h>
23 #include <ModelAPI_Result.h>
24 #include <ModelAPI_Feature.h>
25 #include <ModelAPI_Data.h>
26 #include <ModelAPI_ResultBody.h>
27 #include <ModelAPI_ResultGroup.h>
28 #include <ModelAPI_ResultCompSolid.h>
29 #include <ModelAPI_Tools.h>
30
31 #include <Events_Loop.h>
32 #include <Events_Error.h>
33 #include <Events_LongOp.h>
34
35 #include <ModuleBase_IWorkshop.h>
36
37 #include <ModuleBase_Operation.h>
38 #include <ModuleBase_OperationDescription.h>
39 #include <ModuleBase_OperationFeature.h>
40 #include <ModuleBase_Tools.h>
41 #include <ModuleBase_IViewer.h>
42 #include <ModuleBase_FilterFactory.h>
43
44 #include <Config_FeatureMessage.h>
45 #include <Config_PointerMessage.h>
46 #include <Config_SelectionFilterMessage.h>
47 #include <Config_Keywords.h>
48
49 #include <QApplication>
50 #include <QMainWindow>
51 #include <QThread>
52 #include <QAction>
53
54 #ifdef _DEBUG
55 #include <QDebug>
56 #include <iostream>
57 #endif
58
59 //#define DEBUG_FEATURE_CREATED
60 //#define DEBUG_FEATURE_REDISPLAY
61 //#define DEBUG_FEATURE_UPDATED
62 //#define DEBUG_RESULT_COMPSOLID
63
64 #ifdef DEBUG_FEATURE_REDISPLAY
65 const std::string DebugFeatureKind = "";//"Extrusion";
66 #endif
67
68 XGUI_WorkshopListener::XGUI_WorkshopListener(ModuleBase_IWorkshop* theWorkshop)
69   : myWorkshop(theWorkshop),
70     myUpdatePrefs(false)
71 {
72   XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
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(EVENT_OPERATION_LAUNCHED));
87   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
88   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
89   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
90   aLoop->registerListener(this, Events_LongOp::eventID());
91   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_PLUGIN_LOADED));
92   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SELFILTER_LOADED));
93
94   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED));
95   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED));
96   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION));
97 }
98
99 //******************************************************
100 void XGUI_WorkshopListener::processEvent(const std::shared_ptr<Events_Message>& theMessage)
101 {
102   if (QApplication::instance()->thread() != QThread::currentThread()) {
103     #ifdef _DEBUG
104     std::cout << "XGUI_Workshop::processEvent: " << "Working in another thread." << std::endl;
105     #endif
106     SessionPtr aMgr = ModelAPI_Session::get();
107     PostponeMessageQtEvent* aPostponeEvent = new PostponeMessageQtEvent(theMessage);
108     QApplication::postEvent(this, aPostponeEvent);
109     return;
110   }
111
112   // Process creation of Part
113   if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
114     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
115         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
116     onFeatureCreatedMsg(aUpdMsg);
117     if (myUpdatePrefs) {
118       XGUI_SalomeConnector* aSalomeConnector = workshop()->salomeConnector();
119       if (aSalomeConnector)
120         aSalomeConnector->createPreferences();
121       myUpdatePrefs = false;
122     }
123   }
124   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED)) {
125     myUpdatePrefs = true;
126   }
127   // Redisplay feature
128   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
129     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
130         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
131     onFeatureRedisplayMsg(aUpdMsg);
132   } else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION)) {
133     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
134         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
135     onFeatureEmptyPresentationMsg(aUpdMsg);
136   }
137   //Update property panel on corresponding message. If there is no current operation (no
138   //property panel), or received message has different feature to the current - do nothing.
139   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
140     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
141         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
142     onFeatureUpdatedMsg(anUpdateMsg);
143   } else if (theMessage->eventID() == Events_LongOp::eventID()) {
144     if (Events_LongOp::isPerformed()) {
145       QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
146     } else {
147       QApplication::restoreOverrideCursor();
148     }
149   }
150   //An operation passed by message. Start it, process and commit.
151   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OPERATION_LAUNCHED)) {
152     std::shared_ptr<Config_PointerMessage> aPartSetMsg =
153         std::dynamic_pointer_cast<Config_PointerMessage>(theMessage);
154     //myPropertyPanel->cleanContent();
155     ModuleBase_Operation* anOperation = (ModuleBase_Operation*) aPartSetMsg->pointer();
156     XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
157
158     if (anOperationMgr->startOperation(anOperation)) {
159       ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
160       if (aFOperation) {
161         workshop()->propertyPanel()->updateContentWidget(aFOperation->feature());
162         workshop()->propertyPanel()->createContentPanel(aFOperation->feature());
163       }
164       if (!anOperation->getDescription()->hasXmlRepresentation()) {
165         if (anOperation->commit())
166           workshop()->updateCommandStatus();
167       }
168     }
169   } 
170   else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_SELFILTER_LOADED)) {
171     std::shared_ptr<Config_SelectionFilterMessage> aMsg = 
172       std::dynamic_pointer_cast<Config_SelectionFilterMessage>(theMessage);
173     if (aMsg) {
174       ModuleBase_FilterFactory* aFactory = myWorkshop->selectionFilters();
175       if (!aMsg->attributeId().empty()) {
176         aFactory->assignFilter(aMsg->selectionFilterId(), aMsg->featureId(), aMsg->attributeId(),
177                                aMsg->parameters());
178       }
179     }
180   } else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)) {
181     // the viewer's update context will not happens until viewer updated is emitted
182       workshop()->displayer()->enableUpdateViewer(false);
183   } else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)) {
184     // the viewer's update context is unblocked, the viewer's update works
185     XGUI_Displayer* aDisplayer = workshop()->displayer();
186     aDisplayer->enableUpdateViewer(true);
187   } else {
188     //Show error dialog if error message received.
189     std::shared_ptr<Events_Error> anAppError = std::dynamic_pointer_cast<Events_Error>(theMessage);
190     if (anAppError) {
191       emit errorOccurred(QString::fromLatin1(anAppError->description()));
192     }
193     return;
194   }
195 #ifndef HAVE_SALOME
196     SessionPtr aMgr = ModelAPI_Session::get();
197     AppElements_MainWindow* aMainWindow = workshop()->mainWindow();
198     if (aMgr->isModified() != aMainWindow->isModifiedState())
199       aMainWindow->setModifiedState(aMgr->isModified());
200 #endif
201 }
202
203 //******************************************************
204 void XGUI_WorkshopListener::onFeatureUpdatedMsg(
205                                      const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
206 {
207 #ifdef DEBUG_FEATURE_UPDATED
208   std::set<ObjectPtr> anObjects = theMsg->objects();
209   std::set<ObjectPtr>::const_iterator aIt;
210   QStringList anInfo;
211   for (aIt = anObjects.begin(); aIt != anObjects.end(); ++aIt) {
212     anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
213   }
214   QString anInfoStr = anInfo.join(";\t");
215   qDebug(QString("onFeatureUpdatedMsg: %1, %2").arg(anObjects.size()).arg(anInfoStr).toStdString().c_str());
216 #endif
217   std::set<ObjectPtr> aFeatures = theMsg->objects();
218   XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
219   if (anOperationMgr->hasOperation()) {
220     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
221                                                       (anOperationMgr->currentOperation());
222     if (aFOperation) {
223       FeaturePtr aCurrentFeature = aFOperation->feature();
224       std::set<ObjectPtr>::const_iterator aIt;
225       for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
226         ObjectPtr aNewFeature = (*aIt);
227         if (aNewFeature == aCurrentFeature) {
228           workshop()->propertyPanel()->updateContentWidget(aCurrentFeature);
229           break;
230         }
231       }
232     }
233   }
234   //anOperationMgr->onValidateOperation();
235
236   //if (myObjectBrowser)
237   //  myObjectBrowser->processEvent(theMsg);
238 }
239
240 //******************************************************
241 void XGUI_WorkshopListener::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
242 {
243   std::set<ObjectPtr> anObjects = theMsg->objects();
244   std::set<ObjectPtr>::const_iterator aIt;
245
246 #ifdef DEBUG_FEATURE_REDISPLAY
247   QStringList anInfo;
248   for (aIt = anObjects.begin(); aIt != anObjects.end(); ++aIt) {
249     anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
250   }
251   QString anInfoStr = anInfo.join(";\t");
252   qDebug(QString("onFeatureRedisplayMsg: %1, %2").arg(anObjects.size()).arg(anInfoStr).toStdString().c_str());
253 #endif
254
255   XGUI_Workshop* aWorkshop = workshop();
256   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
257   bool aFirstVisualizedBody = false;
258
259   bool aRedisplayed = false;
260   //std::list<ObjectPtr> aHiddenObjects;
261   for (aIt = anObjects.begin(); aIt != anObjects.end(); ++aIt) {
262     ObjectPtr aObj = (*aIt);
263
264     // Hide the object if it is invalid or concealed one
265     bool aHide = !aObj->data() || !aObj->data()->isValid() || 
266       aObj->isDisabled() || (!aObj->isDisplayed());
267     if (!aHide) { // check that this is not hidden result
268       ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
269       aHide = aRes && aRes->isConcealed();
270
271       // Hide the presentation with an empty shape. But isDisplayed state of the object should not
272       // be changed to the object becomes visible when the shape becomes not empty
273       if (!aHide && aRes.get())
274         aHide = !aRes->shape().get() || aRes->shape()->isNull();
275     }
276
277 #ifdef DEBUG_RESULT_COMPSOLID
278     ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
279     if (aRes.get()) {
280       ResultCompSolidPtr aCompSolidRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aRes);
281       if (aCompSolidRes.get()) {
282           qDebug(QString("COMPSOLID, numberOfSubs = %1").arg(aCompSolidRes->numberOfSubs()).toStdString().c_str());
283       }
284       if (ModelAPI_Tools::compSolidOwner(aRes))
285         qDebug("COMPSOLID sub-object");
286     }
287 #endif
288     #ifdef DEBUG_FEATURE_REDISPLAY
289       QString anObjInfo = ModuleBase_Tools::objectInfo((aObj));
290       FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
291       if (aFeature.get()) {
292         std::string aKind = aFeature->getKind();
293         if (aKind == DebugFeatureKind || DebugFeatureKind.empty()) {
294           qDebug(QString("visible=%1, hide=%2 : display= %2").arg(aDisplayer->isVisible(aObj))
295                                             .arg(aHide).arg(anObjInfo).toStdString().c_str());
296         }
297       }
298     #endif
299     if (aHide) {
300       //we should provide objects which are hidden in the viewer, e.g. sketch always should visualizes
301       // all sub-features, if some features are to be hidden, sould be proposed may be to removed #1223
302       //aHiddenObjects.push_back(aObj);
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       #endif
319
320       if (isVisibleObject)  { // redisplay visible object
321         //displayObject(aObj);  // In order to update presentation
322         // in order to avoid the check whether the object can be redisplayed, the exact method
323         // of redisplay is called. This modification is made in order to have the line is updated
324         // by creation of a horizontal constraint on the line by preselection
325         if (ModelAPI_Tools::hasSubResults(std::dynamic_pointer_cast<ModelAPI_Result>(aObj))) {
326           aRedisplayed = aDisplayer->erase(aObj, false) || aRedisplayed;
327         }
328         else {
329           aRedisplayed = aDisplayer->redisplay(aObj, false) || aRedisplayed;
330           // Deactivate object of current operation from selection
331           aWorkshop->deactivateActiveObject(aObj, false);
332         }
333       } else { // display object if the current operation has it
334         if (displayObject(aObj, aFirstVisualizedBody)) {
335           aRedisplayed = true;
336           // Deactivate object of current operation from selection
337           aWorkshop->deactivateActiveObject(aObj, false);
338         }
339       }
340     }
341   }
342   // this processing should be moved in another place in order to do not cause problems in
343   // flush messages chain
344   //if (aHiddenObjects.size() > 0)
345   //  myWorkshop->module()->processHiddenObject(aHiddenObjects);
346
347   bool isCustomized = customizeCurrentObject(anObjects, aRedisplayed);
348   if (aRedisplayed || isCustomized) {
349     Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION));
350
351     //VSV FitAll updated viewer by it self
352     if (aFirstVisualizedBody)
353       myWorkshop->viewer()->fitAll();
354     else 
355       aDisplayer->updateViewer();
356   }
357 }
358
359 //******************************************************
360 void XGUI_WorkshopListener::onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
361 {
362   std::set<ObjectPtr> anObjects = theMsg->objects();
363   std::set<ObjectPtr>::const_iterator aIt;
364 #ifdef DEBUG_FEATURE_CREATED
365   QStringList anInfo;
366   for (aIt = anObjects.begin(); aIt != anObjects.end(); ++aIt) {
367     anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
368   }
369   QString anInfoStr = anInfo.join(";\t");
370   qDebug(QString("onFeatureCreatedMsg: %1, %2").arg(anObjects.size()).arg(anInfoStr).toStdString().c_str());
371 #endif
372
373   bool aFirstVisualizedBody = false;
374
375   //bool aHasPart = false;
376   bool aDisplayed = false;
377   for (aIt = anObjects.begin(); aIt != anObjects.end(); ++aIt) {
378     ObjectPtr anObject = *aIt;
379
380 #ifdef DEBUG_RESULT_COMPSOLID
381     ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
382     if (aRes.get()) {
383       ResultCompSolidPtr aCompSolidRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aRes);
384       if (aCompSolidRes.get()) {
385           qDebug(QString("COMPSOLID, numberOfSubs = %1").arg(aCompSolidRes->numberOfSubs()).toStdString().c_str());
386       }
387       if (ModelAPI_Tools::compSolidOwner(aRes))
388         qDebug("COMPSOLID sub-object");
389     }
390 #endif
391     // the validity of the data should be checked here in order to avoid display of the objects,
392     // which were created, then deleted, but flush for the creation event happens after that
393     // we should not display disabled objects
394     bool aHide = !anObject->data()->isValid() || 
395                  anObject->isDisabled() ||
396                  !anObject->isDisplayed();
397     if (!aHide) { // check that this is not hidden result
398       ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
399       bool isConcealed = aRes && aRes->isConcealed();
400       aHide = aRes && aRes->isConcealed();
401       // Hide the presentation with an empty shape. But isDisplayed state of the object should not
402       // be changed to the object becomes visible when the shape becomes not empty
403       if (!aHide && aRes.get())
404         aHide = !aRes->shape().get() || aRes->shape()->isNull();
405     }
406     if (!aHide) {
407       // setDisplayed has to be called in order to synchronize internal state of the object 
408       // with list of displayed objects
409       if (myWorkshop->module()->canDisplayObject(anObject)) {
410         anObject->setDisplayed(true);
411         aDisplayed = displayObject(*aIt, aFirstVisualizedBody);
412       } else 
413         anObject->setDisplayed(false);
414     }
415   }
416
417   bool isCustomized = customizeCurrentObject(anObjects, aDisplayed);
418
419   //if (myObjectBrowser)
420   //  myObjectBrowser->processEvent(theMsg);
421   if (aDisplayed) {
422     Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_EMPTY_AIS_PRESENTATION));
423     //VSV FitAll updated viewer by it self
424     if (aFirstVisualizedBody)
425       myWorkshop->viewer()->fitAll();
426     else
427       workshop()->displayer()->updateViewer();
428   }
429   //if (aHasPart) { // TODO: Avoid activate last part on loading of document
430   //  activateLastPart();
431   //}
432 }
433
434 //******************************************************
435 void XGUI_WorkshopListener::onFeatureEmptyPresentationMsg(
436                                       const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
437 {
438   std::set<ObjectPtr> anObjects = theMsg->objects();
439   std::set<ObjectPtr>::const_iterator aIt;
440 #ifdef DEBUG_FEATURE_CREATED
441   QStringList anInfo;
442   for (aIt = anObjects.begin(); aIt != anObjects.end(); ++aIt) {
443     anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
444   }
445   QString anInfoStr = anInfo.join(";\t");
446   qDebug(QString("onFeatureEmptyPresentationMsg: %1, %2").arg(anObjects.size()).arg(anInfoStr).toStdString().c_str());
447 #endif
448
449   XGUI_Workshop* aWorkshop = workshop();
450   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
451
452   bool aRedisplayed = false;
453   for (aIt = anObjects.begin(); aIt != anObjects.end(); ++aIt) {
454     ObjectPtr anObject = *aIt;
455     aRedisplayed = aDisplayer->erase(anObject, false) || aRedisplayed;
456   }
457
458   if (aRedisplayed)
459     aDisplayer->updateViewer();
460 }
461
462 bool XGUI_WorkshopListener::event(QEvent * theEvent)
463 {
464   PostponeMessageQtEvent* aPostponedEv = dynamic_cast<PostponeMessageQtEvent*>(theEvent);
465   if (aPostponedEv) {
466     std::shared_ptr<Events_Message> aEventPtr = aPostponedEv->postponedMessage();
467     processEvent(aEventPtr);
468     return true;
469   }
470   return false;
471 }
472
473 //**************************************************************
474 bool XGUI_WorkshopListener::displayObject(ObjectPtr theObj, bool& theFirstVisualizedBody)
475 {
476 #ifdef DEBUG_RESULT_COMPSOLID
477   ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObj);
478   if (aRes.get() && (ModelAPI_Tools::hasSubResults(aRes) || ModelAPI_Tools::compSolidOwner(aRes))) {
479     ResultCompSolidPtr aCompSolidRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aRes);
480     if (aCompSolidRes.get()) {
481       qDebug("COMPSOLID: displayObject");
482     }
483   }
484 #endif
485
486   bool aDisplayed = false;
487   XGUI_Workshop* aWorkshop = workshop();
488   // do not display the object if it has sub objects. They should be displayed separately.
489   if (!aWorkshop->module()->canDisplayObject(theObj) ||
490       ModelAPI_Tools::hasSubResults(std::dynamic_pointer_cast<ModelAPI_Result>(theObj)))
491     return aDisplayed;
492
493   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
494   int aNb = aDisplayer->objectsCount();
495   aDisplayed = aDisplayer->display(theObj, false);
496
497   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObj);
498   if (aNb == 0 && aResult.get()) {
499     std::string aResultGroupName = aResult->groupName();
500     if (aResultGroupName == ModelAPI_ResultBody::group() ||
501         aResultGroupName == ModelAPI_ResultGroup::group()) {
502       std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(aResult);
503       theFirstVisualizedBody = aShapePtr.get() != NULL;
504     }
505   }
506   return aDisplayed;
507 }
508
509 bool XGUI_WorkshopListener::customizeCurrentObject(const std::set<ObjectPtr>& theObjects,
510                                                    bool theForceRedisplay)
511 {
512   XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
513   FeaturePtr aCurrentFeature;
514   if (anOperationMgr->hasOperation()) {
515     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
516                                                       (anOperationMgr->currentOperation());
517     if (aFOperation) {
518       aCurrentFeature = aFOperation->feature();
519     }
520   }
521
522   bool aCustomized = false;
523   if (aCurrentFeature.get()) {
524     // the customize presentation should be redisplayed if force redislayed is true or
525     // if a list of message objects contains the operation feature for case when
526     // the feature is hidden, but arguments of the feature are modified
527     // e.g. extrusion is hidden(h=0) but sketch is chosen
528     if (theForceRedisplay || theObjects.find(aCurrentFeature) != theObjects.end()) {
529       aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature,
530                                  ModuleBase_IModule::CustomizeArguments, false) || aCustomized;
531       aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature,
532                                    ModuleBase_IModule::CustomizeResults, false) || aCustomized;
533       aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature,
534                         ModuleBase_IModule::CustomizeHighlightedObjects, false) || aCustomized;
535     }
536   }
537   return aCustomized;
538 }
539
540 XGUI_Workshop* XGUI_WorkshopListener::workshop() const
541 {
542   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
543   return aConnector->workshop();
544 }