コード例 #1
0
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()
コード例 #2
0
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()
コード例 #3
0
def tag_faces(_shape, _color, shape_name):
    """ tag the faces of a shape
    in this example, this easy to see which faces of the 2 shapes we need to glue together
    so by reading the tagged faces, its easy to find the correct index for the
    list `facesA` (5) and `facesB` (4)
    :param _shape: the shape to tag
    :param color: a string, to colors the faces the `_shape` we're exploring
    :param shape_name: name to tag the faces the `_shape`
    """
    for n, f in enumerate(_shape):
        # centroid of the face
        center_pt = center_boundingbox(f)
        # displays the face in the viewer
        display.DisplayShape(f, color=_color, transparency=0.9)
        # tag the face in the viewer
        display.DisplayMessage(center_pt, "{0}_nr_{1}".format(shape_name, n))
コード例 #4
0
def tag_faces(_shape, _color, shape_name):
    """ tag the faces of a shape

    in this example, this easy to see which faces of the 2 shapes we need to glue together
    so by reading the tagged faces, its easy to find the correct index for the
    list `facesA` (5) and `facesB` (4)

    :param _shape: the shape to tag
    :param color: a string, to colors the faces the `_shape` we're exploring
    :param shape_name: name to tag the faces the `_shape`
    """
    for n, f in enumerate(_shape):
        # centroid of the face
        center_pt = center_boundingbox(f)
        # displays the face in the viewer
        display.DisplayShape(f, color=_color, transparency=0.9)
        # tag the face in the viewer
        display.DisplayMessage(center_pt, "{0}_nr_{1}".format(shape_name, n))
コード例 #5
0
def tag_edge(_edge, msg, _color=(1, 0, 0)):
    """ tag an edge
    """
    pt = center_boundingbox(_edge)
    display.DisplayMessage(pt, msg, None, _color, False)
コード例 #6
0
def tag_edge(_edge, msg, _color=(1, 0, 0)):
    """ tag an edge
    """
    pt = center_boundingbox(_edge)
    display.DisplayMessage(pt, msg, None, _color, False)