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