diff --git a/src/RepairGUIAdv/basedlg.py b/src/RepairGUIAdv/basedlg.py index 2edaeeda6..de0110f2c 100644 --- a/src/RepairGUIAdv/basedlg.py +++ b/src/RepairGUIAdv/basedlg.py @@ -141,6 +141,10 @@ class BaseDlg(Ui_BaseDlg, QWidget): # Check if we already have selected 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): """ @@ -199,8 +203,11 @@ class BaseDlg(Ui_BaseDlg, QWidget): args_dict = self.get_args() if args_dict: - execute(self._selected_object, self._algo_name, args_dict) - # TODO: do we need to handle here a case if the algo failed? + execute(self._selected_object, + self._algo_name, + args_dict, + self._is_dump_on, + self._is_copy_on) def set_algoname(self, algo_name, is_default_location): diff --git a/src/RepairGUIAdv/geomrepairadv_execute.py b/src/RepairGUIAdv/geomrepairadv_execute.py index 86558e656..78c4a678d 100644 --- a/src/RepairGUIAdv/geomrepairadv_execute.py +++ b/src/RepairGUIAdv/geomrepairadv_execute.py @@ -85,7 +85,7 @@ def module_from_filename(filename): 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. @@ -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 algo_name - path to the algo module 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: 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 geompy = geomBuilder.New() - selected_copy = geompy.MakeCopy( - selected_object, args_dict['result_name'] + '_temp') + if is_copy_on: + selected_copy = geompy.MakeCopy( + selected_object, args_dict['result_name'] + '_temp') + else: + selected_copy = selected_object # Add the copy object as a source 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.exec() - # Delete a copy object in any case - copy_entry = ObjectToID(selected_copy) - tools = GeomStudyTools() - tools.deleteShape(copy_entry) + # Delete a copy object if we really have one + if is_copy_on: + copy_entry = ObjectToID(selected_copy) + tools = GeomStudyTools() + tools.deleteShape(copy_entry) # Python dump if execution was completed without errors if progress_dlg.is_completed(): diff --git a/src/RepairGUIAdv/locate_subshapes.py b/src/RepairGUIAdv/locate_subshapes.py index b551809e9..e538c504d 100644 --- a/src/RepairGUIAdv/locate_subshapes.py +++ b/src/RepairGUIAdv/locate_subshapes.py @@ -98,7 +98,9 @@ class LocateSubShapesDlg(BaseDlg): selection_level ) + # Adjust setup from a base class self._sel_subshape_widget.hide() + self._is_copy_on = False # disable making a copy of object for algo script def get_limits(self): @@ -194,13 +196,16 @@ class LocateSubShapesDlg(BaseDlg): None. """ - if not self._selected_object: - return + # Default values when we don't have selected shapes + 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 - 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)) # Update label @@ -335,7 +340,9 @@ class LocateSubShapesDlg(BaseDlg): '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: self.set_limits(limits[0], limits[1]) diff --git a/src/RepairGUIAdv/locate_subshapes_algo.py b/src/RepairGUIAdv/locate_subshapes_algo.py index e7dfc3a7b..21498ad17 100755 --- a/src/RepairGUIAdv/locate_subshapes_algo.py +++ b/src/RepairGUIAdv/locate_subshapes_algo.py @@ -83,20 +83,14 @@ def run(args_dict, progress_emitter): shape_type = geompy.ShapeType[type_str] group = geompy.CreateGroup(source_solid, shape_type, theName = result_name) - # Iterate all over the group's ids and remove unselected - 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) - + logging.info('Group was created.') 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() return group