source: molecuilder/src/UIElements/CommandLineDialog.cpp@ e62daa

Last change on this file since e62daa was b918031, checked in by Frederik Heber <heber@…>, 16 years ago

new query class EmptyQuery for showing text messages.

Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 5.6 KB
Line 
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
25using namespace std;
26
27
28CommandLineDialog::CommandLineDialog()
29{
30}
31
32CommandLineDialog::~CommandLineDialog()
33{
34}
35
36
37void CommandLineDialog::queryEmpty(const char* title, string _description){
38 registerQuery(new EmptyCommandLineQuery(title, _description));
39}
40
41void CommandLineDialog::queryInt(const char* title, int* target, string _description){
42 registerQuery(new IntCommandLineQuery(title,target, _description));
43}
44
45void CommandLineDialog::queryDouble(const char* title, double* target, string _description){
46 registerQuery(new DoubleCommandLineQuery(title,target, _description));
47}
48
49void CommandLineDialog::queryString(const char* title, string* target, string _description){
50 registerQuery(new StringCommandLineQuery(title,target, _description));
51}
52
53void CommandLineDialog::queryMolecule(const char* title, molecule **target, MoleculeListClass *molecules, string _description) {
54 registerQuery(new MoleculeCommandLineQuery(title,target,molecules, _description));
55}
56
57void 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
61void CommandLineDialog::queryElement(const char* title, const element **target, string _description){
62 registerQuery(new ElementCommandLineQuery(title,target, _description));
63}
64
65/************************** Query Infrastructure ************************/
66
67CommandLineDialog::EmptyCommandLineQuery::EmptyCommandLineQuery(string title, string _description) :
68 Dialog::EmptyQuery(title, _description)
69{}
70
71CommandLineDialog::EmptyCommandLineQuery::~EmptyCommandLineQuery() {}
72
73bool CommandLineDialog::EmptyCommandLineQuery::handle() {
74 cout << "Message of " << getTitle() << ":\n" << getDescription() << "\n";
75 return true;
76}
77
78CommandLineDialog::IntCommandLineQuery::IntCommandLineQuery(string title,int *_target, string _description) :
79 Dialog::IntQuery(title,_target, _description)
80{}
81
82CommandLineDialog::IntCommandLineQuery::~IntCommandLineQuery() {}
83
84bool 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
92CommandLineDialog::StringCommandLineQuery::StringCommandLineQuery(string title,string *_target, string _description) :
93 Dialog::StringQuery(title,_target, _description)
94{}
95
96CommandLineDialog::StringCommandLineQuery::~StringCommandLineQuery() {}
97
98bool 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
106CommandLineDialog::DoubleCommandLineQuery::DoubleCommandLineQuery(string title,double *_target, string _description) :
107 Dialog::DoubleQuery(title,_target, _description)
108{}
109
110CommandLineDialog::DoubleCommandLineQuery::~DoubleCommandLineQuery() {}
111
112bool 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
120CommandLineDialog::MoleculeCommandLineQuery::MoleculeCommandLineQuery(string title, molecule **_target, MoleculeListClass *_molecules, string _description) :
121 Dialog::MoleculeQuery(title,_target,_molecules, _description)
122{}
123
124CommandLineDialog::MoleculeCommandLineQuery::~MoleculeCommandLineQuery() {}
125
126bool 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
136CommandLineDialog::VectorCommandLineQuery::VectorCommandLineQuery(string title, Vector *_target, const double *const _cellSize, bool _check, string _description) :
137 Dialog::VectorQuery(title,_target,_cellSize,_check, _description)
138{}
139
140CommandLineDialog::VectorCommandLineQuery::~VectorCommandLineQuery()
141{}
142
143bool 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
157CommandLineDialog::ElementCommandLineQuery::ElementCommandLineQuery(string title, const element **target, string _description) :
158 Dialog::ElementQuery(title,target, _description)
159{}
160
161CommandLineDialog::ElementCommandLineQuery::~ElementCommandLineQuery()
162{}
163
164bool 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}
Note: See TracBrowser for help on using the repository browser.