From dfb689721a73f8b65b0f61b593ef6421409bbf7b Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 3 Jul 2015 22:30:24 +0300 Subject: [PATCH] Shape plane filter should process shapes of objects selected in object browser. Final modification to use filters from context in:1. preselection processing, 2. onSelectionChanged[for objects from OB only] --- src/ModuleBase/ModuleBase_FilterValidated.cpp | 4 +- src/ModuleBase/ModuleBase_IModule.h | 3 + src/ModuleBase/ModuleBase_IPropertyPanel.h | 6 ++ src/ModuleBase/ModuleBase_ISelection.cpp | 25 ++++++ src/ModuleBase/ModuleBase_ISelection.h | 7 ++ src/ModuleBase/ModuleBase_Operation.cpp | 3 +- src/ModuleBase/ModuleBase_ViewerFilters.cpp | 26 +++---- src/ModuleBase/ModuleBase_WidgetSelector.cpp | 6 +- src/ModuleBase/ModuleBase_WidgetValidated.cpp | 77 +++++++++++++++++-- src/ModuleBase/ModuleBase_WidgetValidated.h | 22 +++++- src/PartSet/PartSet_Filters.cpp | 22 +++--- src/PartSet/PartSet_Module.cpp | 20 +++++ src/PartSet/PartSet_Module.h | 3 + src/PartSet/PartSet_WidgetSketchLabel.cpp | 4 +- src/XGUI/XGUI_ModuleConnector.cpp | 5 +- src/XGUI/XGUI_PropertyPanel.cpp | 11 +++ src/XGUI/XGUI_PropertyPanel.h | 8 ++ 17 files changed, 213 insertions(+), 39 deletions(-) diff --git a/src/ModuleBase/ModuleBase_FilterValidated.cpp b/src/ModuleBase/ModuleBase_FilterValidated.cpp index 28a43c3d7..38dc9a3f5 100644 --- a/src/ModuleBase/ModuleBase_FilterValidated.cpp +++ b/src/ModuleBase/ModuleBase_FilterValidated.cpp @@ -25,8 +25,10 @@ Standard_Boolean ModuleBase_FilterValidated::IsOk(const Handle(SelectMgr_EntityO ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel(); ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget(); + if (!anActiveWidget) + anActiveWidget = aPanel->preselectionWidget(); ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast - (anActiveWidget); + (anActiveWidget); ModuleBase_ViewerPrs aPrs; myWorkshop->selection()->fillPresentation(aPrs, theOwner); diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index 1ef962d28..f3e47d855 100644 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -164,6 +164,9 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject /// \param theOperation the operation virtual void sendOperation(ModuleBase_Operation* theOperation); + //! Returns data object by AIS + virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const = 0; + signals: void operationLaunched(); diff --git a/src/ModuleBase/ModuleBase_IPropertyPanel.h b/src/ModuleBase/ModuleBase_IPropertyPanel.h index 3a18c858b..59c2f8435 100644 --- a/src/ModuleBase/ModuleBase_IPropertyPanel.h +++ b/src/ModuleBase/ModuleBase_IPropertyPanel.h @@ -52,6 +52,12 @@ public: /// \return Enable/Disable state of Cancel button virtual bool isCancelEnabled() const = 0; + /// Returns widget processed by preselection + virtual ModuleBase_ModelWidget* preselectionWidget() const = 0; + + /// Sets widget processed by preselection + virtual void setPreselectionWidget(ModuleBase_ModelWidget* theWidget) = 0; + signals: /// The signal about key release on the control, that corresponds to the attribute /// \param theEvent key release event diff --git a/src/ModuleBase/ModuleBase_ISelection.cpp b/src/ModuleBase/ModuleBase_ISelection.cpp index 708382115..cff9fa134 100644 --- a/src/ModuleBase/ModuleBase_ISelection.cpp +++ b/src/ModuleBase/ModuleBase_ISelection.cpp @@ -2,6 +2,31 @@ #include "ModuleBase_ISelection.h" +//******************************************************************** +void ModuleBase_ISelection::appendSelected(const QList theValues, + QList& theValuesTo) +{ + // collect the objects from the viewer + QObjectPtrList anExistedObjects; + QList::const_iterator aPrsIt = theValuesTo.begin(), + aPrsLast = theValuesTo.end(); + for (; aPrsIt != aPrsLast; aPrsIt++) { + if ((*aPrsIt).owner() && (*aPrsIt).object()) + anExistedObjects.push_back((*aPrsIt).object()); + } + + + QList::const_iterator anIt = theValues.begin(), + aLast = theValues.end(); + for (; anIt != aLast; anIt++) { + ObjectPtr anObject = (*anIt).object(); + if (anObject.get() != NULL && !anExistedObjects.contains(anObject)) { + theValuesTo.append(ModuleBase_ViewerPrs(anObject, TopoDS_Shape(), NULL)); + } + } + +} + //******************************************************************** ResultPtr ModuleBase_ISelection::getResult(const ModuleBase_ViewerPrs& thePrs) { diff --git a/src/ModuleBase/ModuleBase_ISelection.h b/src/ModuleBase/ModuleBase_ISelection.h index 1de791add..ffe5e389f 100644 --- a/src/ModuleBase/ModuleBase_ISelection.h +++ b/src/ModuleBase/ModuleBase_ISelection.h @@ -38,6 +38,13 @@ class ModuleBase_ISelection /// \return list of presentations virtual QList getSelected(const SelectionPlace& thePlace = Browser) const = 0; + /// The values are appended to the first parameter list if the first list does not contain an item + /// with the same object + /// \param theValues a list of new values + /// \param theValuesTo a list, that will be changed + static void appendSelected(const QList theValues, + QList& theValuesTo); + /// Returns a list of viewer highlited presentations /// \return list of presentations virtual QList getHighlighted() const = 0; diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 0cfb98630..cf100595e 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -287,7 +287,7 @@ void ModuleBase_Operation::activateByPreselection() aWgt = (*aWIt); if (!aWgt->canSetValue()) continue; - + myPropertyPanel->setPreselectionWidget(aWgt); if (!aWgt->setSelection(myPreSelection, true)) { isSet = false; break; @@ -296,6 +296,7 @@ void ModuleBase_Operation::activateByPreselection() aFilledWgt = aWgt; } } + myPropertyPanel->setPreselectionWidget(NULL); // in order to redisplay object in the viewer, the update/redisplay signals should be flushed // it is better to perform it not in setSelection of each widget, but do it here, // after the preselection is processed diff --git a/src/ModuleBase/ModuleBase_ViewerFilters.cpp b/src/ModuleBase/ModuleBase_ViewerFilters.cpp index 70d555c8c..a7c1e7f64 100644 --- a/src/ModuleBase/ModuleBase_ViewerFilters.cpp +++ b/src/ModuleBase/ModuleBase_ViewerFilters.cpp @@ -37,24 +37,24 @@ Standard_Boolean ModuleBase_ShapeDocumentFilter::IsOk(const Handle(SelectMgr_Ent if (!anOperation) return true; + std::shared_ptr aAISObj = AISObjectPtr(new GeomAPI_AISObject()); if (theOwner->HasSelectable()) { - Handle(AIS_InteractiveObject) aAisObj = - Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable()); + 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); - if (aObj) { - DocumentPtr aDoc = aObj->document(); - SessionPtr aMgr = ModelAPI_Session::get(); - return (aDoc == aMgr->activeDocument() || aDoc == aMgr->moduleDocument()); - } - else { - // This is not object controlled by the filter - return Standard_True; - } } } + ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj); + if (aObj) { + DocumentPtr aDoc = aObj->document(); + SessionPtr aMgr = ModelAPI_Session::get(); + return (aDoc == aMgr->activeDocument() || aDoc == aMgr->moduleDocument()); + } + else { + // This object is not controlled by the filter + return Standard_True; + } return Standard_False; } diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.cpp b/src/ModuleBase/ModuleBase_WidgetSelector.cpp index e979b9c48..f720767df 100755 --- a/src/ModuleBase/ModuleBase_WidgetSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelector.cpp @@ -47,10 +47,9 @@ void ModuleBase_WidgetSelector::onSelectionChanged() { clearAttribute(); - QList aSelected = myWorkshop->selection()->getSelected( - ModuleBase_ISelection::AllControls); - bool isDone = setSelection(aSelected, true); + QList aSelected = getFilteredSelected(); + bool isDone = setSelection(aSelected, false); emit valuesChanged(); // the updateObject method should be called to flush the updated sigal. The workshop listens it, // calls validators for the feature and, as a result, updates the Apply button state. @@ -174,3 +173,4 @@ void ModuleBase_WidgetSelector::deactivate() activateSelection(false); activateFilters(false); } + diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.cpp b/src/ModuleBase/ModuleBase_WidgetValidated.cpp index 94f837e92..e00fd8094 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.cpp +++ b/src/ModuleBase/ModuleBase_WidgetValidated.cpp @@ -54,38 +54,55 @@ bool ModuleBase_WidgetValidated::setSelection(QList& theVa return isDone; } +//******************************************************************** +ObjectPtr ModuleBase_WidgetValidated::findPresentedObject(const AISObjectPtr& theAIS) const +{ + return myPresentedObject; +} + //******************************************************************** bool ModuleBase_WidgetValidated::isValidInFilters(const ModuleBase_ViewerPrs& thePrs) { bool aValid = true; Handle(SelectMgr_EntityOwner) anOwner = thePrs.owner(); - // if an owern is null, the selection happens in the Object browser. + // if an owner is null, the selection happens in the Object browser. // creates a selection owner on the base of object shape and the object AIS object if (anOwner.IsNull() && thePrs.owner().IsNull() && thePrs.object().get()) { ResultPtr aResult = myWorkshop->selection()->getResult(thePrs); if (aResult.get()) { GeomShapePtr aShape = aResult->shape(); - const TopoDS_Shape aTDShape = aShape->impl(); Handle(AIS_InteractiveObject) anIO = myWorkshop->selection()->getIO(thePrs); anOwner = new StdSelect_BRepOwner(aTDShape, anIO); + myPresentedObject = aResult; } + else + aValid = false; // only results can be filtered } - // finds + // checks the owner by the AIS context activated filters if (!anOwner.IsNull()) { + // the widget validator filter should be active, but during check by preselection + // it is not yet activated, so we need to activate/deactivate it manually + bool isActivated = isFilterActivated(); + if (!isActivated) + activateFilters(true); + const SelectMgr_ListOfFilter& aFilters = myWorkshop->viewer()->AISContext()->Filters(); SelectMgr_ListIteratorOfListOfFilter anIt(aFilters); for (; anIt.More() && aValid; anIt.Next()) { Handle(SelectMgr_Filter) aFilter = anIt.Value(); - //if (aFilter == myWorkshop->validatorFilter()) - // continue; aValid = aFilter->IsOk(anOwner); } + if (!isActivated) + activateFilters(false); } + // removes created owner - if (!anOwner.IsNull() && anOwner != thePrs.owner()) + if (!anOwner.IsNull() && anOwner != thePrs.owner()) { anOwner.Nullify(); + myPresentedObject = ObjectPtr(); + } return aValid; } @@ -178,6 +195,22 @@ bool ModuleBase_WidgetValidated::isValidAttribute() const return aValid; } +bool ModuleBase_WidgetValidated::isFilterActivated() const +{ + bool isActivated = false; + + Handle(SelectMgr_Filter) aSelFilter = myWorkshop->validatorFilter(); + + const SelectMgr_ListOfFilter& aFilters = myWorkshop->viewer()->AISContext()->Filters(); + SelectMgr_ListIteratorOfListOfFilter aIt(aFilters); + for (; aIt.More(); aIt.Next()) { + if (aSelFilter.Access() == aIt.Value().Access()) + isActivated = true; + } + return isActivated; +} + + void ModuleBase_WidgetValidated::activateFilters(const bool toActivate) { ModuleBase_IViewer* aViewer = myWorkshop->viewer(); @@ -241,3 +274,35 @@ void ModuleBase_WidgetValidated::clearValidState() myInvalidPrs.clear(); } +//******************************************************************** +QList ModuleBase_WidgetValidated::getFilteredSelected() +{ + QList aSelected = myWorkshop->selection()->getSelected( + ModuleBase_ISelection::Viewer); + + QList anOBSelected = myWorkshop->selection()->getSelected( + ModuleBase_ISelection::Browser); + // filter the OB presentations + filterPresentations(anOBSelected); + if (!anOBSelected.isEmpty()) + ModuleBase_ISelection::appendSelected(anOBSelected, aSelected); + + return aSelected; +} + +//******************************************************************** +void ModuleBase_WidgetValidated::filterPresentations(QList& theValues) +{ + QList aValidatedValues; + + QList::const_iterator anIt = theValues.begin(), aLast = theValues.end(); + bool isDone = false; + for (; anIt != aLast; anIt++) { + if (isValidInFilters(*anIt)) + aValidatedValues.append(*anIt); + } + if (aValidatedValues.size() != theValues.size()) { + theValues.clear(); + theValues = aValidatedValues; + } +} diff --git a/src/ModuleBase/ModuleBase_WidgetValidated.h b/src/ModuleBase/ModuleBase_WidgetValidated.h index 9861d4248..bafc219aa 100644 --- a/src/ModuleBase/ModuleBase_WidgetValidated.h +++ b/src/ModuleBase/ModuleBase_WidgetValidated.h @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -61,6 +62,10 @@ class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidg /// \param theValues the wrapped selection values virtual bool setSelection(QList& theValues, const bool theToValidate); + + //! Returns data object by AIS + ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const; + protected: /// Creates a backup of the current values of the attribute /// It should be realized in the specific widget because of different @@ -86,10 +91,14 @@ protected: // \return true if all validators return that the attribute is valid bool isValidAttribute() const; + /// Returns true if the workshop validator filter has been already activated + /// \return boolean value + bool isFilterActivated() const; + /// It obtains selection filters from the workshop and activates them in the active viewer /// \param theWorkshop an active workshop /// \param toActivate a flag about activation or deactivation the filters - virtual void activateFilters(const bool toActivate); + void activateFilters(const bool toActivate); /// Gets the validity state of the presentation in an internal map. Returns true if the valid state of value is stored /// \param theValue a viewer presentation @@ -104,10 +113,21 @@ protected: // Removes all presentations from internal maps. void clearValidState(); + /// Returns a list of selected presentations in the viewer and object browser + /// The presentations from the object browser are filtered by the AIS context filters + /// \return a list of presentations + QList getFilteredSelected(); + + /// Applies AIS context filters to the parameter list. The not approved presentations are + /// removed from the parameters. + /// \param theValues a list of presentations. + void filterPresentations(QList& theValues); + protected: ModuleBase_IWorkshop* myWorkshop; /// Reference to workshop private: + ObjectPtr myPresentedObject; /// back up of the filtered object QList myValidPrs; QList myInvalidPrs; bool isValidateBlocked; diff --git a/src/PartSet/PartSet_Filters.cpp b/src/PartSet/PartSet_Filters.cpp index 85038b426..0921844d6 100644 --- a/src/PartSet/PartSet_Filters.cpp +++ b/src/PartSet/PartSet_Filters.cpp @@ -28,24 +28,24 @@ Standard_Boolean PartSet_GlobalFilter::IsOk(const Handle(SelectMgr_EntityOwner)& return true; if (ModuleBase_ShapeDocumentFilter::IsOk(theOwner)) { + std::shared_ptr aAISObj = AISObjectPtr(new GeomAPI_AISObject()); 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); - if (aObj) { - FeaturePtr aFeature = ModelAPI_Feature::feature(aObj); - if (aFeature) { - return aFeature->getKind() != FeaturesPlugin_Group::ID(); - } else - return Standard_True; - } else - // This is not object controlled by the filter - return Standard_True; } } + ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj); + if (aObj) { + FeaturePtr aFeature = ModelAPI_Feature::feature(aObj); + if (aFeature) { + return aFeature->getKind() != FeaturesPlugin_Group::ID(); + } else + return Standard_True; + } else + // This is not object controlled by the filter + return Standard_True; } return Standard_False; } diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 8ad7937e4..938731a81 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -4,6 +4,7 @@ #include "PartSet_WidgetSketchLabel.h" #include "PartSet_Validators.h" #include "PartSet_Tools.h" +#include "ModuleBase_WidgetValidated.h" #include "PartSet_WidgetPoint2d.h" #include "PartSet_WidgetPoint2dDistance.h" #include "PartSet_WidgetShapeSelector.h" @@ -757,6 +758,25 @@ void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser) } } +ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const +{ + ObjectPtr anObject; + ModuleBase_Operation* aOperation = myWorkshop->currentOperation(); + if (aOperation) { + /// If last line finished on vertex the lines creation sequence has to be break + ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel(); + ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget(); + // if there is an active widget, find the presented object in it + if (!anActiveWidget) + anActiveWidget = aPanel->preselectionWidget(); + + ModuleBase_WidgetValidated* aWidgetValidated = dynamic_cast + (anActiveWidget); + if (aWidgetValidated) + anObject = aWidgetValidated->findPresentedObject(theAIS); + } + return anObject; +} void PartSet_Module::addObjectBrowserMenu(QMenu* theMenu) const { diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index f946512a5..eb64c79e4 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -164,6 +164,9 @@ public: /// Returns the viewer Z layer int getVisualLayerId() const { return myVisualLayerId; } + //! Returns data object by AIS + virtual ObjectPtr findPresentedObject(const AISObjectPtr& theAIS) const; + public slots: /// SLOT, that is called by no more widget signal emitted by property panel /// Set a specific flag to restart the sketcher operation diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index e9e43ba5a..fb2b86e60 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -104,8 +104,8 @@ QList PartSet_WidgetSketchLabel::getControls() const void PartSet_WidgetSketchLabel::onSelectionChanged() { - QList aSelected = myWorkshop->selection()->getSelected( - ModuleBase_ISelection::AllControls); + QList aSelected = getFilteredSelected(); + if (aSelected.empty()) return; ModuleBase_ViewerPrs aPrs = aSelected.first(); diff --git a/src/XGUI/XGUI_ModuleConnector.cpp b/src/XGUI/XGUI_ModuleConnector.cpp index 486b89b85..de204ffb4 100644 --- a/src/XGUI/XGUI_ModuleConnector.cpp +++ b/src/XGUI/XGUI_ModuleConnector.cpp @@ -99,7 +99,10 @@ AISObjectPtr XGUI_ModuleConnector::findPresentation(const ObjectPtr& theObject) ObjectPtr XGUI_ModuleConnector::findPresentedObject(const AISObjectPtr& theAIS) const { XGUI_Displayer* aDisp = myWorkshop->displayer(); - return aDisp->getObject(theAIS); + ObjectPtr anObject = aDisp->getObject(theAIS); + if (!anObject.get()) + anObject = module()->findPresentedObject(theAIS); + return anObject; } void XGUI_ModuleConnector::setSelected(const QList& theValues) diff --git a/src/XGUI/XGUI_PropertyPanel.cpp b/src/XGUI/XGUI_PropertyPanel.cpp index 6c53bb843..0a9c7189e 100644 --- a/src/XGUI/XGUI_PropertyPanel.cpp +++ b/src/XGUI/XGUI_PropertyPanel.cpp @@ -34,6 +34,7 @@ XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent) : ModuleBase_IPropertyPanel(theParent), myActiveWidget(NULL), + myPreselectionWidget(NULL), myPanelPage(NULL) { this->setWindowTitle(tr("Property Panel")); @@ -225,3 +226,13 @@ void XGUI_PropertyPanel::setupActions(XGUI_ActionsMgr* theMgr) aBtn->setDefaultAction(anAct); } } + +ModuleBase_ModelWidget* XGUI_PropertyPanel::preselectionWidget() const +{ + return myPreselectionWidget; +} + +void XGUI_PropertyPanel::setPreselectionWidget(ModuleBase_ModelWidget* theWidget) +{ + myPreselectionWidget = theWidget; +} diff --git a/src/XGUI/XGUI_PropertyPanel.h b/src/XGUI/XGUI_PropertyPanel.h index bc0934af5..6a982c1c6 100644 --- a/src/XGUI/XGUI_PropertyPanel.h +++ b/src/XGUI/XGUI_PropertyPanel.h @@ -88,6 +88,12 @@ Q_OBJECT //! Allows to set predefined actions for the property panel fetched from the ActionsMgr void setupActions(XGUI_ActionsMgr* theMgr); + /// Returns widget processed by preselection + virtual ModuleBase_ModelWidget* preselectionWidget() const; + + /// Sets widget processed by preselection + virtual void setPreselectionWidget(ModuleBase_ModelWidget* theWidget); + public slots: /// \brief Update all widgets in property panel with values from the given feature @@ -108,6 +114,8 @@ Q_OBJECT /// Currently active widget ModuleBase_ModelWidget* myActiveWidget; + /// Currently widget processed by preselection + ModuleBase_ModelWidget* myPreselectionWidget; }; #endif /* XGUI_PROPERTYPANEL_H_ */ -- 2.39.2