skeinforge_tools.stretch ($Date: 2008/21/04 $)
index
/home/enrique/Desktop/backup/babbleold/script/reprap/pyRepRap/skeinforge_tools/stretch.py

Stretch is a script to stretch the threads to partially compensate for filament shrinkage when extruded.
 
The default 'Activate Stretch' checkbox is on.  When it is on, the functions described below will work, when it is off, the functions
will not be called.
 
The important value for the stretch preferences is "Maximum Stretch Over Half Extrusion Width (ratio)" which is the ratio of the
maximum amount the thread will be stretched compared to half of the extrusion width, the default is 0.3.  With a value of one or
more, the script might stretch a couple of threads in opposite directions so much that they overlap.  In theory this would be
because they'll contract back to the desired places, but in practice they might not.  The optimal value of stretch will be different
for different materials, so the default value of 0.3 is chosen because it will counter the contraction a bit, but not enough to
cause overlap trouble.
 
In general, stretch will widen holes and push corners out.  The algorithm works by checking at each turning point on the
extrusion path what the direction of the thread is at a distance of "Stretch from Distance over Extrusion Width (ratio)" times the
extrusion width, on both sides, and moves the thread in the opposite direction.  The magnitude of the stretch increases with the
amount that the direction of the two threads is similar and by the "Maximum Stretch Over Half Extrusion Width (ratio)".  The
script then also stretches the thread at two locations on the path on close to the turning points.  In practice the filament
contraction will be similar but different from the algorithm, so even once the optimal parameters are determined, the stretch
script will not be able to eliminate the inaccuracies caused by contraction, but it should reduce them.  To run stretch, in a shell
type:
> python stretch.py
 
 
The following examples stretch the files Hollow Square.gcode & Hollow Square.gts.  The examples are run in a terminal in the
folder which contains Hollow Square.gcode, Hollow Square.gts and stretch.py.  The stretch function will stretch if 'Maximum
Stretch Over Half Extrusion Width' is greater than zero, which can be set in the dialog or by changing the preferences file
'stretch.csv' with a text editor or a spreadsheet program set to separate tabs.  The functions writeOutput and
getStretchChainGcode check to see if the text has been stretched, if not they call the getRaftChainGcode in raft.py to raft the
text; once they have the rafted text, then they stretch.
 
 
> python stretch.py
This brings up the dialog, after clicking 'Stretch', the following is printed:
File Hollow Square.gts is being chain stretched.
The stretched file is saved as Hollow Square_stretch.gcode
 
 
> python
Python 2.5.1 (r251:54863, Sep 22 2007, 01:43:31)
[GCC 4.2.1 (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import stretch
>>> stretch.main()
This brings up the stretch dialog.
 
 
>>> stretch.writeOutput()
Hollow Square.gts
File Hollow Square.gts is being chain stretched.
The stretched file is saved as Hollow Square_stretch.gcode
 
 
>>> stretch.getStretchGcode("
( GCode generated by May 8, 2008 slice.py )
( Extruder Initialization )
..
many lines of gcode
..
")
 
 
>>> stretch.getStretchChainGcode("
( GCode generated by May 8, 2008 slice.py )
( Extruder Initialization )
..
many lines of gcode
..
")

 
Modules
       
__init__
skeinforge_tools.analyze
cStringIO
skeinforge_tools.skeinforge_utilities.euclidean
skeinforge_tools.skeinforge_utilities.gcodec
skeinforge_tools.import_translator
skeinforge_tools.skeinforge_utilities.intercircle
skeinforge_tools.polyfile
skeinforge_tools.skeinforge_utilities.preferences
skeinforge_tools.raft
sys
time

 
Classes
       
StretchPreferences
StretchSkein

 
class StretchPreferences
    A class to handle the stretch preferences.
 
  Methods defined here:
__init__(self)
Set the default preferences, execute title & preferences filename.
execute(self)
Stretch button has been clicked.

 
class StretchSkein
    A class to stretch a skein of extrusions.
 
  Methods defined here:
__init__(self)
addAlongWayLine(self, alongRatio, location)
Add stretched gcode line, along the way from the old location to the location.
addLine(self, line)
Add a line of text and a newline to the output.
addStretchesBeforePoint(self, location)
Get stretched gcode line.
getRelativeStretch(self, location, lineIndexRange)
Get relative stretch for a location minus a point.
getRounded(self, number)
Get number rounded to the number of carried decimal places as a string.
getStretchedLine(self, splitLine)
Get stretched gcode line.
getStretchedLineFromIndexLocation(self, indexPreviousStart, indexNextStart, location)
Get stretched gcode line from line index and location.
parseGcode(self, gcodeText, stretchPreferences)
Parse gcode text and store the stretch gcode.
parseStretch(self, line)
Parse a gcode line and add it to the stretch skein.

 
Functions
       
getStretchChainGcode(filename, gcodeText, stretchPreferences=None)
Stretch a gcode linear move text.  Chain stretch the gcode if it is not already stretched.
getStretchGcode(gcodeText, stretchPreferences=None)
Stretch a gcode linear move text.
main(hashtable=None)
Display the stretch dialog.
writeOutput(filename='')
Stretch a gcode linear move file.  Chain stretch the gcode if it is not already stretched.  If no filename is specified, stretch the first unmodified gcode file in this folder.

 
Data
        __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
__date__ = '$Date: 2008/21/04 $'
__license__ = 'GPL 3.0'
absolute_import = _Feature((2, 5, 0, 'alpha', 1), (2, 7, 0, 'alpha', 0), 16384)

 
Author
        Enrique Perez (perez_enrique@yahoo.com)