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