]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
[bos #38044][EDF] (2023-T3) Support for automatic reparation. User friendly selection.
authorKonstantin Leontev <Konstantin.LEONTEV@opencascade.com>
Fri, 22 Mar 2024 12:18:30 +0000 (12:18 +0000)
committerKonstantin Leontev <Konstantin.LEONTEV@opencascade.com>
Fri, 14 Jun 2024 17:03:06 +0000 (18:03 +0100)
src/RepairGUIAdv/basedlg.py
src/RepairGUIAdv/locate_subshapes.py

index b21c75950deb0fa05ebb8a3b6e5a05b7e9f20c3e..4566ae8675b59c0ffb5cc31e7c5cb702dc2f40b1 100644 (file)
@@ -29,6 +29,7 @@ from salome.kernel.studyedit import EDITOR
 from salome.kernel.services import IDToObject
 from salome.geom import geomBuilder
 from libGEOM_Swig import GEOM_Swig
+import SalomePyQt
 
 from .basedlg_ui import Ui_BaseDlg
 from .geomrepairadv_execute import execute
@@ -124,6 +125,14 @@ class BaseDlg(Ui_BaseDlg, QWidget):
 
         # Default selection level
         self._selection_level = selection_level
+        self._is_level_changed = False
+        self._is_local_selection = False
+
+        # Connect selection manager
+        salome_pyqt = SalomePyQt.SalomePyQt()
+        self._sel_manager = salome_pyqt.getSelection()
+        self._sel_connection = \
+            self._sel_manager.currentSelectionChanged.connect(self.on_select_object)
 
         # Check if we already have selected object
         self.on_select_object()
@@ -248,6 +257,12 @@ class BaseDlg(Ui_BaseDlg, QWidget):
             None.
         """
 
+        # Set the flag to process local selection properly
+        if self._selection_level == selection_level:
+            self._is_level_changed = False
+        else:
+            self._is_level_changed = True
+
         self._selection_level = selection_level
 
         # Update selection for current object
@@ -270,14 +285,27 @@ class BaseDlg(Ui_BaseDlg, QWidget):
 
         geom_swig = GEOM_Swig()
 
-        # Resets selection level
-        geom_swig.closeLocalSelection()
-
         # Set level of selection for specific entry
         if entry:
-            sel_level = geomBuilder.EnumToLong(self._selection_level)
-            geom_swig.initLocalSelection(entry, sel_level)
+            # Init it again if the level was changed
+            if self._is_level_changed:
+                geom_swig.closeLocalSelection()
+                self._is_local_selection = False
+
+            # We need to init a local selection only once
+            if not self._is_local_selection:
+                # Init it here
+                sel_level = geomBuilder.EnumToLong(self._selection_level)
+                geom_swig.initLocalSelection(entry, sel_level)
+
+                self._is_local_selection = True
+        else:
+            # No entry - no local selection
+            geom_swig.closeLocalSelection()
+            self._is_local_selection = False
 
+        # We don't need the flag after selection was set
+        self._is_level_changed = False
 
     def on_select_object(self):
         """
@@ -356,6 +384,9 @@ class BaseDlg(Ui_BaseDlg, QWidget):
         """
 
         super().closeEvent(event)
+
+        # Clean up all selection changes
+        self._sel_manager.currentSelectionChanged.disconnect(self._sel_connection)
         self.set_selection(None)
 
 
index b568ba0d3e5e1cb5ba3cc4a99f044a6ac27c88f0..e57125235b63e4fb30f8244da25ea523a41fcde5 100644 (file)
@@ -80,6 +80,10 @@ class LocateSubShapesDlg(BaseDlg):
             selection_level
             )
 
+        # Connect selection manager from a base class
+        self._sel_subshape_connection = \
+            self._sel_manager.currentSelectionChanged.connect(self.on_select_subshape)
+
 
     def create_pre_selected_widget(self):
         """
@@ -214,6 +218,17 @@ class LocateSubShapesDlg(BaseDlg):
         return None
 
 
+    def closeEvent(self, event):
+        """
+        Overrides default close envent to reset selection level.
+        """
+
+        super().closeEvent(event)
+
+        # Clean up all selection changes
+        self._sel_manager.currentSelectionChanged.disconnect(self._sel_subshape_connection)
+
+
 # For testing run as a module from geomrepairadv parent directory in
 # Salome INSTALL, because the dialog needs a generated Ui_BaseDlg class
 # that we don't have in the SOURCE.