Exemple #1
0
def pipe():
    # the bspline path, must be a wire
    array2 = TColgp_Array1OfPnt(1, 3)
    array2.SetValue(1, gp_Pnt(0, 0, 0))
    array2.SetValue(2, gp_Pnt(0, 1, 2))
    array2.SetValue(3, gp_Pnt(0, 2, 3))
    bspline2 = GeomAPI_PointsToBSpline(array2).Curve()
    path_edge = BRepBuilderAPI_MakeEdge(bspline2).Edge()
    path_wire = BRepBuilderAPI_MakeWire(path_edge).Wire()

    # the bspline profile. Profile mist be a wire
    array = TColgp_Array1OfPnt(1, 5)
    array.SetValue(1, gp_Pnt(0, 0, 0))
    array.SetValue(2, gp_Pnt(1, 2, 0))
    array.SetValue(3, gp_Pnt(2, 3, 0))
    array.SetValue(4, gp_Pnt(4, 3, 0))
    array.SetValue(5, gp_Pnt(5, 5, 0))
    bspline = GeomAPI_PointsToBSpline(array).Curve()
    profile_edge = BRepBuilderAPI_MakeEdge(bspline).Edge()

    # pipe
    pipe = BRepOffsetAPI_MakePipe(path_wire, profile_edge).Shape()

    display.DisplayShape(profile_edge, update=False)
    display.DisplayShape(path_wire, update=False)
    display.DisplayShape(pipe, update=True)
Exemple #2
0
 def create_shape(self):
     data = self.element.attrib.get('d')
     shapes = []
     path = None
     for cmd, params in self.parse_path(data):
         if cmd == 'M':
             if path is not None:
                 shapes.append(path.Wire())
             path = BRepBuilderAPI_MakeWire()
             last_pnt = gp_Pnt(params[0], params[1], 0)
             start_pnt = last_pnt
         elif cmd in ['L', 'H', 'V']:
             pnt = gp_Pnt(params[0], params[1], 0)
             path.Add(BRepBuilderAPI_MakeEdge(last_pnt, pnt).Edge())
             last_pnt = pnt
         elif cmd == 'Q':
             # Quadratic Bezier
             pts = TColgp_Array1OfPnt(1, 3)
             pts.SetValue(1, last_pnt)
             pts.SetValue(2, gp_Pnt(params[0], params[1], 0))
             last_pnt = gp_Pnt(params[2], params[3], 0)
             pts.SetValue(3, last_pnt)
             curve = Geom_BezierCurve(pts)
             path.Add(BRepBuilderAPI_MakeEdge(curve).Edge())
         elif cmd == 'C':
             # Cubic Bezier
             pts = TColgp_Array1OfPnt(1, 4)
             pts.SetValue(1, last_pnt)
             pts.SetValue(2, gp_Pnt(params[0], params[1], 0))
             pts.SetValue(3, gp_Pnt(params[2], params[3], 0))
             last_pnt = gp_Pnt(params[4], params[5], 0)
             pts.SetValue(4, last_pnt)
             curve = Geom_BezierCurve(pts)
             path.Add(BRepBuilderAPI_MakeEdge(curve).Edge())
         elif cmd == 'A':
             # Warning: Play at your own risk!
             x1, y1 = last_pnt.X(), last_pnt.Y()
             rx, ry, phi, large_arc_flag, sweep_flag, x2, y2 = params
             phi = radians(phi)
             pnt = gp_Pnt(x2, y2, 0)
             cx, cy, rx, ry = compute_arc_center(x1, y1, rx, ry, phi,
                                                 large_arc_flag, sweep_flag,
                                                 x2, y2)
             z_dir = Z_DIR if sweep_flag else NEG_Z_DIR  # sweep_flag
             c = make_ellipse((cx, cy, 0), rx, ry, phi, z_dir)
             curve = GC_MakeArcOfEllipse(c, last_pnt, pnt, True).Value()
             path.Add(BRepBuilderAPI_MakeEdge(curve).Edge())
             last_pnt = pnt
         elif cmd == 'Z':
             if not last_pnt.IsEqual(start_pnt, 10e-6):
                 edge = BRepBuilderAPI_MakeEdge(last_pnt, start_pnt).Edge()
                 path.Add(edge)
             shapes.append(path.Wire())
             path = None  # Close path
             last_pnt = start_pnt
     if path is not None:
         shapes.append(path.Wire())
     return shapes
