ADG Lua 

ADG Lua Commit Details

Date:2013-03-22 21:05:03 (6 years 4 months ago)
Author:Nicola Fontana
Branch:master
Commit:523e343445f22867e18845a3155a9a3c3f63f279
Parents: 8a593349a2a42bcd82ce8a04a93df8657ad71f68
Message:piston: added axis

Changes:
Mpiston.lua (4 diffs)

File differences

piston.lua
6565
6666
6767
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
68103
69104
70105
......
204239
205240
206241
242
207243
208244
209245
210
246
247
248
249
250
251
252
211253
212
254
213255
214256
215257
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
258
259
240260
241261
242262
......
276296
277297
278298
279
299
280300
281301
282302
......
449469
450470
451471
472
473
474
475
452476
453477
454478
constructor[model](part, model)
end)
function generator.model.hole(part, path)
path = path or Adg.Path {}
constructor[path] = generator.model.hole
local data = part.data
local pair = Cpml.Pair { x = data.LHOLE, y = 0 }
path:move_to(pair)
path:set_named_pair('LHOLE', pair)
pair.y = data.DHOLE / 2
pair.x = pair.x - pair.y / SQRT3
path:line_to(pair)
local edge = pair:dup()
pair.x = 0
path:line_to(pair)
path:set_named_pair('DHOLE', pair)
path:line_to_explicit(0, (data.D1 + data.DHOLE) / 4)
path:curve_to_explicit(data.LHOLE / 2, data.DHOLE / 2,
data.LHOLE + 2, data.D1 / 2,
data.LHOLE + 2, 0)
path:reflect()
path:close()
-- No need to incomodate an AdgEdge model for two reasons:
-- it is only a single line and it is always needed
path:move_to(edge)
edge.y = -edge.y
path:line_to(edge)
return path
end
function generator.model.body(part, path)
path = path or Adg.Path {}
constructor[path] = generator.model.body
constructor[edges] = generator.model.edges
edges:set_source(part.model.body)
return edges
end
function generator.model.hole(part, path)
function generator.model.axis(part, path)
--[[
XXX: actually the end points can extend outside the body
only in local space. The proper extension values should be
expressed in global space but actually is impossible to
combine local and global space in the AdgPath API.
--]]
path = path or Adg.Path {}
constructor[path] = generator.model.hole
constructor[path] = generator.model.axis
local data = part.data
local pair = Cpml.Pair {x = data.LHOLE, y = 0 }
path:move_to(pair)
path:set_named_pair('LHOLE', pair)
local tmp = Cpml.Pair {}
tmp.y = data.DHOLE / 2
tmp.x = pair.x - tmp.y / SQRT3
path:line_to(tmp)
pair.x = 0
pair.y = tmp.y
path:line_to(pair)
path:set_named_pair('DHOLE', pair)
path:line_to_explicit(0, (data.D1 + data.DHOLE) / 4)
path:curve_to_explicit(data.LHOLE / 2, data.DHOLE / 2,
data.LHOLE + 2, data.D1 / 2,
data.LHOLE + 2, 0)
path:reflect_explicit(1, 0)
path:close()
path:move_to(tmp)
tmp.y = -tmp.y
path:line_to(tmp)
path:move_to_explicit(-1, 0)
path:line_to_explicit(data.A + 1, 0)
return path
end
if not surface then return nil, 'Requested format not supported' end
-- Render the canvas content
local cr = cairo.Context.create(surface);
local cr = cairo.Context.create(surface)
canvas:render(cr)
local status
canvas:add(Adg.Stroke { trail = model.edges })
canvas:add(Adg.Hatch { trail = model.hole })
canvas:add(Adg.Stroke { trail = model.hole })
canvas:add(Adg.Stroke {
trail = model.axis,
line_dress = Adg.Dress.LINE_AXIS
})
add_dimensions(canvas, model)
return canvas

Archive Download the corresponding diff file

Branches

Tags