Files @ 6bcb69712a0e
Branch filter:

Location: EI/VirtualLeaf/src/mainbase.cpp - annotation

Roeland Merks
In response to referee's comment:

"However, (although it is probably not important for model developers), I was
still unable to load the model ‘Meinhardt 1976 with growth’ example from the
‘Models’ drop down menu, I got the ‘Fatal error’ message ‘stepwise underflow in

rkqs, with h=0.000000 and htry = 0.100000’. The model did work when I selected
the Meinhardt model in both the Models and the File -> Read leaf menus together,
it would be preferable if the models loaded from the Models menu worked

automatically. I am not sure that the update referred to in the author’s
response permits the loading of ‘My First Model in Virtual Leaf’ from the
‘Models’ drop down menu; I only got a cell that wiggled."

I made the following changes:

- meinhardt_plugin now reads "meinhardt_init.xml" by default
- changed the name of 'My First Model in Virtual Leaf’ to '0: Empty model template (does nothing)' to make it clear that the wiggle cell is the intended behavior for this model example.
- Added default parameter files for Tutorial1A-D and Tutorial2 to prevent variable behavior depending on the last parameter settings used.


--
user: Roeland Merks <roeland.merks@cwi.nl>
branch 'default'
added data/leaves/tutorial1_init.xml
added data/leaves/tutorial2_init.xml
changed data/leaves/auxin_growth.xml
changed data/leaves/meinhardt_init.xml
changed src/TutorialCode/Tutorial0/tutorial0.cpp
changed src/TutorialCode/Tutorial1A/tutorial1A.h
changed src/TutorialCode/Tutorial1B/tutorial1B.h
changed src/TutorialCode/Tutorial1C/tutorial1C.h
changed src/TutorialCode/Tutorial1D/tutorial1D.h
changed src/TutorialCode/Tutorial2/tutorial2.h
changed src/build_models/meinhardtplugin.h
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
15d600891648
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
15d600891648
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
4f82fc35a2b3
fba32897839a
fba32897839a
4f82fc35a2b3
79f94eaa3b9e
79f94eaa3b9e
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
15d600891648
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
15d600891648
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
4f82fc35a2b3
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
4f82fc35a2b3
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
15d600891648
782330072e62
15d600891648
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
fba32897839a
fba32897839a
fba32897839a
5ec450ff7c49
782330072e62
5ec450ff7c49
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
5ec450ff7c49
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
/*
 *
 *  This file is part of the Virtual Leaf.
 *
 *  VirtualLeaf 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.
 *
 *  VirtualLeaf 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 the Virtual Leaf.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  Copyright 2010 Roeland Merks.
 *
 */

#include <libxml/xpath.h>
#include <libxml/xmlreader.h>

#include "mainbase.h"
#include "xmlwrite.h"

#include <sstream>
#include <string>

#include <QLocale>
#include <QDir>
#include <QDebug>

static const std::string _module_id("$Id$");

xmlNode *MainBase::XMLViewportTree(QTransform &transform) const {
  
  QLocale standardlocale(QLocale::C);
  

  xmlNode *xmlviewport = xmlNewNode(NULL, BAD_CAST "viewport");
  {
    xmlNewProp(xmlviewport, BAD_CAST "m11", BAD_CAST standardlocale.toString(transform.m11()).toStdString().c_str() );
    xmlNewProp(xmlviewport, BAD_CAST "m12", BAD_CAST standardlocale.toString(transform.m12()).toStdString().c_str() );    
    xmlNewProp(xmlviewport, BAD_CAST "m21", BAD_CAST standardlocale.toString(transform.m21()).toStdString().c_str() );    
    xmlNewProp(xmlviewport, BAD_CAST "m22", BAD_CAST standardlocale.toString(transform.m22()).toStdString().c_str() );    
    xmlNewProp(xmlviewport, BAD_CAST "dx", BAD_CAST standardlocale.toString(transform.dx()).toStdString().c_str() );    
    xmlNewProp(xmlviewport, BAD_CAST "dy", BAD_CAST standardlocale.toString(transform.dy()).toStdString().c_str() );    
 }
  
  return xmlviewport;
}

