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 from PyFoam.ThirdParty.six import print_
13
27
29 action=OptionGroup(self.parser,
30 "Action",
31 "What to do")
32 self.parser.add_option_group(action)
33 action.add_option("--join-to",
34 action="store",
35 dest="joinTo",
36 default=None,
37 help="Join the STLs into a single file")
38
39 action.add_option("--patch-names",
40 action="store_true",
41 dest="patchNames",
42 default=False,
43 help="Print the names of the patches (if names are given)")
44
45 action.add_option("--info",
46 action="store_true",
47 dest="info",
48 default=False,
49 help="Info about the patches in the STL")
50
52 sources=[STLFile(f) for f in self.parser.getArgs()]
53 rst=RestructuredTextHelper()
54
55 if self.opts.patchNames:
56 print_(rst.buildHeading("Patch names",level=RestructuredTextHelper.LevelSection))
57 for s in sources:
58 print_(rst.buildHeading(s.filename(),level=RestructuredTextHelper.LevelSubSection))
59 for p in s.patchInfo():
60 print_(p["name"])
61
62 if self.opts.info:
63 print_(rst.buildHeading("Patch info",level=RestructuredTextHelper.LevelSection))
64 for s in sources:
65 print_(rst.buildHeading(s.filename(),level=RestructuredTextHelper.LevelSubSection))
66 tab=rst.table()
67 tab[0]=["name","facets","range in file","bounding box"]
68 tab.addLine(head=True)
69 for i,p in enumerate(s.patchInfo()):
70 tab[(i+1,0)]=p["name"]
71 tab[(i+1,1)]=p["facets"]
72 tab[(i+1,2)]="%d-%d" % (p["start"],p["end"])
73 tab[(i+1,3)]="(%g %g %g) - (%g %g %g)" % tuple(p["min"]+p["max"])
74
75 print_(tab)
76
77 if self.opts.joinTo:
78 if path.exists(self.opts.joinTo):
79 self.error("File",self.opts.joinTo,"does allready exist")
80
81 result=STLFile()
82 for s in sources:
83 result+=s
84
85 result.writeTo(self.opts.joinTo)
86
87
88