]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Create filter "Belongs To"
authorvsv <vsv@opencascade.com>
Wed, 5 Jun 2019 16:56:12 +0000 (19:56 +0300)
committervsv <vsv@opencascade.com>
Wed, 5 Jun 2019 16:56:12 +0000 (19:56 +0300)
13 files changed:
src/FiltersPlugin/FiltersPlugin_BelongsTo.cpp
src/Model/Model_Filter.cpp
src/ModelAPI/ModelAPI_Filter.h
src/ModuleBase/ModuleBase_IWorkshop.h
src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp
src/ModuleBase/ModuleBase_WidgetSelectionFilter.h
src/XGUI/XGUI_ActiveControlMgr.cpp
src/XGUI/XGUI_ActiveControlMgr.h
src/XGUI/XGUI_ModuleConnector.cpp
src/XGUI/XGUI_ModuleConnector.h
src/XGUI/XGUI_PropertyPanel.cpp
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index f2c9d88fcc5b4bdcb8f629decbf4ec355fdd15e4..45a045e0a3ee367782bad358f61b453c1560b15a 100644 (file)
@@ -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<ModelAPI_AttributeSelectionList>(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 =
-"<filter id = \"Belongs to\">"
-" <multi_selector id=\"Belongs to\""
+"<filter id = \"BelongsTo\">"
+" <multi_selector id=\"BelongsTo__BelongsTo\""
 "   label = \"Objects:\""
 "   tooltip = \"Select objects to limit selection.\""
 "   type_choice = \"objects\">"
@@ -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());
 }
index b0592b35e9b81225d89fed6faa25884357312b69..14905d04006d95e2df11012b4dd4cb199d61745a 100644 (file)
@@ -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<FilterPtr, bool> aReverseFlags; /// map of all filters to the reverse values
+  std::list<FilterArgs> aFilters; /// all filters and the reverse values
 
   std::list<std::string> 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<ModelAPI_AttributeBoolean> aReverse =
           std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(*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<FilterPtr, bool>::iterator aFilter = aReverseFlags.begin();
-  for(; aFilter != aReverseFlags.end(); aFilter++) {
-    bool aResult = aFilter->first->isOk(theShape, anArgs);
-    if (aFilter->second)
+  std::list<FilterArgs>::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;
index 758ece6485101a22d416b265328ac73b4ce58b03..a900548bfaeb768b208b3263d11940fcc635ce6c 100644 (file)
@@ -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
index 5877823bd074ab06315ddfe0f57bef9cfef17d38..c3558145bc06342cd393e8b3a457183966168e04 100644 (file)
@@ -138,6 +138,8 @@ Q_OBJECT
   /// \return boolean value
   virtual bool hasSHIFTPressed() const = 0;
 
+  virtual void deactivateCurrentSelector() = 0;
+
 signals:
   /// Signal selection changed.
   void selectionChanged();
index bccb9032b8a1f90bda986ca375bd0356625f64c5..a8b818e26e54807c2afdd95b37eb8e4d223e31c8 100644 (file)
@@ -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"
 
 #include <ModelAPI_Session.h>
 #include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_Events.h>
 #include <GeomAPI_ShapeExplorer.h>
 
+#include <Events_Loop.h>
+
 #include <AIS_InteractiveContext.hxx>
 #include <StdSelect_BRepOwner.hxx>
 #include <TopoDS_Compound.hxx>
@@ -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<ModuleBase_ModelWidget*> 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<QWidget*>  ModuleBase_FilterItem::getControls() const
+{
+  QList<QWidget*> aWidgetsList;
+  foreach(ModuleBase_ModelWidget* aWgt, myWidgets) {
+    QList<QWidget*> 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<ModuleBase_ModelWidget*> 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<QWidget*> ModuleBase_WidgetSelectionFilter::getControls() const
 {
-  return QList<QWidget*>();
+  QList<QWidget*> aWidgets;
+  QList<ModuleBase_FilterItem*> aItems = myFiltersWgt->findChildren<ModuleBase_FilterItem*>();
+  foreach(ModuleBase_FilterItem* aItem, aItems) {
+    QList<QWidget*> 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;
+}
index 8753d12909042065b64be38a75032b6a599e95d3..10c039faa16dc849904db302d8872a9a51332cb3 100644 (file)
@@ -74,6 +74,14 @@ public:
 
   std::string filter() const { return myFilterID; }
 
+  /// Returns list of widget controls
+  /// \return a control list
+  QList<QWidget*> getControls() const;
+
+  QList<ModuleBase_ModelWidget*> 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<ModuleBase_ModelWidget*> 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;
index beffebcee689835db9609a7215e0cb397c42a781..a976b6c3f62b9db19384136514fd81c371431449 100644 (file)
@@ -93,7 +93,13 @@ void XGUI_ActiveControlMgr::onSelectorActivated()
 void XGUI_ActiveControlMgr::onSelectorDeactivated()
 {
   XGUI_ActiveControlSelector* aSelector = qobject_cast<XGUI_ActiveControlSelector*>(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];
index 863fa1bc67e5b638fde7eac314fe2178a7d51f34..31862571fcfd8e5562d2fc84bd76fbfb2235c2a8 100644 (file)
@@ -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();
index 2f41e3659dc0975cffe816a114b9e76c65df80cd..fee5e9fde70024d7cce1a4b48382182616137eb1 100644 (file)
@@ -211,3 +211,8 @@ std::shared_ptr<Config_FeatureMessage> XGUI_ModuleConnector::featureInfo(const Q
   return std::shared_ptr<Config_FeatureMessage>();
 #endif
 }
+
+void XGUI_ModuleConnector::deactivateCurrentSelector()
+{
+  myWorkshop->deactivateCurrentSelector();
+}
index ca97352fbc2dc4511a94f63606ae265f8a3ed453..07fafe3839b1b565bac9cca9b172045af845798a 100644 (file)
@@ -119,6 +119,8 @@ Q_OBJECT
   /// \return boolean value
   virtual bool hasSHIFTPressed() const;
 
+  virtual void deactivateCurrentSelector();
+
   //! Returns workshop
   XGUI_Workshop* workshop() const { return myWorkshop; }
 
index 65180f91a4761a0aea3893114e149fb32a6c600f..7bfd6a3d4013eb7bdf9e06a25f96281eed264090 100644 (file)
@@ -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
index d54412c59160a87956b0e651b969fcd5c6a1bbf4..49ab301971f2c956a847a53fbe4341c7c341266c 100644 (file)
@@ -2934,3 +2934,8 @@ void XGUI_Workshop::onDockSizeChanged()
     disconnect(myObjectBrowser, SIGNAL(sizeChanged()), this, SLOT(onDockSizeChanged()));
   }
 }
+
+void XGUI_Workshop::deactivateCurrentSelector()
+{
+  myActiveControlMgr->deactivateSelector(myActiveControlMgr->activeSelector());
+}
index e7da8532dcd743467b9c989041ec890d42d66be9..ccd7c725ee4009190be0b407b9d7b4d064da94ab 100644 (file)
@@ -325,6 +325,8 @@ Q_OBJECT
 
   void updateAutoComputeState();
 
+  void deactivateCurrentSelector();
+
 signals:
   /// Emitted when selection happens in Salome viewer
   void salomeViewerSelection();