[8df74d] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[0aa122] | 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
[8df74d] | 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | /*
|
---|
| 9 | * ElementsTextQuery.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: Oct 25, 2010
|
---|
| 12 | * Author: heber
|
---|
| 13 | */
|
---|
| 14 |
|
---|
| 15 | // include config.h
|
---|
| 16 | #ifdef HAVE_CONFIG_H
|
---|
| 17 | #include <config.h>
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
[ad011c] | 20 | #include "CodePatterns/MemDebug.hpp"
|
---|
[8df74d] | 21 |
|
---|
| 22 | #include <iostream>
|
---|
| 23 | #include <boost/lexical_cast.hpp>
|
---|
| 24 |
|
---|
[738ae1] | 25 | #include "TextUI/Query/TextQuery.hpp"
|
---|
[8df74d] | 26 |
|
---|
[ad011c] | 27 | #include "CodePatterns/Log.hpp"
|
---|
| 28 | #include "CodePatterns/Verbose.hpp"
|
---|
[3bdb6d] | 29 | #include "Element/element.hpp"
|
---|
| 30 | #include "Element/periodentafel.hpp"
|
---|
[8df74d] | 31 | #include "World.hpp"
|
---|
| 32 |
|
---|
| 33 | using boost::lexical_cast;
|
---|
| 34 | using boost::bad_lexical_cast;
|
---|
| 35 |
|
---|
| 36 |
|
---|
[9d5531] | 37 | TextDialog::ElementsTextQuery::ElementsTextQuery(Parameter<std::vector<const element *> > &_param, std::string title, std::string _description) :
|
---|
[1c55b8] | 38 | Dialog::TQuery<std::vector<const element *> >(_param, title,_description)
|
---|
[8df74d] | 39 | {}
|
---|
| 40 |
|
---|
| 41 | TextDialog::ElementsTextQuery::~ElementsTextQuery()
|
---|
| 42 | {}
|
---|
| 43 |
|
---|
| 44 | bool TextDialog::ElementsTextQuery::handle() {
|
---|
| 45 | std::string shorthand;
|
---|
| 46 | int Z=-1;
|
---|
[d754bb] | 47 | std::cout << getDescription() << ": ";
|
---|
[8df74d] | 48 | std::string line;
|
---|
[d754bb] | 49 | getline(std::cin,line);
|
---|
[8df74d] | 50 | // dissect by " "
|
---|
[1c55b8] | 51 | const element *temp_element;
|
---|
[8df74d] | 52 | std::string::iterator olditer = line.begin();
|
---|
[955b91] | 53 | for(std::string::iterator iter = line.begin(); iter != line.end(); ++iter) {
|
---|
[8df74d] | 54 | if (*iter == ' ') {
|
---|
[955b91] | 55 | std::istringstream stream(std::string(iter, olditer));
|
---|
[8df74d] | 56 | stream >> shorthand;
|
---|
| 57 | try {
|
---|
| 58 | Z = lexical_cast<int>(shorthand);
|
---|
[9d5531] | 59 | temp_element = World::getInstance().getPeriode()->FindElement(Z);
|
---|
[8df74d] | 60 | } catch (bad_lexical_cast) {
|
---|
[9d5531] | 61 | temp_element = World::getInstance().getPeriode()->FindElement(shorthand.c_str());
|
---|
[8df74d] | 62 | };
|
---|
[9d5531] | 63 | if(!temp_element && Z!=-1){
|
---|
[d754bb] | 64 | std::cout << "Invalid Element" << shorthand << std::endl;
|
---|
[8df74d] | 65 | break;
|
---|
| 66 | }
|
---|
[9d5531] | 67 | temp.push_back(temp_element);
|
---|
[8df74d] | 68 | olditer = iter;
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 | if (olditer != line.begin()) { // insert last part also
|
---|
[955b91] | 72 | std::istringstream stream(std::string(olditer, line.end()));
|
---|
[8df74d] | 73 | stream >> shorthand;
|
---|
| 74 | try {
|
---|
| 75 | Z = lexical_cast<int>(shorthand);
|
---|
[9d5531] | 76 | temp_element = World::getInstance().getPeriode()->FindElement(Z);
|
---|
[8df74d] | 77 | } catch (bad_lexical_cast) {
|
---|
[9d5531] | 78 | temp_element = World::getInstance().getPeriode()->FindElement(shorthand.c_str());
|
---|
[8df74d] | 79 | };
|
---|
[9d5531] | 80 | if(!temp_element && Z!=-1) {
|
---|
[d754bb] | 81 | std::cout << "Invalid Element" << shorthand << std::endl;
|
---|
[9d5531] | 82 | temp.push_back(temp_element);
|
---|
[8df74d] | 83 | }
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | return (Z!=-1);
|
---|
| 87 | }
|
---|
| 88 |
|
---|