diff --git a/src/VirtualLeaf.cpp b/src/VirtualLeaf.cpp --- a/src/VirtualLeaf.cpp +++ b/src/VirtualLeaf.cpp @@ -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; @@ -429,7 +430,14 @@ 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,19 +502,19 @@ int main(int argc,char **argv) { */ - - ModelCatalogue model_catalogue(&mesh, (Main *)main_window); - model_catalogue.PopulateModelMenu(); - model_catalogue.InstallFirstModel(); + // 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); main_window->FitLeafToCanvas(); - - + main_window->Plot(); diff --git a/src/VirtualLeaf.pro b/src/VirtualLeaf.pro --- a/src/VirtualLeaf.pro +++ b/src/VirtualLeaf.pro @@ -19,8 +19,8 @@ # Copyright 2010 Roeland Merks. # -CONFIG += release -CONFIG -= debug +CONFIG -= release +CONFIG += debug CONFIG += qt QMAKE_CXXFLAGS += -fexceptions diff --git a/src/modelcatalogue.cpp b/src/modelcatalogue.cpp --- a/src/modelcatalogue.cpp +++ b/src/modelcatalogue.cpp @@ -25,10 +25,16 @@ 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; - LoadPlugins(); + 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 plugins; + //QVector 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 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(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); - mainwin->RefreshInfoBar(); -// mesh->StandardInit(); - mainwin->Init(0); + if (mainwin) { + mainwin->RefreshInfoBar(); + //mainwin->Init(0); + } + // mesh->StandardInit(); + } diff --git a/src/modelcatalogue.h b/src/modelcatalogue.h --- a/src/modelcatalogue.h +++ b/src/modelcatalogue.h @@ -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 diff --git a/src/warning.cpp b/src/warning.cpp --- a/src/warning.cpp +++ b/src/warning.cpp @@ -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