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