measure.py revision 20d0349a1f3c4b7ec90f29c36e56481e2f8c0147
'''
This extension module can measure arbitrary path and object length
It adds a text to the selected path containing the length in a
given unit.
Copyright (C) 2010 Alvin Penner
Copyright (C) 2006 Georg Wiora
Copyright (C) 2006 Nathan Hurst
Copyright (C) 2005 Aaron Spike, aaron@ekips.org
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
TODO:
* should use the standard attributes for text
* Implement option to keep text orientation upright
1. Find text direction i.e. path tangent,
2. check direction >90 or <-90 Degrees
3. rotate by 180 degrees around text center
'''
# Set current system locale
return pointdistance(sp1[1], sp1[2]) + pointdistance(sp1[2], sp2[0]) + pointdistance(sp2[0], sp2[1])
total = 0
lengths = []
total += l
area = 0.0
bezarea = ( 0.0*sp[i-1][1][1] + 2.0*sp[i-1][2][1] + 1.0*sp[i][0][1] - 3.0*sp[i][1][1])*sp[i-1][1][0]
bezarea += (-2.0*sp[i-1][1][1] + 0.0*sp[i-1][2][1] + 1.0*sp[i][0][1] + 1.0*sp[i][1][1])*sp[i-1][2][0]
help="Type of measurement")
help="Display Format")
help="Size of length lable text in px")
help="The distance above the curve")
help="The unit of the measurement")
help="Number of significant digits after decimal point")
help="The distance above the curve")
help="Keep orientation of text upright")
help="The selected UI-tab when OK was pressed")
help="dummy")
# get number of digits
factor = 1.0
# loop over all selected paths
a =[]
else:
# Format the length as string
lenstr = locale.format("%(len)25."+str(prec)+"f",{'len':round(stotal*factor*self.options.scale,prec)}).strip()
self.addTextOnPath(self.group, 0, 0, lenstr+' '+self.options.unit, id, 'start', '50%', self.options.offset)
else:
self.addTextOnPath(self.group, 0, 0, lenstr+' '+self.options.unit+'^2', id, 'start', '0%', self.options.offset)
else:
self.addTextWithTspan(self.group, p[0][0][1][0], p[0][0][1][1], lenstr+' '+self.options.unit, id, 'start', -int(self.options.format), self.options.offset + self.options.fontsize/2)
else:
self.addTextWithTspan(self.group, p[0][0][1][0], p[0][0][1][1], lenstr+' '+self.options.unit+'^2', id, 'start', -int(self.options.format), -self.options.offset + self.options.fontsize/2)
s = {'text-align': 'center', 'vertical-align': 'bottom',
'fill-opacity': '1.0', 'stroke': 'none',
'font-weight': 'normal', 'font-style': 'normal', 'fill': '#000000'}
#new.append(tp)
#node.set('transform','rotate(180,'+str(-x)+','+str(-y)+')')
new = inkex.etree.SubElement(node,inkex.addNS('tspan','svg'), {inkex.addNS('role','sodipodi'): 'line'})
s = {'text-align': 'center', 'vertical-align': 'bottom',
'fill-opacity': '1.0', 'stroke': 'none',
'font-weight': 'normal', 'font-style': 'normal', 'fill': '#000000'}
if __name__ == '__main__':
e = Length()
e.affect()
# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99