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