Salome HOME
Issue #1701 Preselecting before calling constraints does not put objects in the input...
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetValidator.cpp
index 330b4c468caac1b30ee4fd8e5e1fcffc59227032..191a277ee8f41f0ff91273ed12200cc89fcb07fb 100755 (executable)
@@ -20,17 +20,14 @@ ModuleBase_WidgetValidator::~ModuleBase_WidgetValidator()
 //********************************************************************
 bool ModuleBase_WidgetValidator::isValidSelection(const ModuleBase_ViewerPrsPtr& theValue)
 {
-  return myModelWidget->isValidSelectionCustom(theValue);
-}
+  bool aValid = false;
+  if (getValidState(theValue, aValid))
+    return aValid;
 
-bool ModuleBase_WidgetValidator::isFilterActivated() const
-{
-  bool isActivated = false;
+  aValid = myModelWidget->isValidSelectionCustom(theValue);
 
-  Handle(SelectMgr_Filter) aSelFilter = myWorkshop->validatorFilter();
-  ModuleBase_IViewer* aViewer = myWorkshop->viewer();
-
-  return aViewer->hasSelectionFilter(aSelFilter);
+  storeValidState(theValue, aValid);
+  return aValid;
 }
 
 bool ModuleBase_WidgetValidator::activateFilters(const bool toActivate)
@@ -44,8 +41,63 @@ bool ModuleBase_WidgetValidator::activateFilters(const bool toActivate)
     aViewer->addSelectionFilter(aSelFilter);
   else {
     aViewer->removeSelectionFilter(aSelFilter);
-    //clearValidatedCash();
+    clearValidatedCash();
   }
 
   return aHasSelectionFilter;
 }
+
+bool ModuleBase_WidgetValidator::isFilterActivated() const
+{
+  bool isActivated = false;
+
+  Handle(SelectMgr_Filter) aSelFilter = myWorkshop->validatorFilter();
+  ModuleBase_IViewer* aViewer = myWorkshop->viewer();
+
+  return aViewer->hasSelectionFilter(aSelFilter);
+}
+
+void ModuleBase_WidgetValidator::clearValidatedCash()
+{
+  myValidPrs.clear();
+  myInvalidPrs.clear();
+}
+
+bool ModuleBase_WidgetValidator::getValidState(const ModuleBase_ViewerPrsPtr& theValue, bool& theValid)
+{
+  bool aValidPrs = myValidPrs.contains(theValue);
+  bool anInvalidPrs = myInvalidPrs.contains(theValue);
+
+  if (aValidPrs)
+    theValid = true;
+  else if (anInvalidPrs)
+    theValid = false;
+
+  return aValidPrs || anInvalidPrs;
+}
+
+//********************************************************************
+void ModuleBase_WidgetValidator::storeValidState(const ModuleBase_ViewerPrsPtr& theValue, const bool theValid)
+{
+  bool aValidPrs = myInvalidPrs.contains(theValue);
+  bool anInvalidPrs = myInvalidPrs.contains(theValue);
+
+  if (theValid) {
+    if (!aValidPrs)
+      myValidPrs.append(theValue);
+    // the commented code will be useful when the valid state of the presentation
+    // will be changable between activate/deactivate. Currently it does not happen.
+    //if (anInvalidPrs)
+    //  myInvalidPrs.removeOne(theValue);
+  }
+  else { // !theValid
+    if (!anInvalidPrs)
+      myInvalidPrs.append(theValue);
+    //if (!aValidPrs)
+    //  myValidPrs.removeOne(theValue);
+  }
+#ifdef DEBUG_VALID_STATE
+  qDebug(QString("storeValidState: myValidPrs.size() = %1, myInvalidPrs.size() = %2").arg(myValidPrs.count())
+                 .arg(myInvalidPrs.count()).toStdString().c_str());
+#endif
+}