Salome HOME
updated copyright message
[modules/shaper.git] / src / XGUI / XGUI_SelectionActivate.cpp
index 13a67569d46e704b05152135725db7f48069bdfb..123f43c2d8ccd08c2d37d1c044e42bed560ca5b1 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // 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
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "XGUI_SelectionActivate.h"
 //#define DEBUG_ACTIVATE_AIS
 //#define DEBUG_DEACTIVATE_AIS
 
+#ifdef TINSPECTOR
+#include <inspector/VInspectorAPI_CallBack.hxx>
+#endif
+
 #define CLEAR_OUTDATED_SELECTION_BEFORE_REDISPLAY
 
 //**************************************************************
@@ -89,7 +92,7 @@ void XGUI_SelectionActivate::updateSelectionModes()
     break;
     case FacesPanel: {
       XGUI_Tools::workshop(myWorkshop)->facesPanel()->selectionModes(aModes);
-      myWorkshop->module()->customSubShapesSelectionModes(aModes); // avoid wire selection
+      myWorkshop->module()->moduleSelectionModes(-1/*all modes*/, aModes);
     }
     break;
     default: break;
@@ -102,17 +105,24 @@ void XGUI_SelectionActivate::updateSelectionFilters()
 {
   SelectMgr_ListOfFilter aSelectionFilters;
   switch (activeSelectionPlace()) {
-  case Workshop:
-    XGUI_Tools::workshop(myWorkshop)->selectionFilters(aSelectionFilters);
+    case Workshop: {
+      QIntList aModuleSelectionFilters = myWorkshop->module()->selectionFilters();
+      myWorkshop->module()->moduleSelectionFilters(aModuleSelectionFilters, aSelectionFilters);
+    }
     break;
     case PropertyPanel: {
+      QIntList aModuleSelectionFilters = myWorkshop->module()->selectionFilters();
+
       ModuleBase_ModelWidget* anActiveWidget = myWorkshop->module()->activeWidget();
-      getSelectionFilters(anActiveWidget, aSelectionFilters);
+      if (anActiveWidget)
+        anActiveWidget->selectionFilters(aModuleSelectionFilters, aSelectionFilters);
+      myWorkshop->module()->moduleSelectionFilters(aModuleSelectionFilters, aSelectionFilters);
     }
     break;
     case FacesPanel: {
-      //XGUI_Tools::workshop(myWorkshop)->selectionFilters(aSelectionFilters);
       XGUI_Tools::workshop(myWorkshop)->facesPanel()->selectionFilters(aSelectionFilters);
+      //QIntList aModuleSelectionFilters = myWorkshop->module()->selectionFilters();
+      //myWorkshop->module()->moduleSelectionFilters(aModuleSelectionFilters, aSelectionFilters);
     }
     break;
     default: break;
@@ -120,20 +130,6 @@ void XGUI_SelectionActivate::updateSelectionFilters()
   activateSelectionFilters(aSelectionFilters);
 }
 
-//**************************************************************
-void XGUI_SelectionActivate::activateSelectionAndFilters(ModuleBase_ModelWidget* theWidget)
-{
-  // activate selection modes
-  QIntList aModes;
-  getSelectionModes(theWidget, aModes);
-  activateObjects(aModes, getDisplayer()->displayedObjects(), true);
-
-  // activate selection filters
-  SelectMgr_ListOfFilter aSelectionFilters;
-  getSelectionFilters(theWidget, aSelectionFilters);
-  activateSelectionFilters(aSelectionFilters);
-}
-
 //**************************************************************
 void XGUI_SelectionActivate::activateSelectionFilters
   (const SelectMgr_ListOfFilter& theSelectionFilters)
@@ -157,23 +153,9 @@ void XGUI_SelectionActivate::getSelectionModes(ModuleBase_ModelWidget* theWidget
   if (!theWidget)
     return;
 
-  bool isAdditional = false;
-  theWidget->selectionModes(theModes, isAdditional);
-  if (isAdditional) {
-    myWorkshop->module()->customSubShapesSelectionModes(theModes);
-    //theModes.append(XGUI_Tools::workshop(myWorkshop)->viewerSelectionModes());
-    //myWorkshop->module()->activeSelectionModes(theModes);
-  }
-}
-
-//**************************************************************
-void XGUI_SelectionActivate::getSelectionFilters(ModuleBase_ModelWidget* theWidget,
-                                                 SelectMgr_ListOfFilter& theSelectionFilters)
-{
-  XGUI_Tools::workshop(myWorkshop)->selectionFilters(theSelectionFilters);
-
-  if (theWidget)
-    theWidget->selectionFilters(theSelectionFilters);
+  int aModuleSelectionModes = -1;
+  theWidget->selectionModes(aModuleSelectionModes, theModes);
+  myWorkshop->module()->moduleSelectionModes(aModuleSelectionModes, theModes);
 }
 
 //**************************************************************
@@ -247,17 +229,24 @@ void XGUI_SelectionActivate::activateObjects(const QIntList& theModes,
     return;
 
   AIS_ListIteratorOfListOfInteractive aLIt;
+#ifdef _DEBUG
   bool isActivationChanged = false;
+#endif
   for(aLIt.Initialize(aPrsList); aLIt.More(); aLIt.Next()) {
     anAISIO = aLIt.Value();
-    if (activate(anAISIO, false))
+    if (activate(anAISIO, false)) {
+#ifdef _DEBUG
       isActivationChanged = true;
+#endif
+    }
   }
 
   for(aLIt.Initialize(aPrsListToBeDeactivated); aLIt.More(); aLIt.Next()) {
     anAISIO = aLIt.Value();
     deactivateAIS(anAISIO);
+#ifdef _DEBUG
     isActivationChanged = true;
+#endif
   }
 }
 
@@ -354,11 +343,19 @@ void XGUI_SelectionActivate::activateAIS(const Handle(AIS_InteractiveObject)& th
   }
   if (!aContext.IsNull()) {
     if (myWorkshop->module()) {
-      int aMode = (theMode > 8)? theMode : AIS_Shape::SelectionType(theMode);
+      // the code is obsolete, used in additional check before activate, it was removed
+      //int aMode = (theMode > 8)? theMode : AIS_Shape::SelectionType(theMode);
       aContext->Activate(theIO, theMode, false);
-    } else
+#ifdef TINSPECTOR
+      if (getDisplayer()->getCallBack()) getDisplayer()->getCallBack()->Activate(theIO, theMode);
+#endif
+    }
+    else {
       aContext->Activate(theIO, theMode, false);
-
+#ifdef TINSPECTOR
+      if (getDisplayer()->getCallBack()) getDisplayer()->getCallBack()->Activate(theIO, theMode);
+#endif
+    }
     // the fix from VPA for more suitable selection of sketcher lines
     if (theIO->Width() > 1) {
       double aPrecision = theIO->Width() + 2;
@@ -369,6 +366,8 @@ void XGUI_SelectionActivate::activateAIS(const Handle(AIS_InteractiveObject)& th
                (theMode == getSelectionMode(TopAbs_WIRE)))
         aPrecision = theIO->Width() + ModuleBase_Preferences::resourceMgr()->doubleValue("Viewer",
            "edge-selection-sensitivity", 2);
+      if (aPrecision <= 0)
+        aPrecision = 2;
       aContext->SetSelectionSensitivity(theIO, theMode, aPrecision);
     }
 
@@ -431,7 +430,7 @@ bool XGUI_SelectionActivate::activate(const Handle(AIS_InteractiveObject)& theIO
   for (; itr.More(); itr.Next() ) {
     Standard_Integer aMode = itr.Value();
     aHasValidMode = aHasValidMode || aMode != -1;
-    int aShapeMode = (aMode > 8)? aMode : AIS_Shape::SelectionType(aMode);
+    //int aShapeMode = (aMode > 8)? aMode : AIS_Shape::SelectionType(aMode);
     if (!myActiveSelectionModes.contains(aMode)) {
       deactivateAIS(theIO, aMode);
       isDeactivated = true;
@@ -454,7 +453,7 @@ bool XGUI_SelectionActivate::activate(const Handle(AIS_InteractiveObject)& theIO
 
   // loading the interactive object allowing the decomposition
   if (aTColModes.IsEmpty() || !aHasValidMode) {
-    aContext->Load(theIO, -1, true);
+    aContext->Load(theIO);
     Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(theIO);
     if (!aTrihedron.IsNull()) {
       // Workaround for Trihedron. It should be loaded using the next Load method to
@@ -559,14 +558,16 @@ void XGUI_SelectionActivate::deactivateTrihedron(const bool theUpdateViewer) con
 void XGUI_SelectionActivate::deactivateTrihedronInSelectionModes()
 {
   Handle(AIS_InteractiveContext) aContext = AISContext();
-  Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(getTrihedron());
-  /// deactivate trihedron in selection modes
-  TColStd_ListOfInteger aTColModes;
-  aContext->ActivatedModes(aTrihedron, aTColModes);
-  TColStd_ListIteratorOfListOfInteger itr( aTColModes );
-  for (; itr.More(); itr.Next() ) {
-    Standard_Integer aMode = itr.Value();
-    aContext->Deactivate(aTrihedron, aMode);
+  if (!aContext.IsNull()) {
+    Handle(AIS_Trihedron) aTrihedron = Handle(AIS_Trihedron)::DownCast(getTrihedron());
+    /// deactivate trihedron in selection modes
+    TColStd_ListOfInteger aTColModes;
+    aContext->ActivatedModes(aTrihedron, aTColModes);
+    TColStd_ListIteratorOfListOfInteger itr(aTColModes);
+    for (; itr.More(); itr.Next()) {
+      Standard_Integer aMode = itr.Value();
+      aContext->Deactivate(aTrihedron, aMode);
+    }
   }
 }