Example #1
0
def test_stl_importer_2_boxes():
    r"""Import an iges file containing 2 distinct boxes and test topology

    Notes
    -----
    This shows the current limitations of the IgesImporter as 2 boxes cannot be distinguished from one another

    """
    # binary STL
    importer = StlImporter(path_from_file(__file__, "./models_in/2_boxes_binary.stl"))

    topo = Topo(importer.shape)
    assert len([i for i in topo.shells()]) == 2
    assert next(topo.shells()).Closed() is True
    assert [i for i in topo.shells()][1].Closed() is True
    assert topo.number_of_faces() == 108 * 2
    assert topo.number_of_edges() == 162 * 2

    # ascii STL
    importer = StlImporter(path_from_file(__file__, "./models_in/2_boxes_ascii.stl"))

    topo = Topo(importer.shape)
    assert len([i for i in topo.shells()]) == 2
    assert next(topo.shells()).Closed() is True
    assert [i for i in topo.shells()][1].Closed() is True
    assert topo.number_of_faces() == 108 * 2
    assert topo.number_of_edges() == 162 * 2
Example #2
0
def test_stl_importer_2_boxes():
    r"""Import an iges file containing 2 distinct boxes and test topology

    Notes
    -----
    This shows the current limitations of the IgesImporter as 2 boxes cannot be distinguished from one another

    """
    # binary STL
    importer = StlImporter(path_from_file(__file__, "./models_in/2_boxes_binary.stl"))

    topo = Topo(importer.shape)
    assert len([i for i in topo.shells()]) == 2
    assert topo.shells().next().Closed() is True
    assert [i for i in topo.shells()][1].Closed() is True
    assert topo.number_of_faces() == 108 * 2
    assert topo.number_of_edges() == 162 * 2

    # ascii STL
    importer = StlImporter(path_from_file(__file__, "./models_in/2_boxes_ascii.stl"))

    topo = Topo(importer.shape)
    assert len([i for i in topo.shells()]) == 2
    assert topo.shells().next().Closed() is True
    assert [i for i in topo.shells()][1].Closed() is True
    assert topo.number_of_faces() == 108 * 2
    assert topo.number_of_edges() == 162 * 2
Example #3
0
def test_check_overwrite():
    r"""check_overwrite() tests"""
    # file exists
    assert check_overwrite(path_from_file(__file__,
                                          "./models_in/box.igs")) is True

    # file does not exist
    assert check_overwrite(path_from_file(__file__,
                                          "./models_in/bo_.igs")) is False
Example #4
0
def test_check_overwrite():
    r"""check_overwrite() tests"""
    # file exists
    assert check_overwrite(
        path_from_file(__file__, "./models_in/box.igs")) is True

    # file does not exist
    assert check_overwrite(
        path_from_file(__file__, "./models_in/bo_.igs")) is False
Example #5
0
def test_iges_importer_happy_topology():
    r"""import iges file containing a box and test topology"""
    importer = IgesImporter(path_from_file(__file__, "./models_in/box.igs"))

    topo = Topo(importer.compound)
    assert topo.number_of_faces() == 6
    assert topo.number_of_edges() == 24  # 12 edges * 2 possible orientations ?
Example #6
0
def test_iges_importer_happy_path():
    r"""happy path"""
    importer = IgesImporter(path_from_file(__file__, "./models_in/aube_pleine.iges"))
    assert isinstance(importer.compound, TopoDS.TopoDS_Compound)
    assert isinstance(importer.shapes, list)
    for shape in importer.shapes:
        assert isinstance(shape, TopoDS.TopoDS_Shape)
Example #7
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)
Example #8
0
def test_iges_exporter_happy_path(box_shape):
    r"""Happy path"""
    filename = path_from_file(__file__, "./models_out/box.IgS")
    exporter = IgesExporter(filename)
    exporter.add_shape(box_shape)
    exporter.write_file()
    assert os.path.isfile(filename)
Example #9
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)
Example #10
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)
Example #11
0
def test_iges_exporter_happy_path_shape_subclass(box_shape):
    r"""Happy path with a subclass of TopoDS_Shape"""
    filename = path_from_file(__file__, "./models_out/box.igs")
    exporter = IgesExporter(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)
