better bbox resizing for dxf2papercraft, dxfdwgimporter and
papercraft_unfold
This commit is contained in:
parent
93a1009130
commit
4bc3b24572
@ -127,36 +127,16 @@ class PapercraftUnfold(inkex.Effect):
|
|||||||
doc.set('width','')
|
doc.set('width','')
|
||||||
doc.set('height','')
|
doc.set('height','')
|
||||||
doc.set('viewBox','')
|
doc.set('viewBox','')
|
||||||
doc.getchildren()[0].set('transform','')
|
doc.getchildren()[1].set('transform','') #this removes the "transform:scale(1, -1)" from <svg:g id="draft"> child within dxf2papercraft-<id> group
|
||||||
|
|
||||||
#apply scale factor
|
#apply scale factor
|
||||||
node = doc.getchildren()[1]
|
node = doc.getchildren()[1]
|
||||||
translation_matrix = [[self.options.scalefactor, 0.0, 0.0], [0.0, self.options.scalefactor, 0.0]]
|
translation_matrix = [[self.options.scalefactor, 0.0, 0.0], [0.0, self.options.scalefactor, 0.0]]
|
||||||
node.transform = Transform(translation_matrix) * node.transform
|
node.transform = Transform(translation_matrix) * node.transform
|
||||||
|
|
||||||
#Adjust viewport and width/height to have the import at the center of the canvas - unstable at the moment.
|
#Adjust viewport and width/height to have the import at the center of the canvas
|
||||||
if self.options.resizetoimport:
|
if self.options.resizetoimport:
|
||||||
elements = []
|
bbox = inkex.elements._selected.ElementList.bounding_box(node)
|
||||||
for child in doc.getchildren():
|
|
||||||
#if child.tag == inkex.addNS('g','svg'):
|
|
||||||
elements.append(child)
|
|
||||||
|
|
||||||
#build sum of bounding boxes and ignore errors for faulty elements (sum function often fails for that usecase!)
|
|
||||||
bbox = None
|
|
||||||
try:
|
|
||||||
bbox = elements[0].bounding_box() #init with the first bounding box of the tree (and hope that it is not a faulty one)
|
|
||||||
except Exception as e:
|
|
||||||
#inkex.utils.debug(str(e))
|
|
||||||
pass
|
|
||||||
count = 0
|
|
||||||
for element in elements:
|
|
||||||
if count != 0: #skip the first
|
|
||||||
try:
|
|
||||||
bbox += element.bounding_box()
|
|
||||||
except Exception as e:
|
|
||||||
#inkex.utils.debug(str(e))
|
|
||||||
pass
|
|
||||||
count += 1 #some stupid counter
|
|
||||||
if bbox is not None:
|
if bbox is not None:
|
||||||
root = self.svg.getElement('//svg:svg');
|
root = self.svg.getElement('//svg:svg');
|
||||||
offset = self.svg.unittouu(str(self.options.extraborder) + self.options.extraborder_units)
|
offset = self.svg.unittouu(str(self.options.extraborder) + self.options.extraborder_units)
|
||||||
|
@ -427,29 +427,9 @@ class DXFDWGImport(inkex.EffectExtension):
|
|||||||
doc.set('viewBox','')
|
doc.set('viewBox','')
|
||||||
doc.getchildren()[0].set('transform','')
|
doc.getchildren()[0].set('transform','')
|
||||||
|
|
||||||
#adjust viewport and width/height to have the import at the center of the canvas - unstable at the moment.
|
#adjust viewport and width/height to have the import at the center of the canvas
|
||||||
if self.options.resizetoimport:
|
if self.options.resizetoimport:
|
||||||
elements = []
|
bbox = inkex.elements._selected.ElementList.bounding_box(doc.getchildren()[0])
|
||||||
for child in doc.getchildren():
|
|
||||||
#if child.tag == inkex.addNS('g','svg'):
|
|
||||||
elements.append(child)
|
|
||||||
|
|
||||||
#build sum of bounding boxes and ignore errors for faulty elements (sum function often fails for that usecase!)
|
|
||||||
bbox = None
|
|
||||||
try:
|
|
||||||
bbox = elements[0].bounding_box() #init with the first bounding box of the tree (and hope that it is not a faulty one)
|
|
||||||
except Exception as e:
|
|
||||||
#inkex.utils.debug(str(e))
|
|
||||||
pass
|
|
||||||
count = 0
|
|
||||||
for element in elements:
|
|
||||||
if count != 0: #skip the first
|
|
||||||
try:
|
|
||||||
bbox += element.bounding_box()
|
|
||||||
except Exception as e:
|
|
||||||
#inkex.utils.debug(str(e))
|
|
||||||
pass
|
|
||||||
count += 1 #some stupid counter
|
|
||||||
if bbox is not None:
|
if bbox is not None:
|
||||||
root = self.svg.getElement('//svg:svg');
|
root = self.svg.getElement('//svg:svg');
|
||||||
offset = self.svg.unittouu(str(self.options.extraborder) + self.options.extraborder_units)
|
offset = self.svg.unittouu(str(self.options.extraborder) + self.options.extraborder_units)
|
||||||
|
@ -182,30 +182,9 @@ class Unfold(inkex.Effect):
|
|||||||
doc.set('id', self.svg.get_unique_id('papercraft_unfold'))
|
doc.set('id', self.svg.get_unique_id('papercraft_unfold'))
|
||||||
self.document.getroot().append(doc)
|
self.document.getroot().append(doc)
|
||||||
|
|
||||||
#adjust viewport and width/height to have the import at the center of the canvas - unstable at the moment.
|
#adjust viewport and width/height to have the import at the center of the canvas
|
||||||
if self.options.resizetoimport:
|
if self.options.resizetoimport:
|
||||||
elements = []
|
bbox = inkex.elements._selected.ElementList.bounding_box(doc)
|
||||||
for child in doc.getchildren():
|
|
||||||
#if child.tag == inkex.addNS('g','svg'):
|
|
||||||
elements.append(child)
|
|
||||||
|
|
||||||
#build sum of bounding boxes and ignore errors for faulty elements (sum function often fails for that usecase!)
|
|
||||||
bbox = None
|
|
||||||
try:
|
|
||||||
bbox = elements[0].bounding_box() #init with the first bounding box of the tree (and hope that it is not a faulty one)
|
|
||||||
except Exception as e:
|
|
||||||
#inkex.utils.debug(str(e))
|
|
||||||
pass
|
|
||||||
count = 0
|
|
||||||
for element in elements:
|
|
||||||
if count != 0: #skip the first
|
|
||||||
try:
|
|
||||||
#bbox.add(element.bounding_box())
|
|
||||||
bbox += element.bounding_box()
|
|
||||||
except Exception as e:
|
|
||||||
#inkex.utils.debug(str(e))
|
|
||||||
pass
|
|
||||||
count += 1 #some stupid counter
|
|
||||||
if bbox is not None:
|
if bbox is not None:
|
||||||
root = self.svg.getElement('//svg:svg');
|
root = self.svg.getElement('//svg:svg');
|
||||||
offset = self.svg.unittouu(str(self.options.extraborder) + self.options.extraborder_units)
|
offset = self.svg.unittouu(str(self.options.extraborder) + self.options.extraborder_units)
|
||||||
|
Reference in New Issue
Block a user