| [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 | 
 | 
|---|
| [f10b0c] | 37 | TextDialog::ElementsTextQuery::ElementsTextQuery(Parameter<std::vector<const element *> > ¶m, std::string title, std::string _description) :
 | 
|---|
 | 38 |     Dialog::ElementsQuery(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 " "
 | 
|---|
 | 51 |   std::string::iterator olditer = line.begin();
 | 
|---|
| [f10b0c] | 52 |   std::vector<const element *> temp_elements;
 | 
|---|
| [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);
 | 
|---|
 | 59 |         temp = World::getInstance().getPeriode()->FindElement(Z);
 | 
|---|
 | 60 |       } catch (bad_lexical_cast) {
 | 
|---|
 | 61 |         temp = World::getInstance().getPeriode()->FindElement(shorthand.c_str());
 | 
|---|
 | 62 |       };
 | 
|---|
 | 63 |       if(!temp && Z!=-1){
 | 
|---|
| [d754bb] | 64 |         std::cout << "Invalid Element" << shorthand << std::endl;
 | 
|---|
| [8df74d] | 65 |         break;
 | 
|---|
 | 66 |       }
 | 
|---|
| [f10b0c] | 67 |       temp_elements.push_back(temp);
 | 
|---|
| [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);
 | 
|---|
 | 76 |       temp = World::getInstance().getPeriode()->FindElement(Z);
 | 
|---|
 | 77 |     } catch (bad_lexical_cast) {
 | 
|---|
 | 78 |       temp = World::getInstance().getPeriode()->FindElement(shorthand.c_str());
 | 
|---|
 | 79 |     };
 | 
|---|
 | 80 |     if(!temp && Z!=-1) {
 | 
|---|
| [d754bb] | 81 |       std::cout << "Invalid Element" << shorthand << std::endl;
 | 
|---|
| [f10b0c] | 82 |       temp_elements.push_back(temp);
 | 
|---|
| [8df74d] | 83 |     }
 | 
|---|
 | 84 |   }
 | 
|---|
| [f10b0c] | 85 |   tmp.set(temp_elements);
 | 
|---|
| [8df74d] | 86 | 
 | 
|---|
 | 87 |   return (Z!=-1);
 | 
|---|
 | 88 | }
 | 
|---|
 | 89 | 
 | 
|---|