| 1 | /*
|
|---|
| 2 | * CommandLineDialog.cpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: May 8, 2010
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 | #include <cassert>
|
|---|
| 10 | #include <iostream>
|
|---|
| 11 |
|
|---|
| 12 | #include <Descriptors/MoleculeDescriptor.hpp>
|
|---|
| 13 | #include <Descriptors/MoleculeIdDescriptor.hpp>
|
|---|
| 14 | #include "UIElements/CommandLineDialog.hpp"
|
|---|
| 15 |
|
|---|
| 16 | #include "periodentafel.hpp"
|
|---|
| 17 | #include "atom.hpp"
|
|---|
| 18 | #include "CommandLineParser.hpp"
|
|---|
| 19 | #include "defs.hpp"
|
|---|
| 20 | #include "molecule.hpp"
|
|---|
| 21 | #include "log.hpp"
|
|---|
| 22 | #include "verbose.hpp"
|
|---|
| 23 | #include "World.hpp"
|
|---|
| 24 |
|
|---|
| 25 | using namespace std;
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 | CommandLineDialog::CommandLineDialog()
|
|---|
| 29 | {
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | CommandLineDialog::~CommandLineDialog()
|
|---|
| 33 | {
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 | void CommandLineDialog::queryEmpty(const char* title, string _description){
|
|---|
| 38 | registerQuery(new EmptyCommandLineQuery(title, _description));
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | void CommandLineDialog::queryInt(const char* title, int* target, string _description){
|
|---|
| 42 | registerQuery(new IntCommandLineQuery(title,target, _description));
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | void CommandLineDialog::queryDouble(const char* title, double* target, string _description){
|
|---|
| 46 | registerQuery(new DoubleCommandLineQuery(title,target, _description));
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | void CommandLineDialog::queryString(const char* title, string* target, string _description){
|
|---|
| 50 | registerQuery(new StringCommandLineQuery(title,target, _description));
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | void CommandLineDialog::queryMolecule(const char* title, molecule **target, MoleculeListClass *molecules, string _description) {
|
|---|
| 54 | registerQuery(new MoleculeCommandLineQuery(title,target,molecules, _description));
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | void CommandLineDialog::queryVector(const char* title, Vector *target,const double *const cellSize, bool check, string _description) {
|
|---|
| 58 | registerQuery(new VectorCommandLineQuery(title,target,cellSize,check, _description));
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | void CommandLineDialog::queryElement(const char* title, const element **target, string _description){
|
|---|
| 62 | registerQuery(new ElementCommandLineQuery(title,target, _description));
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | /************************** Query Infrastructure ************************/
|
|---|
| 66 |
|
|---|
| 67 | CommandLineDialog::EmptyCommandLineQuery::EmptyCommandLineQuery(string title, string _description) :
|
|---|
| 68 | Dialog::EmptyQuery(title, _description)
|
|---|
| 69 | {}
|
|---|
| 70 |
|
|---|
| 71 | CommandLineDialog::EmptyCommandLineQuery::~EmptyCommandLineQuery() {}
|
|---|
| 72 |
|
|---|
| 73 | bool CommandLineDialog::EmptyCommandLineQuery::handle() {
|
|---|
| 74 | cout << "Message of " << getTitle() << ":\n" << getDescription() << "\n";
|
|---|
| 75 | return true;
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | CommandLineDialog::IntCommandLineQuery::IntCommandLineQuery(string title,int *_target, string _description) :
|
|---|
| 79 | Dialog::IntQuery(title,_target, _description)
|
|---|
| 80 | {}
|
|---|
| 81 |
|
|---|
| 82 | CommandLineDialog::IntCommandLineQuery::~IntCommandLineQuery() {}
|
|---|
| 83 |
|
|---|
| 84 | bool CommandLineDialog::IntCommandLineQuery::handle() {
|
|---|
| 85 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
|---|
| 86 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<int>();
|
|---|
| 87 | return true;
|
|---|
| 88 | } else
|
|---|
| 89 | return false;
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | CommandLineDialog::StringCommandLineQuery::StringCommandLineQuery(string title,string *_target, string _description) :
|
|---|
| 93 | Dialog::StringQuery(title,_target, _description)
|
|---|
| 94 | {}
|
|---|
| 95 |
|
|---|
| 96 | CommandLineDialog::StringCommandLineQuery::~StringCommandLineQuery() {}
|
|---|
| 97 |
|
|---|
| 98 | bool CommandLineDialog::StringCommandLineQuery::handle() {
|
|---|
| 99 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
|---|
| 100 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<string>();
|
|---|
| 101 | return true;
|
|---|
| 102 | } else
|
|---|
| 103 | return false;
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | CommandLineDialog::DoubleCommandLineQuery::DoubleCommandLineQuery(string title,double *_target, string _description) :
|
|---|
| 107 | Dialog::DoubleQuery(title,_target, _description)
|
|---|
| 108 | {}
|
|---|
| 109 |
|
|---|
| 110 | CommandLineDialog::DoubleCommandLineQuery::~DoubleCommandLineQuery() {}
|
|---|
| 111 |
|
|---|
| 112 | bool CommandLineDialog::DoubleCommandLineQuery::handle() {
|
|---|
| 113 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
|---|
| 114 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<double>();
|
|---|
| 115 | return true;
|
|---|
| 116 | } else
|
|---|
| 117 | return false;
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | CommandLineDialog::MoleculeCommandLineQuery::MoleculeCommandLineQuery(string title, molecule **_target, MoleculeListClass *_molecules, string _description) :
|
|---|
| 121 | Dialog::MoleculeQuery(title,_target,_molecules, _description)
|
|---|
| 122 | {}
|
|---|
| 123 |
|
|---|
| 124 | CommandLineDialog::MoleculeCommandLineQuery::~MoleculeCommandLineQuery() {}
|
|---|
| 125 |
|
|---|
| 126 | bool CommandLineDialog::MoleculeCommandLineQuery::handle() {
|
|---|
| 127 | int IdxOfMol = -1;
|
|---|
| 128 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
|---|
| 129 | IdxOfMol = CommandLineParser::getInstance().vm[getTitle()].as<int>();
|
|---|
| 130 | tmp = World::getInstance().getMolecule(MoleculeById(IdxOfMol));
|
|---|
| 131 | return true;
|
|---|
| 132 | } else
|
|---|
| 133 | return false;
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | CommandLineDialog::VectorCommandLineQuery::VectorCommandLineQuery(string title, Vector *_target, const double *const _cellSize, bool _check, string _description) :
|
|---|
| 137 | Dialog::VectorQuery(title,_target,_cellSize,_check, _description)
|
|---|
| 138 | {}
|
|---|
| 139 |
|
|---|
| 140 | CommandLineDialog::VectorCommandLineQuery::~VectorCommandLineQuery()
|
|---|
| 141 | {}
|
|---|
| 142 |
|
|---|
| 143 | bool CommandLineDialog::VectorCommandLineQuery::handle() {
|
|---|
| 144 | vector<double> temp;
|
|---|
| 145 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
|---|
| 146 | temp = CommandLineParser::getInstance().vm[getTitle()].as<vector<double> >();
|
|---|
| 147 | assert((temp.size() == 3) && "Vector from command line does not have three components.");
|
|---|
| 148 | tmp = new Vector;
|
|---|
| 149 | for (int i=0;i<NDIM;i++)
|
|---|
| 150 | tmp->at(i) = temp[i];
|
|---|
| 151 | return true;
|
|---|
| 152 | } else
|
|---|
| 153 | return false;
|
|---|
| 154 | }
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 | CommandLineDialog::ElementCommandLineQuery::ElementCommandLineQuery(string title, const element **target, string _description) :
|
|---|
| 158 | Dialog::ElementQuery(title,target, _description)
|
|---|
| 159 | {}
|
|---|
| 160 |
|
|---|
| 161 | CommandLineDialog::ElementCommandLineQuery::~ElementCommandLineQuery()
|
|---|
| 162 | {}
|
|---|
| 163 |
|
|---|
| 164 | bool CommandLineDialog::ElementCommandLineQuery::handle() {
|
|---|
| 165 | int Z = -1;
|
|---|
| 166 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
|---|
| 167 | Z = CommandLineParser::getInstance().vm[getTitle()].as<int>();
|
|---|
| 168 | tmp = World::getInstance().getPeriode()->FindElement(Z);
|
|---|
| 169 | return true;
|
|---|
| 170 | } else
|
|---|
| 171 | return false;
|
|---|
| 172 | }
|
|---|