summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2d107ef)
raw | patch | inline | side by side (parent: 2d107ef)
author | ozmikepittman <ozmikepittman@users.sourceforge.net> | |
Thu, 1 May 2008 08:13:43 +0000 (08:13 +0000) | ||
committer | ozmikepittman <ozmikepittman@users.sourceforge.net> | |
Thu, 1 May 2008 08:13:43 +0000 (08:13 +0000) |
po/POTFILES.in | patch | blob | history | |
share/extensions/Makefile.am | patch | blob | history | |
share/extensions/grid_cartesian.inx | [new file with mode: 0644] | patch | blob |
share/extensions/grid_cartesian.py | [new file with mode: 0644] | patch | blob |
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 8f44328c42d0379a0bc9ab4c1a375efbd6c22a63..944e5dcd3fabd3391f95f9ccf9c9c03fa3250877 100644 (file)
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
[type: gettext/xml] share/extensions/funcplot.inx
[type: gettext/xml] share/extensions/gears.inx
[type: gettext/xml] share/extensions/gimp_xcf.inx
+[type: gettext/xml] share/extensions/grid_cartesian.inx
+[type: gettext/xml] share/extensions/grid_polar.inx
[type: gettext/xml] share/extensions/handles.inx
[type: gettext/xml] share/extensions/inkscape_help_askaquestion.inx
[type: gettext/xml] share/extensions/inkscape_help_commandline.inx
index 84266d19f494a5ab3fa2174a21efb2ca86885f01..003ec92521ab1805e938a1434f124755c6fe6e9a 100644 (file)
funcplot.py \
gears.py\
gimp_xcf.py \
+ grid_cartesian.py \
grid_polar.py \
handles.py \
ill2svg.pl \
funcplot.inx \
gears.inx\
gimp_xcf.inx \
+ grid_cartesian.inx \
grid_polar.inx \
handles.inx \
inkscape_help_askaquestion.inx \
diff --git a/share/extensions/grid_cartesian.inx b/share/extensions/grid_cartesian.inx
--- /dev/null
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">\r
+ <_name>Cartesian Grid</_name>\r
+ <id>grid.cartesian</id>\r
+ <dependency type="executable" location="extensions">grid_cartesian.py</dependency>\r
+ <dependency type="executable" location="extensions">inkex.py</dependency>\r
+ <param name="x_divs" type="int" min="1" max="1000" _gui-text="Major X Divisions">6</param>\r
+ <param name="dx" type="float" min="1" max="1000" _gui-text="Major X Divsion Spacing / px">100.0</param>\r
+ <param name="x_subdivs" type="int" min="1" max="1000" _gui-text="Subdivisions per Major X Division">2</param>\r
+ <param name="x_log" type="boolean" min="0" max="1" _gui-text="Logarithmic X Subdiv. (Base given by entry above)"></param>\r
+ <param name="x_subsubdivs" type="int" min="1" max="1000" _gui-text="Subsubdivs. per X Subdiv.">5</param>\r
+ <param name="x_half_freq" type="int" min="1" max="1000" _gui-text="Halve X Subsubdiv. Frequency after 'n' Subdivs. (log only)">4</param>\r
+ <param name="x_divs_th" type="float" min="0" max="1000" _gui-text="Major X Division Thickness / px">2</param>\r
+ <param name="x_subdivs_th" type="float" min="0" max="1000" _gui-text="Minor X Division Thickness / px">1</param>\r
+ <param name="x_subsubdivs_th" type="float" min="0" max="1000" _gui-text="Subminor X Division Thickness / px">0.3</param>\r
+ <param name="y_divs" type="int" min="1" max="1000" _gui-text="Major Y Divisions">5</param>\r
+ <param name="dy" type="float" min="1" max="1000" _gui-text="Major Y Division Spacing">100.0</param>\r
+ <param name="y_subdivs" type="int" min="1" max="1000" _gui-text="Subdivisions per Major Y Division">1</param>\r
+ <param name="y_log" type="boolean" min="0" max="1" _gui-text="Logarithmic Y Subdiv. (Base given by entry above)"></param>\r
+ <param name="y_subsubdivs" type="int" min="1" max="1000" _gui-text="Subsubdivs. per Y Subdivision">5</param>\r
+ <param name="y_half_freq" type="int" min="1" max="1000" _gui-text="Halve Y Subsubdiv. Frequency after 'n' Subdivs. (log only)">4</param>\r
+ <param name="y_divs_th" type="float" min="0" max="1000" _gui-text="Major Y Division Thickness / px">2</param>\r
+ <param name="y_subdivs_th" type="float" min="0" max="1000" _gui-text="Minor Y Division Thickness / px">1</param>\r
+ <param name="y_subsubdivs_th" type="float" min="0" max="1000" _gui-text="Subminor Y Division Thickness / px">0.3</param>\r
+ <param name="border_th" type="float" min="0" max="1000" _gui-text="Border Thickness / px">3</param>\r
+ \r
+ <effect>\r
+ <object-type>all</object-type>\r
+ <effects-menu>\r
+ <submenu _name="Render"/>\r
+ </effects-menu>\r
+ </effect>\r
+ <script>\r
+ <command reldir="extensions" interpreter="python">grid_cartesian.py</command>\r
+ </script>\r
+</inkscape-extension>
\ No newline at end of file
diff --git a/share/extensions/grid_cartesian.py b/share/extensions/grid_cartesian.py
--- /dev/null
@@ -0,0 +1,264 @@
+#!/usr/bin/env python
+'''
+Copyright (C) 2007 John Beard john.j.beard@gmail.com
+
+##This extension allows you to draw a Cartesian grid in Inkscape.
+##There is a wide range of options including subdivision, subsubdivions
+## and logarithmic scales. Custom line widths are also possible.
+##All elements are grouped with similar elements (eg all x-subdivs)
+
+This program is free software; you can redistribute it and/or modify
+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
+'''\r
+
+import inkex
+import simplestyle, sys
+from math import *
+
+def log_N(base, x): #computes the base-n log of x
+ return log(x)/log(base)
+
+def draw_SVG_line(x1, y1, x2, y2, width, name, parent):
+ style = { 'stroke': '#000000', 'stroke-width':str(width), 'fill': 'none' }
+ line_attribs = {'style':simplestyle.formatStyle(style),
+ 'inkscape:label':name,
+ 'd':'M '+str(x1)+','+str(y1)+' L '+str(x2)+','+str(y2)}
+ inkex.etree.SubElement(parent, inkex.addNS('path','svg'), line_attribs )
+
+def draw_SVG_rect(x,y,w,h, width, fill, name, parent):
+ style = { 'stroke': '#000000', 'stroke-width':str(width), 'fill':fill}
+ rect_attribs = {'style':simplestyle.formatStyle(style),
+ 'inkscape:label':name,
+ 'x':str(x), 'y':str(y), 'width':str(w), 'height':str(h)}
+ inkex.etree.SubElement(parent, inkex.addNS('rect','svg'), rect_attribs )
+
+class Grid_Polar(inkex.Effect):
+ def __init__(self):
+ inkex.Effect.__init__(self)
+ self.OptionParser.add_option("--x_divs",
+ action="store", type="int",
+ dest="x_divs", default=5,
+ help="Major X Divisions")
+ self.OptionParser.add_option("--dx",
+ action="store", type="float",
+ dest="dx", default=100.0,
+ help="Major X divison Spacing")
+ self.OptionParser.add_option("--x_subdivs",
+ action="store", type="int",
+ dest="x_subdivs", default=2,
+ help="Subdivisions per Major X division")
+ self.OptionParser.add_option("--x_log",
+ action="store", type="inkbool",
+ dest="x_log", default=False,
+ help="Logarithmic x subdivisions if true")
+ self.OptionParser.add_option("--x_subsubdivs",
+ action="store", type="int",
+ dest="x_subsubdivs", default=5,
+ help="Subsubdivisions per Minor X division")
+ self.OptionParser.add_option("--x_half_freq",
+ action="store", type="int",
+ dest="x_half_freq", default=4,
+ help="Halve Subsubdiv. Frequency after 'n' Subdivs. (log only)")
+ self.OptionParser.add_option("--x_divs_th",
+ action="store", type="float",
+ dest="x_divs_th", default=2,
+ help="Major X Division Line thickness")
+ self.OptionParser.add_option("--x_subdivs_th",
+ action="store", type="float",
+ dest="x_subdivs_th", default=1,
+ help="Minor X Division Line thickness")
+ self.OptionParser.add_option("--x_subsubdivs_th",
+ action="store", type="float",
+ dest="x_subsubdivs_th", default=1,
+ help="Subminor X Division Line thickness")
+ self.OptionParser.add_option("--y_divs",
+ action="store", type="int",
+ dest="y_divs", default=6,
+ help="Major Y Divisions")
+ self.OptionParser.add_option("--dy",
+ action="store", type="float",
+ dest="dy", default=100.0,
+ help="Major Gridline Increment")
+ self.OptionParser.add_option("--y_subdivs",
+ action="store", type="int",
+ dest="y_subdivs", default=2,
+ help="Minor Divisions per Major Y division")
+ self.OptionParser.add_option("--y_log",
+ action="store", type="inkbool",
+ dest="y_log", default=False,
+ help="Logarithmic y subdivisions if true")
+ self.OptionParser.add_option("--y_subsubdivs",
+ action="store", type="int",
+ dest="y_subsubdivs", default=5,
+ help="Subsubdivisions per Minor Y division")
+ self.OptionParser.add_option("--y_half_freq",
+ action="store", type="int",
+ dest="y_half_freq", default=4,
+ help="Halve Y Subsubdiv. Frequency after 'n' Subdivs. (log only)")
+ self.OptionParser.add_option("--y_divs_th",
+ action="store", type="float",
+ dest="y_divs_th", default=2,
+ help="Major Y Division Line thickness")
+ self.OptionParser.add_option("--y_subdivs_th",
+ action="store", type="float",
+ dest="y_subdivs_th", default=1,
+ help="Minor Y Division Line thickness")
+ self.OptionParser.add_option("--y_subsubdivs_th",
+ action="store", type="float",
+ dest="y_subsubdivs_th", default=1,
+ help="Subminor Y Division Line thickness")
+ self.OptionParser.add_option("--border_th",
+ action="store", type="float",
+ dest="border_th", default=3,
+ help="Border Line thickness")
+
+
+ def effect(self):
+
+ #find the pixel dimensions of the overall grid
+ ymax = self.options.dy * self.options.y_divs
+ xmax = self.options.dx * self.options.x_divs
+
+ # Embed grid in group
+ #Put in in the centre of the current view
+ t = 'translate(' + str( self.view_center[0]- xmax/2.0) + ',' + \
+ str( self.view_center[1]- ymax/2.0) + ')'
+ g_attribs = {inkex.addNS('label','inkscape'):'Grid_Polar:X' + \
+ str( self.options.x_divs )+':Y'+str( self.options.y_divs ),
+ 'transform':t }
+ grid = inkex.etree.SubElement(self.current_layer, 'g', g_attribs)
+
+ #Group for major x gridlines
+ g_attribs = {inkex.addNS('label','inkscape'):'MajorXGridlines'}
+ majglx = inkex.etree.SubElement(grid, 'g', g_attribs)
+
+ #Group for major y gridlines
+ g_attribs = {inkex.addNS('label','inkscape'):'MajorYGridlines'}
+ majgly = inkex.etree.SubElement(grid, 'g', g_attribs)
+
+ #Group for minor x gridlines
+ if self.options.x_subdivs > 1:#if there are any minor x gridlines
+ g_attribs = {inkex.addNS('label','inkscape'):'MinorXGridlines'}
+ minglx = inkex.etree.SubElement(grid, 'g', g_attribs)
+
+ #Group for subminor x gridlines
+ if self.options.x_subsubdivs > 1:#if there are any minor minor x gridlines
+ g_attribs = {inkex.addNS('label','inkscape'):'SubMinorXGridlines'}
+ mminglx = inkex.etree.SubElement(grid, 'g', g_attribs)
+
+ #Group for minor y gridlines
+ if self.options.y_subdivs > 1:#if there are any minor y gridlines
+ g_attribs = {inkex.addNS('label','inkscape'):'MinorYGridlines'}
+ mingly = inkex.etree.SubElement(grid, 'g', g_attribs)
+
+ #Group for subminor y gridlines
+ if self.options.y_subsubdivs > 1:#if there are any minor minor x gridlines
+ g_attribs = {inkex.addNS('label','inkscape'):'SubMinorYGridlines'}
+ mmingly = inkex.etree.SubElement(grid, 'g', g_attribs)
+
+
+ draw_SVG_rect(0, 0, xmax, ymax, self.options.border_th,
+ 'none', 'Border', grid) #border rectangle
+
+ #DO THE X DIVISONS======================================
+ sd = self.options.x_subdivs #sub divs per div
+ ssd = self.options.x_subsubdivs #subsubdivs per subdiv
+
+ for i in range(0, self.options.x_divs): #Major x divisons
+ if i>0: #dont draw first line (we made a proper border)
+ draw_SVG_line(self.options.dx*i, 0,
+ self.options.dx*i,ymax,
+ self.options.x_divs_th,
+ 'MajorXDiv'+str(i), majglx)
+
+ if self.options.x_log: #log x subdivs
+ for j in range (1, sd):
+ if j>1: #the first loop is only for subsubdivs
+ draw_SVG_line(self.options.dx*(i+log_N(sd, j)), 0,
+ self.options.dx*(i+log_N(sd, j)), ymax,
+ self.options.x_subdivs_th,
+ 'MinorXDiv'+str(i)+':'+str(j), minglx)
+
+ for k in range (1, ssd): #subsub divs
+ if (j <= self.options.x_half_freq) or (k%2 == 0):#only draw half the subsubdivs past the half-freq point
+ if (ssd%2 > 0) and (j > self.options.y_half_freq): #half frequency won't work with odd numbers of subsubdivs,
+ ssd2 = ssd+1 #make even
+ else:
+ ssd2 = ssd #no change
+ draw_SVG_line(self.options.dx*(i+log_N(sd, j+k/float(ssd2) )), 0,
+ self.options.dx*(i+log_N(sd, j+k/float(ssd2) )), ymax,
+ self.options.x_subsubdivs_th,'SubminorXDiv'+str(i)+':'+str(j)+':'+str(k), mminglx)
+
+ else: #linear x subdivs
+ for j in range (0, sd):
+ if j>0: #not for the first loop (this loop is for the subsubdivs before the first subdiv)
+ draw_SVG_line(self.options.dx*(i+j/float(sd)), 0,
+ self.options.dx*(i+j/float(sd)), ymax,
+ self.options.x_subdivs_th,
+ 'MinorXDiv'+str(i)+':'+str(j), minglx)
+
+ for k in range (1, ssd): #subsub divs
+ draw_SVG_line(self.options.dx*(i+(j*ssd+k)/((float(sd)*ssd))) , 0,
+ self.options.dx*(i+(j*ssd+k)/((float(sd)*ssd))) , ymax,
+ self.options.x_subsubdivs_th,
+ 'SubminorXDiv'+str(i)+':'+str(j)+':'+str(k), mminglx)
+
+ #DO THE Y DIVISONS========================================
+ sd = self.options.y_subdivs #sub divs per div
+ ssd = self.options.y_subsubdivs #subsubdivs per subdiv
+
+ for i in range(0, self.options.y_divs): #Major y divisons
+ if i>0:#dont draw first line (we will make a border)
+ draw_SVG_line(0, self.options.dy*i,
+ xmax, self.options.dy*i,
+ self.options.y_divs_th,
+ 'MajorYDiv'+str(i), majgly)
+
+ if self.options.y_log: #log y subdivs
+ for j in range (1, sd):
+ if j>1: #the first loop is only for subsubdivs
+ draw_SVG_line(0, self.options.dy*(i+1-log_N(sd, j)),
+ xmax, self.options.dy*(i+1-log_N(sd, j)),
+ self.options.y_subdivs_th,
+ 'MinorXDiv'+str(i)+':'+str(j), mingly)
+
+ for k in range (1, ssd): #subsub divs
+ if (j <= self.options.y_half_freq) or (k%2 == 0):#only draw half the subsubdivs past the half-freq point
+ if (ssd%2 > 0) and (j > self.options.y_half_freq): #half frequency won't work with odd numbers of subsubdivs,
+ ssd2 = ssd+1
+ else:
+ ssd2 = ssd #no change
+ draw_SVG_line(0, self.options.dx*(i+1-log_N(sd, j+k/float(ssd2) )),
+ xmax, self.options.dx*(i+1-log_N(sd, j+k/float(ssd2) )),
+ self.options.y_subsubdivs_th,
+ 'SubminorXDiv'+str(i)+':'+str(j)+':'+str(k), mmingly)
+ else: #linear y subdivs
+ for j in range (0, self.options.y_subdivs):
+ if j>0:#not for the first loop (this loop is for the subsubdivs before the first subdiv)
+ draw_SVG_line(0, self.options.dy*(i+j/float(sd)),
+ xmax, self.options.dy*(i+j/float(sd)),
+ self.options.y_subdivs_th,
+ 'MinorXYiv'+str(i)+':'+str(j), mingly)
+
+ for k in range (1, ssd): #subsub divs
+ draw_SVG_line(0, self.options.dy*(i+(j*ssd+k)/((float(sd)*ssd))),
+ xmax, self.options.dy*(i+(j*ssd+k)/((float(sd)*ssd))),
+ self.options.y_subsubdivs_th,
+ 'SubminorXDiv'+str(i)+':'+str(j)+':'+str(k), mmingly)
+
+
+
+e = Grid_Polar()
+e.affect()
+