Example #12
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
Example #13
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
Example #14
0
def test_step_importer_2_boxes():
    r"""Import an step file containing 2 distinct boxes and test topology"""
    importer = StepImporter(path_from_file(__file__, "./models_in/2_boxes_203.stp"))
    assert len(importer.shapes) == 1
    assert importer.shapes[0].ShapeType() == TopAbs.TopAbs_COMPOUND

    topo = Topo(importer.shapes[0])
    assert topo.number_of_compounds() == 1
    assert topo.number_of_comp_solids() == 0
    assert topo.number_of_solids() == 2
    assert topo.number_of_shells() == 2
Example #15
0
def test_stl_importer_happy_topology():
    r"""import iges file containing a box and test topology"""

    # binary STL
    importer = StlImporter(path_from_file(__file__, "./models_in/box_binary.stl"))
    topo = Topo(importer.shape)
    # assert len(topo.solids()) == 1
    assert len([i for i in topo.shells()]) == 1
    assert next(topo.shells()).Closed() is True  # direct method on TopoDS_Shell
    assert len([i for i in topo.faces()]) == 108
    assert len([i for i in topo.edges()]) == 162

    # ascii STL
    importer = StlImporter(path_from_file(__file__, "./models_in/box_ascii.stl"))
    topo = Topo(importer.shape)
    # assert len(topo.solids) == 1
    assert len([i for i in topo.shells()]) == 1
    assert next(topo.shells()).Closed() is True
    assert len([i for i in topo.faces()]) == 108
    assert len([i for i in topo.edges()]) == 162
Example #16
0
def test_stl_importer_happy_topology():
    r"""import iges file containing a box and test topology"""

    # binary STL
    importer = StlImporter(path_from_file(__file__, "./models_in/box_binary.stl"))
    topo = Topo(importer.shape)
    # assert len(topo.solids()) == 1
    assert len([i for i in topo.shells()]) == 1
    assert topo.shells().next().Closed() is True  # direct method on TopoDS_Shell
    assert len([i for i in topo.faces()]) == 108
    assert len([i for i in topo.edges()]) == 162

    # ascii STL
    importer = StlImporter(path_from_file(__file__, "./models_in/box_ascii.stl"))
    topo = Topo(importer.shape)
    # assert len(topo.solids) == 1
    assert len([i for i in topo.shells()]) == 1
    assert topo.shells().next().Closed() is True
    assert len([i for i in topo.faces()]) == 108
    assert len([i for i in topo.edges()]) == 162
Example #17
0
def test_iges_importer_2_boxes():
    r"""Import an iges file containing 2 distinct boxes and test topology

    Notes
    -----
    This shows the current limitations of the IgesImporter as 2 boxes cannot be distinguished from one another

    """
    importer = IgesImporter(path_from_file(__file__, "./models_in/2_boxes.igs"))
    topo = Topo(importer.compound)
    assert topo.number_of_faces() == 6 * 2
    assert topo.number_of_edges() == 24 * 2
Example #18
0
def test_step_importer_happy_topology():
    r"""import step file containing a box and test topology"""
    importer = StepImporter(path_from_file(__file__, "./models_in/box_203.stp"))
    assert len(importer.shapes) == 1

    assert isinstance(importer.shapes[0], TopoDS.TopoDS_Shape)
    assert importer.shapes[0].ShapeType() == TopAbs.TopAbs_SOLID

    topo = Topo(importer.shapes[0])
    assert topo.number_of_compounds() == 0
    assert topo.number_of_comp_solids() == 0
    assert topo.number_of_solids() == 1
    assert topo.number_of_shells() == 1
Example #19
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
Example #20
0
def test_iges_exporter_overwrite(box_shape):
    r"""Happy path with a subclass of TopoDS_Shape"""
    filename = path_from_file(__file__, "./models_out/box.igs")
    exporter = IgesExporter(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)

    # read the written box.igs
    importer = IgesImporter(filename)
    topo_compound = Topo(importer.compound)
    assert topo_compound.number_of_faces() == 6
    assert topo_compound.number_of_edges() == 24

    # 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

    # check that the file contains the box and the sphere
    importer = IgesImporter(filename)
    topo_compound = Topo(importer.compound)
    assert topo_compound.number_of_faces() == 7  # 6 from box + 1 from sphere

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

    # check the file only contains a box
    importer = IgesImporter(filename)
    topo_compound = Topo(importer.compound)
    assert topo_compound.number_of_faces() == 6  # 6 from box
