Example #1
0
def saveImage(multi=False):
    """Save an image to file.

    This will show the Save Image dialog, with the multisave mode checked if
    multi = True. Then, depending on the user's selection, it will either:
     - save the current Canvas/Window to file
     - start the multisave/autosave mode
     - do nothing
    """
    pat = map(utils.fileDescription, ['img','icon','all'])
    dia = widgets.SaveImageDialog(pf.cfg['workdir'],pat,multi=multi)
    opt = dia.getResult()
    if opt:
        if opt.fm == 'From Extension':
            if utils.fileTypeFromExt(opt.fn) == '':
                opt.fn += '.png'
            opt.fm = None
        if opt.qu < 0:
            opt.qu = -1
        updateSettings({'workdir':os.path.dirname(opt.fn)},save=True)
        image.save(filename=opt.fn,
                   format=opt.fm,
                   quality=opt.qu,
                   size=opt.sz,
                   window=opt.wi,
                   multi=opt.mu,
                   hotkey=opt.hk,
                   autosave=opt.au,
                   border=opt.bo,
                   rootcrop=opt.rc
                   )
Example #2
0
def saveImage(multi=False):
    """Save an image to file.

    This will show the Save Image dialog, with the multisave mode checked if
    multi = True. Then, depending on the user's selection, it will either:
     - save the current Canvas/Window to file
     - start the multisave/autosave mode
     - do nothing
    """
    pat = map(utils.fileDescription, ['img', 'icon', 'all'])
    dia = widgets.SaveImageDialog(pf.cfg['workdir'], pat, multi=multi)
    opt = dia.getResult()
    if opt:
        if opt.fm == 'From Extension':
            if utils.fileTypeFromExt(opt.fn) == '':
                opt.fn += '.png'
            opt.fm = None
        if opt.qu < 0:
            opt.qu = -1
        updateSettings({'workdir': os.path.dirname(opt.fn)}, save=True)
        image.save(filename=opt.fn,
                   format=opt.fm,
                   quality=opt.qu,
                   size=opt.sz,
                   window=opt.wi,
                   multi=opt.mu,
                   hotkey=opt.hk,
                   autosave=opt.au,
                   border=opt.bo,
                   rootcrop=opt.rc)
Example #3
0
def readGeometry(filename, filetype=None):
    """Read geometry from a stored file.

    This is a wrapper function over several other functions specialized
    for some file type. Some file types require the existence of more
    than one file, may need to write intermediate files, or may call
    external programs.

    The return value is a dictionary with named geometry objects read from
    the file.

    If no filetype is given, it is derived from the filename extension.
    Currently the following file types can be handled.

    'pgf': pyFormex Geometry File. This is the native pyFormex geometry
        file format. It can store multiple parts of different type, together
        with their name.
    'surface': a global filetype for any of the following surface formats:
        'stl', 'gts', 'off', 'neu'
    'inp': Abaqus and CalculiX input format
    'tetgen':
    """
    pf.GUI.setBusy(True)
    res = {}
    if filetype is None:
        filetype = utils.fileTypeFromExt(filename)

    print("Reading file of type %s" % filetype)

    if filetype == 'pgf' or filetype == 'pgf.gz':
        res = GeometryFile(filename).read()

    elif filetype in ['surface', 'stl', 'off', 'gts', 'neu']:
        surf = TriSurface.read(filename)
        name = autoName(TriSurface).next()
        res = {name: surf}

    elif filetype == 'inp':
        parts = fileread.readInpFile(filename)
        res = {}
        color_by_part = len(parts.keys()) > 1
        j = 0
        for name, part in parts.items():
            for i, mesh in enumerate(part.meshes()):
                p = j if color_by_part else i
                print("Color %s" % p)
                res["%s-%s" % (name, i)] = mesh.setProp(p)
            j += 1

    elif filetype in tetgen.filetypes:
        res = tetgen.readTetgen(filename)

    else:
        error("Can not import from file %s of type %s" % (filename, filetype))
    pf.GUI.setBusy(False)

    return res
def writeGeometry(obj,filename,filetype=None,shortlines=False):
    """Write the geometry items in objdict to the specified file.

    """
    if filetype is None:
        filetype = utils.fileTypeFromExt(filename)
        
    print "Writing file of type %s" % filetype

    if filetype in [ 'pgf', 'pyf' ]:
        # Can write anything
        if filetype == 'pgf':
            res = writeGeomFile(filename,obj,shortlines=shortlines)

    else:
        error("Don't know how to export in '%s' format" % filetype)
        
    return res
Example #5
0
def writeGeometry(obj, filename, filetype=None, sep=' ', shortlines=False):
    """Write the geometry items in objdict to the specified file.

    """
    if filetype is None:
        filetype = utils.fileTypeFromExt(filename)

    print("Writing file of type %s" % filetype)

    if filetype in ['pgf', 'pgf.gz', 'pyf']:
        # Can write anything
        if filetype in ['pgf', 'pgf.gz']:
            res = writeGeomFile(filename, obj, sep=sep, shortlines=shortlines)

    else:
        error("Don't know how to export in '%s' format" % filetype)

    return res
def readGeometry(filename,filetype=None):
    """Read geometry from a stored file.

    This is a wrapper function over several other functions specialized
    for some file type. Some file types require the existence of more
    than one file, may need to write intermediate files, or may call
    external programs.
    
    The return value is a dictionary with named geometry objects read from
    the file.

    If no filetype is given, it is derived from the filename extension.
    Currently the following file types can be handled. 

    'pgf': pyFormex Geometry File. This is the native pyFormex geometry
        file format. It can store multiple parts of different type, together
        with their name.
    'surface': a global filetype for any of the following surface formats:
        'stl', 'gts', 'off',
    'stl': 
    """
    res = {}
    if filetype is None:
        filetype = utils.fileTypeFromExt(filename)
        
    print "Reading file of type %s" % filetype

    if filetype == 'pgf':
        res = GeometryFile(filename).read()

    elif filetype in ['surface','stl','off','gts','smesh','neu']:
        surf = TriSurface.read(filename)
        res = {autoName(TriSurface).next():surf}

    else:
        error("Can not import from file %s of type %s" % (filename,filetype))
        
    return res