Salome HOME
4ce3f489643e306f789eab89cd76cb7e5277761f
[modules/shaper.git] / src / XGUI / XGUI_FacesPanel.cpp
1 // Copyright (C) 2014-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "XGUI_FacesPanel.h"
21 #include "XGUI_ObjectsBrowser.h"
22 #include "XGUI_SelectionMgr.h"
23 #include "XGUI_Selection.h"
24 #include "XGUI_Tools.h"
25 #include "XGUI_Workshop.h"
26 #include "XGUI_Displayer.h"
27 #include "XGUI_ViewerProxy.h"
28
29 #include <ModuleBase_IModule.h>
30 #include <ModuleBase_ISelection.h>
31 #include <ModuleBase_IWorkshop.h>
32 #include <ModuleBase_IViewer.h>
33 #include <ModuleBase_ListView.h>
34 #include <ModuleBase_ResultPrs.h>
35 #include <ModuleBase_Tools.h>
36 #include <ModuleBase_ViewerPrs.h>
37 #include <ModuleBase_SelectionFilterType.h>
38
39 #include <Config_PropManager.h>
40 #include <Events_Loop.h>
41 #include <GeomAlgoAPI_CompoundBuilder.h>
42 #include <GeomAPI_Shape.h>
43
44 #include <ModelAPI_Events.h>
45 #include <ModelAPI_AttributeSelectionList.h>
46
47 #include <QAction>
48 #include <QCheckBox>
49 #include <QFocusEvent>
50 #include <QGridLayout>
51 #include <QListWidget>
52 #include <QMainWindow>
53 #include <QTimer>
54
55 static const int LayoutMargin = 3;
56
57 //********************************************************************
58 bool getGroup(ModuleBase_ViewerPrsPtr thePrs, ResultGroupPtr& theResGroup,
59   FeaturePtr& theGroupFeature)
60 {
61   ObjectPtr anObject = thePrs->object();
62   if (!anObject.get())
63     return false;
64
65   theResGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(anObject);
66   if (theResGroup.get()) {
67     theGroupFeature = ModelAPI_Feature::feature(theResGroup);
68   }
69   else {
70     theGroupFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
71     if (theGroupFeature.get())
72       theResGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(theGroupFeature->firstResult());
73   }
74   return theGroupFeature.get() && theResGroup.get();
75 }
76
77 //********************************************************************
78 void updateHiddenShapes(Handle(ModuleBase_ResultPrs) thePrs, const TopoDS_ListOfShape& theShapes)
79 {
80   TopoDS_ListOfShape aAlreadyHidden = thePrs->hiddenSubShapes();
81   TopoDS_ListOfShape::Iterator aShPIt(theShapes);
82   for (; aShPIt.More(); aShPIt.Next()) {
83     if (aAlreadyHidden.Contains(aShPIt.Value()))
84       aAlreadyHidden.Remove(aShPIt.Value());
85   }
86   thePrs->setSubShapeHidden(aAlreadyHidden);
87 }
88
89 //********************************************************************
90 XGUI_FacesPanel::XGUI_FacesPanel(QWidget* theParent, XGUI_Workshop* theWorkshop)
91   : QDockWidget(theParent), myIsActive(false), myWorkshop(theWorkshop)
92 {
93   setWindowTitle(tr("Hide Faces"));
94   QAction* aViewAct = toggleViewAction();
95   setStyleSheet("::title { position: relative; padding-left: 5px; text-align: left center }");
96
97   QWidget* aContent = new QWidget(this);
98   QGridLayout* aMainLayout = new QGridLayout(aContent);
99   aMainLayout->setContentsMargins(LayoutMargin, LayoutMargin, LayoutMargin, LayoutMargin);
100   setWidget(aContent);
101
102   myHiddenOrTransparent = new QCheckBox(tr("Transparent"), aContent);
103   connect(myHiddenOrTransparent, SIGNAL(toggled(bool)), SLOT(onTransparencyChanged()));
104
105   myListView = new ModuleBase_ListView(aContent, "", "Hidden/transparent faces in 3D view");
106   connect(myListView, SIGNAL(deleteActionClicked()), SLOT(onDeleteItem()));
107
108   aMainLayout->addWidget(myHiddenOrTransparent, 0, 0);
109   aMainLayout->addWidget(myListView->getControl(), 1, 0);
110
111   myListView->getControl()->setFocusPolicy(Qt::StrongFocus);
112   myListView->getControl()->viewport()->installEventFilter(this);
113
114   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
115   connect(aDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
116     SLOT(onObjectDisplay(ObjectPtr, AISObjectPtr)));
117 }
118
119 //********************************************************************
120 void XGUI_FacesPanel::reset(const bool isToFlushRedisplay)
121 {
122   if (myLastItemIndex == 0) // do nothing because there was no activity in the pane after reset
123     return;
124
125   std::map<ObjectPtr, TopoDS_ListOfShape> anObjectToShapes;
126   std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) > anObjectToPrs;
127   QMap<int, ModuleBase_ViewerPrsPtr >::const_iterator aIt;
128   for (aIt = myItems.cbegin(); aIt != myItems.cend(); aIt++) {
129     getObjectsMapFromPrs(aIt.value(), anObjectToShapes, anObjectToPrs);
130   }
131
132   std::set<ObjectPtr> aObjects;
133   TopoDS_ListOfShape anEmpty;
134   std::map<ObjectPtr, Handle(ModuleBase_ResultPrs)>::const_iterator aPrsIt;
135   for (aPrsIt = anObjectToPrs.cbegin(); aPrsIt != anObjectToPrs.cend(); aPrsIt++) {
136     aObjects.insert(aPrsIt->first);
137     aPrsIt->second->setSubShapeHidden(anEmpty);
138   }
139   std::set<ObjectPtr >::const_iterator aGrpIt;
140   for (aGrpIt = myHiddenGroups.cbegin(); aGrpIt != myHiddenGroups.cend(); aGrpIt++)
141     (*aGrpIt)->setDisplayed(true);
142   myHiddenGroups.clear();
143
144   if (redisplayObjects(aObjects))
145     flushRedisplay();
146
147   // clear internal containers
148   myListView->getControl()->clear();
149   myItems.clear();
150   updateProcessedObjects(myItems, myItemObjects);
151   myLastItemIndex = 0; // it should be after redisplay as flag used in customize
152   myHiddenObjects.clear();
153 }
154
155 //********************************************************************
156 bool XGUI_FacesPanel::isEmpty() const
157 {
158   return myItems.size() == 0;
159 }
160
161 //********************************************************************
162 void XGUI_FacesPanel::selectionModes(QIntList& theModes)
163 {
164   theModes.append(TopAbs_FACE);
165 }
166
167 //********************************************************************
168 void XGUI_FacesPanel::selectionFilters(SelectMgr_ListOfFilter& theSelectionFilters)
169 {
170   ModuleBase_IModule* aModule = myWorkshop->module();
171   QIntList aModuleSelectionFilters = myWorkshop->module()->selectionFilters();
172
173   // The global filter makes problem for groups selection when any operation is launched
174   // theSelectionFilters.Append(aModule->selectionFilter(SF_GlobalFilter));
175   theSelectionFilters.Append(aModule->selectionFilter(SF_FilterInfinite));
176   theSelectionFilters.Append(aModule->selectionFilter(SF_ResultGroupNameFilter));
177 }
178
179 //********************************************************************
180 bool XGUI_FacesPanel::eventFilter(QObject* theObject, QEvent *theEvent)
181 {
182   QWidget* aWidget = qobject_cast<QWidget*>(theObject);
183   if (theEvent->type() == QEvent::MouseButtonRelease)
184   {
185     if (myListView->getControl()->viewport() == aWidget)
186       setActivePanel(true);
187   }
188   // pass the event on to the parent class
189   return QObject::eventFilter(theObject, theEvent);
190 }
191
192 //********************************************************************
193 void XGUI_FacesPanel::setActivePanel(const bool theIsActive)
194 {
195   if (myIsActive == theIsActive)
196     return;
197
198   ModuleBase_Tools::setShadowEffect(myListView->getControl(), theIsActive);
199   myIsActive = theIsActive;
200
201   if (myIsActive) {
202     emit activated();
203     // selection should be cleared after emit of signal to do not process selection change
204     // event by the previous selector
205     // the selection is cleared by activating selection control
206     myWorkshop->selector()->clearSelection();
207   }
208   else
209     emit deactivated();
210 }
211
212 //********************************************************************
213 bool XGUI_FacesPanel::useTransparency() const
214 {
215   return myHiddenOrTransparent->isChecked();
216 }
217
218 //********************************************************************
219 double XGUI_FacesPanel::transparency() const
220 {
221   return useTransparency() ?
222     Config_PropManager::real("Visualization", "hidden_face_transparency") : 1;
223 }
224
225
226 //********************************************************************
227 void XGUI_FacesPanel::restoreObjects(const std::set<ObjectPtr>& theHiddenObjects)
228 {
229   std::set<int> anIndicesToBeRemoved;
230   for (QMap<int, ModuleBase_ViewerPrsPtr>::const_iterator anItemsIt = myItems.begin();
231     anItemsIt != myItems.end(); anItemsIt++)
232   {
233     ModuleBase_ViewerPrsPtr aPrs = anItemsIt.value();
234     ObjectPtr anObject = aPrs->object();
235     if (theHiddenObjects.find(anObject) == theHiddenObjects.end()) // not found
236       continue;
237     anIndicesToBeRemoved.insert(anItemsIt.key());
238   }
239
240   // remove from myItes container
241   removeItems(anIndicesToBeRemoved);
242   if (!anIndicesToBeRemoved.empty()) // means that myItems has been changed
243     updateProcessedObjects(myItems, myItemObjects);
244
245   // remove from container of hidden objects
246   for (std::set<ObjectPtr>::const_iterator aHiddenIt = theHiddenObjects.begin();
247     aHiddenIt != theHiddenObjects.end(); aHiddenIt++)
248   {
249     if (myHiddenObjects.find(*aHiddenIt) != myHiddenObjects.end()) /// found objects
250       myHiddenObjects.erase(*aHiddenIt);
251   }
252 }
253
254 //********************************************************************
255 bool XGUI_FacesPanel::processAction(ModuleBase_ActionType theActionType)
256 {
257   switch (theActionType) {
258     //case ActionEnter:
259     //  return processEnter();
260     case ActionEscape:
261       setActivePanel(false);
262       return true;
263     case ActionDelete:
264       return processDelete();
265     //case ActionUndo:
266     //case ActionRedo:
267     default:
268       return false;
269   }
270 }
271
272 //********************************************************************
273 void XGUI_FacesPanel::getObjectsMapFromResult(ResultGroupPtr theResGroup,
274   FeaturePtr theGroupFeature,
275   std::map<ObjectPtr, TopoDS_ListOfShape>& theObjectToShapes,
276   std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) >& theObjectToPrs)
277 {
278   XGUI_Displayer* aDisplayer = myWorkshop->displayer();
279   // Process a grouip result
280   AttributeSelectionListPtr aSelectionList = theGroupFeature->selectionList("group_list");
281   AISObjectPtr aPrs;
282   for (int i = 0; i < aSelectionList->size(); i++) {
283     AttributeSelectionPtr aSelection = aSelectionList->value(i);
284     ResultPtr aRes = aSelection->context();
285     aPrs = aDisplayer->getAISObject(aRes);
286     if (aPrs.get()) {
287       Handle(ModuleBase_ResultPrs) aResultPrs = Handle(ModuleBase_ResultPrs)::DownCast(
288         aPrs->impl<Handle(AIS_InteractiveObject)>());
289       if (!aResultPrs.IsNull()) {
290         GeomShapePtr aShape = aSelection->value();
291         if (theObjectToShapes.find(aRes) != theObjectToShapes.end())
292           theObjectToShapes.at(aRes).Append(aShape->impl<TopoDS_Shape>());
293         else {
294           TopoDS_ListOfShape aListOfShapes;
295           aListOfShapes.Append(aShape->impl<TopoDS_Shape>());
296           theObjectToShapes[aRes] = aListOfShapes;
297           theObjectToPrs[aRes] = aResultPrs;
298         }
299       }
300     }
301   }
302 }
303
304 //********************************************************************
305 void objectsMapFromPrs(ModuleBase_ViewerPrsPtr thePrs,
306   std::map<ObjectPtr, TopoDS_ListOfShape>& theObjectToShapes,
307   std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) >& theObjectToPrs)
308 {
309   ObjectPtr anObject = thePrs->object();
310   if (!anObject.get())
311     return;
312
313   // Process bodies
314   Handle(ModuleBase_ResultPrs) aResultPrs = Handle(ModuleBase_ResultPrs)::DownCast(
315     thePrs->interactive());
316   if (aResultPrs.IsNull())
317     return;
318
319   if (theObjectToShapes.find(anObject) != theObjectToShapes.end())
320     theObjectToShapes.at(anObject).Append(ModuleBase_Tools::getSelectedShape(thePrs));
321   else {
322     TopoDS_ListOfShape aListOfShapes;
323     aListOfShapes.Append(ModuleBase_Tools::getSelectedShape(thePrs));
324     theObjectToShapes[anObject] = aListOfShapes;
325     theObjectToPrs[anObject] = aResultPrs;
326   }
327 }
328
329 //********************************************************************
330 void XGUI_FacesPanel::getObjectsMapFromPrs(ModuleBase_ViewerPrsPtr thePrs,
331   std::map<ObjectPtr, TopoDS_ListOfShape>& theObjectToShapes,
332   std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) >& theObjectToPrs)
333 {
334   ResultGroupPtr aResGroup;
335   FeaturePtr aGroupFeature;
336   if (getGroup(thePrs, aResGroup, aGroupFeature))
337     getObjectsMapFromResult(aResGroup, aGroupFeature, theObjectToShapes, theObjectToPrs);
338   else
339     objectsMapFromPrs(thePrs, theObjectToShapes, theObjectToPrs);
340 }
341
342 //********************************************************************
343 void XGUI_FacesPanel::processSelection()
344 {
345   QList<ModuleBase_ViewerPrsPtr> aSelected =
346     myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Viewer);
347
348   if (aSelected.size() == 0)
349     return;
350
351   bool isModified = false;
352   static Events_ID aDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
353
354   std::map<ObjectPtr, TopoDS_ListOfShape> anObjectToShapes;
355   std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) > anObjectToPrs;
356   std::set<int> aToRemove;
357
358   for (int i = 0; i < aSelected.size(); i++) {
359     ModuleBase_ViewerPrsPtr aPrs = aSelected[i];
360     ObjectPtr anObject = aPrs->object();
361     if (!anObject.get())
362       continue;
363
364     ResultGroupPtr aResGroup;
365     FeaturePtr aGroupFeature;
366     if (getGroup(aPrs, aResGroup, aGroupFeature)) {
367       AttributeSelectionListPtr aSelectionListAttr =
368         aGroupFeature->data()->selectionList("group_list");
369       std::string aType = aSelectionListAttr->selectionType();
370       if (aType != "Faces")
371         continue;
372     }
373     else {
374       GeomShapePtr aShapePtr = aPrs->shape();
375       if (!aShapePtr.get() || !aShapePtr->isFace())
376         continue;
377     }
378
379     QString aItemName = aResGroup.get()?
380       aResGroup->data()->name().c_str() : XGUI_Tools::generateName(aPrs);
381     if (myListView->hasItem(aItemName))
382       continue;
383
384     if (aResGroup.get()) {
385       if (aResGroup->isDisplayed()) {
386         aResGroup->setDisplayed(false);
387         myHiddenGroups.insert(aResGroup);
388       }
389       getObjectsMapFromResult(aResGroup, aGroupFeature, anObjectToShapes, anObjectToPrs);
390     }
391     else
392       objectsMapFromPrs(aPrs, anObjectToShapes, anObjectToPrs);
393
394     // The code is dedicated to remove already selected items if they are selected twice
395     // It can happen in case of groups selection
396     QMap<int, ModuleBase_ViewerPrsPtr>::const_iterator aIt;
397     for (aIt = myItems.cbegin(); aIt != myItems.cend(); aIt++) {
398       ModuleBase_ViewerPrsPtr aPrs = aIt.value();
399       ObjectPtr aObject = aPrs->object();
400       ResultGroupPtr aResGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(aObject);
401       if (aResGroup.get())
402         continue;
403       if (anObjectToShapes.find(aObject) != anObjectToShapes.end()) {
404         TopoDS_ListOfShape aShapes = anObjectToShapes[aObject];
405         GeomShapePtr aShapePtr = aPrs->shape();
406         if (aShapes.Contains(aShapePtr->impl<TopoDS_Shape>())) {
407           aToRemove.insert(aIt.key());
408         }
409       }
410     }
411
412     myItems.insert(myLastItemIndex, aPrs);
413     myListView->addItem(aItemName, myLastItemIndex);
414     myLastItemIndex++;
415     isModified = true;
416   }
417
418   // Hide fully hidden shapes
419   std::map<ObjectPtr, TopoDS_ListOfShape>::const_iterator anIt;
420   for (anIt = anObjectToShapes.begin(); anIt != anObjectToShapes.end(); anIt++) {
421     ObjectPtr anObject = anIt->first;
422     if (!anObject.get() || anObjectToPrs.find(anObject) == anObjectToPrs.end())
423       continue;
424     Handle(ModuleBase_ResultPrs) aResultPrs = anObjectToPrs.at(anObject);
425
426     if (!aResultPrs->hasSubShapeVisible(anIt->second)) { // redisplay
427       // erase object because it is entirely hidden
428       anObject->setDisplayed(false);
429       myHiddenObjects.insert(anObject);
430     }
431     ModelAPI_EventCreator::get()->sendUpdated(anObject, aDispEvent);
432   }
433
434   // Process selected presentations
435   double aTransp = transparency();
436   std::map<ObjectPtr, Handle(ModuleBase_ResultPrs)>::iterator aPrsIt;
437   for (aPrsIt = anObjectToPrs.begin(); aPrsIt != anObjectToPrs.end(); aPrsIt++) {
438     ObjectPtr anObject = aPrsIt->first;
439     Handle(ModuleBase_ResultPrs) aPrs = aPrsIt->second;
440     TopoDS_ListOfShape aAlreadyHidden = aPrs->hiddenSubShapes();
441     TopoDS_ListOfShape aListOfShapes = anObjectToShapes[anObject];
442     TopoDS_ListOfShape::Iterator aShapesIt(aListOfShapes);
443     for (; aShapesIt.More(); aShapesIt.Next()) {
444       if (!aAlreadyHidden.Contains(aShapesIt.Value()))
445         aAlreadyHidden.Append(aShapesIt.Value());
446     }
447     aPrs->setSubShapeHidden(aAlreadyHidden);
448     aPrs->setHiddenSubShapeTransparency(aTransp);
449   }
450
451   // Remove duplicate items
452   removeItems(aToRemove);
453   if (isModified) {
454     updateProcessedObjects(myItems, myItemObjects);
455     flushRedisplay();
456   }
457 }
458
459 //********************************************************************
460 bool XGUI_FacesPanel::processDelete()
461 {
462   //appendFirstSelectionInHistory();
463   QModelIndexList anIndices = myListView->getControl()->selectionModel()->selectedIndexes();
464
465   std::set<int> aSelectedIds;
466   myListView->getSelectedIndices(aSelectedIds);
467   if (aSelectedIds.empty())
468     return false;
469
470   bool isModified = false;
471   std::set<ModuleBase_ViewerPrsPtr> aRestored;
472   std::set<int>::const_iterator anIt;
473   for (anIt = aSelectedIds.begin(); anIt != aSelectedIds.end(); anIt++) {
474     ModuleBase_ViewerPrsPtr aPrs = myItems[*anIt];
475     if (aRestored.find(aPrs) == aRestored.end()) {
476       aRestored.insert(aPrs);
477       myItems.remove(*anIt);
478       isModified = true;
479     }
480   }
481   std::map<ObjectPtr, TopoDS_ListOfShape> anObjectToShapes;
482   std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) > anObjectToPrs;
483
484   std::set<ModuleBase_ViewerPrsPtr>::const_iterator aIt;
485   for (aIt = aRestored.cbegin(); aIt != aRestored.cend(); aIt++) {
486     getObjectsMapFromPrs((*aIt), anObjectToShapes, anObjectToPrs);
487     ResultGroupPtr aResGroup;
488     FeaturePtr aGroupFeature;
489     if (getGroup((*aIt), aResGroup, aGroupFeature)) {
490       std::set<ObjectPtr >::iterator aGrpIt = myHiddenGroups.find(aResGroup);
491       if (aGrpIt != myHiddenGroups.end()) {
492         aResGroup->setDisplayed(true);
493         myHiddenGroups.erase(aGrpIt);
494       }
495     }
496   }
497
498   std::set<ObjectPtr> aRestoredObjects;
499   std::map<ObjectPtr, TopoDS_ListOfShape>::const_iterator aShapesIt;
500   for (aShapesIt = anObjectToShapes.begin(); aShapesIt != anObjectToShapes.end(); aShapesIt++) {
501     TopoDS_ListOfShape aShapes = aShapesIt->second;
502     aRestoredObjects.insert(aShapesIt->first);
503     Handle(ModuleBase_ResultPrs) aPrs = anObjectToPrs[aShapesIt->first];
504     TopoDS_ListOfShape aHiddenShapes = aPrs->hiddenSubShapes();
505     TopoDS_ListOfShape::Iterator aSubShapesIt(aShapes);
506     for (; aSubShapesIt.More(); aSubShapesIt.Next()) {
507       if (aHiddenShapes.Contains(aSubShapesIt.Value()))
508         aHiddenShapes.Remove(aSubShapesIt.Value());
509     }
510     aPrs->setSubShapeHidden(aHiddenShapes);
511   }
512   if (redisplayObjects(aRestoredObjects))
513     flushRedisplay();
514
515   myListView->removeSelectedItems();
516   return true;
517 }
518
519 //********************************************************************
520 bool XGUI_FacesPanel::redisplayObjects(
521   const std::set<ObjectPtr >& theObjects)
522 {
523   if (theObjects.empty())
524     return false;
525
526   bool isModified = false;
527   static Events_ID aDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
528   for (std::set<ObjectPtr>::const_iterator anIt = theObjects.begin(); anIt != theObjects.end();
529        anIt++)
530   {
531     ObjectPtr anObject = *anIt;
532     if (!anObject->isDisplayed())
533       continue;
534     ModelAPI_EventCreator::get()->sendUpdated(anObject, aDispEvent);
535     isModified = true;
536   }
537   return isModified;
538 }
539
540 //********************************************************************
541 void XGUI_FacesPanel::updateProcessedObjects(QMap<int, ModuleBase_ViewerPrsPtr> theItems,
542                                              std::set<ObjectPtr>& theObjects)
543 {
544   theObjects.clear();
545   for (QMap<int, ModuleBase_ViewerPrsPtr>::const_iterator anIt = theItems.begin();
546        anIt != theItems.end(); anIt++) {
547     ModuleBase_ViewerPrsPtr aPrs = anIt.value();
548     ResultGroupPtr aResGroup;
549     FeaturePtr aGroupFeature;
550     if (getGroup(aPrs, aResGroup, aGroupFeature)) {
551       AttributeSelectionListPtr aSelectionList = aGroupFeature->selectionList("group_list");
552       for (int i = 0; i < aSelectionList->size(); i++) {
553         AttributeSelectionPtr aSelection = aSelectionList->value(i);
554         ResultPtr aRes = aSelection->context();
555         if (theObjects.find(aRes) == theObjects.end())
556           theObjects.insert(aRes);
557       }
558     }
559     else {
560       if (theObjects.find(aPrs->object()) == theObjects.end())
561         theObjects.insert(aPrs->object());
562     }
563   }
564 }
565
566 //********************************************************************
567 void XGUI_FacesPanel::closeEvent(QCloseEvent* theEvent)
568 {
569   QDockWidget::closeEvent(theEvent);
570   emit closed();
571 }
572
573 //********************************************************************
574 void XGUI_FacesPanel::onDeleteItem()
575 {
576   processDelete();
577 }
578
579 //********************************************************************
580 void XGUI_FacesPanel::onTransparencyChanged()
581 {
582   std::map<ObjectPtr, TopoDS_ListOfShape> anObjectToShapes;
583   std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) > anObjectToPrs;
584   QMap<int, ModuleBase_ViewerPrsPtr >::const_iterator aIt;
585   for (aIt = myItems.cbegin(); aIt != myItems.cend(); aIt++) {
586     getObjectsMapFromPrs(aIt.value(), anObjectToShapes, anObjectToPrs);
587   }
588
589   double aTransp = Config_PropManager::real("Visualization", "hidden_face_transparency");
590   std::set<ObjectPtr> aObjects;
591   std::map<ObjectPtr, Handle(ModuleBase_ResultPrs)>::const_iterator aPrsIt;
592   for (aPrsIt = anObjectToPrs.cbegin(); aPrsIt != anObjectToPrs.cend(); aPrsIt++) {
593     aObjects.insert(aPrsIt->first);
594     aPrsIt->second->setHiddenSubShapeTransparency(useTransparency()? aTransp : 1);
595   }
596   if (redisplayObjects(aObjects))
597     flushRedisplay();
598 }
599
600 //********************************************************************
601 void XGUI_FacesPanel::onClosed()
602 {
603   setActivePanel(false);
604   reset(true);
605 }
606
607 //********************************************************************
608 void XGUI_FacesPanel::flushRedisplay() const
609 {
610   Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
611   // Necessary for update visibility icons in ObjectBrowser
612   XGUI_ObjectsBrowser* anObjectBrowser = myWorkshop->objectBrowser();
613   if (anObjectBrowser)
614     anObjectBrowser->updateAllIndexes();
615   myWorkshop->viewer()->update();
616 }
617
618
619 //********************************************************************
620 void XGUI_FacesPanel::onObjectDisplay(ObjectPtr theObject, AISObjectPtr theAIS)
621 {
622   bool aContains = false;
623   QMap<int, ModuleBase_ViewerPrsPtr>::iterator aIt;
624   for (aIt = myItems.begin(); aIt != myItems.end(); aIt++) {
625     ModuleBase_ViewerPrsPtr aPrs = aIt.value();
626     if (aPrs->object() == theObject) {
627       aContains = true;
628       break;
629     }
630   }
631   if (aContains) {
632     ResultGroupPtr aResGroup;
633     FeaturePtr aGroupFeature;
634     std::map<ObjectPtr, TopoDS_ListOfShape> aObjectToShapes;
635     std::map<ObjectPtr, Handle(ModuleBase_ResultPrs)> aObjectToPrs;
636     std::set<ObjectPtr> aObjects;
637     std::set<int> aIdsToRem;
638
639     TopoDS_ListOfShape aHideShapes;
640     std::map<ObjectPtr, TopoDS_ListOfShape>::const_iterator aSIt;
641     for (aIt = myItems.begin(); aIt != myItems.end(); aIt++) {
642       ModuleBase_ViewerPrsPtr aPrs = aIt.value();
643       if (getGroup(aPrs, aResGroup, aGroupFeature)) {
644         getObjectsMapFromResult(aResGroup, aGroupFeature, aObjectToShapes, aObjectToPrs);
645         if (aResGroup == theObject) {
646           // If group is displayed it means that it has to be deleted from the Faces list and all
647           // corresponded faces have been restored
648           for (aSIt = aObjectToShapes.begin(); aSIt != aObjectToShapes.end(); aSIt++) {
649             TopoDS_ListOfShape aShapes = aSIt->second;
650             Handle(ModuleBase_ResultPrs) aPrs = aObjectToPrs[aSIt->first];
651             TopoDS_ListOfShape aAlreadyHidden = aPrs->hiddenSubShapes();
652             TopoDS_ListOfShape::Iterator aShPIt(aShapes);
653             for (; aShPIt.More(); aShPIt.Next()) {
654               if (aAlreadyHidden.Contains(aShPIt.Value()))
655                 aAlreadyHidden.Remove(aShPIt.Value());
656             }
657             aPrs->setSubShapeHidden(aAlreadyHidden);
658             aObjects.insert(aSIt->first);
659           }
660           aIdsToRem.insert(aIt.key());
661         }
662         else {
663           std::map<ObjectPtr, Handle(ModuleBase_ResultPrs)>::iterator aPIt =
664             aObjectToPrs.find(theObject);
665           if (aPIt != aObjectToPrs.end()) {
666             ObjectPtr aObj = aPIt->first;
667             if (aObj == theObject) {
668               Handle(ModuleBase_ResultPrs) aPrs = aPIt->second;
669               TopoDS_ListOfShape aShapes = aObjectToShapes[aObj];
670               aHideShapes.Append(aShapes);
671               aObjects.insert(aObj);
672             }
673           }
674         }
675       }
676       else {
677         if (aPrs->object() == theObject) {
678           TopoDS_Shape aShape = aPrs->shape()->impl<TopoDS_Shape>();
679           if (!aShape.IsNull())
680             aHideShapes.Append(aShape);
681           aPrs->setInteractive(theAIS->impl<Handle(AIS_InteractiveObject)>());
682         }
683       }
684     }
685     double aTransp = transparency();
686     if (aHideShapes.Size() > 0) {
687       Handle(ModuleBase_ResultPrs) aResultPrs = Handle(ModuleBase_ResultPrs)::DownCast(
688         theAIS->impl<Handle(AIS_InteractiveObject)>());
689       if (!aResultPrs.IsNull()) {
690         aResultPrs->setSubShapeHidden(aHideShapes);
691         aResultPrs->setHiddenSubShapeTransparency(aTransp);
692         aObjects.insert(theObject);
693       }
694     }
695     removeItems(aIdsToRem);
696     myWorkshop->selector()->clearSelection();
697     if (redisplayObjects(aObjects))
698       QTimer::singleShot(50, this, SLOT(flushRedisplay()));
699   }
700 }
701
702 void XGUI_FacesPanel::removeItems(std::set<int> theIds)
703 {
704   if (theIds.empty())
705     return;
706   myListView->removeItems(theIds);
707   std::set<int>::const_iterator aRIt;
708   for (aRIt = theIds.begin(); aRIt != theIds.end(); aRIt++)
709     myItems.remove(*aRIt);
710 }