예제 #1
0
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 OCC.Core.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
예제 #2
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())
예제 #3
0
 def renderTube(self, geometry, transforms, styleName, layerName):
     aWire, radius = geometry
     startPoint, tangentDir = getWireStartPointAndTangentDir(aWire)
     profileCircle = GC_MakeCircle(startPoint, tangentDir, radius).Value()
     profileEdge = BRepBuilderAPI_MakeEdge(profileCircle).Edge()
     profileWire =  BRepBuilderAPI_MakeWire(profileEdge).Wire()
     
     pipeShell = BRepOffsetAPI_MakePipe(aWire, profileWire)
     pipeShape = pipeShell.Shape()
     
     self.renderShapeObj(pipeShape, transforms, styleName)
예제 #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()
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)
예제 #6
0
    def _renderWireObj(self, aWire, aWireRadius):
        startPoint, tangentDir = _getWireStartPointAndTangentDir(aWire)
        profileCircle = GC_MakeCircle(startPoint, tangentDir,
                                      aWireRadius).Value()
        profileEdge = BRepBuilderAPI_MakeEdge(profileCircle).Edge()
        profileWire = BRepBuilderAPI_MakeWire(profileEdge).Wire()

        shape = BRepOffsetAPI_MakePipe(aWire, profileWire).Shape()

        self._renderShapeObj(shape)
예제 #7
0
def sweep_pipe(edge, xvec, r, wt, geom_repr=ElemType.SOLID):
    if geom_repr not in [ElemType.SOLID, ElemType.SHELL]:
        raise ValueError("Sweeping pipe must be either 'solid' or 'shell'")

    t = TopologyExplorer(edge)
    points = [v for v in t.vertices()]
    point = BRep_Tool_Pnt(points[0])
    # x, y, z = point.X(), point.Y(), point.Z()
    direction = gp_Dir(*unit_vector(xvec).astype(float).tolist())

    # pipe
    makeWire = BRepBuilderAPI_MakeWire()
    makeWire.Add(edge)
    makeWire.Build()
    wire = makeWire.Wire()
    try:
        if geom_repr == ElemType.SOLID:
            i = make_circular_sec_face(point, direction, r - wt)
            elbow_i = BRepOffsetAPI_MakePipe(wire, i).Shape()
            o = make_circular_sec_face(point, direction, r)
            elbow_o = BRepOffsetAPI_MakePipe(wire, o).Shape()
        else:
            elbow_i = None
            o = make_circular_sec_wire(point, direction, r)
            elbow_o = BRepOffsetAPI_MakePipe(wire, o).Shape()
    except RuntimeError as e:
        logging.error(f'Pipe sweep failed: "{e}"')
        return wire
    if geom_repr == ElemType.SOLID:
        boolean_result = BRepAlgoAPI_Cut(elbow_o, elbow_i).Shape()
        if boolean_result.IsNull():
            logging.debug("Boolean returns None")
    else:
        boolean_result = elbow_o

    return boolean_result
 def make_pipe(wire, p1, p2):
     # the pipe
     if p2 is not None:
         direction_coords = np.array(p2.XYZ().Coord()) - np.array(
             p1.XYZ().Coord())
         direction_coords /= np.linalg.norm(direction_coords)
         direction = gp_Dir(*list(direction_coords))
     else:
         direction = gp_Dir(1, 0, 0)
     # print(p1.XYZ().Coord(), p2.XYZ().Coord())
     circle = gp_Circ(gp_Ax2(p1, direction), RADIUS)
     profile_edge = BRepBuilderAPI_MakeEdge(circle).Edge()
     profile_wire = BRepBuilderAPI_MakeWire(profile_edge).Wire()
     profile_face = BRepBuilderAPI_MakeFace(profile_wire).Face()
     pipe = BRepOffsetAPI_MakePipe(wire, profile_face).Shape()
     return pipe
예제 #9
0
def _pipe(shp, spine, mode="corrected_frenet", force_approx_c1=False):
    if (spine.Shape().IsNull()):
        raise Exception("Cannot sweep along empty spine")

    if (shp.Shape().IsNull()):
        raise Exception("Cannot sweep empty profile")

    try:
        if isinstance(mode, str):
            tri = geomfill_triedron_map[mode]
        else:
            tri = mode

    except Exception:
        raise Exception("pipe: undefined mode")

    return Shape(BRepOffsetAPI_MakePipe(spine.Wire_orEdgeToWire(), shp.Shape(), tri, force_approx_c1).Shape())
예제 #10
0
def sweep_geom(sweep_wire: TopoDS_Wire, wire_face: TopoDS_Wire):
    return BRepOffsetAPI_MakePipe(sweep_wire, wire_face).Shape()
예제 #11
0
def make_pipe(spine, profile):
    from OCC.Core.BRepOffsetAPI import BRepOffsetAPI_MakePipe
    pipe = BRepOffsetAPI_MakePipe(spine, profile)
    with assert_isdone(pipe, 'failed building pipe'):
        pipe.Build()
        return pipe.Shape()