Salome HOME
The same, as in onEnterViewPort(): validation of the operation should be pefromed...
[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         myWorkshop->module()->customizeObject(aCurrentFeature);
224     }
225   }
226   anOperationMgr->onValidateOperation();
227
228   //if (myObjectBrowser)
229   //  myObjectBrowser->processEvent(theMsg);
230 }
231
232 //******************************************************
233 void XGUI_WorkshopListener::onFeatureRedisplayMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
234 {
235   std::set<ObjectPtr> aObjects = theMsg->objects();
236   std::set<ObjectPtr>::const_iterator aIt;
237
238 #ifdef DEBUG_FEATURE_REDISPLAY
239   QStringList anInfo;
240   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
241     anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
242   }
243   QString anInfoStr = anInfo.join(";\t");
244   qDebug(QString("onFeatureRedisplayMsg: %1, %2").arg(aObjects.size()).arg(anInfoStr).toStdString().c_str());
245 #endif
246
247   XGUI_Workshop* aWorkshop = workshop();
248   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
249   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
250     ObjectPtr aObj = (*aIt);
251
252     // Hide the object if it is invalid or concealed one
253     bool aHide = !aObj->data() || !aObj->data()->isValid() || 
254       aObj->isDisabled() || (!aObj->isDisplayed());
255     if (!aHide) { // check that this is not hidden result
256       ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
257       aHide = aRes && aRes->isConcealed();
258     }
259 #ifdef DEBUG_RESULT_COMPSOLID
260     ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
261     if (aRes.get()) {
262       ResultCompSolidPtr aCompSolidRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aRes);
263       if (aCompSolidRes.get()) {
264           qDebug(QString("COMPSOLID, numberOfSubs = %1").arg(aCompSolidRes->numberOfSubs()).toStdString().c_str());
265       }
266       if (ModelAPI_Tools::compSolidOwner(aRes))
267         qDebug("COMPSOLID sub-object");
268     }
269 #endif
270     if (aHide) {
271       aDisplayer->erase(aObj, false);
272       #ifdef DEBUG_FEATURE_REDISPLAY
273         // Redisplay the visible object or the object of the current operation
274         bool isVisibleObject = aDisplayer->isVisible(aObj);
275
276         QString anObjInfo = ModuleBase_Tools::objectInfo((aObj));
277         //qDebug(QString("visible=%1 : erase  = %2").arg(isVisibleObject).arg(anObjInfo).toStdString().c_str());
278       #endif
279     }
280     else {
281       // Redisplay the visible object or the object of the current operation
282       bool isVisibleObject = aDisplayer->isVisible(aObj);
283       #ifdef DEBUG_FEATURE_REDISPLAY
284         QString anObjInfo = ModuleBase_Tools::objectInfo((aObj));
285         //qDebug(QString("visible=%1 : display= %2").arg(isVisibleObject).arg(anObjInfo).toStdString().c_str());
286         /*FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
287         if (aFeature.get()) {
288           std::string aKind = aFeature->getKind();
289           if (aKind == "SketchMultiRotation")
290             bool aValue = true;
291         }*/
292       #endif
293
294       if (isVisibleObject)  { // redisplay visible object
295         //displayObject(aObj);  // In order to update presentation
296         // in order to avoid the check whether the object can be redisplayed, the exact method
297         // of redisplay is called. This modification is made in order to have the line is updated
298         // by creation of a horizontal constraint on the line by preselection
299         if (ModelAPI_Tools::hasSubResults(std::dynamic_pointer_cast<ModelAPI_Result>(aObj))) {
300           aDisplayer->erase(aObj, false);
301         }
302         else {
303           aDisplayer->redisplay(aObj, false);
304           // Deactivate object of current operation from selection
305           aWorkshop->deactivateActiveObject(aObj, false);
306         }
307       } else { // display object if the current operation has it
308         if (displayObject(aObj)) {
309           // Deactivate object of current operation from selection
310           aWorkshop->deactivateActiveObject(aObj, false);
311         }
312       }
313     }
314   }
315   aDisplayer->updateViewer();
316 }
317 //******************************************************
318 void XGUI_WorkshopListener::onFeatureCreatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
319 {
320   std::set<ObjectPtr> aObjects = theMsg->objects();
321   std::set<ObjectPtr>::const_iterator aIt;
322 #ifdef DEBUG_FEATURE_CREATED
323   QStringList anInfo;
324   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
325     anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
326   }
327   QString anInfoStr = anInfo.join(";\t");
328   qDebug(QString("onFeatureCreatedMsg: %1, %2").arg(aObjects.size()).arg(anInfoStr).toStdString().c_str());
329 #endif
330
331   //bool aHasPart = false;
332   bool isDisplayed = false;
333   for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
334     ObjectPtr anObject = *aIt;
335
336 #ifdef DEBUG_RESULT_COMPSOLID
337     ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
338     if (aRes.get()) {
339       ResultCompSolidPtr aCompSolidRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aRes);
340       if (aCompSolidRes.get()) {
341           qDebug(QString("COMPSOLID, numberOfSubs = %1").arg(aCompSolidRes->numberOfSubs()).toStdString().c_str());
342       }
343       if (ModelAPI_Tools::compSolidOwner(aRes))
344         qDebug("COMPSOLID sub-object");
345     }
346 #endif
347     // the validity of the data should be checked here in order to avoid display of the objects,
348     // which were created, then deleted, but flush for the creation event happens after that
349     // we should not display disabled objects
350     bool aHide = !anObject->data()->isValid() || 
351                  anObject->isDisabled() ||
352                  !anObject->isDisplayed();
353     if (!aHide) {
354       // setDisplayed has to be called in order to synchronize internal state of the object 
355       // with list of displayed objects
356       if (myWorkshop->module()->canDisplayObject(anObject)) {
357         anObject->setDisplayed(true);
358         isDisplayed = displayObject(*aIt);
359       } else 
360         anObject->setDisplayed(false);
361     }
362   }
363   //if (myObjectBrowser)
364   //  myObjectBrowser->processEvent(theMsg);
365   if (isDisplayed)
366     workshop()->displayer()->updateViewer();
367   //if (aHasPart) { // TODO: Avoid activate last part on loading of document
368   //  activateLastPart();
369   //}
370 }
371
372 void XGUI_WorkshopListener::onNestedStateChanged(const std::string& theFeatureId, const bool theState)
373 {
374   XGUI_Workshop* aWorkshop = workshop();
375
376   //one button is used for all features, which can have nested actions, so it is obtained from
377   // the action manager
378   QAction* anAcceptAllAction = aWorkshop->actionsMgr()->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL);
379   if (aWorkshop->isSalomeMode()) {
380     XGUI_SalomeConnector* aSalomeConnector = aWorkshop->salomeConnector();
381     XGUI_ActionsMgr* anActionsMgr = aWorkshop->actionsMgr();
382     if (aSalomeConnector->isNestedFeature(anActionsMgr->action(theFeatureId.c_str())))
383       anAcceptAllAction->setEnabled(theState);
384   } else {
385     AppElements_MainMenu* aMenuBar = aWorkshop->mainWindow()->menuObject();
386     AppElements_Command* aCommand = aMenuBar->feature(theFeatureId.c_str());
387     if (aCommand && aCommand->button()->additionalButtonWidget())
388       anAcceptAllAction->setEnabled(theState);
389   }
390 }
391
392 bool XGUI_WorkshopListener::event(QEvent * theEvent)
393 {
394   PostponeMessageQtEvent* aPostponedEv = dynamic_cast<PostponeMessageQtEvent*>(theEvent);
395   if (aPostponedEv) {
396     std::shared_ptr<Events_Message> aEventPtr = aPostponedEv->postponedMessage();
397     processEvent(aEventPtr);
398     return true;
399   }
400   return false;
401 }
402
403 void XGUI_WorkshopListener::addFeature(const std::shared_ptr<Config_FeatureMessage>& theMessage)
404 {
405   if (!theMessage) {
406 #ifdef _DEBUG
407     qDebug() << "XGUI_WorkshopListener::addFeature: NULL message.";
408 #endif
409     return;
410   }
411   ActionInfo aFeatureInfo;
412   aFeatureInfo.initFrom(theMessage);
413
414   XGUI_Workshop* aWorkshop = workshop();
415
416   QString aWchName = QString::fromStdString(theMessage->workbenchId());
417   QStringList aNestedFeatures =
418       QString::fromStdString(theMessage->nestedFeatures()).split(" ", QString::SkipEmptyParts);
419   QString aDocKind = QString::fromStdString(theMessage->documentKind());
420   QList<QAction*> aNestedActList;
421   bool isColumnButton = !aNestedFeatures.isEmpty();
422   if (isColumnButton) {
423     QString aNestedActions = QString::fromStdString(theMessage->actionsWhenNested());
424     XGUI_OperationMgr* anOperationMgr = aWorkshop->operationMgr();
425     XGUI_ActionsMgr* anActionsMgr = aWorkshop->actionsMgr();
426     if (aNestedActions.contains(FEATURE_WHEN_NESTED_ACCEPT)) {
427       QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL);
428       connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(commitAllOperations()));
429       aNestedActList << anAction;
430     }
431     if (aNestedActions.contains(FEATURE_WHEN_NESTED_ABORT)) {
432       QAction* anAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::AbortAll, NULL);
433       connect(anAction, SIGNAL(triggered()), anOperationMgr, SLOT(abortAllOperations()));
434       aNestedActList << anAction;
435     }
436   }
437
438   if (aWorkshop->isSalomeMode()) {
439     XGUI_SalomeConnector* aSalomeConnector = aWorkshop->salomeConnector();
440     QAction* aAction;
441     if (isColumnButton) {
442       aAction = aSalomeConnector->addNestedFeature(aWchName, aFeatureInfo, aNestedActList);
443     } else {
444       //Issue #650: in the SALOME mode the tooltip should be same as text
445       aFeatureInfo.toolTip = aFeatureInfo.text;
446       aAction = aSalomeConnector->addFeature(aWchName, aFeatureInfo);
447     }
448     aSalomeConnector->setNestedActions(aFeatureInfo.id, aNestedFeatures);
449     aSalomeConnector->setDocumentKind(aFeatureInfo.id, aDocKind);
450
451     aWorkshop->actionsMgr()->addCommand(aAction);
452     aWorkshop->module()->actionCreated(aAction);
453   } else {
454     //Find or create Workbench
455     AppElements_MainMenu* aMenuBar = aWorkshop->mainWindow()->menuObject();
456     AppElements_Workbench* aPage = aMenuBar->findWorkbench(aWchName);
457     if (!aPage) {
458       aPage = aWorkshop->addWorkbench(aWchName);
459     }
460     //Find or create Group
461     QString aGroupName = QString::fromStdString(theMessage->groupId());
462     AppElements_MenuGroupPanel* aGroup = aPage->findGroup(aGroupName);
463     if (!aGroup) {
464       aGroup = aPage->addGroup(aGroupName);
465     }
466     // Check if hotkey sequence is already defined:
467     XGUI_ActionsMgr* anActionsMgr = aWorkshop->actionsMgr();
468     QKeySequence aHotKey = anActionsMgr->registerShortcut(aFeatureInfo.shortcut);
469     if(aHotKey != aFeatureInfo.shortcut) {
470       aFeatureInfo.shortcut = aHotKey;
471     }
472     // Create feature...
473     AppElements_Command* aCommand = aGroup->addFeature(aFeatureInfo,
474                                                        aDocKind,
475                                                        aNestedFeatures);
476     // Enrich created button with accept/abort buttons if necessary
477     AppElements_Button* aButton = aCommand->button();
478     if (aButton->isColumnButton()) {
479       aButton->setAdditionalButtons(aNestedActList);
480     }
481     aWorkshop->actionsMgr()->addCommand(aCommand);
482     aWorkshop->module()->actionCreated(aCommand);
483   }
484 }
485
486
487 //**************************************************************
488 bool XGUI_WorkshopListener::displayObject(ObjectPtr theObj)
489 {
490 #ifdef DEBUG_RESULT_COMPSOLID
491   ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObj);
492   if (aRes.get() && (ModelAPI_Tools::hasSubResults(aRes) || ModelAPI_Tools::compSolidOwner(aRes))) {
493     ResultCompSolidPtr aCompSolidRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(aRes);
494     if (aCompSolidRes.get()) {
495       qDebug("COMPSOLID: displayObject");
496     }
497   }
498 #endif
499
500   XGUI_Workshop* aWorkshop = workshop();
501   // do not display the object if it has sub objects. They should be displayed separately.
502   if (!aWorkshop->module()->canDisplayObject(theObj) ||
503       ModelAPI_Tools::hasSubResults(std::dynamic_pointer_cast<ModelAPI_Result>(theObj)))
504     return false;
505
506   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
507   ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theObj);
508   if (aBody.get() != NULL) {
509     int aNb = aDisplayer->objectsCount();
510     aDisplayer->display(theObj, false);
511     if (aNb == 0)
512       myWorkshop->viewer()->fitAll();
513   } else 
514     aDisplayer->display(theObj, false);
515
516   return true;
517 }
518
519 XGUI_Workshop* XGUI_WorkshopListener::workshop() const
520 {
521   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
522   return aConnector->workshop();
523 }