Updating algo Merge Faces - first step

This commit is contained in:
NATHALIE GORE 2024-05-23 14:57:31 +02:00 committed by Konstantin Leontev
parent e7035f5efe
commit de9595d5e5

View File

@ -50,85 +50,60 @@ def run(args_dict, progress_emitter):
logging.info('Run Merge Faces algorithm.')
progress_emitter.emit()
if ('source_solid' not in args_dict or
'selected_ids' not in args_dict or
len(args_dict['selected_ids']) < 2 or
'result_name' not in args_dict or
'precision' not in args_dict):
logging.info('Cant execute an algo because the arguments are empty!')
logging.info('Cant execute an algo because some arguments are missing!')
return False
source_solid = args_dict['source_solid']
faces_ids = args_dict['selected_ids']
result_name = args_dict['result_name']
logging.info('Creating of two faces...')
logging.info('Merging of two faces...')
progress_emitter.emit()
# This block creates a face using passed selected faces.
# Commented to simplify output - just one object.
# # Fusion des deux faces
# faces = geompy.SubShapes(source_solid, faces_ids)
# logging.info('faces: %s', faces)
# partition = geompy.MakePartition([faces[0], faces[1]],[])
# points = [geompy.GetVertexNearPoint(partition, geompy.MakeVertex(-298, 29, 250)),
# geompy.GetVertexNearPoint(partition, geompy.MakeVertex(178, 29, 250)),
# geompy.GetVertexNearPoint(partition, geompy.MakeVertex(178, -282, 250)),
# geompy.GetVertexNearPoint(partition, geompy.MakeVertex(-298, -282, 250))]
# wire = geompy.MakePolyline(points,True)
# fused_face = geompy.MakeFaceWires([wire], True)
# geompy.addToStudy(fused_face, "fused_face")
# Test si les faces sont mergeables
CR = geompy.CanonicalRecognition()
for idFace in args_dict['selected_ids']:
face = geompy.GetSubShape(source_solid, [idFace])
dataFace = CR.isPlane(face, args_dict['precision']+1e-7)
if not dataFace[0]:
logging.info('Face non planaire détectée')
return False
logging.info('Creating of a new geometry from the source brep...')
progress_emitter.emit()
# Fusion des faces
gpToMerge = geompy.CreateGroup(source_solid, geompy.ShapeType['FACE'])
geompy.UnionIDs(gpToMerge, args_dict['selected_ids'])
# A modifier pour un merge propre
unionFaces = geompy.UnionFaces(gpToMerge)
lFaces = geompy.SubShapeAll(unionFaces, geompy.ShapeType['FACE'])
sleep(1)
# Fusion des deux faces au sein de la boite + nettoyage de la boite
points = [geompy.GetVertexNearPoint(source_solid, geompy.MakeVertex(-298, 29, 250)),
geompy.GetVertexNearPoint(source_solid, geompy.MakeVertex(178, 29, 250)),
geompy.GetVertexNearPoint(source_solid, geompy.MakeVertex(178, -282, 250)),
geompy.GetVertexNearPoint(source_solid, geompy.MakeVertex(-298, -282, 250)),
geompy.GetVertexNearPoint(source_solid, geompy.MakeVertex(-298, 29, 0)),
geompy.GetVertexNearPoint(source_solid, geompy.MakeVertex(178, 29, 0)),
geompy.GetVertexNearPoint(source_solid, geompy.MakeVertex(178, -282, 0)),
geompy.GetVertexNearPoint(source_solid, geompy.MakeVertex(-298, -282, 0))]
# ### Fusion des deux faces
wire = geompy.MakePolyline(points[:4],True)
faces = [geompy.MakeFaceWires([wire], True)]
logging.info('Cleaning of the new geometry...')
progress_emitter.emit()
gpNotToMerge = geompy.CreateGroup(source_solid, geompy.ShapeType['FACE'])
geompy.UnionIDs(gpNotToMerge, geompy.SubShapeAllIDs(source_solid, geompy.ShapeType['FACE']))
geompy.DifferenceIDs(gpNotToMerge, args_dict['selected_ids'])
sleep(1)
# Uncomment to simulate exception handling in a thread worker class
# raise Exception
# ### Nettoyage des 4 faces latérales
wire = geompy.MakePolyline([points[3], points[2], points[6], points[7]],True)
faces.append(geompy.MakeFaceWires([wire], True))
wire = geompy.MakePolyline([points[0], points[3], points[7], points[4]],True)
faces.append(geompy.MakeFaceWires([wire], True))
wire = geompy.MakePolyline([points[1], points[0], points[4], points[5]],True)
faces.append(geompy.MakeFaceWires([wire], True))
wire = geompy.MakePolyline([points[2], points[1], points[5], points[6]],True)
faces.append(geompy.MakeFaceWires([wire], True))
# ### Récupération de la dernière face
faces.append(geompy.GetFaceNearPoint(source_solid, geompy.MakeVertex(-59, -127, 0)))
logging.info('Creating a solid...')
progress_emitter.emit()
sleep(1)
# ### Création du solide
shell = geompy.MakeShell(faces)
solid = geompy.MakeSolid(shell)
lFaces = lFaces + geompy.SubShapeAll(gpNotToMerge, geompy.ShapeType['FACE'])
shell = geompy.MakeShell(lFaces)
solid = geompy.MakeSolid([shell])
geompy.addToStudy(solid, result_name)