Improved Bounding Boxes
This commit is contained in:
parent
ccab5c6f34
commit
92e163a793
@ -6,6 +6,7 @@
|
|||||||
<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="box" type="bool" gui-text="Draw boxes">true</param>
|
||||||
<param name="circle" type="bool" gui-text="Draw circles">false</param>
|
<param name="circle" type="bool" gui-text="Draw circles">false</param>
|
||||||
|
<param name="split" type="bool" gui-text="Handle selection as group">True</param>
|
||||||
<effect>
|
<effect>
|
||||||
<object-type>all</object-type>
|
<object-type>all</object-type>
|
||||||
<effects-menu>
|
<effects-menu>
|
||||||
|
@ -10,13 +10,11 @@ class DrawBBoxes(inkex.Effect):
|
|||||||
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('--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')
|
self.arg_parser.add_argument('--circle', type=inkex.Boolean, default=0.0, help='Draw circles')
|
||||||
|
self.arg_parser.add_argument('--split', type = inkex.Boolean, default = True, help = 'Handle selection as group')
|
||||||
|
|
||||||
def effect(self):
|
def drawBBox(self, node):
|
||||||
if len(self.svg.selected) > 0:
|
bbox = node.bounding_box()
|
||||||
bboxes = [(id, node, node.bounding_box()) for id, node in self.svg.selected.items()]
|
|
||||||
|
|
||||||
if self.options.box:
|
if self.options.box:
|
||||||
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),
|
||||||
@ -27,7 +25,6 @@ class DrawBBoxes(inkex.Effect):
|
|||||||
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:
|
if self.options.circle:
|
||||||
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'})),
|
||||||
'cx' : str(bbox.center_x),
|
'cx' : str(bbox.center_x),
|
||||||
@ -36,4 +33,13 @@ class DrawBBoxes(inkex.Effect):
|
|||||||
'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),
|
'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)
|
etree.SubElement(self.svg.get_current_layer(), inkex.addNS('circle','svg'), attribs)
|
||||||
|
|
||||||
|
def effect(self):
|
||||||
|
if len(self.svg.selected) > 0:
|
||||||
|
if self.options.split is False:
|
||||||
|
for id, item in self.svg.selected.items():
|
||||||
|
self.drawBBox(item)
|
||||||
|
else:
|
||||||
|
self.drawBBox(self.svg.selected)
|
||||||
|
|
||||||
DrawBBoxes().run()
|
DrawBBoxes().run()
|
Reference in New Issue
Block a user