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