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::queryInt(const char* title, int* target){
|
---|
38 | registerQuery(new IntTextQuery(title,target));
|
---|
39 | }
|
---|
40 |
|
---|
41 | void CommandLineDialog::queryDouble(const char* title, double* target){
|
---|
42 | registerQuery(new DoubleTextQuery(title,target));
|
---|
43 | }
|
---|
44 |
|
---|
45 | void CommandLineDialog::queryString(const char* title, string* target){
|
---|
46 | registerQuery(new StringTextQuery(title,target));
|
---|
47 | }
|
---|
48 |
|
---|
49 | void CommandLineDialog::queryMolecule(const char* title, molecule **target, MoleculeListClass *molecules) {
|
---|
50 | registerQuery(new MoleculeTextQuery(title,target,molecules));
|
---|
51 | }
|
---|
52 |
|
---|
53 | void CommandLineDialog::queryVector(const char* title, Vector *target,const double *const cellSize, bool check) {
|
---|
54 | registerQuery(new VectorTextQuery(title,target,cellSize,check));
|
---|
55 | }
|
---|
56 |
|
---|
57 | void CommandLineDialog::queryElement(const char* title, const element **target){
|
---|
58 | registerQuery(new ElementTextQuery(title,target));
|
---|
59 | }
|
---|
60 |
|
---|
61 | /************************** Query Infrastructure ************************/
|
---|
62 |
|
---|
63 | CommandLineDialog::IntTextQuery::IntTextQuery(string title,int *_target) :
|
---|
64 | Dialog::IntQuery(title,_target)
|
---|
65 | {}
|
---|
66 |
|
---|
67 | CommandLineDialog::IntTextQuery::~IntTextQuery() {}
|
---|
68 |
|
---|
69 | bool CommandLineDialog::IntTextQuery::handle() {
|
---|
70 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
---|
71 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<int>();
|
---|
72 | return true;
|
---|
73 | } else
|
---|
74 | return false;
|
---|
75 | }
|
---|
76 |
|
---|
77 | CommandLineDialog::StringTextQuery::StringTextQuery(string title,string *_target) :
|
---|
78 | Dialog::StringQuery(title,_target)
|
---|
79 | {}
|
---|
80 |
|
---|
81 | CommandLineDialog::StringTextQuery::~StringTextQuery() {}
|
---|
82 |
|
---|
83 | bool CommandLineDialog::StringTextQuery::handle() {
|
---|
84 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
---|
85 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<std::string>();
|
---|
86 | return true;
|
---|
87 | } else
|
---|
88 | return false;
|
---|
89 | }
|
---|
90 |
|
---|
91 | CommandLineDialog::DoubleTextQuery::DoubleTextQuery(string title,double *_target) :
|
---|
92 | Dialog::DoubleQuery(title,_target)
|
---|
93 | {}
|
---|
94 |
|
---|
95 | CommandLineDialog::DoubleTextQuery::~DoubleTextQuery() {}
|
---|
96 |
|
---|
97 | bool CommandLineDialog::DoubleTextQuery::handle() {
|
---|
98 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
---|
99 | tmp = CommandLineParser::getInstance().vm[getTitle()].as<double>();
|
---|
100 | return true;
|
---|
101 | } else
|
---|
102 | return false;
|
---|
103 | }
|
---|
104 |
|
---|
105 | CommandLineDialog::MoleculeTextQuery::MoleculeTextQuery(string title, molecule **_target, MoleculeListClass *_molecules) :
|
---|
106 | Dialog::MoleculeQuery(title,_target,_molecules)
|
---|
107 | {}
|
---|
108 |
|
---|
109 | CommandLineDialog::MoleculeTextQuery::~MoleculeTextQuery() {}
|
---|
110 |
|
---|
111 | bool CommandLineDialog::MoleculeTextQuery::handle() {
|
---|
112 | int IdxOfMol = -1;
|
---|
113 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
---|
114 | IdxOfMol = CommandLineParser::getInstance().vm[getTitle()].as<int>();
|
---|
115 | tmp = World::getInstance().getMolecule(MoleculeById(IdxOfMol));
|
---|
116 | return true;
|
---|
117 | } else
|
---|
118 | return false;
|
---|
119 | }
|
---|
120 |
|
---|
121 | CommandLineDialog::VectorTextQuery::VectorTextQuery(std::string title, Vector *_target, const double *const _cellSize, bool _check) :
|
---|
122 | Dialog::VectorQuery(title,_target,_cellSize,_check)
|
---|
123 | {}
|
---|
124 |
|
---|
125 | CommandLineDialog::VectorTextQuery::~VectorTextQuery()
|
---|
126 | {}
|
---|
127 |
|
---|
128 | bool CommandLineDialog::VectorTextQuery::handle() {
|
---|
129 | vector<double> temp;
|
---|
130 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
---|
131 | temp = CommandLineParser::getInstance().vm[getTitle()].as<vector<double> >();
|
---|
132 | assert((temp.size() == 3) && "Vector from command line does not have three components.");
|
---|
133 | tmp = new Vector;
|
---|
134 | for (int i=0;i<NDIM;i++)
|
---|
135 | tmp->at(i) = temp[i];
|
---|
136 | return true;
|
---|
137 | } else
|
---|
138 | return false;
|
---|
139 | }
|
---|
140 |
|
---|
141 |
|
---|
142 | CommandLineDialog::ElementTextQuery::ElementTextQuery(std::string title, const element **target) :
|
---|
143 | Dialog::ElementQuery(title,target)
|
---|
144 | {}
|
---|
145 |
|
---|
146 | CommandLineDialog::ElementTextQuery::~ElementTextQuery()
|
---|
147 | {}
|
---|
148 |
|
---|
149 | bool CommandLineDialog::ElementTextQuery::handle() {
|
---|
150 | int Z = -1;
|
---|
151 | if (CommandLineParser::getInstance().vm.count(getTitle())) {
|
---|
152 | Z = CommandLineParser::getInstance().vm[getTitle()].as<int>();
|
---|
153 | tmp = World::getInstance().getPeriode()->FindElement(Z);
|
---|
154 | return true;
|
---|
155 | } else
|
---|
156 | return false;
|
---|
157 | }
|
---|