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
def read_tetgen(surface=True, volume=True): """Read a tetgen model from files fn.node, fn.ele, fn.smesh.""" ftype = '' if surface: ftype += ' *.smesh' if volume: ftype += ' *.ele' fn = askFilename(GD.cfg['workdir'],"Tetgen files (%s)" % ftype,exist=True) nodes = elems =surf = None if fn: chdir(fn) project = utils.projectName(fn) set_project(project) nodes,nodenrs = tetgen.readNodes(project+'.node') # print "Read %d nodes" % nodes.shape[0] if volume: elems,elemnrs,elemattr = tetgen.readElems(project+'.ele') print "Read %d tetraeders" % elems.shape[0] PF['volume'] = (nodes,elems) if surface: surf = tetgen.readSurface(project+'.smesh') print "Read %d triangles" % surf.shape[0] PF['surface'] = (nodes,surf) if surface: show_surface() else: show_volume()
def exportPGF(): """Export the current scene to PGF""" from plugins.webgl import WebGL types = utils.fileDescription(['pgf','all']) fn = draw.askNewFilename(pf.cfg['workdir'],types) if fn: pf.GUI.setBusy() pf.message("Exporting current scene to %s" % fn) fn = os.path.basename(fn) if not fn.endswith('.pgf'): fn += '.pgf' name = utils.projectName(fn) W = WebGL(name) W.addScene() res = W.exportPGF(fn,sep='') pf.message("Contents: %s" % res) pf.GUI.setBusy(False)
def exportPGF(): """Export the current scene to PGF""" from plugins.webgl import WebGL types = utils.fileDescription(['pgf', 'all']) fn = draw.askNewFilename(pf.cfg['workdir'], types) if fn: pf.GUI.setBusy() pf.message("Exporting current scene to %s" % fn) fn = os.path.basename(fn) if not fn.endswith('.pgf'): fn += '.pgf' name = utils.projectName(fn) W = WebGL(name) W.addScene() res = W.exportPGF(fn, sep='') pf.message("Contents: %s" % res) pf.GUI.setBusy(False)
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
def readHeader(self): """Read the header of a pyFormex geometry file. """ sep = ' ' s = self.fil.readline() if s.startswith('# Formex'): version = '1.1' elif s.startswith('# pyFormex Geometry File'): pos = s.rfind(')') exec(s[pos+1:].strip()) else: version = None raise RuntimeError,"This does not look like a pyFormex geometry file, or it is a very old version." self._version_ = version self.sep = sep self.objname = utils.NameSequence('%s_000' % utils.projectName(self.fil.name)) self.results = ODict()
def exportWebGL(): """Export the current scene to WebGL""" from plugins.webgl import WebGL types = [ utils.fileDescription('html') ] fn = draw.askNewFilename(pf.cfg['workdir'],types) if fn: pf.message("Exporting current scene to %s" % fn) pf.GUI.setBusy() fn = os.path.basename(fn) name = utils.projectName(fn) W = WebGL(name) W.addScene() fn = W.export(title="%s WebGL model"%name,createdby=50) pf.GUI.setBusy(False) if draw.ack("Show the scene in your browser?"): fn = os.path.join(os.getcwd(),fn) print(fn) from gui.helpMenu import help help('file:%s' % fn)
def exportWebGL(): """Export the current scene to WebGL""" from plugins.webgl import WebGL types = [utils.fileDescription('html')] fn = draw.askNewFilename(pf.cfg['workdir'], types) if fn: pf.message("Exporting current scene to %s" % fn) pf.GUI.setBusy() fn = os.path.basename(fn) name = utils.projectName(fn) W = WebGL(name) W.addScene() fn = W.export(title="%s WebGL model" % name, createdby=50) pf.GUI.setBusy(False) if draw.ack("Show the scene in your browser?"): fn = os.path.join(os.getcwd(), fn) print(fn) from gui.helpMenu import help help('file:%s' % fn)
def readHeader(self): """Read the header of a pyFormex geometry file. """ sep = ' ' s = self.fil.readline() if s.startswith('# Formex'): version = '1.1' elif s.startswith('# pyFormex Geometry File'): pos = s.rfind(')') exec(s[pos + 1:].strip()) else: version = None raise RuntimeError, "This does not look like a pyFormex geometry file, or it is a very old version." self._version_ = version self.sep = sep self.objname = utils.NameSequence('%s_000' % utils.projectName(self.fil.name)) self.results = ODict()
def charCurves(fontfile,character): l = charContours(fontfile,character) c = [ contourCurve(li) for li in l ] fontname = utils.projectName(fontfile) export({'%s-%s'%(fontname,character):c}) return c