Ejemplo n.º 1
0
def test_stl_exporter_happy_path(box_shape):
    r"""Happy path"""
    filename = path_from_file(__file__, "./models_out/box.sTl")
    exporter = StlExporter(filename)
    exporter.set_shape(box_shape)
    exporter.write_file()
    assert os.path.isfile(filename)
Ejemplo n.º 2
0
def test_stl_exporter_happy_path_shape_subclass(box_shape):
    r"""Happy path with a subclass of TopoDS_Shape"""
    filename = path_from_file(__file__, "./models_out/box.stl")
    exporter = StlExporter(filename)
    solid = shape_to_topology(box_shape)
    assert isinstance(solid, TopoDS.TopoDS_Solid)
    exporter.set_shape(solid)
    exporter.write_file()
    assert os.path.isfile(filename)
Ejemplo n.º 3
0
def test_stl_exporter_happy_path(box_shape):
    r"""Happy path"""
    filename = path_from_file(__file__, "./models_out/box.stl")
    exporter = StlExporter(filename)
    exporter.set_shape(box_shape)
    exporter.write_file()
    assert os.path.isfile(filename)
Ejemplo n.º 4
0
def test_stl_exporter_happy_path_shape_subclass(box_shape):
    r"""Happy path with a subclass of TopoDS_Shape"""
    filename = path_from_file(__file__, "./models_out/box.stl")
    exporter = StlExporter(filename)
    solid = shape_to_topology(box_shape)
    assert isinstance(solid, TopoDS.TopoDS_Solid)
    exporter.set_shape(solid)
    exporter.write_file()
    assert os.path.isfile(filename)
Ejemplo n.º 5
0
def shape_to_file(shape, pth, filename, format='iges'):
    """write a Shape to a .iges .brep .stl or .step file"""

    from OCCDataExchange.brep import BrepExporter
    from OCCDataExchange.iges import IgesExporter
    from OCCDataExchange.step import StepExporter
    from OCCDataExchange.stl import StlExporter

    _pth = os.path.join(pth, filename)
    assert not os.path.isdir(_pth), 'wrong path, filename'
    _file = str("%s.%s" % (_pth, format))

    _formats = ['iges', 'igs', 'step', 'stp', 'brep', 'stl']
    assert format in _formats, '%s is not a readable format, should be one of %s ' % (
        format, _formats)

    if format in ['iges', 'igs']:
        writer = IgesExporter(_file)
        writer.add_shape(shape)
        writer.write_file()
        return _file

    elif format in ['step', 'stp']:
        writer = StepExporter(_file)
        writer.add_shape(shape)
        writer.write_file()
        return _file

    elif format == 'brep':
        writer = BrepExporter(_file)
        writer.set_shape(shape)
        writer.write_file()
        return _file

    elif format == 'stl':
        writer = StlExporter(_file)
        writer.set_shape(shape)
        writer.write_file()
        return _file

    else:
        raise ValueError(
            'format should be one of [iges,igs], [step,stp], brep, stl\ngot %s'
            % (format))
Ejemplo n.º 6
0
def test_stl_exporter_overwrite(box_shape):
    r"""Happy path with a subclass of TopoDS_Shape"""
    filename = path_from_file(__file__, "./models_out/box.stl")
    exporter = StlExporter(filename)
    solid = shape_to_topology(box_shape)
    assert isinstance(solid, TopoDS.TopoDS_Solid)
    exporter.set_shape(solid)
    exporter.write_file()
    assert os.path.isfile(filename)

    # read the written box.stl
    importer = StlImporter(filename)
    topo = Topo(importer.shape)
    assert topo.number_of_shells() == 1

    # set a sphere and write again with same exporter
    sphere = BRepPrimAPI.BRepPrimAPI_MakeSphere(10)
    exporter.set_shape(sphere.Shape())
    exporter.write_file()  # this creates a file with a sphere only, this is STL specific

    # check that the file contains the sphere only
    importer = StlImporter(filename)
    topo = Topo(importer.shape)
    assert topo.number_of_shells() == 1

    # create a new exporter and overwrite with a box only
    filename = path_from_file(__file__, "./models_out/box.stl")
    exporter = StlExporter(filename)
    solid = shape_to_topology(box_shape)
    exporter.set_shape(solid)
    exporter.write_file()
    assert os.path.isfile(filename)

    # check the file only contains a box
    importer = StlImporter(filename)
    topo = Topo(importer.shape)
    assert topo.number_of_shells() == 1
