]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #236: Provide filtering of selected objects for extrusion
authorvsv <vitaly.smetannikov@opencascade.com>
Fri, 7 Nov 2014 12:14:02 +0000 (15:14 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Fri, 7 Nov 2014 12:14:02 +0000 (15:14 +0300)
src/FeaturesPlugin/extrusion_widget.xml
src/ModuleBase/ModuleBase_IViewer.h
src/ModuleBase/ModuleBase_ViewerFilters.cpp
src/ModuleBase/ModuleBase_ViewerFilters.h
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.h
src/NewGeom/NewGeom_SalomeViewer.cpp
src/NewGeom/NewGeom_SalomeViewer.h
src/XGUI/XGUI_ViewerProxy.cpp
src/XGUI/XGUI_ViewerProxy.h

index c7c5f4bdd90bebae461edbd3873fae7ace5471a5..da2d99d2dbed4c7f7856c7db807b3d1bb7515bbb 100644 (file)
@@ -5,6 +5,7 @@
     tooltip="Select a face for extrusion"
     activate="true"
     shape_types="face"
+       object_types="construction"
     use_subshapes="true"
   />
   <doublevalue id="extrusion_size" label="Size" min="0" step="1.0" default="1" icon=":icons/dimension_v.png" tooltip="Set size of extrusion">
index 6858fbefc099ee1e140d62cf06b200cbbd828ac6..3e573d22379843ca8c1c6cd5c46f9030dc1b3f10 100644 (file)
@@ -53,6 +53,14 @@ Q_OBJECT
   /// \param theZ the Z projection value
   virtual void setViewProjection(double theX, double theY, double theZ) = 0;
 
+  /// Add selection filter to the viewer
+  virtual void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) = 0;
+
+  /// Remove selection filter from the viewer
+  virtual void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) = 0;
+
+  /// Remove all selection filters from the viewer
+  virtual void clearSelectionFilters() = 0;
 
 signals:
   void lastViewClosed();
index b10437101a851b008480626dab1abd86a57e9dae..c18fd0eaee48ff5041442082755b10f51ea28e5f 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Document.h>
+#include <ModelAPI_ResultConstruction.h>
 
 #include <AIS_InteractiveObject.hxx>
 #include <AIS_Shape.hxx>
@@ -81,3 +82,32 @@ Standard_Boolean ModuleBase_ShapeInPlaneFilter::IsOk(const Handle(SelectMgr_Enti
   }
   return Standard_False;
 }
+
+
+IMPLEMENT_STANDARD_HANDLE(ModuleBase_ObjectTypesFilter, SelectMgr_Filter);
+IMPLEMENT_STANDARD_RTTIEXT(ModuleBase_ObjectTypesFilter, SelectMgr_Filter);
+
+
+//TODO (VSV): Check bug in OCCT: Filter result is ignored (bug25340)
+Standard_Boolean ModuleBase_ObjectTypesFilter::IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const
+{
+  Standard_Boolean isOk = ModuleBase_ShapeDocumentFilter::IsOk(theOwner);
+  if (isOk && theOwner->HasSelectable()) {
+    Handle(AIS_InteractiveObject) aAisObj = 
+      Handle(AIS_InteractiveObject)::DownCast(theOwner->Selectable());
+    if (!aAisObj.IsNull()) {
+      boost::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 = 
+            boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aObj);
+          return (aConstr != NULL);
+        } // ToDo: Process other types of objects
+      }
+    }
+  }
+  return Standard_False;
+}
index d26d3db3ed617f5db6ab13a66eb4b4b47a5e048b..e4aa93ae29b299bc3713a20f0424f7d5f6f1f712 100644 (file)
@@ -6,6 +6,8 @@
 #ifndef ModuleBase_ViewerFilters_H
 #define ModuleBase_ViewerFilters_H
 
+#include <QStringList>
+
 #include <SelectMgr_Filter.hxx>
 #include <SelectMgr_EntityOwner.hxx>
 #include <gp_Pln.hxx>