Example #21
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
Example #22
0
def test_stl_importer_happy_path():
    r"""happy path"""
    importer = StlImporter(path_from_file(__file__, "./models_in/box_binary.stl"))
    assert isinstance(importer.shape, TopoDS.TopoDS_Shape)
Example #23
0
def test_step_importer_wrong_file_content():
    r"""wrong file content"""
    with pytest.raises(ValueError):
        StepImporter(path_from_file(__file__, "./models_in/empty.stp"))
Example #24
0
def test_stl_importer_wrong_extension():
    r"""wrong file format (i.e. trying to read a step file with iges importer)"""
    with pytest.raises(AssertionError):
        StlImporter(path_from_file(__file__, "./models_in/aube_pleine.stp"))
from __future__ import print_function

import logging
from OCC.Display import SimpleGui
from OCCUtils.Topology import Topo
from OCCDataExchange.iges import IgesImporter
from OCCDataExchange.utils import path_from_file

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

display, start_display, add_menu, add_function_to_menu = SimpleGui.init_display()

# my_iges_importer = occaddons.dataexchange.iges.IgesImporter("../../data/IGES/splines.igs")
filename = path_from_file(__file__, "./models_in/iges/aube_pleine.iges")
iges_importer = IgesImporter(filename)

print(iges_importer.nb_shapes)  # 13
print(len(iges_importer.shapes))  # 13

the_compound = iges_importer.compound
# display.DisplayShape(the_compound)

# there are no shells or solids in the compound (IGES specific)
for fc in Topo(iges_importer.compound).faces():
    display.DisplayShape(fc)

display.FitAll()
display.View_Iso()
start_display()
Example #26
0
def test_check_importer_filename_inexistent_file():
    r"""Inexistent file test for check_importer_filename()"""
    with pytest.raises(AssertionError):
        check_importer_filename(
            path_from_file(__file__, "./models_out/dummy.igs"))
Example #27
0
def test_iges_exporter_wrong_filename(box_shape):
    r"""Trying to write to a non-existent directory"""
    filename = path_from_file(__file__, "./nonexistent/box.igs")
    with pytest.raises(AssertionError):
        IgesExporter(filename)
Example #28
0
def test_iges_exporter_wrong_format(box_shape):
    r"""Format is not 5.1 or 5.3"""
    filename = path_from_file(__file__, "./models_out/box.igs")
    with pytest.raises(ValueError):
        IgesExporter(filename, format="48.3")
Example #29
0
def test_step_exporter_wrong_extension(box_shape):
    r"""Trying to write a step file with the IgesExporter"""
    filename = path_from_file(__file__, "./models_out/box.igs")
    with pytest.raises(AssertionError):
        StepExporter(filename)
Example #30
0
def test_step_exporter_wrong_schema(box_shape):
    r"""Schema is not AP203 or AP214CD"""
    filename = path_from_file(__file__, "./models_out/box.stp")
    with pytest.raises(AssertionError):
        StepExporter(filename, schema="48.3")
Example #31
0
def test_check_exporter_filename_happy_path():
    r"""Happy path for check_exporter_filename()"""
    check_exporter_filename(
        path_from_file(__file__, "./models_out/box.igs"))
Example #32
0
def test_read_dat_file():
    r"""Test reading a foil section definition dat file"""
    importer = DatImporter(path_from_file(__file__, "./models_in/naca0006.dat"),
                                               skip_first_line=True)
    pts = importer.points
    assert len(pts) == 35
Example #33
0
def test_step_exporter_wrong_schema(box_shape):
    r"""Schema is not AP203 or AP214CD"""
    filename = path_from_file(__file__, "./models_out/box.stp")
    with pytest.raises(AssertionError):
        StepExporter(filename, schema="48.3")
