Salome HOME
Implement filter "F9: External Faces"
[modules/shaper.git] / src / FiltersPlugin / FiltersPlugin_BelongsTo.cpp
index 854fc26c9c030dff5d6866a3c4af58a0cdae2b1a..6a1553acedb9a7a4997630b09bc60be439d2de0c 100644 (file)
 
 #include "FiltersPlugin_BelongsTo.h"
 
+#include <ModelAPI_AttributeSelectionList.h>
+
 bool FiltersPlugin_BelongsTo::isSupported(GeomAPI_Shape::ShapeType theType) const
 {
   return true;
 }
 
-bool FiltersPlugin_BelongsTo::isOk(const GeomShapePtr& theShape,
-  const ModelAPI_FiltersArgs& theArgs) const
+bool FiltersPlugin_BelongsTo::isOk(const GeomShapePtr& theShape, const ResultPtr&,
+                                   const ModelAPI_FiltersArgs& theArgs) const
 {
-  return true;
+  AttributePtr aAttr = theArgs.argument("BelongsTo");
+  AttributeSelectionListPtr aList =
+    std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(aAttr);
+  if (!aList.get())
+    return false;
+  for (int i = 0; i < aList->size(); i++) {
+    AttributeSelectionPtr aAttr = aList->value(i);
+    GeomShapePtr aGeom = aAttr->value();
+    if (aGeom->isSubShape(theShape))
+      return true;
+  }
+  return false;
 }
 
 static std::string XMLRepresentation =
-"<filter id = \"Belongs to\">"
-" <multi_selector id=\"Belongs to\""
-"   label = \"Objects:\""
-"   tooltip = \"Select objects to limit selection.\""
-"   type_choice = \"objects\">"
+"<filter id = \"BelongsTo\">"
+" <multi_selector id=\"BelongsTo__BelongsTo\""
+"   label=\"Objects:\""
+"   tooltip=\"Select objects to limit selection.\""
+"   type_choice=\"objects\">"
 " </multi_selector>"
 "</filter>";
 
@@ -43,4 +56,9 @@ static std::string XMLRepresentation =
 std::string FiltersPlugin_BelongsTo::xmlRepresentation() const
 {
   return XMLRepresentation;
-}
\ No newline at end of file
+}
+
+void FiltersPlugin_BelongsTo::initAttributes(ModelAPI_FiltersArgs& theArguments)
+{
+  theArguments.initAttribute("BelongsTo", ModelAPI_AttributeSelectionList::typeId());
+}