From: vsv Date: Wed, 5 Jun 2019 16:56:12 +0000 (+0300) Subject: Create filter "Belongs To" X-Git-Tag: VEDF2019Lot4~101^2~40 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=01dbd58cc4ad49d9ff5c506257572a269e1d599d;p=modules%2Fshaper.git Create filter "Belongs To" --- diff --git a/src/FiltersPlugin/FiltersPlugin_BelongsTo.cpp b/src/FiltersPlugin/FiltersPlugin_BelongsTo.cpp index f2c9d88fc..45a045e0a 100644 --- a/src/FiltersPlugin/FiltersPlugin_BelongsTo.cpp +++ b/src/FiltersPlugin/FiltersPlugin_BelongsTo.cpp @@ -29,12 +29,23 @@ bool FiltersPlugin_BelongsTo::isSupported(GeomAPI_Shape::ShapeType theType) cons bool FiltersPlugin_BelongsTo::isOk(const GeomShapePtr& theShape, const ModelAPI_FiltersArgs& theArgs) const { - return true; + AttributePtr aAttr = theArgs.argument("BelongsTo"); + AttributeSelectionListPtr aList = + std::dynamic_pointer_cast(aAttr); + if (!aList.get()) + return false; + for (int i = 0; i < aList->size(); i++) { + AttributeSelectionPtr aAttr = aList->value(i); + GeomShapePtr aGeom = aAttr->value(); + if (aGeom->isSubShape(theShape)) + return true; + } + return false; } static std::string XMLRepresentation = -"" -" " +" " @@ -49,5 +60,5 @@ std::string FiltersPlugin_BelongsTo::xmlRepresentation() const void FiltersPlugin_BelongsTo::initAttributes(ModelAPI_FiltersArgs& theArguments) { - theArguments.initAttribute("Belongs to", ModelAPI_AttributeSelectionList::typeId()); + theArguments.initAttribute("BelongsTo", ModelAPI_AttributeSelectionList::typeId()); } diff --git a/src/Model/Model_Filter.cpp b/src/Model/Model_Filter.cpp index b0592b35e..14905d040 100644 --- a/src/Model/Model_Filter.cpp +++ b/src/Model/Model_Filter.cpp @@ -33,11 +33,17 @@ void Model_FiltersFactory::registerFilter(const std::string& theID, ModelAPI_Fil } } +struct FilterArgs { + FilterPtr myFilter; + bool myReverse; + std::string myFilterID; +}; + bool Model_FiltersFactory::isValid(FeaturePtr theFiltersFeature, GeomShapePtr theShape) { // prepare all filters args ModelAPI_FiltersArgs anArgs; - std::map aReverseFlags; /// map of all filters to the reverse values + std::list aFilters; /// all filters and the reverse values std::list aGroups; theFiltersFeature->data()->allGroups(aGroups); @@ -53,7 +59,9 @@ bool Model_FiltersFactory::isValid(FeaturePtr theFiltersFeature, GeomShapePtr th if (anArgID.empty()) { // reverse flag std::shared_ptr aReverse = std::dynamic_pointer_cast(*anAttrIter); - aReverseFlags[myFilters[*aGIter] ] = aReverse->value(); + FilterArgs aFArgs = { myFilters[*aGIter] , aReverse->value() , *aGIter }; + aFilters.push_back(aFArgs); + } else { anArgs.add(*anAttrIter); } @@ -61,10 +69,11 @@ bool Model_FiltersFactory::isValid(FeaturePtr theFiltersFeature, GeomShapePtr th } // iterate filters and check shape for validity for all of them - std::map::iterator aFilter = aReverseFlags.begin(); - for(; aFilter != aReverseFlags.end(); aFilter++) { - bool aResult = aFilter->first->isOk(theShape, anArgs); - if (aFilter->second) + std::list::iterator aFilter = aFilters.begin(); + for(; aFilter != aFilters.end(); aFilter++) { + anArgs.setFilter(aFilter->myFilterID); + bool aResult = aFilter->myFilter->isOk(theShape, anArgs); + if (aFilter->myReverse) aResult = !aResult; if (!aResult) // one filter is failed => exit immediately return false; diff --git a/src/ModelAPI/ModelAPI_Filter.h b/src/ModelAPI/ModelAPI_Filter.h index 758ece648..a900548bf 100644 --- a/src/ModelAPI/ModelAPI_Filter.h +++ b/src/ModelAPI/ModelAPI_Filter.h @@ -87,7 +87,7 @@ public: } /// returns the argument of the current filter by the argument id - AttributePtr argument(const std::string& theID) { + AttributePtr argument(const std::string& theID) const { return myMap.find(myCurrentFilter + kFilterSeparator + theID)->second; } /// adds an attribute of the filter diff --git a/src/ModuleBase/ModuleBase_IWorkshop.h b/src/ModuleBase/ModuleBase_IWorkshop.h index 5877823bd..c3558145b 100644 --- a/src/ModuleBase/ModuleBase_IWorkshop.h +++ b/src/ModuleBase/ModuleBase_IWorkshop.h @@ -138,6 +138,8 @@ Q_OBJECT /// \return boolean value virtual bool hasSHIFTPressed() const = 0; + virtual void deactivateCurrentSelector() = 0; + signals: /// Signal selection changed. void selectionChanged(); diff --git a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp index bccb9032b..a8b818e26 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp @@ -20,6 +20,7 @@ #include "ModuleBase_WidgetSelectionFilter.h" #include "ModuleBase_Tools.h" #include "ModuleBase_IWorkshop.h" +#include "ModuleBase_ISelectionActivate.h" #include "ModuleBase_IModule.h" #include "ModuleBase_IViewer.h" #include "ModuleBase_IPropertyPanel.h" @@ -30,8 +31,11 @@ #include #include +#include #include +#include + #include #include #include @@ -142,11 +146,16 @@ ModuleBase_FilterItem::ModuleBase_FilterItem( aLayout->addWidget(aItemRow); ModuleBase_PageWidget* aParamsWgt = new ModuleBase_PageWidget(this); + aParamsWgt->setFrameStyle(QFrame::Box | QFrame::Raised); aFactory.createWidget(aParamsWgt); ModuleBase_Tools::zeroMargins(aParamsWgt->layout()); - QList aWidgets = aFactory.getModelWidgets(); - foreach(ModuleBase_ModelWidget* aWidget, aWidgets) { + myWidgets = aFactory.getModelWidgets(); + foreach(ModuleBase_ModelWidget* aWidget, myWidgets) { aWidget->setFeature(theParent->feature()); + connect(aWidget, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)), + theParent, SIGNAL(focusInWidget(ModuleBase_ModelWidget*))); + connect(aWidget, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)), + theParent, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*))); } aLayout->addWidget(aParamsWgt); } @@ -193,6 +202,19 @@ void ModuleBase_FilterItem::onDelete() emit deleteItem(this); } +QList ModuleBase_FilterItem::getControls() const +{ + QList aWidgetsList; + foreach(ModuleBase_ModelWidget* aWgt, myWidgets) { + QList aSubList = aWgt->getControls(); + foreach(QWidget* aSub, aSubList) { + aWidgetsList.append(aSub); + } + } + return aWidgetsList; +} + + //***************************************************************************** //***************************************************************************** @@ -333,11 +355,17 @@ void ModuleBase_WidgetSelectionFilter::onAddFilter(int theIndex) updateNumberSelected(); myFiltersCombo->setCurrentIndex(0); myFiltersCombo->removeItem(theIndex); + + enableFocusProcessing(); } void ModuleBase_WidgetSelectionFilter::onDeleteItem(ModuleBase_FilterItem* theItem) { std::string aFilter = theItem->filter(); + QList aWidgets = theItem->widgets(); + foreach(ModuleBase_ModelWidget* aWgt, aWidgets) { + aWgt->deactivate(); + } myFiltersLayout->removeWidget(theItem); theItem->deleteLater(); @@ -352,6 +380,20 @@ void ModuleBase_WidgetSelectionFilter::onDeleteItem(ModuleBase_FilterItem* theIt updateSelectBtn(); clearCurrentSelection(true); updateNumberSelected(); + + enableFocusProcessing(); + myWorkshop->deactivateCurrentSelector(); + myWorkshop->selectionActivate()->updateSelectionModes(); + myWorkshop->selectionActivate()->updateSelectionFilters(); + redisplayFeature(); +} + + +void ModuleBase_WidgetSelectionFilter::redisplayFeature() +{ + static Events_ID aDispEvent = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY); + ModelAPI_EventCreator::get()->sendUpdated(myFeature, aDispEvent); + Events_Loop::loop()->flush(aDispEvent); } void ModuleBase_WidgetSelectionFilter::onReverseItem(ModuleBase_FilterItem* theItem) @@ -419,8 +461,9 @@ void ModuleBase_WidgetSelectionFilter::updatePreview(const TopoDS_Shape& theShap if (myPreview.IsNull()) { myPreview = new AIS_Shape(theShape); - myPreview->SetDisplayMode(myShowBtn->isChecked()? AIS_Shaded : AIS_WireFrame); - myPreview->SetColor(Quantity_NOC_YELLOW); + //myPreview->SetDisplayMode(myShowBtn->isChecked()? AIS_Shaded : AIS_WireFrame); + myPreview->SetDisplayMode(AIS_Shaded); + myPreview->SetColor(Quantity_NOC_BLUE1); myPreview->SetTransparency(); aCtx->Display(myPreview, true); aCtx->Deactivate(myPreview); @@ -439,14 +482,10 @@ void ModuleBase_WidgetSelectionFilter::onShowOnly(bool theShow) Handle(AIS_InteractiveContext) aCtx = myWorkshop->viewer()->AISContext(); if (theShow) { - aCtx->SetDisplayMode(myPreview, AIS_Shaded, false); myListIO.Clear(); aCtx->DisplayedObjects(AIS_KOI_Shape, -1, myListIO); myListIO.Remove(myPreview); } - else { - aCtx->SetDisplayMode(myPreview, AIS_WireFrame, false); - } AIS_ListOfInteractive::const_iterator aIt; Handle(AIS_Shape) aShapeIO; for (aIt = myListIO.cbegin(); aIt != myListIO.cend(); aIt++) { @@ -472,7 +511,15 @@ void ModuleBase_WidgetSelectionFilter::updateNumberSelected() } QList ModuleBase_WidgetSelectionFilter::getControls() const { - return QList(); + QList aWidgets; + QList aItems = myFiltersWgt->findChildren(); + foreach(ModuleBase_FilterItem* aItem, aItems) { + QList aSubList = aItem->getControls(); + foreach(QWidget* aWgt, aSubList) { + aWidgets.append(aWgt); + } + } + return aWidgets; } void ModuleBase_WidgetSelectionFilter::clearCurrentSelection(bool toUpdate) @@ -494,4 +541,17 @@ void ModuleBase_WidgetSelectionFilter::onFeatureAccepted() foreach(ModuleBase_ViewerPrsPtr aPrs, myValues) { aSelListAttr->append(aPrs->object(), aPrs->shape()); } -} \ No newline at end of file +} + +bool ModuleBase_WidgetSelectionFilter::storeValueCustom() +{ + return true; +} + +bool ModuleBase_WidgetSelectionFilter::restoreValueCustom() +{ + ModuleBase_ModelWidget* aActive = myWorkshop->propertyPanel()->activeWidget(); + if (aActive) + return aActive->restoreValue(); + return true; +} diff --git a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h index 8753d1290..10c039faa 100644 --- a/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h +++ b/src/ModuleBase/ModuleBase_WidgetSelectionFilter.h @@ -74,6 +74,14 @@ public: std::string filter() const { return myFilterID; } + /// Returns list of widget controls + /// \return a control list + QList getControls() const; + + QList widgets() const { + return myWidgets; + } + signals: void deleteItem(ModuleBase_FilterItem* theItem); void reversedItem(ModuleBase_FilterItem* theItem); @@ -88,6 +96,7 @@ private: std::string myFilterID; FiltersFeaturePtr mySelection; QToolButton* myRevBtn; + QList myWidgets; }; class ModuleBase_WidgetSelectionFilter : public ModuleBase_ModelWidget @@ -114,10 +123,10 @@ public: protected: /// Saves the internal parameters to the given feature (not ussed for this widget) /// \return True in success - virtual bool storeValueCustom() { return true; } + virtual bool storeValueCustom(); /// Restore value from attribute data to the widget's control (not ussed for this widget) - virtual bool restoreValueCustom() { return true; } + virtual bool restoreValueCustom(); private slots: void onAddFilter(int); @@ -131,6 +140,7 @@ private: void updateNumberSelected(); void clearCurrentSelection(bool toUpdate = false); void updatePreview(const TopoDS_Shape& theShape); + void redisplayFeature(); private: ModuleBase_IWorkshop* myWorkshop; diff --git a/src/XGUI/XGUI_ActiveControlMgr.cpp b/src/XGUI/XGUI_ActiveControlMgr.cpp index beffebcee..a976b6c3f 100644 --- a/src/XGUI/XGUI_ActiveControlMgr.cpp +++ b/src/XGUI/XGUI_ActiveControlMgr.cpp @@ -93,7 +93,13 @@ void XGUI_ActiveControlMgr::onSelectorActivated() void XGUI_ActiveControlMgr::onSelectorDeactivated() { XGUI_ActiveControlSelector* aSelector = qobject_cast(sender()); - if (!aSelector || aSelector != myActiveSelector || !myActiveSelector) + deactivateSelector(aSelector); +} + +//******************************************************************** +void XGUI_ActiveControlMgr::deactivateSelector(XGUI_ActiveControlSelector* theSelector) +{ + if (!theSelector || theSelector != myActiveSelector || !myActiveSelector) return; if (myIsBlocked) // we've come here from the same method @@ -104,8 +110,7 @@ void XGUI_ActiveControlMgr::onSelectorDeactivated() activateSelector(NULL); XGUI_ActiveControlSelector* aSelectorToBeActivated = 0; - for (int i = 0, aCount = mySelectors.count(); i < aCount; i++) - { + for (int i = 0, aCount = mySelectors.count(); i < aCount; i++) { if (!mySelectors[i]->needToBeActiated()) continue; aSelectorToBeActivated = mySelectors[i]; diff --git a/src/XGUI/XGUI_ActiveControlMgr.h b/src/XGUI/XGUI_ActiveControlMgr.h index 863fa1bc6..31862571f 100644 --- a/src/XGUI/XGUI_ActiveControlMgr.h +++ b/src/XGUI/XGUI_ActiveControlMgr.h @@ -56,6 +56,8 @@ public: /// \return selector instance XGUI_ActiveControlSelector* activeSelector() const { return myActiveSelector; } + void deactivateSelector(XGUI_ActiveControlSelector* theSelector); + protected slots: /// Deactivates active selector and set the sender selector as active void onSelectorActivated(); diff --git a/src/XGUI/XGUI_ModuleConnector.cpp b/src/XGUI/XGUI_ModuleConnector.cpp index 2f41e3659..fee5e9fde 100644 --- a/src/XGUI/XGUI_ModuleConnector.cpp +++ b/src/XGUI/XGUI_ModuleConnector.cpp @@ -211,3 +211,8 @@ std::shared_ptr XGUI_ModuleConnector::featureInfo(const Q return std::shared_ptr(); #endif } + +void XGUI_ModuleConnector::deactivateCurrentSelector() +{ + myWorkshop->deactivateCurrentSelector(); +} diff --git a/src/XGUI/XGUI_ModuleConnector.h b/src/XGUI/XGUI_ModuleConnector.h index ca97352fb..07fafe383 100644 --- a/src/XGUI/XGUI_ModuleConnector.h +++ b/src/XGUI/XGUI_ModuleConnector.h @@ -119,6 +119,8 @@ Q_OBJECT /// \return boolean value virtual bool hasSHIFTPressed() const; + virtual void deactivateCurrentSelector(); + //! Returns workshop XGUI_Workshop* workshop() const { return myWorkshop; } diff --git a/src/XGUI/XGUI_PropertyPanel.cpp b/src/XGUI/XGUI_PropertyPanel.cpp index 65180f91a..7bfd6a3d4 100644 --- a/src/XGUI/XGUI_PropertyPanel.cpp +++ b/src/XGUI/XGUI_PropertyPanel.cpp @@ -155,8 +155,10 @@ void XGUI_PropertyPanel::cleanContent() myPanelPage->clearPage(); myActiveWidget = NULL; emit propertyPanelDeactivated(); - myOperationMgr->workshop()->selectionActivate()->updateSelectionModes(); - myOperationMgr->workshop()->selectionActivate()->updateSelectionFilters(); + // VSV: It seems that this code is not necessary: + // it is called on propertyPanelDeactivated() event + //myOperationMgr->workshop()->selectionActivate()->updateSelectionModes(); + //myOperationMgr->workshop()->selectionActivate()->updateSelectionFilters(); #ifdef DEBUG_ACTIVE_WIDGET std::cout << "myActiveWidget = NULL" << std::endl; #endif diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index d54412c59..49ab30197 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -2934,3 +2934,8 @@ void XGUI_Workshop::onDockSizeChanged() disconnect(myObjectBrowser, SIGNAL(sizeChanged()), this, SLOT(onDockSizeChanged())); } } + +void XGUI_Workshop::deactivateCurrentSelector() +{ + myActiveControlMgr->deactivateSelector(myActiveControlMgr->activeSelector()); +} diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index e7da8532d..ccd7c725e 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -325,6 +325,8 @@ Q_OBJECT void updateAutoComputeState(); + void deactivateCurrentSelector(); + signals: /// Emitted when selection happens in Salome viewer void salomeViewerSelection();