]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
[bos #38044][EDF] (2023-T3) Support for automatic reparation. Added default algo...
authorKonstantin Leontev <Konstantin.LEONTEV@opencascade.com>
Mon, 25 Mar 2024 18:05:37 +0000 (18:05 +0000)
committerKonstantin Leontev <Konstantin.LEONTEV@opencascade.com>
Fri, 14 Jun 2024 17:03:06 +0000 (18:03 +0100)
src/RepairGUIAdv/CMakeLists.txt
src/RepairGUIAdv/locate_subshapes.py
src/RepairGUIAdv/locate_subshapes_algo.py [new file with mode: 0755]
src/RepairGUIAdv/merge_faces_algo.py
src/RepairGUIAdv/union_edges.py
src/RepairGUIAdv/union_edges_algo.py [new file with mode: 0755]

index c64ea9db23a1246001c2391a22b489db804c93a5..1ef411c4f5f8d1d9668625f581b72961bf79aaea 100644 (file)
@@ -36,9 +36,11 @@ IF(SALOME_BUILD_GUI)
     geomrepairadv_progress.py
     geomrepairadv_worker.py
     locate_subshapes.py
+    locate_subshapes_algo.py
     merge_faces.py
     merge_faces_algo.py
     union_edges.py
+    union_edges_algo.py
     )
 
   # gui scripts 
index e57125235b63e4fb30f8244da25ea523a41fcde5..2388cfdb82f913afd356fcd4d13bfed5df19bdd3 100644 (file)
@@ -76,7 +76,7 @@ class LocateSubShapesDlg(BaseDlg):
             main_widget,
             'Locate Subshapes',
             'locate_subshapes_algo.py',
-            False,
+            True,
             selection_level
             )
 
diff --git a/src/RepairGUIAdv/locate_subshapes_algo.py b/src/RepairGUIAdv/locate_subshapes_algo.py
new file mode 100755 (executable)
index 0000000..9591881
--- /dev/null
@@ -0,0 +1,134 @@
+# -*- coding: utf-8 -*-
+# Copyright (C) 2014-2024  EDF
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See https://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+# Author : Konstantin Leontev (OpenCascade S.A.S)
+
+"""Example of algorithm script for GEOM Locate Subshapes plugin.
+"""
+
+import sys
+import logging
+from time import sleep
+
+import salome
+
+from salome.geom import geomBuilder
+from qtsalome import QFileDialog, QApplication, pyqtSignal
+import GEOM
+
+
+salome.salome_init()
+geompy = geomBuilder.New()
+
+
+def run(args_dict, progress_emitter):
+    """
+    Helper function to call run() with arguments parsed from dictionary.
+
+    Args:
+        args_dict - arguments as pairs string : any type value
+
+    Returns:
+        A result object.
+    """
+
+    logging.info('Run Locate Subshapes algorithm.')
+    progress_emitter.emit()
+
+
+    if ('source_solid' not in args_dict or
+        'selected_ids' not in args_dict or
+        'result_name' not in args_dict or
+        'selection_level' not in args_dict or
+        'min_limit' not in args_dict or
+        'max_limit' not in args_dict):
+
+        logging.info('Cant execute an algo because the arguments are empty!')
+        return False
+
+    source_solid = args_dict['source_solid']
+    selected_ids = args_dict['selected_ids']
+    result_name = args_dict['result_name']
+    selection_level = args_dict['selection_level']
+    min_limit = args_dict['min_limit']
+    max_limit = args_dict['max_limit']
+
+    # Replace the lines below with an actual algorithm
+    logging.info('Received arguments:')
+    logging.info('\tsource_solid: %s', source_solid)
+    logging.info('\tselected_ids: %s', selected_ids)
+    logging.info('\tresult_name: %s', result_name)
+    logging.info('\tselection_level: %s', selection_level)
+    logging.info('\tmin_limit: %s', min_limit)
+    logging.info('\tmax_limit: %s', max_limit)
+    progress_emitter.emit()
+
+    sleep(1)
+
+    logging.warning('The algo script is not implemented! Return the copy of the source object...')
+    solid = geompy.MakeCopy(source_solid, result_name)
+
+    progress_emitter.emit()
+
+    logging.info('Done.')
+    progress_emitter.emit()
+
+    return solid
+
+
+def test():
+    """
+    Tests execution of repair algo script.
+    """
+
+    logging.basicConfig(level=logging.DEBUG)
+
+    test_file, _ = QFileDialog.getOpenFileName(None, 'Open brep', '/home', 'Brep Files (*.brep)')
+    if not test_file:
+        return
+
+    # test_file = "PartitionCube.brep"
+    source_solid = geompy.ImportBREP(test_file)
+    geompy.addToStudy(source_solid, "source_solid")
+
+    # TODO: Implement for actual algorithm
+    # Here we just use all ids.
+    all_subshapes = geompy.SubShapeAllIDs(source_solid, GEOM.EDGE)
+
+    args_dict = {
+            'source_solid': source_solid,
+            'selected_ids': all_subshapes,
+            'result_name': 'LocateSubshapes_result',
+            'selection_level': GEOM.EDGE,
+            'min_limit': 0.0,
+            'max_limit': 99.99
+    }
+
+    # Dummy emitter
+    # TODO: doesn't work
+    # progress_emitter = pyqtSignal()
+    progress_emitter = type('DummyEmitter', (object,), {'emit': lambda self: sleep(0.1)})()
+
+    run(args_dict, progress_emitter)
+
+
+if __name__ == "__main__":
+    app = QApplication(sys.argv)
+    test()
+    sys.exit(app.exec_())
index 3808baa49978486b589948dc23be74fed4469892..c357f08d7ab086caabc08848fd544b978a3dacd3 100755 (executable)
@@ -143,6 +143,8 @@ def test():
     Tests execution of repair algo script.
     """
 
+    logging.basicConfig(level=logging.DEBUG)
+
     cube_file, _ = QFileDialog.getOpenFileName(None, 'Open brep', '/home', 'Brep Files (*.brep)')
     if not cube_file:
         return
@@ -161,14 +163,15 @@ def test():
 
     args_dict = {
             'source_solid': source_solid,
-            'face_a': face_a,
-            'face_b': face_b,
-            'result_name': 'MergeFaces_result'
+            'selected_ids': [face_a, face_b],
+            'result_name': 'MergeFaces_result',
+            'precision': 0.1
     }
 
     # Dummy emitter
     # TODO: doesn't work
-    progress_emitter = pyqtSignal()
+    # progress_emitter = pyqtSignal()
+    progress_emitter = type('DummyEmitter', (object,), {'emit': lambda self: sleep(0.1)})()
 
     run(args_dict, progress_emitter)
 
index dd27be457ef7f2e103fccbe1a6e5007cd4e40536..2f805716ee2a83e65d59c840152d549c9340d97a 100644 (file)
@@ -32,7 +32,7 @@ class UnionEdgesDlg(SubShapesBaseDlg):
     """
     def __init__(self, selection_level = GEOM.EDGE):
         SubShapesBaseDlg.__init__(
-            self, 'Union Edges', 'union_edges_algo.py', False, selection_level, 1)
+            self, 'Union Edges', 'union_edges_algo.py', True, selection_level, 1)
 
 
 # For testing run as a module from geomrepairadv parent directory in
