[bos #38044][EDF] (2023-T3) Support for automatic reparation. Locate subshapes: fixed wrong group creation, removed creation of copy object for algo script, fixed counter update on object deselection.

This commit is contained in:
Konstantin Leontev 2024-04-10 21:24:33 +01:00 committed by DUC ANH HOANG
parent 7b15be21d5
commit 045927cfdd
4 changed files with 40 additions and 27 deletions

View File

@ -141,6 +141,10 @@ class BaseDlg(Ui_BaseDlg, QWidget):
# Check if we already have selected object # Check if we already have selected object
self.on_select_object() self.on_select_object()
# Default args for execution
self._is_dump_on = True # enables Python dump
self._is_copy_on = True # enables passing copy of object into algo script
def on_apply_close(self): def on_apply_close(self):
""" """
@ -199,8 +203,11 @@ class BaseDlg(Ui_BaseDlg, QWidget):
args_dict = self.get_args() args_dict = self.get_args()
if args_dict: if args_dict:
execute(self._selected_object, self._algo_name, args_dict) execute(self._selected_object,
# TODO: do we need to handle here a case if the algo failed? self._algo_name,
args_dict,
self._is_dump_on,
self._is_copy_on)
def set_algoname(self, algo_name, is_default_location): def set_algoname(self, algo_name, is_default_location):

View File

@ -85,7 +85,7 @@ def module_from_filename(filename):
return module return module
def execute(selected_object, algo_name, args_dict, is_dump_on = True): def execute(selected_object, algo_name, args_dict, is_dump_on = True, is_copy_on = True):
""" """
Executes GEOM advanced repair algorithm. Executes GEOM advanced repair algorithm.
@ -93,7 +93,8 @@ def execute(selected_object, algo_name, args_dict, is_dump_on = True):
selected_object - geom object selected by user for algorithm selected_object - geom object selected by user for algorithm
algo_name - path to the algo module algo_name - path to the algo module
args_dict - dictionary with arguments those are specific for each algo args_dict - dictionary with arguments those are specific for each algo
is_dump_on - if True saves the call to the Python dump. is_dump_on - if True saves the call to the Python dump
is_copy_on - if True makes copy of selected_object to pass into algo script.
Returns: Returns:
Result GEOM object or None if failed or canceled. Result GEOM object or None if failed or canceled.
@ -113,8 +114,11 @@ def execute(selected_object, algo_name, args_dict, is_dump_on = True):
# Make copy to prevent unintentional changing of a source object from the algo script # Make copy to prevent unintentional changing of a source object from the algo script
geompy = geomBuilder.New() geompy = geomBuilder.New()
selected_copy = geompy.MakeCopy( if is_copy_on:
selected_object, args_dict['result_name'] + '_temp') selected_copy = geompy.MakeCopy(
selected_object, args_dict['result_name'] + '_temp')
else:
selected_copy = selected_object
# Add the copy object as a source # Add the copy object as a source
args_dict['source_solid'] = selected_copy args_dict['source_solid'] = selected_copy
@ -123,10 +127,11 @@ def execute(selected_object, algo_name, args_dict, is_dump_on = True):
progress_dlg = RepairProgressDialog(parent=None, target=algo_module.run, args=args_dict) progress_dlg = RepairProgressDialog(parent=None, target=algo_module.run, args=args_dict)
progress_dlg.exec() progress_dlg.exec()
# Delete a copy object in any case # Delete a copy object if we really have one
copy_entry = ObjectToID(selected_copy) if is_copy_on:
tools = GeomStudyTools() copy_entry = ObjectToID(selected_copy)
tools.deleteShape(copy_entry) tools = GeomStudyTools()
tools.deleteShape(copy_entry)
# Python dump if execution was completed without errors # Python dump if execution was completed without errors
if progress_dlg.is_completed(): if progress_dlg.is_completed():

View File

@ -98,7 +98,9 @@ class LocateSubShapesDlg(BaseDlg):
selection_level selection_level
) )
# Adjust setup from a base class
self._sel_subshape_widget.hide() self._sel_subshape_widget.hide()
self._is_copy_on = False # disable making a copy of object for algo script
def get_limits(self): def get_limits(self):
@ -194,13 +196,16 @@ class LocateSubShapesDlg(BaseDlg):
None. None.
""" """
if not self._selected_object: # Default values when we don't have selected shapes
return selected_ids = []
all_ids = []
if self._selected_object:
geompy = geomBuilder.New()
selected_ids = self.get_local_selection()
all_ids = geompy.SubShapeAllIDs(self._selected_object, self.get_selection_level())
# Update counters # Update counters
geompy = geomBuilder.New()
all_ids = geompy.SubShapeAllIDs(self._selected_object, self.get_selection_level())
selected_ids = self.get_local_selection()
self.set_subshapes_counters(len(selected_ids), len(all_ids)) self.set_subshapes_counters(len(selected_ids), len(all_ids))
# Update label # Update label
@ -335,7 +340,9 @@ class LocateSubShapesDlg(BaseDlg):
'selection_level': self.get_selection_level() 'selection_level': self.get_selection_level()
} }
limits = execute(self._selected_object, self._minmax_algo, args, False) # Making Python dump and copy of selected object are disabled
# because we don't need for both of them here.
limits = execute(self._selected_object, self._minmax_algo, args, False, False)
if len(limits) >= 2: if len(limits) >= 2:
self.set_limits(limits[0], limits[1]) self.set_limits(limits[0], limits[1])

View File

@ -83,20 +83,14 @@ def run(args_dict, progress_emitter):
shape_type = geompy.ShapeType[type_str] shape_type = geompy.ShapeType[type_str]
group = geompy.CreateGroup(source_solid, shape_type, theName = result_name) group = geompy.CreateGroup(source_solid, shape_type, theName = result_name)
# Iterate all over the group's ids and remove unselected logging.info('Group was created.')
group_ids = geompy.GetObjectIDs(group)
logging.info('Group Sub-shapes ids: %s', group_ids)
for subshape_id in group_ids:
if subshape_id not in selected_ids:
geompy.RemoveObject(group, subshape_id)
logging.info('\tSub-shape %s was removed!', subshape_id)
progress_emitter.emit() progress_emitter.emit()
geompy.addToStudy(group, result_name) # Add sub-shapes into the group
for subshape_id in selected_ids:
geompy.AddObject(group, subshape_id)
logging.info('Group of selected sub-shapes was created.') logging.info('Selected sub-shapes were added to the group.')
progress_emitter.emit() progress_emitter.emit()
return group return group