def readSplines():
    """Read spline curves from a geometry file.

    The geometry file splines.pgf is provided with the pyFormex distribution.
    """
    from geomfile import GeometryFile
    fn = getcfg('datadir')+'/splines.pgf'
    f = GeometryFile(fn)
    obj = f.read()
    T = obj.values()
    print len(T)
    print [len(Si.coords) for Si in T]
Example #2
0
def readSplines():
    """Read spline curves from a geometry file.

    The geometry file splines.pgf is provided with the pyFormex distribution.
    """
    from geomfile import GeometryFile
    fn = getcfg('datadir')+'/splines.pgf'
    f = GeometryFile(fn)
    obj = f.read()
    T = obj.values()
    print(len(T))
    print([len(Si.coords) for Si in T])
    return T
    def write(self,fil,sep=' ',mode='w'):
        """Write a Geometry to a .pgf file.

        If fil is a string, a file with that name is opened. Else fil should
        be an open file.
        The Geometry is then written to that file in a native format, using
        sep as separator between the coordinates.
        If fil is a string, the file is closed prior to returning.
        """
        from geomfile import GeometryFile
        f = GeometryFile(fil,mode='w',sep=sep)
        f.write(self)
        if f.isname and mode[0]=='w':
            f.close()
Example #4
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
Example #5
0
def convertGeometryFile():
    """Convert pyFormex geometry file to latest format."""
    filter = utils.fileDescription(['pgf', 'all'])
    cur = pf.cfg['workdir']
    fn = askFilename(cur=cur, filter=filter)
    if fn:
        from geomfile import GeometryFile
        message("Converting geometry file %s to version %s" %
                (fn, GeometryFile._version_))
        GeometryFile(fn).rewrite()
Example #6
0
    def write(self,fil,sep=' ',mode='w'):
        """Write a Geometry to a .pgf file.

        If fil is a string, a file with that name is opened. Else fil should
        be an open file.
        The Geometry is then written to that file in a native format, using
        sep as separator between the coordinates.
        If fil is a string, the file is closed prior to returning.
        """
        from geomfile import GeometryFile
        f = GeometryFile(fil,mode='w',sep=sep)
        f.write(self)
        if f.isname and mode[0]=='w':
            f.close()