| 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 | * AtomsTextQuery.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 <Descriptors/AtomDescriptor.hpp>
|
|---|
| 23 | #include <Descriptors/AtomIdDescriptor.hpp>
|
|---|
| 24 | #include "TextUI/Query/TextQuery.hpp"
|
|---|
| 25 |
|
|---|
| 26 | #include "CodePatterns/Log.hpp"
|
|---|
| 27 | #include "CodePatterns/Verbose.hpp"
|
|---|
| 28 |
|
|---|
| 29 | #include "Atom/atom.hpp"
|
|---|
| 30 | #include "World.hpp"
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 | TextDialog::AtomsTextQuery::AtomsTextQuery(Parameter<std::vector<const atom *> > ¶m, std::string title, std::string _description) :
|
|---|
| 34 | Dialog::AtomsQuery(param, title,_description)
|
|---|
| 35 | {}
|
|---|
| 36 |
|
|---|
| 37 | TextDialog::AtomsTextQuery::~AtomsTextQuery() {}
|
|---|
| 38 |
|
|---|
| 39 | bool TextDialog::AtomsTextQuery::handle() {
|
|---|
| 40 | int idxOfAtom=-1;
|
|---|
| 41 | std::cout << getDescription() << ": ";
|
|---|
| 42 | std::string line;
|
|---|
| 43 | getline(std::cin,line);
|
|---|
| 44 | // dissect by " "
|
|---|
| 45 | std::string::iterator olditer = line.begin();
|
|---|
| 46 | std::vector<const atom *> temp_atoms;
|
|---|
| 47 | for(std::string::iterator iter = line.begin(); iter != line.end(); ++iter) {
|
|---|
| 48 | if (*iter == ' ') {
|
|---|
| 49 | std::istringstream stream(std::string(iter, olditer));
|
|---|
| 50 | stream >> idxOfAtom;
|
|---|
| 51 | temp = World::getInstance().getAtom(AtomById(idxOfAtom));
|
|---|
| 52 | if(!temp && idxOfAtom!=-1){
|
|---|
| 53 | std::cout << "Invalid Atom Index" << idxOfAtom << std::endl;
|
|---|
| 54 | break;
|
|---|
| 55 | }
|
|---|
| 56 | temp_atoms.push_back(temp);
|
|---|
| 57 | olditer = iter;
|
|---|
| 58 | }
|
|---|
| 59 | }
|
|---|
| 60 | if (olditer != line.begin()) { // insert last part also
|
|---|
| 61 | std::istringstream stream(std::string(olditer, line.end()));
|
|---|
| 62 | stream >> idxOfAtom;
|
|---|
| 63 | temp = World::getInstance().getAtom(AtomById(idxOfAtom));
|
|---|
| 64 | if(!temp && idxOfAtom!=-1) {
|
|---|
| 65 | std::cout << "Invalid Atom Index" << idxOfAtom << std::endl;
|
|---|
| 66 | temp_atoms.push_back(temp);
|
|---|
| 67 | }
|
|---|
| 68 | }
|
|---|
| 69 | tmp.set(temp_atoms);
|
|---|
| 70 |
|
|---|
| 71 | return (idxOfAtom!=-1);
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|