def prism():
    # the bspline profile
    array = TColgp_Array1OfPnt(1, 5)
    array.SetValue(1, gp_Pnt(0, 0, 0))
    array.SetValue(2, gp_Pnt(1, 2, 0))
    array.SetValue(3, gp_Pnt(2, 3, 0))
    array.SetValue(4, gp_Pnt(4, 3, 0))
    array.SetValue(5, gp_Pnt(5, 5, 0))
    bspline = GeomAPI_PointsToBSpline(array).Curve()
    profile = BRepBuilderAPI_MakeEdge(bspline).Edge()

    # the linear path
    starting_point = gp_Pnt(0., 0., 0.)
    end_point = gp_Pnt(0., 0., 6.)
    vec = gp_Vec(starting_point, end_point)
    path = BRepBuilderAPI_MakeEdge(starting_point, end_point).Edge()

    # extrusion
    prism = BRepPrimAPI_MakePrism(profile, vec).Shape()

    display.DisplayShape(profile, update=False)
    display.DisplayShape(starting_point, update=False)
    display.DisplayShape(end_point, update=False)
    display.DisplayShape(path, update=False)
    display.DisplayShape(prism, update=True)
Exemple #4
0
 def setUpClass(cls):
     """
     Set up for TColgp_HArray1OfPnt.
     """
     p1 = gp_Pnt()
     p2 = gp_Pnt(1, 0, 0)
     p3 = gp_Pnt(2, 0, 0)
     arr = TColgp_Array1OfPnt(1, 3)
     arr.SetValue(1, p1)
     arr.SetValue(2, p2)
     arr.SetValue(3, p3)
     cls._harr = TColgp_HArray1OfPnt(arr)
Exemple #5
0
    def create_shape(self):
        d = self.declaration
        if not d.points:
            raise ValueError("Must have at least two points")
        # Poles and weights
        points = self.get_transformed_points()
        pts = TColgp_Array1OfPnt(1, len(points))
        set_value = pts.SetValue

        # TODO: Support weights
        for i, p in enumerate(points):
            set_value(i + 1, p)
        curve = self.curve = GeomAPI_PointsToBSpline(pts).Curve()
        self.shape = self.make_edge(curve)
Exemple #6
0
def edge(event=None):
    # The blud edge
    BlueEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(-80, -50, -20),
                                       gp_Pnt(-30, -60, -60))
    V1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-20, 10, -30))
    V2 = BRepBuilderAPI_MakeVertex(gp_Pnt(10, 7, -25))
    YellowEdge = BRepBuilderAPI_MakeEdge(V1.Vertex(), V2.Vertex())

    #The white edge
    line = gp_Lin(gp_Ax1(gp_Pnt(10, 10, 10), gp_Dir(1, 0, 0)))
    WhiteEdge = BRepBuilderAPI_MakeEdge(line, -20, 10)

    #The red edge
    Elips = gp_Elips(gp_Ax2(gp_Pnt(10, 0, 0), gp_Dir(1, 1, 1)), 60, 30)
    RedEdge = BRepBuilderAPI_MakeEdge(Elips, 0, math.pi/2)

    # The green edge and the both extreme vertex
    P1 = gp_Pnt(-15, 200, 10)
    P2 = gp_Pnt(5, 204, 0)
    P3 = gp_Pnt(15, 200, 0)
    P4 = gp_Pnt(-15, 20, 15)
    P5 = gp_Pnt(-5, 20, 0)
    P6 = gp_Pnt(15, 20, 0)
    P7 = gp_Pnt(24, 120, 0)
    P8 = gp_Pnt(-24, 120, 12.5)
    array = TColgp_Array1OfPnt(1, 8)
    array.SetValue(1, P1)
    array.SetValue(2, P2)
    array.SetValue(3, P3)
    array.SetValue(4, P4)
    array.SetValue(5, P5)
    array.SetValue(6, P6)
    array.SetValue(7, P7)
    array.SetValue(8, P8)
    curve = Geom_BezierCurve(array)
    ME = BRepBuilderAPI_MakeEdge(curve)
    GreenEdge = ME
    V3 = ME.Vertex1()
    V4 = ME.Vertex2()

    display.DisplayColoredShape(BlueEdge.Edge(), 'BLUE')
    display.DisplayShape(V1.Vertex())
    display.DisplayShape(V2.Vertex())
    display.DisplayColoredShape(WhiteEdge.Edge(), 'WHITE')
    display.DisplayColoredShape(YellowEdge.Edge(), 'YELLOW')
    display.DisplayColoredShape(RedEdge.Edge(), 'RED')
    display.DisplayColoredShape(GreenEdge.Edge(), 'GREEN')
    display.DisplayShape(V3)
    display.DisplayShape(V4, update=True)
