]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
An interface creation for a separate filter in order to use as a filter the OCC reali...
authornds <natalia.donis@opencascade.com>
Tue, 16 Dec 2014 05:50:37 +0000 (08:50 +0300)
committernds <natalia.donis@opencascade.com>
Tue, 16 Dec 2014 05:50:37 +0000 (08:50 +0300)
13 files changed:
src/ConstructionPlugin/plane_widget.xml
src/ModuleBase/CMakeLists.txt
src/ModuleBase/ModuleBase_Filter.cpp
src/ModuleBase/ModuleBase_Filter.h
src/ModuleBase/ModuleBase_FilterFace.cpp [new file with mode: 0644]
src/ModuleBase/ModuleBase_FilterFace.h [new file with mode: 0644]
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/PartSet/PartSet_Module.cpp
src/SketchPlugin/plugin-Sketch.xml

index bf062da02cb222a25597be8725baa461df0669ff..8697dcca05cde95edbe23424946da0f8ad2678bf 100644 (file)
@@ -5,7 +5,9 @@
                   label="Plane face" 
                   tooltip="Select a planar face for plane definition"
                   shape_types="face"
-                  use_subshapes="true" />
+                  use_subshapes="true">
+                 <selection_filter id="FaceFilter" parameters="plane"/>
+  </shape_selector>
   <doublevalue id="distance" 
                label="Distance" 
                tooltip="Distance from selected face to plane" 
