forked from drphonon/Inkscape_LivingHinge
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
publication of v0.3
- Loading branch information
siteswapjuggler
committed
Aug 26, 2017
1 parent
cca5ba7
commit da32b3b
Showing
5 changed files
with
142 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
|
@@ -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 | ||
|
@@ -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.') | ||
|
@@ -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 | ||
|
@@ -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) | ||
|
@@ -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 = '' | ||
|
@@ -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}, ... ] | ||
|
@@ -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() |
Oops, something went wrong.