piston: the view size is subject to global map
[adg-lua.git] / adg-web.lua
blob19a2d1c6a6e9d32ab729d5a21f5784ce4dacbcc8
1 --[[
3 This file is part of adg-lua.
4 Copyright (C) 2012-2013 Nicola Fontana <ntd at entidi.it>
6 adg-lua is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2 of
9 the License, or (at your option) any later version.
11 adg-lua is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General
17 Public License along with adg-lua; if not, write to the Free
18 Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
24 -- Convenient function to load scripts from the same directory
25 -- of this very same file
26 local function local_require(filename)
27 local FILE = arg[0]
28 local basedir = FILE and FILE:match('^(.*/).*$') or './'
29 local filename = basedir .. filename .. '.lua'
30 return assert(loadfile(filename)())
31 end
34 local lgi = require 'lgi'
35 local Adg = lgi.require 'Adg'
36 local Piston = local_require 'piston'
40 -- Command line parsing
41 -----------------------------------------------------------------
44 local request = {}
45 for n, s in ipairs(arg) do
46 -- Arguments are expected in k=v tuples
47 local k, v = s:match('(.-)=(.*)')
48 if not k then error('Invalid argument ' .. n) end
49 request[k] = v
50 end
52 -- Provide fallback values
53 for k, v in pairs {
54 A = 55,
55 B = 20.6,
56 C = 2,
57 DHOLE = 2,
58 LHOLE = 3,
59 D1 = 9.3,
60 D2 = 6.5,
61 D3 = 13.8,
62 D4 = 6.5,
63 D5 = 4.5,
64 D6 = 7.2,
65 D7 = 2,
66 RD34 = 1,
67 RD56 = 0.2,
68 LD2 = 7,
69 LD3 = 3.5,
70 LD5 = 5,
71 LD6 = 1,
72 LD7 = 0.5,
73 GROOVE = false,
74 ZGROOVE = 16,
75 DGROOVE = 8.3,
76 LGROOVE = 1,
77 CHAMFER = 0.3,
79 -- Metadata
80 TITLE = 'SAMPLE DRAWING',
81 DRAWING = 'PISTON',
82 AUTHOR = 'adg-web',
83 DATE = os.date('%d/%m/%Y'),
84 } do
85 if not request[k] then request[k] = v end
86 end
89 -- Part definition
90 -----------------------------------------------------------------
92 local piston = Piston.new(request)
95 -- Canvas settings
96 -----------------------------------------------------------------
98 local n = 1
99 local canvas = piston.view.detailed
100 canvas:set_size_explicit(request.width or 800, request.height or 600)
101 canvas:set_top_margin(10)
102 canvas:set_bottom_margin(10)
103 canvas:set_left_margin(10)
104 canvas:set_right_margin(10)
106 piston:refresh()
107 canvas:autoscale()
110 -- File generation
111 -----------------------------------------------------------------
113 local _, err = canvas:export('/dev/stdout', 'png')
114 if err then error(err) end