Salome HOME
Add BelongsTo filter prototipe
authorvsv <vsv@opencascade.com>
Tue, 4 Jun 2019 11:55:00 +0000 (14:55 +0300)
committervsv <vsv@opencascade.com>
Tue, 4 Jun 2019 11:55:00 +0000 (14:55 +0300)
src/FiltersPlugin/FiltersPlugin_BelongsTo.cpp [new file with mode: 0644]
src/FiltersPlugin/FiltersPlugin_BelongsTo.h [new file with mode: 0644]
src/ModelAPI/ModelAPI_Filter.h
src/ModuleBase/ModuleBase_WidgetSelectionFilter.cpp
src/ModuleBase/ModuleBase_WidgetSelectionFilter.h

diff --git a/src/FiltersPlugin/FiltersPlugin_BelongsTo.cpp b/src/FiltersPlugin/FiltersPlugin_BelongsTo.cpp
new file mode 100644 (file)
index 0000000..0f4f9b5
--- /dev/null
@@ -0,0 +1,46 @@
+// 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_BelongsTo.h"
+
+bool FiltersPlugin_BelongsTo::isSupported(GeomAPI_Shape::ShapeType theType) const
+{
+  return true;
+}
+
+bool FiltersPlugin_BelongsTo::isOk(const GeomShapePtr& theShape,
+  const ModelAPI_FiltersArgs& theArgs) const
+{
+  return true;
+}
+
+static std::string XMLRepresentation =
+"<filter id = \"Belongs to\""
+" <multi_selector id=\"Belongs to\""
+"   label = \"Objects:\""
+"   tooltip = \"Select objects to limit selection.\""
+"   type_choice = \"objects\""
+" </multi_selector>"
+"</filter>";
+
+
+std::string FiltersPlugin_BelongsTo::xmlRepresentation() const
+{
+  return XMLRepresentation;
+}
\ No newline at end of file
diff --git a/src/FiltersPlugin/FiltersPlugin_BelongsTo.h b/src/FiltersPlugin/FiltersPlugin_BelongsTo.h
new file mode 100644 (file)
index 0000000..1976269
--- /dev/null
@@ -0,0 +1,54 @@
+// 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_BELONGSTO_H_
+#define FILTERSPLUGIN_BELONGSTO_H_
+
+#include "FiltersPlugin.h"
+
+#include <ModelAPI_Filter.h>
+
+/**\class FiltersPlugin_HorizontalFace
+* \ingroup DataModel
+* \brief Filter for horizontal faces only
+*/
+class FiltersPlugin_BelongsTo : public ModelAPI_Filter
+{
+public:
+  FiltersPlugin_BelongsTo() : ModelAPI_Filter() {}
+
+  virtual const std::string& name() const {
+    static const std::string kName("Belongs to");
+    return kName;
+  }
+
+  /// Returns true for any type because it supports all selection types
+  virtual bool isSupported(GeomAPI_Shape::ShapeType theType) const override;
+
+  /// This method should contain the filter logic. It returns true if the given shape
+  /// is accepted by the filter.
+  /// \param theShape the given shape
+  virtual bool isOk(const GeomShapePtr& theShape,
+    const ModelAPI_FiltersArgs& theArgs) const override;
+
+  /// Returns XML string which represents GUI of the filter
+  virtual std::string xmlRepresentation() const override;
+};
+
+#endif
\ No newline at end of file
index 4399e1063854c97ed0be3fd6d86921d06912cd82..e313d9f24299eb594aa21ffa695a195ec49bba7f 100644 (file)
@@ -73,6 +73,10 @@ public:
   /// \param theShape the given shape
   virtual bool isOk(const GeomShapePtr& theShape, const ModelAPI_FiltersArgs& theArgs) const = 0;
 
+  /// Returns XML string which represents GUI of the filter
+  /// By default it retrurns nothing (no GUI)
+  virtual std::string xmlRepresentation() const { return ""; }
+
 private:
   bool myIsReverse;
 };
index 9da94eb6ccacce135d14b5e598a44cd57692bcf4..d8b9233c8fb1ba1d8ec86dd5906ba7e8aadf1522 100644 (file)
@@ -128,6 +128,8 @@ ModuleBase_FilterItem::ModuleBase_FilterItem(
   : QWidget(theParent), myFilterID(theFilter),
     mySelection(std::dynamic_pointer_cast<ModelAPI_FiltersFeature>(theSelection))
 {
+  std::string aXmlString = ModelAPI_Session::get()->filters()->filter(theFilter)->xmlRepresentation();
+
   QHBoxLayout* aLayout = new QHBoxLayout(this);
   ModuleBase_Tools::zeroMargins(aLayout);
 
@@ -155,11 +157,12 @@ ModuleBase_FilterItem::ModuleBase_FilterItem(
 
 void ModuleBase_FilterItem::onReverse(bool theCheck)
 {
-  //mySelection->setReversed(myFilterID, theCheck);
+  mySelection->setReversed(myFilterID, theCheck);
   if (theCheck)
     myRevBtn->setIcon(QIcon(":pictures/reverce.png"));
   else
     myRevBtn->setIcon(QIcon(":pictures/add.png"));
+  emit reversedItem(this);
 }
 
 void ModuleBase_FilterItem::onDelete()
@@ -292,9 +295,11 @@ void ModuleBase_WidgetSelectionFilter::onAddFilter(int theIndex)
   if (!aFilter.empty()) {
     myUseFilters.push_back(aFilter);
     ModuleBase_FilterItem* aItem =
-      new ModuleBase_FilterItem(aFilter, mySelectorFeature, myFiltersWgt);
+      new ModuleBase_FilterItem(aFilter, myFeature, myFiltersWgt);
     connect(aItem, SIGNAL(deleteItem(ModuleBase_FilterItem*)),
       SLOT(onDeleteItem(ModuleBase_FilterItem*)));
+    connect(aItem, SIGNAL(reversedItem(ModuleBase_FilterItem*)),
+      SLOT(onReverseItem(ModuleBase_FilterItem*)));
     myFiltersLayout->addWidget(aItem);
 
     FiltersFeaturePtr aFiltersFeature =
@@ -327,6 +332,13 @@ void ModuleBase_WidgetSelectionFilter::onDeleteItem(ModuleBase_FilterItem* theIt
   updateNumberSelected();
 }
 
+void ModuleBase_WidgetSelectionFilter::onReverseItem(ModuleBase_FilterItem* theItem)
+{
+  updateSelectBtn();
+  clearCurrentSelection(true);
+  updateNumberSelected();
+}
+
 void ModuleBase_WidgetSelectionFilter::onSelect()
 {
   if (myUseFilters.size() == 0)
index 39645d88b506ff26450d629732c7ce55ecf7e529..381ed5f4b9a4fb62acbd3def120b818c8d7c92bd 100644 (file)
@@ -74,8 +74,9 @@ public:
 
 signals:
   void deleteItem(ModuleBase_FilterItem* theItem);
+  void reversedItem(ModuleBase_FilterItem* theItem);
 
-  private slots:
+private slots:
   void onReverse(bool theCheck);
   void onDelete();
 
@@ -113,6 +114,7 @@ protected:
 private slots:
   void onAddFilter(int);
   void onDeleteItem(ModuleBase_FilterItem* theItem);
+  void onReverseItem(ModuleBase_FilterItem* theItem);
   void onSelect();
   void onShowOnly(bool theErase);