Exemple #7
0
    def create_shape(self):
        d = self.declaration
        n = len(d.points)
        if n < 2:
            raise ValueError("A bezier must have at least 2 points!")

        points = self.get_transformed_points()
        pts = TColgp_Array1OfPnt(1, n)
        set_value = pts.SetValue

        # TODO: Support weights
        for i, p in enumerate(points):
            set_value(i + 1, p)

        curve = self.curve = Geom_BezierCurve(pts)
        self.shape = self.make_edge(curve)
def revolved_cut(base):
    # Define 7 points
    face_points = TColgp_Array1OfPnt(1, 7)
    face_inner_radius = 0.6

    pts = [
        gp_Pnt(face_inner_radius - 0.05, 0.0, -0.05),
        gp_Pnt(face_inner_radius - 0.10, 0.0, -0.025),
        gp_Pnt(face_inner_radius - 0.10, 0.0, 0.025),
        gp_Pnt(face_inner_radius + 0.10, 0.0, 0.025),
        gp_Pnt(face_inner_radius + 0.10, 0.0, -0.025),
        gp_Pnt(face_inner_radius + 0.05, 0.0, -0.05),
        gp_Pnt(face_inner_radius - 0.05, 0.0, -0.05),
    ]

    for n, i in enumerate(pts):
        face_points.SetValue(n + 1, i)

    # Use these points to create edges and add these edges to a wire
    hexwire = BRepBuilderAPI_MakeWire()

    for i in range(1, 7):
        hexedge = BRepBuilderAPI_MakeEdge(face_points.Value(i),
                                          face_points.Value(i + 1)).Edge()
        hexwire.Add(hexedge)

    # Turn the wire into a 6 sided face
    hexface = BRepBuilderAPI_MakeFace(hexwire.Wire()).Face()

    # Revolve the face around an axis
    revolve_axis = gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1))
    revolved_shape = BRepPrimAPI_MakeRevol(hexface, revolve_axis).Shape()

    # Move the generated shape
    move = gp_Trsf()
    move.SetTranslation(gp_Pnt(0, 0, 0), gp_Pnt(0, 0, sin(0.5)))
    moved_shape = BRepBuilderAPI_Transform(revolved_shape, move, False).Shape()

    # Remove the revolved shape
    cut = BRepAlgoAPI_Cut(base, moved_shape).Shape()
    return cut
Exemple #9
0
def to_tcolgp_array1_pnt(pnts):
    """
    Convert the 1-D array of point_like entities to OCC data.

    :param array_like pnts: Array of points to convert.

    :return: OCC array of points.
    :rtype: TColgp_Array1OfPnt
    """
    gp_pnts = []
    for gp in pnts:
        gp = to_gp_pnt(gp)
        if not gp:
            continue
        gp_pnts.append(gp)

    n = len(gp_pnts)
    array = TColgp_Array1OfPnt(1, n)
    for i, gp in enumerate(gp_pnts, 1):
        array.SetValue(i, gp)

    return array
def point_list_to_TColgp_Array1OfPnt(li):
    pts = TColgp_Array1OfPnt(0, len(li)-1)
    for n, i in enumerate(li):
        pts.SetValue(n, i)
    return pts