Example #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)
Example #2
0
def sew_shapes(shapes, tolerance=0.001):
    sew = BRepBuilderAPI_Sewing(tolerance)
    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
Example #3
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
    '''
    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
        ]
Example #4
0
def make_loft(elements,
              ruled=False,
              tolerance=TOLERANCE,
              continuity=GeomAbs_C2,
              check_compatibility=True):
    from OCC.Core.Core.BRepOffsetAPI import BRepOffsetAPI_ThruSections
    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(check_compatibility)
    sections.SetContinuity(continuity)
    sections.Build()
    with assert_isdone(sections, 'failed lofting'):
        te = ShapeToTopology()
        loft = te(sections.Shape())
        return loft
Example #5
0
r"""IGES file writing tests"""

import glob
import os.path

import pytest
from OCC import BRepPrimAPI
from OCC import TopoDS
from OCC import gp
from OCCUtils.Topology import Topo
from OCCUtils.types_lut import ShapeToTopology

from OCCDataExchange.iges import IgesExporter, IgesImporter
from OCCDataExchange.utils import path_from_file

shape_to_topology = ShapeToTopology()


@pytest.yield_fixture(autouse=True)
def cleandir():
    r"""Clean the tests output directory

    autouse=True insure this fixture wraps every test function
    yield represents the function call
    """
    yield  # represents the test function call
    output_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "models_out")
    files = glob.glob(output_dir + "\*")
    print("Cleaning output directory ...")
    for f in files:
        os.remove(f)
Example #6
0
                              GeomAbs_G1, GeomAbs_G2, GeomAbs_C1)
from OCC.Core.TopAbs import TopAbs_REVERSED
from OCC.Core.TopoDS import (TopoDS_Wire, TopoDS_Solid, TopoDS_Vertex,
                             TopoDS_Shape, TopoDS_Builder, TopoDS_Compound)
from OCC.Core.TColgp import TColgp_SequenceOfVec, TColgp_HArray1OfPnt
from OCC.Core.gp import (gp_Vec, gp_Pnt, gp_Dir, gp_Trsf, gp_Ax1,
                         gp_Quaternion, gp_Circ, gp_Pln)

from OCCUtils.Common import (TOLERANCE, assert_isdone, to_tcol_, to_adaptor_3d,
                             vertex2pnt, smooth_pnts, points_to_bspline,
                             project_point_on_curve)
from OCCUtils.types_lut import ShapeToTopology
from OCCUtils.Topology import Topo

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


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):
    return gp_Vec(self)


def vec_to_dir(self):