Skip to content

Commit

Permalink
Resizing plot and connection plot windows now working.
Browse files Browse the repository at this point in the history
  • Loading branch information
highperformancecoder committed Jul 23, 2024
1 parent dbc8f4b commit 643c872
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 27 deletions.
3 changes: 2 additions & 1 deletion include/arrays.h
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,8 @@ namespace ecolab
typedef T value_type;
typedef size_t size_type;

explicit array(size_t s=0)
array() {set_size(0);}
explicit array(size_t s)
{
set_size(s);
}
Expand Down
14 changes: 4 additions & 10 deletions lib/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,18 @@ def getPlot(name):
plotWindow.eval('load '+ecolabHome()+'/lib/ecolab.so')
plotWindow.eval('image create cairoSurface plotCanvas -surface ecolab '+plotName)
label=ttk.Label(plotWindow, image="plotCanvas")
label.pack()
label.pack(fill='both',expand=True)
windows.append(ref(plotWindow))
return ecolab.__dict__[plotName]

def plot(name,x,*y):
def plot(name,x,*y,pens=[]):
plot=getPlot(name)
if hasattr(y,'__len__') and len(y)==1: y=y[0] # deal with an single array of values being passed
if hasattr(y,'__len__'):
for i in range(len(y)):
plot.addPt(i, x, y[i])
plot.addPt(pens[i] if len(pens)>0 else i, x, y[i])
else:
plot.addPt(0, x, y)
plot.addPt(pens[0] if len(pens)>0 else 0, x, y)
plot.requestRedraw()

def penPlot(name,x,y,pens):
assert len(y)==len(pens)
plot=getPlot(name)
for i in range(len(y)):
plot.addPt(pens[i], x, y[i])
plot.requestRedraw()

10 changes: 6 additions & 4 deletions models/panmictic_ecolab.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
ecolab.repro_max(0.1)
ecolab.odiag_min(-1e-5)
ecolab.odiag_max(1e-5)
ecolab.mut_max(1e-4)
#ecolab.mut_max(1e-4)
ecolab.mut_max(1e-3)
ecolab.sp_sep(0.1)

def randomList(num, min, max):
Expand All @@ -25,16 +26,17 @@ def randomList(num, min, max):
ecolab.mutation(nsp*[ecolab.mut_max()])
ecolab.migration(nsp*[1e-5])

from plot import plot, penPlot
from plot import plot
from GUI import gui, statusBar, windows

from tkinter import Tk,ttk
from weakref import ref
from ecolab import ecolabHome
connectionPlot=Tk()
connectionPlot.wm_title('Connections')
connectionPlot.eval('load '+ecolabHome()+'/lib/ecolab.so')
connectionPlot.eval('image create cairoSurface connectionCanvas -surface ecolab_model panmictic_ecolab.connectionPlot')
ttk.Label(connectionPlot, image='connectionCanvas').pack()
ttk.Label(connectionPlot, image='connectionCanvas').pack(fill='both',expand=True)
windows.append(ref(connectionPlot))
ecolab.updateConnectionPlot()

Expand All @@ -46,7 +48,7 @@ def step():
nsp=len(ecolab.species)
statusBar.configure(text=f't={ecolab.tstep()} nsp:{nsp}')
plot('No. species',ecolab.tstep(),nsp)
penPlot('Density',ecolab.tstep(),ecolab.density()._properties, ecolab.species()._properties)
plot('Density',ecolab.tstep(),ecolab.density()._properties, pens=ecolab.species()._properties)

gui(step)

Expand Down
24 changes: 12 additions & 12 deletions src/cairoSurfaceImage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,15 @@ namespace
{
CairoSurface& csurf;
Tk_ImageMaster imageMaster;
TkWinSurface(CairoSurface& csurf, Tk_ImageMaster imageMaster, cairo_surface_t* surf):
cairo::Surface(surf), csurf(csurf), imageMaster(imageMaster) {/*TkWinSurface::requestRedraw();*/}
int m_width, m_height;
TkWinSurface(CairoSurface& csurf, Tk_ImageMaster imageMaster, cairo_surface_t* surf, int width, int height):
cairo::Surface(surf), csurf(csurf), imageMaster(imageMaster), m_width(width), m_height(height) {}
void requestRedraw() {
Tk_ImageChanged(imageMaster,left(),top(),width(),height(),width(),height());
Tk_ImageChanged(imageMaster,left(),top(),m_width,m_height,m_width,m_height);
}
void blit() {cairo_surface_flush(surface());}
double width() const override {return 500;}
double height() const override {return 500;}
double width() const override {return m_width;}
double height() const override {return m_height;}
};

struct CD
Expand All @@ -91,8 +92,6 @@ namespace
if (CairoSurface* csurf=dynamic_cast<CairoSurface*>(rp->second->getClassdescObject()))
{
*masterData=new CD(0,master,*csurf);
//Tk_ImageChanged(master,-1000000,-1000000,2000000,2000000,2000000,2000000);
// TODO - pass in width/height
Tk_ImageChanged(master,0,0,500,500,500,500);
return TCL_OK;
}
Expand All @@ -118,6 +117,8 @@ namespace
{
clock_t t0=clock();
CD& c=*(CD*)cd;
width=min(width,Tk_Width(c.tkWin));
height=min(height,Tk_Height(c.tkWin));
#ifdef USE_WIN32_SURFACE
// TkWinGetDrawableDC is an internal (ie undocumented) routine
// for getting the DC. We need to declare something to take
Expand All @@ -130,7 +131,7 @@ namespace
c.csurf.surface.reset
(new TkWinSurface
(c.csurf, c.master,
cairo_win32_surface_create(hdc)));
cairo_win32_surface_create(hdc),Tk_Width(c.tkWin)-2, Tk_Height(c.tkWin)-2)));
#elif defined(MAC_OSX_TK)
// calculate the offset of the window within it's toplevel
int xoffs=0, yoffs=0;
Expand All @@ -144,18 +145,17 @@ namespace
c.csurf.surface.reset
(new TkWinSurface
(c.csurf, c.master,
cairo_quartz_surface_create_for_cg_context(nctx.context, Tk_Width(c.tkWin), Tk_Height(c.tkWin))));
cairo_quartz_surface_create_for_cg_context(nctx.context, Tk_Width(c.tkWin), Tk_Height(c.tkWin)),Tk_Width(c.tkWin)-2, Tk_Height(c.tkWin)-2)));
#else
int depth;
Visual *visual = Tk_GetVisual(interp(), c.tkWin, "default", &depth, NULL);
c.csurf.surface.reset
(new TkWinSurface
(c.csurf, c.master,
cairo_xlib_surface_create(display, win, visual, Tk_Width(c.tkWin), Tk_Height(c.tkWin))));
cairo_xlib_surface_create(display, win, visual, Tk_Width(c.tkWin), Tk_Height(c.tkWin)),Tk_Width(c.tkWin)-2, Tk_Height(c.tkWin)-2));
// why subtract 2?

#endif
width=min(width,Tk_Width(c.tkWin));
height=min(height,Tk_Height(c.tkWin));
try
{
c.csurf.redraw(imageX,imageY,width,height);
Expand Down

0 comments on commit 643c872

Please sign in to comment.