From 8691b29f7c82816531f328262a6147f548d809eb Mon Sep 17 00:00:00 2001 From: Konstantin Leontev Date: Mon, 25 Mar 2024 18:05:37 +0000 Subject: [PATCH] [bos #38044][EDF] (2023-T3) Support for automatic reparation. Added default algo files for Locate Subshapes and Union Edges. --- src/RepairGUIAdv/CMakeLists.txt | 2 + src/RepairGUIAdv/locate_subshapes.py | 2 +- src/RepairGUIAdv/locate_subshapes_algo.py | 134 ++++++++++++++++++++++ src/RepairGUIAdv/merge_faces_algo.py | 11 +- src/RepairGUIAdv/union_edges.py | 2 +- src/RepairGUIAdv/union_edges_algo.py | 126 ++++++++++++++++++++ 6 files changed, 271 insertions(+), 6 deletions(-) create mode 100755 src/RepairGUIAdv/locate_subshapes_algo.py create mode 100755 src/RepairGUIAdv/union_edges_algo.py diff --git a/src/RepairGUIAdv/CMakeLists.txt b/src/RepairGUIAdv/CMakeLists.txt index c64ea9db2..1ef411c4f 100644 --- a/src/RepairGUIAdv/CMakeLists.txt +++ b/src/RepairGUIAdv/CMakeLists.txt @@ -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 diff --git a/src/RepairGUIAdv/locate_subshapes.py b/src/RepairGUIAdv/locate_subshapes.py index e57125235..2388cfdb8 100644 --- a/src/RepairGUIAdv/locate_subshapes.py +++ b/src/RepairGUIAdv/locate_subshapes.py @@ -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 index 000000000..959188190 --- /dev/null +++ b/src/RepairGUIAdv/locate_subshapes_algo.py @@ -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_()) diff --git a/src/RepairGUIAdv/merge_faces_algo.py b/src/RepairGUIAdv/merge_faces_algo.py index 3808baa49..c357f08d7 100755 --- a/src/RepairGUIAdv/merge_faces_algo.py +++ b/src/RepairGUIAdv/merge_faces_algo.py @@ -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) diff --git a/src/RepairGUIAdv/union_edges.py b/src/RepairGUIAdv/union_edges.py index dd27be457..2f805716e 100644 --- a/src/RepairGUIAdv/union_edges.py +++ b/src/RepairGUIAdv/union_edges.py @@ -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 index 000000000..78e02ef32 --- /dev/null +++ b/src/RepairGUIAdv/union_edges_algo.py @@ -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_()) -- 2.39.2