Example #34
0
#!/usr/bin/env python
# coding: utf-8
r"""Exporting a single shape to BREP"""

import logging

from OCC import BRepPrimAPI

from OCCDataExchange.brep import BrepExporter
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 BREP
filename = path_from_file(__file__, "./models_out/box.brep")
step_exporter = BrepExporter(filename)
step_exporter.set_shape(box_shape)
step_exporter.write_file()
from OCC.Display import SimpleGui
from OCCUtils.Topology import Topo

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

logging.basicConfig(
    level=logging.DEBUG,
    format=
    '%(asctime)s :: %(levelname)6s :: %(module)20s :: %(lineno)3d :: %(message)s'
)
display, start_display, add_menu, add_function_to_menu = SimpleGui.init_display(
)

# my_iges_importer = occaddons.dataexchange.iges.IgesImporter("../../data/IGES/splines.igs")
filename = path_from_file(__file__, "./models_in/iges/2_boxes.igs")
iges_importer = IgesImporter(filename)

the_shapes = iges_importer.shapes

print(iges_importer.nb_shapes)  # 13
print(len(iges_importer.shapes))  # 13

# display.DisplayShape(iges_importer.compound)

# there are no shells or solids in the compound (IGES specific)

for fc in Topo(iges_importer.compound).faces():
    display.DisplayShape(fc)

display.FitAll()
Example #36
0
def test_check_exporter_filename_wrong_extension():
    r"""Wrong extension test for check_exporter_filename()"""
    with pytest.raises(AssertionError):
        check_exporter_filename(
            path_from_file(__file__, "./models_out/box.igs"), ["step"])
Example #37
0
import logging

from OCC.Display import SimpleGui
from OCCUtils.Topology import Topo

from OCCDataExchange.brep import BrepImporter
from OCCDataExchange.utils import path_from_file

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

# open/parse BREP file and get the resulting TopoDS_Shape instance
filename = path_from_file(__file__, "./models_in/brep/carter.brep")
my_brep_importer = BrepImporter(filename)
the_shape = my_brep_importer.shape

# Then display the shape
display, start_display, add_menu, add_function_to_menu = SimpleGui.init_display(
)
# display.DisplayShape(the_shape, color='BLUE', update=True)

# 1 solid to display

for s in Topo(the_shape).solids():
    display.DisplayShape(s)

# faces
# OCCUtils.display.topology.faces(display, the_shape, show_numbers=False)  # super slow !!
from OCCDataExchange.step import StepImporter
from OCCDataExchange.utils import path_from_file

logging.basicConfig(
    level=logging.DEBUG,
    format=
    '%(asctime)s :: %(levelname)6s :: %(module)20s :: %(lineno)3d :: %(message)s'
)
display, start_display, add_menu, add_function_to_menu = SimpleGui.init_display(
)

# filename = OCCDataExchange.path_from_file(__file__, "./models_in/step/dm1-id-214.stp")
# filename = OCCDataExchange.path_from_file(__file__, "./models_in/step/APB_GC.stp")  # big file 50 Mb !
# filename = OCCDataExchange.path_from_file(__file__, "./models_in/step/66m.stp")
filename = path_from_file(__file__, "./models_in/step/ASA.STEP")
# filename = path_from_file(__file__, "./models_in/step/solar_charger_asm.stp")
# filename = OCCDataExchange.path_from_file(__file__, "./models_in/step/Groupama_VO70.stp")
step_importer = StepImporter(filename)

the_shapes = step_importer.shapes
print("Nb shapes : %i" % len(the_shapes))  # 4
# print("number_of_shapes(): %i" % step_importer.number_of_shapes)  # 0 ??

# display.DisplayColoredShape(the_shapes[0], Quantity.Quantity_Color(Quantity.Quantity_NOC_GRAY3))
for s in Topo(the_shapes[0]).solids():
    display.DisplayShape(s)

display.FitAll()
display.View_Iso()
start_display()
Example #39
0
def test_check_exporter_filename_inexistent_directory():
    r"""Inexistent directory test for check_exporter_filename()"""
    with pytest.raises(AssertionError):
        check_exporter_filename(path_from_file(__file__,
                                               "./inexistent-dir/dummy.igs"))
