-// Copyright (C) 2014-2020 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2024 CEA, EDF
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
#include <ModelAPI_Events.h>
#include <ModelAPI_AttributeSelectionList.h>
+#include <ModuleBase_Operation.h>
+#include <ModuleBase_OperationFeature.h>
+#include <XGUI_OperationMgr.h>
+
#include <QAction>
#include <QCheckBox>
#include <QFocusEvent>
#include <QMainWindow>
#include <QTimer>
-static const int LayoutMargin = 3;
+#ifdef WIN32
+#pragma warning(disable : 4189) // for skipping MAYBE_UNUSED on Win
+#endif
-//********************************************************************
-bool getGroup(ModuleBase_ViewerPrsPtr thePrs, ResultGroupPtr& theResGroup,
- FeaturePtr& theGroupFeature)
-{
- ObjectPtr anObject = thePrs->object();
- if (!anObject.get())
- return false;
-
- theResGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(anObject);
- if (theResGroup.get()) {
- theGroupFeature = ModelAPI_Feature::feature(theResGroup);
- }
- else {
- theGroupFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
- if (theGroupFeature.get())
- theResGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(theGroupFeature->firstResult());
- }
- return theGroupFeature.get() && theResGroup.get();
-}
+static const int LayoutMargin = 3;
//********************************************************************
void updateHiddenShapes(Handle(ModuleBase_ResultPrs) thePrs, const TopoDS_ListOfShape& theShapes)
thePrs->setSubShapeHidden(aAlreadyHidden);
}
+//********************************************************************
+void objectsMapFromPrs(ModuleBase_ViewerPrsPtr thePrs,
+ std::map<ObjectPtr, TopoDS_ListOfShape>& theObjectToShapes,
+ std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) >& theObjectToPrs)
+{
+ ObjectPtr anObject = thePrs->object();
+ if (!anObject.get())
+ return;
+
+ // Process bodies
+ Handle(ModuleBase_ResultPrs) aResultPrs = Handle(ModuleBase_ResultPrs)::DownCast(
+ thePrs->interactive());
+ if (aResultPrs.IsNull())
+ return;
+
+ if (theObjectToShapes.find(anObject) != theObjectToShapes.end())
+ theObjectToShapes.at(anObject).Append(ModuleBase_Tools::getSelectedShape(thePrs));
+ else {
+ TopoDS_ListOfShape aListOfShapes;
+ aListOfShapes.Append(ModuleBase_Tools::getSelectedShape(thePrs));
+ theObjectToShapes[anObject] = aListOfShapes;
+ theObjectToPrs[anObject] = aResultPrs;
+ }
+}
+
//********************************************************************
XGUI_FacesPanel::XGUI_FacesPanel(QWidget* theParent, XGUI_Workshop* theWorkshop)
- : QDockWidget(theParent), myWorkshop(theWorkshop), myIsActive(false)
+ : QDockWidget(theParent), myWorkshop(theWorkshop), myIsActive(false), myLastItemIndex(0)
{
setWindowTitle(tr("Hide Faces"));
setObjectName("Hide Faces");
std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) > anObjectToPrs;
QMap<int, ModuleBase_ViewerPrsPtr >::const_iterator aIt;
for (aIt = myItems.cbegin(); aIt != myItems.cend(); aIt++) {
- getObjectsMapFromPrs(aIt.value(), anObjectToShapes, anObjectToPrs);
+ objectsMapFromPrs(aIt.value(), anObjectToShapes, anObjectToPrs);
}
std::set<ObjectPtr> aObjects;
aObjects.insert(aPrsIt->first);
aPrsIt->second->setSubShapeHidden(anEmpty);
}
- std::set<ObjectPtr >::const_iterator aGrpIt;
- for (aGrpIt = myHiddenGroups.cbegin(); aGrpIt != myHiddenGroups.cend(); aGrpIt++)
- (*aGrpIt)->setDisplayed(true);
- myHiddenGroups.clear();
if (redisplayObjects(aObjects))
flushRedisplay();
// the selection is cleared by activating selection control
myWorkshop->selector()->clearSelection();
}
- else
+ else{
emit deactivated();
+ myUndoList.clear();
+ }
}
//********************************************************************
}
}
-//********************************************************************
-void XGUI_FacesPanel::getObjectsMapFromResult(ResultGroupPtr theResGroup,
- FeaturePtr theGroupFeature,
- std::map<ObjectPtr, TopoDS_ListOfShape>& theObjectToShapes,
- std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) >& theObjectToPrs)
-{
- XGUI_Displayer* aDisplayer = myWorkshop->displayer();
- // Process a grouip result
- AttributeSelectionListPtr aSelectionList = theGroupFeature->selectionList("group_list");
- AISObjectPtr aPrs;
- for (int i = 0; i < aSelectionList->size(); i++) {
- AttributeSelectionPtr aSelection = aSelectionList->value(i);
- ResultPtr aRes = aSelection->context();
- aPrs = aDisplayer->getAISObject(aRes);
- if (aPrs.get()) {
- Handle(ModuleBase_ResultPrs) aResultPrs = Handle(ModuleBase_ResultPrs)::DownCast(
- aPrs->impl<Handle(AIS_InteractiveObject)>());
- if (!aResultPrs.IsNull()) {
- GeomShapePtr aShape = aSelection->value();
- if (theObjectToShapes.find(aRes) != theObjectToShapes.end())
- theObjectToShapes.at(aRes).Append(aShape->impl<TopoDS_Shape>());
- else {
- TopoDS_ListOfShape aListOfShapes;
- aListOfShapes.Append(aShape->impl<TopoDS_Shape>());
- theObjectToShapes[aRes] = aListOfShapes;
- theObjectToPrs[aRes] = aResultPrs;
- }
- }
- }
- }
-}
-
-//********************************************************************
-void objectsMapFromPrs(ModuleBase_ViewerPrsPtr thePrs,
- std::map<ObjectPtr, TopoDS_ListOfShape>& theObjectToShapes,
- std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) >& theObjectToPrs)
-{
- ObjectPtr anObject = thePrs->object();
- if (!anObject.get())
- return;
-
- // Process bodies
- Handle(ModuleBase_ResultPrs) aResultPrs = Handle(ModuleBase_ResultPrs)::DownCast(
- thePrs->interactive());
- if (aResultPrs.IsNull())
- return;
-
- if (theObjectToShapes.find(anObject) != theObjectToShapes.end())
- theObjectToShapes.at(anObject).Append(ModuleBase_Tools::getSelectedShape(thePrs));
- else {
- TopoDS_ListOfShape aListOfShapes;
- aListOfShapes.Append(ModuleBase_Tools::getSelectedShape(thePrs));
- theObjectToShapes[anObject] = aListOfShapes;
- theObjectToPrs[anObject] = aResultPrs;
- }
-}
-
-//********************************************************************
-void XGUI_FacesPanel::getObjectsMapFromPrs(ModuleBase_ViewerPrsPtr thePrs,
- std::map<ObjectPtr, TopoDS_ListOfShape>& theObjectToShapes,
- std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) >& theObjectToPrs)
-{
- ResultGroupPtr aResGroup;
- FeaturePtr aGroupFeature;
- if (getGroup(thePrs, aResGroup, aGroupFeature))
- getObjectsMapFromResult(aResGroup, aGroupFeature, theObjectToShapes, theObjectToPrs);
- else
- objectsMapFromPrs(thePrs, theObjectToShapes, theObjectToPrs);
-}
//********************************************************************
void XGUI_FacesPanel::processSelection()
if (!anObject.get())
continue;
- ResultGroupPtr aResGroup;
- FeaturePtr aGroupFeature;
- if (getGroup(aPrs, aResGroup, aGroupFeature)) {
- AttributeSelectionListPtr aSelectionListAttr =
- aGroupFeature->data()->selectionList("group_list");
- std::string aType = aSelectionListAttr->selectionType();
- if (aType != "Faces")
- continue;
- }
- else {
- GeomShapePtr aShapePtr = aPrs->shape();
- if (!aShapePtr.get() || !aShapePtr->isFace())
- continue;
- }
+ GeomShapePtr aShapePtr = aPrs->shape();
+ if (!aShapePtr.get() || !aShapePtr->isFace())
+ continue;
- QString aItemName = aResGroup.get()?
- aResGroup->data()->name().c_str() : XGUI_Tools::generateName(aPrs);
+ QString aItemName = XGUI_Tools::generateName(aPrs);
if (myListView->hasItem(aItemName))
continue;
- if (aResGroup.get()) {
- if (aResGroup->isDisplayed()) {
- aResGroup->setDisplayed(false);
- myHiddenGroups.insert(aResGroup);
- }
- getObjectsMapFromResult(aResGroup, aGroupFeature, anObjectToShapes, anObjectToPrs);
- }
- else
- objectsMapFromPrs(aPrs, anObjectToShapes, anObjectToPrs);
+ objectsMapFromPrs(aPrs, anObjectToShapes, anObjectToPrs);
// The code is dedicated to remove already selected items if they are selected twice
// It can happen in case of groups selection
for (aIt = myItems.cbegin(); aIt != myItems.cend(); aIt++) {
ModuleBase_ViewerPrsPtr aCurPrs = aIt.value();
ObjectPtr aObject = aCurPrs->object();
- ResultGroupPtr aCurResGroup = std::dynamic_pointer_cast<ModelAPI_ResultGroup>(aObject);
- if (aCurResGroup.get())
- continue;
if (anObjectToShapes.find(aObject) != anObjectToShapes.end()) {
TopoDS_ListOfShape aShapes = anObjectToShapes[aObject];
GeomShapePtr aShapePtr = aCurPrs->shape();
myItems.insert(myLastItemIndex, aPrs);
myListView->addItem(aItemName, myLastItemIndex);
+ // add in undo list
+ myUndoList.push_back(myLastItemIndex);
myLastItemIndex++;
isModified = true;
}
// Remove duplicate items
removeItems(aToRemove);
+ myWorkshop->selector()->clearSelection();
if (isModified) {
updateProcessedObjects(myItems, myItemObjects);
flushRedisplay();
bool XGUI_FacesPanel::processDelete()
{
//appendFirstSelectionInHistory();
- QModelIndexList anIndices = myListView->getControl()->selectionModel()->selectedIndexes();
+ //QModelIndexList anIndices = myListView->getControl()->selectionModel()->selectedIndexes();
std::set<int> aSelectedIds;
myListView->getSelectedIndices(aSelectedIds);
std::set<ModuleBase_ViewerPrsPtr>::const_iterator aIt;
for (aIt = aRestored.cbegin(); aIt != aRestored.cend(); aIt++) {
- getObjectsMapFromPrs((*aIt), anObjectToShapes, anObjectToPrs);
- ResultGroupPtr aResGroup;
- FeaturePtr aGroupFeature;
- if (getGroup((*aIt), aResGroup, aGroupFeature)) {
- std::set<ObjectPtr >::iterator aGrpIt = myHiddenGroups.find(aResGroup);
- if (aGrpIt != myHiddenGroups.end()) {
- aResGroup->setDisplayed(true);
- myHiddenGroups.erase(aGrpIt);
- }
- }
+ objectsMapFromPrs((*aIt), anObjectToShapes, anObjectToPrs);
}
std::set<ObjectPtr> aRestoredObjects;
for (QMap<int, ModuleBase_ViewerPrsPtr>::const_iterator anIt = theItems.begin();
anIt != theItems.end(); anIt++) {
ModuleBase_ViewerPrsPtr aPrs = anIt.value();
- ResultGroupPtr aResGroup;
- FeaturePtr aGroupFeature;
- if (getGroup(aPrs, aResGroup, aGroupFeature)) {
- AttributeSelectionListPtr aSelectionList = aGroupFeature->selectionList("group_list");
- for (int i = 0; i < aSelectionList->size(); i++) {
- AttributeSelectionPtr aSelection = aSelectionList->value(i);
- ResultPtr aRes = aSelection->context();
- if (theObjects.find(aRes) == theObjects.end())
- theObjects.insert(aRes);
- }
- }
- else {
- if (theObjects.find(aPrs->object()) == theObjects.end())
- theObjects.insert(aPrs->object());
- }
+ if (theObjects.find(aPrs->object()) == theObjects.end())
+ theObjects.insert(aPrs->object());
}
}
std::map<ObjectPtr, Handle(ModuleBase_ResultPrs) > anObjectToPrs;
QMap<int, ModuleBase_ViewerPrsPtr >::const_iterator aIt;
for (aIt = myItems.cbegin(); aIt != myItems.cend(); aIt++) {
- getObjectsMapFromPrs(aIt.value(), anObjectToShapes, anObjectToPrs);
+ objectsMapFromPrs(aIt.value(), anObjectToShapes, anObjectToPrs);
}
double aTransp = Config_PropManager::real("Visualization", "hidden_face_transparency");
reset(true);
}
+//********************************************************************
+
+void XGUI_FacesPanel::processUndo()
+{
+ if(!myUndoList.size())
+ return;
+
+ myListView->selectIndices({myUndoList.back()});
+ processDelete();
+ myUndoList.pop_back();
+}
+
//********************************************************************
void XGUI_FacesPanel::flushRedisplay() const
{
}
}
if (aContains) {
- ResultGroupPtr aResGroup;
- FeaturePtr aGroupFeature;
std::map<ObjectPtr, TopoDS_ListOfShape> aObjectToShapes;
std::map<ObjectPtr, Handle(ModuleBase_ResultPrs)> aObjectToPrs;
std::set<ObjectPtr> aObjects;
std::map<ObjectPtr, TopoDS_ListOfShape>::const_iterator aSIt;
for (aIt = myItems.begin(); aIt != myItems.end(); aIt++) {
ModuleBase_ViewerPrsPtr aPrs = aIt.value();
- if (getGroup(aPrs, aResGroup, aGroupFeature)) {
- getObjectsMapFromResult(aResGroup, aGroupFeature, aObjectToShapes, aObjectToPrs);
- if (aResGroup == theObject) {
- // If group is displayed it means that it has to be deleted from the Faces list and all
- // corresponded faces have been restored
- for (aSIt = aObjectToShapes.begin(); aSIt != aObjectToShapes.end(); aSIt++) {
- TopoDS_ListOfShape aShapes = aSIt->second;
- Handle(ModuleBase_ResultPrs) aResPrs = aObjectToPrs[aSIt->first];
- TopoDS_ListOfShape aAlreadyHidden = aResPrs->hiddenSubShapes();
- TopoDS_ListOfShape::Iterator aShPIt(aShapes);
- for (; aShPIt.More(); aShPIt.Next()) {
- if (aAlreadyHidden.Contains(aShPIt.Value()))
- aAlreadyHidden.Remove(aShPIt.Value());
- }
- aResPrs->setSubShapeHidden(aAlreadyHidden);
- aObjects.insert(aSIt->first);
- }
- aIdsToRem.insert(aIt.key());
- }
- else {
- std::map<ObjectPtr, Handle(ModuleBase_ResultPrs)>::iterator aPIt =
- aObjectToPrs.find(theObject);
- if (aPIt != aObjectToPrs.end()) {
- ObjectPtr aObj = aPIt->first;
- if (aObj == theObject) {
- TopoDS_ListOfShape aShapes = aObjectToShapes[aObj];
- aHideShapes.Append(aShapes);
- aObjects.insert(aObj);
- }
- }
- }
- }
- else {
- if (aPrs->object() == theObject) {
- TopoDS_Shape aShape = aPrs->shape()->impl<TopoDS_Shape>();
- if (!aShape.IsNull())
- aHideShapes.Append(aShape);
- aPrs->setInteractive(theAIS->impl<Handle(AIS_InteractiveObject)>());
- }
+ if (aPrs->object() == theObject) {
+ TopoDS_Shape aShape = aPrs->shape()->impl<TopoDS_Shape>();
+ if (!aShape.IsNull())
+ aHideShapes.Append(aShape);
+ aPrs->setInteractive(theAIS->impl<Handle(AIS_InteractiveObject)>());
}
}
double aTransp = transparency();