From 9c54e4ae9e74a13735989977a477141c7a5535cf Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Wed, 26 Jun 2013 11:18:52 -0400 Subject: Add render rack gear extension from bug#1174800, modify gears location to render sub-menu Fixed bugs: - https://launchpad.net/bugs/1174800 (bzr r12391) --- share/extensions/gears.inx | 26 ----- share/extensions/gears.py | 185 ---------------------------------- share/extensions/render_gear_rack.inx | 21 ++++ share/extensions/render_gear_rack.py | 105 +++++++++++++++++++ share/extensions/render_gears.inx | 28 +++++ share/extensions/render_gears.py | 185 ++++++++++++++++++++++++++++++++++ 6 files changed, 339 insertions(+), 211 deletions(-) delete mode 100644 share/extensions/gears.inx delete mode 100755 share/extensions/gears.py create mode 100644 share/extensions/render_gear_rack.inx create mode 100644 share/extensions/render_gear_rack.py create mode 100644 share/extensions/render_gears.inx create mode 100755 share/extensions/render_gears.py (limited to 'share/extensions') diff --git a/share/extensions/gears.inx b/share/extensions/gears.inx deleted file mode 100644 index 78d556b4a..000000000 --- a/share/extensions/gears.inx +++ /dev/null @@ -1,26 +0,0 @@ - - - <_name>Gear - org.ekips.filter.gears - gears.py - inkex.py - 24 - 20.0 - 20.0 - 20.0 - - <_option value="px">px - <_option value="in">in - <_option value="mm">mm - - <_param name="unit_text" type="description">Unit of measurement for both circular pitch and center diameter. - - all - - - - - - diff --git a/share/extensions/gears.py b/share/extensions/gears.py deleted file mode 100755 index a1b3ee666..000000000 --- a/share/extensions/gears.py +++ /dev/null @@ -1,185 +0,0 @@ -#! /usr/bin/env python -''' -Copyright (C) 2007 Aaron Spike (aaron @ ekips.org) -Copyright (C) 2007 Tavmjong Bah (tavmjong @ free.fr) - -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 -''' - -import inkex -import simplestyle, sys -from math import * -import string - -def involute_intersect_angle(Rb, R): - Rb, R = float(Rb), float(R) - return (sqrt(R**2 - Rb**2) / (Rb)) - (acos(Rb / R)) - -def point_on_circle(radius, angle): - x = radius * cos(angle) - y = radius * sin(angle) - return (x, y) - -def points_to_svgd(p): - f = p[0] - p = p[1:] - svgd = 'M%.3f,%.3f' % f - for x in p: - svgd += 'L%.3f,%.3f' % x - svgd += 'z' - return svgd - -class Gears(inkex.Effect): - def __init__(self): - inkex.Effect.__init__(self) - self.OptionParser.add_option("-t", "--teeth", - action="store", type="int", - dest="teeth", default=24, - help="Number of teeth") - self.OptionParser.add_option("-p", "--pitch", - action="store", type="float", - dest="pitch", default=20.0, - help="Circular Pitch (length of arc from one tooth to next)") - self.OptionParser.add_option("-a", "--angle", - action="store", type="float", - dest="angle", default=20.0, - help="Pressure Angle (common values: 14.5, 20, 25 degrees)") - self.OptionParser.add_option("-c", "--centerdiameter", - action="store", type="float", - dest="centerdiameter", default=10.0, - help="Diameter of central hole - 0.0 for no hole") - self.OptionParser.add_option("-u", "--unit", - action="store", type="string", - dest="unit", default="px", - help="unit of measure for circular pitch and center diameter") - def effect(self): - - teeth = self.options.teeth - pitch = inkex.unittouu( str(self.options.pitch) + self.options.unit) - angle = self.options.angle # Angle of tangent to tooth at circular pitch wrt radial line. - centerdiameter = inkex.unittouu( str(self.options.centerdiameter) + self.options.unit) - - # print >>sys.stderr, "Teeth: %s\n" % teeth - - two_pi = 2.0 * pi - - # Pitch (circular pitch): Length of the arc from one tooth to the next) - # Pitch diameter: Diameter of pitch circle. - pitch_diameter = float( teeth ) * pitch / pi - pitch_radius = pitch_diameter / 2.0 - - # Base Circle - base_diameter = pitch_diameter * cos( radians( angle ) ) - base_radius = base_diameter / 2.0 - - # Diametrial pitch: Number of teeth per unit length. - pitch_diametrial = float( teeth )/ pitch_diameter - - # Addendum: Radial distance from pitch circle to outside circle. - addendum = 1.0 / pitch_diametrial - - # Outer Circle - outer_radius = pitch_radius + addendum - outer_diameter = outer_radius * 2.0 - - # Tooth thickness: Tooth width along pitch circle. - tooth = ( pi * pitch_diameter ) / ( 2.0 * float( teeth ) ) - - # Undercut? - undercut = (2.0 / ( sin( radians( angle ) ) ** 2)) - needs_undercut = teeth < undercut - - - # Clearance: Radial distance between top of tooth on one gear to bottom of gap on another. - clearance = 0.0 - - # Dedendum: Radial distance from pitch circle to root diameter. - dedendum = addendum + clearance - - # Root diameter: Diameter of bottom of tooth spaces. - root_radius = pitch_radius - dedendum - root_diameter = root_radius * 2.0 - - half_thick_angle = two_pi / (4.0 * float( teeth ) ) - pitch_to_base_angle = involute_intersect_angle( base_radius, pitch_radius ) - pitch_to_outer_angle = involute_intersect_angle( base_radius, outer_radius ) - pitch_to_base_angle - - centers = [(x * two_pi / float( teeth) ) for x in range( teeth ) ] - - points = [] - - for c in centers: - - # Angles - pitch1 = c - half_thick_angle - base1 = pitch1 - pitch_to_base_angle - outer1 = pitch1 + pitch_to_outer_angle - - pitch2 = c + half_thick_angle - base2 = pitch2 + pitch_to_base_angle - outer2 = pitch2 - pitch_to_outer_angle - - # Points - b1 = point_on_circle( base_radius, base1 ) - p1 = point_on_circle( pitch_radius, pitch1 ) - o1 = point_on_circle( outer_radius, outer1 ) - - b2 = point_on_circle( base_radius, base2 ) - p2 = point_on_circle( pitch_radius, pitch2 ) - o2 = point_on_circle( outer_radius, outer2 ) - - if root_radius > base_radius: - pitch_to_root_angle = pitch_to_base_angle - involute_intersect_angle(base_radius, root_radius ) - root1 = pitch1 - pitch_to_root_angle - root2 = pitch2 + pitch_to_root_angle - r1 = point_on_circle(root_radius, root1) - r2 = point_on_circle(root_radius, root2) - p_tmp = [r1,p1,o1,o2,p2,r2] - else: - r1 = point_on_circle(root_radius, base1) - r2 = point_on_circle(root_radius, base2) - p_tmp = [r1,b1,p1,o1,o2,p2,b2,r2] - - points.extend( p_tmp ) - - path = points_to_svgd( points ) - - # Embed gear in group to make animation easier: - # Translate group, Rotate path. - t = 'translate(' + str( self.view_center[0] ) + ',' + str( self.view_center[1] ) + ')' - g_attribs = {inkex.addNS('label','inkscape'):'Gear' + str( teeth ), - 'transform':t } - g = inkex.etree.SubElement(self.current_layer, 'g', g_attribs) - - # Create SVG Path for gear - style = { 'stroke': '#000000', 'fill': 'none' } - gear_attribs = {'style':simplestyle.formatStyle(style), 'd':path} - gear = inkex.etree.SubElement(g, inkex.addNS('path','svg'), gear_attribs ) - if(centerdiameter > 0.0): - center_attribs = {'style':simplestyle.formatStyle(style), - inkex.addNS('cx','sodipodi') :'0.0', - inkex.addNS('cy','sodipodi') :'0.0', - inkex.addNS('rx','sodipodi') :str(centerdiameter/2), - inkex.addNS('ry','sodipodi') :str(centerdiameter/2), - inkex.addNS('type','sodipodi') :'arc' - } - center = inkex.etree.SubElement(g, inkex.addNS('path','svg'), center_attribs ) - -if __name__ == '__main__': - e = Gears() - e.affect() - - -# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99 diff --git a/share/extensions/render_gear_rack.inx b/share/extensions/render_gear_rack.inx new file mode 100644 index 000000000..c7750d806 --- /dev/null +++ b/share/extensions/render_gear_rack.inx @@ -0,0 +1,21 @@ + + + <_name>Rack Gear + org.bg.filter.rackgear + render_gear_rack.py + inkex.py + 100. + 10.0 + 20.0 + + all + + + + + + + + diff --git a/share/extensions/render_gear_rack.py b/share/extensions/render_gear_rack.py new file mode 100644 index 000000000..13eaf1017 --- /dev/null +++ b/share/extensions/render_gear_rack.py @@ -0,0 +1,105 @@ +#! /usr/bin/env python +''' +Copyright (C) 2013 Brett Graham (hahahaha @ hahaha.org) + +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 +''' + +import inkex +import simplestyle +from math import * + + +def involute_intersect_angle(Rb, R): + Rb, R = float(Rb), float(R) + return (sqrt(R**2 - Rb**2) / (Rb)) - (acos(Rb / R)) + + +def point_on_circle(radius, angle): + x = radius * cos(angle) + y = radius * sin(angle) + return (x, y) + + +def points_to_svgd(p): + """ + p: list of 2 tuples (x, y coordinates) + """ + f = p[0] + p = p[1:] + svgd = 'M%.3f,%.3f' % f + for x in p: + svgd += 'L%.3f,%.3f' % x + return svgd + + +class RackGear(inkex.Effect): + def __init__(self): + inkex.Effect.__init__(self) + self.OptionParser.add_option( + "-l", "--length", + action="store", type="float", + dest="length", default=100., + help="Rack Length") + self.OptionParser.add_option( + "-s", "--spacing", + action="store", type="float", + dest="spacing", default=10., + help="Tooth Spacing") + self.OptionParser.add_option( + "-a", "--angle", + action="store", type="float", + dest="angle", default=20., + help="Contact Angle") + + def effect(self): + length = self.options.length + spacing = self.options.spacing + angle = radians(self.options.angle) + + # generate points: list of (x, y) pairs + points = [] + x = 0 + tas = tan(angle) * spacing + while x < length: + # move along path, generating the next 'tooth' + points.append((x, 0)) + points.append((x + tas, spacing)) + points.append((x + spacing, spacing)) + points.append((x + spacing + tas, 0)) + x += spacing * 2. + + path = points_to_svgd(points) + + # Embed gear in group to make animation easier: + # Translate group, Rotate path. + t = 'translate(' + str(self.view_center[0]) + ',' + \ + str(self.view_center[1]) + ')' + g_attribs = { + inkex.addNS('label', 'inkscape'): 'RackGear' + str(length), + 'transform': t} + g = inkex.etree.SubElement(self.current_layer, 'g', g_attribs) + + # Create SVG Path for gear + style = {'stroke': '#000000', 'fill': 'none'} + gear_attribs = { + 'style': simplestyle.formatStyle(style), + 'd': path} + gear = inkex.etree.SubElement( + g, inkex.addNS('path', 'svg'), gear_attribs) + +if __name__ == '__main__': + e = RackGear() + e.affect() diff --git a/share/extensions/render_gears.inx b/share/extensions/render_gears.inx new file mode 100644 index 000000000..13a3afd40 --- /dev/null +++ b/share/extensions/render_gears.inx @@ -0,0 +1,28 @@ + + + <_name>Gear + org.ekips.filter.gears + render_gears.py + inkex.py + 24 + 20.0 + 20.0 + 20.0 + + <_option value="px">px + <_option value="in">in + <_option value="mm">mm + + <_param name="unit_text" type="description">Unit of measurement for both circular pitch and center diameter. + + all + + + + + + + + diff --git a/share/extensions/render_gears.py b/share/extensions/render_gears.py new file mode 100755 index 000000000..a1b3ee666 --- /dev/null +++ b/share/extensions/render_gears.py @@ -0,0 +1,185 @@ +#! /usr/bin/env python +''' +Copyright (C) 2007 Aaron Spike (aaron @ ekips.org) +Copyright (C) 2007 Tavmjong Bah (tavmjong @ free.fr) + +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 +''' + +import inkex +import simplestyle, sys +from math import * +import string + +def involute_intersect_angle(Rb, R): + Rb, R = float(Rb), float(R) + return (sqrt(R**2 - Rb**2) / (Rb)) - (acos(Rb / R)) + +def point_on_circle(radius, angle): + x = radius * cos(angle) + y = radius * sin(angle) + return (x, y) + +def points_to_svgd(p): + f = p[0] + p = p[1:] + svgd = 'M%.3f,%.3f' % f + for x in p: + svgd += 'L%.3f,%.3f' % x + svgd += 'z' + return svgd + +class Gears(inkex.Effect): + def __init__(self): + inkex.Effect.__init__(self) + self.OptionParser.add_option("-t", "--teeth", + action="store", type="int", + dest="teeth", default=24, + help="Number of teeth") + self.OptionParser.add_option("-p", "--pitch", + action="store", type="float", + dest="pitch", default=20.0, + help="Circular Pitch (length of arc from one tooth to next)") + self.OptionParser.add_option("-a", "--angle", + action="store", type="float", + dest="angle", default=20.0, + help="Pressure Angle (common values: 14.5, 20, 25 degrees)") + self.OptionParser.add_option("-c", "--centerdiameter", + action="store", type="float", + dest="centerdiameter", default=10.0, + help="Diameter of central hole - 0.0 for no hole") + self.OptionParser.add_option("-u", "--unit", + action="store", type="string", + dest="unit", default="px", + help="unit of measure for circular pitch and center diameter") + def effect(self): + + teeth = self.options.teeth + pitch = inkex.unittouu( str(self.options.pitch) + self.options.unit) + angle = self.options.angle # Angle of tangent to tooth at circular pitch wrt radial line. + centerdiameter = inkex.unittouu( str(self.options.centerdiameter) + self.options.unit) + + # print >>sys.stderr, "Teeth: %s\n" % teeth + + two_pi = 2.0 * pi + + # Pitch (circular pitch): Length of the arc from one tooth to the next) + # Pitch diameter: Diameter of pitch circle. + pitch_diameter = float( teeth ) * pitch / pi + pitch_radius = pitch_diameter / 2.0 + + # Base Circle + base_diameter = pitch_diameter * cos( radians( angle ) ) + base_radius = base_diameter / 2.0 + + # Diametrial pitch: Number of teeth per unit length. + pitch_diametrial = float( teeth )/ pitch_diameter + + # Addendum: Radial distance from pitch circle to outside circle. + addendum = 1.0 / pitch_diametrial + + # Outer Circle + outer_radius = pitch_radius + addendum + outer_diameter = outer_radius * 2.0 + + # Tooth thickness: Tooth width along pitch circle. + tooth = ( pi * pitch_diameter ) / ( 2.0 * float( teeth ) ) + + # Undercut? + undercut = (2.0 / ( sin( radians( angle ) ) ** 2)) + needs_undercut = teeth < undercut + + + # Clearance: Radial distance between top of tooth on one gear to bottom of gap on another. + clearance = 0.0 + + # Dedendum: Radial distance from pitch circle to root diameter. + dedendum = addendum + clearance + + # Root diameter: Diameter of bottom of tooth spaces. + root_radius = pitch_radius - dedendum + root_diameter = root_radius * 2.0 + + half_thick_angle = two_pi / (4.0 * float( teeth ) ) + pitch_to_base_angle = involute_intersect_angle( base_radius, pitch_radius ) + pitch_to_outer_angle = involute_intersect_angle( base_radius, outer_radius ) - pitch_to_base_angle + + centers = [(x * two_pi / float( teeth) ) for x in range( teeth ) ] + + points = [] + + for c in centers: + + # Angles + pitch1 = c - half_thick_angle + base1 = pitch1 - pitch_to_base_angle + outer1 = pitch1 + pitch_to_outer_angle + + pitch2 = c + half_thick_angle + base2 = pitch2 + pitch_to_base_angle + outer2 = pitch2 - pitch_to_outer_angle + + # Points + b1 = point_on_circle( base_radius, base1 ) + p1 = point_on_circle( pitch_radius, pitch1 ) + o1 = point_on_circle( outer_radius, outer1 ) + + b2 = point_on_circle( base_radius, base2 ) + p2 = point_on_circle( pitch_radius, pitch2 ) + o2 = point_on_circle( outer_radius, outer2 ) + + if root_radius > base_radius: + pitch_to_root_angle = pitch_to_base_angle - involute_intersect_angle(base_radius, root_radius ) + root1 = pitch1 - pitch_to_root_angle + root2 = pitch2 + pitch_to_root_angle + r1 = point_on_circle(root_radius, root1) + r2 = point_on_circle(root_radius, root2) + p_tmp = [r1,p1,o1,o2,p2,r2] + else: + r1 = point_on_circle(root_radius, base1) + r2 = point_on_circle(root_radius, base2) + p_tmp = [r1,b1,p1,o1,o2,p2,b2,r2] + + points.extend( p_tmp ) + + path = points_to_svgd( points ) + + # Embed gear in group to make animation easier: + # Translate group, Rotate path. + t = 'translate(' + str( self.view_center[0] ) + ',' + str( self.view_center[1] ) + ')' + g_attribs = {inkex.addNS('label','inkscape'):'Gear' + str( teeth ), + 'transform':t } + g = inkex.etree.SubElement(self.current_layer, 'g', g_attribs) + + # Create SVG Path for gear + style = { 'stroke': '#000000', 'fill': 'none' } + gear_attribs = {'style':simplestyle.formatStyle(style), 'd':path} + gear = inkex.etree.SubElement(g, inkex.addNS('path','svg'), gear_attribs ) + if(centerdiameter > 0.0): + center_attribs = {'style':simplestyle.formatStyle(style), + inkex.addNS('cx','sodipodi') :'0.0', + inkex.addNS('cy','sodipodi') :'0.0', + inkex.addNS('rx','sodipodi') :str(centerdiameter/2), + inkex.addNS('ry','sodipodi') :str(centerdiameter/2), + inkex.addNS('type','sodipodi') :'arc' + } + center = inkex.etree.SubElement(g, inkex.addNS('path','svg'), center_attribs ) + +if __name__ == '__main__': + e = Gears() + e.affect() + + +# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99 -- cgit v1.2.3 From 53dd41195eb149448a812eec9c32b45b1c455a9a Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Wed, 26 Jun 2013 13:58:57 -0400 Subject: Update makefile for extensions for gears (bzr r12392) --- share/extensions/Makefile.am | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'share/extensions') diff --git a/share/extensions/Makefile.am b/share/extensions/Makefile.am index 5a600be79..468a8e753 100644 --- a/share/extensions/Makefile.am +++ b/share/extensions/Makefile.am @@ -64,7 +64,8 @@ extensions = \ foldablebox.py \ fractalize.py \ funcplot.py \ - gears.py\ + render_gears.py \ + render_gear_rack.py \ gcodetools.py\ generate_voronoi.py \ gimp_xcf.py \ @@ -243,7 +244,8 @@ modules = \ foldablebox.inx \ fractalize.inx \ funcplot.inx \ - gears.inx\ + render_gears.inx \ + render_gear_rack.inx \ gcodetools_about.inx\ gcodetools_area.inx\ gcodetools_check_for_updates.inx\ -- cgit v1.2.3 From 82763271e9c4c490a41968b5729daeba54926251 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Thu, 27 Jun 2013 21:41:38 +0200 Subject: Extensions. Strings consistency fix in Rack gears extension. Translations. Translatable files list, translation template and French translation update. (bzr r12393) --- share/extensions/render_gear_rack.inx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'share/extensions') diff --git a/share/extensions/render_gear_rack.inx b/share/extensions/render_gear_rack.inx index c7750d806..9da3e36e4 100644 --- a/share/extensions/render_gear_rack.inx +++ b/share/extensions/render_gear_rack.inx @@ -4,16 +4,16 @@ org.bg.filter.rackgear render_gear_rack.py inkex.py - 100. - 10.0 - 20.0 + 100. + 10.0 + 20.0 - all + all - +