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