X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModuleBase%2FModuleBase_WidgetSelectionFilter.cpp;h=5ae3446f37ca07fff0310b73c7b1ea868e8654b4;hb=d335fa85ad1b38088f011253a3189276556cc959;hp=3e3d407d3a1f903f381fa8a7f6e530513ca0478e;hpb=f78afe4d9b7611ab7f4d42df1329b481fb2265ce;p=modules%2Fshaper.git diff --git a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp index 3e3d407d3..5ae3446f3 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2020 CEA/DEN, EDF R&D +// Copyright (C) 2014-2023 CEA, EDF // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -34,7 +34,9 @@ #include #include #include + #include +#include #include #include @@ -55,6 +57,10 @@ #include #include +#ifdef WIN32 +#pragma warning(disable : 4456) // for nested foreach +#endif + FeaturePtr ModuleBase_WidgetSelectionFilter::SelectorFeature; std::string ModuleBase_WidgetSelectionFilter::AttributeId; @@ -178,6 +184,7 @@ ModuleBase_FilterItem::ModuleBase_FilterItem( connect(aWidget, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)), theParent, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*))); connect(aWidget, SIGNAL(objectUpdated()), theParent, SLOT(onObjectUpdated())); + aWidget->enableFocusProcessing(); } aLayout->addWidget(aParamsWgt); } @@ -360,7 +367,6 @@ void ModuleBase_WidgetSelectionFilter::onAddFilter(int theIndex) std::string aText = myFiltersCombo->itemText(theIndex).toStdString(); std::list::iterator aIt; - int i; std::string aFilter; std::map::const_iterator aFound = myFilters.find(aText); if (aFound == myFilters.end()) { @@ -452,35 +458,24 @@ void ModuleBase_WidgetSelectionFilter::onSelect() clearCurrentSelection(); + FiltersFeaturePtr aFiltersFeature = + std::dynamic_pointer_cast(myFeature); + static SessionPtr aSession = ModelAPI_Session::get(); + std::list< std::pair > aResList = + aSession->filters()->select(aFiltersFeature, (GeomAPI_Shape::ShapeType)mySelectionType); + BRep_Builder aBuilder; TopoDS_Compound aComp; aBuilder.MakeCompound(aComp); - DocumentPtr aDoc = myFeature->document(); - int aNb = aDoc->size(ModelAPI_ResultBody::group()); - ObjectPtr aObj; - ResultBodyPtr aBody; - for (int i = 0; i < aNb; i++) { - aObj = aDoc->object(ModelAPI_ResultBody::group(), i); - aBody = std::dynamic_pointer_cast(aObj); - GeomShapePtr aShape = aBody->shape(); - std::list aSubShapes = - aShape->subShapes((GeomAPI_Shape::ShapeType)mySelectionType); - TopTools_MapOfShape alreadyThere; - std::list::const_iterator aShapesIt; - for (aShapesIt = aSubShapes.cbegin(); aShapesIt != aSubShapes.cend(); aShapesIt++) { - GeomShapePtr aSubShape = (*aShapesIt); - TopoDS_Shape aTShape = aSubShape->impl(); - if (!alreadyThere.Add(aTShape)) - continue; - static SessionPtr aSession = ModelAPI_Session::get(); - bool isValid = aSession->filters()->isValid(myFeature, aBody, aSubShape); - if (isValid) { - aBuilder.Add(aComp, aTShape); - ModuleBase_ViewerPrsPtr aValue(new ModuleBase_ViewerPrs(aObj, aSubShape)); - myValues.append(aValue); - } - } + std::list< std::pair >::const_iterator itSelected = aResList.cbegin(); + for (; itSelected != aResList.cend(); itSelected++) { + ResultPtr aCurRes = (*itSelected).first; + GeomShapePtr aSubShape = (*itSelected).second; + TopoDS_Shape aTShape = aSubShape->impl(); + aBuilder.Add(aComp, aTShape); + ModuleBase_ViewerPrsPtr aValue (new ModuleBase_ViewerPrs(aCurRes, aSubShape)); + myValues.append(aValue); } if (myValues.size() > 0) @@ -521,33 +516,40 @@ void ModuleBase_WidgetSelectionFilter::updatePreview(const TopoDS_Shape& theShap void ModuleBase_WidgetSelectionFilter::onShowOnly(bool theShow) { - if (myPreview.IsNull()) - return; Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext(); - if (theShow) { AIS_ListOfInteractive aList; aCtx->DisplayedObjects(AIS_KOI_Shape, -1, aList); - aList.Remove(myPreview); + if (!myPreview.IsNull()) + aList.Remove(myPreview); if (aList.Size() > 0) myListIO = aList; } AIS_ListOfInteractive::const_iterator aIt; Handle(AIS_Shape) aShapeIO; + bool isModified = false; for (aIt = myListIO.cbegin(); aIt != myListIO.cend(); aIt++) { aShapeIO = Handle(AIS_Shape)::DownCast(*aIt); if (!aShapeIO.IsNull()) { - if (theShow) - aCtx->Erase(aShapeIO, false); + if (theShow) { + if (aCtx->IsDisplayed(aShapeIO)) { + aCtx->Erase(aShapeIO, false); + isModified = true; + } + } else { - aCtx->Display(aShapeIO, false); - std::shared_ptr anAISObj = AISObjectPtr(new GeomAPI_AISObject()); - anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aShapeIO)); - myWorkshop->applyCurrentSelectionModes(anAISObj); + if (!aCtx->IsDisplayed(aShapeIO)) { + aCtx->Display(aShapeIO, false); + std::shared_ptr anAISObj = AISObjectPtr(new GeomAPI_AISObject()); + anAISObj->setImpl(new Handle(AIS_InteractiveObject)(aShapeIO)); + myWorkshop->applyCurrentSelectionModes(anAISObj); + isModified = true; + } } } } - myWorkshop->viewer()->update(); + if (isModified) + myWorkshop->viewer()->update(); } void ModuleBase_WidgetSelectionFilter::updateSelectBtn() @@ -560,11 +562,16 @@ void ModuleBase_WidgetSelectionFilter::updateNumberSelected() { int aNb = myValues.size(); myNbLbl->setText(QString::number(aNb)); - if (aNb == 0) + if (aNb == 0) { myFeature->setError(translate("Selection is empty").toStdString(), false, false); + myShowBtn->setChecked(false); + onShowOnly(false); + myShowBtn->setEnabled(false); + } else { myFeature->setError("", false, false); myFeature->data()->execState(ModelAPI_StateDone); + myShowBtn->setEnabled(true); } }