xmlNode *MainBase::XMLSettingsTree(void) const {

  xmlNode *xmlsettings = xmlNewNode(NULL, BAD_CAST "settings");
  {
    xmlNode *xmloption = xmlNewChild(xmlsettings, NULL, BAD_CAST "setting", NULL);
    xmlNewProp(xmloption, BAD_CAST "name", BAD_CAST "show_cell_centers");
    ostringstream text;
    text << bool_name(showcentersp);
    xmlNewProp(xmloption, BAD_CAST "val", BAD_CAST text.str().c_str());
  }
  {
    xmlNode *xmloption = xmlNewChild(xmlsettings, NULL, BAD_CAST "setting", NULL);
    xmlNewProp(xmloption, BAD_CAST "name", BAD_CAST "show_nodes");
    ostringstream text;
    text << bool_name(showmeshp);
    xmlNewProp(xmloption, BAD_CAST "val", BAD_CAST text.str().c_str());
  }
  {
    xmlNode *xmloption = xmlNewChild(xmlsettings, NULL, BAD_CAST "setting", NULL);
    xmlNewProp(xmloption, BAD_CAST "name", BAD_CAST "show_node_numbers");
    ostringstream text;
    text << bool_name(shownodenumbersp);
    xmlNewProp(xmloption, BAD_CAST "val", BAD_CAST text.str().c_str());
  }
  {
    xmlNode *xmloption = xmlNewChild(xmlsettings, NULL, BAD_CAST "setting", NULL);
    xmlNewProp(xmloption, BAD_CAST "name", BAD_CAST "show_cell_numbers");
    ostringstream text;
    text << bool_name(showcellnumbersp);
    xmlNewProp(xmloption, BAD_CAST "val", BAD_CAST text.str().c_str());
  }
  {
    xmlNode *xmloption = xmlNewChild(xmlsettings, NULL, BAD_CAST "setting", NULL);
    xmlNewProp(xmloption, BAD_CAST "name", BAD_CAST "show_border_cells");
    ostringstream text;
    text << bool_name(showbordercellp);
    xmlNewProp(xmloption, BAD_CAST "val", BAD_CAST text.str().c_str());
  }
  {
    xmlNode *xmloption = xmlNewChild(xmlsettings, NULL, BAD_CAST "setting", NULL);
    xmlNewProp(xmloption, BAD_CAST "name", BAD_CAST "show_cell_axes");
    ostringstream text;
    text << bool_name(showcellsaxesp);
    xmlNewProp(xmloption, BAD_CAST "val", BAD_CAST text.str().c_str());
  }
  {
    xmlNode *xmloption = xmlNewChild(xmlsettings, NULL, BAD_CAST "setting", NULL);
    xmlNewProp(xmloption, BAD_CAST "name", BAD_CAST "show_cell_strain");
    ostringstream text;
    text << bool_name(showcellstrainp);
    xmlNewProp(xmloption, BAD_CAST "val", BAD_CAST text.str().c_str());
  }
  {
    xmlNode *xmloption = xmlNewChild(xmlsettings, NULL, BAD_CAST "setting", NULL);
    xmlNewProp(xmloption, BAD_CAST "name", BAD_CAST "show_fluxes");
    ostringstream text;
    text << bool_name(showfluxesp);
    xmlNewProp(xmloption, BAD_CAST "val", BAD_CAST text.str().c_str());
  }
  {
    xmlNode *xmloption = xmlNewChild(xmlsettings, NULL, BAD_CAST "setting", NULL);
    xmlNewProp(xmloption, BAD_CAST "name", BAD_CAST "show_walls");
    ostringstream text;
    text << bool_name(showwallsp);
    xmlNewProp(xmloption, BAD_CAST "val", BAD_CAST text.str().c_str());
  }
 /* {
    xmlNode *xmloption = xmlNewChild(xmlsettings, NULL, BAD_CAST "setting", NULL);
    xmlNewProp(xmloption, BAD_CAST "name", BAD_CAST "show_apoplasts");
    ostringstream text;
    text << bool_name(showapoplastsp);
    xmlNewProp(xmloption, BAD_CAST "val", BAD_CAST text.str().c_str());
  }*/
  {
    xmlNode *xmloption = xmlNewChild(xmlsettings, NULL, BAD_CAST "setting", NULL);
    xmlNewProp(xmloption, BAD_CAST "name", BAD_CAST "save_movie_frames");
    ostringstream text;
    text << bool_name(movieframesp);
    xmlNewProp(xmloption, BAD_CAST "val", BAD_CAST text.str().c_str());
  }
  {
    xmlNode *xmloption = xmlNewChild(xmlsettings, NULL, BAD_CAST "setting", NULL);
    xmlNewProp(xmloption, BAD_CAST "name", BAD_CAST "show_only_leaf_boundary");
    ostringstream text;
    text << bool_name(showboundaryonlyp);
    xmlNewProp(xmloption, BAD_CAST "val", BAD_CAST text.str().c_str());
  }
  {
    xmlNode *xmloption = xmlNewChild(xmlsettings, NULL, BAD_CAST "setting", NULL);
    xmlNewProp(xmloption, BAD_CAST "name", BAD_CAST "cell_growth");
    ostringstream text;
    text << bool_name(dynamicscellsp);
    xmlNewProp(xmloption, BAD_CAST "val", BAD_CAST text.str().c_str());
  }
  {
    xmlNode *xmloption = xmlNewChild(xmlsettings, NULL, BAD_CAST "setting", NULL);
    xmlNewProp(xmloption, BAD_CAST "name", BAD_CAST "hide_cells");
    ostringstream text;
    text << bool_name(hidecellsp);
    xmlNewProp(xmloption, BAD_CAST "val", BAD_CAST text.str().c_str());
  }
  return xmlsettings;
}

