Added bounding circles to bounding boxes tool
This commit is contained in:
parent
ecbb8bf340
commit
3e2cf6216a
@ -4,6 +4,8 @@
|
|||||||
<id>fablabchemnitz.de.boundingbox</id>
|
<id>fablabchemnitz.de.boundingbox</id>
|
||||||
<param name="help_text" type="description">Draws bounding boxes around selected objects, useful for debugging. Author: Pawel Mosakowski. Modded by Mario Voigt.</param>
|
<param name="help_text" type="description">Draws bounding boxes around selected objects, useful for debugging. Author: Pawel Mosakowski. Modded by Mario Voigt.</param>
|
||||||
<param min="-10000.0" max="10000.0" name="offset" type="float" gui-text="Offset from object (all directions)">0.0</param>
|
<param min="-10000.0" max="10000.0" name="offset" type="float" gui-text="Offset from object (all directions)">0.0</param>
|
||||||
|
<param name="box" type="bool" gui-text="Draw boxes">true</param>
|
||||||
|
<param name="circle" type="bool" gui-text="Draw circles">false</param>
|
||||||
<effect>
|
<effect>
|
||||||
<object-type>all</object-type>
|
<object-type>all</object-type>
|
||||||
<effects-menu>
|
<effects-menu>
|
||||||
|
@ -1,24 +1,39 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import inkex
|
import inkex
|
||||||
|
import math
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
class DrawBBoxes(inkex.Effect):
|
class DrawBBoxes(inkex.Effect):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
inkex.Effect.__init__(self)
|
inkex.Effect.__init__(self)
|
||||||
self.arg_parser.add_argument('--offset', type=float, default=0.0, help='Offset from object (all directions)')
|
self.arg_parser.add_argument('--offset', type=float, default=0.0, help='Offset from object (all directions)')
|
||||||
|
self.arg_parser.add_argument('--box', type=inkex.Boolean, default=0.0, help='Draw boxes')
|
||||||
|
self.arg_parser.add_argument('--circle', type=inkex.Boolean, default=0.0, help='Draw circles')
|
||||||
|
|
||||||
def effect(self):
|
def effect(self):
|
||||||
if len(self.svg.selected) > 0:
|
if len(self.svg.selected) > 0:
|
||||||
bboxes = [(id, node, node.bounding_box()) for id, node in self.svg.selected.items()]
|
bboxes = [(id, node, node.bounding_box()) for id, node in self.svg.selected.items()]
|
||||||
|
|
||||||
|
if self.options.box:
|
||||||
for id, node, bbox in bboxes:
|
for id, node, bbox in bboxes:
|
||||||
attribs = {
|
attribs = {
|
||||||
'style' : str(inkex.Style({'stroke':'#ff0000','stroke-width' : '1','fill':'none'})),
|
'style' : str(inkex.Style({'stroke':'#ff0000','stroke-width' : '1','fill':'none'})),
|
||||||
'x' : str(bbox.left - self.options.offset),
|
'x' : str(bbox.left - self.options.offset),
|
||||||
'y' : str(bbox.top - self.options.offset),
|
'y' : str(bbox.top - self.options.offset),
|
||||||
'width' : str(bbox.width + 2 * self.options.offset),
|
'width' : str(bbox.width + 2 * self.options.offset),
|
||||||
'height' : str(bbox.height + 2 * self.options.offset),
|
'height': str(bbox.height + 2 * self.options.offset),
|
||||||
}
|
}
|
||||||
etree.SubElement(self.svg.get_current_layer(), inkex.addNS('rect','svg'), attribs )
|
etree.SubElement(self.svg.get_current_layer(), inkex.addNS('rect','svg'), attribs )
|
||||||
|
|
||||||
|
if self.options.circle:
|
||||||
|
for id, node, bbox in bboxes:
|
||||||
|
attribs = {
|
||||||
|
'style': str(inkex.Style({'stroke':'#ff0000','stroke-width' : '1','fill':'none'})),
|
||||||
|
'cx' : str(bbox.center_x),
|
||||||
|
'cy' : str(bbox.center_y),
|
||||||
|
#'r' : str(bbox.width / 2 + self.options.offset),
|
||||||
|
'r' : str(math.sqrt((bbox.width + 2 * self.options.offset)* (bbox.width + 2 * self.options.offset) + (bbox.height + 2 * self.options.offset) * (bbox.height + 2 * self.options.offset)) / 2),
|
||||||
|
}
|
||||||
|
etree.SubElement(self.svg.get_current_layer(), inkex.addNS('circle','svg'), attribs )
|
||||||
DrawBBoxes().run()
|
DrawBBoxes().run()
|
Reference in New Issue
Block a user