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