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 | * MoleculesTextQuery.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 |
|
---|
24 | #include <Descriptors/MoleculeDescriptor.hpp>
|
---|
25 | #include <Descriptors/MoleculeIdDescriptor.hpp>
|
---|
26 | #include "TextUI/Query/TextQuery.hpp"
|
---|
27 |
|
---|
28 | #include "CodePatterns/Log.hpp"
|
---|
29 | #include "CodePatterns/Verbose.hpp"
|
---|
30 | #include "World.hpp"
|
---|
31 |
|
---|
32 |
|
---|
33 | TextDialog::MoleculesTextQuery::MoleculesTextQuery(Parameter<std::vector<const molecule *> > &_param, std::string title, std::string _description) :
|
---|
34 | Dialog::TQuery<std::vector<const molecule *> >(_param, title,_description)
|
---|
35 | {}
|
---|
36 |
|
---|
37 | TextDialog::MoleculesTextQuery::~MoleculesTextQuery() {}
|
---|
38 |
|
---|
39 | bool TextDialog::MoleculesTextQuery::handle() {
|
---|
40 | int idxOfMol=-1;
|
---|
41 | std::cout << getDescription() << ": ";
|
---|
42 | std::string line;
|
---|
43 | getline(std::cin,line);
|
---|
44 | // dissect by " "
|
---|
45 | const molecule *temp_element;
|
---|
46 | std::string::iterator olditer = line.begin();
|
---|
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 >> idxOfMol;
|
---|
51 | temp_element = World::getInstance().getMolecule(MoleculeById(idxOfMol));
|
---|
52 | if(!temp_element && idxOfMol!=-1){
|
---|
53 | std::cout << "Invalid Molecule Index" << idxOfMol << std::endl;
|
---|
54 | break;
|
---|
55 | }
|
---|
56 | temp.push_back(temp_element);
|
---|
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 >> idxOfMol;
|
---|
63 | temp_element = World::getInstance().getMolecule(MoleculeById(idxOfMol));
|
---|
64 | if(!temp_element && idxOfMol!=-1){
|
---|
65 | std::cout << "Invalid Molecule Index" << idxOfMol << std::endl;
|
---|
66 | temp.push_back(temp_element);
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | return (idxOfMol!=-1);
|
---|
71 | }
|
---|
72 |
|
---|