diff --git a/src/RepairGUIAdv/union_edges_algo.py b/src/RepairGUIAdv/union_edges_algo.py
new file mode 100755 (executable)
index 0000000..78e02ef
--- /dev/null
@@ -0,0 +1,126 @@
+# -*- coding: utf-8 -*-
+# Copyright (C) 2014-2024  EDF
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See https://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+# Author : Konstantin Leontev (OpenCascade S.A.S)
+
+"""Example of algorithm script for GEOM Union Edges plugin.
+"""
+
+import sys
+import logging
+from time import sleep
+
+import salome
+
+from salome.geom import geomBuilder
+from qtsalome import QFileDialog, QApplication, pyqtSignal
+import GEOM
+
+
+salome.salome_init()
+geompy = geomBuilder.New()
+
+
+def run(args_dict, progress_emitter):
+    """
+    Helper function to call run() with arguments parsed from dictionary.
+
+    Args:
+        args_dict - arguments as pairs string : any type value
+
+    Returns:
+        A result object.
+    """
+
+    logging.info('Run Union Edges algorithm.')
+    progress_emitter.emit()
+
+
+    if ('source_solid' not in args_dict or
+        'selected_ids' not in args_dict or
+        'result_name' not in args_dict or
+        'precision' not in args_dict):
+
+        logging.info('Cant execute an algo because the arguments are empty!')
+        return False
+
+    source_solid = args_dict['source_solid']
+    selected_ids = args_dict['selected_ids']
+    result_name = args_dict['result_name']
+    precision = args_dict['precision']
+
+    # Replace the lines below with an actual algorithm
+    logging.info('Received arguments:')
+    logging.info('\tsource_solid: %s', source_solid)
+    logging.info('\tselected_ids: %s', selected_ids)
+    logging.info('\tresult_name: %s', result_name)
+    logging.info('\tprecision: %s', precision)
+    progress_emitter.emit()
+
+    sleep(1)
+
+    logging.warning('The algo script is not implemented! Return the copy of the source object...')
+    solid = geompy.MakeCopy(source_solid, result_name)
+
+    progress_emitter.emit()
+
+    logging.info('Done.')
+    progress_emitter.emit()
+
+    return solid
+
+
+def test():
+    """
+    Tests execution of repair algo script.
+    """
+
+    logging.basicConfig(level=logging.DEBUG)
+
+    test_file, _ = QFileDialog.getOpenFileName(None, 'Open brep', '/home', 'Brep Files (*.brep)')
+    if not test_file:
+        return
+
+    # test_file = "PartitionCube.brep"
+    source_solid = geompy.ImportBREP(test_file)
+    geompy.addToStudy(source_solid, "source_solid")
+
+    # TODO: Implement for actual algorithm
+    # Here we just use all ids.
+    all_subshapes = geompy.SubShapeAllIDs(source_solid, GEOM.EDGE)
+
+    args_dict = {
+            'source_solid': source_solid,
+            'selected_ids': all_subshapes,
+            'result_name': 'UnionEdges_result',
+            'precision': 0.1
+    }
+
+    # Dummy emitter
+    # TODO: doesn't work
+    # progress_emitter = pyqtSignal()
+    progress_emitter = type('DummyEmitter', (object,), {'emit': lambda self: sleep(0.1)})()
+
+    run(args_dict, progress_emitter)
+
+
+if __name__ == "__main__":
+    app = QApplication(sys.argv)
+    test()
+    sys.exit(app.exec_())