]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
The Linear filter applying
authornds <natalia.donis@opencascade.com>
Mon, 15 Dec 2014 09:44:38 +0000 (12:44 +0300)
committernds <natalia.donis@opencascade.com>
Mon, 15 Dec 2014 09:44:38 +0000 (12:44 +0300)
src/ModuleBase/ModuleBase_FilterFactory.cpp
src/ModuleBase/ModuleBase_FilterFactory.h
src/ModuleBase/ModuleBase_FilterLinearEdge.cpp
src/ModuleBase/ModuleBase_FilterLinearEdge.h
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/XGUI/XGUI_Workshop.cpp

index 86213407f7e0ed0d5dca7b654183443dd9e763b6..891d74370621fb944a2ff2789ec631cdf0927a95 100644 (file)
 #include "ModuleBase_FilterFactory.h"
 #include <ModuleBase_Filter.h>
 
-#include <Model_FeatureValidator.h>
+//#include <Model_FeatureValidator.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Attribute.h>
 #include <ModelAPI_Data.h>
-#include <ModelAPI_AttributeValidator.h>
+//#include <ModelAPI_AttributeValidator.h>
 #include <Events_Error.h>
 
 
 void ModuleBase_FilterFactory::registerFilter(const std::string& theID,
                                               Handle(ModuleBase_Filter) theFilter)
 {
-  /*if (myIDs.find(theID) != myIDs.end()) {
-    Events_Error::send(std::string("Validator ") + theID + " is already registered");
+  if (myIDs.find(theID) != myIDs.end()) {
+    Events_Error::send(std::string("Filter ") + theID + " is already registered");
   } else {
-    myIDs[theID] = theValidator;
-  }*/
+    myIDs[theID] = theFilter;
+  }
 }
 
 void ModuleBase_FilterFactory::assignFilter(const std::string& theID,
-  const std::string& theFeatureID,
-  const std::string& theAttrID)
+                                            const std::string& theFeatureID,
+                                            const std::string& theAttrID)
 {
-  /*
   // create feature-structures if not exist
-  std::map<std::string, std::map<std::string, AttrValidators> >::iterator aFeature = myAttrs.find(
+  std::map<std::string, std::map<std::string, AttrFilters> >::iterator aFeature = myAttrs.find(
     theFeatureID);
   if (aFeature == myAttrs.end()) {
-    myAttrs[theFeatureID] = std::map<std::string, AttrValidators>();
+    myAttrs[theFeatureID] = std::map<std::string, AttrFilters>();
     aFeature = myAttrs.find(theFeatureID);
   }
   // add attr-structure if not exist, or generate error if already exist
-  std::map<std::string, AttrValidators>::iterator anAttr = aFeature->second.find(theAttrID);
+  std::map<std::string, AttrFilters>::iterator anAttr = aFeature->second.find(theAttrID);
   if (anAttr == aFeature->second.end()) {
-    aFeature->second[theAttrID] = AttrValidators();
+    aFeature->second[theAttrID] = AttrFilters();
   }
-  //aFeature->second[theAttrID][theID] = theArguments;
-  */
+  aFeature->second[theAttrID][theID] = std::list<std::string>();
 }
 
