Esempio n. 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
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 4
0
step_writer.Write(stpfile)

topo = Topo(domain)
faces = topo.faces
iface = 0
print dir(faces)
N = float(topo.number_of_faces())
surfaces = [None for i in range(topo.number_of_faces())]
maxima = [-1 for i in range(topo.number_of_faces())]

for f in topo.faces():
    print str(100. * float(iface) / N) + ' % done'
    for f2 in d_faces:
        shp = BRepAlgoAPI_Section(f, d_faces[f2]).Shape()
        tp = Topo(shp)
        nedge = tp.number_of_edges()
        if (nedge > maxima[iface]):
            surfaces[iface] = f2
            maxima[iface] = nedge
    iface += 1

gmsh_dict = {}

for i in range(topo.number_of_faces()):
    if not gmsh_dict.has_key(surfaces[i]):
        gmsh_dict[surfaces[i]] = []
    gmsh_dict[surfaces[i]].append(i + 1)

print gmsh_dict
name = stpfile.replace('.stp', '')
fgeo = open(stpfile.replace('stp', 'geo'), 'w')