From 351546863020e221779cd62899b7de852595590f Mon Sep 17 00:00:00 2001 From: Konstantin Leontev Date: Fri, 22 Mar 2024 12:18:30 +0000 Subject: [PATCH] [bos #38044][EDF] (2023-T3) Support for automatic reparation. User friendly selection. --- src/RepairGUIAdv/basedlg.py | 41 ++++++++++++++++++++++++---- src/RepairGUIAdv/locate_subshapes.py | 15 ++++++++++ 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/RepairGUIAdv/basedlg.py b/src/RepairGUIAdv/basedlg.py index b21c75950..4566ae867 100644 --- a/src/RepairGUIAdv/basedlg.py +++ b/src/RepairGUIAdv/basedlg.py @@ -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) diff --git a/src/RepairGUIAdv/locate_subshapes.py b/src/RepairGUIAdv/locate_subshapes.py index b568ba0d3..e57125235 100644 --- a/src/RepairGUIAdv/locate_subshapes.py +++ b/src/RepairGUIAdv/locate_subshapes.py @@ -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. -- 2.39.2