| 1 | /*
|
|---|
| 2 | * Project: MoleCuilder
|
|---|
| 3 | * Description: creates and alters molecular systems
|
|---|
| 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
|---|
| 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 |
|
|---|
| 20 | #include "CodePatterns/MemDebug.hpp"
|
|---|
| 21 |
|
|---|
| 22 | #include <iostream>
|
|---|
| 23 | #include <boost/lexical_cast.hpp>
|
|---|
| 24 |
|
|---|
| 25 | #include "TextUI/Query/TextQuery.hpp"
|
|---|
| 26 |
|
|---|
| 27 | #include "CodePatterns/Log.hpp"
|
|---|
| 28 | #include "CodePatterns/Verbose.hpp"
|
|---|
| 29 | #include "Element/element.hpp"
|
|---|
| 30 | #include "Element/periodentafel.hpp"
|
|---|
| 31 | #include "World.hpp"
|
|---|
| 32 |
|
|---|
| 33 | using boost::lexical_cast;
|
|---|
| 34 | using boost::bad_lexical_cast;
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 | TextDialog::ElementsTextQuery::ElementsTextQuery(Parameter<std::vector<const element *> > &_param, std::string title, std::string _description) :
|
|---|
| 38 | Dialog::TQuery<std::vector<const element *> >(_param, title,_description)
|
|---|
| 39 | {}
|
|---|
| 40 |
|
|---|
| 41 | TextDialog::ElementsTextQuery::~ElementsTextQuery()
|
|---|
| 42 | {}
|
|---|
| 43 |
|
|---|
| 44 | bool TextDialog::ElementsTextQuery::handle() {
|
|---|
| 45 | std::string shorthand;
|
|---|
| 46 | int Z=-1;
|
|---|
| 47 | std::cout << getDescription() << ": ";
|
|---|
| 48 | std::string line;
|
|---|
| 49 | getline(std::cin,line);
|
|---|
| 50 | // dissect by " "
|
|---|
| 51 | const element *temp_element;
|
|---|
| 52 | std::string::iterator olditer = line.begin();
|
|---|
| 53 | for(std::string::iterator iter = line.begin(); iter != line.end(); ++iter) {
|
|---|
| 54 | if (*iter == ' ') {
|
|---|
| 55 | std::istringstream stream(std::string(iter, olditer));
|
|---|
| 56 | stream >> shorthand;
|
|---|
| 57 | try {
|
|---|
| 58 | Z = lexical_cast<int>(shorthand);
|
|---|
| 59 | temp_element = World::getInstance().getPeriode()->FindElement(Z);
|
|---|
| 60 | } catch (bad_lexical_cast) {
|
|---|
| 61 | temp_element = World::getInstance().getPeriode()->FindElement(shorthand.c_str());
|
|---|
| 62 | };
|
|---|
| 63 | if(!temp_element && Z!=-1){
|
|---|
| 64 | std::cout << "Invalid Element" << shorthand << std::endl;
|
|---|
| 65 | break;
|
|---|
| 66 | }
|
|---|
| 67 | temp.push_back(temp_element);
|
|---|
| 68 | olditer = iter;
|
|---|
| 69 | }
|
|---|
| 70 | }
|
|---|
| 71 | if (olditer != line.begin()) { // insert last part also
|
|---|
| 72 | std::istringstream stream(std::string(olditer, line.end()));
|
|---|
| 73 | stream >> shorthand;
|
|---|
| 74 | try {
|
|---|
| 75 | Z = lexical_cast<int>(shorthand);
|
|---|
| 76 | temp_element = World::getInstance().getPeriode()->FindElement(Z);
|
|---|
| 77 | } catch (bad_lexical_cast) {
|
|---|
| 78 | temp_element = World::getInstance().getPeriode()->FindElement(shorthand.c_str());
|
|---|
| 79 | };
|
|---|
| 80 | if(!temp_element && Z!=-1) {
|
|---|
| 81 | std::cout << "Invalid Element" << shorthand << std::endl;
|
|---|
| 82 | temp.push_back(temp_element);
|
|---|
| 83 | }
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | return (Z!=-1);
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|