Package PyFoam :: Package Applications :: Module STLUtility
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Applications.STLUtility

 1  """ 
 2  Application-class that implements pyFoamSTLUtility.py 
 3  """ 
 4  from optparse import OptionGroup 
 5   
 6  from PyFoamApplication import PyFoamApplication 
 7  from PyFoam.Basics.STLFile import STLFile 
 8  from PyFoam.Basics.RestructuredTextHelper import RestructuredTextHelper 
 9   
10  from os import path 
11   
12 -class STLUtility(PyFoamApplication):
13 - def __init__(self,args=None):
14 description="""\ 15 This utility does some basic manipulations with STL-files 16 """ 17 PyFoamApplication.__init__(self, 18 args=args, 19 description=description, 20 usage="%prog <source1.stl> <source2.stl> ...", 21 interspersed=True, 22 changeVersion=False, 23 nr=1, 24 exactNr=False)
25
26 - def addOptions(self):
27 action=OptionGroup(self.parser, 28 "Action", 29 "What to do") 30 self.parser.add_option_group(action) 31 action.add_option("--join-to", 32 action="store", 33 dest="joinTo", 34 default=None, 35 help="Join the STLs into a single file") 36 37 action.add_option("--patch-names", 38 action="store_true", 39 dest="patchNames", 40 default=False, 41 help="Print the names of the patches (if names are given)") 42 43 action.add_option("--info", 44 action="store_true", 45 dest="info", 46 default=False, 47 help="Info about the patches in the STL")
48
49 - def run(self):
50 sources=[STLFile(f) for f in self.parser.getArgs()] 51 rst=RestructuredTextHelper() 52 53 if self.opts.patchNames: 54 print rst.buildHeading("Patch names",level=RestructuredTextHelper.LevelSection) 55 for s in sources: 56 print rst.buildHeading(s.filename(),level=RestructuredTextHelper.LevelSubSection) 57 for p in s.patchInfo(): 58 print p["name"] 59 60 if self.opts.info: 61 print rst.buildHeading("Patch info",level=RestructuredTextHelper.LevelSection) 62 for s in sources: 63 print rst.buildHeading(s.filename(),level=RestructuredTextHelper.LevelSubSection) 64 tab=rst.table() 65 tab[0]=["name","facets","range in file","bounding box"] 66 tab.addLine(head=True) 67 for i,p in enumerate(s.patchInfo()): 68 tab[(i+1,0)]=p["name"] 69 tab[(i+1,1)]=p["facets"] 70 tab[(i+1,2)]="%d-%d" % (p["start"],p["end"]) 71 tab[(i+1,3)]="(%g %g %g) - (%g %g %g)" % tuple(p["min"]+p["max"]) 72 73 print tab 74 75 if self.opts.joinTo: 76 if path.exists(self.opts.joinTo): 77 self.error("File",self.opts.joinTo,"does allready exist") 78 79 result=STLFile() 80 for s in sources: 81 result+=s 82 83 result.writeTo(self.opts.joinTo)
84