From bd136efd3a26c10c6e9716fc9aa26f4f87b1a2aa Mon Sep 17 00:00:00 2001 From: Mario Voigt Date: Wed, 19 Aug 2020 12:16:00 +0200 Subject: [PATCH] Added fill with circles --- extensions/fablabchemnitz_fill_circle.inx | 19 +++++ extensions/fablabchemnitz_fill_circle.py | 82 +++++++++++++++++++++ extensions/fablabchemnitz_imagetracerjs.inx | 8 +- extensions/fablabchemnitz_living_hinge.inx | 52 ++++++------- 4 files changed, 132 insertions(+), 29 deletions(-) create mode 100644 extensions/fablabchemnitz_fill_circle.inx create mode 100644 extensions/fablabchemnitz_fill_circle.py diff --git a/extensions/fablabchemnitz_fill_circle.inx b/extensions/fablabchemnitz_fill_circle.inx new file mode 100644 index 00000000..a2b49330 --- /dev/null +++ b/extensions/fablabchemnitz_fill_circle.inx @@ -0,0 +1,19 @@ + + + Fill Rectangle With Circles + fablabchemnitz.fill_circle + 3.0 + 10.0 + 30.0 + + all + + + + + + + + \ No newline at end of file diff --git a/extensions/fablabchemnitz_fill_circle.py b/extensions/fablabchemnitz_fill_circle.py new file mode 100644 index 00000000..46d1aa9c --- /dev/null +++ b/extensions/fablabchemnitz_fill_circle.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 + +# Program allowing the addition of small grey dots in rectangles created using Inkscape. + +# Thomas Guzik, thomas.guzik@laposte.net +# Leo 130 contact@avilab.fr +# Corentin Bettiol - corentin-bettiol@hotmail.fr + +# -Creative Commons License +# -This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. +# -http://creativecommons.org/licenses/by-nc-sa/4.0/ + +import inkex +from lxml import etree + +def recup(selection,attrib): + l = [] + for i in selection: + selec = i + valr = selec.get(attrib) + l.append(valr) + return l + +def generCircle(y,x,r): + circle = etree.Element('{http://www.w3.org/2000/svg}circle') + circle.set('cy',str(y)) + circle.set('cx',str(x)) + circle.set('r',str(r)) + circle.set('fill','#000000') + circle.set('stroke','#000000') + circle.set('stroke-width','0') + return circle + +def toFloat(l): + for i in range(len(l)): + l[i] = float(l[i]) + return l + +class Circle(inkex.Effect): + def __init__(self): + inkex.Effect.__init__(self) + self.arg_parser.add_argument('--radius', type = float, default = 3.0, help = 'Radius to enter') + self.arg_parser.add_argument('--margin', type = float, default = 10.0, help = 'Margin between the edge of the rectangles and the circles') + self.arg_parser.add_argument('--space', type = float, default = 30.0, help = 'Spacing between circles') + + def effect(self): + # svg = self.svg.document.getroot() + # layer = etree.SubElement(svg, 'g') + # layer.set(inkex.addNS('label', 'inkscape'), 'Layer') + # layer.set(inkex.addNS('groupmode', 'inkscape'), 'layer') + # Should we add the circles on a different layer sheet? + + radius = self.options.radius + margin = self.options.margin + space = self.options.space + + if str(list(self.svg.selected.values())[0]) == 'rect': + selection = (self.svg.selected).values() + + y,x,height,width = [], [], [], [] + + if (len(selection))>0: + y = toFloat(recup(selection,'y')) + x = toFloat(recup(selection,'x')) + height = toFloat(recup(selection,'height')) + width = toFloat(recup(selection,'width')) + + for i in range(len(selection)): + xC = x[i] + margin + yC = y[i] + margin + + while xC < (x[i] + width[i] - margin): + while yC < (y[i] + height[i] - margin): + self.svg.get_current_layer().append(generCircle(yC,xC,radius)) + yC += (space + radius) + + xC += space + radius + yC = y[i] + margin + else: + inkex.utils.debug("No rectangle(s) have been selected.") + +Circle().run() \ No newline at end of file diff --git a/extensions/fablabchemnitz_imagetracerjs.inx b/extensions/fablabchemnitz_imagetracerjs.inx index 4fcb1526..de6be1f9 100644 --- a/extensions/fablabchemnitz_imagetracerjs.inx +++ b/extensions/fablabchemnitz_imagetracerjs.inx @@ -55,9 +55,11 @@ image - - - + + + + + + + + + + \ No newline at end of file