From a355e529b59bbfb99e67b3179f7dc987e45116c2 Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 18 Mar 2015 10:33:25 +0300 Subject: [PATCH] Multi-selection widget to be used in the extrusion feature. Shape validator correction --- src/ModelAPI/ModelAPI_ShapeValidator.cpp | 18 ++--- src/ModelAPI/ModelAPI_ShapeValidator.h | 18 ++--- src/ModuleBase/CMakeLists.txt | 2 + src/ModuleBase/ModuleBase_FilterValidated.cpp | 64 ++++++++++++++++++ src/ModuleBase/ModuleBase_FilterValidated.h | 47 ++++++++++++++ .../ModuleBase_WidgetShapeSelector.cpp | 8 +-- .../PartSet_WidgetConstraintShapeSelector.cpp | 4 +- .../SketchPlugin_ShapeValidator.cpp | 65 ++++++++++--------- .../SketchPlugin_ShapeValidator.h | 23 ++++--- src/XGUI/XGUI_Displayer.h | 3 + 10 files changed, 180 insertions(+), 72 deletions(-) create mode 100644 src/ModuleBase/ModuleBase_FilterValidated.cpp create mode 100644 src/ModuleBase/ModuleBase_FilterValidated.h diff --git a/src/ModelAPI/ModelAPI_ShapeValidator.cpp b/src/ModelAPI/ModelAPI_ShapeValidator.cpp index 08f0a687b..0ef625cd7 100644 --- a/src/ModelAPI/ModelAPI_ShapeValidator.cpp +++ b/src/ModelAPI/ModelAPI_ShapeValidator.cpp @@ -9,17 +9,19 @@ #include #include "ModelAPI_Object.h" -bool ModelAPI_ShapeValidator::isValid(const FeaturePtr& theFeature, - const std::list& theArguments, - const ObjectPtr& theObject, - const AttributePtr& theAttribute, - const GeomShapePtr& theShape) const +bool ModelAPI_ShapeValidator::isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const { + FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); + AttributeSelectionPtr aSelectionAttribute = + std::dynamic_pointer_cast(theAttribute); + GeomShapePtr aShape = aSelectionAttribute->value(); + std::string aCurrentAttributeId = theAttribute->id(); // get all feature attributes std::list anAttrs = - theFeature->data()->attributes(ModelAPI_AttributeSelection::type()); - if (anAttrs.size() > 0 && theShape.get() != NULL) { + aFeature->data()->attributes(ModelAPI_AttributeSelection::type()); + if (anAttrs.size() > 0 && aShape.get() != NULL) { std::list::iterator anAttr = anAttrs.begin(); for(; anAttr != anAttrs.end(); anAttr++) { AttributePtr anAttribute = *anAttr; @@ -28,7 +30,7 @@ bool ModelAPI_ShapeValidator::isValid(const FeaturePtr& theFeature, AttributeSelectionPtr aSelectionAttribute = std::dynamic_pointer_cast(anAttribute); // the shape of the attribute should be not the same - if (aSelectionAttribute.get() != NULL && theShape->isEqual(aSelectionAttribute->value())) { + if (aSelectionAttribute.get() != NULL && aShape->isEqual(aSelectionAttribute->value())) { return false; } } diff --git a/src/ModelAPI/ModelAPI_ShapeValidator.h b/src/ModelAPI/ModelAPI_ShapeValidator.h index 3be9323f7..beac5e2c9 100644 --- a/src/ModelAPI/ModelAPI_ShapeValidator.h +++ b/src/ModelAPI/ModelAPI_ShapeValidator.h @@ -9,29 +9,21 @@ #include -#include -#include +#include #include -#include - /** * Generic validator for any attribute of a feature. */ -class ModelAPI_ShapeValidator : public ModelAPI_Validator +class ModelAPI_ShapeValidator : public ModelAPI_AttributeValidator { public: /// returns True if the attribute is valid. It checks whether the feature of the attribute /// does not contain a selection attribute filled with the same shape - /// \param theFeature a feature to check - /// \param theArguments a filter parameters - /// \param theObject an object /// \param theAttribute an attribute to check - /// \param theShape a shape - MODELAPI_EXPORT virtual bool isValid(const FeaturePtr& theFeature, - const std::list& theArguments, - const ObjectPtr& theObject, const AttributePtr& theAttribute, - const GeomShapePtr& theShape) const; + /// \param theArguments a filter parameters + MODELAPI_EXPORT virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const; }; #endif diff --git a/src/ModuleBase/CMakeLists.txt b/src/ModuleBase/CMakeLists.txt index cf2020c12..a7ad900d1 100644 --- a/src/ModuleBase/CMakeLists.txt +++ b/src/ModuleBase/CMakeLists.txt @@ -14,6 +14,7 @@ SET(PROJECT_HEADERS ModuleBase_FilterNoConsructionSubShapes.h ModuleBase_FilterNoDegeneratedEdge.h ModuleBase_FilterShapeType.h + ModuleBase_FilterValidated.h ModuleBase_Tools.h ModuleBase_IModule.h ModuleBase_Operation.h @@ -62,6 +63,7 @@ SET(PROJECT_SOURCES ModuleBase_FilterNoConsructionSubShapes.cpp ModuleBase_FilterNoDegeneratedEdge.cpp ModuleBase_FilterShapeType.cpp + ModuleBase_FilterValidated.cpp ModuleBase_Tools.cpp ModuleBase_IModule.cpp ModuleBase_IWorkshop.cpp diff --git a/src/ModuleBase/ModuleBase_FilterValidated.cpp b/src/ModuleBase/ModuleBase_FilterValidated.cpp new file mode 100644 index 000000000..20c169262 --- /dev/null +++ b/src/ModuleBase/ModuleBase_FilterValidated.cpp @@ -0,0 +1,64 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModuleBase_FilterValidated.h +// Created: 17 Mar 2015 +// Author: Natalia ERMOLAEVA + + +#include "ModuleBase_FilterValidated.h" +#include "ModuleBase_IWorkshop.h" + +#include +#include +#include + +#include +#include + +#include + +#include +#include +#include +#include + +#include +#include + + +IMPLEMENT_STANDARD_HANDLE(ModuleBase_FilterValidated, SelectMgr_Filter); +IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_FilterValidated, SelectMgr_Filter); + +Standard_Boolean ModuleBase_FilterValidated::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const +{ +/* // global selection should be ignored, the filter processes only selected sub-shapes + Handle(StdSelect_BRepOwner) aShapeOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner); + if (!aShapeOwner.IsNull()) { + if (!aShapeOwner->ComesFromDecomposition()) + return Standard_True; + } + + if (theOwner->HasSelectable()) { + Handle(AIS_InteractiveObject) aAisObj = + Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable()); + if (!aAisObj.IsNull()) { + std::shared_ptr aAISObj = AISObjectPtr(new GeomAPI_AISObject()); + aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj)); + ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj); + + ResultConstructionPtr aConstr = + std::dynamic_pointer_cast(aObj); + if (aConstr != NULL) { + // it provides selection only on compositie features, construction without composite + // feature is not selectable + FeaturePtr aFeature = ModelAPI_Feature::feature(aConstr); + CompositeFeaturePtr aComposite = + std::dynamic_pointer_cast(aFeature); + return aComposite && aComposite->numberOfSubs() > 0; + } + } + } + */ + return Standard_False; +} + diff --git a/src/ModuleBase/ModuleBase_FilterValidated.h b/src/ModuleBase/ModuleBase_FilterValidated.h new file mode 100644 index 000000000..2fd2371b9 --- /dev/null +++ b/src/ModuleBase/ModuleBase_FilterValidated.h @@ -0,0 +1,47 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ModuleBase_FilterValidated.h +// Created: 17 Mar 2015 +// Author: Natalia ERMOLAEVA + + +#ifndef ModuleBase_FilterValidated_H +#define ModuleBase_FilterValidated_H + +#include +#include + +class ModuleBase_IWorkshop; + +/** +* \ingroup GUI +* \class ModuleBase_FilterValidated +* A filter which provides filtering of selection in 3d viewer. +* Installing of this filter lets to select objects which belong to +* currently active document or to global document +*/ +DEFINE_STANDARD_HANDLE(ModuleBase_FilterValidated, SelectMgr_Filter); +class ModuleBase_FilterValidated: public SelectMgr_Filter +{ +public: + /// Constructor + /// \param theWorkshop instance of workshop interface + Standard_EXPORT ModuleBase_FilterValidated(ModuleBase_IWorkshop* theWorkshop): + SelectMgr_Filter(), myWorkshop(theWorkshop) {} + + /** + * Returns true if the owner is computed from decomposition(it is global selection, not the sub-shapes) + * of if the selected result is a construction and the result feature is composite and has sub-elements. + * \param theOwner the result of selection + * \return whether the owner is selectable in the viewer + */ + Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const; + + DEFINE_STANDARD_RTTI(ModuleBase_FilterValidated) + +protected: + /// Instance of workshop interface + ModuleBase_IWorkshop* myWorkshop; +}; + +#endif \ No newline at end of file diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 7a9c2449d..a2034fce6 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include #include @@ -486,13 +486,13 @@ bool ModuleBase_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptrblockSendAttributeUpdated(true); storeAttributeValues(theObj, theShape); -// 3. check the acceptability of the current values + // 3. check the acceptability of the current values std::list::iterator aValidator = aValidators.begin(); std::list >::iterator aArgs = anArguments.begin(); bool aValid = true; for (; aValidator != aValidators.end() && aValid; aValidator++, aArgs++) { - const ModelAPI_RefAttrValidator* aAttrValidator = - dynamic_cast(*aValidator); + const ModelAPI_AttributeValidator* aAttrValidator = + dynamic_cast(*aValidator); if (aAttrValidator) { aValid = aAttrValidator->isValid(anAttribute, *aArgs); } diff --git a/src/PartSet/PartSet_WidgetConstraintShapeSelector.cpp b/src/PartSet/PartSet_WidgetConstraintShapeSelector.cpp index 405fc74b5..e559fa608 100644 --- a/src/PartSet/PartSet_WidgetConstraintShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetConstraintShapeSelector.cpp @@ -15,7 +15,6 @@ bool PartSet_WidgetConstraintShapeSelector::storeAttributeValues(ObjectPtr theSelectedObject, GeomShapePtr theShape) const { ObjectPtr aSelectedObject = theSelectedObject; - GeomShapePtr aShape = theShape; FeaturePtr aFeature = ModelAPI_Feature::feature(aSelectedObject); if (aFeature) { @@ -25,11 +24,10 @@ bool PartSet_WidgetConstraintShapeSelector::storeAttributeValues(ObjectPtr theSe ObjectPtr aObj = PartSet_Tools::createFixedObjectByExternal(theShape->impl(), aSelectedObject, mySketch); if (aObj) { - PartSet_WidgetConstraintShapeSelector* that = (PartSet_WidgetConstraintShapeSelector*) this; aSelectedObject = aObj; } else return false; } } - return ModuleBase_WidgetShapeSelector::storeAttributeValues(theSelectedObject, theShape); + return ModuleBase_WidgetShapeSelector::storeAttributeValues(aSelectedObject, theShape); } diff --git a/src/SketchPlugin/SketchPlugin_ShapeValidator.cpp b/src/SketchPlugin/SketchPlugin_ShapeValidator.cpp index 1b2795900..2aca20171 100644 --- a/src/SketchPlugin/SketchPlugin_ShapeValidator.cpp +++ b/src/SketchPlugin/SketchPlugin_ShapeValidator.cpp @@ -13,42 +13,43 @@ #include #include -bool SketchPlugin_ShapeValidator::isValid(const FeaturePtr& theFeature, - const std::list& theArguments, - const ObjectPtr& theObject, - const AttributePtr& theAttribute, - const GeomShapePtr& theShape) const +bool SketchPlugin_ShapeValidator::isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const { - ResultPtr aResult = std::dynamic_pointer_cast(theObject); - std::shared_ptr aShape = ModelAPI_Tools::shape(aResult); - - // if the shapes are equal, that means that the given shape is a result. - // if the result is selected, the - if (aShape->isEqual(theShape)) + if (theArguments.size() != 1) return true; - // found a non-external argument on the feature - std::list::const_iterator anIt = theArguments.begin(), aLast = theArguments.end(); - bool aHasNullParam = false; - bool aHasNonExternalParams = false; - for (; anIt != aLast; anIt++) { - std::string aParamA = *anIt; - std::shared_ptr anAttr = std::dynamic_pointer_cast< - ModelAPI_AttributeRefAttr>(theFeature->data()->attribute(aParamA)); - if (anAttr) { - FeaturePtr anOtherFeature = ModelAPI_Feature::feature(anAttr->object()); - if (anOtherFeature.get() != NULL) { - std::shared_ptr aSketchFeature = - std::dynamic_pointer_cast(anOtherFeature); - if (aSketchFeature) { - aHasNonExternalParams = !aSketchFeature->isExternal(); - } + // ask whether the feature of the attribute is external + //std::shared_ptr aSketchFeature = + //AttributeRefAttrPtr anAttribute = std::dynamic_pointer_cast(theAttribute); + // std::dynamic_pointer_cast(aFeature); + bool isAttributeExternal = isExternalAttribute(theAttribute); + + // ask whether the feature of the attribute by parameter identifier is external + std::string aFrontArgument = theArguments.front(); + FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); + bool isParameterExternal = isExternalAttribute(aFeature->attribute(aFrontArgument)); + + // it is not possible that both features, attribute and attribute in parameter, are external + if (isAttributeExternal && isParameterExternal) + return false; + return true; +} + +bool SketchPlugin_ShapeValidator::isExternalAttribute(const AttributePtr& theAttribute) const +{ + bool isExternal = false; + AttributeRefAttrPtr anAttribute = std::dynamic_pointer_cast(theAttribute); + + if (anAttribute.get() != NULL) { + FeaturePtr anArgumentFeature = ModelAPI_Feature::feature(anAttribute->object()); + if (anArgumentFeature.get() != NULL) { + std::shared_ptr aSketchFeature = + std::dynamic_pointer_cast(anArgumentFeature); + if (aSketchFeature.get() != NULL) { + isExternal = aSketchFeature->isExternal(); } - else - aHasNullParam = true; } } - if (aHasNullParam || aHasNonExternalParams) - return true; - return false; + return isExternal; } diff --git a/src/SketchPlugin/SketchPlugin_ShapeValidator.h b/src/SketchPlugin/SketchPlugin_ShapeValidator.h index 6e35f4da1..d07581ebd 100644 --- a/src/SketchPlugin/SketchPlugin_ShapeValidator.h +++ b/src/SketchPlugin/SketchPlugin_ShapeValidator.h @@ -8,8 +8,7 @@ #define SketchPlugin_ShapeValidator_H #include -#include -#include +#include /**\class SketchPlugin_ResultPointValidator * \ingroup Validators @@ -17,20 +16,20 @@ * * Allows to select points only. */ -class SketchPlugin_ShapeValidator : public ModelAPI_ShapeValidator +class SketchPlugin_ShapeValidator : public ModelAPI_AttributeValidator { public: - // returns true if there is an empty or non-external shape on the feature. - // in the given shape or in the list of attribute shapes - /// \param theFeature a feature to check + /// returns true if the feature of attribute do not contain external features in the given attribute and + /// among attributes listed in the arguments + /// \param theAttribute an attribute to check /// \param theArguments a filter parameters - /// \param theObject an object + SKETCHPLUGIN_EXPORT virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments) const; + +protected: + /// returns true if the feature of the attribute is external /// \param theAttribute an attribute to check - /// \param theShape a shape - SKETCHPLUGIN_EXPORT virtual bool isValid(const FeaturePtr& theFeature, - const std::list& theArguments, - const ObjectPtr& theObject, const AttributePtr& theAttribute, - const GeomShapePtr& theShape) const; + bool isExternalAttribute(const AttributePtr& theAttribute) const; }; #endif diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index da11c4d8e..bfdf8a5d5 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -19,6 +19,7 @@ #include #include +#include #include @@ -231,6 +232,8 @@ class XGUI_EXPORT XGUI_Displayer /// A container for selection filters Handle(SelectMgr_AndFilter) myAndFilter; + Handle(ModuleBase_FilterValidated) myFilterValidated; + /// A default custom presentation, which is used if the displayed feature is not a custom presentation GeomCustomPrsPtr myCustomPrs; -- 2.30.2