From 3f28b864e07f77b37a46a67dbf3ee4639eee4e08 Mon Sep 17 00:00:00 2001 From: vsv Date: Wed, 1 Aug 2018 17:23:31 +0300 Subject: [PATCH] Use Feature as a value for selection attribute --- .../GeomValidators_BodyShapes.cpp | 40 +++++++++++----- .../GeomValidators_ShapeType.cpp | 48 ++++++++++++------- src/ModuleBase/ModuleBase_Tools.cpp | 8 ++-- src/ModuleBase/ModuleBase_WidgetSelector.cpp | 2 + src/ModuleBase/ModuleBase_WidgetValidated.cpp | 10 +++- src/XGUI/XGUI_SelectionMgr.cpp | 39 ++++++++------- 6 files changed, 95 insertions(+), 52 deletions(-) diff --git a/src/GeomValidators/GeomValidators_BodyShapes.cpp b/src/GeomValidators/GeomValidators_BodyShapes.cpp index 8faa007ec..ff040cecb 100644 --- a/src/GeomValidators/GeomValidators_BodyShapes.cpp +++ b/src/GeomValidators/GeomValidators_BodyShapes.cpp @@ -26,6 +26,7 @@ #include #include #include +#include bool GeomValidators_BodyShapes::isValid(const AttributePtr& theAttribute, const std::list& theArguments, @@ -36,21 +37,36 @@ bool GeomValidators_BodyShapes::isValid(const AttributePtr& theAttribute, AttributeSelectionPtr anAttrSelection = std::dynamic_pointer_cast(theAttribute); ResultPtr aContext = anAttrSelection->context(); - if(!aContext.get()) { + FeaturePtr aContextFeature = anAttrSelection->contextFeature(); + if (!(aContext.get() || aContextFeature.get())) { theError = "Error: Context is empty."; return false; } - - ResultConstructionPtr aResultConstruction = - std::dynamic_pointer_cast(aContext); - if(aResultConstruction.get()) { - theError = "Error: Result construction selected."; - return false; - } - // additional check that the selected object is top-level result - if (theArguments.size() > 0 && *(theArguments.rbegin()) == "toplevel") { - if (ModelAPI_Tools::bodyOwner(aContext).get()) { - theError = "Error: Only higher level shape allowed."; + if (aContext.get()) { + ResultConstructionPtr aResultConstruction = + std::dynamic_pointer_cast(aContext); + if (aResultConstruction.get()) { + theError = "Error: Result construction selected."; + return false; + } + // additional check that the selected object is top-level result + if (theArguments.size() > 0 && *(theArguments.rbegin()) == "toplevel") { + if (ModelAPI_Tools::bodyOwner(aContext).get()) { + theError = "Error: Only higher level shape allowed."; + return false; + } + } + } else { + std::list aResList = aContextFeature->results(); + std::list::const_iterator aIt; + for (aIt = aResList.cbegin(); aIt != aResList.cend(); aIt++) { + ResultPtr aRes = (*aIt); + ResultBodyPtr aBody = std::dynamic_pointer_cast(aRes); + if (aBody.get()) + break; + } + if (aIt == aResList.cend()) { + theError = "Error: Feature doesn't creates body."; return false; } } diff --git a/src/GeomValidators/GeomValidators_ShapeType.cpp b/src/GeomValidators/GeomValidators_ShapeType.cpp index 3ee016de3..afb7dd0c9 100755 --- a/src/GeomValidators/GeomValidators_ShapeType.cpp +++ b/src/GeomValidators/GeomValidators_ShapeType.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -130,8 +131,12 @@ bool GeomValidators_ShapeType::isValidAttribute(const AttributePtr& theAttribute GeomShapePtr aShape = anAttr->value(); if (aShape.get()) aValid = isValidShape(aShape, theShapeType, theError); - else - aValid = isValidObject(anAttr->context(), theShapeType, theError); + else { + if (anAttr->context().get()) + aValid = isValidObject(anAttr->context(), theShapeType, theError); + else + aValid = isValidObject(anAttr->contextFeature(), theShapeType, theError); + } } else if (anAttributeType == ModelAPI_AttributeRefAttr::typeId()) { AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast(theAttribute); @@ -178,6 +183,8 @@ bool GeomValidators_ShapeType::isValidAttribute(const AttributePtr& theAttribute theError = "The attribute with the %1 type is not processed"; theError.arg(anAttributeType); } + if (aValid) + theError = ""; return aValid; } @@ -194,20 +201,29 @@ bool GeomValidators_ShapeType::isValidObject(const ObjectPtr& theObject, } else { ResultPtr aResult = std::dynamic_pointer_cast(theObject); - if( theShapeType==Plane ) - { - ResultConstructionPtr aResultConstruction = - std::dynamic_pointer_cast(theObject); - FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); - const std::string& aKind = aFeature->getKind(); - return aResult.get() != NULL && aKind == "Plane"; - } - if (!aResult.get()) { - aValid = false; - theError = "The result is empty"; - } - else { - aValid = isValidShape(aResult->shape(), theShapeType, theError); + if (aResult.get()) { + if (theShapeType == Plane) + { + ResultConstructionPtr aResultConstruction = + std::dynamic_pointer_cast(theObject); + FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); + const std::string& aKind = aFeature->getKind(); + return aResult.get() != NULL && aKind == "Plane"; + } + if (!aResult.get()) { + aValid = false; + theError = "The result is empty"; + } else { + aValid = isValidShape(aResult->shape(), theShapeType, theError); + } + } else { + FeaturePtr aFeature = std::dynamic_pointer_cast(theObject); + if (aFeature.get() && (theShapeType == CompSolid)) + return aValid; + else { + aValid = false; + theError = "The feature has to produce a compsolid"; + } } } return aValid; diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index 996f4b181..67d2b349a 100755 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -679,18 +679,16 @@ bool setObject(const AttributePtr& theAttribute, const ObjectPtr& theObject, } else if (aType == ModelAPI_AttributeSelection::typeId()) { AttributeSelectionPtr aSelectAttr = std::dynamic_pointer_cast(theAttribute); - ResultPtr aResult = std::dynamic_pointer_cast(theObject); if (aSelectAttr.get() != NULL) { - aSelectAttr->setValue(aResult, theShape, theTemporarily); + aSelectAttr->setValue(theObject, theShape, theTemporarily); } } if (aType == ModelAPI_AttributeSelectionList::typeId()) { AttributeSelectionListPtr aSelectionListAttr = std::dynamic_pointer_cast(theAttribute); - ResultPtr aResult = std::dynamic_pointer_cast(theObject); if (!theCheckIfAttributeHasObject || - !aSelectionListAttr->isInList(aResult, theShape, theTemporarily)) - aSelectionListAttr->append(aResult, theShape, theTemporarily); + !aSelectionListAttr->isInList(theObject, theShape, theTemporarily)) + aSelectionListAttr->append(theObject, theShape, theTemporarily); } else if (aType == ModelAPI_AttributeRefList::typeId()) { AttributeRefListPtr aRefListAttr = diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.cpp b/src/ModuleBase/ModuleBase_WidgetSelector.cpp index 3d4afc9a1..9642a37af 100755 --- a/src/ModuleBase/ModuleBase_WidgetSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelector.cpp @@ -64,6 +64,8 @@ void ModuleBase_WidgetSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr& { ModuleBase_ISelection* aSelection = myWorkshop->selection(); theObject = aSelection->getResult(thePrs); + if (!theObject.get()) + theObject = thePrs->object(); theShape = aSelection->getShape(thePrs); } diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.cpp b/src/ModuleBase/ModuleBase_WidgetValidated.cpp index 4d8b47998..91713b65b 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.cpp +++ b/src/ModuleBase/ModuleBase_WidgetValidated.cpp @@ -115,8 +115,14 @@ bool ModuleBase_WidgetValidated::isValidInFilters(const ModuleBase_ViewerPrsPtr& anOwner = new StdSelect_BRepOwner(aTDShape, anIO); myPresentedObject = aResult; } - else - aValid = false; // only results with a shape can be filtered + else { + FeaturePtr aFeature = ModelAPI_Feature::feature(thePrs->object()); + if (aFeature.get()) { + // Use feature as a reference to all its results + myPresentedObject = aFeature; + } else + aValid = false; // only results with a shape can be filtered + } } // checks the owner by the AIS context activated filters if (!anOwner.IsNull()) { diff --git a/src/XGUI/XGUI_SelectionMgr.cpp b/src/XGUI/XGUI_SelectionMgr.cpp index 405c1979e..db0987efa 100755 --- a/src/XGUI/XGUI_SelectionMgr.cpp +++ b/src/XGUI/XGUI_SelectionMgr.cpp @@ -98,27 +98,32 @@ void XGUI_SelectionMgr::setSelectedOwners(const SelectMgr_IndexedMapOfOwner& the void XGUI_SelectionMgr::onObjectBrowserSelection() { QList aSelectedPrs = - myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Browser); - - QList aTmpList = aSelectedPrs; - ObjectPtr aObject; - FeaturePtr aFeature; - foreach(ModuleBase_ViewerPrsPtr aPrs, aTmpList) { - aObject = aPrs->object(); - if (aObject.get()) { - aFeature = std::dynamic_pointer_cast(aObject); - if (aFeature.get()) { - std::list allRes; - ModelAPI_Tools::allResults(aFeature, allRes); - for(std::list::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) { - aSelectedPrs.append(std::shared_ptr( - new ModuleBase_ViewerPrs(*aRes, GeomShapePtr(), NULL))); + myWorkshop->selector()->selection()->getSelected(ModuleBase_ISelection::Browser); + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + if (!myWorkshop->operationMgr()->hasOperation()) { + + QList aTmpList = aSelectedPrs; + ObjectPtr aObject; + FeaturePtr aFeature; + // Select all results of a selected feature in viewer + foreach(ModuleBase_ViewerPrsPtr aPrs, aSelectedPrs) { + aObject = aPrs->object(); + if (aObject.get()) { + aFeature = std::dynamic_pointer_cast(aObject); + if (aFeature.get()) { + std::list allRes; + ModelAPI_Tools::allResults(aFeature, allRes); + for (std::list::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) { + aTmpList.append(std::shared_ptr( + new ModuleBase_ViewerPrs(*aRes, GeomShapePtr(), NULL))); + } } } } + aDisplayer->setSelected(aTmpList); + } else { + aDisplayer->setSelected(aSelectedPrs); } - XGUI_Displayer* aDisplayer = myWorkshop->displayer(); - aDisplayer->setSelected(aSelectedPrs); emit selectionChanged(); } -- 2.39.2