コード例 #1
0
def intersection(shp1: TopoDS_Shape,
                 shp2: Union[TopoDS_Shape, gp.GP3d]) -> TopoDS_Shape:
    """
    Most Robust TopoDS intersection

    BRepAlgoAPI_Common will only return if the intersection is solid.
    BRepAlgoAPI_Section will work for face-on-face

    similar issue with GeomAPI is documented here:
        https://www.opencascade.com/content/use-brepalgosection-instead-brepalgoapisection

    :param: shp1 - TopoDS_Shape1
    :param: shp2 - TopoDS_Shape2

    BRepAlgoAPI_Section(TopoDS_Shape const &,TopoDS_Shape const &,BOPAlgo_PaveFiller const &,Standard_Boolean const)
    BRepAlgoAPI_Section(TopoDS_Shape const &,TopoDS_Shape const &,Standard_Boolean const)
    BRepAlgoAPI_Section(TopoDS_Shape const &,gp_Pln const &,Standard_Boolean const)
    BRepAlgoAPI_Section(TopoDS_Shape const &,Handle_Geom_Surface const &,Standard_Boolean const)
    BRepAlgoAPI_Section(Handle_Geom_Surface const &,TopoDS_Shape const &,Standard_Boolean const)
    BRepAlgoAPI_Section(Handle_Geom_Surface const &,Handle_Geom_Surface const &,Standard_Boolean const)

    returns wires representing the intersection
    """
    intrs = BRepAlgoAPI_Section(shp1, shp2)
    if intrs.BuilderCanWork() is True:
        intrs.Build()
        # todo add isDone check (maybe ??)
        # intrs.FuseEdges()
        intrs.RefineEdges()
        shp = intrs.Shape()
        intrs.Destroy()
        return shp
コード例 #2
0
def splitwire(base, in_edge):
    sect = BRepAlgoAPI_Section(base, in_edge)
    sect.Build()
    sect.RefineEdges()
    edge = sect.Shape()

    splt = BRepFeat_SplitShape(base)
    Ex = TopExp_Explorer(edge, TopAbs_VERTEX)
    while Ex.More():
        # print(Ex.Current())
        Sx = TopExp_Explorer(base, TopAbs_EDGE)
        while Sx.More():
            if sect.HasAncestorFaceOn1(Ex.Current(), Sx.Current()):
                print('add', Ex.Current(), Sx.Current())
                splt.Add(Ex.Current(), Sx.Current())
            Sx.Next()
        Ex.Next()
    splt.Build()
    return splt.Shape()