-
Notifications
You must be signed in to change notification settings - Fork 4
/
fablab_tabs_generator.py
82 lines (61 loc) · 3.06 KB
/
fablab_tabs_generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
# These two lines are only needed if you don't put the script directly into
# the installation directory
import sys
sys.path.append('/usr/share/inkscape/extensions')
# We will use the inkex module with the predefined Effect base class.
import inkex
# The simplestyle module provides functions for style parsing.
from simplestyle import *
import simplepath
from fablab_box_lib import BoxEffect
from fablab_lib import BaseEffect
from fablab_lib import print_
def unsignedLong(signedLongString):
longColor = long(signedLongString)
if longColor < 0:
longColor = longColor & 0xFFFFFFFF
return longColor
def getColorString(longColor):
longColor = unsignedLong(longColor)
hexColor = hex(longColor)[2:-3]
hexColor = hexColor.rjust(6, '0')
return '#' + hexColor.upper()
class BoxGeneratorEffect(BaseEffect, BoxEffect):
def __init__(self):
"""
Constructor.
Defines the "--what" option of a script.
"""
# Call the base class constructor.
BaseEffect.__init__(self)
self.OptionParser.add_option('-i', '--path_id', action='store',
type='string', dest='path_id', default='encoches',
help='Id of svg path')
self.OptionParser.add_option('--width', action='store',
type='float', dest='width', default=200,
help='Width')
self.OptionParser.add_option('--thickness', action='store',
type='float', dest='thickness', default=3,
help='Thickness of material')
self.OptionParser.add_option('--tab_size', action='store',
type='float', dest='tab_size', default=10,
help='Tab size')
self.OptionParser.add_option('--backlash', action='store',
type='float', dest='backlash', default=0.0,
help='Backlash generated by lasercut')
self.start_stop = {}
def effect(self):
print_(self.options)
parent = self.current_layer
centre = self.view_center
tabs = self.tabs(self.options.width, self.options.tab_size, self.options.thickness, backlash=self.options.backlash * -1, lastUp=True)
shape = self.getPath(self.toPathString(self.mm2u(tabs)), '%s_bottom' % self.options.path_id, centre[0], centre[1], None, '#FF0000')
inkex.etree.SubElement(parent, inkex.addNS('path', 'svg'), shape)
tabs = [[0, 0]]
tabs.extend(self.tabs(self.options.width, self.options.tab_size, self.options.thickness, backlash=self.options.backlash))
shape = self.getPath(self.toPathString(self.mm2u(tabs)), '%s_bottom' % self.options.path_id, centre[0], centre[1] + 2 * self.mm2u(self.options.thickness), None, '#00FF00')
inkex.etree.SubElement(parent, inkex.addNS('path', 'svg'), shape)
if __name__ == '__main__':
effect = BoxGeneratorEffect()
effect.affect()