@@ -30,7 +32,7 @@ public:
 
   DEFINE_STANDARD_RTTI(ModuleBase_ShapeDocumentFilter)
 
-private:
+protected:
   ModuleBase_IWorkshop* myWorkshop;
 };
 
@@ -52,4 +54,23 @@ private:
   gp_Pln myPlane;
 };
 
+
+/**
+* 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_ObjectTypesFilter, SelectMgr_Filter);
+class ModuleBase_ObjectTypesFilter: public ModuleBase_ShapeDocumentFilter
+{
+public:
+  Standard_EXPORT ModuleBase_ObjectTypesFilter(ModuleBase_IWorkshop* theWorkshop, const QStringList& theTypes): 
+      ModuleBase_ShapeDocumentFilter(theWorkshop), myTypes(theTypes) {}
+
+  Standard_EXPORT virtual Standard_Boolean IsOk(const Handle(SelectMgr_EntityOwner)& theOwner) const;
+
+  DEFINE_STANDARD_RTTI(ModuleBase_ObjectTypesFilter)
+private:
+  QStringList myTypes;
+};
+
 #endif
\ No newline at end of file
index 4a53eb0438d730b3671190346966dee17abb413d..caf3e0b4dbd3eeac604d7474afd90fde90c9475b 100644 (file)
@@ -6,8 +6,10 @@
 #include <ModuleBase_Definitions.h>
 #include <ModuleBase_ISelection.h>
 #include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_IViewer.h>
 #include <ModuleBase_Tools.h>
 #include <ModuleBase_WidgetValueFeature.h>
+
 #include <Config_WidgetAPI.h>
 #include <Events_Loop.h>
 #include <Events_Message.h>
@@ -19,6 +21,7 @@
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Result.h>
+#include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_Session.h>
@@ -108,6 +111,9 @@ ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParen
   std::string aTypes = theData->getProperty("shape_types");
   myShapeTypes = QString(aTypes.c_str()).split(' ');
 
+  std::string aObjTypes = theData->getProperty("object_types");
+  myObjectTypes = QString(aObjTypes.c_str()).split(' ');
+
   myUseSubShapes = theData->getBooleanAttribute("use_subshapes", false); 
 }
 
@@ -213,6 +219,10 @@ void ModuleBase_WidgetShapeSelector::onSelectionChanged()
     if (!aShape)
       return;
 
+    /// Check that object has acceptable type
+    if (!acceptObjectType(aObject)) 
+      return;
+
     // Get sub-shapes from local selection
     if (myUseSubShapes) {
       NCollection_List<TopoDS_Shape> aShapeList;
@@ -226,10 +236,10 @@ void ModuleBase_WidgetShapeSelector::onSelectionChanged()
 
     // Check that the selection corresponds to selection type
     if (myUseSubShapes) {
-      if (!isAccepted(aShape))
+      if (!acceptSubShape(aShape))
         return;
     } else {
-      if (!isAccepted(aObject))
+      if (!acceptObjectShape(aObject))
         return;
     }
     setObject(aObject, aShape);
@@ -256,7 +266,7 @@ void ModuleBase_WidgetShapeSelector::setObject(ObjectPtr theObj, boost::shared_p
 }
 
 //********************************************************************
-bool ModuleBase_WidgetShapeSelector::isAccepted(const ObjectPtr theResult) const
+bool ModuleBase_WidgetShapeSelector::acceptObjectShape(const ObjectPtr theResult) const
 {
   ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(theResult);
 
@@ -285,7 +295,7 @@ bool ModuleBase_WidgetShapeSelector::isAccepted(const ObjectPtr theResult) const
 }
 
 //********************************************************************
-bool ModuleBase_WidgetShapeSelector::isAccepted(boost::shared_ptr<GeomAPI_Shape> theShape) const
+bool ModuleBase_WidgetShapeSelector::acceptSubShape(boost::shared_ptr<GeomAPI_Shape> theShape) const
 {
   TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
   foreach (QString aType, myShapeTypes) {
@@ -295,6 +305,26 @@ bool ModuleBase_WidgetShapeSelector::isAccepted(boost::shared_ptr<GeomAPI_Shape>
   return false;
 }
 
+//********************************************************************
+bool ModuleBase_WidgetShapeSelector::acceptObjectType(const ObjectPtr theObject) const
+{
+  // Definition of types is not obligatory. If types are not defined then
+  // it means that accepted any type
+  if (myObjectTypes.isEmpty())
+    return true;
+
+  foreach (QString aType, myObjectTypes) {
+    if (aType.toLower() == "construction") {
+      ResultConstructionPtr aConstr = 
+        boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theObject);
+      return (aConstr != NULL);
+    } // ToDo: Process other types of objects
+  }
+  // Object type is defined but not found
+  return false;
+}
+
+
 //********************************************************************
 void ModuleBase_WidgetShapeSelector::updateSelectionName()
 {
@@ -331,15 +361,26 @@ void ModuleBase_WidgetShapeSelector::activateSelection(bool toActivate)
   if (myIsActive) {
     connect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
     if (myUseSubShapes) {
+
       QIntList aList;
       foreach (QString aType, myShapeTypes)
         aList.append(shapeType(aType));
       myWorkshop->activateSubShapesSelection(aList);
+      if (!myObjectTypes.isEmpty()) {
+        myObjTypeFilter = new ModuleBase_ObjectTypesFilter(myWorkshop, myObjectTypes);
+        myWorkshop->viewer()->clearSelectionFilters();
+        myWorkshop->viewer()->addSelectionFilter(myObjTypeFilter);
+      }
     }
   } else {
     disconnect(myWorkshop, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
-    if (myUseSubShapes) 
+    if (myUseSubShapes) {
+      if (!myObjTypeFilter.IsNull()) {
+        myWorkshop->viewer()->removeSelectionFilter(myObjTypeFilter);
+        myObjTypeFilter.Nullify();
+      }
       myWorkshop->deactivateSubShapesSelection();
+    }
   }
 }
 
@@ -385,7 +426,7 @@ bool ModuleBase_WidgetShapeSelector::setValue(ModuleBase_WidgetValue* theValue)
         dynamic_cast<ModuleBase_WidgetValueFeature*>(theValue);
     if (aFeatureValue && aFeatureValue->object()) {
       ObjectPtr aObject = aFeatureValue->object();
-      if (isAccepted(aObject)) {
+      if (acceptObjectShape(aObject)) {
         setObject(aObject);
         return true;
       }
index 7d0a453f6931e4c25646fd6aac9bc739c57e5942..9396c21e63167184d10598e9b85b3a0dc9b9fcbc 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "ModuleBase.h"
 #include "ModuleBase_ModelWidget.h"
+#include "ModuleBase_ViewerFilters.h"
 
 #include <ModelAPI_Object.h>
 #include <GeomAPI_Shape.h>
@@ -74,19 +75,29 @@ private slots:
 protected:
   bool eventFilter(QObject* theObj, QEvent* theEvent);
 
-private:
   void updateSelectionName();
   void raisePanel() const;
-  bool isAccepted(const ObjectPtr theObject) const;
-  bool isAccepted(boost::shared_ptr<GeomAPI_Shape> theShape) const;
+
+  /// Returns true if Sape of given object corresponds to requested shape type
+  /// This method is called only in non sub-shapes selection mode
+  virtual bool acceptObjectShape(const ObjectPtr theObject) const;
+
+  /// Returns true if selected shape corresponds to requested shape types
+  /// This method is called only in sub-shapes selection mode
+  virtual bool acceptSubShape(boost::shared_ptr<GeomAPI_Shape> theShape) const;
+
+  /// Returns true if selected object corresponds to requested Object type
+  /// Thid method is used in any selection mode
+  virtual bool acceptObjectType(const ObjectPtr theObject) const;
+
 
   // Set the given object as a value of the widget
   void setObject(ObjectPtr theObj, boost::shared_ptr<GeomAPI_Shape> theShape = boost::shared_ptr<GeomAPI_Shape>());
 
+  //----------- Class members -------------
   QWidget* myContainer;
   QLabel* myLabel;
   QLineEdit* myTextLine;
-  //QToolButton* myActivateBtn;
 
   ModuleBase_IWorkshop* myWorkshop;
 
@@ -94,6 +105,7 @@ private:
   boost::shared_ptr<GeomAPI_Shape> myShape;
 
   QStringList myShapeTypes;
+  QStringList myObjectTypes;
 
   /// If true then local selector has to be activated in context
   bool myUseSubShapes;
@@ -102,6 +114,8 @@ private:
   QPalette myInactivePalet;
 
   bool myIsActive;
+
+  Handle(ModuleBase_ObjectTypesFilter) myObjTypeFilter;
 };
 
 #endif
index fe9cd2310214d6a07099bc0564055e564f2b992d..419c5d0b88e14593970b5f97fdc27ffac25ba026 100644 (file)
@@ -174,4 +174,31 @@ void NewGeom_SalomeViewer::setViewProjection(double theX, double theY, double th
       aView3d->SetZSize(0.);
     }
   }
-}
\ No newline at end of file
+}
+
+//***************************************
+void NewGeom_SalomeViewer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
+{
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (!aContext.IsNull()) {
+    aContext->AddFilter(theFilter);
+  }
+}
+
+//***************************************
+void NewGeom_SalomeViewer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
+{
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (!aContext.IsNull()) {
+    aContext->RemoveFilter(theFilter);
+  }
+}
+
+//***************************************
+void NewGeom_SalomeViewer::clearSelectionFilters()
+{
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (!aContext.IsNull()) {
+    aContext->RemoveFilters();
+  }
+}
index 29bdd5218be92523f8d6de153d056fbfbded17f1..5148dcc6db73730209b1a5454d3488182656eaa3 100644 (file)
@@ -50,6 +50,15 @@ Q_OBJECT
 
   void setSelector(NewGeom_OCCSelector* theSel);
 
+  /// Add selection filter to the viewer
+  virtual void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
+
+  /// Remove selection filter from the viewer
+  virtual void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
+
+  /// Remove all selection filters from the viewer
+  virtual void clearSelectionFilters();
+
   NewGeom_OCCSelector* selector() const
   {
     return mySelector;
index fee0419ddd6dfb31fbd19fce786d7fceee121325..782023d870aa6cb4bdfaf996f1c2436c2b8624fc 100644 (file)
@@ -187,3 +187,30 @@ bool XGUI_ViewerProxy::isMultiSelectionEnabled() const
     return myWorkshop->mainWindow()->viewer()->isMultiSelectionEnabled();
   }
 }
+
+//***************************************
+void XGUI_ViewerProxy::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
+{
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (!aContext.IsNull()) {
+    aContext->AddFilter(theFilter);
+  }
+}
+
+//***************************************
+void XGUI_ViewerProxy::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
+{
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (!aContext.IsNull()) {
+    aContext->RemoveFilter(theFilter);
+  }
+}
+
+//***************************************
+void XGUI_ViewerProxy::clearSelectionFilters()
+{
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  if (!aContext.IsNull()) {
+    aContext->RemoveFilters();
+  }
+}
index 9c39bdf20c9ef3549f8404b1fa614986e448bfcf..caca6ec42133103af9f64c78e0ab2291764e1cbe 100644 (file)
@@ -52,6 +52,15 @@ Q_OBJECT
   /// Connects to a viewer according to current environment
   void connectToViewer();
 
+  /// Add selection filter to the viewer
+  virtual void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
+
+  /// Remove selection filter from the viewer
+  virtual void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
+
+  /// Remove all selection filters from the viewer
+  virtual void clearSelectionFilters();
+
  private slots:
   void onMousePress(XGUI_ViewWindow*, QMouseEvent*);
   void onMouseRelease(XGUI_ViewWindow*, QMouseEvent*);