Ejemplo n.º 1
0
def make_shell(*args):
    shell = BRepBuilderAPI_MakeShell(*args)
    st = ShapeToTopology()
    with assert_isdone(shell, 'failed to produce shell'):
        result = shell.Shell()
        shell.Delete()
        return st(result)
Ejemplo n.º 2
0
def fix_continuity(edge, continuity=1):
    from OCC.ShapeUpgrade import ShapeUpgrade_ShapeDivideContinuity
    su = ShapeUpgrade_ShapeDivideContinuity(edge)
    su.SetBoundaryCriterion(eval('GeomAbs_C'+str(continuity)))
    su.Perform()
    st = ShapeToTopology()
    te = st(su.Result())
    return te
Ejemplo n.º 3
0
def fix_shape(shp, tolerance=1e-3):
    te = ShapeToTopology()
    fix = ShapeFix_Shape(shp)
    fix.SetFixFreeShellMode(True)
    sf = fix.FixShellTool().GetObject()
    sf.SetFixOrientationMode(True)
    fix.LimitTolerance(tolerance)
    fix.Perform()
    return fix.Shape()
Ejemplo n.º 4
0
    def copy(self):
        """

        :return:
        """
        from OCC.BRepBuilderAPI import BRepBuilderAPI_Copy
        cp = BRepBuilderAPI_Copy(self.topo)
        cp.Perform(self.topo)
        return ShapeToTopology()(cp.Shape())
Ejemplo n.º 5
0
def make_loft(elements, ruled=False, tolerance=TOLERANCE):
    sections = BRepOffsetAPI_ThruSections(False, ruled, tolerance)
    for i in elements:
        if isinstance(i, TopoDS_Wire):
            sections.AddWire(i)
        elif isinstance(i, TopoDS_Vertex):
            sections.AddVertex(i)
        else:
            raise TypeError(
                'elements is a list of TopoDS_Wire or TopoDS_Vertex, found a %s fool'
                % (i.__class__))
    sections.CheckCompatibility(True)
    sections.Build()
    with assert_isdone(sections, 'failed lofting'):
        te = ShapeToTopology()
        loft = te(sections.Shape())
        return loft
Ejemplo n.º 6
0
def sew_shapes(shapes, tolerance=0.001):
    #    sew = BRepBuilderAPI_Sewing(tolerance, True, True, True, False)
    #    sew = BRepBuilderAPI_Sewing(1e-3, True, False, False, False)
    sew = BRepBuilderAPI_Sewing(tolerance)
    # sew.SetFloatingEdgesMode(True)
    for shp in shapes:
        if isinstance(shp, list):
            for i in shp:
                sew.Add(i)
        else:
            sew.Add(shp)
    sew.Perform()
    print 'n degenerated shapes', sew.NbDegeneratedShapes()
    print 'n deleted faces:', sew.NbDeletedFaces()
    print 'n free edges', sew.NbFreeEdges()
    print 'n multiple edges:', sew.NbMultipleEdges()
    result = ShapeToTopology()(sew.SewedShape())
    return result
Ejemplo n.º 7
0
def translate_topods_from_vector(brep_or_iterable, vec, copy=False):
    '''
    translate a brep over a vector
    @param brep:    the Topo_DS to translate
    @param vec:     the vector defining the translation
    @param copy:    copies to brep if True
    '''
    from OCC.KBE.types_lut import ShapeToTopology
    st = ShapeToTopology()
    trns = gp_Trsf()
    trns.SetTranslation(vec)
    if issubclass(brep_or_iterable.__class__, TopoDS_Shape):
        brep_trns = BRepBuilderAPI_Transform(brep_or_iterable, trns, copy)
        brep_trns.Build()
        return st(brep_trns.Shape())
    else:
        return [
            translate_topods_from_vector(brep_or_iterable, vec, copy)
            for i in brep_or_iterable
        ]
Ejemplo n.º 8
0
from OCC.BRepPrimAPI import *
from OCC.GeomAbs import *
from OCC.TopAbs import *
from OCC.TopoDS import *
from OCC.gp import *

# high level
from OCC.Utils.Common import *
from OCC.Utils.Context import assert_isdone
from OCC.KBE.types_lut import shape_lut, curve_lut, surface_lut, topo_lut

from functools import wraps
import warnings, operator, math

EPSILON = TOLERANCE = 1e-6
ST = ShapeToTopology()

#===============================================================================
# ---MONKEY PATCH GP---
#===============================================================================


def point_to_vector(self):
    return gp_Vec(self.XYZ())


def vector_to_point(self):
    return gp_Pnt(self.XYZ())


def dir_to_vec(self):