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