def glue_solids(event=None): display.EraseAll() display.Context.RemoveAll() # Without common edges S1 = BRepPrimAPI_MakeBox(gp_Pnt(500., 500., 0.), gp_Pnt(100., 250., 300.)).Shape() facesA = get_faces(S1) tag_faces(facesA, "BLUE", "facesA") # the face to glue F1 = facesA[5] S2 = BRepPrimAPI_MakeBox(gp_Pnt(400., 400., 300.), gp_Pnt(200., 300., 500.)).Shape() facesB = get_faces(S2) tag_faces(facesB, "GREEN", "facesB") # the face to glue of the opposite shape F2 = facesB[4] # perform glueing operation glue1 = BRepFeat_Gluer(S2, S1) glue1.Bind(F2, F1) shape = glue1.Shape() display.SetModeHLR() # move the glued shape, such to be able to inspect input and output # of glueing operation trsf = gp_Trsf() trsf.SetTranslation(gp_Vec(500, 0, 0)) shape.Move(TopLoc_Location(trsf)) tag_faces(get_faces(shape), "BLACK", "") # render glued shape display.DisplayShape(shape) display.FitAll()
def glue_solids_edges(event=None): display.EraseAll() display.Context.RemoveAll() # With common edges S3 = BRepPrimAPI_MakeBox(500., 400., 300.).Shape() S4 = BRepPrimAPI_MakeBox(gp_Pnt(0., 0., 300.), gp_Pnt(200., 200., 500.)).Shape() faces_S3 = get_faces(S3) faces_S4 = get_faces(S4) # tagging allows to visually find the right faces to glue tag_faces(faces_S3, "BLUE", "s3") tag_faces(faces_S4, "GREEN", "s4") F3, F4 = faces_S3[5], faces_S4[4] glue2 = BRepFeat_Gluer(S4, S3) glue2.Bind(F4, F3) glue2.Build() shape = glue2.Shape() # move the glued shape, such to be able to inspect input and output # of glueing operation trsf = gp_Trsf() trsf.SetTranslation(gp_Vec(750, 0, 0)) shape.Move(TopLoc_Location(trsf)) common_edges = LocOpe_FindEdges(F4, F3) common_edges.InitIterator() n = 0 while common_edges.More(): edge_from = common_edges.EdgeFrom() edge_to = common_edges.EdgeTo() center_pt_edge_to = center_boundingbox(edge_to) center_pt_edge_from = center_boundingbox(edge_from) red = (1, 0, 0) display.DisplayMessage(center_pt_edge_from, "edge_{0}_from".format(n), message_color=red) display.DisplayMessage(center_pt_edge_to, "edge_{0}_to".format(n), message_color=red) glue2.Bind(edge_from, edge_to) common_edges.Next() n += 1 tag_faces(get_faces(shape), "BLACK", "") display.FitAll()