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