index cc1b006a202313d0ee4b808328c96f87b0f308ae..a7d3cc5007cc72490c14671c837df19b9d793ec2 100644 (file)
@@ -6,6 +6,7 @@ SET(CMAKE_AUTOMOC ON)
 SET(PROJECT_HEADERS
        ModuleBase.h
        ModuleBase_Filter.h
+       ModuleBase_FilterFace.h
        ModuleBase_FilterFactory.h
        ModuleBase_FilterLinearEdge.h
        ModuleBase_Tools.h
@@ -41,6 +42,7 @@ SET(PROJECT_HEADERS
 
 SET(PROJECT_SOURCES
        ModuleBase_Filter.cpp
+       ModuleBase_FilterFace.cpp
        ModuleBase_FilterFactory.cpp
        ModuleBase_FilterLinearEdge.cpp
        ModuleBase_Tools.cpp
index 05056f31278fbeeb20c0482ea6c43583c9833077..c799ed47fee04187511a76b949f1ffb3fd040bac 100644 (file)
@@ -4,13 +4,12 @@
 // 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
+Handle(SelectMgr_Filter) ModuleBase_Filter::getFilter()
 {
-  return Standard_True;
+  if (myFilter.IsNull())
+    createFilter();
+
+  return myFilter;
 }
index c18a6a56725b989e1a7ddd9e95e4e3f01f11217d..7b1f63d1e91c66ad02fb295675011988ed6f5994 100644 (file)
@@ -11,6 +11,8 @@
 
 #include <SelectMgr_Filter.hxx>
 
+#include <list>
+
 /**
  * This object is assigned by the name
  * in the XML file to the specific attribute or to the whole feature.
  * 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
+class ModuleBase_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)
+  MODULEBASE_EXPORT ModuleBase_Filter() {}
+
+  /**
+   * Returns an OCC selection filter. It can be appended into the context of a viewer
+   * It creates a filter if it has not be created yet.
+   * \return the selection filter
+   */
+  MODULEBASE_EXPORT Handle(SelectMgr_Filter) getFilter();
+
+  /**
+   * Sets the arguments to the filter.
+   * \param theArguments a list of arguments
+   */
+  MODULEBASE_EXPORT virtual void setArguments(const std::list<std::string>& theArguments) = 0;
+protected:
+  /**
+   * It creates an internal instance of the OCC filter
+   */
+  virtual void createFilter() = 0;
+
+protected:
+  Handle(SelectMgr_Filter) myFilter; // current instance of the OCC selection filter
 };
 
 #endif //ModuleBase_Filter
diff --git a/src/ModuleBase/ModuleBase_FilterFace.cpp b/src/ModuleBase/ModuleBase_FilterFace.cpp
new file mode 100644 (file)
index 0000000..8391e17
--- /dev/null
@@ -0,0 +1,47 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModuleBase_FilterFace.cpp
+// Created:     10 Dec 2014
+// Author:      Natalia ERMOLAEVA
+
+
+#include "ModuleBase_FilterFace.h"
+
+#include <StdSelect_FaceFilter.hxx>
+#include <StdSelect_TypeOfFace.hxx>
+
+#include <Events_Error.h>
+
+#include <QString>
+#include <QMap>
+
+typedef QMap<QString, StdSelect_TypeOfFace> FaceTypes;
+static FaceTypes MyFaceTypes;
+
+StdSelect_TypeOfFace ModuleBase_FilterFace::faceType(const std::string& theType)
+{
+  if (MyFaceTypes.count() == 0) {
+    MyFaceTypes["plane"] = StdSelect_Plane;
+  }
+  QString aType = QString(theType.c_str()).toLower();
+  if (MyFaceTypes.contains(aType))
+    return MyFaceTypes[aType];
+  Events_Error::send("Face type defined in XML is not implemented!");
+  return StdSelect_AnyFace;
+}
+
+void ModuleBase_FilterFace::createFilter()
+{
+  myFilter = new StdSelect_FaceFilter(StdSelect_AnyFace);
+}
+
+void ModuleBase_FilterFace::setArguments(const std::list<std::string>& theArguments)
+{
+  if (theArguments.size()!= 1)
+    return;
+
+  std::string anArgument = theArguments.front();
+  Handle(StdSelect_FaceFilter) aFilter = Handle(StdSelect_FaceFilter)::DownCast(getFilter());
+  if (!aFilter.IsNull())
+    aFilter->SetType(faceType(anArgument));
+}
diff --git a/src/ModuleBase/ModuleBase_FilterFace.h b/src/ModuleBase/ModuleBase_FilterFace.h
new file mode 100644 (file)
index 0000000..4e6919a
--- /dev/null
@@ -0,0 +1,38 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        ModuleBase_FilterFace.h
+// Created:     10 Dec 2014
+// Author:      Natalia ERMOLAEVA
+
+#ifndef ModuleBase_FilterFace_H
+#define ModuleBase_FilterFace_H
+
+#include "ModuleBase.h"
+
+#include "ModuleBase_Filter.h"
+
+#include <StdSelect_TypeOfFace.hxx>
+
+class ModuleBase_FilterFace: public ModuleBase_Filter
+{
+public:
+  static MODULEBASE_EXPORT StdSelect_TypeOfFace faceType(const std::string& theType);
+
+  MODULEBASE_EXPORT ModuleBase_FilterFace(): 
+      ModuleBase_Filter() {}
+
+  /**
+   * Sets the arguments to the filter.
+   * \param theArguments a list of arguments
+   */
+  MODULEBASE_EXPORT virtual void setArguments(const std::list<std::string>& theArguments);
+
+protected:
+  /**
+   * It creates an OCC face filter
+   */
+  virtual void createFilter();
+
+};
+
+#endif //ModuleBase_FilterFace
index c1fb82fc2d04c846e7dace999e65f1cd46214ecd..f89d6e71b8d931287684c92440f03c13ebb07138 100644 (file)
@@ -16,7 +16,7 @@
 
 
 void ModuleBase_FilterFactory::registerFilter(const std::string& theID,
-                                              Handle(ModuleBase_Filter) theFilter)
+                                              ModuleBase_Filter* theFilter)
 {
   if (myIDs.find(theID) != myIDs.end()) {
     Events_Error::send(std::string("Filter ") + theID + " is already registered");
@@ -48,7 +48,7 @@ void ModuleBase_FilterFactory::assignFilter(const std::string& theID,
 void ModuleBase_FilterFactory::filters(const std::string& theFeatureID,
                                        const std::string& theAttrID,
                                        SelectMgr_ListOfFilter& theFilters/*,
-                                        std::list<Handle(ModuleBase_Filter)>& theFilters/*,
+                                        std::list<ModuleBase_Filter*>& theFilters/*,
                                         std::list<std::list<std::string> >& theArguments*/) const
 {
   SelectMgr_ListOfFilter aFilters;
@@ -60,16 +60,17 @@ void ModuleBase_FilterFactory::filters(const std::string& theFeatureID,
     if (anAttr != aFeature->second.end()) {
       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(
+        std::map<std::string, ModuleBase_Filter*>::const_iterator aFound = myIDs.find(
           aValIter->first);
         if (aFound == myIDs.end()) {
           Events_Error::send(std::string("Filter ") + aValIter->first + " was not registered");
         } else {
-          Handle(ModuleBase_Filter) aFilter = aFound->second;
-          if (aFilter.IsNull())
-            continue;
+          ModuleBase_Filter* aFilter = aFound->second;
+          aFilter->setArguments(aValIter->second);
+          //if (aFilter.IsNull())
+          //  continue;
 
-          theFilters.Append(aFilter);//aFound->second);
+          theFilters.Append(aFilter->getFilter());//aFound->second);
           //theArguments.push_back(aValIter->second);
         }
       }
@@ -83,9 +84,9 @@ ModuleBase_FilterFactory::ModuleBase_FilterFactory()
   //registerFilter(kDefaultId, new Model_FeatureFilter);
 }
 
-const Handle(ModuleBase_Filter) ModuleBase_FilterFactory::filter(const std::string& theID) const
+const 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, ModuleBase_Filter*>::const_iterator aIt = myIDs.find(theID);
   if (aIt != myIDs.end()) {
     return aIt->second;
   }
index a0759f25c517ca89d930811f5a5f7705331f7a7f..043bd64ad8ce1c52324ebc9ebaf510530855fd36 100644 (file)
@@ -28,7 +28,7 @@
 class ModuleBase_FilterFactory : public QObject
 {
  private:
-  std::map<std::string, Handle_ModuleBase_Filter> myIDs;  ///< map from ID to registered filter
+  std::map<std::string, 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
@@ -39,7 +39,7 @@ class ModuleBase_FilterFactory : public QObject
  public:
   /// Registers the instance of the filter by the ID
   MODULEBASE_EXPORT virtual void registerFilter(const std::string& theID,
-                                                Handle_ModuleBase_Filter theFilter);
+                                                ModuleBase_Filter* theFilter);
 
   /// Assigns filter to the attribute of the feature
   MODULEBASE_EXPORT virtual void assignFilter(const std::string& theID,
@@ -53,7 +53,7 @@ class ModuleBase_FilterFactory : public QObject
                                  SelectMgr_ListOfFilter& theFilters) const;
 
   /// Returns registered filter by its Id
-  MODULEBASE_EXPORT virtual const Handle_ModuleBase_Filter filter(const std::string& theID) const;
+  MODULEBASE_EXPORT virtual const ModuleBase_Filter* filter(const std::string& theID) const;
 
 protected:
   ModuleBase_FilterFactory();
index 97f5ffa9a7e80a7d12b4a973c04bd7e9d1498a22..a5634cba4a8f92609d63426cec0523045ca18486 100644 (file)
@@ -6,47 +6,43 @@
 
 
 #include "ModuleBase_FilterLinearEdge.h"
-#include "ModuleBase_IWorkshop.h"
 
-#include <ModelAPI_Session.h>
-#include <ModelAPI_Document.h>
-#include <ModelAPI_ResultConstruction.h>
+#include <StdSelect_EdgeFilter.hxx>
+#include <StdSelect_TypeOfEdge.hxx>
 
-#include <AIS_InteractiveObject.hxx>
-#include <AIS_Shape.hxx>
+#include <Events_Error.h>
 
-#include <StdSelect_BRepOwner.hxx>
+#include <QString>
+#include <QMap>
 
-#include <GeomAPI_Edge.h>
+typedef QMap<QString, StdSelect_TypeOfEdge> EdgeTypes;
+static EdgeTypes MyEdgeTypes;
 
-#include <BRep_Tool.hxx>
-#include <TopoDS.hxx>
-#include <TopoDS_Edge.hxx>
-#include <Geom_Curve.hxx>
-
-
-IMPLEMENT_STANDARD_HANDLE(ModuleBase_FilterLinearEdge, ModuleBase_Filter);
-IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_FilterLinearEdge, ModuleBase_Filter);
+StdSelect_TypeOfEdge ModuleBase_FilterLinearEdge::edgeType(const std::string& theType)
+{
+  if (MyEdgeTypes.count() == 0) {
+    MyEdgeTypes["line"] = StdSelect_Line;
+    MyEdgeTypes["circle"] = StdSelect_Circle;
+  }
+  QString aType = QString(theType.c_str()).toLower();
+  if (MyEdgeTypes.contains(aType))
+    return MyEdgeTypes[aType];
+  Events_Error::send("Edge type defined in XML is not implemented!");
+  return StdSelect_AnyEdge;
+}
 
+void ModuleBase_FilterLinearEdge::createFilter()
+{
+  myFilter = new StdSelect_EdgeFilter(StdSelect_AnyEdge);
+}
 
-Standard_Boolean ModuleBase_FilterLinearEdge::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
+void ModuleBase_FilterLinearEdge::setArguments(const std::list<std::string>& theArguments)
 {
-  Standard_Boolean isOk = ModuleBase_Filter::IsOk(theOwner);
-  if (isOk && theOwner->HasSelectable()) {
-    Handle(AIS_InteractiveObject) anAIS = 
-      Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
-    if (!anAIS.IsNull()) {
-      Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAIS);
-      if (aShapeAIS) {
-        const TopoDS_Shape& aShape = aShapeAIS->Shape();
-        if (aShape.ShapeType()  == TopAbs_EDGE) {
-          std::shared_ptr<GeomAPI_Edge> anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge());
-          anEdge->setImpl(new TopoDS_Shape(aShape));
-
-          isOk = anEdge->isLine();
-        }
-      }
-    }
-  }
-  return isOk;
+  if (theArguments.size()!= 1)
+    return;
+
+  std::string anArgument = theArguments.front();
+  Handle(StdSelect_EdgeFilter) aFilter = Handle(StdSelect_EdgeFilter)::DownCast(getFilter());
+  if (!aFilter.IsNull())
+    aFilter->SetType(edgeType(anArgument));
 }
index 7f3b798f8b642383ed2a5769a99698da89baeb7b..cdfa8e4351ad0f9976bf74e1dd9feb8e5ffd63eb 100644 (file)
 
 #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, ModuleBase_Filter);
+#include <StdSelect_TypeOfEdge.hxx>
+
 class ModuleBase_FilterLinearEdge: public ModuleBase_Filter
 {
 public:
-  Standard_EXPORT ModuleBase_FilterLinearEdge(): 
-      ModuleBase_Filter() {}
+  static MODULEBASE_EXPORT StdSelect_TypeOfEdge edgeType(const std::string& theType);
 
-  Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const;
+  MODULEBASE_EXPORT ModuleBase_FilterLinearEdge(): 
+      ModuleBase_Filter() {}
 
-  DEFINE_STANDARD_RTTI(ModuleBase_FilterLinearEdge)
+  /**
+   * Sets the arguments to the filter.
+   * \param theArguments a list of arguments
+   */
+  MODULEBASE_EXPORT virtual void setArguments(const std::list<std::string>& theArguments);
+
+protected:
+  /**
+   * It creates an OCC edge filter
+   */
+  virtual void createFilter();
 
 };
 
index 49fe8cf55b8043e12aa6fb36fcc9b9696e828059..1ef62f92a0788a56d77ea8959fb891a321d48963 100644 (file)
@@ -444,13 +444,13 @@ void ModuleBase_WidgetShapeSelector::activateSelection(bool toActivate)
     if (aSelFilter.IsNull())
       continue;
 
-    Handle(ModuleBase_Filter) aFilter = Handle(ModuleBase_Filter)::DownCast(aIt.Value());
-    if (aFilter.IsNull())
-      continue;
+    //Handle(ModuleBase_Filter) aFilter = Handle(ModuleBase_Filter)::DownCast(aIt.Value());
+    //if (aFilter.IsNull())
+    //  continue;
     if (myIsActive)
-      aViewer->addSelectionFilter(aFilter);
+      aViewer->addSelectionFilter(aSelFilter);
     else
-      aViewer->removeSelectionFilter(aFilter);
+      aViewer->removeSelectionFilter(aSelFilter);
   }
 }
 
index c154d43d4804b95a66db049279c76be00e05d770..146dfa692d083494a06a0e2d78a946295cbd7c56 100644 (file)
@@ -15,6 +15,7 @@
 #include <ModuleBase_WidgetEditor.h>
 #include <ModuleBase_FilterFactory.h>
 #include <ModuleBase_FilterLinearEdge.h>
+#include <ModuleBase_FilterFace.h>
 
 
 #include <ModelAPI_Object.h>
@@ -148,7 +149,8 @@ void PartSet_Module::registerFilters()
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
   ModuleBase_FilterFactory* aFactory = aConnector->selectionFilters();
 
-  aFactory->registerFilter("LinearEdgeFilter", new ModuleBase_FilterLinearEdge);
+  aFactory->registerFilter("EdgeFilter", new ModuleBase_FilterLinearEdge);
+  aFactory->registerFilter("FaceFilter", new ModuleBase_FilterFace);
 }
 
 void PartSet_Module::operationCommitted(ModuleBase_Operation* theOperation) 
