From: nds Date: Thu, 19 Mar 2015 05:42:08 +0000 (+0300) Subject: Sketch selection in the browser for extrusion operation X-Git-Tag: V_1.1.0~110 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=571cc113b54efb9fb058a053cd9ac489549a0729;p=modules%2Fshaper.git Sketch selection in the browser for extrusion operation An empty shape for the sketch result --- diff --git a/src/ModuleBase/ModuleBase_FilterValidated.cpp b/src/ModuleBase/ModuleBase_FilterValidated.cpp index 20c169262..a6336d353 100644 --- a/src/ModuleBase/ModuleBase_FilterValidated.cpp +++ b/src/ModuleBase/ModuleBase_FilterValidated.cpp @@ -4,61 +4,25 @@ // 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 - +#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); + ModuleBase_Operation* anOperation = myWorkshop->module()->currentOperation(); + ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel(); - 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; + ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget(); + ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast + (anActiveWidget); + return !aWidgetValidated || aWidgetValidated->isValid(theOwner); } diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index 1e467d859..ffe513947 100644 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -69,6 +69,10 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject /// Realizes some functionality by an operation abort virtual void operationAborted(ModuleBase_Operation* theOperation) {} + /// Realizes some functionality by an operation start + /// \param theOperation a started operation + virtual ModuleBase_Operation* currentOperation() const = 0; + /// Add menu atems for viewer into the given menu /// \param theMenu a popup menu to be shown in the viewer virtual void addViewerItems(QMenu* theMenu) const {} diff --git a/src/ModuleBase/ModuleBase_IWorkshop.cpp b/src/ModuleBase/ModuleBase_IWorkshop.cpp index 4531933bc..6105bf263 100644 --- a/src/ModuleBase/ModuleBase_IWorkshop.cpp +++ b/src/ModuleBase/ModuleBase_IWorkshop.cpp @@ -7,6 +7,17 @@ #include "ModuleBase_IWorkshop.h" #include "ModuleBase_FilterFactory.h" +ModuleBase_IWorkshop::ModuleBase_IWorkshop(QObject* theParent) +: QObject(theParent) +{ + myValidatorFilter = new ModuleBase_FilterValidated(this); +} + +Handle(ModuleBase_FilterValidated) ModuleBase_IWorkshop::validatorFilter() +{ + return myValidatorFilter; +} + ModuleBase_FilterFactory* ModuleBase_IWorkshop::selectionFilters() const { static ModuleBase_FilterFactory* aFactory = new ModuleBase_FilterFactory; diff --git a/src/ModuleBase/ModuleBase_IWorkshop.h b/src/ModuleBase/ModuleBase_IWorkshop.h index b7f02f4a1..3646e630c 100644 --- a/src/ModuleBase/ModuleBase_IWorkshop.h +++ b/src/ModuleBase/ModuleBase_IWorkshop.h @@ -9,6 +9,7 @@ #include "ModuleBase.h" #include "ModuleBase_Definitions.h" +#include #include #include @@ -31,9 +32,7 @@ Q_OBJECT public: /// Constructor /// \param theParent parent object - ModuleBase_IWorkshop(QObject* theParent) - : QObject(theParent) - {} + ModuleBase_IWorkshop(QObject* theParent); virtual ~ModuleBase_IWorkshop() {} @@ -54,6 +53,10 @@ Q_OBJECT //! Returns current viewer virtual ModuleBase_IViewer* viewer() const = 0; + /// A filter to process an attribute validators + /// \return a filter + Handle(ModuleBase_FilterValidated) validatorFilter(); + //! Returns the factory of selection filters : the only one instance per application ModuleBase_FilterFactory* selectionFilters() const; @@ -80,6 +83,9 @@ signals: /// Signal which is emited after activation of property panel void propertyPanelActivated(); +protected: + /// A filter to process an attribute validators + Handle(ModuleBase_FilterValidated) myValidatorFilter; }; #endif diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.cpp b/src/ModuleBase/ModuleBase_WidgetValidated.cpp index a6f05af60..509814ee6 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.cpp +++ b/src/ModuleBase/ModuleBase_WidgetValidated.cpp @@ -3,18 +3,21 @@ #include #include #include -#include #include #include #include +#include + +#include +#include #include ModuleBase_WidgetValidated::ModuleBase_WidgetValidated(QWidget* theParent, const Config_WidgetAPI* theData, const std::string& theParentId) - : ModuleBase_ModelWidget(theParent, theData, theParentId) + : ModuleBase_ModelWidget(theParent, theData, theParentId) { } @@ -22,6 +25,47 @@ ModuleBase_WidgetValidated::~ModuleBase_WidgetValidated() { } +bool ModuleBase_WidgetValidated::isValid(const Handle_SelectMgr_EntityOwner& theOwner) +{ + backupAttributeValue(true); + + setValue(theOwner); + bool aValid = isValidAttribute(); + backupAttributeValue(false); + + return aValid; +} + +//******************************************************************** +bool ModuleBase_WidgetValidated::isValidAttribute() const +{ + SessionPtr aMgr = ModelAPI_Session::get(); + ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + std::list aValidators; + std::list > anArguments; + aFactory->validators(parentID(), attributeID(), aValidators, anArguments); + + DataPtr aData = myFeature->data(); + AttributePtr anAttribute = myFeature->attribute(attributeID()); + + aData->blockSendAttributeUpdated(true); + + // 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_AttributeValidator* aAttrValidator = + dynamic_cast(*aValidator); + if (aAttrValidator) { + aValid = aAttrValidator->isValid(anAttribute, *aArgs); + } + } + aData->blockSendAttributeUpdated(false); + + return aValid; +} + //******************************************************************** bool ModuleBase_WidgetValidated::isValid(ObjectPtr theObj, GeomShapePtr theShape) const { @@ -52,7 +96,13 @@ void ModuleBase_WidgetValidated::activateFilters(ModuleBase_IWorkshop* theWorksh const bool toActivate) const { ModuleBase_IViewer* aViewer = theWorkshop->viewer(); - + /* + Handle(SelectMgr_Filter) aSelFilter = theWorkshop->validatorFilter(); + if (toActivate) + aViewer->addSelectionFilter(aSelFilter); + else + aViewer->removeSelectionFilter(aSelFilter);*/ + // apply filters loaded from the XML definition of the widget ModuleBase_FilterFactory* aFactory = theWorkshop->selectionFilters(); SelectMgr_ListOfFilter aFactoryFilters; diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.h b/src/ModuleBase/ModuleBase_WidgetValidated.h index 014668e12..03b3175ce 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.h +++ b/src/ModuleBase/ModuleBase_WidgetValidated.h @@ -19,6 +19,7 @@ class QWidget; class ModuleBase_IWorkshop; class Config_WidgetAPI; +class Handle_SelectMgr_EntityOwner; /** * \ingroup GUI @@ -37,7 +38,27 @@ class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidg const std::string& theParentId); virtual ~ModuleBase_WidgetValidated(); + /// Checks all widget validator if the owner is valid + /// \param theOwner a selected owner in the view + /// \return a boolean value + bool isValid(const Handle_SelectMgr_EntityOwner& theOwner); + protected: + /// Creates a backup of the current values of the attribute + /// It should be realized in the specific widget because of different + /// parameters of the current attribute + /// \param isBackup a boolean flag, if true, store values from the attribute + /// to backup, otherwise set the backed up values to the attribute + virtual void backupAttributeValue(const bool isBackup) {}//= 0; + + /// Fills the attribute with the value of the selected owner + /// \param theOwner a selected owner + virtual void setValue(const Handle_SelectMgr_EntityOwner& theOwner) {}//= 0; + + /// Checks the current attibute in all attribute validators + // \return true if all validators return that the attribute is valid + bool isValidAttribute() const; + /// Check the selected with validators if installed /// \param theObj the object for checking /// \param theShape the shape for checking diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index cb62b8797..83f59bfe6 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -218,6 +218,13 @@ void PartSet_Module::operationStopped(ModuleBase_Operation* theOperation) myWorkshop->viewer()->removeSelectionFilter(myDocumentShapeFilter); } +ModuleBase_Operation* PartSet_Module::currentOperation() const +{ + XGUI_ModuleConnector* aConnector = dynamic_cast(workshop()); + XGUI_OperationMgr* anOpMgr = aConnector->workshop()->operationMgr(); + return anOpMgr->currentOperation(); +} + bool PartSet_Module::canUndo() const { bool aCanUndo = false; diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 138ffb3de..11214c096 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -79,6 +79,10 @@ public: /// \param theOperation a stopped operation virtual void operationStopped(ModuleBase_Operation* theOperation); + /// Realizes some functionality by an operation start + /// \param theOperation a started operation + virtual ModuleBase_Operation* currentOperation() const; + /// Returns action according to the given ID /// \param theId an action identifier, it should be uniqued in the bounds of the module QAction* action(const QString& theId) const; diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index bfdf8a5d5..da11c4d8e 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -19,7 +19,6 @@ #include #include -#include #include @@ -232,8 +231,6 @@ 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;