The Virtual Leaf
\nThe Virtual Leaf
\nVirtual Leaf
" ""
"Leaf growth computer model
"
"(c) 2005-2007, Roeland Merks
"
"VIB Department Plant Systems Biology
"
"Ghent, Belgium
"
"(c) 2008-2009, Roeland Merks
"
"CWI/NCSB, Amsterdam, Netherlands
"
"Pilot release for WUR/Biometris, 21-10-2009
",
QMessageBox::Information, 1, 0, 0, this, 0, FALSE );
about->setButtonText( 1, "Dismiss" );
about->show();
}
void Main::aboutQt()
{
QMessageBox::aboutQt( this, "Virtual Leaf" );
}
/* void Main::toggleDoubleBuffer()
{
bool s = !options->isItemChecked(dbf_id);
options->setItemChecked(dbf_id,s);
canvas.setDoubleBuffering(s);
}
*/
void Main::toggleShowCellCenters()
{
//bool s = !view->isItemChecked(com_id);
//view->setItemChecked(com_id,s);
Plot();
}
void Main::toggleShowWalls()
{
//bool s = !view->isItemChecked(cell_walls_id);
//view->setItemChecked(cell_walls_id,s);
Plot();
}
void Main::toggleShowApoplasts()
{
Plot();
}
void Main::toggleShowNodes()
{
//bool s = !view->isItemChecked(mesh_id);
//view->setItemChecked(mesh_id,s);
Plot();
}
void Main::toggleNodeNumbers(void) {
//bool s = !view->isItemChecked(node_number_id);
//view->setItemChecked(node_number_id,s);
Plot();
}
void Main::toggleCellNumbers(void) {
//bool s = !view->isItemChecked(cell_number_id);
//view->setItemChecked(cell_number_id,s);
Plot();
}
void Main::toggleCellAxes(void) {
//bool s = !view->isItemChecked(cell_axes_id);
//view->setItemChecked(cell_axes_id,s);
Plot();
}
void Main::toggleCellStrain(void) {
//bool s = !view->isItemChecked(cell_strain_id);
//view->setItemChecked(cell_strain_id,s);
Plot();
}
void Main::toggleShowFluxes(void) {
//bool s = !view->isItemChecked(fluxes_id);
//view->setItemChecked(fluxes_id,s);
Plot();
}
void Main::toggleShowBorderCells()
{
//bool s = !view->isItemChecked(border_id);
//view->setItemChecked(border_id,s);
Plot();
}
void Main::toggleHideCells(void) {
Plot();
editor->FullRedraw();
}
void Main::toggleMovieFrames()
{
//bool s = !view->isItemChecked(movie_frames_id);
//view->setItemChecked(movie_frames_id,s);
}
void Main::toggleLeafBoundary()
{
//bool s = !view->isItemChecked(only_boundary_id);
//view->setItemChecked(only_boundary_id,s);
}
void Main::toggleDynCells()
{
//bool s = !options->isItemChecked(dyn_cells_id);
//options->setItemChecked(dyn_cells_id,s);
}
void Main::startSimulation(void) {
//run->setItemChecked(paused_id, false);
timer->start( 0 );
statusBar()->message("Simulation started");
running = true;
}
void Main::stopSimulation(void) {
//run->setItemChecked(paused_id, true);
timer->stop();
cerr << "Stopping simulation\n";
statusBar()->message("Simulation paused");
running = false;
}
void Main::togglePaused()
{
bool s = run->isItemChecked(paused_id);
if (s) {
cerr << "Calling start simulation\n";
startSimulation();
} else {
cerr << "Calling stop simulation\n";
stopSimulation();
}
}
void Main::setFluxArrowSize(int size) {
flux_arrow_size = size/100.;
}
void Main::enlarge()
{
//canvas.resize(canvas.width()*4/3, canvas.height()*4/3);
canvas.setSceneRect( QRectF( 0,0, canvas.width()*4./3., canvas.height()*4./3.) );
}
void Main::shrink()
{
canvas.setSceneRect( QRectF( 0,0, canvas.width()*3/4, canvas.height()*3/4) );
}
/* void Main::scrollBy(int dx, int dy) {
editor->scrollBy(dx,dy);
}*/
void Main::scale(double factor) {
QMatrix m = editor->matrix();
m.scale(factor, factor);
editor->setMatrix( m );
}
void Main::zoomIn()
{
QMatrix m = editor->matrix();
m.scale( 1.1, 1.1 );
editor->setMatrix( m );
}
void Main::zoomOut()
{
QMatrix m = editor->matrix();
m.scale( 0.9, 0.9 );
editor->setMatrix( m );
}
void Main::print()
{
if ( !printer ) printer = new QPrinter;
if ( printer->setup(this) ) {
// extern Mesh mesh;
Vector bbll,bbur;
mesh.BoundingBox(bbll,bbur);
cerr << "bbll = " << bbll << endl;
cerr << "bbur = " << bbur << endl;
double cw = (bbur.x - bbll.x);
double ch = (bbur.y - bbll.y);
QPainter pp(printer);
QRect vp=pp.viewport();
cerr << "Paper width = " << vp.width() << " x " << vp.height() << endl;
// Note that Cell is also translated...
pp.translate(-bbur.x,-bbur.y);
if (cw>ch) {
pp.scale(vp.width()/(2*cw*Cell::Magnification()), vp.width()/(2*cw*Cell::Magnification()));
} else {
pp.scale(vp.height()/(2*ch*Cell::Magnification()), vp.height()/(2*ch*Cell::Magnification()));
}
canvas.render(&pp, QRectF(), QRectF(0.,0.,canvas.width(),canvas.height()));
}
}
void Main::TimeStepWrap(void) {
static int t=0;
TimeStep();
t++;
// check number of timesteps
if (t==par.nit) {
emit SimulationDone();
}
}
void Main::RestartSim(void) {
stopSimulation();
if ( QMessageBox::question(
this,
tr("Restart simulation?"),
tr("Restart simulation.\n"
"Are you sure?"),
QMessageBox::Yes | QMessageBox::No, QMessageBox::NoButton ) == QMessageBox::Yes ) {
cerr << "Restarting simulation\n";
// extern Mesh mesh;
mesh.Clear();
Init();
Plot();
editor->FullRedraw();
}
//startSimulation();
}
/*
void Main::SaveToGifAnim(void) {
if (gifanim) {
QPixmap image(canvas.width(), canvas.height());
QPainter im(&image);
canvas.drawArea(QRect(0,0,canvas.width(),canvas.height()),&im,FALSE);
QFile conversionpipe;
conversionpipe.open ( IO_WriteOnly, popen("pngtopnm | ppmtogif > tmp.gif", "w") );
image.save( &conversionpipe, "PNG");
conversionpipe.close();
QFile readconvertedimage("tmp.gif");
readconvertedimage.open(IO_ReadOnly);
int c;
while ( (c=readconvertedimage.getch())!=-1) {
gifanim->putch(c);
}
}
}*/
/* void Main::StartGifAnim(QString fname) {
if (gifanim) {
QMessageBox::information( this, "Animation",
"Already making another animation."
"Please end it and try again.",
QMessageBox::Ok );
} else {
QString cmdline("gifsicle --multifile - > ");
cmdline += fname;
gifanim = new QFile;
gifanim->open( IO_WriteOnly,
popen((const char *)cmdline, "w") );
*/ /* QStringList cmdline;
cmdline << "gifsicle" << "--multifile" << "-";
gifanim = new QProcess( cmdline );
cmdline.clear();
cmdline << "pngtopnm";
pngtopnm = new QProcess( cmdline );
pngtopnm->start();
cmdline.clear();
cmdline << "ppmtogif";
ppmtogif = new QProcess( cmdline );
ppmtogif->start();*/
/* }
}*/
/*void Main::EndGifAnim(void) {
if (gifanim)
gifanim->close();
}*/
void Main::FitCanvasToWindow(void) {
double scale_factor_x = (double)editor->width()/(double)canvas.width();
double scale_factor_y = (double)editor->height()/(double)canvas.height();
double scale_factor = scale_factor_x > scale_factor_y ? scale_factor_x : scale_factor_y;
QMatrix m = editor->matrix();
cerr << "editor->width() = " << editor->width() << endl;
cerr << "editor->height() = " << editor->height() << endl;
cerr << "scale_factor = " << scale_factor << endl;
cerr << "scale_factor_x = " << scale_factor_x << endl;
cerr << "scale_factor_y = " << scale_factor_y << endl;
m.scale( scale_factor, scale_factor );
editor->setMatrix( m );
editor->show();
}
void Main::PauseIfRunning(void) {
if (running) {
timer->stop();
}
}
void Main::ContIfRunning(void) {
if (running) {
timer->start( 0 );
}
}
void Main::FitLeafToCanvas(void) {
Vector ll,ur;
mesh.BoundingBox(ll, ur);
ll*=Cell::Magnification(); ur*=Cell::Magnification();
// give the leaf some space
Vector border = ((ur-ll)/5.);
QRectF bb( ll.x - border.x, ll.y - border.y, ur.x-ll.x + 2*border.x, ur.y-ll.y + 2*border.y );
// cerr << ur << ", " << ll << endl;
editor->fitInView(bb, Qt::KeepAspectRatio);
}
void Main::CleanMesh(void) {
vector