Skip to content

Commit

Permalink
v0.3 modifications
Browse files Browse the repository at this point in the history
publication of v0.3
  • Loading branch information
siteswapjuggler committed Aug 26, 2017
1 parent cca5ba7 commit da32b3b
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 207 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
Inkscape_LivingHinge
Inkscape LivingHinge
====================

An Inkscape extension for automating the process of adding cut lines to create a living hinge.

To install:
copy living_hinge.inx and living_hinge.py to the inkscape/extensions directory on your computer.
**v0.3 modifications:**

- New option to choose the direction of the cuts.
- Information text adjustement.
- Category changes to "Fablab" for easier navigation

**To install:**

copy living\_hinge.inx and living\_hinge.py to the inkscape/extensions directory on your computer.

**Licence & Copyrights**

- Licence GNU GPL v3
- Copyright (c) 2013 Mark Endicott
- v0.3 modifications (c) 2017 Sylvain Garnavault
6 changes: 0 additions & 6 deletions copy_files.sh

This file was deleted.

37 changes: 25 additions & 12 deletions living_hinge.inx
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,40 @@
<dependency type="executable" location="extensions">simpletransform.py</dependency>
<dependency type="executable" location="extensions">inkex.py</dependency>

<param name="unit" _gui-text="Unit" type="enum">
<param name="direction" _gui-text="Direction " type="enum">
<_item value="y">vertical cuts</_item>
<_item value="x">horizontal cuts</_item>
</param>

<param name="unit" _gui-text="Unit " type="enum">
<_item value="mm">mm</_item>
<_item value="cm">cm</_item>
<_item value="in">in</_item>
<_item value="px">px</_item>
</param>

<param name="cut_length" type="float" precision="2" _gui-text="cut length (y)" min="1" max="1000">19.0</param>
<param name="gap_length" type="float" precision="2" _gui-text="gap length (y)" min="1" max="1000">3.0</param>
<param name="sep_distance" type="float" precision="2" _gui-text="separation distance (x)" min="1" max="1000">1.5</param>
<param name="help_text" type="description">This extension renders the lines to make the cuts for a living hinge. The cuts run in the y-direction.
cut length: the length of each cut in the y-direction.
gap length: the separation between cut lines in the y-direction.
separation distance: the separation distance in the x-direction between adjacent sets of cut lines.
The entered value for cut length will be adjusted so that an integer number of whole cut lines lies in the y-direction. The entered value for separation distance will be adjusted so that in integer number of cut lines lies in the x-direction.
</param>
<param name="cut_length" type="float" precision="2" _gui-text="cut length" min="1" max="1000">19.0</param>
<param name="gap_length" type="float" precision="2" _gui-text="gap length" min="1" max="1000">3.0</param>
<param name="sep_distance" type="float" precision="2" _gui-text="separation distance" min="1" max="1000">1.5</param>
<param name="help_text" type="description" xml:space="preserve">


This extension renders the lines to make the cuts for a living hinge. The cuts run in the choosen direction.

- direction: choose the direction of the cuts.
- cut length: the length of each cut.
- gap length: the separation between cut lines.
- separation distance: the separation distance between adjacent sets of cut lines.

The entered value for cut length will be adjusted so that an integer number of whole cut lines lies in the rectangle. The entered value for separation distance will be adjusted so that in integer number of cut lines lies in rectangle.


</param>

<effect>
<object-type>all</object-type>
<object-type>all</object-type>
<effects-menu>
<submenu _name="Render" />
<submenu _name="Fablab" />
</effects-menu>
</effect>
<script>
Expand Down
107 changes: 101 additions & 6 deletions living_hinge.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env python
"""
hinge_cuts.py
living_hinge.py
A module for creating lines to laser cut living hinges
Copyright (C) 2013 Mark Endicott; [email protected]
Expand All @@ -21,14 +21,23 @@
"""

"""
Change in version 0.2.
Change in version 0.2
Changed self.unittouu to self.unittouu
and self.uutounit to self.uutounit
to make it work with Inkscape 0.91
Thanks to Pete Prodoehl for pointing this out.
"""

__version__ = "0.2"
"""
Change in version 0.3
Add a direction option so the cuts can be done in the X or Y direction.
Modification by Sylvain GARNAVAULT; [email protected]
"""


__version__ = "0.3"