void MainBase::XMLReadViewport(xmlNode *settings) {

  if (settings == 0) {
    return;
  }

  qreal m11=25,m12=0,m21=0,m22=25,dx=0,dy=0;
  QLocale standardlocale(QLocale::C);
  xmlNode *cur = settings->xmlChildrenNode;

  while (cur!=NULL) {
    
    if (!xmlStrcmp(cur->name,(const xmlChar *)"viewport")) {
      bool ok;
      {
	xmlChar *v_str = xmlGetProp(cur, BAD_CAST "m11");
	
	if (v_str==0) {
	  MyWarning::unique_warning("Error reading viewport in mainbase.cpp");
	}
	if (v_str != NULL) {
	  m11=standardlocale.toDouble((char *)v_str, &ok);
	  if (!ok) MyWarning::error("Could Not Convert \"%S\" To Double In XMLRead.",(char *)v_str);
	  xmlFree(v_str);
	}
      }
      {
	xmlChar *v_str = xmlGetProp(cur, BAD_CAST "m12");
	
	if (v_str==0) {
	  MyWarning::unique_warning("Error reading viewport in mainbase.cpp");
	}
	if (v_str != NULL) {
	  m12=standardlocale.toDouble((char *)v_str, &ok);
	  if (!ok) MyWarning::error("Could Not Convert \"%S\" To Double In XMLRead.",(char *)v_str);
	  xmlFree(v_str);
	}
      }
      { 
	xmlChar *v_str = xmlGetProp(cur, BAD_CAST "m21");
	
	if (v_str==0) {
	  MyWarning::unique_warning("Error reading viewport in mainbase.cpp");
	}
	if (v_str != NULL) {
	  m21=standardlocale.toDouble((char *)v_str, &ok);
	  if (!ok) MyWarning::error("Could Not Convert \"%S\" To Double In XMLRead.",(char *)v_str);
	  xmlFree(v_str);
	}
      }
      {
	xmlChar *v_str = xmlGetProp(cur, BAD_CAST "m22");
	
	if (v_str==0) {
	  MyWarning::unique_warning("Error reading viewport in mainbase.cpp");
	}
	if (v_str != NULL) {
	  m22=standardlocale.toDouble((char *)v_str, &ok);
	  if (!ok) MyWarning::error("Could Not Convert \"%S\" To Double In XMLRead.",(char *)v_str);
	  xmlFree(v_str);
	}
      }
      {
	xmlChar *v_str = xmlGetProp(cur, BAD_CAST "dx");
	
	if (v_str==0) {
	  MyWarning::unique_warning("Error reading viewport in mainbase.cpp");
	}
	if (v_str != NULL) {
	  dx=standardlocale.toDouble((char *)v_str, &ok);
	  if (!ok) MyWarning::error("Could Not Convert \"%S\" To Double In XMLRead.",(char *)v_str);
	  xmlFree(v_str);
	}
      }
      {
	xmlChar *v_str = xmlGetProp(cur, BAD_CAST "dy");
	
	if (v_str==0) {
	  MyWarning::unique_warning("Error reading viewport in mainbase.cpp");
	}
	if (v_str != NULL) {
	  dy=standardlocale.toDouble((char *)v_str, &ok);
	  if (!ok) MyWarning::error("Could Not Convert \"%S\" To Double In XMLRead.",(char *)v_str);
	  xmlFree(v_str);
	}
      }
    }
    cur=cur->next;
  }
  viewport = QTransform(m11,m12,m21,m22,dx,dy);
}

