1 // Copyright (C) 2014-2021 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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"
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>
39 #include <Config_PropManager.h>
40 #include <Events_Loop.h>
41 #include <GeomAlgoAPI_CompoundBuilder.h>
42 #include <GeomAPI_Shape.h>
44 #include <ModelAPI_Events.h>
45 #include <ModelAPI_AttributeSelectionList.h>
47 #include <ModuleBase_Operation.h>
48 #include <ModuleBase_OperationFeature.h>
49 #include <XGUI_OperationMgr.h>
53 #include <QFocusEvent>
54 #include <QGridLayout>
55 #include <QListWidget>
56 #include <QMainWindow>
60 #pragma warning(disable : 4189) // for skipping MAYBE_UNUSED on Win
63 static const int LayoutMargin = 3;
65 //********************************************************************
66 bool getGroup(ModuleBase_ViewerPrsPtr thePrs, ResultGroupPtr& theResGroup,
67 FeaturePtr& theGroupFeature)
69 ObjectPtr anObject = thePrs->object();
73 theResGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(anObject);
74 if (theResGroup.get()) {
75 theGroupFeature = ModelAPI_Feature::feature(theResGroup);
78 theGroupFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
79 if (theGroupFeature.get())
80 theResGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(theGroupFeature->firstResult());
82 return theGroupFeature.get() && theResGroup.get();
85 //********************************************************************
86 void updateHiddenShapes(Handle(ModuleBase_ResultPrs) thePrs, const TopoDS_ListOfShape& theShapes)
88 TopoDS_ListOfShape aAlreadyHidden = thePrs->hiddenSubShapes();
89 TopoDS_ListOfShape::Iterator aShPIt(theShapes);
90 for (; aShPIt.More(); aShPIt.Next()) {
91 if (aAlreadyHidden.Contains(aShPIt.Value()))
92 aAlreadyHidden.Remove(aShPIt.Value());
94 thePrs->setSubShapeHidden(aAlreadyHidden);
97 //********************************************************************
98 XGUI_FacesPanel::XGUI_FacesPanel(QWidget* theParent, XGUI_Workshop* theWorkshop)
99 : QDockWidget(theParent), myWorkshop(theWorkshop), myIsActive(false), myLastItemIndex(0)
101 setWindowTitle(tr("Hide Faces"));
102 setObjectName("Hide Faces");
104 MAYBE_UNUSED QAction* aViewAct = toggleViewAction();
105 setStyleSheet("::title { position: relative; padding-left: 5px; text-align: left center }");
107 QWidget* aContent = new QWidget(this);
108 QGridLayout* aMainLayout = new QGridLayout(aContent);
109 aMainLayout->setContentsMargins(LayoutMargin, LayoutMargin, LayoutMargin, LayoutMargin);
112 myHiddenOrTransparent = new QCheckBox(tr("Transparent"), aContent);
113 connect(myHiddenOrTransparent, SIGNAL(toggled(bool)), SLOT(onTransparencyChanged()));
115 myListView = new ModuleBase_ListView(aContent, "", "Hidden/transparent faces in 3D view");
116 connect(myListView, SIGNAL(deleteActionClicked()), SLOT(onDeleteItem()));
118 aMainLayout->addWidget(myHiddenOrTransparent, 0, 0);
119 aMainLayout->addWidget(myListView->getControl(), 1, 0);
121 myListView->getControl()->setFocusPolicy(Qt::StrongFocus);
122 myListView->getControl()->viewport()->installEventFilter(this);
124 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
125 connect(aDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
126 SLOT(onObjectDisplay(ObjectPtr, AISObjectPtr)));
129 //********************************************************************
130 void XGUI_FacesPanel::reset(const bool isToFlushRedisplay)
132 if (myLastItemIndex == 0) // do nothing because there was no activity in the pane after reset
135 std::map<ObjectPtr, TopoDS_ListOfShape> anObjectToShapes;
136 std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) > anObjectToPrs;
137 QMap<int, ModuleBase_ViewerPrsPtr >::const_iterator aIt;
138 for (aIt = myItems.cbegin(); aIt != myItems.cend(); aIt++) {
139 getObjectsMapFromPrs(aIt.value(), anObjectToShapes, anObjectToPrs);
142 std::set<ObjectPtr> aObjects;
143 TopoDS_ListOfShape anEmpty;
144 std::map<ObjectPtr, Handle(ModuleBase_ResultPrs)>::const_iterator aPrsIt;
145 for (aPrsIt = anObjectToPrs.cbegin(); aPrsIt != anObjectToPrs.cend(); aPrsIt++) {
146 aObjects.insert(aPrsIt->first);
147 aPrsIt->second->setSubShapeHidden(anEmpty);
149 std::set<ObjectPtr >::const_iterator aGrpIt;
150 for (aGrpIt = myHiddenGroups.cbegin(); aGrpIt != myHiddenGroups.cend(); aGrpIt++)
151 (*aGrpIt)->setDisplayed(true);
152 myHiddenGroups.clear();
154 if (redisplayObjects(aObjects))
157 // clear internal containers
158 myListView->getControl()->clear();
160 updateProcessedObjects(myItems, myItemObjects);
161 myLastItemIndex = 0; // it should be after redisplay as flag used in customize
162 myHiddenObjects.clear();
165 //********************************************************************
166 bool XGUI_FacesPanel::isEmpty() const
168 return myItems.size() == 0;
171 //********************************************************************
172 void XGUI_FacesPanel::selectionModes(QIntList& theModes)
174 theModes.append(TopAbs_FACE);
177 //********************************************************************
178 void XGUI_FacesPanel::selectionFilters(SelectMgr_ListOfFilter& theSelectionFilters)
180 ModuleBase_IModule* aModule = myWorkshop->module();
181 QIntList aModuleSelectionFilters = myWorkshop->module()->selectionFilters();
183 // The global filter makes problem for groups selection when any operation is launched
184 // theSelectionFilters.Append(aModule->selectionFilter(SF_GlobalFilter));
185 theSelectionFilters.Append(aModule->selectionFilter(SF_FilterInfinite));
186 theSelectionFilters.Append(aModule->selectionFilter(SF_ResultGroupNameFilter));
189 //********************************************************************
190 bool XGUI_FacesPanel::eventFilter(QObject* theObject, QEvent *theEvent)
192 QWidget* aWidget = qobject_cast<QWidget*>(theObject);
193 if (theEvent->type() == QEvent::MouseButtonRelease)
195 if (myListView->getControl()->viewport() == aWidget)
196 setActivePanel(true);
198 // pass the event on to the parent class
199 return QObject::eventFilter(theObject, theEvent);
202 //********************************************************************
203 void XGUI_FacesPanel::setActivePanel(const bool theIsActive)
205 if (myIsActive == theIsActive)
208 ModuleBase_Tools::setShadowEffect(myListView->getControl(), theIsActive);
209 myIsActive = theIsActive;
213 // selection should be cleared after emit of signal to do not process selection change
214 // event by the previous selector
215 // the selection is cleared by activating selection control
216 myWorkshop->selector()->clearSelection();
224 //********************************************************************
225 bool XGUI_FacesPanel::useTransparency() const
227 return myHiddenOrTransparent->isChecked();
230 //********************************************************************
231 double XGUI_FacesPanel::transparency() const
233 return useTransparency() ?
234 Config_PropManager::real("Visualization", "hidden_face_transparency") : 1;
238 //********************************************************************
239 void XGUI_FacesPanel::restoreObjects(const std::set<ObjectPtr>& theHiddenObjects)
241 std::set<int> anIndicesToBeRemoved;
242 for (QMap<int, ModuleBase_ViewerPrsPtr>::const_iterator anItemsIt = myItems.begin();
243 anItemsIt != myItems.end(); anItemsIt++)
245 ModuleBase_ViewerPrsPtr aPrs = anItemsIt.value();
246 ObjectPtr anObject = aPrs->object();
247 if (theHiddenObjects.find(anObject) == theHiddenObjects.end()) // not found
249 anIndicesToBeRemoved.insert(anItemsIt.key());
252 // remove from myItes container
253 removeItems(anIndicesToBeRemoved);
254 if (!anIndicesToBeRemoved.empty()) // means that myItems has been changed
255 updateProcessedObjects(myItems, myItemObjects);
257 // remove from container of hidden objects
258 for (std::set<ObjectPtr>::const_iterator aHiddenIt = theHiddenObjects.begin();
259 aHiddenIt != theHiddenObjects.end(); aHiddenIt++)
261 if (myHiddenObjects.find(*aHiddenIt) != myHiddenObjects.end()) /// found objects
262 myHiddenObjects.erase(*aHiddenIt);
266 //********************************************************************
267 bool XGUI_FacesPanel::processAction(ModuleBase_ActionType theActionType)
269 switch (theActionType) {
271 // return processEnter();
273 setActivePanel(false);
276 return processDelete();
284 //********************************************************************
285 void XGUI_FacesPanel::getObjectsMapFromResult(ResultGroupPtr theResGroup,
286 FeaturePtr theGroupFeature,
287 std::map<ObjectPtr, TopoDS_ListOfShape>& theObjectToShapes,
288 std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) >& theObjectToPrs)
290 XGUI_Displayer* aDisplayer = myWorkshop->displayer();
291 // Process a grouip result
292 AttributeSelectionListPtr aSelectionList = theGroupFeature->selectionList("group_list");
294 for (int i = 0; i < aSelectionList->size(); i++) {
295 AttributeSelectionPtr aSelection = aSelectionList->value(i);
296 ResultPtr aRes = aSelection->context();
297 aPrs = aDisplayer->getAISObject(aRes);
299 Handle(ModuleBase_ResultPrs) aResultPrs = Handle(ModuleBase_ResultPrs)::DownCast(
300 aPrs->impl<Handle(AIS_InteractiveObject)>());
301 if (!aResultPrs.IsNull()) {
302 GeomShapePtr aShape = aSelection->value();
303 if (theObjectToShapes.find(aRes) != theObjectToShapes.end())
304 theObjectToShapes.at(aRes).Append(aShape->impl<TopoDS_Shape>());
306 TopoDS_ListOfShape aListOfShapes;
307 aListOfShapes.Append(aShape->impl<TopoDS_Shape>());
308 theObjectToShapes[aRes] = aListOfShapes;
309 theObjectToPrs[aRes] = aResultPrs;
316 //********************************************************************
317 void objectsMapFromPrs(ModuleBase_ViewerPrsPtr thePrs,
318 std::map<ObjectPtr, TopoDS_ListOfShape>& theObjectToShapes,
319 std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) >& theObjectToPrs)
321 ObjectPtr anObject = thePrs->object();
326 Handle(ModuleBase_ResultPrs) aResultPrs = Handle(ModuleBase_ResultPrs)::DownCast(
327 thePrs->interactive());
328 if (aResultPrs.IsNull())
331 if (theObjectToShapes.find(anObject) != theObjectToShapes.end())
332 theObjectToShapes.at(anObject).Append(ModuleBase_Tools::getSelectedShape(thePrs));
334 TopoDS_ListOfShape aListOfShapes;
335 aListOfShapes.Append(ModuleBase_Tools::getSelectedShape(thePrs));
336 theObjectToShapes[anObject] = aListOfShapes;
337 theObjectToPrs[anObject] = aResultPrs;
341 //********************************************************************
342 void XGUI_FacesPanel::getObjectsMapFromPrs(ModuleBase_ViewerPrsPtr thePrs,
343 std::map<ObjectPtr, TopoDS_ListOfShape>& theObjectToShapes,
344 std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) >& theObjectToPrs)
346 ResultGroupPtr aResGroup;
347 FeaturePtr aGroupFeature;
348 if (getGroup(thePrs, aResGroup, aGroupFeature))
349 getObjectsMapFromResult(aResGroup, aGroupFeature, theObjectToShapes, theObjectToPrs);
351 objectsMapFromPrs(thePrs, theObjectToShapes, theObjectToPrs);
354 //********************************************************************
355 void XGUI_FacesPanel::processSelection()
357 QList<ModuleBase_ViewerPrsPtr> aSelected =
358 myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Viewer);
360 if (aSelected.size() == 0)
363 bool isModified = false;
364 static Events_ID aDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
366 std::map<ObjectPtr, TopoDS_ListOfShape> anObjectToShapes;
367 std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) > anObjectToPrs;
368 std::set<int> aToRemove;
370 for (int i = 0; i < aSelected.size(); i++) {
371 ModuleBase_ViewerPrsPtr aPrs = aSelected[i];
372 ObjectPtr anObject = aPrs->object();
376 ResultGroupPtr aResGroup;
377 FeaturePtr aGroupFeature;
378 if (getGroup(aPrs, aResGroup, aGroupFeature)) {
379 AttributeSelectionListPtr aSelectionListAttr =
380 aGroupFeature->data()->selectionList("group_list");
381 std::string aType = aSelectionListAttr->selectionType();
382 if (aType != "Faces")
386 GeomShapePtr aShapePtr = aPrs->shape();
387 if (!aShapePtr.get() || !aShapePtr->isFace())
391 QString aItemName = aResGroup.get()?
392 QString::fromStdWString(aResGroup->data()->name()) : XGUI_Tools::generateName(aPrs);
393 if (myListView->hasItem(aItemName))
396 if (aResGroup.get()) {
397 if (aResGroup->isDisplayed()) {
398 aResGroup->setDisplayed(false);
399 myHiddenGroups.insert(aResGroup);
401 getObjectsMapFromResult(aResGroup, aGroupFeature, anObjectToShapes, anObjectToPrs);
404 objectsMapFromPrs(aPrs, anObjectToShapes, anObjectToPrs);
406 // The code is dedicated to remove already selected items if they are selected twice
407 // It can happen in case of groups selection
408 QMap<int, ModuleBase_ViewerPrsPtr>::const_iterator aIt;
409 for (aIt = myItems.cbegin(); aIt != myItems.cend(); aIt++) {
410 ModuleBase_ViewerPrsPtr aCurPrs = aIt.value();
411 ObjectPtr aObject = aCurPrs->object();
412 ResultGroupPtr aCurResGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(aObject);
413 if (aCurResGroup.get())
415 if (anObjectToShapes.find(aObject) != anObjectToShapes.end()) {
416 TopoDS_ListOfShape aShapes = anObjectToShapes[aObject];
417 GeomShapePtr aShapePtr = aCurPrs->shape();
418 if (aShapes.Contains(aShapePtr->impl<TopoDS_Shape>())) {
419 aToRemove.insert(aIt.key());
424 myItems.insert(myLastItemIndex, aPrs);
425 myListView->addItem(aItemName, myLastItemIndex);
427 myUndoList.push_back(myLastItemIndex);
432 // Hide fully hidden shapes
433 std::map<ObjectPtr, TopoDS_ListOfShape>::const_iterator anIt;
434 for (anIt = anObjectToShapes.begin(); anIt != anObjectToShapes.end(); anIt++) {
435 ObjectPtr anObject = anIt->first;
436 if (!anObject.get() || anObjectToPrs.find(anObject) == anObjectToPrs.end())
438 Handle(ModuleBase_ResultPrs) aResultPrs = anObjectToPrs.at(anObject);
440 if (!aResultPrs->hasSubShapeVisible(anIt->second)) { // redisplay
441 // erase object because it is entirely hidden
442 anObject->setDisplayed(false);
443 myHiddenObjects.insert(anObject);
445 ModelAPI_EventCreator::get()->sendUpdated(anObject, aDispEvent);
448 // Process selected presentations
449 double aTransp = transparency();
450 std::map<ObjectPtr, Handle(ModuleBase_ResultPrs)>::iterator aPrsIt;
451 for (aPrsIt = anObjectToPrs.begin(); aPrsIt != anObjectToPrs.end(); aPrsIt++) {
452 ObjectPtr anObject = aPrsIt->first;
453 Handle(ModuleBase_ResultPrs) aPrs = aPrsIt->second;
454 TopoDS_ListOfShape aAlreadyHidden = aPrs->hiddenSubShapes();
455 TopoDS_ListOfShape aListOfShapes = anObjectToShapes[anObject];
456 TopoDS_ListOfShape::Iterator aShapesIt(aListOfShapes);
457 for (; aShapesIt.More(); aShapesIt.Next()) {
458 if (!aAlreadyHidden.Contains(aShapesIt.Value()))
459 aAlreadyHidden.Append(aShapesIt.Value());
461 aPrs->setSubShapeHidden(aAlreadyHidden);
462 aPrs->setHiddenSubShapeTransparency(aTransp);
465 // Remove duplicate items
466 removeItems(aToRemove);
468 updateProcessedObjects(myItems, myItemObjects);
473 //********************************************************************
474 bool XGUI_FacesPanel::processDelete()
476 //appendFirstSelectionInHistory();
477 //QModelIndexList anIndices = myListView->getControl()->selectionModel()->selectedIndexes();
479 std::set<int> aSelectedIds;
480 myListView->getSelectedIndices(aSelectedIds);
481 if (aSelectedIds.empty())
484 std::set<ModuleBase_ViewerPrsPtr> aRestored;
485 std::set<int>::const_iterator anIt;
486 for (anIt = aSelectedIds.begin(); anIt != aSelectedIds.end(); anIt++) {
487 ModuleBase_ViewerPrsPtr aPrs = myItems[*anIt];
488 if (aRestored.find(aPrs) == aRestored.end()) {
489 aRestored.insert(aPrs);
490 myItems.remove(*anIt);
493 std::map<ObjectPtr, TopoDS_ListOfShape> anObjectToShapes;
494 std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) > anObjectToPrs;
496 std::set<ModuleBase_ViewerPrsPtr>::const_iterator aIt;
497 for (aIt = aRestored.cbegin(); aIt != aRestored.cend(); aIt++) {
498 getObjectsMapFromPrs((*aIt), anObjectToShapes, anObjectToPrs);
499 ResultGroupPtr aResGroup;
500 FeaturePtr aGroupFeature;
501 if (getGroup((*aIt), aResGroup, aGroupFeature)) {
502 std::set<ObjectPtr >::iterator aGrpIt = myHiddenGroups.find(aResGroup);
503 if (aGrpIt != myHiddenGroups.end()) {
504 aResGroup->setDisplayed(true);
505 myHiddenGroups.erase(aGrpIt);
510 std::set<ObjectPtr> aRestoredObjects;
511 std::map<ObjectPtr, TopoDS_ListOfShape>::const_iterator aShapesIt;
512 for (aShapesIt = anObjectToShapes.begin(); aShapesIt != anObjectToShapes.end(); aShapesIt++) {
513 TopoDS_ListOfShape aShapes = aShapesIt->second;
514 aRestoredObjects.insert(aShapesIt->first);
515 Handle(ModuleBase_ResultPrs) aPrs = anObjectToPrs[aShapesIt->first];
516 TopoDS_ListOfShape aHiddenShapes = aPrs->hiddenSubShapes();
517 TopoDS_ListOfShape::Iterator aSubShapesIt(aShapes);
518 for (; aSubShapesIt.More(); aSubShapesIt.Next()) {
519 if (aHiddenShapes.Contains(aSubShapesIt.Value()))
520 aHiddenShapes.Remove(aSubShapesIt.Value());
522 aPrs->setSubShapeHidden(aHiddenShapes);
524 if (redisplayObjects(aRestoredObjects))
527 myListView->removeSelectedItems();
531 //********************************************************************
532 bool XGUI_FacesPanel::redisplayObjects(
533 const std::set<ObjectPtr >& theObjects)
535 if (theObjects.empty())
538 bool isModified = false;
539 static Events_ID aDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
540 for (std::set<ObjectPtr>::const_iterator anIt = theObjects.begin(); anIt != theObjects.end();
543 ObjectPtr anObject = *anIt;
544 if (!anObject->isDisplayed())
546 ModelAPI_EventCreator::get()->sendUpdated(anObject, aDispEvent);
552 //********************************************************************
553 void XGUI_FacesPanel::updateProcessedObjects(QMap<int, ModuleBase_ViewerPrsPtr> theItems,
554 std::set<ObjectPtr>& theObjects)
557 for (QMap<int, ModuleBase_ViewerPrsPtr>::const_iterator anIt = theItems.begin();
558 anIt != theItems.end(); anIt++) {
559 ModuleBase_ViewerPrsPtr aPrs = anIt.value();
560 ResultGroupPtr aResGroup;
561 FeaturePtr aGroupFeature;
562 if (getGroup(aPrs, aResGroup, aGroupFeature)) {
563 AttributeSelectionListPtr aSelectionList = aGroupFeature->selectionList("group_list");
564 for (int i = 0; i < aSelectionList->size(); i++) {
565 AttributeSelectionPtr aSelection = aSelectionList->value(i);
566 ResultPtr aRes = aSelection->context();
567 if (theObjects.find(aRes) == theObjects.end())
568 theObjects.insert(aRes);
572 if (theObjects.find(aPrs->object()) == theObjects.end())
573 theObjects.insert(aPrs->object());
578 //********************************************************************
579 void XGUI_FacesPanel::closeEvent(QCloseEvent* theEvent)
581 QDockWidget::closeEvent(theEvent);
585 //********************************************************************
586 void XGUI_FacesPanel::onDeleteItem()
591 //********************************************************************
592 void XGUI_FacesPanel::onTransparencyChanged()
594 std::map<ObjectPtr, TopoDS_ListOfShape> anObjectToShapes;
595 std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) > anObjectToPrs;
596 QMap<int, ModuleBase_ViewerPrsPtr >::const_iterator aIt;
597 for (aIt = myItems.cbegin(); aIt != myItems.cend(); aIt++) {
598 getObjectsMapFromPrs(aIt.value(), anObjectToShapes, anObjectToPrs);
601 double aTransp = Config_PropManager::real("Visualization", "hidden_face_transparency");
602 std::set<ObjectPtr> aObjects;
603 std::map<ObjectPtr, Handle(ModuleBase_ResultPrs)>::const_iterator aPrsIt;
604 for (aPrsIt = anObjectToPrs.cbegin(); aPrsIt != anObjectToPrs.cend(); aPrsIt++) {
605 aObjects.insert(aPrsIt->first);
606 aPrsIt->second->setHiddenSubShapeTransparency(useTransparency()? aTransp : 1);
608 if (redisplayObjects(aObjects))
612 //********************************************************************
613 void XGUI_FacesPanel::onClosed()
615 setActivePanel(false);
619 //********************************************************************
621 void XGUI_FacesPanel::processUndo()
623 if(!myUndoList.size())
626 myListView->selectIndices({myUndoList.back()});
628 myUndoList.pop_back();
631 //********************************************************************
632 void XGUI_FacesPanel::flushRedisplay() const
634 Events_Loop::loop()->flush(Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY));
635 // Necessary for update visibility icons in ObjectBrowser
636 XGUI_ObjectsBrowser* anObjectBrowser = myWorkshop->objectBrowser();
638 anObjectBrowser->updateAllIndexes();
639 myWorkshop->viewer()->update();
643 //********************************************************************
644 void XGUI_FacesPanel::onObjectDisplay(ObjectPtr theObject, AISObjectPtr theAIS)
646 bool aContains = false;
647 QMap<int, ModuleBase_ViewerPrsPtr>::iterator aIt;
648 for (aIt = myItems.begin(); aIt != myItems.end(); aIt++) {
649 ModuleBase_ViewerPrsPtr aPrs = aIt.value();
650 if (aPrs->object() == theObject) {
656 ResultGroupPtr aResGroup;
657 FeaturePtr aGroupFeature;
658 std::map<ObjectPtr, TopoDS_ListOfShape> aObjectToShapes;
659 std::map<ObjectPtr, Handle(ModuleBase_ResultPrs)> aObjectToPrs;
660 std::set<ObjectPtr> aObjects;
661 std::set<int> aIdsToRem;
663 TopoDS_ListOfShape aHideShapes;
664 std::map<ObjectPtr, TopoDS_ListOfShape>::const_iterator aSIt;
665 for (aIt = myItems.begin(); aIt != myItems.end(); aIt++) {
666 ModuleBase_ViewerPrsPtr aPrs = aIt.value();
667 if (getGroup(aPrs, aResGroup, aGroupFeature)) {
668 getObjectsMapFromResult(aResGroup, aGroupFeature, aObjectToShapes, aObjectToPrs);
669 if (aResGroup == theObject) {
670 // If group is displayed it means that it has to be deleted from the Faces list and all
671 // corresponded faces have been restored
672 for (aSIt = aObjectToShapes.begin(); aSIt != aObjectToShapes.end(); aSIt++) {
673 TopoDS_ListOfShape aShapes = aSIt->second;
674 Handle(ModuleBase_ResultPrs) aResPrs = aObjectToPrs[aSIt->first];
675 TopoDS_ListOfShape aAlreadyHidden = aResPrs->hiddenSubShapes();
676 TopoDS_ListOfShape::Iterator aShPIt(aShapes);
677 for (; aShPIt.More(); aShPIt.Next()) {
678 if (aAlreadyHidden.Contains(aShPIt.Value()))
679 aAlreadyHidden.Remove(aShPIt.Value());
681 aResPrs->setSubShapeHidden(aAlreadyHidden);
682 aObjects.insert(aSIt->first);
684 aIdsToRem.insert(aIt.key());
687 std::map<ObjectPtr, Handle(ModuleBase_ResultPrs)>::iterator aPIt =
688 aObjectToPrs.find(theObject);
689 if (aPIt != aObjectToPrs.end()) {
690 ObjectPtr aObj = aPIt->first;
691 if (aObj == theObject) {
692 TopoDS_ListOfShape aShapes = aObjectToShapes[aObj];
693 aHideShapes.Append(aShapes);
694 aObjects.insert(aObj);
700 if (aPrs->object() == theObject) {
701 TopoDS_Shape aShape = aPrs->shape()->impl<TopoDS_Shape>();
702 if (!aShape.IsNull())
703 aHideShapes.Append(aShape);
704 aPrs->setInteractive(theAIS->impl<Handle(AIS_InteractiveObject)>());
708 double aTransp = transparency();
709 if (aHideShapes.Size() > 0) {
710 Handle(ModuleBase_ResultPrs) aResultPrs = Handle(ModuleBase_ResultPrs)::DownCast(
711 theAIS->impl<Handle(AIS_InteractiveObject)>());
712 if (!aResultPrs.IsNull()) {
713 aResultPrs->setSubShapeHidden(aHideShapes);
714 aResultPrs->setHiddenSubShapeTransparency(aTransp);
715 aObjects.insert(theObject);
718 removeItems(aIdsToRem);
719 myWorkshop->selector()->clearSelection();
720 if (redisplayObjects(aObjects))
721 QTimer::singleShot(50, this, SLOT(flushRedisplay()));
725 void XGUI_FacesPanel::removeItems(std::set<int> theIds)
729 myListView->removeItems(theIds);
730 std::set<int>::const_iterator aRIt;
731 for (aRIt = theIds.begin(); aRIt != theIds.end(); aRIt++)
732 myItems.remove(*aRIt);