예제 #1
0
def stlConvert(stlname,outname=None,options='-d'):
    """Transform an .stl file to .off or .gts format.

    If outname is given, it is either '.off' or '.gts' or a filename ending
    on one of these extensions. If it is only an extension, the stlname will
    be used with extension changed.

    If the outname file exists and its mtime is more recent than the stlname,
    the outname file is considered uptodate and the conversion programwill
    not be run.
    
    The conversion program will be choosen depending on the extension.
    This uses the external commands 'admesh' or 'stl2gts'.

    The return value is a tuple of the output file name, the conversion
    program exit code (0 if succesful) and the stdout of the conversion
    program (or a 'file is already uptodate' message).
    """
    if not outname:
        outname = GD.cfg.get('surface/stlread','.off')
    if outname.startswith('.'):
        outname = changeExt(stlname,outname)
    if os.path.exists(outname) and mtime(stlname) < mtime(outname):
        return outname,0,"File '%s' seems to be up to date" % outname
    
    if outname.endswith('.off'):
        cmd = "admesh %s --write-off '%s' '%s'" % (options,outname,stlname)
    elif outname.endswith('.gts'):
        cmd = "stl2gts < '%s' > '%s'" % (stlname,outname)
    else:
        return outname,1,"Can not convert file '%s' to '%s'" % (stlname,outname)
       
    sta,out = runCommand(cmd)
    return outname,sta,out
예제 #2
0
    def PopulateList(self):
        self.list = wxListCtrl(self, wxNewId(), style=wxLC_REPORT)
        i = 0
        for t in (("Name", wxLIST_FORMAT_LEFT),
                  ("Size", wxLIST_FORMAT_RIGHT),
                  ("Size on disk", wxLIST_FORMAT_RIGHT),
                  ("Permissions", wxLIST_FORMAT_LEFT),
                  ("User", wxLIST_FORMAT_LEFT),
                  ("Group", wxLIST_FORMAT_LEFT),
                  ("Modification time", wxLIST_FORMAT_LEFT)):
            n, f = t
            self.list.InsertColumn(i, n, f)
            #self.list.SetColumnWidth(i, wxLIST_AUTOSIZE)
            i = i + 1

        for i in range(len(self.items)):
            path = self.items[i]
            name = os.path.basename(path)

            size, diskSize = self.PathSizes(path)

            self.list.InsertStringItem(i, name)
            try:
                self.list.SetStringItem(i, 1, size)
                self.list.SetStringItem(i, 2, diskSize)
                self.list.SetStringItem(i, 3, PermsFromPath(path))
                self.list.SetStringItem(i, 4, UserFromPath(path))
                self.list.SetStringItem(i, 5, GroupFromPath(path))
                self.list.SetStringItem(i, 6, mtime(path))
            except OSError:
                pass
예제 #3
0
    def PopulateList(self):
        self.list = wxListCtrl(self, wxNewId(), style=wxLC_REPORT)
        i = 0
        for t in (("Name", wxLIST_FORMAT_LEFT), ("Size", wxLIST_FORMAT_RIGHT),
                  ("Size on disk", wxLIST_FORMAT_RIGHT), ("Permissions",
                                                          wxLIST_FORMAT_LEFT),
                  ("User", wxLIST_FORMAT_LEFT), ("Group", wxLIST_FORMAT_LEFT),
                  ("Modification time", wxLIST_FORMAT_LEFT)):
            n, f = t
            self.list.InsertColumn(i, n, f)
            #self.list.SetColumnWidth(i, wxLIST_AUTOSIZE)
            i = i + 1

        for i in range(len(self.items)):
            path = self.items[i]
            name = os.path.basename(path)

            size, diskSize = self.PathSizes(path)

            self.list.InsertStringItem(i, name)
            try:
                self.list.SetStringItem(i, 1, size)
                self.list.SetStringItem(i, 2, diskSize)
                self.list.SetStringItem(i, 3, PermsFromPath(path))
                self.list.SetStringItem(i, 4, UserFromPath(path))
                self.list.SetStringItem(i, 5, GroupFromPath(path))
                self.list.SetStringItem(i, 6, mtime(path))
            except OSError:
                pass
예제 #4
0
    def OnItemSelectedName(self, name):
        curPath = self.currentPath
        fullPath = os.path.join(curPath, name)
        if not os.path.exists(fullPath):
            self.Refresh()
            return

        #if os.path.isdir(fullPath): size = ""
        #else: size = "Size: " + str(os.path.getsize(fullPath))

        bytes, size, unit, selFiles = self.GetFileInfo()
        if unit: sizeStr = str(bytes) + " bytes (%.1f %s)" % (size, unit)
        else: sizeStr = str(bytes) + " bytes"

        statName = ""
        if len(selFiles) == 1:
            path = selFiles[0]
            statStr = "%s  %s %s " % (sizeStr, "[%s %s %s]" %
                                      PermsUserGroup(path), mtime(path))
            statName = name
        elif len(selFiles) > 1:
            statName = "%d items" % len(selFiles)
            statStr = sizeStr
        else:
            statStr = ""

        self.UpdateStatusBar(statName, statStr, 1)
예제 #5
0
    def OnItemSelectedName(self, name):
        curPath = self.currentPath
        fullPath = os.path.join(curPath, name)
        if not os.path.exists(fullPath):
            self.Refresh()
            return

        #if os.path.isdir(fullPath): size = ""
        #else: size = "Size: " + str(os.path.getsize(fullPath))

        bytes, size, unit, selFiles = self.GetFileInfo()
        if unit: sizeStr = str(bytes) + " bytes (%.1f %s)" % (size, unit)
        else: sizeStr = str(bytes) + " bytes"

        statName = ""
        if len(selFiles) == 1:
            path = selFiles[0]
            statStr = "%s  %s %s " %  (sizeStr, "[%s %s %s]" % PermsUserGroup(path), mtime(path))
            statName = name
        elif len(selFiles) > 1:
            statName = "%d items" % len(selFiles)
            statStr = sizeStr
        else: statStr = ""

        self.UpdateStatusBar(statName, statStr, 1)
예제 #6
0
def readSurface(fn,ftype=None):
    if ftype is None:
        ftype = os.path.splitext(fn)[1]  # deduce from extension
    ftype = ftype.strip('.').lower()
    if ftype == 'stl':
        ofn = changeExt(fn,'.gts')
        if (not os.path.exists(ofn)) or (mtime(ofn) < mtime(fn)):
            stl_to_gts(fn)
        nodes,edges,faces = read_gts(ofn)
        elems = expandEdges(edges,faces)
    elif ftype == 'off':
        nodes,elems = read_off(fn)
    elif ftype == 'neu':
        nodes,elems = read_gambit_neutral(fn)
    elif ftype == 'smesh':
        nodes,elems = tetgen.readSurface(fn)
    elif ftype == 'gts':
        nodes,edges,faces = read_gts(fn)
        elems = expandEdges(edges,faces)
    else:
        print "Cannot read file %s" % fn
    return nodes,elems
예제 #7
0
def modification_date(filename):
    t = utils.mtime(filename)
    return datetime.fromtimestamp(t).isoformat()