[bos #38044][EDF] (2023-T3) Support for automatic reparation. User friendly selection.

This commit is contained in:
Konstantin Leontev 2024-03-22 12:18:30 +00:00 committed by DUC ANH HOANG
parent 8833db2ff1
commit 3515468630
2 changed files with 51 additions and 5 deletions

View 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:
# 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)

View 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.