# 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):
"""
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):
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.
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.
# 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
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():
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):
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
'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])
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