]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
It is a filters implementation to be set in the XML file.
authornds <natalia.donis@opencascade.com>
Wed, 10 Dec 2014 10:52:05 +0000 (13:52 +0300)
committernds <natalia.donis@opencascade.com>
Wed, 10 Dec 2014 10:52:05 +0000 (13:52 +0300)
14 files changed:
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_Filter.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_Filter.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_FilterFactory.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_FilterFactory.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_FilterLinearEdge.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_FilterLinearEdge.h [new file with mode: 0644]
src/ModuleBase/ModuleBase_IModule.cpp
src/ModuleBase/ModuleBase_IModule.h
src/ModuleBase/ModuleBase_IWorkshop.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_IWorkshop.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/XGUI/XGUI_Workshop.cpp

index e80812b3c6fd7ee67df00b0f92aaae63ad1d24e4..c7a56cf5c4225c2a9fba53797aa340cdf703fd5c 100644 (file)
@@ -3,6 +3,9 @@ SET(CMAKE_AUTOMOC ON)
 
 SET(PROJECT_HEADERS
        ModuleBase.h
+       ModuleBase_Filter.h
+       ModuleBase_FilterFactory.h
+       ModuleBase_FilterLinearEdge.h
        ModuleBase_Tools.h
        ModuleBase_IModule.h
        ModuleBase_Operation.h
@@ -33,8 +36,12 @@ SET(PROJECT_HEADERS
 )
 
 SET(PROJECT_SOURCES
+       ModuleBase_Filter.cpp
+       ModuleBase_FilterFactory.cpp
+       ModuleBase_FilterLinearEdge.cpp
        ModuleBase_Tools.cpp
        ModuleBase_IModule.cpp
+       ModuleBase_IWorkshop.cpp
        ModuleBase_Operation.cpp
        ModuleBase_OperationDescription.cpp
        ModuleBase_ModelWidget.cpp
@@ -47,7 +54,7 @@ SET(PROJECT_SOURCES
        ModuleBase_WidgetChoice.cpp
        ModuleBase_WidgetFileSelector.cpp
        ModuleBase_DoubleSpinBox.cpp
-    ModuleBase_WidgetLineEdit.cpp
+       ModuleBase_WidgetLineEdit.cpp
        ModuleBase_WidgetMultiSelector.cpp
        ModuleBase_ViewerFilters.cpp
        ModuleBase_ResultPrs.cpp
diff --git a/src/ModuleBase/ModuleBase_Filter.cpp b/src/ModuleBase/ModuleBase_Filter.cpp
new file mode 100644 (file)
index 0000000..401d029
--- /dev/null
@@ -0,0 +1,14 @@
+// File:        ModuleBase_Filter.cpp
+// Created:     10 Dec 2014
+// Author:      Natalia ERMOLAEVA
+
+
+#include "ModuleBase_Filter.h"
+
+IMPLEMENT_STANDARD_HANDLE(ModuleBase_Filter, SelectMgr_Filter);
+IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_Filter, SelectMgr_Filter);
+
+Standard_Boolean ModuleBase_Filter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
+{
+  return Standard_True;
+}
diff --git a/src/ModuleBase/ModuleBase_Filter.h b/src/ModuleBase/ModuleBase_Filter.h
new file mode 100644 (file)
index 0000000..210d9db
--- /dev/null
@@ -0,0 +1,31 @@
+// File:        ModuleBase_Filter.h
+// Created:     10 Dec 2014
+// Author:      Natalia ERMOLAEVA
+
+#ifndef ModuleBase_Filter_H
+#define ModuleBase_Filter_H
+
+#include "ModuleBase.h"
+
+#include <SelectMgr_Filter.hxx>
+
+/**
+ * This object is assigned by the name
+ * in the XML file to the specific attribute or to the whole feature.
+ * If isOK method of the filter returns "false", it is signalized in user interface
+ * that the processed entity should not be selected.
+ * Filterss must be registered in the filters factory to be
+ * correctly identified by the XML string-ID.
+ */
+DEFINE_STANDARD_HANDLE(ModuleBase_Filter, SelectMgr_Filter);
+class ModuleBase_Filter: public SelectMgr_Filter
+{
+public:
+  Standard_EXPORT ModuleBase_Filter(): SelectMgr_Filter() {}
+
+  Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const;
+
+  DEFINE_STANDARD_RTTI(ModuleBase_Filter)
+};
+
+#endif //ModuleBase_Filter
diff --git a/src/ModuleBase/ModuleBase_FilterFactory.cpp b/src/ModuleBase/ModuleBase_FilterFactory.cpp
new file mode 100644 (file)
index 0000000..1d45b9f
--- /dev/null
@@ -0,0 +1,232 @@
+// File:        ModuleBase_FilterFactory.h
+// Created:     10 Dec 2014
+// Author:      Natalia ERMOLAEVA
+
+#include "ModuleBase_FilterFactory.h"
+
+#include <Model_FeatureValidator.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Attribute.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_AttributeValidator.h>
+#include <Events_Error.h>
+
+
+void ModuleBase_FilterFactory::registerFilter(const std::string& theID,
+                                                        ModuleBase_Filter* theValidator)
+{
+  /*if (myIDs.find(theID) != myIDs.end()) {
+    Events_Error::send(std::string("Validator ") + theID + " is already registered");
+  } else {
+    myIDs[theID] = theValidator;
+  }*/
+}
+
+void ModuleBase_FilterFactory::assignFilter(const std::string& theID,
+  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(
+    theFeatureID);
+  if (aFeature == myAttrs.end()) {
+    myAttrs[theFeatureID] = std::map<std::string, AttrValidators>();
+    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);
+  if (anAttr == aFeature->second.end()) {
+    aFeature->second[theAttrID] = AttrValidators();
+  }
+  //aFeature->second[theAttrID][theID] = theArguments;
+  */
+}
+
+void ModuleBase_FilterFactory::validators(const std::string& theFeatureID,
+  std::list<ModuleBase_Filter*>& theResult,
+  std::list<std::list<std::string> >& theArguments) const
+{
+/*  std::map<std::string, AttrValidators>::const_iterator aFeature = myFeatures.find(theFeatureID);
+  if (aFeature != myFeatures.cend()) {
+    AttrValidators::const_iterator aValIter = aFeature->second.cbegin();
+    for (; aValIter != aFeature->second.cend(); aValIter++) {
+      std::map<std::string, 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 {
+        theResult.push_back(aFound->second);
+        theArguments.push_back(aValIter->second);
+      }
+    }
+  }
+  addDefaultValidators(theResult);*/
+}
+
+void ModuleBase_FilterFactory::validators(const std::string& theFeatureID,
+  const std::string& theAttrID,
+  std::list<ModuleBase_Filter*>& theValidators,
+  std::list<std::list<std::string> >& theArguments) const
+{
+/*  std::map<std::string, std::map<std::string, AttrValidators> >::const_iterator aFeature = 
+    myAttrs.find(theFeatureID);
+  if (aFeature != myAttrs.cend()) {
+    std::map<std::string, AttrValidators>::const_iterator anAttr = aFeature->second.find(theAttrID);
+    if (anAttr != aFeature->second.end()) {
+      AttrValidators::const_iterator aValIter = anAttr->second.cbegin();
+      for (; aValIter != anAttr->second.cend(); aValIter++) {
+        std::map<std::string, 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 {
+          theValidators.push_back(aFound->second);
+          theArguments.push_back(aValIter->second);
+        }
+      }
+    }
+  }*/
+}
+
+ModuleBase_FilterFactory::ModuleBase_FilterFactory()
+{
+  //const static std::string kDefaultId = "Model_FeatureValidator";
+  //registerValidator(kDefaultId, new Model_FeatureValidator);
+}
+
+const ModuleBase_Filter* ModuleBase_FilterFactory::validator(const std::string& theID) const
+{
+/*  std::map<std::string, ModuleBase_Filter*>::const_iterator aIt = myIDs.find(theID);
+  if (aIt != myIDs.end()) {
+    return aIt->second;
+  }*/
+  return NULL;
+}
+
+void ModuleBase_FilterFactory::addDefaultValidators(std::list<ModuleBase_Filter*>& theValidators) const
+{
+/*  const static std::string kDefaultId = "Model_FeatureValidator";
+  std::map<std::string, 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, 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, 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, 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, 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, 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;
+}
diff --git a/src/ModuleBase/ModuleBase_FilterFactory.h b/src/ModuleBase/ModuleBase_FilterFactory.h
new file mode 100644 (file)
index 0000000..15f7542
--- /dev/null
@@ -0,0 +1,100 @@
+// File:        ModuleBase_FilterFactory.h
+// Created:     10 Dec 2014
+// Author:      Natalia ERMOLAEVA
+
+#ifndef ModuleBase_FilterFactory_H
+#define ModeleBase_SelectionFilterFactory_H
+
+#include "ModuleBase.h"
+#include "ModuleBase_IWorkshop.h"
+
+#include <map>
+#include <set>
+
+class ModuleBase_Filter;
+
+/**\class ModuleBase_FilterFactory
+ * \ingroup ModelBase
+ * \breif Manages the registered selection filters
+ *
+ * Allows to get a selection filter by the feature identifier and 
+ * 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.
+ * 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,
+ * 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, 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;
+
+ public:
+  /// Registers the instance of the validator by the ID
+  MODULEBASE_EXPORT virtual void registerFilter(const std::string& theID,
+                                                ModuleBase_Filter* theValidator);
+
+  /// Assigns validator 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 feature, returns NULL if no validator
+  MODULEBASE_EXPORT virtual void validators(const std::string& theFeatureID,
+                                       std::list<ModuleBase_Filter*>& theResult,
+                                       std::list<std::list<std::string> >& theArguments) const;
+  /// Provides a validator for the attribute, returns NULL if no validator
+  MODULEBASE_EXPORT virtual void validators(const std::string& theFeatureID,
+                                       const std::string& theAttrID,
+                                       std::list<ModuleBase_Filter*>& theValidators,
+                                       std::list<std::list<std::string> >& theArguments) const;
+
+  /// Returns registered validator by its Id
+  MODULEBASE_EXPORT virtual const ModuleBase_Filter* validator(const std::string& theID) 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);
+
+protected:
+  void addDefaultValidators(std::list<ModuleBase_Filter*>& theValidators) const;
+  /// Get instance from workshop
+
+  ModuleBase_FilterFactory();
+
+  ~ModuleBase_FilterFactory() {}
+
+  friend class ModuleBase_IWorkshop;
+
+};
+
+#endif //ModuleBase_FilterFactory
diff --git a/src/ModuleBase/ModuleBase_FilterLinearEdge.cpp b/src/ModuleBase/ModuleBase_FilterLinearEdge.cpp
new file mode 100644 (file)
index 0000000..76712c0
--- /dev/null
@@ -0,0 +1,50 @@
+// File:        ModuleBase_FilterLinearEdge.cpp
+// Created:     10 Dec 2014
+// Author:      Natalia ERMOLAEVA
+
+
+#include "ModuleBase_FilterLinearEdge.h"
+#include "ModuleBase_IWorkshop.h"
+
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_ResultConstruction.h>
+
+#include <AIS_InteractiveObject.hxx>
+#include <AIS_Shape.hxx>
+
+#include <StdSelect_BRepOwner.hxx>
+
+#include <BRep_Tool.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <Geom_Curve.hxx>
+
+
+IMPLEMENT_STANDARD_HANDLE(ModuleBase_FilterLinearEdge, SelectMgr_Filter);
+IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_FilterLinearEdge, SelectMgr_Filter);
+
+
+Standard_Boolean ModuleBase_FilterLinearEdge::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
+{
+  Standard_Boolean isOk = ModuleBase_Filter::IsOk(theOwner);
+  if (isOk && theOwner->HasSelectable()) {
+    Handle(AIS_InteractiveObject) aAisObj = 
+      Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
+    if (!aAisObj.IsNull()) {
+      std::shared_ptr<GeomAPI_AISObject> aAISObj = AISObjectPtr(new GeomAPI_AISObject());
+      aAISObj->setImpl(new Handle(AIS_InteractiveObject)(aAisObj));
+      //ObjectPtr aObj = myWorkshop->findPresentedObject(aAISObj);
+
+
+      /*foreach (QString aType, myTypes) {
+        if (aType.toLower() == "construction") {
+          ResultConstructionPtr aConstr = 
+            std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aObj);
+          return (aConstr != NULL);
+        } // ToDo: Process other types of objects
+      }*/
+    }
+  }
+  return Standard_False;
+}
diff --git a/src/ModuleBase/ModuleBase_FilterLinearEdge.h b/src/ModuleBase/ModuleBase_FilterLinearEdge.h
new file mode 100644 (file)
index 0000000..d578881
--- /dev/null
@@ -0,0 +1,29 @@
+// File:        ModuleBase_FilterLinearEdge.h
+// Created:     10 Dec 2014
+// Author:      Natalia ERMOLAEVA
+
+#ifndef ModuleBase_FilterLinearEdge_H
+#define ModuleBase_FilterLinearEdge_H
+
+#include "ModuleBase.h"
+
+#include "ModuleBase_Filter.h"
+
+/**
+* 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);
+class ModuleBase_FilterLinearEdge: public ModuleBase_Filter
+{
+public:
+  Standard_EXPORT ModuleBase_FilterLinearEdge(): 
+      ModuleBase_Filter() {}
+
+  Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const;
+
+  DEFINE_STANDARD_RTTI(ModuleBase_FilterLinearEdge)
+
+};
+
+#endif //ModuleBase_FilterLinearEdge
index bd0c987e47aa2f04572fed3f8f7da6678408633b..ab6aa1f3e40e68196566bbde98290d3058c29f67 100644 (file)
@@ -107,6 +107,7 @@ ModuleBase_Operation* ModuleBase_IModule::createOperation(const std::string& the
 void ModuleBase_IModule::createFeatures()
 {
   registerValidators();
+  registerFilters();
 
   Config_ModuleReader aXMLReader = Config_ModuleReader();
   aXMLReader.readAll();
index 46d0e81ca36b8b5d414a78bdf4d30ce96cc2fa47..f6219675ce0679430ddbf3b878941ebd066d933d 100644 (file)
@@ -119,6 +119,9 @@ protected slots:
   /// Register validators for this module\r
   virtual void registerValidators() {}\r
 \r
+  /// Register selection filters for this module\r
+  virtual void registerFilters() {}\r
+\r
   /// Returns new instance of operation object (used in createOperation for customization)\r
   virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);\r
 \r
diff --git a/src/ModuleBase/ModuleBase_IWorkshop.cpp b/src/ModuleBase/ModuleBase_IWorkshop.cpp
new file mode 100644 (file)
index 0000000..7ea7fe5
--- /dev/null
@@ -0,0 +1,12 @@
+// File:        ModuleBase_ModelWidget.h
+// Created:     25 Apr 2014
+// Author:      Natalia ERMOLAEVA
+
+#include "ModuleBase_IWorkshop.h"
+#include "ModuleBase_FilterFactory.h"
+
+ModuleBase_FilterFactory* ModuleBase_IWorkshop::selectionFilters() const
+{
+  static ModuleBase_FilterFactory* aFactory = new ModuleBase_FilterFactory;
+  return aFactory;
+}
index 94c1800d11d3a29124a16402c96ce04113bd666d..46ff9f84a817547eaa6655e7cfdfadcfaea2c711 100644 (file)
@@ -17,6 +17,7 @@ class ModuleBase_IModule;
 class ModuleBase_ISelection;
 class ModuleBase_IViewer;
 class ModuleBase_Operation;
+class ModuleBase_FilterFactory;
 
 /**
  * Class which provides access to Workshop object serveces
@@ -47,6 +48,9 @@ Q_OBJECT
   //! Returns current viewer
   virtual ModuleBase_IViewer* viewer() const = 0;
 
+  //! Returns the factory of selection filters : the only one instance per application
+  ModuleBase_FilterFactory* selectionFilters() const;
+  
   //! Returns currently active operation
   virtual ModuleBase_Operation* currentOperation() const = 0;
 
index 7ecd6033b6905972b5214d9abda3640c414cc35e..0d9aa900805e46563159b3d35b23902e8901d0a3 100644 (file)
@@ -12,6 +12,9 @@
 #include <ModuleBase_IViewWindow.h>
 #include <ModuleBase_IPropertyPanel.h>
 #include <ModuleBase_WidgetEditor.h>
+#include <ModuleBase_FilterFactory.h>
+#include <ModuleBase_FilterLinearEdge.h>
+
 
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Events.h>
@@ -141,6 +144,14 @@ void PartSet_Module::registerValidators()
   aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
 }
 
+void PartSet_Module::registerFilters()
+{
+  //Registering of selection filters
+  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
+  ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
+
+  aFactory->registerFilter("LinearEdgeFilter", new ModuleBase_FilterLinearEdge);
+}
 
 void PartSet_Module::onOperationComitted(ModuleBase_Operation* theOperation) 
 {
index bf61299979a4d43be788abf0fc8acff7a572ecfd..e85205aed451eb8180114af2fc8968202c7151de 100644 (file)
@@ -107,6 +107,9 @@ protected slots:
   /// Register validators for this module
   virtual void registerValidators();
 
+  /// Register selection filters for this module
+  virtual void registerFilters();
+
  private slots:
    void onVertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape);
 
index 301839bf241424fc41bf310406e7ad6b0f773f09..b04468f7d18ea5f53ac411207c6a77a9787e0365 100644 (file)
 #include <ModuleBase_WidgetFactory.h>
 #include <ModuleBase_Tools.h>
 #include <ModuleBase_IViewer.h>
+#include<ModuleBase_FilterFactory.h>
 
 #include <Config_Common.h>
 #include <Config_FeatureMessage.h>
 #include <Config_PointerMessage.h>
 #include <Config_ModuleReader.h>
 #include <Config_PropManager.h>
+#include <Config_SelectionFilterMessage.h>
 
 #include <QApplication>
 #include <QFileDialog>
@@ -183,8 +185,10 @@ void XGUI_Workshop::startApplication()
   aLoop->registerListener(this, Events_Loop::eventByName("CurrentDocumentChanged"));
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TOSHOW));
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TOHIDE));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_SELFILTER_LOADED));
 
   registerValidators();
+
   // Calling of  loadCustomProps before activating module is required
   // by Config_PropManger to restore user-defined path to plugins
   XGUI_Preferences::loadCustomProps();
@@ -415,7 +419,21 @@ void XGUI_Workshop::processEvent(const std::shared_ptr<Events_Message>& theMessa
     // If not found then activate global document
     activatePart(ResultPartPtr()); 
 
-  } else {
+  }
+  else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_SELFILTER_LOADED)) {
+    std::shared_ptr<Config_SelectionFilterMessage> aMsg = 
+      std::dynamic_pointer_cast<Config_SelectionFilterMessage>(theMessage);
+    if (aMsg) {
+      if (aMsg->attributeId().empty()) {  // feature validator
+        moduleConnector()->selectionFilters()->assignFilter(aMsg->selectionFilterId(), aMsg->featureId(), aMsg->attributeId());
+      } else {  // attribute validator
+        moduleConnector()->selectionFilters()->assignFilter(aMsg->selectionFilterId(), aMsg->featureId(), aMsg->attributeId());
+      }
+    }
+  }
+
+  
+  else {
     //Show error dialog if error message received.
     std::shared_ptr<Events_Error> anAppError = std::dynamic_pointer_cast<Events_Error>(theMessage);
     if (anAppError) {