]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
[bos #38044][EDF] (2023-T3) Support for automatic reparation. Locate subshapes: fixed... duc/auto_repair
authorKonstantin Leontev <Konstantin.LEONTEV@opencascade.com>
Wed, 10 Apr 2024 20:24:33 +0000 (21:24 +0100)
committerDUC ANH HOANG <dh77501n@dsp1043837>
Thu, 23 May 2024 11:58:25 +0000 (13:58 +0200)
src/RepairGUIAdv/basedlg.py
src/RepairGUIAdv/geomrepairadv_execute.py
src/RepairGUIAdv/locate_subshapes.py
src/RepairGUIAdv/locate_subshapes_algo.py

index 2edaeeda686ff8603d1795f2a5a49e35ec0ff56d..de0110f2c7be82234e98e1fa62054606377b6e1c 100644 (file)
@@ -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):
index 86558e656ca33c8630d857bf59c66b7ec5e659bc..78c4a678d9aa313071c3f5fa7afd2b58e315e730 100644 (file)
@@ -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():
index b551809e9fa5e461dee6c44923971d640e06c3cd..e538c504d282e8de067869db60ac885c7a41f683 100644 (file)
@@ -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])
 
index e7dfc3a7b78bc7d9f5e1e5f8a2c40421e8c163af..21498ad17ed176594e574e002a4a0db082b458b6 100755 (executable)
@@ -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