]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #2949: "On geometry" filter correct name and selection mechanism
authorazv <azv@opencascade.com>
Mon, 29 Jul 2019 14:50:24 +0000 (17:50 +0300)
committerazv <azv@opencascade.com>
Mon, 29 Jul 2019 14:51:01 +0000 (17:51 +0300)
Implement new validator to select shape types specified by the Group feature.

src/FiltersPlugin/CMakeLists.txt
src/FiltersPlugin/FiltersPlugin_Plugin.cpp
src/FiltersPlugin/FiltersPlugin_Validators.cpp [new file with mode: 0644]
src/FiltersPlugin/FiltersPlugin_Validators.h [new file with mode: 0644]
src/FiltersPlugin/filter-OnGeometry.xml
src/GeomValidators/GeomValidators_ShapeType.cpp
src/GeomValidators/GeomValidators_ShapeType.h

index 5a52a8cfd147800999c8f6edf51eecb1a082a4e1..f4dd058390f721a3901c6f093779e48854b8c6f1 100644 (file)
@@ -34,6 +34,7 @@ SET(PROJECT_HEADERS
     FiltersPlugin_OppositeToEdge.h
     FiltersPlugin_RelativeToSolid.h
     FiltersPlugin_ExternalFaces.h
+    FiltersPlugin_Validators.h
 )
 
 SET(PROJECT_SOURCES
@@ -49,6 +50,7 @@ SET(PROJECT_SOURCES
     FiltersPlugin_OppositeToEdge.cpp
     FiltersPlugin_RelativeToSolid.cpp
     FiltersPlugin_ExternalFaces.cpp
+    FiltersPlugin_Validators.cpp
 )
 
 SET(PROJECT_LIBRARIES
@@ -57,6 +59,7 @@ SET(PROJECT_LIBRARIES
     Config
     GeomAPI
     GeomAlgoAPI
+    GeomValidators
 )
 
 SET(PROJECT_PYFILES
@@ -87,6 +90,8 @@ INCLUDE_DIRECTORIES(
   ${PROJECT_SOURCE_DIR}/src/GeomAPI
   ${PROJECT_SOURCE_DIR}/src/GeomAlgoAPI
   ${PROJECT_SOURCE_DIR}/src/GeomDataAPI
+  ${PROJECT_SOURCE_DIR}/src/GeomValidators
+  ${PROJECT_SOURCE_DIR}/src/CollectionPlugin
 )
 
 INSTALL(TARGETS Filters DESTINATION ${SHAPER_INSTALL_PLUGIN_FILES})
index 0ff5b5f69386d11988ddec1e2fc121663e3b6f04..e7bc6a9ad529668ba1896659d66f9eb7981035d8 100644 (file)
@@ -29,6 +29,7 @@
 #include "FiltersPlugin_OppositeToEdge.h"
 #include "FiltersPlugin_RelativeToSolid.h"
 #include "FiltersPlugin_ExternalFaces.h"
+#include "FiltersPlugin_Validators.h"
 
 #include <Config_ModuleReader.h>
 
@@ -40,7 +41,7 @@ static FiltersPlugin_Plugin* MY_VIEWFILTERS_INSTANCE = new FiltersPlugin_Plugin(
 
 FiltersPlugin_Plugin::FiltersPlugin_Plugin()
 {
-  // register validators
+  // register filters
   SessionPtr aMgr = ModelAPI_Session::get();
   ModelAPI_FiltersFactory* aFactory = aMgr->filters();
   aFactory->registerFilter("HorizontalFaces", new FiltersPlugin_HorizontalFace);
@@ -56,6 +57,11 @@ FiltersPlugin_Plugin::FiltersPlugin_Plugin()
 
   Config_ModuleReader::loadScript("FiltersPlugin_TopoConnectedFaces");
 
+  // register validators
+  ModelAPI_ValidatorsFactory* aValidators = aMgr->validators();
+  aValidators->registerValidator("FiltersPlugin_ShapeType",
+                                 new FiltersPlugin_ShapeTypeValidator);
+
   ModelAPI_Session::get()->registerPlugin(this);
 }
 
diff --git a/src/FiltersPlugin/FiltersPlugin_Validators.cpp b/src/FiltersPlugin/FiltersPlugin_Validators.cpp
new file mode 100644 (file)
index 0000000..c03b9ad
--- /dev/null
@@ -0,0 +1,52 @@
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "FiltersPlugin_Validators.h"
+
+#include <CollectionPlugin_Group.h>
+
+#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_Session.h>
+
+bool FiltersPlugin_ShapeTypeValidator::isValid(const AttributePtr& theAttribute,
+                                               const std::list<std::string>& theArguments,
+                                               Events_InfoMessage& theError) const
+{
+  if (!theAttribute)
+    return false;
+  FeaturePtr aFilterFeature = ModelAPI_Feature::feature(theAttribute->owner());
+  if (!aFilterFeature)
+    return false;
+
+  // iterate on groups and find the one having the current filters feature
+  DocumentPtr aCurDoc = ModelAPI_Session::get()->activeDocument();
+  std::list<FeaturePtr> aFeatList = aCurDoc->allFeatures();
+  for (std::list<FeaturePtr>::iterator anIt = aFeatList.begin(); anIt != aFeatList.end(); ++anIt)
+    if ((*anIt)->getKind() == CollectionPlugin_Group::ID()) {
+      AttributeSelectionListPtr aSelList =
+          (*anIt)->selectionList(CollectionPlugin_Group::LIST_ID());
+      if (aSelList->filters() == aFilterFeature) {
+        TypeOfShape aType = shapeType(aSelList->selectionType());
+        if (isValidAttribute(theAttribute, aType, theError))
+          return true;
+      }
+    }
+
+  return false;
+}
diff --git a/src/FiltersPlugin/FiltersPlugin_Validators.h b/src/FiltersPlugin/FiltersPlugin_Validators.h
new file mode 100644 (file)
index 0000000..78921da
--- /dev/null
@@ -0,0 +1,44 @@
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef FILTERSPLUGIN_VALIDATORS_H_
+#define FILTERSPLUGIN_VALIDATORS_H_
+
+#include "FiltersPlugin.h"
+
+#include <GeomValidators_ShapeType.h>
+
+/**
+ * Validates selection of "On geometry" filter to select only
+ * the shapes specified by the group type.
+ */
+class FiltersPlugin_ShapeTypeValidator : public GeomValidators_ShapeType
+{
+public:
+  /// \return True if the attribute is valid. It checks whether the shape is a
+  /// body subshape. Does not allow select construction shapes.
+  /// \param[in]  theAttribute an attribute to check
+  /// \param[in]  theArguments a filter parameters
+  /// \param[out] theError error message.
+  FILTERS_EXPORT virtual bool isValid(const AttributePtr& theAttribute,
+                                      const std::list<std::string>& theArguments,
+                                      Events_InfoMessage& theError) const;
+};
+
+#endif
\ No newline at end of file
index cd44c7ee211eb0bbde7c82b768ebfae0ad4cd378..80053d57ecaf236b4fe714ddefb7b62643b5b26e 100644 (file)
@@ -1,8 +1,8 @@
 <filter id="OnGeometry">
   <multi_selector id="OnGeometry__OnGeometry"
-                  label="Edges/faces:"
+                  label="Shapes:"
                   tooltip="Select objects to limit selection."
                   type_choice="edges faces">
-    <validator id="GeomValidators_ShapeType" parameters="edge,face"/>
+    <validator id="FiltersPlugin_ShapeType"/>
   </multi_selector>
 </filter>
index 963f53c9a12cc8851eae20fac69e1af0cd8aba68..e748d9ac6e1e6fdcea896fc400c9c814b1964c78 100644 (file)
@@ -33,6 +33,7 @@
 
 #include <Events_InfoMessage.h>
 
+#include <algorithm>
 #include <string>
 #include <map>
 
@@ -46,18 +47,23 @@ GeomValidators_ShapeType::TypeOfShape
   if (MyShapeTypes.size() == 0) {
     MyShapeTypes["empty"]     = Empty;
     MyShapeTypes["vertex"]    = Vertex;
+    MyShapeTypes["vertices"]  = Vertex;
     MyShapeTypes["edge"]      = Edge;
+    MyShapeTypes["edges"]     = Edge;
     MyShapeTypes["line"]      = Line;
     MyShapeTypes["circle"]    = Circle;
     MyShapeTypes["wire"]      = Wire;
     MyShapeTypes["face"]      = Face;
+    MyShapeTypes["faces"]     = Face;
     MyShapeTypes["plane"]     = Plane;
     MyShapeTypes["shell"]     = Shell;
     MyShapeTypes["solid"]     = Solid;
+    MyShapeTypes["solids"]    = Solid;
     MyShapeTypes["compsolid"] = CompSolid;
     MyShapeTypes["compound"]  = Compound;
   }
   std::string aType = std::string(theType.c_str());
+  std::transform(aType.begin(), aType.end(), aType.begin(), ::tolower);
   if (MyShapeTypes.find(aType) != MyShapeTypes.end())
     return MyShapeTypes[aType];
 
index d4f38cf5bfc3504cbdbb1b19ff8aaa2813814fa9..288af74397ce01dfaff90b02797d84b650978b1f 100644 (file)
@@ -66,12 +66,13 @@ class GeomValidators_ShapeType : public ModelAPI_AttributeValidator
 protected:
   /// Convert string to TypeOfShape value
   /// \param theType a string value
-  static TypeOfShape shapeType(const std::string& theType);
+  GEOMVALIDATORS_EXPORT static TypeOfShape shapeType(const std::string& theType);
 
   /// Returns true if the attibute's object type satisfies the argument value
   /// \param[in] theAttribute a checked attribute
   /// \param[in] theShapeType a type of shape
   /// \param[out] theError error message.
+  GEOMVALIDATORS_EXPORT
   bool isValidAttribute(const AttributePtr& theAttribute,
                         const TypeOfShape theShapeType,
                         Events_InfoMessage& theError) const;