From 8e13a6fd505815aba8d7f64d10a5626817698e61 Mon Sep 17 00:00:00 2001 From: nds Date: Thu, 19 Mar 2015 12:28:50 +0300 Subject: [PATCH] Union of validator and filter functionalities. The selection is obtained from the entity owner instead of getting it from the viewer context. --- src/ModuleBase/ModuleBase_ISelection.h | 6 +- .../ModuleBase_WidgetMultiSelector.cpp | 12 +++ .../ModuleBase_WidgetMultiSelector.h | 11 +++ .../ModuleBase_WidgetShapeSelector.cpp | 86 ++++++++----------- .../ModuleBase_WidgetShapeSelector.h | 23 +++++ src/ModuleBase/ModuleBase_WidgetValidated.cpp | 9 +- src/ModuleBase/ModuleBase_WidgetValidated.h | 4 +- src/XGUI/XGUI_Selection.cpp | 59 +++++++++---- src/XGUI/XGUI_Selection.h | 12 ++- 9 files changed, 141 insertions(+), 81 deletions(-) diff --git a/src/ModuleBase/ModuleBase_ISelection.h b/src/ModuleBase/ModuleBase_ISelection.h index e3190488a..29829a39e 100644 --- a/src/ModuleBase/ModuleBase_ISelection.h +++ b/src/ModuleBase/ModuleBase_ISelection.h @@ -28,14 +28,12 @@ class ModuleBase_ISelection public: /// Returns a list of viewer selected presentations - /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build /// \return list of presentations - virtual QList getSelected(int theShapeTypeToSkip = -1) const = 0; + virtual QList getSelected() const = 0; /// Returns a list of viewer highlited presentations - /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build /// \return list of presentations - virtual QList getHighlighted(int theShapeTypeToSkip = -1) const = 0; + virtual QList getHighlighted() const = 0; /** * Returns list of features currently selected in object browser diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 22145d36f..c3bf95327 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -171,6 +171,18 @@ bool ModuleBase_WidgetMultiSelector::restoreValue() return false; } +//******************************************************************** +void ModuleBase_WidgetMultiSelector::backupAttributeValue(const bool isBackup) +{ + +} + +//******************************************************************** +void ModuleBase_WidgetMultiSelector::setSelection(const Handle_SelectMgr_EntityOwner& theOwner) +{ + +} + //******************************************************************** QList ModuleBase_WidgetMultiSelector::getControls() const { diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h index bdb1a46ed..e0b257ca4 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.h @@ -95,6 +95,17 @@ protected slots: /// \return True in success virtual bool storeValueCustom() const; + /// 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); + + /// Fills the attribute with the value of the selected owner + /// \param theOwner a selected owner + virtual void setSelection(const Handle_SelectMgr_EntityOwner& theOwner); + /// Set current shape type for selection void setCurrentShapeType(const TopAbs_ShapeEnum theShapeType); diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index a2034fce6..ec7defe22 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -448,6 +448,41 @@ void ModuleBase_WidgetShapeSelector::activateCustom() activateSelection(true); } +//******************************************************************** +void ModuleBase_WidgetShapeSelector::backupAttributeValue(const bool isBackup) +{ + DataPtr aData = myFeature->data(); + AttributePtr anAttribute = myFeature->attribute(attributeID()); + + if (isBackup) { + myObject = getObject(anAttribute); + myShape = getShape(); + myRefAttribute = NULL; + myIsObject = false; + AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); + if (aRefAttr) { + myIsObject = aRefAttr->isObject(); + myRefAttribute = aRefAttr->attr(); + } + } + else { + storeAttributeValues(myObject, myShape); + AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); + if (aRefAttr) { + if (myIsObject) + aRefAttr->setObject(myObject); + else + aRefAttr->setAttr(myRefAttribute); + } + } +} + +//******************************************************************** +void ModuleBase_WidgetShapeSelector::setSelection(const Handle_SelectMgr_EntityOwner& theOwner) +{ + +} + //******************************************************************** void ModuleBase_WidgetShapeSelector::deactivate() { @@ -472,19 +507,9 @@ bool ModuleBase_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptrattribute(attributeID()); // 1. make a backup of the previous attribute values - ObjectPtr aPrevObject = getObject(anAttribute); - GeomShapePtr aPrevShape = getShape(); - AttributePtr aPrevAttribute; - bool aPrevIsObject = false; - AttributeRefAttrPtr aRefAttr = aData->refattr(attributeID()); - if (aRefAttr) { - aPrevIsObject = aRefAttr->isObject(); - aPrevAttribute = aRefAttr->attr(); - } - + backupAttributeValue(true); // 2. store the current values, disable the model's update aData->blockSendAttributeUpdated(true); - storeAttributeValues(theObj, theShape); // 3. check the acceptability of the current values std::list::iterator aValidator = aValidators.begin(); @@ -499,44 +524,9 @@ bool ModuleBase_WidgetShapeSelector::isValid(ObjectPtr theObj, std::shared_ptrsetObject(aPrevObject); - else - aRefAttr->setAttr(aPrevAttribute); - } + backupAttributeValue(false); // 5. enable the model's update aData->blockSendAttributeUpdated(false); - //updateObject(myFeature); - //return aValid; - - if (!aValid) - return false; - -/* // Check the acceptability of the object as attribute - std::list::iterator aValidator = aValidators.begin(); - std::list >::iterator aArgs = anArguments.begin(); - for (; aValidator != aValidators.end(); aValidator++, aArgs++) { - const ModelAPI_RefAttrValidator* aAttrValidator = - dynamic_cast(*aValidator); - if (aAttrValidator) { - //if (!aAttrValidator->isValid(myFeature, *aArgs, theObj)) { - // return false; - //} - } - else { - const ModelAPI_ShapeValidator* aShapeValidator = - dynamic_cast(*aValidator); - if (aShapeValidator) { - DataPtr aData = myFeature->data(); - AttributeSelectionPtr aSelectAttr = aData->selection(attributeID()); - if (!aShapeValidator->isValid(myFeature, *aArgs, theObj, aSelectAttr, theShape)) { - return false; - } - } - } - }*/ - return true; + return aValid; } diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index fe4d0cb49..ca735d532 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -110,6 +110,17 @@ Q_OBJECT /// The methiod called when widget is activated virtual void activateCustom(); + /// 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); + + /// Fills the attribute with the value of the selected owner + /// \param theOwner a selected owner + virtual void setSelection(const Handle_SelectMgr_EntityOwner& theOwner); + /// Computes and updates name of selected object in the widget void updateSelectionName(); @@ -159,6 +170,18 @@ Q_OBJECT /// Active/inactive flag bool myIsActive; + + /// backup parameters of the model attribute. The class processes three types of attribute: + /// Reference, RefAttr and Selection. Depending on the attribute type, only the attribute parameter + /// values are reserved in the backup + /// An attribute object + ObjectPtr myObject; + /// An attribute shape + GeomShapePtr myShape; + /// A reference of the attribute + AttributePtr myRefAttribute; + /// A boolean value whether refAttr uses reference of object + bool myIsObject; }; #endif diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.cpp b/src/ModuleBase/ModuleBase_WidgetValidated.cpp index 509814ee6..d81ec7970 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.cpp +++ b/src/ModuleBase/ModuleBase_WidgetValidated.cpp @@ -29,8 +29,9 @@ bool ModuleBase_WidgetValidated::isValid(const Handle_SelectMgr_EntityOwner& the { backupAttributeValue(true); - setValue(theOwner); + setSelection(theOwner); bool aValid = isValidAttribute(); + backupAttributeValue(false); return aValid; @@ -96,13 +97,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);*/ - + 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 03b3175ce..90a83677e 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.h +++ b/src/ModuleBase/ModuleBase_WidgetValidated.h @@ -49,11 +49,11 @@ protected: /// 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; + 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; + virtual void setSelection(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 diff --git a/src/XGUI/XGUI_Selection.cpp b/src/XGUI/XGUI_Selection.cpp index 30c623181..0de6255da 100644 --- a/src/XGUI/XGUI_Selection.cpp +++ b/src/XGUI/XGUI_Selection.cpp @@ -15,8 +15,11 @@ #include #include +#include + #include #include +#include #include @@ -25,7 +28,7 @@ XGUI_Selection::XGUI_Selection(XGUI_Workshop* theWorkshop) { } -QList XGUI_Selection::getSelected(int theShapeTypeToSkip) const +QList XGUI_Selection::getSelected() const { QList aSelectedIds; // Remember of selected address in order to avoid duplicates @@ -39,25 +42,18 @@ QList XGUI_Selection::getSelected(int theShapeTypeToSkip) if (aContext->HasOpenedContext()) { for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) { ModuleBase_ViewerPrs aPrs; - Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive(); - if (aSelectedIds.contains((long)anIO.Access())) + Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner(); + + if (aSelectedIds.contains((long)anOwner.Access())) continue; - - aSelectedIds.append((long)anIO.Access()); - aPrs.setInteractive(anIO); + aSelectedIds.append((long)anOwner.Access()); + + fillPresentation(aPrs, anOwner); - ObjectPtr aFeature = aDisplayer->getObject(anIO); - // we should not check the appearance of this feature because there can be some selected shapes - // for one feature - TopoDS_Shape aShape = aContext->SelectedShape(); - if (!aShape.IsNull() && (aShape.ShapeType() != theShapeTypeToSkip)) - aPrs.setShape(aShape); - Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner(); - aPrs.setOwner(anOwner); - aPrs.setFeature(aFeature); aPresentations.append(aPrs); } - } else { + } + /* else { for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent()) { ModuleBase_ViewerPrs aPrs; Handle(AIS_InteractiveObject) anIO = aContext->Current(); @@ -71,11 +67,36 @@ QList XGUI_Selection::getSelected(int theShapeTypeToSkip) aPrs.setFeature(aFeature); aPresentations.append(aPrs); } - } + }*/ return aPresentations; } -QList XGUI_Selection::getHighlighted(int theShapeTypeToSkip) const +void XGUI_Selection::fillPresentation(ModuleBase_ViewerPrs& thePrs, + const Handle(SelectMgr_EntityOwner)& theOwner) const +{ + thePrs.setOwner(theOwner); + + Handle(AIS_InteractiveObject) anIO = + Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable()); + thePrs.setInteractive(anIO); + + // we should not check the appearance of this feature because there can be some selected shapes + // for one feature + Handle(StdSelect_BRepOwner) aBRO = Handle(StdSelect_BRepOwner)::DownCast(theOwner); + if( !aBRO.IsNull() ) { + // the located method is called in the context to obtain the shape by the SelectedShape() method, + // so the shape is located by the same rules + TopoDS_Shape aShape = aBRO->Shape().Located (aBRO->Location() * aBRO->Shape().Location()); + if (!aShape.IsNull()) + thePrs.setShape(aShape); + } + + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + ObjectPtr aFeature = aDisplayer->getObject(anIO); + thePrs.setFeature(aFeature); +} + +QList XGUI_Selection::getHighlighted() const { QList aSelectedIds; // Remember of selected address in order to avoid duplicates QList aPresentations; @@ -97,7 +118,7 @@ QList XGUI_Selection::getHighlighted(int theShapeTypeToSki aPrs.setFeature(aResult); if (aContext->HasOpenedContext()) { TopoDS_Shape aShape = aContext->DetectedShape(); - if (!aShape.IsNull() && aShape.ShapeType() != theShapeTypeToSkip) + if (!aShape.IsNull()) aPrs.setShape(aShape); } aPresentations.push_back(aPrs); diff --git a/src/XGUI/XGUI_Selection.h b/src/XGUI/XGUI_Selection.h index f766841d6..9d6848ccd 100644 --- a/src/XGUI/XGUI_Selection.h +++ b/src/XGUI/XGUI_Selection.h @@ -21,6 +21,7 @@ #include class XGUI_Workshop; +class Handle_SelectMgr_EntityOwner; /** * \ingroup GUI @@ -34,14 +35,17 @@ class XGUI_EXPORT XGUI_Selection : public ModuleBase_ISelection XGUI_Selection(XGUI_Workshop* theWorkshop); /// Returns a list of viewer selected presentations - /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build /// \return list of presentations - virtual QList getSelected(int theShapeTypeToSkip = -1) const; + virtual QList getSelected() const; + + /// Fills the viewer presentation parameters by the parameters from the owner + /// \param thePrs a container for selection + /// \param theOwner a selection owner + void fillPresentation(ModuleBase_ViewerPrs& thePrs, const Handle_SelectMgr_EntityOwner& theOwner) const; /// Returns a list of viewer highlited presentations - /// \param theShapeTypeToSkip the shapes with this type will be skipped during the result list build /// \return list of presentations - virtual QList getHighlighted(int theShapeTypeToSkip = -1) const; + virtual QList getHighlighted() const; /** * Returns list of currently selected objects in object browser -- 2.39.2