/* * CommandLineDialog.cpp * * Created on: May 8, 2010 * Author: heber */ #include #include #include #include #include "UIElements/CommandLineDialog.hpp" #include "periodentafel.hpp" #include "atom.hpp" #include "CommandLineParser.hpp" #include "defs.hpp" #include "molecule.hpp" #include "log.hpp" #include "verbose.hpp" #include "World.hpp" using namespace std; CommandLineDialog::CommandLineDialog() { } CommandLineDialog::~CommandLineDialog() { } void CommandLineDialog::queryEmpty(const char* title, string _description){ registerQuery(new EmptyCommandLineQuery(title, _description)); } void CommandLineDialog::queryInt(const char* title, int* target, string _description){ registerQuery(new IntCommandLineQuery(title,target, _description)); } void CommandLineDialog::queryDouble(const char* title, double* target, string _description){ registerQuery(new DoubleCommandLineQuery(title,target, _description)); } void CommandLineDialog::queryString(const char* title, string* target, string _description){ registerQuery(new StringCommandLineQuery(title,target, _description)); } void CommandLineDialog::queryMolecule(const char* title, molecule **target, MoleculeListClass *molecules, string _description) { registerQuery(new MoleculeCommandLineQuery(title,target,molecules, _description)); } void CommandLineDialog::queryVector(const char* title, Vector *target,const double *const cellSize, bool check, string _description) { registerQuery(new VectorCommandLineQuery(title,target,cellSize,check, _description)); } void CommandLineDialog::queryElement(const char* title, const element **target, string _description){ registerQuery(new ElementCommandLineQuery(title,target, _description)); } /************************** Query Infrastructure ************************/ CommandLineDialog::EmptyCommandLineQuery::EmptyCommandLineQuery(string title, string _description) : Dialog::EmptyQuery(title, _description) {} CommandLineDialog::EmptyCommandLineQuery::~EmptyCommandLineQuery() {} bool CommandLineDialog::EmptyCommandLineQuery::handle() { cout << "Message of " << getTitle() << ":\n" << getDescription() << "\n"; return true; } CommandLineDialog::IntCommandLineQuery::IntCommandLineQuery(string title,int *_target, string _description) : Dialog::IntQuery(title,_target, _description) {} CommandLineDialog::IntCommandLineQuery::~IntCommandLineQuery() {} bool CommandLineDialog::IntCommandLineQuery::handle() { if (CommandLineParser::getInstance().vm.count(getTitle())) { tmp = CommandLineParser::getInstance().vm[getTitle()].as(); return true; } else return false; } CommandLineDialog::StringCommandLineQuery::StringCommandLineQuery(string title,string *_target, string _description) : Dialog::StringQuery(title,_target, _description) {} CommandLineDialog::StringCommandLineQuery::~StringCommandLineQuery() {} bool CommandLineDialog::StringCommandLineQuery::handle() { if (CommandLineParser::getInstance().vm.count(getTitle())) { tmp = CommandLineParser::getInstance().vm[getTitle()].as(); return true; } else return false; } CommandLineDialog::DoubleCommandLineQuery::DoubleCommandLineQuery(string title,double *_target, string _description) : Dialog::DoubleQuery(title,_target, _description) {} CommandLineDialog::DoubleCommandLineQuery::~DoubleCommandLineQuery() {} bool CommandLineDialog::DoubleCommandLineQuery::handle() { if (CommandLineParser::getInstance().vm.count(getTitle())) { tmp = CommandLineParser::getInstance().vm[getTitle()].as(); return true; } else return false; } CommandLineDialog::MoleculeCommandLineQuery::MoleculeCommandLineQuery(string title, molecule **_target, MoleculeListClass *_molecules, string _description) : Dialog::MoleculeQuery(title,_target,_molecules, _description) {} CommandLineDialog::MoleculeCommandLineQuery::~MoleculeCommandLineQuery() {} bool CommandLineDialog::MoleculeCommandLineQuery::handle() { int IdxOfMol = -1; if (CommandLineParser::getInstance().vm.count(getTitle())) { IdxOfMol = CommandLineParser::getInstance().vm[getTitle()].as(); tmp = World::getInstance().getMolecule(MoleculeById(IdxOfMol)); return true; } else return false; } CommandLineDialog::VectorCommandLineQuery::VectorCommandLineQuery(string title, Vector *_target, const double *const _cellSize, bool _check, string _description) : Dialog::VectorQuery(title,_target,_cellSize,_check, _description) {} CommandLineDialog::VectorCommandLineQuery::~VectorCommandLineQuery() {} bool CommandLineDialog::VectorCommandLineQuery::handle() { vector temp; if (CommandLineParser::getInstance().vm.count(getTitle())) { temp = CommandLineParser::getInstance().vm[getTitle()].as >(); assert((temp.size() == 3) && "Vector from command line does not have three components."); tmp = new Vector; for (int i=0;iat(i) = temp[i]; return true; } else return false; } CommandLineDialog::ElementCommandLineQuery::ElementCommandLineQuery(string title, const element **target, string _description) : Dialog::ElementQuery(title,target, _description) {} CommandLineDialog::ElementCommandLineQuery::~ElementCommandLineQuery() {} bool CommandLineDialog::ElementCommandLineQuery::handle() { int Z = -1; if (CommandLineParser::getInstance().vm.count(getTitle())) { Z = CommandLineParser::getInstance().vm[getTitle()].as(); tmp = World::getInstance().getPeriode()->FindElement(Z); return true; } else return false; }