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
25
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
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