Commit 4f4b1b4a authored by Erik Jonsson's avatar Erik Jonsson

Made the gviz component resize as the window resizes.

parent 8af5496a
...@@ -3,7 +3,7 @@ import wx,time ...@@ -3,7 +3,7 @@ import wx,time
class window(wx.Frame): class window(wx.Frame):
def __init__(self,f,size=(600,600),bedsize=(200,200),grid=(10,50),extrusion_width=0.5): 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])) 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) self.p=gviz(self, size=size, bedsize=bedsize, grid=grid, extrusion_width=extrusion_width, keepProportions=0)
s=time.time() s=time.time()
for i in f: for i in f:
self.p.addgcode(i) self.p.addgcode(i)
...@@ -53,11 +53,12 @@ class window(wx.Frame): ...@@ -53,11 +53,12 @@ class window(wx.Frame):
elif z < 0: self.p.zoom(event.GetX(),event.GetY(),1/1.2) elif z < 0: self.p.zoom(event.GetX(),event.GetY(),1/1.2)
class gviz(wx.Panel): 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),bedsize=(200,200),grid=(10,50),extrusion_width=0.5,keepProportions=1):
wx.Panel.__init__(self,parent,-1,size=(size[0],size[1])) wx.Panel.__init__(self,parent,-1)
self.size=size self.size=size
self.bedsize=bedsize self.bedsize=bedsize
self.grid=grid self.grid=grid
self.keepProportions = keepProportions
self.lastpos=[0,0,0,0,0] self.lastpos=[0,0,0,0,0]
self.hilightpos=self.lastpos[:] self.hilightpos=self.lastpos[:]
self.Bind(wx.EVT_PAINT,self.paint) self.Bind(wx.EVT_PAINT,self.paint)
...@@ -67,7 +68,7 @@ class gviz(wx.Panel): ...@@ -67,7 +68,7 @@ class gviz(wx.Panel):
self.layers=[] self.layers=[]
self.layerindex=0 self.layerindex=0
self.filament_width=extrusion_width # set it to 0 to disable scaling lines with zoom 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.calculatScale()
penwidth = max(1.0,self.filament_width*((self.scale[0]+self.scale[1])/2.0)) penwidth = max(1.0,self.filament_width*((self.scale[0]+self.scale[1])/2.0))
self.translate=[0.0,0.0] self.translate=[0.0,0.0]
self.mainpen=wx.Pen(wx.Colour(0,0,0),penwidth) self.mainpen=wx.Pen(wx.Colour(0,0,0),penwidth)
...@@ -121,8 +122,29 @@ class gviz(wx.Panel): ...@@ -121,8 +122,29 @@ class gviz(wx.Panel):
self.repaint() self.repaint()
self.Refresh() self.Refresh()
def calculatScale(self):
self.scale=[min(float(self.size[0])/self.bedsize[0],float(self.size[1])/self.bedsize[1])]*2
def setBedsize(self, width, height):
self.bedsize = (width, height)
self.repaint()
self.Refresh()
def adjustSize(self):
width = self.size[0]
height = self.size[1]
wtoh = self.bedsize[1]/self.bedsize[0]
if(width * wtoh > height):
self.size[0] = height/wtoh
elif(height / wtoh > width):
self.size[1] = width*wtoh
def repaint(self): def repaint(self):
self.blitmap=wx.EmptyBitmap(self.GetClientSize()[0],self.GetClientSize()[1],-1) self.size = self.GetSize()
if self.keepProportions:
self.adjustSize()
self.calculatScale()
self.blitmap=wx.EmptyBitmap(self.size[0],self.size[1],-1)
dc=wx.MemoryDC() dc=wx.MemoryDC()
dc.SelectObject(self.blitmap) dc.SelectObject(self.blitmap)
dc.SetBackground(wx.Brush((250,250,200))) dc.SetBackground(wx.Brush((250,250,200)))
......
...@@ -368,7 +368,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -368,7 +368,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
#sizer layout: topsizer is a column sizer containing two sections #sizer layout: topsizer is a column sizer containing two sections
#upper section contains the mini view buttons #upper section contains the mini view buttons
#lower section contains the rest of the window - manual controls, console, visualizations #lower section contains the rest of the window - manual controls, console, visualizations
#TOP ROW: #TOP button ROW:
uts=self.uppertopsizer=wx.BoxSizer(wx.HORIZONTAL) uts=self.uppertopsizer=wx.BoxSizer(wx.HORIZONTAL)
uts.Add(wx.StaticText(self.panel,-1,_("Port:"),pos=(0,5)),wx.TOP|wx.LEFT,5) uts.Add(wx.StaticText(self.panel,-1,_("Port:"),pos=(0,5)),wx.TOP|wx.LEFT,5)
scan=self.scanserial() scan=self.scanserial()
...@@ -415,9 +415,8 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -415,9 +415,8 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
uts.Add((15,-1),flag=wx.EXPAND) uts.Add((15,-1),flag=wx.EXPAND)
uts.Add(self.minibtn) uts.Add(self.minibtn)
#SECOND ROW #SECOND button ROW
ubs=self.upperbottomsizer=wx.BoxSizer(wx.HORIZONTAL) ubs=self.upperbottomsizer=wx.BoxSizer(wx.HORIZONTAL)
self.loadbtn=wx.Button(self.panel,-1,_("Load file"),pos=(0,40)) self.loadbtn=wx.Button(self.panel,-1,_("Load file"),pos=(0,40))
self.loadbtn.Bind(wx.EVT_BUTTON,self.loadfile) self.loadbtn.Bind(wx.EVT_BUTTON,self.loadfile)
ubs.Add(self.loadbtn) ubs.Add(self.loadbtn)
...@@ -437,30 +436,31 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -437,30 +436,31 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
self.pausebtn.Bind(wx.EVT_BUTTON,self.pause) self.pausebtn.Bind(wx.EVT_BUTTON,self.pause)
ubs.Add(self.pausebtn) ubs.Add(self.pausebtn)
ubs.Add((50,-1),flag=wx.EXPAND) ubs.Add((50,-1),flag=wx.EXPAND)
#Right full view
#Log panel full view
lrs=self.lowerrsizer=wx.BoxSizer(wx.VERTICAL) lrs=self.lowerrsizer=wx.BoxSizer(wx.VERTICAL)
self.logbox=wx.TextCtrl(self.panel,size=(350,340),pos=(440,75),style = wx.TE_MULTILINE) self.logbox=wx.TextCtrl(self.panel, style = wx.TE_MULTILINE) #,size=(350,340),pos=(440,75),style = wx.TE_MULTILINE)
self.logbox.SetEditable(0) self.logbox.SetEditable(0)
lrs.Add(self.logbox) lrs.Add(self.logbox, 1, flag=wx.EXPAND)
lbrs=wx.BoxSizer(wx.HORIZONTAL) lbrs=wx.BoxSizer(wx.HORIZONTAL)
self.commandbox=wx.TextCtrl(self.panel,size=(250,30),pos=(440,420),style = wx.TE_PROCESS_ENTER) self.commandbox=wx.TextCtrl(self.panel, style = wx.TE_PROCESS_ENTER) #,size=(250,30),pos=(440,420),style = wx.TE_PROCESS_ENTER)
self.commandbox.Bind(wx.EVT_TEXT_ENTER,self.sendline) self.commandbox.Bind(wx.EVT_TEXT_ENTER, self.sendline)
#self.printerControls.append(self.commandbox) #self.printerControls.append(self.commandbox)
lbrs.Add(self.commandbox) lbrs.Add(self.commandbox, 1, flag=wx.EXPAND)
self.sendbtn=wx.Button(self.panel,-1,_("Send"),pos=(700,420)) self.sendbtn=wx.Button(self.panel, -1, _("Send")) #,pos=(700,420))
self.sendbtn.Bind(wx.EVT_BUTTON,self.sendline) self.sendbtn.Bind(wx.EVT_BUTTON,self.sendline)
#self.printerControls.append(self.sendbtn) #self.printerControls.append(self.sendbtn)
lbrs.Add(self.sendbtn) lbrs.Add(self.sendbtn)
lrs.Add(lbrs) lrs.Add(lbrs, flag=wx.EXPAND)
#left pane #left pane
lls=self.lowerlsizer=wx.GridBagSizer() lls=self.lowerlsizer=wx.GridBagSizer()
lls.Add(wx.StaticText(self.panel,-1,_("mm/min"),pos=(60,69)),pos=(0,4),span=(1,4)) lls.Add(wx.StaticText(self.panel,-1,_("mm/min")),pos=(0,4),span=(1,4))
self.xyfeedc=wx.SpinCtrl(self.panel,-1,str(self.settings.xy_feedrate),min=0,max=50000,size=(70,25),pos=(25,83)) self.xyfeedc=wx.SpinCtrl(self.panel,-1,str(self.settings.xy_feedrate),min=0,max=50000,size=(70,25),pos=(25,83))
lls.Add(wx.StaticText(self.panel,-1,_("XY:"),pos=(2,90-2)),pos=(1,0),span=(1,2)) lls.Add(wx.StaticText(self.panel,-1,_("XY:")),pos=(1,0),span=(1,2))
lls.Add(self.xyfeedc,pos=(1,2),span=(1,4)) lls.Add(self.xyfeedc,pos=(1,2),span=(1,4))
lls.Add(wx.StaticText(self.panel,-1,_("Z:"),pos=(90,90-2)),pos=(1,6),span=(1,2)) lls.Add(wx.StaticText(self.panel,-1,_("Z:")),pos=(1,6),span=(1,2))
self.zfeedc=wx.SpinCtrl(self.panel,-1,str(self.settings.z_feedrate),min=0,max=50000,size=(70,25),pos=(105,83)) self.zfeedc=wx.SpinCtrl(self.panel,-1,str(self.settings.z_feedrate),min=0,max=50000,pos=(105,83))
lls.Add(self.zfeedc,pos=(1,8),span=(1,4)) lls.Add(self.zfeedc,pos=(1,8),span=(1,4))
#lls.Add((200,375)) #lls.Add((200,375))
...@@ -530,9 +530,9 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -530,9 +530,9 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
extrusion_width=self.settings.preview_extrusion_width) extrusion_width=self.settings.preview_extrusion_width)
self.gviz.Bind(wx.EVT_LEFT_DOWN,self.showwin) self.gviz.Bind(wx.EVT_LEFT_DOWN,self.showwin)
self.gwindow.Bind(wx.EVT_CLOSE,lambda x:self.gwindow.Hide()) self.gwindow.Bind(wx.EVT_CLOSE,lambda x:self.gwindow.Hide())
cs=self.centersizer=wx.GridBagSizer() cs=self.centersizer=wx.BoxSizer()
cs.Add(self.gviz,pos=(0,0),span=(1,3)) cs.Add(self.gviz, 1, flag=wx.EXPAND)
lls.Add(cs,pos=(0,10),span=(15,1)) cs.Add((10,10))
self.uppersizer=wx.BoxSizer(wx.VERTICAL) self.uppersizer=wx.BoxSizer(wx.VERTICAL)
self.uppersizer.Add(self.uppertopsizer) self.uppersizer.Add(self.uppertopsizer)
...@@ -540,10 +540,11 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -540,10 +540,11 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
self.lowersizer=wx.BoxSizer(wx.HORIZONTAL) self.lowersizer=wx.BoxSizer(wx.HORIZONTAL)
self.lowersizer.Add(lls) self.lowersizer.Add(lls)
self.lowersizer.Add(lrs) self.lowersizer.Add(cs, 1, flag=wx.EXPAND)
self.lowersizer.Add(lrs, 1, flag=wx.EXPAND)
self.topsizer=wx.BoxSizer(wx.VERTICAL) self.topsizer=wx.BoxSizer(wx.VERTICAL)
self.topsizer.Add(self.uppersizer) self.topsizer.Add(self.uppersizer)
self.topsizer.Add(self.lowersizer) self.topsizer.Add(self.lowersizer, 1, flag=wx.EXPAND)
self.panel.SetSizer(self.topsizer) self.panel.SetSizer(self.topsizer)
self.status=self.CreateStatusBar() self.status=self.CreateStatusBar()
self.status.SetStatusText(_("Not connected to printer.")) self.status.SetStatusText(_("Not connected to printer."))
...@@ -1261,6 +1262,8 @@ class options(wx.Dialog): ...@@ -1261,6 +1262,8 @@ class options(wx.Dialog):
for k,v in pronterface.settings._all_settings().items(): for k,v in pronterface.settings._all_settings().items():
if ctrls[k].GetValue() != str(v): if ctrls[k].GetValue() != str(v):
pronterface.set(k,str(ctrls[k].GetValue())) pronterface.set(k,str(ctrls[k].GetValue()))
pronterface.gviz.setBedsize(pronterface.settings.bed_size_x,
pronterface.settings.bed_size_y)
self.Destroy() self.Destroy()
class ButtonEdit(wx.Dialog): class ButtonEdit(wx.Dialog):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment