Esempio n. 1
0
def make_offset(wire_or_face, offsetDistance, altitude=0, joinType=GeomAbs_Arc):
    '''
    builds a offsetted wire or face from a wire or face
    construct an offsetted version of the shape

    @param wire_or_face:        the wire or face to offset
    @param offsetDistance:      the distance to offset
    @param altitude:            move the offsetted shape to altitude
    from the normal of the wire or face
    @param joinType:            the type of offset you want
    can be one of GeomAbs_Arc, GeomAbs_Tangent, GeomAbs_Intersection

    note: a shape that has a negative offsetDistance will return
    a sharp corner
    '''
    from OCCT.BRepOffsetAPI import BRepOffsetAPI_MakeOffset
    _joints = [GeomAbs_Arc, GeomAbs_Tangent, GeomAbs_Intersection]
    assert joinType in _joints, '%s is not one of %s' % (joinType, _joints)
    try:
        offset = BRepOffsetAPI_MakeOffset(wire_or_face, joinType)
        offset.Perform(offsetDistance, altitude)
        if offset.IsDone():
            return ST(offset.Shape())
        else:
            return None
    except RuntimeError('failed to offset shape'):
        return None
Esempio n. 2
0
 def __init__(self,
              spine,
              distance,
              altitude=0.,
              join=Geometry.ARC,
              is_open=False):
     offset = BRepOffsetAPI_MakeOffset(spine.object, join, is_open)
     offset.Perform(distance, altitude)
     self._w = Wire(offset.Shape())
Esempio n. 3
0
    def update_shape(self, change=None):
        d = self.declaration
        shape = Topology.cast_shape(self.get_shape_to_offset())
        if isinstance(shape, TopoDS_Edge):
            shape = BRepBuilderAPI_MakeWire(shape).Wire()
        elif not isinstance(shape, (TopoDS_Wire, TopoDS_Face)):
            t = type(shape)
            raise TypeError(
                "Unsupported child shape %s when using planar mode" % t)

        offset_shape = BRepOffsetAPI_MakeOffset(
            shape, self.join_types[d.join_type], not d.closed)
        offset_shape.Perform(d.offset)
        if not offset_shape.IsDone():
            # Note: Lines cannot be offset as they have no plane of reference
            raise ValueError("Could not perform offset: %s" % d)
        self.shape = offset_shape.Shape()
def create_offsets(face, nr_of_counters, distance_between_contours):
    offset = BRepOffsetAPI_MakeOffset()
    offset.Init(GeomAbs_Arc)

    for wi in TopologyExplorer(face).wires():
        offset.AddWire(wi)

    for i in range(nr_of_counters):
        offset.Perform(-distance_between_contours * i)
        if offset.IsDone():
            yield offset.Shape()