2020-07-30 01:16:18 +02:00
|
|
|
#!/usr/bin/env python3
|
2020-08-17 15:21:46 +02:00
|
|
|
|
2020-07-30 01:16:18 +02:00
|
|
|
import inkex
|
2020-09-03 00:35:27 +02:00
|
|
|
import apolloniangasket_func
|
2020-07-30 01:16:18 +02:00
|
|
|
from lxml import etree
|
|
|
|
|
|
|
|
__version__ = '0.0'
|
|
|
|
|
|
|
|
def cplxs2pts(zs):
|
|
|
|
tt = []
|
|
|
|
for z in zs:
|
|
|
|
tt.extend([z.real,z.imag])
|
|
|
|
return tt
|
|
|
|
|
|
|
|
def draw_SVG_circle(parent, r, cx, cy, name):
|
|
|
|
" structre an SVG circle entity under parent "
|
|
|
|
circ_attribs = { 'cx': str(cx), 'cy': str(cy),
|
|
|
|
'r': str(r),
|
|
|
|
inkex.addNS('label','inkscape'): name}
|
|
|
|
|
|
|
|
|
|
|
|
circle = etree.SubElement(parent, inkex.addNS('circle','svg'), circ_attribs )
|
|
|
|
|
2021-04-04 01:52:28 +02:00
|
|
|
class Gasket(inkex.EffectExtension): # choose a better name
|
2020-07-30 01:16:18 +02:00
|
|
|
|
2021-04-16 14:41:12 +02:00
|
|
|
def add_arguments(self, pars):
|
|
|
|
pars.add_argument("--depth",type=int, default=3, help="command line help")
|
|
|
|
pars.add_argument("--c1", type=float, default=2.0, help="command line help")
|
|
|
|
pars.add_argument("--c2", type=float, default=3.0, help="command line help")
|
|
|
|
pars.add_argument("--c3", type=float, default=3.0, help="command line help")
|
|
|
|
pars.add_argument("--shrink", type=inkex.Boolean, default=True, help="command line help")
|
|
|
|
pars.add_argument("--active_tab", default='title', help="Active tab.")
|
2020-07-30 01:16:18 +02:00
|
|
|
|
|
|
|
def calc_unit_factor(self):
|
|
|
|
unit_factor = self.svg.unittouu(str(1.0) + self.options.units)
|
|
|
|
return unit_factor
|
|
|
|
|
|
|
|
### -------------------------------------------------------------------
|
|
|
|
### Main function and is called when the extension is run.
|
|
|
|
|
|
|
|
def effect(self):
|
|
|
|
|
|
|
|
#set up path styles
|
|
|
|
path_stroke = '#DD0000' # take color from tab3
|
|
|
|
path_fill = 'none' # no fill - just a line
|
|
|
|
path_stroke_width = self.svg.unittouu(str(0.1) + "mm")
|
|
|
|
page_id = self.options.active_tab # sometimes wrong the very first time
|
|
|
|
|
|
|
|
style_curve = { 'stroke': path_stroke,
|
|
|
|
'fill': 'none',
|
|
|
|
'stroke-width': path_stroke_width }
|
|
|
|
|
|
|
|
# This finds center of current view in inkscape
|
2021-04-04 01:52:28 +02:00
|
|
|
t = 'translate(%s,%s)' % (self.svg.namedview.center[0], self.svg.namedview.center[1])
|
2020-07-30 01:16:18 +02:00
|
|
|
|
|
|
|
# add a group to the document's current layer
|
|
|
|
#all the circles inherit style from this group
|
|
|
|
g_attribs = { inkex.addNS('label','inkscape'): 'zengon' + "_%d"%(self.options.depth),
|
|
|
|
inkex.addNS('transform-center-x','inkscape'): str(0),
|
|
|
|
inkex.addNS('transform-center-y','inkscape'): str(0),
|
|
|
|
'transform': t,
|
|
|
|
'style' : str(inkex.Style((style_curve))),
|
|
|
|
'info':'N: '}
|
2021-04-04 01:52:28 +02:00
|
|
|
topgroup = etree.SubElement(self.svg.get_current_layer(), 'g', g_attribs)
|
2020-07-30 01:16:18 +02:00
|
|
|
|
2020-09-03 00:35:27 +02:00
|
|
|
circles = apolloniangasket_func.main(c1=self.options.c1,
|
2020-07-30 01:16:18 +02:00
|
|
|
c2=self.options.c2,
|
|
|
|
c3=self.options.c3,
|
|
|
|
depth=self.options.depth)
|
|
|
|
|
|
|
|
#shrink the circles so they don't touch
|
|
|
|
#useful for laser cutting
|
|
|
|
|
|
|
|
if self.options.shrink:
|
|
|
|
circles = circles[1:]
|
|
|
|
for cc in circles:
|
|
|
|
cc.r = abs(cc.r)
|
|
|
|
if cc.r >.5:
|
|
|
|
cc.r -= .1
|
|
|
|
else:
|
|
|
|
cc.r *= .9
|
|
|
|
|
|
|
|
scale_factor = 200
|
|
|
|
for c in circles:
|
|
|
|
cx, cy, r = c.m.real, c.m.imag, abs(c.r)
|
|
|
|
|
|
|
|
#rescale and add circle to document
|
2021-04-04 01:52:28 +02:00
|
|
|
cx, cy, r = scale_factor * cx , scale_factor * cy, scale_factor * r
|
|
|
|
draw_SVG_circle(topgroup, r, cx, cy, 'apo')
|
2020-07-30 01:16:18 +02:00
|
|
|
|
2020-08-31 21:25:41 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
Gasket().run()
|