Example #40
0
def test_iges_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):
        IgesExporter(filename)
#!/usr/bin/env python
# coding: utf-8
r"""Exporting multiple shapes to IGES"""

import logging

from OCC import BRepPrimAPI

from OCCDataExchange.iges import IgesExporter
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 IGES
filename = path_from_file(__file__, "./models_out/result_export_multi.iges")
my_iges_exporter = IgesExporter(filename, format="5.3")
my_iges_exporter.add_shape(box_shape)
my_iges_exporter.add_shape(sphere_shape)
my_iges_exporter.write_file()
Example #42
0
def test_iges_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.igs")
    exporter = IgesExporter(filename)
    with pytest.raises(ValueError):
        exporter.add_shape(gp.gp_Pnt(1, 1, 1))
Example #43
0
def test_check_exporter_filename_happy_path():
    r"""Happy path for check_exporter_filename()"""
    check_exporter_filename(path_from_file(__file__, "./models_out/box.igs"))
Example #44
0
def test_check_exporter_filename_inexistent_directory():
    r"""Inexistent directory test for check_exporter_filename()"""
    with pytest.raises(AssertionError):
        check_exporter_filename(
            path_from_file(__file__, "./inexistent-dir/dummy.igs"))
from __future__ import print_function

import logging

from OCC.Display import SimpleGui
from OCCUtils.Topology import Topo

from OCCDataExchange.step import StepImporter
from OCCDataExchange.utils import path_from_file

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

display, start_display, add_menu, add_function_to_menu = SimpleGui.init_display()

filename = path_from_file(__file__, "./models_in/step/aube_pleine.stp")
step_importer = StepImporter(filename)

# step_importer.read_file() -> automatic read_file !!

print("Nb shapes: %i" % len(step_importer.shapes))
for shape in step_importer.shapes:
    print(shape.ShapeType())  # 2 -> solid
# print("number_of_shapes: %i" % step_importer.number_of_shapes)  # 0 ??
# display.DisplayShape(step_importer.shapes)
for s in Topo(step_importer.shapes[0]).solids():
    display.DisplayShape(s, transparency=0.8)

for e in Topo(step_importer.shapes[0]).edges():
    display.DisplayShape(e)
Example #46
0
def test_step_importer_wrong_extension():
    r"""wrong file format (i.e. trying to read a iges file with step importer)"""
    with pytest.raises(AssertionError):
        filename = path_from_file(__file__, "./models_in/aube_pleine.iges")
        StepImporter(filename)
Example #47
0
def test_stl_importer_wrong_extension():
    r"""wrong file format (i.e. trying to read a step file with iges importer)"""
    with pytest.raises(AssertionError):
        StlImporter(path_from_file(__file__, "./models_in/aube_pleine.stp"))
Example #48
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))
Example #49
0
def test_stl_importer_happy_path():
    r"""happy path"""
    importer = StlImporter(path_from_file(__file__, "./models_in/box_binary.stl"))
    assert isinstance(importer.shape, TopoDS.TopoDS_Shape)
Example #50
0
def test_check_importer_filename_inexistent_file():
    r"""Inexistent file test for check_importer_filename()"""
    with pytest.raises(AssertionError):
        check_importer_filename(path_from_file(__file__, "./models_out/dummy.igs"))
Example #51
0
def test_iges_importer_wrong_file_content():
    r"""wrong file content"""
    with pytest.raises(ValueError):
        IgesImporter(path_from_file(__file__, "./models_in/empty.igs"))
Example #52
0
def test_check_exporter_filename_wrong_extension():
    r"""Wrong extension test for check_exporter_filename()"""
    with pytest.raises(AssertionError):
        check_exporter_filename(
            path_from_file(__file__, "./models_out/box.igs"),
            ["step"])
Example #53
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()
Example #54
0
def test_step_exporter_wrong_filename(box_shape):
    r"""Trying to write to a non-existent directory"""
    filename = path_from_file(__file__, "./nonexistent/box.stp")
    with pytest.raises(AssertionError):
        StepExporter(filename)
Example #55
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()