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