# 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 . import wx,time class window(wx.Frame): 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) self.CreateStatusBar(1); self.SetStatusText("Layer number and Z position show here when you scroll"); s=time.time() #print time.time()-s self.initpos=[0,0] self.p.Bind(wx.EVT_KEY_DOWN,self.key) self.Bind(wx.EVT_KEY_DOWN,self.key) self.p.Bind(wx.EVT_MOUSEWHEEL,self.zoom) 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): self.initpos=None elif event.Dragging(): e=event.GetPositionTuple() if self.initpos is None or not hasattr(self,"basetrans"): self.initpos=e self.basetrans=self.p.translate #print self.p.translate,e,self.initpos self.p.translate = [ self.basetrans[0]+(e[0]-self.initpos[0]), self.basetrans[1]+(e[1]-self.initpos[1]) ] self.p.repaint() self.p.Refresh() else: event.Skip() def key(self, event): x=event.GetKeyCode() if event.ShiftDown(): cx,cy=self.p.translate if x==wx.WXK_UP: self.p.zoom(cx,cy,1.2) if x==wx.WXK_DOWN: self.p.zoom(cx,cy,1/1.2) else: if x==wx.WXK_UP: self.p.layerup() if x==wx.WXK_DOWN: self.p.layerdown() #print x #print p.lines.keys() def zoom(self, event): z=event.GetWheelRotation() if event.ShiftDown(): if z > 0: self.p.layerdown() elif z < 0: self.p.layerup() else: if z > 0: self.p.zoom(event.GetX(),event.GetY(),1.2) elif z < 0: self.p.zoom(event.GetX(),event.GetY(),1/1.2) class gviz(wx.Panel): 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.parent=parent self.size=size 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,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.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) self.arcpen=wx.Pen(wx.Colour(255,0,0),penwidth) self.travelpen=wx.Pen(wx.Colour(10,80,80),penwidth) self.hlpen=wx.Pen(wx.Colour(200,50,50),penwidth) self.fades=[wx.Pen(wx.Colour(250-0.6**i*100,250-0.6**i*100,200-0.4**i*50),penwidth) for i in xrange(6)] self.penslist=[self.mainpen,self.travelpen,self.hlpen]+self.fades self.showall=0 self.hilight=[] self.hilightarcs=[] self.dirty=1 self.blitmap=wx.EmptyBitmap(self.GetClientSize()[0],self.GetClientSize()[1],-1) 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 #self.repaint() def layerup(self): if(self.layerindex+1