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()
Beispiel #2
0
 def update_shape(self, change=None):
     d = self.declaration
     shape = self.get_shape_to_offset()
     offset_shape = BRepOffsetAPI_MakeOffsetShape()
     offset_shape.PerformByJoin(shape, d.offset, d.tolerance,
                                self.offset_modes[d.offset_mode],
                                d.intersection, False,
                                self.join_types[d.join_type])
     self.shape = offset_shape.Shape()
Beispiel #3
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 OCCT.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
Beispiel #4
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())
Beispiel #5
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 OCCT.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