Salome HOME
It corrects the validator parameter from the entrity to viewerprs in order to validat...
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetValidated.cpp
index 88c587aff5ee622c0b7db7bc3aa08ee678b2a07a..0c84fa8e9ad0e4b86512fe7b60ccb88dfa32a470 100644 (file)
@@ -6,12 +6,13 @@
 
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
-#include <ModelAPI_ResultValidator.h>
 #include <ModelAPI_AttributeValidator.h>
 
 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
 #include <SelectMgr_EntityOwner.hxx>
 
+#include <Events_Loop.h>
+
 #include <QWidget>
 
 ModuleBase_WidgetValidated::ModuleBase_WidgetValidated(QWidget* theParent,
@@ -25,27 +26,47 @@ ModuleBase_WidgetValidated::~ModuleBase_WidgetValidated()
 {
 }
 
+//********************************************************************
 bool ModuleBase_WidgetValidated::setSelection(ModuleBase_ViewerPrs theValue)
 {
   bool isDone = false;
 
-  Handle(SelectMgr_EntityOwner) anOwner = theValue.owner();
-  if (isValid(anOwner)) {
-    setSelection(anOwner);
+  if (isValidSelection(theValue)) {
+    isDone = setSelectionCustom(theValue);
     updateObject(myFeature);
     emit valuesChanged();
   }
   return isDone;
 }
 
-bool ModuleBase_WidgetValidated::isValid(const Handle_SelectMgr_EntityOwner& theOwner)
+//********************************************************************
+bool ModuleBase_WidgetValidated::isValidSelection(const ModuleBase_ViewerPrs& theValue)
 {
-  backupAttributeValue(true);
+  DataPtr aData = myFeature->data();
+  AttributePtr anAttribute = myFeature->attribute(attributeID());
+
+  // stores the current values of the widget attribute
+  Events_Loop* aLoop = Events_Loop::loop();
+  // blocks the flush signals to avoid the temporary objects visualization in the viewer
+  // they should not be shown in order to do not lose highlight by erasing them
+  aLoop->activateFlushes(false);
+
+  aData->blockSendAttributeUpdated(true);
+  bool isAttributeBlocked = anAttribute->blockSetInitialized(true);
+  storeAttributeValue();
 
-  setSelection(theOwner);
-  bool aValid = isValidAttribute();
+  // saves the owner value to the widget attribute
+  bool aValid = setSelectionCustom(theValue);
 
-  backupAttributeValue(false);
+  if (aValid)
+    // checks the attribute validity
+    aValid = isValidAttribute();
+
+  // restores the current values of the widget attribute
+  restoreAttributeValue(aValid);
+  aData->blockSendAttributeUpdated(false);
+  anAttribute->blockSetInitialized(isAttributeBlocked);
+  aLoop->activateFlushes(true);
 
   return aValid;
 }
@@ -62,9 +83,6 @@ bool ModuleBase_WidgetValidated::isValidAttribute() const
   DataPtr aData = myFeature->data();
   AttributePtr anAttribute = myFeature->attribute(attributeID());
 
-  aData->blockSendAttributeUpdated(true);
-
-    // 3. check the acceptability of the current values
   std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
   std::list<std::list<std::string> >::iterator aArgs = anArguments.begin();
   bool aValid = true;
@@ -75,79 +93,17 @@ bool ModuleBase_WidgetValidated::isValidAttribute() const
       aValid = aAttrValidator->isValid(anAttribute, *aArgs);
     }
   }
-  aData->blockSendAttributeUpdated(false);
-
   return aValid;
 }
 
-//********************************************************************
-bool ModuleBase_WidgetValidated::isValid(ObjectPtr theObj, GeomShapePtr theShape) const
-{
-  SessionPtr aMgr = ModelAPI_Session::get();
-  ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
-  std::list<ModelAPI_Validator*> aValidators;
-  std::list<std::list<std::string> > anArguments;
-  aFactory->validators(parentID(), attributeID(), aValidators, anArguments);
-
-  // Check the type of selected object
-  std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
-  bool isValid = true;
-  for (; aValidator != aValidators.end(); aValidator++) {
-    const ModelAPI_ResultValidator* aResValidator =
-        dynamic_cast<const ModelAPI_ResultValidator*>(*aValidator);
-    if (aResValidator) {
-      isValid = false;
-      if (aResValidator->isValid(theObj)) {
-        isValid = true;
-        break;
-      }
-    }
-  }
-  return isValid;
-}
-
-#define VALIDATOR_FILTER
 void ModuleBase_WidgetValidated::activateFilters(ModuleBase_IWorkshop* theWorkshop,
                                                  const bool toActivate) const
 {
   ModuleBase_IViewer* aViewer = theWorkshop->viewer();
 
-#ifdef VALIDATOR_FILTER
   Handle(SelectMgr_Filter) aSelFilter = theWorkshop->validatorFilter();
   if (toActivate)
     aViewer->addSelectionFilter(aSelFilter);
   else
     aViewer->removeSelectionFilter(aSelFilter);
-#else
-  // apply filters loaded from the XML definition of the widget
-  ModuleBase_FilterFactory* aFactory = theWorkshop->selectionFilters();
-  SelectMgr_ListOfFilter aFactoryFilters;
-  aFactory->filters(parentID(), attributeID(), aFactoryFilters);
-  SelectMgr_ListIteratorOfListOfFilter aFactoryIt(aFactoryFilters);
-  for (; aFactoryIt.More(); aFactoryIt.Next()) {
-    Handle(SelectMgr_Filter) aSelFilter = aFactoryIt.Value();
-    if (aSelFilter.IsNull())
-      continue;
-    if (toActivate)
-      aViewer->addSelectionFilter(aSelFilter);
-    else
-      aViewer->removeSelectionFilter(aSelFilter);
-  }
-#endif
-}
-
-void ModuleBase_WidgetValidated::selectionFilters(ModuleBase_IWorkshop* theWorkshop,
-                                                  SelectMgr_ListOfFilter& theFilters) const
-{
-  ModuleBase_FilterFactory* aFactory = theWorkshop->selectionFilters();
-  SelectMgr_ListOfFilter aFilters;
-  aFactory->filters(parentID(), attributeID(), aFilters);
-  SelectMgr_ListIteratorOfListOfFilter aIt(aFilters);
-  for (; aIt.More(); aIt.Next()) {
-    Handle(SelectMgr_Filter) aSelFilter = aIt.Value();
-    if (aSelFilter.IsNull())
-      continue;
-
-    theFilters.Append(aSelFilter);
-  }
 }