Salome HOME
Issue #1412: Activate selection mode FACES for sketcher only in operations with selector
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 25 May 2016 15:01:23 +0000 (18:01 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 25 May 2016 15:01:40 +0000 (18:01 +0300)
src/ModuleBase/ModuleBase_IModule.h
src/ModuleBase/ModuleBase_WidgetValidated.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/XGUI/XGUI_Displayer.cpp

index f9b5868b7c973c01ed39fc4517ec281a620c9249..f65b1d313dbad4bb4e689d3712aaf4b8a83ddf35 100755 (executable)
@@ -183,6 +183,16 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject
   /// \param theObject a model object\r
   virtual bool canActivateSelection(const ObjectPtr& theObject) const;\r
 \r
+  /// Returns true if the given selection mode can be activated for the given presentgation\r
+  /// \param theIO an object presentation\r
+  /// \param theMode selection mode\r
+  virtual bool canActivateSelectionMode(const Handle(AIS_InteractiveObject)& theIO, int theMode) const { return true; }\r
+\r
+  /// Returns true if the given selection mode must be deactivated for the given presentgation in any case\r
+  /// \param theIO an object presentation\r
+  /// \param theMode selection mode\r
+  virtual bool needDeactivateSelectionMode(const Handle(AIS_InteractiveObject)& theIO, int theMode) const { return false; }\r
+\r
   /// Reacts to the delete action in module\r
   /// \returns true if the action is processed\r
   virtual bool deleteObjects() { return false; };\r
index f20a298c432cfce632770b0a67607196fcbdd33f..cb826704bec6cb15544bd64c26ddec065c2a9e3c 100644 (file)
@@ -64,6 +64,10 @@ class MODULEBASE_EXPORT ModuleBase_WidgetValidated : public ModuleBase_ModelWidg
   //! Clear all validated cash in the widget
   void clearValidatedCash();
 
+  /// Returns true if the workshop validator filter has been already activated
+  /// \return boolean value
+  bool isFilterActivated() const;
+
 protected:
   /// Checks whether all active viewer filters validate the presentation
   /// \param thePrs a selected presentation in the view
@@ -132,10 +136,6 @@ private:
   /// \return true if all validators return that the attribute is valid
   bool isValidAttribute(const AttributePtr& theAttribute) const;
 
-  /// Returns true if the workshop validator filter has been already activated
-  /// \return boolean value
-  bool isFilterActivated() const;
-
 protected:
   /// Gets the validity state of the presentation in an internal map. Returns true if the valid state of value is stored
   /// \param theValue a viewer presentation
index 2c127173d9a4f79e97afcdbcb90ac0a02c55e7e1..3235693f3903b17929851486a000e5d4809de06f 100755 (executable)
@@ -1322,3 +1322,35 @@ void PartSet_Module::setDefaultConstraintShown()
   myHasConstraintShown[PartSet_Tools::Dimensional] = true;
   myHasConstraintShown[PartSet_Tools::Expressions] = false;
 }
+
+//******************************************************
+bool PartSet_Module::canActivateSelectionMode(const Handle(AIS_InteractiveObject)& theIO, int theMode) const
+{
+  if (theMode == TopAbs_FACE) {
+    Handle(PartSet_ResultSketchPrs) aSketchPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theIO);
+    if (!aSketchPrs.IsNull()) {
+        ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
+        if (anOperation) {
+          ModuleBase_IPropertyPanel* aPropPanel = anOperation->propertyPanel();
+          ModuleBase_ModelWidget* aModelWgt = aPropPanel->activeWidget();
+          ModuleBase_WidgetSelector* aWgtSelector = dynamic_cast<ModuleBase_WidgetSelector*>(aModelWgt);
+          if (aWgtSelector) {
+            return aWgtSelector->isFilterActivated();
+          } else
+            return true;
+        } else
+          return false;
+    }
+  }
+  return true; 
+}
+
+//******************************************************
+bool PartSet_Module::needDeactivateSelectionMode(const Handle(AIS_InteractiveObject)& theIO, int theMode) const
+{
+  if (theMode == TopAbs_FACE) {
+    Handle(PartSet_ResultSketchPrs) aSketchPrs = Handle(PartSet_ResultSketchPrs)::DownCast(theIO);
+    return !aSketchPrs.IsNull();
+  }
+  return false;
+}
index bca62aaa916128df1897fe791271054c75495905..0c03bede41507900529d9a2cf4f46a27efdb95ad 100755 (executable)
@@ -307,6 +307,16 @@ public:
   /// \return theAttribute
   virtual AttributePtr findAttribute(const ObjectPtr& theObject, const GeomShapePtr& theGeomShape);
 
+  /// Returns true if the given selection mode can be activated for the given presentgation
+  /// \param theIO an object presentation
+  /// \param theMode selection mode
+  virtual bool canActivateSelectionMode(const Handle(AIS_InteractiveObject)& theIO, int theMode) const;
+
+  /// Returns true if the given selection mode must be deactivated for the given presentgation in any case
+  /// \param theIO an object presentation
+  /// \param theMode selection mode
+  virtual bool needDeactivateSelectionMode(const Handle(AIS_InteractiveObject)& theIO, int theMode) const;
+
 public slots:
   /// Redefines the parent method in order to customize the next case:
   /// If the sketch nested operation is active and the presentation is not visualized in the viewer,
index bc1bb7526ef53b8c8cd54e6cef675f5ec8adc8a3..4c41e5243c7a7f1dbe4f765ee0f72997a5cd4580 100644 (file)
@@ -885,7 +885,12 @@ void XGUI_Displayer::activateAIS(const Handle(AIS_InteractiveObject)& theIO,
 {
   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
   if (!aContext.IsNull()) {
-    aContext->Activate(theIO, theMode, false);
+    if (myWorkshop->module()) {
+      int aMode = (theMode > 8)? theMode : AIS_Shape::SelectionType(theMode);
+      if (myWorkshop->module()->canActivateSelectionMode(theIO, aMode))
+        aContext->Activate(theIO, theMode, false);
+    } else
+      aContext->Activate(theIO, theMode, false);
 
 #ifdef DEBUG_ACTIVATE_AIS
     ObjectPtr anObject = getObject(theIO);
@@ -903,9 +908,9 @@ void XGUI_Displayer::deactivateAIS(const Handle(AIS_InteractiveObject)& theIO, c
   if (!aContext.IsNull()) {
     if (theMode == -1)
       aContext->Deactivate(theIO);
-    else
+    else 
       aContext->Deactivate(theIO, theMode);
-
+   
 #ifdef DEBUG_DEACTIVATE_AIS
     ObjectPtr anObject = getObject(theIO);
     anInfo.append(ModuleBase_Tools::objectInfo((*anIt)));
@@ -1154,7 +1159,8 @@ bool XGUI_Displayer::activate(const Handle(AIS_InteractiveObject)& theIO,
   bool isDeactivated = false;
   for (; itr.More(); itr.Next() ) {
     Standard_Integer aMode = itr.Value();
-    if (!theModes.contains(aMode)) {
+    int aShapeMode = (aMode > 8)? aMode : AIS_Shape::SelectionType(aMode);
+    if (!theModes.contains(aMode) || (myWorkshop->module()->needDeactivateSelectionMode(theIO, aShapeMode))) {
       deactivateAIS(theIO, aMode);
       isDeactivated = true;
     }