def offset_cube(event=None):
    S2 = BRepPrimAPI_MakeBox(gp_Pnt(300, 0, 0), 220, 140, 180).Shape()
    offsetB = BRepOffsetAPI_MakeOffsetShape(S2, -20, 0.01, BRepOffset_Skin, False, False, GeomAbs_Arc)
    offB = display.DisplayColoredShape(S2, 'BLUE')
    display.Context.SetTransparency(offB, 0.3, True)
    display.DisplayColoredShape(offsetB.Shape(), 'GREEN')
    display.FitAll()
Пример #2
0
class OffsetShape(object):
    """
    Offset a shape.

    :param afem.topology.entities.Shape shape: The shape. It may be a face,
        shell, a solid, or a compound of these kinds.
    :param float offset: The offset value. The offset will be outside the
        shape if positive and inside if negative.
    :param float tol: Tolerance for coincidence for generated shapes. If not
        provided the average tolerance of the shape is used.
    :param OCC.Core.GeomAbs.GeomAbs_JoinType join_mode: Option for how to fill
        holes that may appear when offsetting two adjacent faces.
    :param bool remove_internal_edges: Option to remove internal edges from the
        result.
    :param bool perform_simple: Option to use simple algorithm without
        intersection computation.
    """
    def __init__(self,
                 shape,
                 offset,
                 tol=None,
                 join_mode=Geometry.ARC,
                 remove_internal_edges=False,
                 perform_simple=False):
        if tol is None:
            tol = shape.tol_avg

        self._tool = BRepOffsetAPI_MakeOffsetShape()
        if perform_simple:
            self._tool.PerformBySimple(shape.object, offset)
        else:
            self._tool.PerformByJoin(shape.object, offset, tol,
                                     BRepOffset_Skin, False, False, join_mode,
                                     remove_internal_edges)

        self._shape = Shape.wrap(self._tool.Shape())

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

    @property
    def shape(self):
        """
        :return: The offset shape.
        :rtype: afem.topology.entities.Shape
        """
        return self._shape
Пример #3
0
    def __init__(self,
                 shape,
                 offset,
                 tol=None,
                 join_mode=Geometry.ARC,
                 remove_internal_edges=False,
                 perform_simple=False):
        if tol is None:
            tol = shape.tol_avg

        self._tool = BRepOffsetAPI_MakeOffsetShape()
        if perform_simple:
            self._tool.PerformBySimple(shape.object, offset)
        else:
            self._tool.PerformByJoin(shape.object, offset, tol,
                                     BRepOffset_Skin, False, False, join_mode,
                                     remove_internal_edges)

        self._shape = Shape.wrap(self._tool.Shape())
Пример #4
0
def make_offset_shape(shapeToOffset, offsetDistance, tolerance=TOLERANCE,
                      offsetMode=BRepOffset_Skin, intersection=False,
                      selfintersection=False, joinType=GeomAbs_Arc):
    '''
    builds an offsetted shell from a shape
    construct an offsetted version of the shape
    '''
    from OCC.Core.BRepOffsetAPI import BRepOffsetAPI_MakeOffsetShape
    try:
        offset = BRepOffsetAPI_MakeOffsetShape(shapeToOffset,
                                               offsetDistance,
                                               tolerance,
                                               offsetMode,
                                               intersection,
                                               selfintersection,
                                               joinType)
        if offset.IsDone():
            return offset.Shape()
        else:
            return None
    except RuntimeError('failed to offset shape'):
        return None
Пример #5
0
def _offset(shp, off):
    algo = BRepOffsetAPI_MakeOffsetShape()
    algo.PerformByJoin(shp.Shape(), off, 1e-6)
    algo.Build()
    return Shape(algo.Shape())