index 571c97d778faad15a39edfb0648d8e29969f332b..f63903b659e84a2190382ed388ec2ae986ce72de 100644 (file)
@@ -68,6 +68,7 @@
                <shape_selector id="ConstraintEntityA" label="Circle or Arc" tooltip="Select a circle or an arc in the viewer" 
                        shape_types="edge">
                        <validator id="SketchPlugin_ResultArc"/>
+                       <selection_filter id="EdgeFilter" parameters="circle"/>
                </shape_selector>
         <sketch-2dpoint_selector id="ConstraintFlyoutValuePnt" internal="1" obligatory="0"/>
         <doublevalue_editor label="Value" tooltip="Constraint value" id="ConstraintValue" default="computed"/>
                <sketch_constraint_shape_selector id="ConstraintEntityA" 
                        label="First line" tooltip="Select an line in the viewer" 
                        shape_types="edge" use_subshapes="true">
-                       <selection_filter id="LinearEdgeFilter"/>
+                       <selection_filter id="EdgeFilter" parameters="line"/>
                </sketch_constraint_shape_selector>
                
                <sketch_constraint_shape_selector id="ConstraintEntityB" label="Last line" tooltip="Select an line in the viewer" 
                        shape_types="edge" use_subshapes="true">
+                       <selection_filter id="EdgeFilter" parameters="line"/>
                        <validator id="SketchPlugin_DifferentObjects"/>
                </sketch_constraint_shape_selector>