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