fixes in bbox extension
This commit is contained in:
parent
c4b01c7f94
commit
9216775939
@ -3,10 +3,20 @@
|
|||||||
<name>Bounding Box</name>
|
<name>Bounding Box</name>
|
||||||
<id>fablabchemnitz.de.bounding_box</id>
|
<id>fablabchemnitz.de.bounding_box</id>
|
||||||
<label>Draws bounding boxes around selected objects, useful for debugging. Author: Pawel Mosakowski. Modded by Mario Voigt.</label>
|
<label>Draws bounding boxes around selected objects, useful for debugging. Author: Pawel Mosakowski. Modded by Mario Voigt.</label>
|
||||||
|
<param name="unit" gui-text="Unit" type="optiongroup" appearance="combo" gui-description="The unit applies to interval and thresholds">
|
||||||
|
<option value="mm">mm</option>
|
||||||
|
<option value="cm">cm</option>
|
||||||
|
<option value="px">px</option>
|
||||||
|
<option value="pt">pt</option>
|
||||||
|
<option value="pc">pc</option>
|
||||||
|
<option value="in">in</option>
|
||||||
|
</param>
|
||||||
<param name="offset" min="-10000.000" max="10000.000" precision="3" type="float" gui-text="Offset from object (all directions)">0.000</param>
|
<param name="offset" min="-10000.000" max="10000.000" precision="3" type="float" gui-text="Offset from object (all directions)">0.000</param>
|
||||||
<param name="box" type="bool" gui-text="Draw boxes">true</param>
|
|
||||||
<param name="corner_radius" type="float" min="0.000" precision="3" max="10000.000" gui-text="Corner radius" gui-description="Only applies for box type">0.000</param>
|
<param name="corner_radius" type="float" min="0.000" precision="3" max="10000.000" gui-text="Corner radius" gui-description="Only applies for box type">0.000</param>
|
||||||
|
<separator/>
|
||||||
|
<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>
|
||||||
|
<separator/>
|
||||||
<param name="split" type="bool" gui-text="Handle selection as group">true</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>
|
||||||
|
@ -8,19 +8,22 @@ class BoundingBox(inkex.EffectExtension):
|
|||||||
|
|
||||||
def add_arguments(self, pars):
|
def add_arguments(self, pars):
|
||||||
pars.add_argument('--offset', type=float, default=0.0, help='Offset from object (all directions)')
|
pars.add_argument('--offset', type=float, default=0.0, help='Offset from object (all directions)')
|
||||||
|
pars.add_argument('--unit', default="mm")
|
||||||
pars.add_argument('--box', type=inkex.Boolean, default=0.0, help='Draw boxes')
|
pars.add_argument('--box', type=inkex.Boolean, default=0.0, help='Draw boxes')
|
||||||
pars.add_argument('--corner_radius', type=float, default=0.0, help='Corner radius')
|
pars.add_argument('--corner_radius', type=float, default=0.0, help='Corner radius')
|
||||||
pars.add_argument('--circle', type=inkex.Boolean, default=0.0, help='Draw circles')
|
pars.add_argument('--circle', type=inkex.Boolean, default=0.0, help='Draw circles')
|
||||||
pars.add_argument('--split', type = inkex.Boolean, default = True, help = 'Handle selection as group')
|
pars.add_argument('--split', type = inkex.Boolean, default = True, help = 'Handle selection as group')
|
||||||
|
|
||||||
def drawBBox(self, bbox):
|
def drawBBox(self, bbox):
|
||||||
|
so = self.options
|
||||||
|
offset = self.svg.unittouu(str(so.offset) + so.unit)
|
||||||
if self.options.box:
|
if self.options.box:
|
||||||
attribs = {
|
attribs = {
|
||||||
'style' : str(inkex.Style({'stroke':'#ff0000','stroke-width' : '1','fill':'none'})),
|
'style' : str(inkex.Style({'stroke':'#ff0000','stroke-width':str(self.svg.unittouu("1px")),'fill':'none'})),
|
||||||
'x' : str(bbox.left - self.options.offset),
|
'x' : str(bbox.left - offset),
|
||||||
'y' : str(bbox.top - self.options.offset),
|
'y' : str(bbox.top - offset),
|
||||||
'width' : str(bbox.width + 2 * self.options.offset),
|
'width' : str(bbox.width + 2 * offset),
|
||||||
'height': str(bbox.height + 2 * self.options.offset),
|
'height': str(bbox.height + 2 * offset),
|
||||||
'ry' : str(self.options.corner_radius),
|
'ry' : str(self.options.corner_radius),
|
||||||
'rx' : str(self.options.corner_radius)
|
'rx' : str(self.options.corner_radius)
|
||||||
}
|
}
|
||||||
@ -28,23 +31,42 @@ class BoundingBox(inkex.EffectExtension):
|
|||||||
|
|
||||||
if self.options.circle:
|
if self.options.circle:
|
||||||
attribs = {
|
attribs = {
|
||||||
'style': str(inkex.Style({'stroke':'#ff0000','stroke-width' : '1','fill':'none'})),
|
'style': str(inkex.Style({'stroke':'#ff0000','stroke-width':str(self.svg.unittouu("1px")),'fill':'none'})),
|
||||||
'cx' : str(bbox.center_x),
|
'cx' : str(bbox.center_x),
|
||||||
'cy' : str(bbox.center_y),
|
'cy' : str(bbox.center_y),
|
||||||
#'r' : str(bbox.width / 2 + self.options.offset),
|
#'r' : str(bbox.width / 2 + 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),
|
'r' : str(math.sqrt((bbox.width + 2 * offset)* (bbox.width + 2 * 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):
|
def effect(self):
|
||||||
|
|
||||||
|
scale_factor = self.svg.unittouu("1px")
|
||||||
|
|
||||||
if len(self.svg.selected) > 0:
|
if len(self.svg.selected) > 0:
|
||||||
if self.options.split is False:
|
if self.options.split is False:
|
||||||
for element in self.svg.selected.values():
|
for element in self.svg.selected.values():
|
||||||
self.drawBBox(element.bounding_box())
|
if isinstance (element, inkex.ShapeElement) and element.tag != inkex.addNS('use','svg') and element.get('inkscape:groupmode') != 'layer': #bbox fails for svg:use elements and layers:
|
||||||
|
if isinstance (element, inkex.Rectangle) or \
|
||||||
|
isinstance (element, inkex.Circle) or \
|
||||||
|
isinstance (element, inkex.Ellipse):
|
||||||
|
self.drawBBox(element.bounding_box() * scale_factor)
|
||||||
else:
|
else:
|
||||||
|
self.drawBBox(element.bounding_box())
|
||||||
|
else: #combined bbox
|
||||||
#self.drawBBox(self.svg.get_selected_bbox()) #works for InkScape (1:1.0+devel+202008292235+eff2292935) @ Linux and for Windows (but with deprecation)
|
#self.drawBBox(self.svg.get_selected_bbox()) #works for InkScape (1:1.0+devel+202008292235+eff2292935) @ Linux and for Windows (but with deprecation)
|
||||||
self.drawBBox(self.svg.selection.bounding_box()) #works for InkScape 1.1dev (9b1fc87, 2020-08-27)) @ Windows
|
#self.drawBBox(self.svg.selection.bounding_box()) #works for InkScape 1.1dev (9b1fc87, 2020-08-27)) @ Windows
|
||||||
|
bbox = inkex.BoundingBox()
|
||||||
|
for element in self.svg.selected.values():
|
||||||
|
if isinstance (element, inkex.ShapeElement) and element.tag != inkex.addNS('use','svg') and element.get('inkscape:groupmode') != 'layer': #bbox fails for svg:use elements and layers:
|
||||||
|
if isinstance (element, inkex.Rectangle) or \
|
||||||
|
isinstance (element, inkex.Circle) or \
|
||||||
|
isinstance (element, inkex.Ellipse):
|
||||||
|
bbox += element.bounding_box() * scale_factor
|
||||||
|
else:
|
||||||
|
bbox += element.bounding_box()
|
||||||
|
self.drawBBox(bbox)
|
||||||
else:
|
else:
|
||||||
inkex.errormsg('Please select some objects first.')
|
inkex.errormsg('Please select some objects first.')
|
||||||
return
|
return
|
||||||
|
Reference in New Issue
Block a user