-const SelectMgr_ListOfFilter& ModuleBase_FilterFactory::filters(const std::string& theFeatureID,
-  const std::string& theAttrID/*,
-  std::list<Handle(ModuleBase_Filter)>& theFilters/*,
-  std::list<std::list<std::string> >& theArguments*/) const
+void ModuleBase_FilterFactory::filters(const std::string& theFeatureID,
+                                       const std::string& theAttrID,
+                                       SelectMgr_ListOfFilter& theFilters/*,
+                                        std::list<Handle(ModuleBase_Filter)>& theFilters/*,
+                                        std::list<std::list<std::string> >& theArguments*/) const
 {
   SelectMgr_ListOfFilter aFilters;
-  return aFilters;
-  /*  std::map<std::string, std::map<std::string, AttrValidators> >::const_iterator aFeature = 
+
+  std::map<std::string, std::map<std::string, AttrFilters> >::const_iterator aFeature = 
     myAttrs.find(theFeatureID);
   if (aFeature != myAttrs.cend()) {
-    std::map<std::string, AttrValidators>::const_iterator anAttr = aFeature->second.find(theAttrID);
+    std::map<std::string, AttrFilters>::const_iterator anAttr = aFeature->second.find(theAttrID);
     if (anAttr != aFeature->second.end()) {
-      AttrValidators::const_iterator aValIter = anAttr->second.cbegin();
+      AttrFilters::const_iterator aValIter = anAttr->second.cbegin();
       for (; aValIter != anAttr->second.cend(); aValIter++) {
         std::map<std::string, Handle(ModuleBase_Filter)>::const_iterator aFound = myIDs.find(
           aValIter->first);
         if (aFound == myIDs.end()) {
-          Events_Error::send(std::string("Validator ") + aValIter->first + " was not registered");
+          Events_Error::send(std::string("Filter ") + aValIter->first + " was not registered");
         } else {
-          theValidators.push_back(aFound->second);
-          theArguments.push_back(aValIter->second);
+          Handle(ModuleBase_Filter) aFilter = aFound->second;
+          if (aFilter.IsNull())
+            continue;
+
+          theFilters.Append(aFilter);//aFound->second);
+          //theArguments.push_back(aValIter->second);
         }
       }
     }
-  }*/
+  }
 }
 
 ModuleBase_FilterFactory::ModuleBase_FilterFactory()
 {
-  //const static std::string kDefaultId = "Model_FeatureValidator";
-  //registerValidator(kDefaultId, new Model_FeatureValidator);
+  //const static std::string kDefaultId = "Model_FeatureFilter";
+  //registerFilter(kDefaultId, new Model_FeatureFilter);
 }
 
