Ejemplo n.º 1
0
    def __init__(self, shape1, shape2, pnt=None, tol=-1.):
        shape = IntersectShapes(shape1, shape2).shape

        pnt = CheckGeom.to_point(pnt)

        self._found = False
        self._pln = None
        if pnt is None:
            tool = PlaneByEdges(shape, tol)
            self._found = tool.found
            self._pln = tool.plane
        elif CheckGeom.is_point(pnt):
            edges = shape.edges
            pnts = [pnt]
            for edge in edges:
                BRepMesh_IncrementalMesh(edge.object, 0.001)
                loc = TopLoc_Location()
                poly3d = BRep_Tool.Polygon3D_(edge.object, loc)
                if poly3d.NbNodes == 0:
                    continue
                tcol_pnts = poly3d.Nodes()
                for i in range(1, tcol_pnts.Length() + 1):
                    gp_pnt = tcol_pnts.Value(i)
                    pnt = CheckGeom.to_point(gp_pnt)
                    pnts.append(pnt)
            if len(pnts) < 3:
                raise ValueError('Less than three points to fit a plane.')
            if tol < 0.:
                tol = 1.0e-7
            tool = PlaneByApprox(pnts, tol)
            self._found = True
            self._pln = tool.plane
        else:
            raise TypeError('Invalid input.')
Ejemplo n.º 2
0
    def _default_location(self):
        """ Get the final location based on the assembly tree.

        """
        location = TopLoc_Location()
        parent = self.parent()
        while isinstance(parent, OccPart):
            location = parent.location.Multiplied(location)
            parent = parent.parent()
        return location
Ejemplo n.º 3
0
def rotating_cube_1_axis(event=None):
    display.EraseAll()
    ais_boxshp = build_shape()
    ax1 = gp_Ax1(gp_Pnt(0., 0., 0.), gp_Dir(0., 0., 1.))
    aCubeTrsf = gp_Trsf()
    angle = 0.0
    tA = time.time()
    n_rotations = 200
    for i in range(n_rotations):
        aCubeTrsf.SetRotation(ax1, angle)
        aCubeToploc = TopLoc_Location(aCubeTrsf)
        display.Context.SetLocation(ais_boxshp, aCubeToploc)
        display.Context.UpdateCurrentViewer()
        angle += 2 * pi / n_rotations
    print("%i rotations took %f" % (n_rotations, time.time() - tA))
def glue_solids_edges(event=None):
    display.EraseAll()
    display.Context.RemoveAll(True)

    # 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()

        tag_edge(edge_from, "edge_{0}_from".format(n))
        tag_edge(edge_to, "edge_{0}_to".format(n))

        glue2.Bind(edge_from, edge_to)
        common_edges.Next()
        n += 1

    tag_faces(get_faces(shape), "BLACK", "")
    display.FitAll()
Ejemplo n.º 5
0
def simple_mesh():
    #
    # Create the shape
    #
    theBox = BRepPrimAPI_MakeBox(200, 60, 60).Shape()
    theSphere = BRepPrimAPI_MakeSphere(gp_Pnt(100, 20, 20), 80).Shape()
    shape = BRepAlgoAPI_Fuse(theSphere, theBox).Shape()
    #
    # Mesh the shape
    #
    BRepMesh_IncrementalMesh(shape, 0.8)
    builder = BRep_Builder()
    comp = TopoDS_Compound()
    builder.MakeCompound(comp)

    bt = BRep_Tool()
    ex = TopExp_Explorer(shape, TopAbs_FACE)
    while ex.More():
        face = topods_Face(ex.Current())
        location = TopLoc_Location()
        facing = (bt.Triangulation(face, location))
        tab = facing.Nodes()
        tri = facing.Triangles()
        for i in range(1, facing.NbTriangles() + 1):
            trian = tri.Value(i)
            index1, index2, index3 = trian.Get()
            for j in range(1, 4):
                if j == 1:
                    m = index1
                    n = index2
                elif j == 2:
                    n = index3
                elif j == 3:
                    m = index2
                me = BRepBuilderAPI_MakeEdge(tab.Value(m), tab.Value(n))
                if me.IsDone():
                    builder.Add(comp, me.Edge())
        ex.Next()
    display.EraseAll()
    display.DisplayShape(shape)
    display.DisplayShape(comp, update=True)
def glue_solids(event=None):
    display.EraseAll()
    display.Context.RemoveAll(True)
    # 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()
Ejemplo n.º 7
0
 def _default_location(self):
     return TopLoc_Location(self.get_transform())
Ejemplo n.º 8
0
def location_from_vector(x, y, z):
    trsf = gp_Trsf()
    trsf.SetTranslation(gp_Vec(x, y, z))
    loc = TopLoc_Location(trsf)
    return loc