import sys,inkex,simplestyle,gettext
_ = gettext.gettext
Expand All @@ -46,6 +55,7 @@ def __init__(self):
# Call the base class constructor.
inkex.Effect.__init__(self)
# Define options - Must match to the <param> elements in the .inx file
self.OptionParser.add_option('--direction',action='store',type='string', dest='direction',default='y',help='cuts direction')
self.OptionParser.add_option('--unit',action='store',type='string', dest='unit',default='mm',help='units of measurement')
self.OptionParser.add_option('--cut_length',action='store',type='float', dest='cut_length',default=0,help='length of the cuts for the hinge.')
self.OptionParser.add_option('--gap_length',action='store',type='float', dest='gap_length',default=0,help='separation distance between successive hinge cuts.')
Expand All @@ -54,6 +64,8 @@ def __init__(self):
def effect(self):

unit=self.options.unit
# which direction are we cutting
dir = self.options.direction
# starting cut length. Will be adjusted for get an integer number of cuts in the y-direction.
l = self.unittouu(str(self.options.cut_length) + unit)
# cut separation in the y-direction
Expand All @@ -64,7 +76,7 @@ def effect(self):

# get selected nodes
if self.selected:
# put lines on the current layer
# put lines on the current layer
parent = self.current_layer
for id, node in self.selected.iteritems():
# inkex.debug("id:" + id)
Expand All @@ -76,7 +88,11 @@ def effect(self):
dy = float(node.get("height"))

# calculate the cut lines for the hinge
lines, l_actual, d_actual, dd_actual = self.calcCutLines(x, y, dx, dy, l, d, dd)
if (dir=="y"):
lines, l_actual, d_actual, dd_actual = self.calcYCutLines(x, y, dx, dy, l, d, dd)
else:
lines, l_actual, d_actual, dd_actual = self.calcXCutLines(x, y, dx, dy, l, d, dd)


# all the lines are one path. Prepare the string that describes the path.
s = ''
Expand All @@ -97,7 +113,7 @@ def effect(self):
else:
inkex.debug("No rectangle(s) have been selected.")

def calcCutLines(self, x, y, dx, dy, l, d, dd):
def calcYCutLines(self, x, y, dx, dy, l, d, dd):
"""
Return a list of cut lines as dicts. Each dict contains the end points for one cut line.
[{x1, y1, x2, y2}, ... ]
Expand Down Expand Up @@ -174,7 +190,86 @@ def calcCutLines(self, x, y, dx, dy, l, d, dd):
donex = True

return (ret, l, d, dd)

def calcXCutLines(self, x, y, dx, dy, l, d, dd):
"""
Return a list of cut lines as dicts. Each dict contains the end points for one cut line.
[{x1, y1, x2, y2}, ... ]
Parameters
x, y: the coordinates of the lower left corner of the bounding rect
dx, dy: width and height of the bounding rect
l: the nominal length of a cut line
d: the separation between cut lines in the x-direction
dd: the nominal separation between cut lines in the y-direction
l will be adjusted so that there is an integral number of cuts in the x-direction.
dd will be adjusted so that there is an integral number of cuts in the y-direction.
"""
ret = []

# use l as a starting guess. Adjust it so that we get an integer number of cuts in the y-direction
# First compute the number of cuts in the x-direction using l. This will not in general be an integer.
p = (dx-d)/(d+l)
#round p to the nearest integer
p = round(p)
#compute the new l that will result in p cuts in the x-direction.
l = (dx-d)/p - d

# use dd as a starting guess. Adjust it so that we get an even integer number of cut lines in the y-direction.
p = dy/dd
p = round(p)
if p % 2 == 1:
p = p + 1
dd = dy/p

#
# Rows A cuts
#
curry = 0
doney = False
while not doney:
donex = False
startx = 0
endx = (l + d)/2.0
while not donex:
if endx >= dx:
endx = dx
# Add the end points of the line
ret.append({'x1' : x + startx, 'y1' : y + curry, 'x2': x + endx, 'y2': y + curry})
startx = endx + d
endx = startx + l
if startx >= dx:
donex = True
curry = curry + dd * 2.0
if curry - dy > dd:
doney = True

#
# Rows B cuts
#
curry = dd
doney = False
while not doney:
donex = False
startx = d
endx = startx + l
while not donex:
if endx >= dx:
endx = dx
# create a line
ret.append({'x1' : x + startx, 'y1' : y + curry, 'x2': x + endx, 'y2': y + curry})
startx = endx + d
endx = startx + l
if startx >= dx:
donex = True
curry = curry + dd*2.0
if curry > dy:
doney = True

return (ret, l, d, dd)


# Create effect instance and apply it.
effect = HingeCuts()
effect.affect()
Loading

0 comments on commit da32b3b

Please sign in to comment.