-const Handle(ModuleBase_Filter) ModuleBase_FilterFactory::validator(const std::string& theID) const
+const Handle(ModuleBase_Filter) ModuleBase_FilterFactory::filter(const std::string& theID) const
 {
-/*  std::map<std::string, Handle(ModuleBase_Filter)>::const_iterator aIt = myIDs.find(theID);
+  std::map<std::string, Handle(ModuleBase_Filter)>::const_iterator aIt = myIDs.find(theID);
   if (aIt != myIDs.end()) {
     return aIt->second;
-  }*/
-  return NULL;
-}
-
-void ModuleBase_FilterFactory::addDefaultValidators(std::list<Handle(ModuleBase_Filter)>& theValidators) const
-{
-/*  const static std::string kDefaultId = "Model_FeatureValidator";
-  std::map<std::string, Handle(ModuleBase_Filter)>::const_iterator it = myIDs.find(kDefaultId);
-  if(it == myIDs.end())
-    return;
-  theValidators.push_back(it->second);*/
-}
-
-bool ModuleBase_FilterFactory::validate(const std::shared_ptr<ModelAPI_Feature>& theFeature) const
-{
-/*  const static std::string kDefaultId = "Model_FeatureValidator";
-  // check feature validators first
-  std::map<std::string, AttrValidators>::const_iterator aFeature = 
-    myFeatures.find(theFeature->getKind());
-  if (aFeature != myFeatures.end()) {
-    AttrValidators::const_iterator aValidator = aFeature->second.begin();
-    for(; aValidator != aFeature->second.end(); aValidator++) {
-      std::map<std::string, Handle(ModuleBase_Filter)>::const_iterator aValFind = 
-        myIDs.find(aValidator->first);
-      if (aValFind == myIDs.end()) {
-        Events_Error::send(std::string("Validator ") + aValidator->first + " was not registered");
-        continue;
-      }
-      const ModelAPI_FeatureValidator* aFValidator = 
-        dynamic_cast<const ModelAPI_FeatureValidator*>(aValFind->second);
-      if (aFValidator) {
-        if (!aFValidator->isValid(theFeature, aValidator->second))
-          return false;
-      }
-    }
-  }
-  // check default validator
-  std::map<std::string, Handle(ModuleBase_Filter)>::const_iterator aDefaultVal = myIDs.find(kDefaultId);
-  if(aDefaultVal != myIDs.end()) {
-    static const std::list<std::string> anEmptyArgList;
-    const ModelAPI_FeatureValidator* aFValidator = 
-      dynamic_cast<const ModelAPI_FeatureValidator*>(aDefaultVal->second);
-    if (aFValidator) {
-      if (!aFValidator->isValid(theFeature, anEmptyArgList))
-        return false;
-    }
-  }
-  
-  // check all attributes for validity
-  std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
-  // Validity of data is checked by "Model_FeatureValidator" (kDefaultId)
-  // if (!aData || !aData->isValid())
-  //   return false;
-  static const std::string kAllTypes = "";
-  std::map<std::string, std::map<std::string, AttrValidators> >::const_iterator aFeatureIter = 
-    myAttrs.find(theFeature->getKind());
-  if (aFeatureIter != myAttrs.cend()) {
-    std::list<std::string> aLtAttributes = aData->attributesIDs(kAllTypes);
-    std::list<std::string>::iterator anAttrIter = aLtAttributes.begin();
-    for (; anAttrIter != aLtAttributes.end(); anAttrIter++) {
-      std::map<std::string, AttrValidators>::const_iterator anAttr = 
-          aFeatureIter->second.find(*anAttrIter);
-      if (anAttr != aFeatureIter->second.end()) {
-        AttrValidators::const_iterator aValIter = anAttr->second.cbegin();
-        for (; aValIter != anAttr->second.cend(); aValIter++) {
-          std::map<std::string, Handle(ModuleBase_Filter)>::const_iterator aFound = myIDs.find(
-            aValIter->first);
-          if (aFound == myIDs.end()) {
-            Events_Error::send(std::string("Validator ") + aValIter->first + " was not registered");
-          } else {
-            const ModelAPI_AttributeValidator* anAttrValidator = 
-              dynamic_cast<const ModelAPI_AttributeValidator*>(aFound->second);
-            if (anAttrValidator) {
-              AttributePtr anAttribute = theFeature->data()->attribute(*anAttrIter);
-              if (!anAttrValidator->isValid(anAttribute, aValIter->second)) {
-                  return false;
-              }
-            }
-          }
-        }
-      }
-    }
   }
-  */
- return true;
-}
-
-void ModuleBase_FilterFactory::registerNotObligatory(std::string theFeature, std::string theAttribute)
-{
-/*  const static std::string kDefaultId = "Model_FeatureValidator";
-  std::map<std::string, Handle(ModuleBase_Filter)>::const_iterator it = myIDs.find(kDefaultId);
-  if (it != myIDs.end()) {
-    Model_FeatureValidator* aValidator = dynamic_cast<Model_FeatureValidator*>(it->second);
-    if (aValidator) {
-      aValidator->registerNotObligatory(theFeature, theAttribute);
-    }
-  }*/
-}
-
-bool ModuleBase_FilterFactory::isNotObligatory(std::string theFeature, std::string theAttribute)
-{
-/*  const static std::string kDefaultId = "Model_FeatureValidator";
-  std::map<std::string, Handle(ModuleBase_Filter)>::const_iterator it = myIDs.find(kDefaultId);
-  if (it != myIDs.end()) {
-    Model_FeatureValidator* aValidator = dynamic_cast<Model_FeatureValidator*>(it->second);
-    if (aValidator) {
-      return aValidator->isNotObligatory(theFeature, theAttribute);
-    }
-  }*/
-  return false; // default
-}
-
-void ModuleBase_FilterFactory::registerConcealment(std::string theFeature, std::string theAttribute)
-{
-/*  std::map<std::string, std::set<std::string> >::iterator aFind = myConcealed.find(theFeature);
-  if (aFind == myConcealed.end()) {
-    std::set<std::string> aNewSet;
-    aNewSet.insert(theAttribute);
-    myConcealed[theFeature] = aNewSet;
-  } else {
-    aFind->second.insert(theAttribute);
-  }*/
-}
-
-bool ModuleBase_FilterFactory::isConcealed(std::string theFeature, std::string theAttribute)
-{
-  /*std::map<std::string, std::set<std::string> >::iterator aFind = myConcealed.find(theFeature);
-  return aFind != myConcealed.end() && aFind->second.find(theAttribute) != aFind->second.end();*/
-  return true;
+  return NULL;
 }
