def initialize(): """Initialize the image module.""" global image_formats_qt, image_formats_qtr, image_formats_gl2ps, image_formats_fromeps, gl2ps, _producer, _gl2ps_types # Find interesting supporting software utils.hasExternal("ImageMagick") # Set some globals GD.debug("LOADING IMAGE FORMATS") image_formats_qt = map(str, QtGui.QImageWriter.supportedImageFormats()) image_formats_qtr = map(str, QtGui.QImageReader.supportedImageFormats()) if GD.cfg.get("imagesfromeps", False): GD.image_formats_qt = [] if utils.hasModule("gl2ps"): import gl2ps _producer = GD.Version + " (http://pyformex.berlios.de)" _gl2ps_types = {"ps": gl2ps.GL2PS_PS, "eps": gl2ps.GL2PS_EPS, "tex": gl2ps.GL2PS_TEX, "pdf": gl2ps.GL2PS_PDF} if utils.checkVersion("gl2ps", "1.03") >= 0: _gl2ps_types.update({"svg": gl2ps.GL2PS_SVG, "pgf": gl2ps.GL2PS_PGF}) image_formats_gl2ps = _gl2ps_types.keys() image_formats_fromeps = ["ppm", "png", "jpeg", "rast", "tiff", "xwd", "y4m"] if GD.options.debug: print "Qt image types for saving: ", image_formats_qt print "Qt image types for input: ", image_formats_qtr print "gl2ps image types:", image_formats_gl2ps print "image types converted from EPS:", image_formats_fromeps
def detect(): """Check if we have calpy and if so, add its path to sys.path.""" global calpy_path calpy = utils.hasExternal('calpy') if not calpy: return GD.message("You have calpy version %s" % calpy) path = '' calpy = calpy.split('-')[0] # trim the version trailer if utils.checkVersion('calpy','0.3.4-rev3',external=True) >= 0: sta,out = utils.runCommand('calpy --whereami') if not sta: path = os.path.dirname(out) GD.debug("I found calpy in %s" % path) if not path: trypaths = [ '/usr/local/lib', '/usr/local' ] for p in trypaths: path = '%s/calpy-%s' % (p,calpy) if os.path.exists(path): GD.debug('path exists: %s' % path) break else: GD.debug('path does not exist: %s' % path) path = '' if path: GD.message("I found calpy in '%s'" % path) sys.path.append(path) calpy_path = path
def readDXF(filename): """Read a DXF file and extract the recognized entities. `filename`: name of a .DXF file. Returns a multiline string with one line for each recognized entity, in a format that can directly be used by :func:`convertDXF`. This function requires the external program `dxfparser` which comes with the pyFormex distribution. It currently recognizes entities of type 'Arc', 'Line', 'Polyline', 'Vertex'. """ import utils,commands print(filename) if utils.hasExternal('dxfparser'): cmd = 'pyformex-dxfparser %s 2>/dev/null' % filename print(cmd) sta,out = utils.runCommand(cmd) if sta==0: return out else: return '' else: utils.warn('warn_no_dxfparser') return ''
def runTetgen(fn,options=''): """Run tetgen mesher on the specified file. The input file is a closed triangulated surface. tetgen will generate a volume tetraeder mesh inside the surface, and create a new approximation of the surface as a by-product. """ if not utils.hasExternal('tetgen'): pf.warning(""".. I could not find the 'tetgen' command. tetgen is a quality tetrahedral mesh generator and a 3D Delaunay triangulator. See http://tetgen.org. It is available from the Debian non-free section. """) return if os.path.exists(fn) and utils.hasExternal('tetgen'): sta,out = utils.runCommand('tetgen -z%s %s' % (options,fn))
def runTetgen(fn, options=''): """Run tetgen mesher on the specified file. The input file is a closed triangulated surface. tetgen will generate a volume tetraeder mesh inside the surface, and create a new approximation of the surface as a by-product. """ if not utils.hasExternal('tetgen'): pf.warning(""".. I could not find the 'tetgen' command. tetgen is a quality tetrahedral mesh generator and a 3D Delaunay triangulator. See http://tetgen.org. It is available from the Debian non-free section. """) return if os.path.exists(fn) and utils.hasExternal('tetgen'): sta, out = utils.runCommand('tetgen -z%s %s' % (options, fn))
def initialize(): """Initialize the image module.""" global image_formats_qt, image_formats_qtr, image_formats_gl2ps, image_formats_fromeps, gl2ps, _producer, _gl2ps_types # Find interesting supporting software utils.hasExternal('imagemagick') # Set some globals pf.debug("Loading Image Formats", pf.DEBUG.IMAGE) image_formats_qt = map(str, QtGui.QImageWriter.supportedImageFormats()) image_formats_qtr = map(str, QtGui.QImageReader.supportedImageFormats()) ## if pf.cfg.get('imagesfromeps',False): ## pf.image_formats_qt = [] if utils.hasModule('gl2ps'): import gl2ps _producer = pf.Version + ' (%s)' % pf.cfg.get('help/website', '') _gl2ps_types = { 'ps': gl2ps.GL2PS_PS, 'eps': gl2ps.GL2PS_EPS, 'tex': gl2ps.GL2PS_TEX, 'pdf': gl2ps.GL2PS_PDF, } if utils.checkVersion('gl2ps', '1.03') >= 0: _gl2ps_types.update({ 'svg': gl2ps.GL2PS_SVG, 'pgf': gl2ps.GL2PS_PGF, }) image_formats_gl2ps = _gl2ps_types.keys() image_formats_fromeps = [ 'ppm', 'png', 'jpeg', 'rast', 'tiff', 'xwd', 'y4m' ] pf.debug( """ Qt image types for saving: %s Qt image types for input: %s gl2ps image types: %s image types converted from EPS: %s""" % (image_formats_qt, image_formats_qtr, image_formats_gl2ps, image_formats_fromeps), pf.DEBUG.IMAGE | pf.DEBUG.INFO)
def install_external(pkgdir,prgname): extdir = os.path.join(pf.cfg['pyformexdir'],'extra',pkgdir) sta,out = utils.runCommand("cd %s; make && gksu make install" % extdir) if sta: info = out else: if utils.hasExternal(prgname,force=True): info = "Succesfully installed %s" % pkgdir else: info ="You should now restart pyFormex!" draw.showInfo(info) return sta
def install_external(pkgdir, prgname): extdir = os.path.join(pf.cfg['pyformexdir'], 'extra', pkgdir) sta, out = utils.runCommand("cd %s; make && gksu make install" % extdir) if sta: info = out else: if utils.hasExternal(prgname, force=True): info = "Succesfully installed %s" % pkgdir else: info = "You should now restart pyFormex!" draw.showInfo(info) return sta
def initialize(): """Initialize the image module.""" global image_formats_qt,image_formats_qtr,image_formats_gl2ps,image_formats_fromeps,gl2ps,_producer,_gl2ps_types # Find interesting supporting software utils.hasExternal('ImageMagick') # Set some globals pf.debug("LOADING IMAGE FORMATS") image_formats_qt = map(str,QtGui.QImageWriter.supportedImageFormats()) image_formats_qtr = map(str,QtGui.QImageReader.supportedImageFormats()) ## if pf.cfg.get('imagesfromeps',False): ## pf.image_formats_qt = [] if utils.hasModule('gl2ps'): import gl2ps _producer = pf.Version + ' (http://pyformex.berlios.de)' _gl2ps_types = { 'ps':gl2ps.GL2PS_PS, 'eps':gl2ps.GL2PS_EPS, 'tex':gl2ps.GL2PS_TEX, 'pdf':gl2ps.GL2PS_PDF, } if utils.checkVersion('gl2ps','1.03') >= 0: _gl2ps_types.update({ 'svg':gl2ps.GL2PS_SVG, 'pgf':gl2ps.GL2PS_PGF, }) image_formats_gl2ps = _gl2ps_types.keys() image_formats_fromeps = [ 'ppm', 'png', 'jpeg', 'rast', 'tiff', 'xwd', 'y4m' ] pf.debug(""" Qt image types for saving: %s Qt image types for input: %s gl2ps image types: %s image types converted from EPS: %s""" % (image_formats_qt,image_formats_qtr,image_formats_gl2ps,image_formats_fromeps))
## This program is distributed under the GNU General Public License ## version 2 or later (see file COPYING for details) ## """Import/Export Formex structures to/from stl format. An stl is stored as a numerical array with shape [n,3,3]. This is compatible with the pyFormex data model. """ import os import globaldata as GD from plugins import tetgen from utils import runCommand, changeExt,countLines,mtime,hasExternal from formex import * hasExternal('admesh') hasExternal('tetgen') # The Stl class should not be used yet! Use the functions instead. class STL(object): """A 3D surface described by a set of triangles.""" def __init__(self,*args): """Create a new STL surface. The surface contains ntri triangles, each having 3 vertices with 3 coordinates. The surface can be initialized from one of the following: - a (ntri,3,3) shaped array of floats ; - a 3-plex Formex with ntri elements ; - an (ncoords,3) float array of vertex coordinates and
import menu import cameraMenu import fileMenu import scriptsMenu import prefMenu import toolbar import canvas import actionlist import script import utils import draw import widgets # Find interesting supporting software utils.hasExternal('ImageMagick') def Size(widget): """Return the size of a widget as a tuple.""" s = widget.size() return s.width(),s.height() def Pos(widget): """Return the position of a widget as a tuple.""" p = widget.pos() return p.x(),p.y() ################# Message Board ############### class Board(QtGui.QTextEdit):
## You should have received a copy of the GNU General Public License ## along with this program. If not, see http://www.gnu.org/licenses/. ## """Operations on triangulated surfaces using GTS functions. This module provides access to GTS from insisde pyFormex. """ from __future__ import print_function import pyformex as pf from coords import * import utils import os from plugins.trisurface import TriSurface,read_gts_intersectioncurve utils.hasExternal('gts') # # gts commands used: # in Debian package: stl2gts gts2stl gtscheck # not in Debian package: gtssplit gtscoarsen gtsrefine gtssmooth # def boolean(self,surf,op,check=False,verbose=False): """Perform a boolean operation with another surface. Boolean operations between surfaces are a basic operation in free surface modeling. Both surfaces should be closed orientable non-intersecting manifolds. Use the :meth:`check` method to find out. The boolean operations are set operations on the enclosed volumes:
## You should have received a copy of the GNU General Public License ## along with this program. If not, see http://www.gnu.org/licenses/. ## """Operations on triangulated surfaces using GTS functions. This module provides access to GTS from insisde pyFormex. """ from __future__ import print_function import pyformex as pf from coords import * import utils import os from plugins.trisurface import TriSurface, read_gts_intersectioncurve utils.hasExternal('gts') # # gts commands used: # in Debian package: stl2gts gts2stl gtscheck # not in Debian package: gtssplit gtscoarsen gtsrefine gtssmooth # def boolean(self, surf, op, check=False, verbose=False): """Perform a boolean operation with another surface. Boolean operations between surfaces are a basic operation in free surface modeling. Both surfaces should be closed orientable non-intersecting manifolds. Use the :meth:`check` method to find out.