Ejemplo n.º 7
0
def test_stl_exporter_adding_not_a_shape(box_shape):
    r"""Adding something to the exporter that is not a TopoDS_Shape or a subclass"""
    filename = path_from_file(__file__, "./models_out/box.stl")
    exporter = StlExporter(filename)
    with pytest.raises(ValueError):
        exporter.set_shape(gp.gp_Pnt(1, 1, 1))
Ejemplo n.º 8
0
#!/usr/bin/env python
# coding: utf-8
r"""Exporting a shape to STL"""

from __future__ import print_function

import logging

from OCC import BRepPrimAPI

from OCCDataExchange.stl import StlExporter
from OCCDataExchange.utils import path_from_file

logging.basicConfig(
    level=logging.DEBUG,
    format=
    '%(asctime)s :: %(levelname)6s :: %(module)20s :: %(lineno)3d :: %(message)s'
)

# First create a simple shape to export
my_box_shape = BRepPrimAPI.BRepPrimAPI_MakeBox(50, 50, 50).Shape()

# Export to STL. If ASCIIMode is set to False, then binary format is used.
filename = path_from_file(__file__, "./models_out/result_export.stl")
my_stl_exporter = StlExporter(filename, ascii_mode=True)
my_stl_exporter.set_shape(my_box_shape)
my_stl_exporter.write_file()
Ejemplo n.º 9
0
#!/usr/bin/env python
# coding: utf-8

r"""Exporting a shape to STL"""

from __future__ import print_function

import logging

from OCC import BRepPrimAPI

from OCCDataExchange.stl import StlExporter
from OCCDataExchange import path_from_file

logging.basicConfig(
    level=logging.DEBUG, format="%(asctime)s :: %(levelname)6s :: %(module)20s :: %(lineno)3d :: %(message)s"
)

# First create a simple shape to export
my_box_shape = BRepPrimAPI.BRepPrimAPI_MakeBox(50, 50, 50).Shape()

# Export to STL. If ASCIIMode is set to False, then binary format is used.
filename = path_from_file(__file__, "./models_out/result_export.stl")
my_stl_exporter = StlExporter(filename, ascii_mode=True)
my_stl_exporter.set_shape(my_box_shape)
my_stl_exporter.write_file()
Ejemplo n.º 10
0
def test_stl_exporter_overwrite(box_shape):
    r"""Happy path with a subclass of TopoDS_Shape"""
    filename = path_from_file(__file__, "./models_out/box.stl")
    exporter = StlExporter(filename)
    solid = shape_to_topology(box_shape)
    assert isinstance(solid, TopoDS.TopoDS_Solid)
    exporter.set_shape(solid)
    exporter.write_file()
    assert os.path.isfile(filename)

    # read the written box.stl
    importer = StlImporter(filename)
    topo = Topo(importer.shape)
    assert topo.number_of_shells() == 1

    # set a sphere and write again with same exporter
    sphere = BRepPrimAPI.BRepPrimAPI_MakeSphere(10)
    exporter.set_shape(sphere.Shape())
    exporter.write_file(
    )  # this creates a file with a sphere only, this is STL specific

    # check that the file contains the sphere only
    importer = StlImporter(filename)
    topo = Topo(importer.shape)
    assert topo.number_of_shells() == 1

    # create a new exporter and overwrite with a box only
    filename = path_from_file(__file__, "./models_out/box.stl")
    exporter = StlExporter(filename)
    solid = shape_to_topology(box_shape)
    exporter.set_shape(solid)
    exporter.write_file()
    assert os.path.isfile(filename)

    # check the file only contains a box
    importer = StlImporter(filename)
    topo = Topo(importer.shape)
    assert topo.number_of_shells() == 1
Ejemplo n.º 11
0
def test_stl_exporter_adding_not_a_shape(box_shape):
    r"""Adding something to the exporter that is not a TopoDS_Shape or a subclass"""
    filename = path_from_file(__file__, "./models_out/box.stl")
    exporter = StlExporter(filename)
    with pytest.raises(ValueError):
        exporter.set_shape(gp.gp_Pnt(1, 1, 1))
Ejemplo n.º 12
0
def test_stl_exporter_wrong_extension(box_shape):
    r"""Trying to write a step file with the IgesExporter"""
    filename = path_from_file(__file__, "./models_out/box.step")
    with pytest.raises(AssertionError):
        StlExporter(filename)
Ejemplo n.º 13
0
def test_stl_exporter_wrong_filename(box_shape):
    r"""Trying to write to a non-existent directory"""
    filename = path_from_file(__file__, "./nonexistent/box.stl")
    with pytest.raises(AssertionError):
        StlExporter(filename)