Пример #1
0
def test_step_exporter_happy_path(box_shape):
    r"""Happy path"""
    filename = path_from_file(__file__, "./models_out/box.StP")
    exporter = StepExporter(filename)
    exporter.add_shape(box_shape)
    exporter.write_file()
    assert os.path.isfile(filename)
Пример #2
0
def test_step_exporter_happy_path(box_shape):
    r"""Happy path"""
    filename = path_from_file(__file__, "./models_out/box.StP")
    exporter = StepExporter(filename)
    exporter.add_shape(box_shape)
    exporter.write_file()
    assert os.path.isfile(filename)
Пример #3
0
def test_step_exporter_happy_path_shape_subclass(box_shape):
    r"""Happy path with a subclass of TopoDS_Shape"""
    filename = path_from_file(__file__, "./models_out/box.stp")
    exporter = StepExporter(filename)
    solid = shape_to_topology(box_shape)
    assert isinstance(solid, TopoDS.TopoDS_Solid)
    exporter.add_shape(solid)
    exporter.write_file()
    assert os.path.isfile(filename)
Пример #4
0
def test_step_exporter_happy_path_shape_subclass(box_shape):
    r"""Happy path with a subclass of TopoDS_Shape"""
    filename = path_from_file(__file__, "./models_out/box.stp")
    exporter = StepExporter(filename)
    solid = shape_to_topology(box_shape)
    assert isinstance(solid, TopoDS.TopoDS_Solid)
    exporter.add_shape(solid)
    exporter.write_file()
    assert os.path.isfile(filename)
Пример #5
0
def export_step():
    """
    Exports a TopoDS_Shape to a STEP file.
    """
    test_shape = BRepPrimAPI.BRepPrimAPI_MakeBox(100., 100., 100.).Shape()
    # export to AP203 schema
    ap203_exporter = StepExporter('./models_out/box_203.stp', schema='AP203')
    ap203_exporter.add_shape(test_shape)
    ap203_exporter.write_file()
    # export AP214 schema
    ap214cd_exporter = StepExporter('./models_out/box_214CD.stp', schema='AP214CD')
    ap214cd_exporter.add_shape(test_shape)
    ap214cd_exporter.write_file()
Пример #6
0
def export_step():
    """
    Exports a TopoDS_Shape to a STEP file.
    """
    test_shape = BRepPrimAPI.BRepPrimAPI_MakeBox(100., 100., 100.).Shape()
    # export to AP203 schema
    ap203_exporter = StepExporter('./models_out/box_203.stp', schema='AP203')
    ap203_exporter.add_shape(test_shape)
    ap203_exporter.write_file()
    # export AP214 schema
    ap214cd_exporter = StepExporter('./models_out/box_214CD.stp',
                                    schema='AP214CD')
    ap214cd_exporter.add_shape(test_shape)
    ap214cd_exporter.write_file()
Пример #7
0
def test_step_exporter_overwrite(box_shape):
    r"""Happy path with a subclass of TopoDS_Shape"""
    filename = path_from_file(__file__, "./models_out/box.stp")
    exporter = StepExporter(filename)
    solid = shape_to_topology(box_shape)
    assert isinstance(solid, TopoDS.TopoDS_Solid)
    exporter.add_shape(solid)
    exporter.write_file()
    initial_timestamp = os.path.getmtime(filename)
    assert os.path.isfile(filename)

    # read the written box.stp
    importer = StepImporter(filename)
    topo_compound = Topo(importer.compound)
    assert topo_compound.number_of_faces() == 6
    assert len([i for i in topo_compound.faces()]) == 6
    assert topo_compound.number_of_edges() == 12

    # add a sphere and write again with same exporter
    sphere = BRepPrimAPI.BRepPrimAPI_MakeSphere(10)
    exporter.add_shape(sphere.Shape())
    exporter.write_file()  # this creates a file with a box and a sphere
    intermediate_timestamp = os.path.getmtime(filename)
    assert intermediate_timestamp >= initial_timestamp

    # check that the file contains the box and the sphere
    importer = StepImporter(filename)
    assert len([i for i in Topo(importer.compound).faces()]) == 7  # 6 from box + 1 from sphere
    assert len([i for i in Topo(importer.compound).solids()]) == 2

    # create a new exporter and overwrite with a box only
    filename = path_from_file(__file__, "./models_out/box.stp")
    exporter = StepExporter(filename)
    solid = shape_to_topology(box_shape)
    exporter.add_shape(solid)
    exporter.write_file()
    assert os.path.isfile(filename)
    last_timestamp = os.path.getmtime(filename)
    assert last_timestamp >= intermediate_timestamp

    # check the file only contains a box
    importer = StepImporter(filename)
    assert len([i for i in Topo(importer.compound).faces()]) == 6  # 6 from box
    assert len([i for i in Topo(importer.compound).solids()]) == 1
