Example #1
0
    def update_shape(self, change=None):
        d = self.declaration

        if d.spline and d.profile:
            spline, profile = d.spline, d.profile
        elif d.spline:
            spline = d.spline
            profile = self.get_first_child().shape
        elif d.profile:
            profile = d.profile
            spline = self.get_first_child().shape
        else:
            shapes = [
                c.shape for c in self.children() if isinstance(c, OccShape)
            ]
            spline, profile = shapes[0:2]

        args = [coerce_shape(spline), coerce_shape(profile)]

        # Make sure spline is a wire
        if isinstance(args[0], TopoDS_Edge):
            args[0] = BRepBuilderAPI_MakeWire(args[0]).Wire()

        if d.fill_mode:
            args.append(self.fill_modes[d.fill_mode])
        pipe = BRepOffsetAPI_MakePipe(*args)
        self.shape = pipe.Shape()
def make_oriented_box(v_corner, v_x, v_y, v_z):
    """
    produces an oriented box
    oriented meaning here that the x,y,z axis do not have to be
    cartesian aligned

    :param v_corner: the lower corner
    :param v_x: gp_Vec that describes the X-axis
    :param v_y: gp_Vec that describes the Y-axis
    :param v_z: gp_Vec that describes the Z-axis
    :return: TopoDS_Solid
    """
    from OCCT.BRepOffsetAPI import BRepOffsetAPI_MakePipe
    verts = map(
        lambda x: x.as_pnt(),
        [v_corner, v_corner + v_x, v_corner + v_x + v_y, v_corner + v_y])
    p = make_polygon(verts, closed=True)
    li = make_line(v_corner.as_pnt(), (v_corner + v_z).as_pnt())
    bmp = BRepOffsetAPI_MakePipe(p, li)
    bmp.Build()
    shp = bmp.Shape()

    bottom = make_face(p)
    top = translate_topods_from_vector(bottom, v_z, True)
    oriented_bbox = make_solid(sew_shapes([bottom, shp, top]))
    return oriented_bbox
Example #3
0
class SweepShape(object):
    """
    Sweep a profile along a spine.

    :param spine: The path for the sweep. This must be at least G1 continuous.
    :type spine: afem.geometry.entities.Curve or afem.topology.entities.Edge or
        afem.topology.entities.Wire
    :param profile: The profile.
    :type profile: afem.geometry.entities.Geometry or
        afem.topology.entities.Shape

    :raise TypeError: If ``spine`` is not or cannot be converted to a wire.
    """

    def __init__(self, spine, profile):
        if isinstance(spine, Curve):
            spine = Wire.by_curve(spine)
        elif spine.is_edge:
            spine = Wire.by_edge(spine)

        if not spine.is_wire:
            raise TypeError('Spine is not a wire.')

        profile = Shape.to_shape(profile)
        self._tool = BRepOffsetAPI_MakePipe(spine.object, profile.object)

        self._tool.Build()

    @property
    def is_done(self):
        """
        :return: *True* if done, *False* if not.
        :rtype: bool
        """
        return self._tool.IsDone()

    @property
    def shape(self):
        """
        :return: The swept shape.
        :rtype: afem.topology.entities.Shape
        """
        return Shape.wrap(self._tool.Shape())

    @property
    def first_shape(self):
        """
        :return: The first/bottom shape of the sweep.
        :rtype: afem.topology.entities.Shape
        """
        return Shape.wrap(self._tool.FirstShape())

    @property
    def last_shape(self):
        """
        :return: The last/top shape of the sweep.
        :rtype: afem.topology.entities.Shape
        """
        return Shape.wrap(self._tool.LastShape())
Example #4
0
    def __init__(self, spine, profile):
        if isinstance(spine, Curve):
            spine = Wire.by_curve(spine)
        elif spine.is_edge:
            spine = Wire.by_edge(spine)

        if not spine.is_wire:
            raise TypeError('Spine is not a wire.')

        profile = Shape.to_shape(profile)
        self._tool = BRepOffsetAPI_MakePipe(spine.object, profile.object)

        self._tool.Build()
Example #5
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)
Example #6
0
def make_pipe(spine, profile):
    from OCCT.BRepOffsetAPI import BRepOffsetAPI_MakePipe
    pipe = BRepOffsetAPI_MakePipe(spine, profile)
    with assert_isdone(pipe, 'failed building pipe'):
        pipe.Build()
        return pipe.Shape()