index e1f71dc34e9368470edcdc203b0aa100d647e692..d0d627639f21574dace29e7b7ae7230a47ad69f4 100644 (file)
  * the attribute identifier (if attribute is validated).
  * All accessible filters must be registered by the ID string first.
  * The instance of this factory can be get in the Workshop interface.
- * Keeps the validator objects alive and just returns one of it by request.
- * All the needed information is provided to the validator as an argument,
+ * Keeps the filter objects alive and just returns one of it by request.
+ * All the needed information is provided to the filter as an argument,
  * this allows to work with them independently from the feature specific object.
  */
 class ModuleBase_FilterFactory : public QObject
 {
- public:
-
-   //ModuleBase_FilterFactory();
-   //virtual ~ModuleBase_FilterFactory() {}
-
-
  private:
-  std::map<std::string, Handle_ModuleBase_Filter> myIDs;  ///< map from ID to registered validator
-  /// validators IDs to list of arguments
-  typedef std::map<std::string, std::list<std::string> > AttrValidators;
-  /// validators IDs by feature ID
-  std::map<std::string, AttrValidators> myFeatures;
-  /// validators IDs and arguments by feature and attribute IDs
-  std::map<std::string, std::map<std::string, AttrValidators> > myAttrs;
-  /// Stores the registered attributes that leads to the concealment of referenced objects in 
-  /// data tree. Map from feature kind to set of attribute IDs.
-  std::map<std::string, std::set<std::string> > myConcealed;
+  std::map<std::string, Handle_ModuleBase_Filter> myIDs;  ///< map from ID to registered filter
+  /// filters IDs to list of arguments
+  typedef std::map<std::string, std::list<std::string> > AttrFilters;
+  /// filters IDs by feature ID
+  std::map<std::string, AttrFilters> myFeatures;
+  /// filters IDs and arguments by feature and attribute IDs
+  std::map<std::string, std::map<std::string, AttrFilters> > myAttrs;
 
  public:
-  /// Registers the instance of the validator by the ID
+  /// Registers the instance of the filter by the ID
   MODULEBASE_EXPORT virtual void registerFilter(const std::string& theID,
-                                                Handle_ModuleBase_Filter theValidator);
+                                                Handle_ModuleBase_Filter theFilter);
 
-  /// Assigns validator to the attribute of the feature
+  /// Assigns filter to the attribute of the feature
   MODULEBASE_EXPORT virtual void assignFilter(const std::string& theID,
-                                            const std::string& theFeatureID,
-                                            const std::string& theAttrID);
-
-  /// Provides a validator for the attribute, returns NULL if no validator
-  MODULEBASE_EXPORT const SelectMgr_ListOfFilter& filters(const std::string& theFeatureID,
-                                       const std::string& theAttrID) const;
+                                              const std::string& theFeatureID,
+                                              const std::string& theAttrID);
 
-  /// Returns registered validator by its Id
-  MODULEBASE_EXPORT virtual const Handle_ModuleBase_Filter validator(const std::string& theID) const;
+  /// Provides a filter for the attribute, returns NULL if no filter
+  MODULEBASE_EXPORT void filters(const std::string& theFeatureID,
+                                 const std::string& theAttrID,
+                                 SelectMgr_ListOfFilter& theFilters) const;
 
-  /// Returns true if feature and all its attributes are valid.
-  MODULEBASE_EXPORT virtual bool validate(const std::shared_ptr<ModelAPI_Feature>& theFeature) const;
-
-  /// register that this attribute in feature is not obligatory for the feature execution
-  /// so, it is not needed for the standard validation mechanism
-  virtual void registerNotObligatory(std::string theFeature, std::string theAttribute);
-
-  /// Returns true if the attribute in feature is not obligatory for the feature execution
-  virtual bool isNotObligatory(std::string theFeature, std::string theAttribute);
-
-  /// register that this attribute conceals in the object browser
-  /// all referenced features after execution
-  virtual void registerConcealment(std::string theFeature, std::string theAttribute);
-
-  /// Returns true that it was registered that attribute conceals the referenced result
-  virtual bool isConcealed(std::string theFeature, std::string theAttribute);
+  /// Returns registered filter by its Id
+  MODULEBASE_EXPORT virtual const Handle_ModuleBase_Filter filter(const std::string& theID) const;
 
 protected:
