示例#1
0
def read_surface(types=['stl/off','stl','off','neu','smesh','gts'],show=True):
    """Read STL model from file fn.

    If no file is given, one is asked.
    The file fn should exist and contain a valid STL model.
    The STL model is stored in the Formex F.
    The workdir and project name are set from the filename.
    The Formex is stored under the project basename.
    The model is displayed.
    """
    if type(types) == str:
        types = [ types ]
    types = map(utils.fileDescription,types)
    fn = askFilename(GD.cfg['workdir'],types,exist=True)
    if fn:
        chdir(fn)
        set_project(utils.projectName(fn))
        GD.message("Reading file %s" % fn)
        GD.gui.setBusy()
        t = timer.Timer()
        nodes,elems =stl.readSurface(fn)
        GD.message("Time to import stl: %s seconds" % t.seconds())
        GD.gui.setBusy(False)
        set_surface(nodes,elems)
        if show:
            show_surface(view='front')
        if ack('Convert to Formex?'):
            name = toFormex()
            # This is convenient for the user
            if name:
                formex_menu.setSelection(name)
                #formex_menu.drawSelection()
    return fn
示例#2
0
def read_surface(fn='',types=['stl/off','stl','off','neu','smesh','gts'],convert=None,show=True):
    """Read STL model from file fn.

    If no file is given, one is asked.
    The file fn should exist and contain a valid surface model.
    
    The STL model is stored in the Formex F.
    The workdir and project name are set from the filename.
    The Formex is stored under the project basename.
    The model is displayed.

    If convert == True, the model is converted to a Formex.
    If convert == False, it will not be converted.
    The default is to ask the user.
    """
    if not (fn and os.path.exists(fn)):
        if type(types) == str:
            types = [ types ]
        types = map(utils.fileDescription,types)
        fn = askFilename(GD.cfg['workdir'],types,exist=True)
    if fn:
        chdir(fn)
        set_project(utils.projectName(fn))
        GD.message("Reading file %s" % fn)
        GD.gui.setBusy()
        t = timer.Timer()
        nodes,elems =stl.readSurface(fn)
        GD.message("Time to import surface: %s seconds" % t.seconds())
        GD.gui.setBusy(False)
        set_surface(nodes,elems)
        if show:
            show_surface(view='front')
        if convert is None:
            convert = ack('Convert to Formex?')
        if convert:
            GD.debug("GOING")
            name = toFormex(PF.get('project',''))
            # This is convenient for the user
            if name:
                formex_menu.setSelection(name)
                if show:
                    formex_menu.drawSelection()
        else:
            pass
        
    return fn