Changeset - 6d2e1692ec10
[Not reviewed]
default
0 5 0
Roeland Merks - 15 years ago 2010-05-26 10:47:32
roeland.merks@cwi.nl
I've repaired VLeaf's batch mode to work with dynamic model loading. There is a new option now "-m" that allows you to supply a model name.

For example:

./VirtualLeaf -l ../data/leaves/auxin_growth.xml -m libauxingrowth.so -b

or

./VirtualLeaf --leaffile ../data/leaves/auxin_growth.xml --model libauxingrowth.so --batch


user: Roeland Merks <roeland.merks@cwi.nl>
branch 'default'
changed src/VirtualLeaf.cpp
changed src/VirtualLeaf.pro
changed src/modelcatalogue.cpp
changed src/modelcatalogue.h
changed src/warning.cpp
5 files changed with 85 insertions and 20 deletions:
0 comments (0 inline, 0 general)
src/VirtualLeaf.cpp
Show inline comments
 
@@ -388,20 +388,21 @@ int main(int argc,char **argv) {
 

	
 
						
 
    char *leaffile=0;
 

	
 
    char *modelfile=0;
 
						
 
    while (1) {
 
							
 
      //int this_option_optind = optind ? optind : 1;
 
      int option_index = 0;
 
      static struct option long_options[] = {
 
	{"batch", 0, 0, 0},
 
	{"leaffile", 2, 0, 0}
 
	{"batch", no_argument, NULL, 'b'},
 
	{"leaffile", required_argument, NULL, 'l'},
 
	{"model", required_argument, NULL, 'm'} 
 
      };
 
		
 
      // short option 'p' creates trouble for non-commandline usage on MacOSX. Option -p changed to -P (capital)
 
      static char *short_options = "bl";
 
      c = getopt_long (argc, argv, "bl:",
 
      static char *short_options = "blm";
 
      c = getopt_long (argc, argv, "bl:m:",
 
		       long_options, &option_index);
 
      if (c == -1)
 
	break;
 
@@ -430,6 +431,13 @@ int main(int argc,char **argv) {
 
	printf("Reading leaf state file '%s'\n", leaffile);
 
	break;
 
				
 
      case 'm':
 
	modelfile=strdup(optarg);
 
	if (!modelfile) {
 
	  throw("Out of memory");
 
	}
 
	break;
 
					
 
      case '?':
 
	break;
 
				
 
@@ -494,12 +502,13 @@ int main(int argc,char **argv) {
 
	  */
 

	
 
	 	  
 

	
 
	  ModelCatalogue model_catalogue(&mesh, (Main *)main_window);
 
    // Install model or read catalogue of models
 
    ModelCatalogue model_catalogue(&mesh, useGUI?(Main *)main_window:0,modelfile);
 
    if (useGUI)
 
	  model_catalogue.PopulateModelMenu();
 
	  model_catalogue.InstallFirstModel();
 
	  
 
	  //main_window->Init(leaffile);
 
    main_window->Init(leaffile);
 
	  
 
    Cell::SetMagnification(1);
 
    Cell::setOffset(0,0);
 
@@ -507,7 +516,6 @@ int main(int argc,char **argv) {
 
    main_window->FitLeafToCanvas();
 
						
 
				
 
						
 
    main_window->Plot();
 

	
 
						
src/VirtualLeaf.pro
Show inline comments
 
@@ -19,8 +19,8 @@
 
#  Copyright 2010 Roeland Merks.
 
#
 

	
 
CONFIG += release
 
CONFIG -= debug
 
CONFIG -= release
 
CONFIG += debug
 
CONFIG += qt
 

	
 
QMAKE_CXXFLAGS += -fexceptions
src/modelcatalogue.cpp
Show inline comments
 
@@ -25,11 +25,17 @@
 

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

	
 
ModelCatalogue::ModelCatalogue(Mesh *_mesh, Main *_mainwin) {
 
ModelCatalogue::ModelCatalogue(Mesh *_mesh, Main *_mainwin, const char *model=0) {
 
	mesh = _mesh;
 
	mainwin = _mainwin;
 
	if (model) {
 
	  cerr << "Loading model: " << model << endl;
 
		LoadPlugin(model);
 
	} else {
 
	  cerr << "Loading all models." << endl;
 
	LoadPlugins();
 
}
 
}
 

	
 
void ModelCatalogue::LoadPlugins() {
 
	
 
@@ -55,7 +61,7 @@ void ModelCatalogue::LoadPlugins() {
 
	}
 
	
 
	
 
	QVector<SimPluginInterface *> plugins;
 
	//QVector<SimPluginInterface *> plugins;
 
	foreach (QString fileName, pluginDir.entryList(QDir::Files)){ 
 
		QPluginLoader loader(pluginDir.absoluteFilePath(fileName)); 
 
		if (SimPluginInterface *plugin = 
 
@@ -67,6 +73,53 @@ void ModelCatalogue::LoadPlugins() {
 
	}
 
}
 

	
 
void ModelCatalogue::LoadPlugin(const char *model) {
 

	
 
	
 
  QDir pluginDir(QApplication::applicationDirPath()); 
 
  QStringList plugin_filters; // filter for plugins, i.e "*.dll", "*.dylib"
 
	
 
	
 
#if defined(Q_OS_WIN) 
 
  if (pluginDir.dirName().toLower() =="debug" 
 
      ||pluginDir.dirName().toLower() =="release") 
 
    pluginDir.cdUp(); 
 
  //plugin_filters << "*.dll";
 
#elif defined(Q_OS_MAC) 
 
  if (pluginDir.dirName() =="MacOS"){ 
 
    pluginDir.cdUp(); 
 
    pluginDir.cdUp(); 
 
    pluginDir.cdUp(); 
 
  } 
 
  //plugin_filters << "*.dylib";
 
#endif
 
  plugin_filters << model;
 
  pluginDir.setNameFilters(plugin_filters);
 
	
 
  if (!pluginDir.cd("models")) {
 
    MyWarning::error("Directory 'models' not found!");
 
  }
 
	
 
	
 
  //QVector<SimPluginInterface *> plugins;
 
	
 
  QStringList modelnames=pluginDir.entryList(QDir::Files);
 
  if (modelnames.empty()) {
 
    MyWarning::error("Model %s not found - hint: do not include path in filename.",model);
 
  }
 
  foreach (QString fileName, modelnames){ 
 
    QPluginLoader loader(pluginDir.absoluteFilePath(fileName)); 
 
		
 
    if (SimPluginInterface *plugin = 
 
	qobject_cast<SimPluginInterface *>(loader.instance())) {
 
      models.append(plugin); 
 
      MyWarning::warning("Successfully loaded model %s",fileName.toStdString().c_str());
 
    } else {
 
      MyWarning::warning("Could not load plugin %s",fileName.toStdString().c_str());
 
    }
 
  }
 
}
 

	
 
void ModelCatalogue::InstallFirstModel() {
 
	InstallModel(models[0]);
 
}
 
@@ -99,7 +152,10 @@ void ModelCatalogue::InstallModel(SimPlu
 
	Cell::SetNChem(plugin->NChem());
 
	plugin->SetParameters(&par);
 

	
 
	if (mainwin) {
 
	mainwin->RefreshInfoBar();
 
		//mainwin->Init(0);
 
	}
 
//	mesh->StandardInit();
 
	mainwin->Init(0);
 
	></i>
 
}
src/modelcatalogue.h
Show inline comments
 
@@ -41,8 +41,9 @@
 
class ModelCatalogue : public QObject {
 
Q_OBJECT
 
public:
 
	ModelCatalogue(Mesh *mesh, Main *mainwin); 	
 
	ModelCatalogue(Mesh *mesh, Main *mainwin, const char *model); 	
 
	void LoadPlugins(); 
 
	void LoadPlugin(const char *model);
 
	
 
	void InstallFirstModel();
 
	void PopulateModelMenu();	
 
@@ -56,4 +57,4 @@ private:
 
	Main *mainwin;
 

	
 
};
 
#endif
 
\ No newline at end of file
 
#endif
src/warning.cpp
Show inline comments
 
@@ -66,9 +66,9 @@ void MyWarning::error(const char *fmt, .
 
  
 
  QString qmess(message);
 
  
 
  bool batch = false;
 
  //  bool batch = false;
 
  
 
  if (batch) {
 
  if (qApp->type()==QApplication::Tty) {
 
    // batch mode: print the message to stderr
 
    fprintf(stderr, "Fatal error: %s\n",qmess.toStdString().c_str());
 
    exit(1);
 
@@ -123,9 +123,9 @@ void MyWarning::warning(const char *fmt,
 
  
 
  QString qmess(message);
 
  
 
  bool batch = false;
 
  //  bool batch = false;
 
  
 
  if (batch) {
 
  if (qApp->type()==QApplication::Tty) {
 
    // batch mode: print the message to stderr
 
    fprintf(stderr, "Warning: %s\n",qmess.toStdString().c_str());
 
  } else { // issue a dialog box
0 comments (0 inline, 0 general)