-  void addDefaultValidators(std::list<Handle_ModuleBase_Filter>& theValidators) const;
-  /// Get instance from workshop
-
   ModuleBase_FilterFactory();
 
   ~ModuleBase_FilterFactory() {}
index 59dc3503866fe394ad129307f6561b009c378358..97f5ffa9a7e80a7d12b4a973c04bd7e9d1498a22 100644 (file)
@@ -25,8 +25,8 @@
 #include <Geom_Curve.hxx>
 
 
-IMPLEMENT_STANDARD_HANDLE(ModuleBase_FilterLinearEdge, SelectMgr_Filter);
-IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_FilterLinearEdge, SelectMgr_Filter);
+IMPLEMENT_STANDARD_HANDLE(ModuleBase_FilterLinearEdge, ModuleBase_Filter);
+IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_FilterLinearEdge, ModuleBase_Filter);
 
 
 Standard_Boolean ModuleBase_FilterLinearEdge::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
@@ -48,5 +48,5 @@ Standard_Boolean ModuleBase_FilterLinearEdge::IsOk(const Handle(SelectMgr_Entity
       }
     }
   }
-  return Standard_False;
+  return isOk;
 }
index 286542c925665b2659bd9e47e39006349805a59c..7f3b798f8b642383ed2a5769a99698da89baeb7b 100644 (file)
@@ -15,7 +15,7 @@
 * A filter which provides filtering of selection in 3d viewer.
 * Installing of this filter lets to select only object of requested type
 */
-DEFINE_STANDARD_HANDLE(ModuleBase_FilterLinearEdge, SelectMgr_Filter);
+DEFINE_STANDARD_HANDLE(ModuleBase_FilterLinearEdge, ModuleBase_Filter);
 class ModuleBase_FilterLinearEdge: public ModuleBase_Filter
 {
 public:
index 315edde7f9ecc17335be5254927d6d3f53030626..49fe8cf55b8043e12aa6fb36fcc9b9696e828059 100644 (file)
@@ -434,17 +434,24 @@ void ModuleBase_WidgetShapeSelector::activateSelection(bool toActivate)
       myWorkshop->deactivateSubShapesSelection();
     }
   }
-
-  /*ModuleBase_FilterFactory* aFactory = myWorkshop->selectionFilters();
-  const SelectMgr_ListOfFilter& aFilters = aFactory->filters(parentID(), attributeID());
+  // apply filters loaded from the XML definition of the widget
+  ModuleBase_FilterFactory* aFactory = myWorkshop->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;
+
     Handle(ModuleBase_Filter) aFilter = Handle(ModuleBase_Filter)::DownCast(aIt.Value());
+    if (aFilter.IsNull())
+      continue;
     if (myIsActive)
       aViewer->addSelectionFilter(aFilter);
     else
       aViewer->removeSelectionFilter(aFilter);
-  }*/
+  }
 }
 
 //********************************************************************
index 39d1254f3269a728d718c417ebe8550860631878..42308e3732e66e7dc0661326725e316e2aec8ce3 100644 (file)
@@ -431,10 +431,11 @@ void XGUI_Workshop::processEvent(const std::shared_ptr<Events_Message>& theMessa
     std::shared_ptr<Config_SelectionFilterMessage> aMsg = 
       std::dynamic_pointer_cast<Config_SelectionFilterMessage>(theMessage);
     if (aMsg) {
+      ModuleBase_FilterFactory* aFactory = moduleConnector()->selectionFilters();
       if (aMsg->attributeId().empty()) {  // feature validator
-        moduleConnector()->selectionFilters()->assignFilter(aMsg->selectionFilterId(), aMsg->featureId(), aMsg->attributeId());
+        //aFactory->assignFilter(aMsg->selectionFilterId(), aMsg->featureId());
       } else {  // attribute validator
-        moduleConnector()->selectionFilters()->assignFilter(aMsg->selectionFilterId(), aMsg->featureId(), aMsg->attributeId());
+        aFactory->assignFilter(aMsg->selectionFilterId(), aMsg->featureId(), aMsg->attributeId());
       }
     }
   }