コード例 #1
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
コード例 #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
コード例 #3
0
ファイル: DoubleBall.py プロジェクト: tnakaicode/GeomSurf
 def get_face(self, sol):
     top_api = Topo(sol)
     print(top_api.number_of_faces())
     for face in top_api.faces():
         sol_face = face
     return sol_face
コード例 #4
0
step_writer = STEPControl_Writer()
step_writer.Transfer(domain, STEPControl_AsIs)

stpfile = "foil.stp"

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]] = []
コード例 #5
0
    obj = plotocc(view=False)

    face1 = read_step_file("./stp_surf/gen_surf_001.stp")
    axis1 = gp_Ax3(gp_Pnt(0, 0, 1), gp_Dir(0, 0, 1))
    face1.Location(set_loc(gp_Ax3(), axis1))

    face2 = read_step_file("./stp_surf/gen_surf_030.stp")
    axis2 = gp_Ax3(gp_Pnt(0, 0, 2), gp_Dir(0, 0, 1))
    face2.Location(set_loc(gp_Ax3(), axis2))

    axs = gp_Ax3()
    ax1 = gp_Ax3(gp_Pnt(0, 0, -10), axs.Direction())
    vec = gp_Vec(gp_Pnt(0, 0, -10), gp_Pnt(0, 0, 10))
    face = obj.make_EllipWire(rxy=[50.0, 50.0], axs=ax1, skin=0)
    body = BRepPrimAPI_MakePrism(face, vec).Shape()

    lens = make_lens(body, face1, face2)
    obj.create_tempdir(flag=-1)

    wire1 = obj.make_PolyWire(radi=50, num=6, axs=axis1)
    proj = BRepProj_Projection(wire1, face1, axis1.Direction())
    proj_wire = proj.Current()
    top = Topo(face1)
    for faces in top.faces():
        face1_1 = faces
        print(faces)

    api = BRepBuilderAPI_MakeFace(face1_1)
    api.Add(proj_wire)
    obj.export_stp(api.Face())
コード例 #6
0
ファイル: Ellipsoid.py プロジェクト: tnakaicode/GeomSurf
    # obj.show_ball()

    axs = gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(1, 1, 1))
    elp = gen_ellipsoid(axs, [10, 20, 30])
    obj.display.DisplayShape(elp, transparency=0.7, color="BLUE")
    obj.show_axs_pln(axs, scale=20)

    axs = gp_Ax3(gp_Pnt(30, 0, 0), gp_Dir(1, 1, 0))
    elp = gen_ellipsoid(axs, [10, 20, 30])
    obj.display.DisplayShape(elp, transparency=0.7, color="BLUE")
    obj.show_axs_pln(axs, scale=20)

    #elp = gen_ellipsoid_geom(axs, [10, 20, 30])

    top_api = Topo(elp)
    print(top_api.number_of_faces())
    for face in top_api.faces():
        elp_face = face

    print(elp_face)
    elp_surf = BRep_Tool_Surface(elp_face)
    print(elp_surf)

    lin = Geom_Line(gp_Ax1(axs.Location(), gp_Dir(0, 1, 1)))
    api = GeomAPI_IntCS(lin, elp_surf)
    obj.display.DisplayShape(lin)
    print(api.Point(1))
    print(api.Point(2))

    obj.show()