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