Skip to content

Commit

Permalink
merged from kliment
Browse files Browse the repository at this point in the history
  • Loading branch information
ulrichard committed Feb 2, 2012
2 parents 101f280 + e5b0a4f commit 256145e
Show file tree
Hide file tree
Showing 20 changed files with 5,921 additions and 1,753 deletions.
3,075 changes: 3,075 additions & 0 deletions 20cube_export.gcode

Large diffs are not rendered by default.

35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,48 @@ Printrun consists of printcore, pronsole and pronterface, and a small collection
# INSTALLING DEPENDENCIES

## Windows

A precompiled version is available at http://koti.kapsi.fi/~kliment/printrun/

Download the following, and install in this order:

1. http://python.org/ftp/python/2.7.2/python-2.7.2.msi
2. http://pypi.python.org/packages/any/p/pyserial/pyserial-2.5.win32.exe
3. http://downloads.sourceforge.net/wxpython/wxPython2.8-win32-unicode-2.8.12.0-py27.exe
4. http://launchpad.net/pyreadline/1.7/1.7/+download/pyreadline-1.7.win32.exe
5. http://pyglet.googlecode.com/files/pyglet-1.1.4.zip

For the last one, you will need to unpack it, open a command terminal,
go into the the directory you unpacked it in and run
`python setup.py install`

## Ubuntu/Debian
`sudo apt-get install python-serial python-wxgtk2.8`
`sudo apt-get install python-serial python-wxgtk2.8 python-pyglet`

## Fedora 15
`sudo yum install pyserial wxpython`
`sudo yum install pyserial wxpython pyglet`

## Mac OS X Lion

A precompiled version is available at http://koti.kapsi.fi/~kliment/printrun/

1. Ensure that the active Python is the system version. (`brew uninstall python` or other appropriate incantations)
2. Download an install [wxPython2.8-osx-unicode] matching to your python version (most likely 2.7 on Lion,
check with: python --version) from: http://wxpython.org/download.php#stable
Known to work PythonWX: http://superb-sea2.dl.sourceforge.net/project/wxpython/wxPython/2.8.12.1/wxPython2.8-osx-unicode-2.8.12.1-universal-py2.7.dmg
3. Download and unpack pyserial from http://pypi.python.org/packages/source/p/pyserial/pyserial-2.5.tar.gz
4. In a terminal, change to the folder you unzipped to, then type in: `sudo python setup.py install`
5. Repeat 4. with http://http://pyglet.googlecode.com/files/pyglet-1.1.4.zip

The tools will probably run just fine in 64bit on Lion, you don't need to mess
with any of the 32bit settings. In case they don't, try
5. export VERSIONER_PYTHON_PREFER_32_BIT=yes
in a terminal before running Pronterface

## Mac OS X (pre Lion)

A precompiled version is available at http://koti.kapsi.fi/~kliment/printrun/

1. Download and install http://downloads.sourceforge.net/wxpython/wxPython2.8-osx-unicode-2.8.12.0-universal-py2.6.dmg
2. Grab the source for pyserial from http://pypi.python.org/packages/source/p/pyserial/pyserial-2.5.tar.gz
3. Unzip pyserial to a folder. Then, in a terminal, change to the folder you unzipped to, then type in:
Expand All @@ -52,13 +66,15 @@ This alternative approach is confirmed to work on Mac OS X 10.6.8.
`sudo python setup.py install`

Then repeat the same with http://launchpad.net/pyreadline/trunk/1.7/+download/pyreadline-1.7.zip
Then repeat the same with http://http://pyglet.googlecode.com/files/pyglet-1.1.4.zip

# USING PRONTERFACE

To use pronterface, you need:

* python (ideally 2.6.x or 2.7.x),
* pyserial (or python-serial on ubuntu/debian),
* pyglet
* pyreadline (not needed on Linux) and
* wxPython

Expand Down Expand Up @@ -98,4 +114,19 @@ sender, or the following code example:
p.resume()
p.disconnect()

# LICENSE

```
Printrun 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 3 of the License, or
(at your option) any later version.
Printrun 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 Printrun. If not, see <http://www.gnu.org/licenses/>.
```
73 changes: 54 additions & 19 deletions gviz.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
# This file is part of the Printrun suite.
#
# Printrun 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 3 of the License, or
# (at your option) any later version.
#
# Printrun 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 Printrun. If not, see <http://www.gnu.org/licenses/>.

