mirror of
https://git.salome-platform.org/gitpub/modules/geom.git
synced 2024-11-13 17:18:36 +05:00
[bos #38044][EDF] (2023-T3) Support for automatic reparation. Added default algo files for Locate Subshapes and Union Edges.
This commit is contained in:
parent
5b8419e26f
commit
8691b29f7c
@ -36,9 +36,11 @@ IF(SALOME_BUILD_GUI)
|
|||||||
geomrepairadv_progress.py
|
geomrepairadv_progress.py
|
||||||
geomrepairadv_worker.py
|
geomrepairadv_worker.py
|
||||||
locate_subshapes.py
|
locate_subshapes.py
|
||||||
|
locate_subshapes_algo.py
|
||||||
merge_faces.py
|
merge_faces.py
|
||||||
merge_faces_algo.py
|
merge_faces_algo.py
|
||||||
union_edges.py
|
union_edges.py
|
||||||
|
union_edges_algo.py
|
||||||
)
|
)
|
||||||
|
|
||||||
# gui scripts
|
# gui scripts
|
||||||
|
@ -76,7 +76,7 @@ class LocateSubShapesDlg(BaseDlg):
|
|||||||
main_widget,
|
main_widget,
|
||||||
'Locate Subshapes',
|
'Locate Subshapes',
|
||||||
'locate_subshapes_algo.py',
|
'locate_subshapes_algo.py',
|
||||||
False,
|
True,
|
||||||
selection_level
|
selection_level
|
||||||
)
|
)
|
||||||
|
|
||||||
|
134
src/RepairGUIAdv/locate_subshapes_algo.py
Executable file
134
src/RepairGUIAdv/locate_subshapes_algo.py
Executable file
@ -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_())
|
@ -143,6 +143,8 @@ def test():
|
|||||||
Tests execution of repair algo script.
|
Tests execution of repair algo script.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
||||||
cube_file, _ = QFileDialog.getOpenFileName(None, 'Open brep', '/home', 'Brep Files (*.brep)')
|
cube_file, _ = QFileDialog.getOpenFileName(None, 'Open brep', '/home', 'Brep Files (*.brep)')
|
||||||
if not cube_file:
|
if not cube_file:
|
||||||
return
|
return
|
||||||
@ -161,14 +163,15 @@ def test():
|
|||||||
|
|
||||||
args_dict = {
|
args_dict = {
|
||||||
'source_solid': source_solid,
|
'source_solid': source_solid,
|
||||||
'face_a': face_a,
|
'selected_ids': [face_a, face_b],
|
||||||
'face_b': face_b,
|
'result_name': 'MergeFaces_result',
|
||||||
'result_name': 'MergeFaces_result'
|
'precision': 0.1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Dummy emitter
|
# Dummy emitter
|
||||||
# TODO: doesn't work
|
# 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)
|
run(args_dict, progress_emitter)
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ class UnionEdgesDlg(SubShapesBaseDlg):
|
|||||||
"""
|
"""
|
||||||
def __init__(self, selection_level = GEOM.EDGE):
|
def __init__(self, selection_level = GEOM.EDGE):
|
||||||
SubShapesBaseDlg.__init__(
|
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
|
# For testing run as a module from geomrepairadv parent directory in
|
||||||
|
126
src/RepairGUIAdv/union_edges_algo.py
Executable file
126
src/RepairGUIAdv/union_edges_algo.py
Executable file
@ -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_())
|
Loading…
Reference in New Issue
Block a user