Code

Extensions. Gear extension with center hole (see Bug #692719, gear extension should...
authorJazzyNico <nicoduf@yahoo.fr>
Thu, 30 Dec 2010 08:08:48 +0000 (09:08 +0100)
committerJazzyNico <nicoduf@yahoo.fr>
Thu, 30 Dec 2010 08:08:48 +0000 (09:08 +0100)
share/extensions/gears.inx
share/extensions/gears.py

index 8360a3745bee7704e8dfa029d1d91fcbe3110198..ec733fb6bc8a61ae00dc138560cbd60ebf7a2a59 100644 (file)
@@ -5,8 +5,15 @@
     <dependency type="executable" location="extensions">gears.py</dependency>
     <dependency type="executable" location="extensions">inkex.py</dependency>
     <param name="teeth"    type="int"   min="6"    max="360"    _gui-text="Number of teeth:">24</param>
-    <param name="pitch"    type="float" min="0.0"  max="1000.0" _gui-text="Circular pitch (px):">20.0</param>
-    <param name="angle"    type="float" min="10.0" max="30.0"   _gui-text="Pressure angle:">20.0</param>
+    <param name="pitch"    type="float" min="0.0"  max="1000.0" _gui-text="Circular pitch (tooth size):">20.0</param>
+    <param name="angle"    type="float" min="10.0" max="30.0"   _gui-text="Pressure angle (degrees):">20.0</param>
+    <param name="centerdiameter"    type="float" min="0.0" max="1000.0"   _gui-text="Diameter of center hole (0 for none):">20.0</param>
+    <param name="unit" _gui-text="Units:" type="optiongroup" appearance="minimal">
+        <_option value="px">px</_option>
+        <_option value="in">in</_option>
+        <_option value="mm">mm</_option>
+    </param>
+    <param name="unit_text" type="description">Unit of measure for both circular pitch and center diameter.</param>
     <effect>
        <object-type>all</object-type>
         <effects-menu>
index 8f47454239b29f3a29e1c72497522ca58b2e3ae2..a1b3ee666d4b6bb4cd02390f2bd6dd261d7a7556 100644 (file)
@@ -21,6 +21,7 @@ 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)
@@ -55,11 +56,20 @@ class Gears(inkex.Effect):
                         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 = self.options.pitch
+        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
 
@@ -157,6 +167,15 @@ class Gears(inkex.Effect):
         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()