void MainBase::XMLReadSettings(xmlNode *settings)
{

  // Many files have no settings section, so don't complain about it.
  // Defaults will be used instead.
  if (settings == 0) {
    return;
  }

  XMLReadViewport(settings);
  xmlNode *cur = settings->xmlChildrenNode;

  while (cur!=NULL) {

    if ((!xmlStrcmp(cur->name, (const xmlChar *)"setting"))){

      xmlChar *name = xmlGetProp(cur, BAD_CAST "name");
    
      xmlChar *val = xmlGetProp(cur, BAD_CAST "val");
      if (!xmlStrcmp(name, (const xmlChar *)"show_cell_centers")) {
	showcentersp = strtobool( (const char *)val );
      }
      if (!xmlStrcmp(name, (const xmlChar *)"show_nodes")) {
	showmeshp = strtobool( (const char *)val );
      }
      if (!xmlStrcmp(name, (const xmlChar *)"show_node_numbers")) {
	shownodenumbersp = strtobool( (const char *)val );
      }
      if (!xmlStrcmp(name, (const xmlChar *)"show_cell_numbers")) {
	showcellnumbersp = strtobool( (const char *)val );
      }
      if (!xmlStrcmp(name, (const xmlChar *)"show_border_cells")) {
	showbordercellp = strtobool( (const char *)val );
      }
      if (!xmlStrcmp(name, (const xmlChar *)"show_cell_axes")) {
	showcellsaxesp = strtobool( (const char *)val );
      }
      if (!xmlStrcmp(name, (const xmlChar *)"show_cell_strain")) {
	showcellstrainp = strtobool( (const char *)val );
      }
      if (!xmlStrcmp(name, (const xmlChar *)"show_fluxes")) {
	showfluxesp = strtobool( (const char *)val );
      }
      if (!xmlStrcmp(name, (const xmlChar *)"show_walls")) {
	showwallsp = strtobool( (const char *)val );
      }
     /* if (!xmlStrcmp(name, (const xmlChar *)"show_apoplasts")) {
	showapoplastsp = strtobool( (const char *)val );
      }*/
      if (!xmlStrcmp(name, (const xmlChar *)"save_movie_frames")) {
	movieframesp = strtobool( (const char *)val );
      }
      if (!xmlStrcmp(name, (const xmlChar *)"show_only_leaf_boundary")) {
	showboundaryonlyp = strtobool( (const char *)val );
      }
      if (!xmlStrcmp(name, (const xmlChar *)"cell_growth")) {
	dynamicscellsp = strtobool( (const char *)val );
      }
      if (!xmlStrcmp(name,(const xmlChar *)"hide_cells")) {
	hidecellsp = strtobool( (const char *)val ); 
      }
    
	
  
      xmlFree(name);
      xmlFree(val);
    }
    cur=cur->next;
  }
}

void MainBase::Save(const char *fname, const char *format, int sizex, int sizey)
{

  Vector ll,ur;
  mesh.BoundingBox(ll, ur);

  if (QString(fname).isEmpty()) {
    MyWarning::warning("No output filename given. Saving nothing.\n");
    return;
  }

  ll*=Cell::Magnification(); ur*=Cell::Magnification();

  // give the leaf some space
  Vector border = ((ur-ll)/5.);

  if (!QString(format).contains("pdf", Qt::CaseInsensitive)) {

    QImage *image = new QImage(QSize(sizex, sizey), QImage::Format_RGB32);
    image->fill(QColor(Qt::white).rgb());
    QPainter *painter=new QPainter(image);
    canvas.render(painter);
#ifdef QDEBUG
    qDebug() << "Native Image Filename: " << QDir::toNativeSeparators(QString(fname)) << endl;
#endif
    if (!image->save(QDir::toNativeSeparators(QString(fname)), format)) {
      MyWarning::warning("Image not saved successfully. Is the disk full or the extension not recognized?");
    }
    delete painter;
    delete image;
  } else {
    QPrinter pdf(QPrinter::HighResolution);
    pdf.setOutputFileName(fname);
    pdf.setOutputFormat(QPrinter::PdfFormat);
    QPainter painter(&pdf);
    canvas.render(&painter, QRectF(), QRectF(-5000,-5000, 10000, 10000));
    
    cerr << "Rendering to printer\n";
  }
}

void MainBase::CutSAM()
{
  mesh.CutAwaySAM();
}

/* finis */