2016-02-12 21:22:32 +01:00
|
|
|
#!/usr/bin/python3
|
2014-03-16 18:26:12 +01:00
|
|
|
# Copyright (C) 2013-2014 Florian Festi
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2013-04-16 04:25:37 +02:00
|
|
|
|
2013-07-20 10:49:45 +02:00
|
|
|
from boxes import *
|
2013-06-07 12:51:04 +02:00
|
|
|
import math
|
2013-04-16 04:25:37 +02:00
|
|
|
|
2013-07-20 17:44:16 +02:00
|
|
|
|
|
|
|
"""
|
|
|
|
22x7.5x7cm
|
|
|
|
D=23cm, d=21cm
|
|
|
|
d = 8" D = 9"
|
|
|
|
"""
|
|
|
|
|
2016-03-25 14:02:52 +01:00
|
|
|
class RoundedTriangleSettings(edges.Settings):
|
2013-07-20 10:49:45 +02:00
|
|
|
absolute_params = {
|
|
|
|
"angle" : 60,
|
|
|
|
"radius" : 30,
|
|
|
|
"r_hole" : None,
|
|
|
|
}
|
2013-04-16 04:25:37 +02:00
|
|
|
|
2016-03-25 14:02:52 +01:00
|
|
|
class RoundedTriangle(edges.Edge):
|
2013-07-20 10:49:45 +02:00
|
|
|
char = "t"
|
|
|
|
def __call__(self, length, **kw):
|
|
|
|
angle = self.settings.angle
|
|
|
|
r = self.settings.radius
|
2013-04-16 04:25:37 +02:00
|
|
|
|
2013-07-20 10:49:45 +02:00
|
|
|
if self.settings.r_hole:
|
|
|
|
x = 0.5*(length-2*r)*math.tan(math.radians(angle))
|
|
|
|
y = 0.5*(length)
|
|
|
|
self.hole(x, y, self.settings.r_hole)
|
2013-04-16 04:25:37 +02:00
|
|
|
|
2013-06-07 12:51:04 +02:00
|
|
|
l = 0.5 * (length-2*r) / math.cos(math.radians(angle))
|
|
|
|
self.corner(90-angle, r)
|
|
|
|
self.edge(l)
|
|
|
|
self.corner(2*angle, r)
|
|
|
|
self.edge(l)
|
|
|
|
self.corner(90-angle, r)
|
|
|
|
|
2013-07-20 10:49:45 +02:00
|
|
|
def startAngle(self):
|
|
|
|
return 90
|
|
|
|
|
|
|
|
def endAngle(self):
|
|
|
|
return 90
|
|
|
|
|
|
|
|
class Lamp(Boxes):
|
|
|
|
def __init__(self):
|
2016-03-03 13:27:22 +01:00
|
|
|
Boxes.__init__(self)
|
2013-07-20 10:49:45 +02:00
|
|
|
|
2013-06-07 12:51:04 +02:00
|
|
|
def side(self, y, h):
|
2013-07-20 10:49:45 +02:00
|
|
|
return
|
2016-04-02 20:52:27 +02:00
|
|
|
self.edges["f"](y)
|
2013-06-07 12:51:04 +02:00
|
|
|
self.corner(90)
|
2016-04-02 20:52:27 +02:00
|
|
|
self.edges["f"](h)
|
2013-07-20 17:44:16 +02:00
|
|
|
self.roundedTriangle(y, 75, 25)
|
2016-04-02 20:52:27 +02:00
|
|
|
self.edges["f"](h)
|
2013-06-07 12:51:04 +02:00
|
|
|
self.corner(90)
|
2013-04-16 04:25:37 +02:00
|
|
|
|
2013-04-18 04:44:33 +02:00
|
|
|
def render(self, r, w, x, y, h):
|
2013-04-16 04:25:37 +02:00
|
|
|
"""
|
|
|
|
r : radius of lamp
|
|
|
|
w : width of surrounding ring
|
2013-07-20 17:44:16 +02:00
|
|
|
x : length box
|
|
|
|
y : width box
|
|
|
|
h : height box
|
2013-04-16 04:25:37 +02:00
|
|
|
"""
|
2016-03-03 13:27:22 +01:00
|
|
|
|
2016-06-07 20:20:35 +02:00
|
|
|
self.open()
|
2016-03-03 13:27:22 +01:00
|
|
|
|
2016-04-02 20:52:27 +02:00
|
|
|
#self.edges["f"].settings = (5, 5) # XXX
|
2016-03-03 13:27:22 +01:00
|
|
|
|
|
|
|
s = RoundedTriangleSettings(self.thickness, angle=72, r_hole=2)
|
|
|
|
self.addPart(RoundedTriangle(self, s))
|
|
|
|
|
|
|
|
self.flexSettings = (3, 5.0, 20.0)
|
|
|
|
|
2016-04-02 20:52:27 +02:00
|
|
|
self.edges["f"].settings.setValues(self.thickness, finger=5, space=5, relative=False)
|
2013-04-16 04:25:37 +02:00
|
|
|
d = 2*(r+w)
|
2013-07-20 17:44:16 +02:00
|
|
|
|
2013-07-20 10:49:45 +02:00
|
|
|
self.roundedPlate(d, d, r, move="right", callback=[
|
|
|
|
lambda: self.hole(w, r+w, r),])
|
2013-07-20 17:44:16 +02:00
|
|
|
#dist = ((2**0.5)*r-r) / (2**0.5) + 4
|
|
|
|
#pos = (w-dist, dist)
|
|
|
|
self.roundedPlate(d, d, r, holesMargin=w/2.0) #, callback=[
|
|
|
|
# lambda: self.hole(pos[0], pos[1], 7),])
|
2013-07-20 10:49:45 +02:00
|
|
|
self.roundedPlate(d, d, r, move="only left up")
|
2013-04-16 04:25:37 +02:00
|
|
|
|
2013-07-20 17:44:16 +02:00
|
|
|
hole = lambda: self.hole(w, 70, 2)
|
|
|
|
self.surroundingWall(d, d, r, 120, top='h', bottom='h', callback=[
|
|
|
|
None, hole, None, hole], move="up")
|
2013-07-20 10:49:45 +02:00
|
|
|
|
|
|
|
self.ctx.save()
|
|
|
|
self.rectangularWall(x, y, edges="fFfF", holesMargin=5, move="right")
|
|
|
|
self.rectangularWall(x, y, edges="fFfF", holesMargin=5, move="right")
|
|
|
|
# sides
|
|
|
|
self.rectangularWall(y, h, "fftf", move="right")
|
|
|
|
self.rectangularWall(y, h, "fftf")
|
2013-04-16 04:25:37 +02:00
|
|
|
self.ctx.restore()
|
2013-07-20 10:49:45 +02:00
|
|
|
self.rectangularWall(x, y, edges="fFfF", holesMargin=5,
|
|
|
|
move="up only")
|
|
|
|
|
|
|
|
self.rectangularWall(x, h, edges='hFFF', holesMargin=5, move="right")
|
2013-05-14 17:54:47 +02:00
|
|
|
self.rectangularWall(x, h, edges='hFFF', holesMargin=5)
|
2013-04-16 04:25:37 +02:00
|
|
|
|
2014-03-21 21:08:54 +01:00
|
|
|
self.close()
|
2013-04-16 04:25:37 +02:00
|
|
|
|
2016-03-23 22:05:06 +01:00
|
|
|
def main():
|
2016-03-03 13:27:22 +01:00
|
|
|
l = Lamp()
|
|
|
|
l.parseArgs()
|
|
|
|
l.render(r=4*25.4, w=20, x=270, y=150, h=100)
|
2016-03-23 22:05:06 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|