Salome HOME
Update of pictures by ABA
[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 #include <AppElements_Workbench.h>
15 #include <AppElements_Command.h>
16 #include <AppElements_MainMenu.h>
17 #include <AppElements_MainWindow.h>
18 #include <AppElements_MenuGroupPanel.h>
19 #include <AppElements_Button.h>
20
21 #include <ModuleBase_IModule.h>
22
23 #include <ModelAPI_Object.h>
24 #include <ModelAPI_Events.h>
25 #include <ModelAPI_Session.h>
26 #include <ModelAPI_Result.h>
27 #include <ModelAPI_Feature.h>
28 #include <ModelAPI_Data.h>
29 #include <ModelAPI_ResultBody.h>
30 #include <ModelAPI_ResultCompSolid.h>
31 #include <ModelAPI_Tools.h>
32
33 #include <Events_Loop.h>
34 #include <Events_Error.h>
35 #include <Events_LongOp.h>
36
37 #include <ModuleBase_IWorkshop.h>
38
39 #include <ModuleBase_Operation.h>
40 #include <ModuleBase_OperationDescription.h>
41 #include <ModuleBase_OperationFeature.h>
42 #include <ModuleBase_Tools.h>
43 #include <ModuleBase_IViewer.h>
44 #include <ModuleBase_FilterFactory.h>
45
46 #include <Config_FeatureMessage.h>
47 #include <Config_PointerMessage.h>
48 #include <Config_SelectionFilterMessage.h>
49 #include <Config_Keywords.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 XGUI_WorkshopListener::XGUI_WorkshopListener(ModuleBase_IWorkshop* theWorkshop)
67   : myWorkshop(theWorkshop),
68     myUpdatePrefs(false)
69 {
70   XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
71   connect(anOperationMgr, SIGNAL(nestedStateChanged(const std::string&, const bool)),
72           this, SLOT(onNestedStateChanged(const std::string&, const bool)));
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(Config_FeatureMessage::GUI_EVENT()));
87   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OPERATION_LAUNCHED));
88   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
89   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
90   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
91   aLoop->registerListener(this, Events_LongOp::eventID());
92   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_PLUGIN_LOADED));
93   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SELFILTER_LOADED));
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   //A message to start feature creation received.
113   if (theMessage->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
114     std::shared_ptr<Config_FeatureMessage> aFeatureMsg =
115        std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
116     if (!aFeatureMsg->isInternal()) {
117       addFeature(aFeatureMsg);
118     }
119   }
120   // Process creation of Part
121   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_CREATED)) {
122     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
123         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
124     onFeatureCreatedMsg(aUpdMsg);
125     if (myUpdatePrefs) {
126       XGUI_SalomeConnector* aSalomeConnector = workshop()->salomeConnector();
127       if (aSalomeConnector)
128         aSalomeConnector->createPreferences();
129       myUpdatePrefs = false;
130     }
131   }
132   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED)) {
133     myUpdatePrefs = true;
134   }
135   // Redisplay feature
136   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
137     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> aUpdMsg =
138         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
139     onFeatureRedisplayMsg(aUpdMsg);
140   }
141   //Update property panel on corresponding message. If there is no current operation (no
142   //property panel), or received message has different feature to the current - do nothing.
143   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_UPDATED)) {
144     std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
145         std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
146     onFeatureUpdatedMsg(anUpdateMsg);
147   } else if (theMessage->eventID() == Events_LongOp::eventID()) {
148     if (Events_LongOp::isPerformed()) {
149       QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
150     } else {
151       QApplication::restoreOverrideCursor();
152     }
153   }
154   //An operation passed by message. Start it, process and commit.
155   else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OPERATION_LAUNCHED)) {
156     std::shared_ptr<Config_PointerMessage> aPartSetMsg =
157         std::dynamic_pointer_cast<Config_PointerMessage>(theMessage);
158     //myPropertyPanel->cleanContent();
159     ModuleBase_Operation* anOperation = (ModuleBase_Operation*) aPartSetMsg->pointer();
160     XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
161
162     if (anOperationMgr->startOperation(anOperation)) {
163       ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
164       if (aFOperation)
165         workshop()->propertyPanel()->updateContentWidget(aFOperation->feature());
166       if (!anOperation->getDescription()->hasXmlRepresentation()) {
167         if (anOperation->commit())
168           workshop()->updateCommandStatus();
169       }
170     }
171   } 
172   else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_SELFILTER_LOADED)) {
173     std::shared_ptr<Config_SelectionFilterMessage> aMsg = 
174       std::dynamic_pointer_cast<Config_SelectionFilterMessage>(theMessage);
175     if (aMsg) {
176       ModuleBase_FilterFactory* aFactory = myWorkshop->selectionFilters();
177       if (!aMsg->attributeId().empty()) {
178         aFactory->assignFilter(aMsg->selectionFilterId(), aMsg->featureId(), aMsg->attributeId(),
179                                aMsg->parameters());
180       }
181     }
182   } else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)) {
183     // the viewer's update context will not happens until viewer updated is emitted
184       workshop()->displayer()->enableUpdateViewer(false);
185   } else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)) {
186     // the viewer's update context is unblocked, the viewer's update works
187     XGUI_Displayer* aDisplayer = workshop()->displayer();
188     aDisplayer->enableUpdateViewer(true);
189     aDisplayer->updateViewer();
190   } else {
191     //Show error dialog if error message received.
192     std::shared_ptr<Events_Error> anAppError = std::dynamic_pointer_cast<Events_Error>(theMessage);
193     if (anAppError) {
194       emit errorOccurred(QString::fromLatin1(anAppError->description()));
195     }
196     return;
197   }
198   if (!workshop()->isSalomeMode()) {
199     SessionPtr aMgr = ModelAPI_Session::get();
200     AppElements_MainWindow* aMainWindow = workshop()->mainWindow();
201     if (aMgr->isModified() != aMainWindow->isModifiedState())
202       aMainWindow->setModifiedState(aMgr->isModified());
203   }
204 }
205
206 //******************************************************
207 void XGUI_WorkshopListener::onFeatureUpdatedMsg(
208                                      const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
209 {
210 #ifdef DEBUG_FEATURE_UPDATED
211   std::set<ObjectPtr> aObjects = theMsg->objects();
212   std::set<ObjectPtr>::const_iterator aIt;
213   QStringList anInfo;
214   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
215     anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
216   }
217   QString anInfoStr = anInfo.join(";\t");
218   qDebug(QString("onFeatureUpdatedMsg: %1, %2").arg(aObjects.size()).arg(anInfoStr).toStdString().c_str());
219 #endif
220   std::set<ObjectPtr> aFeatures = theMsg->objects();
221   XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
222   if (anOperationMgr->hasOperation()) {
223     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
224                                                       (anOperationMgr->currentOperation());
225     if (aFOperation) {
226       FeaturePtr aCurrentFeature = aFOperation->feature();
227       std::set<ObjectPtr>::const_iterator aIt;
228       for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
229         ObjectPtr aNewFeature = (*aIt);
230         if (aNewFeature == aCurrentFeature) {
231           workshop()->propertyPanel()->updateContentWidget(aCurrentFeature);
232           break;
233         }
234       }
235     }
236   }
237   anOperationMgr->onValidateOperation();
238
239   //if (myObjectBrowser)
240   //  myObjectBrowser->processEvent(theMsg);
241 }
242
243 //******************************************************
244 void XGUI_WorkshopListener::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
245 {
246   std::set<ObjectPtr> aObjects = theMsg->objects();
247   std::set<ObjectPtr>::const_iterator aIt;
248
249 #ifdef DEBUG_FEATURE_REDISPLAY
250   QStringList anInfo;
251   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
252     anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
253   }
254   QString anInfoStr = anInfo.join(";\t");
255   qDebug(QString("onFeatureRedisplayMsg: %1, %2").arg(aObjects.size()).arg(anInfoStr).toStdString().c_str());
256 #endif
257
258   XGUI_Workshop* aWorkshop = workshop();
259   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
260   bool aRedisplayed = false;
261   for (aIt = aObjects.begin(); aIt != aObjects.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 #ifdef DEBUG_RESULT_COMPSOLID
272     ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
273     if (aRes.get()) {
274       ResultCompSolidPtr aCompSolidRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aRes);
275       if (aCompSolidRes.get()) {
276           qDebug(QString("COMPSOLID, numberOfSubs = %1").arg(aCompSolidRes->numberOfSubs()).toStdString().c_str());
277       }
278       if (ModelAPI_Tools::compSolidOwner(aRes))
279         qDebug("COMPSOLID sub-object");
280     }
281 #endif
282     if (aHide) {
283       aRedisplayed = aDisplayer->erase(aObj, false) || aRedisplayed;
284       #ifdef DEBUG_FEATURE_REDISPLAY
285         // Redisplay the visible object or the object of the current operation
286         bool isVisibleObject = aDisplayer->isVisible(aObj);
287
288         QString anObjInfo = ModuleBase_Tools::objectInfo((aObj));
289         //qDebug(QString("visible=%1 : erase  = %2").arg(isVisibleObject).arg(anObjInfo).toStdString().c_str());
290       #endif
291     }
292     else {
293       // Redisplay the visible object or the object of the current operation
294       bool isVisibleObject = aDisplayer->isVisible(aObj);
295       #ifdef DEBUG_FEATURE_REDISPLAY
296         QString anObjInfo = ModuleBase_Tools::objectInfo((aObj));
297         //qDebug(QString("visible=%1 : display= %2").arg(isVisibleObject).arg(anObjInfo).toStdString().c_str());
298         /*FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
299         if (aFeature.get()) {
300           std::string aKind = aFeature->getKind();
301           if (aKind == "SketchMultiRotation")
302             bool aValue = true;
303         }*/
304       #endif
305
306       if (isVisibleObject)  { // redisplay visible object
307         //displayObject(aObj);  // In order to update presentation
308         // in order to avoid the check whether the object can be redisplayed, the exact method
309         // of redisplay is called. This modification is made in order to have the line is updated
310         // by creation of a horizontal constraint on the line by preselection
311         if (ModelAPI_Tools::hasSubResults(std::dynamic_pointer_cast<ModelAPI_Result>(aObj))) {
312           aRedisplayed = aDisplayer->erase(aObj, false) || aRedisplayed;
313         }
314         else {
315           aRedisplayed = aDisplayer->redisplay(aObj, false) || aRedisplayed;
316           // Deactivate object of current operation from selection
317           aWorkshop->deactivateActiveObject(aObj, false);
318         }
319       } else { // display object if the current operation has it
320         if (displayObject(aObj)) {
321           aRedisplayed = true;
322           // Deactivate object of current operation from selection
323           aWorkshop->deactivateActiveObject(aObj, false);
324         }
325       }
326     }
327   }
328   if (aRedisplayed) {
329     customizeCurrentObject();
330     aDisplayer->updateViewer();
331   }
332 }
333 //******************************************************
334 void XGUI_WorkshopListener::onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
335 {
336   std::set<ObjectPtr> aObjects = theMsg->objects();
337   std::set<ObjectPtr>::const_iterator aIt;
338 #ifdef DEBUG_FEATURE_CREATED
339   QStringList anInfo;
340   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
341     anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
342   }
343   QString anInfoStr = anInfo.join(";\t");
344   qDebug(QString("onFeatureCreatedMsg: %1, %2").arg(aObjects.size()).arg(anInfoStr).toStdString().c_str());
345 #endif
346
347   //bool aHasPart = false;
348   bool aDisplayed = false;
349   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
350     ObjectPtr anObject = *aIt;
351
352 #ifdef DEBUG_RESULT_COMPSOLID
353     ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
354     if (aRes.get()) {
355       ResultCompSolidPtr aCompSolidRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aRes);
356       if (aCompSolidRes.get()) {
357           qDebug(QString("COMPSOLID, numberOfSubs = %1").arg(aCompSolidRes->numberOfSubs()).toStdString().c_str());
358       }
359       if (ModelAPI_Tools::compSolidOwner(aRes))
360         qDebug("COMPSOLID sub-object");
361     }
362 #endif
363     // the validity of the data should be checked here in order to avoid display of the objects,
364     // which were created, then deleted, but flush for the creation event happens after that
365     // we should not display disabled objects
366     bool aHide = !anObject->data()->isValid() || 
367                  anObject->isDisabled() ||
368                  !anObject->isDisplayed();
369     if (!aHide) {
370       // setDisplayed has to be called in order to synchronize internal state of the object 
371       // with list of displayed objects
372       if (myWorkshop->module()->canDisplayObject(anObject)) {
373         anObject->setDisplayed(true);
374         aDisplayed = displayObject(*aIt);
375       } else 
376         anObject->setDisplayed(false);
377     }
378   }
379
380   //if (myObjectBrowser)
381   //  myObjectBrowser->processEvent(theMsg);
382   if (aDisplayed) {
383     customizeCurrentObject();
384     workshop()->displayer()->updateViewer();
385   }
386   //if (aHasPart) { // TODO: Avoid activate last part on loading of document
387   //  activateLastPart();
388   //}
389 }
390
391 void XGUI_WorkshopListener::onNestedStateChanged(const std::string& theFeatureId, const bool theState)
392 {
393   XGUI_Workshop* aWorkshop = workshop();
394
395   //one button is used for all features, which can have nested actions, so it is obtained from
396   // the action manager
397   QAction* anAcceptAllAction = aWorkshop->actionsMgr()->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL);
398   bool aActionToBeUpdated = false;
399   if (aWorkshop->isSalomeMode()) {
400     XGUI_SalomeConnector* aSalomeConnector = aWorkshop->salomeConnector();
401     XGUI_ActionsMgr* anActionsMgr = aWorkshop->actionsMgr();
402     if (aSalomeConnector->isNestedFeature(anActionsMgr->action(theFeatureId.c_str())))
403       aActionToBeUpdated = true;
404   } else {
405     AppElements_MainMenu* aMenuBar = aWorkshop->mainWindow()->menuObject();
406     AppElements_Command* aCommand = aMenuBar->feature(theFeatureId.c_str());
407     if (aCommand && aCommand->button()->additionalButtonWidget())
408       aActionToBeUpdated = true;
409   }
410   if (aActionToBeUpdated) {
411     anAcceptAllAction->setEnabled(theState);
412   }
413 }
414
415 bool XGUI_WorkshopListener::event(QEvent * theEvent)
416 {
417   PostponeMessageQtEvent* aPostponedEv = dynamic_cast<PostponeMessageQtEvent*>(theEvent);
418   if (aPostponedEv) {
419     std::shared_ptr<Events_Message> aEventPtr = aPostponedEv->postponedMessage();
420     processEvent(aEventPtr);
421     return true;
422   }
423   return false;
424 }
425
426 void XGUI_WorkshopListener::addFeature(const std::shared_ptr<Config_FeatureMessage>& theMessage)
427 {
428   if (!theMessage) {
429 #ifdef _DEBUG
430     qDebug() << "XGUI_WorkshopListener::addFeature: NULL message.";
431 #endif
432     return;
433   }
434   ActionInfo aFeatureInfo;
435   aFeatureInfo.initFrom(theMessage);
436
437   XGUI_Workshop* aWorkshop = workshop();
438
439   QString aWchName = QString::fromStdString(theMessage->workbenchId());
440   QStringList aNestedFeatures =
441       QString::fromStdString(theMessage->nestedFeatures()).split(" ", QString::SkipEmptyParts);
442   QString aDocKind = QString::fromStdString(theMessage->documentKind());
443   QList<QAction*> aNestedActList;
444   bool isColumnButton = !aNestedFeatures.isEmpty();
445   if (isColumnButton) {
446     QString aNestedActions = QString::fromStdString(theMessage->actionsWhenNested());
447     XGUI_OperationMgr* anOperationMgr = aWorkshop->operationMgr();
448     XGUI_ActionsMgr* anActionsMgr = aWorkshop->actionsMgr();
449     if (aNestedActions.contains(FEATURE_WHEN_NESTED_ACCEPT)) {
450       QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL);
451       connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(commitAllOperations()));
452       aNestedActList << anAction;
453     }
454     if (aNestedActions.contains(FEATURE_WHEN_NESTED_ABORT)) {
455       QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll, NULL);
456       connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(abortAllOperations()));
457       aNestedActList << anAction;
458     }
459   }
460
461   if (aWorkshop->isSalomeMode()) {
462     XGUI_SalomeConnector* aSalomeConnector = aWorkshop->salomeConnector();
463     QAction* aAction;
464     if (isColumnButton) {
465       aAction = aSalomeConnector->addNestedFeature(aWchName, aFeatureInfo, aNestedActList);
466     } else {
467       //Issue #650: in the SALOME mode the tooltip should be same as text
468       aFeatureInfo.toolTip = aFeatureInfo.text;
469       aAction = aSalomeConnector->addFeature(aWchName, aFeatureInfo);
470     }
471     aSalomeConnector->setNestedActions(aFeatureInfo.id, aNestedFeatures);
472     aSalomeConnector->setDocumentKind(aFeatureInfo.id, aDocKind);
473
474     aWorkshop->actionsMgr()->addCommand(aAction);
475     aWorkshop->module()->actionCreated(aAction);
476   } else {
477     //Find or create Workbench
478     AppElements_MainMenu* aMenuBar = aWorkshop->mainWindow()->menuObject();
479     AppElements_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
480     if (!aPage) {
481       aPage = aWorkshop->addWorkbench(aWchName);
482     }
483     //Find or create Group
484     QString aGroupName = QString::fromStdString(theMessage->groupId());
485     AppElements_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
486     if (!aGroup) {
487       aGroup = aPage->addGroup(aGroupName);
488     }
489     // Check if hotkey sequence is already defined:
490     XGUI_ActionsMgr* anActionsMgr = aWorkshop->actionsMgr();
491     QKeySequence aHotKey = anActionsMgr->registerShortcut(aFeatureInfo.shortcut);
492     if(aHotKey != aFeatureInfo.shortcut) {
493       aFeatureInfo.shortcut = aHotKey;
494     }
495     // Create feature...
496     AppElements_Command* aCommand = aGroup->addFeature(aFeatureInfo,
497                                                        aDocKind,
498                                                        aNestedFeatures);
499     // Enrich created button with accept/abort buttons if necessary
500     AppElements_Button* aButton = aCommand->button();
501     if (aButton->isColumnButton()) {
502       aButton->setAdditionalButtons(aNestedActList);
503     }
504     aWorkshop->actionsMgr()->addCommand(aCommand);
505     aWorkshop->module()->actionCreated(aCommand);
506   }
507 }
508
509
510 //**************************************************************
511 bool XGUI_WorkshopListener::displayObject(ObjectPtr theObj)
512 {
513 #ifdef DEBUG_RESULT_COMPSOLID
514   ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObj);
515   if (aRes.get() && (ModelAPI_Tools::hasSubResults(aRes) || ModelAPI_Tools::compSolidOwner(aRes))) {
516     ResultCompSolidPtr aCompSolidRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aRes);
517     if (aCompSolidRes.get()) {
518       qDebug("COMPSOLID: displayObject");
519     }
520   }
521 #endif
522
523   bool aDisplayed = false;
524   XGUI_Workshop* aWorkshop = workshop();
525   // do not display the object if it has sub objects. They should be displayed separately.
526   if (!aWorkshop->module()->canDisplayObject(theObj) ||
527       ModelAPI_Tools::hasSubResults(std::dynamic_pointer_cast<ModelAPI_Result>(theObj)))
528     return aDisplayed;
529
530   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
531   ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObj);
532   if (aBody.get() != NULL) {
533     int aNb = aDisplayer->objectsCount();
534     aDisplayed = aDisplayer->display(theObj, false);
535     if (aNb == 0)
536       myWorkshop->viewer()->fitAll();
537   } else 
538     aDisplayed = aDisplayer->display(theObj, false);
539
540   return aDisplayed;
541 }
542
543 bool XGUI_WorkshopListener::customizeCurrentObject()
544 {
545   bool aCustomized = false;
546   XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
547   if (anOperationMgr->hasOperation()) {
548     ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
549                                                       (anOperationMgr->currentOperation());
550     if (aFOperation) {
551       FeaturePtr aCurrentFeature = aFOperation->feature();
552       if (aCurrentFeature.get())
553         aCustomized = myWorkshop->module()->customizeObject(aCurrentFeature, false);
554     }
555   }
556   return aCustomized;
557 }
558
559 XGUI_Workshop* XGUI_WorkshopListener::workshop() const
560 {
561   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
562   return aConnector->workshop();
563 }