Пример #8
0
def test_step_exporter_overwrite(box_shape):
    r"""Happy path with a subclass of TopoDS_Shape"""
    filename = path_from_file(__file__, "./models_out/box.stp")
    exporter = StepExporter(filename)
    solid = shape_to_topology(box_shape)
    assert isinstance(solid, TopoDS.TopoDS_Solid)
    exporter.add_shape(solid)
    exporter.write_file()
    initial_timestamp = os.path.getmtime(filename)
    assert os.path.isfile(filename)

    # read the written box.stp
    importer = StepImporter(filename)
    topo_compound = Topo(importer.compound)
    assert topo_compound.number_of_faces() == 6
    assert len([i for i in topo_compound.faces()]) == 6
    assert topo_compound.number_of_edges() == 12

    # add a sphere and write again with same exporter
    sphere = BRepPrimAPI.BRepPrimAPI_MakeSphere(10)
    exporter.add_shape(sphere.Shape())
    exporter.write_file()  # this creates a file with a box and a sphere
    intermediate_timestamp = os.path.getmtime(filename)
    assert intermediate_timestamp >= initial_timestamp

    # check that the file contains the box and the sphere
    importer = StepImporter(filename)
    assert len([i for i in Topo(importer.compound).faces()]) == 7  # 6 from box + 1 from sphere
    assert len([i for i in Topo(importer.compound).solids()]) == 2

    # create a new exporter and overwrite with a box only
    filename = path_from_file(__file__, "./models_out/box.stp")
    exporter = StepExporter(filename)
    solid = shape_to_topology(box_shape)
    exporter.add_shape(solid)
    exporter.write_file()
    assert os.path.isfile(filename)
    last_timestamp = os.path.getmtime(filename)
    assert last_timestamp >= intermediate_timestamp

    # check the file only contains a box
    importer = StepImporter(filename)
    assert len([i for i in Topo(importer.compound).faces()]) == 6  # 6 from box
    assert len([i for i in Topo(importer.compound).solids()]) == 1
Пример #9
0
#!/usr/bin/env python
# coding: utf-8

r"""Exporting multiple shapes to STEP"""

import logging

from OCC import BRepPrimAPI

from OCCDataExchange.step import StepExporter
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
box_shape = BRepPrimAPI.BRepPrimAPI_MakeBox(50, 50, 50).Shape()
sphere_shape = BRepPrimAPI.BRepPrimAPI_MakeSphere(20).Shape()

# Export to STEP
filename = path_from_file(__file__, "./models_out/result_export_multi.stp")
step_exporter = StepExporter(filename)
step_exporter.add_shape(box_shape)
step_exporter.add_shape(sphere_shape)
step_exporter.write_file()
Пример #10
0
def test_step_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.stp")
    exporter = StepExporter(filename)
    with pytest.raises(ValueError):
        exporter.add_shape(gp.gp_Pnt(1, 1, 1))
Пример #11
0
def test_step_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.stp")
    exporter = StepExporter(filename)
    with pytest.raises(ValueError):
        exporter.add_shape(gp.gp_Pnt(1, 1, 1))
Пример #12
0
#!/usr/bin/env python
# coding: utf-8

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

import logging

from OCC import BRepPrimAPI

from OCCDataExchange.step import StepExporter
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
box_shape = BRepPrimAPI.BRepPrimAPI_MakeBox(50, 50, 50).Shape()

# Export to STEP
filename = path_from_file(__file__, "./models_out/result_export_single.stp")
step_exporter = StepExporter(filename)
step_exporter.add_shape(box_shape)
step_exporter.write_file()
Пример #13
0
#!/usr/bin/env python
# coding: utf-8
r"""Exporting multiple shapes to STEP"""

import logging

from OCC import BRepPrimAPI

from OCCDataExchange.step import StepExporter
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
box_shape = BRepPrimAPI.BRepPrimAPI_MakeBox(50, 50, 50).Shape()
sphere_shape = BRepPrimAPI.BRepPrimAPI_MakeSphere(20).Shape()

# Export to STEP
filename = path_from_file(__file__, "./models_out/result_export_multi.stp")
step_exporter = StepExporter(filename)
step_exporter.add_shape(box_shape)
step_exporter.add_shape(sphere_shape)
step_exporter.write_file()
Пример #14
0
#!/usr/bin/env python
# coding: utf-8
r"""Exporting a single shape to STL"""

import logging

from OCC import BRepPrimAPI

from OCCDataExchange.step import StepExporter
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
box_shape = BRepPrimAPI.BRepPrimAPI_MakeBox(50, 50, 50).Shape()

# Export to STEP
filename = path_from_file(__file__, "./models_out/result_export_single.stp")
step_exporter = StepExporter(filename)
step_exporter.add_shape(box_shape)
step_exporter.write_file()