import wx,time

class window(wx.Frame):
def __init__(self,f,size=(600,600),bedsize=(200,200),grid=(10,50),extrusion_width=0.5):
wx.Frame.__init__(self,None,title="Layer view (Use shift+mousewheel to switch layers)",size=(size[0],size[1]))
self.p=gviz(self,size=size,bedsize=bedsize,grid=grid,extrusion_width=extrusion_width)
def __init__(self,f,size=(600,600),build_dimensions=[200,200,100,0,0,0],grid=(10,50),extrusion_width=0.5):
wx.Frame.__init__(self,None,title="Gcode view, shift to move view, mousewheel to set layer",size=(size[0],size[1]))
self.p=gviz(self,size=size,build_dimensions=build_dimensions,grid=grid,extrusion_width=extrusion_width)
s=time.time()
for i in f:
self.p.addgcode(i)
#print time.time()-s
self.initpos=[0,0]
self.p.Bind(wx.EVT_KEY_DOWN,self.key)
Expand All @@ -15,7 +28,7 @@ def __init__(self,f,size=(600,600),bedsize=(200,200),grid=(10,50),extrusion_widt
self.Bind(wx.EVT_MOUSEWHEEL,self.zoom)
self.p.Bind(wx.EVT_MOUSE_EVENTS,self.mouse)
self.Bind(wx.EVT_MOUSE_EVENTS,self.mouse)

def mouse(self,event):
if event.ButtonUp(wx.MOUSE_BTN_LEFT):
if(self.initpos is not None):
Expand Down Expand Up @@ -53,23 +66,24 @@ def zoom(self, event):
elif z < 0: self.p.zoom(event.GetX(),event.GetY(),1/1.2)

class gviz(wx.Panel):
def __init__(self,parent,size=(200,200),bedsize=(200,200),grid=(10,50),extrusion_width=0.5):
def __init__(self,parent,size=(200,200),build_dimensions=[200,200,100,0,0,0],grid=(10,50),extrusion_width=0.5):
wx.Panel.__init__(self,parent,-1,size=(size[0],size[1]))
self.size=size
self.bedsize=bedsize
self.build_dimensions=build_dimensions
self.grid=grid
self.lastpos=[0,0,0,0,0,0,0]
self.hilightpos=self.lastpos[:]
self.Bind(wx.EVT_PAINT,self.paint)
self.Bind(wx.EVT_SIZE,lambda *e:(wx.CallAfter(self.repaint),wx.CallAfter(self.Refresh)))
self.Bind(wx.EVT_SIZE,self.resize)
self.lines={}
self.pens={}
self.arcs={}
self.arcpens={}
self.layers=[]
self.layerindex=0
self.filament_width=extrusion_width # set it to 0 to disable scaling lines with zoom
self.scale=[min(float(size[0])/bedsize[0],float(size[1])/bedsize[1])]*2
self.basescale=[min(float(size[0])/build_dimensions[0],float(size[1])/build_dimensions[1])]*2
self.scale=self.basescale
penwidth = max(1.0,self.filament_width*((self.scale[0]+self.scale[1])/2.0))
self.translate=[0.0,0.0]
self.mainpen=wx.Pen(wx.Colour(0,0,0),penwidth)
Expand All @@ -88,7 +102,11 @@ def clear(self):
self.lastpos=[0,0,0,0,0,0,0]
self.lines={}
self.pens={}
self.arcs={}
self.arcpens={}
self.layers=[]
self.hilight=[]
self.hilightarcs=[]
self.layerindex=0
self.showall=0
self.dirty=1
Expand All @@ -114,9 +132,16 @@ def setlayer(self,layer):
except:
pass

def resize(self,event):
size=self.GetClientSize()
newsize=min(float(size[0])/self.size[0],float(size[1])/self.size[1])
self.size=self.GetClientSize()
wx.CallAfter(self.zoom,0,0,newsize)


def zoom(self,x,y,factor):
self.scale = [s * factor for s in self.scale]

self.translate = [ x - (x-self.translate[0]) * factor,
y - (y-self.translate[1]) * factor]
penwidth = max(1.0,self.filament_width*((self.scale[0]+self.scale[1])/2.0))
Expand All @@ -126,6 +151,7 @@ def zoom(self,x,y,factor):
self.repaint()
self.Refresh()


def repaint(self):
self.blitmap=wx.EmptyBitmap(self.GetClientSize()[0],self.GetClientSize()[1],-1)
dc=wx.MemoryDC()
Expand All @@ -135,10 +161,10 @@ def repaint(self):
dc.SetPen(wx.Pen(wx.Colour(180,180,150)))
for grid_unit in self.grid:
if grid_unit > 0:
for x in xrange(int(self.bedsize[0]/grid_unit)+1):
dc.DrawLine(self.translate[0]+x*self.scale[0]*grid_unit,self.translate[1],self.translate[0]+x*self.scale[0]*grid_unit,self.translate[1]+self.scale[1]*self.bedsize[1])
for y in xrange(int(self.bedsize[1]/grid_unit)+1):
dc.DrawLine(self.translate[0],self.translate[1]+y*self.scale[1]*grid_unit,self.translate[0]+self.scale[0]*self.bedsize[0],self.translate[1]+y*self.scale[1]*grid_unit)
for x in xrange(int(self.build_dimensions[0]/grid_unit)+1):
dc.DrawLine(self.translate[0]+x*self.scale[0]*grid_unit,self.translate[1],self.translate[0]+x*self.scale[0]*grid_unit,self.translate[1]+self.scale[1]*self.build_dimensions[1])
for y in xrange(int(self.build_dimensions[1]/grid_unit)+1):
dc.DrawLine(self.translate[0],self.translate[1]+y*self.scale[1]*grid_unit,self.translate[0]+self.scale[0]*self.build_dimensions[0],self.translate[1]+y*self.scale[1]*grid_unit)
dc.SetPen(wx.Pen(wx.Colour(0,0,0)))
if not self.showall:
self.size = self.GetSize()
Expand Down Expand Up @@ -200,12 +226,19 @@ def paint(self,event):
dc.DrawBitmap(self.blitmap,0,0)
del dc

def addfile(self,gcodes=[]):
self.clear()
for i in gcodes:
self.addgcode(i)

def addgcode(self,gcode="M105",hilight=0):
gcode=gcode.split("*")[0]
gcode=gcode.split(";")[0]
gcode = gcode.lower().strip().split()
if len(gcode) == 0:
return
if gcode[0][0] == 'n':
gcode.pop(0)

def _readgcode():
target=self.lastpos[:]
Expand Down Expand Up @@ -236,13 +269,15 @@ def _readgcode():
return target

def _y(y):
return self.bedsize[1]-y
return self.build_dimensions[1]-(y-self.build_dimensions[4])
def _x(x):
return x-self.build_dimensions[3]

start_pos = self.hilightpos[:] if hilight else self.lastpos[:]

if gcode[0] == "g1":
target = _readgcode()
line = [ start_pos[0], _y(start_pos[1]), target[0], _y(target[1]) ]
line = [ _x(start_pos[0]), _y(start_pos[1]), _x(target[0]), _y(target[1]) ]
if not hilight:
self.lines[ target[2] ] += [line]
self.pens[ target[2] ] += [self.mainpen if target[3] != self.lastpos[3] else self.travelpen]
Expand All @@ -255,9 +290,9 @@ def _y(y):
if gcode[0] in [ "g2", "g3" ]:
target = _readgcode()
arc = []
arc += [ start_pos[0], _y(start_pos[1]) ]
arc += [ target[0], _y(target[1]) ]
arc += [ start_pos[0] + target[5], _y(start_pos[1] + target[6]) ] # center
arc += [ _x(start_pos[0]), _y(start_pos[1]) ]
arc += [ _x(target[0]), _y(target[1]) ]
arc += [ _x(start_pos[0] + target[5]), _y(start_pos[1] + target[6]) ] # center
if gcode[0] == "g2": # clockwise, reverse endpoints
arc[0], arc[1], arc[2], arc[3] = arc[2], arc[3], arc[0], arc[1]

Expand Down
Loading

0 comments on commit 256145e

Please sign in to comment.