[03bb99] | 1 | /*
|
---|
| 2 | * LoadXyzAction.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: May 8, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[bf3817] | 8 | // include config.h
|
---|
| 9 | #ifdef HAVE_CONFIG_H
|
---|
| 10 | #include <config.h>
|
---|
| 11 | #endif
|
---|
| 12 |
|
---|
[112b09] | 13 | #include "Helpers/MemDebug.hpp"
|
---|
| 14 |
|
---|
[a1e929] | 15 | using namespace std;
|
---|
| 16 |
|
---|
[03bb99] | 17 | #include "Actions/ParserAction/LoadXyzAction.hpp"
|
---|
[0430e3] | 18 | #include "Actions/ActionRegistry.hpp"
|
---|
[03bb99] | 19 | #include "Parser/XyzParser.hpp"
|
---|
[215b89] | 20 | #include "atom.hpp"
|
---|
[952f38] | 21 | #include "Helpers/Log.hpp"
|
---|
[215b89] | 22 | #include "molecule.hpp"
|
---|
[952f38] | 23 | #include "Helpers/Verbose.hpp"
|
---|
[215b89] | 24 | #include "World.hpp"
|
---|
[03bb99] | 25 |
|
---|
| 26 | #include <iostream>
|
---|
[a1e929] | 27 | #include <set>
|
---|
[03bb99] | 28 | #include <string>
|
---|
[a1e929] | 29 | #include <vector>
|
---|
[03bb99] | 30 |
|
---|
| 31 | #include "UIElements/UIFactory.hpp"
|
---|
| 32 | #include "UIElements/Dialog.hpp"
|
---|
[861874] | 33 | #include "Actions/ValueStorage.hpp"
|
---|
[03bb99] | 34 |
|
---|
| 35 | /****** ParserLoadXyzAction *****/
|
---|
| 36 |
|
---|
| 37 | //// memento to remember the state when undoing
|
---|
| 38 | //
|
---|
| 39 | //class ParserLoadXyzState : public ActionState {
|
---|
| 40 | //public:
|
---|
| 41 | // ParserLoadXyzState(molecule* _mol,std::string _lastName) :
|
---|
| 42 | // mol(_mol),
|
---|
| 43 | // lastName(_lastName)
|
---|
| 44 | // {}
|
---|
| 45 | // molecule* mol;
|
---|
| 46 | // std::string lastName;
|
---|
| 47 | //};
|
---|
| 48 |
|
---|
[a1e929] | 49 | const char ParserLoadXyzAction::NAME[] = "parse-xyz";
|
---|
[03bb99] | 50 |
|
---|
| 51 | ParserLoadXyzAction::ParserLoadXyzAction() :
|
---|
| 52 | Action(NAME)
|
---|
| 53 | {}
|
---|
| 54 |
|
---|
| 55 | ParserLoadXyzAction::~ParserLoadXyzAction()
|
---|
| 56 | {}
|
---|
| 57 |
|
---|
[215b89] | 58 | void ParserLoadXyz(std::string &filename) {
|
---|
| 59 | ValueStorage::getInstance().setCurrentValue(ParserLoadXyzAction::NAME, filename);
|
---|
| 60 | ActionRegistry::getInstance().getActionByName(ParserLoadXyzAction::NAME)->call(Action::NonInteractive);
|
---|
| 61 | };
|
---|
| 62 |
|
---|
[047878] | 63 | Dialog* ParserLoadXyzAction::fillDialog(Dialog *dialog) {
|
---|
| 64 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
[0454de] | 65 |
|
---|
| 66 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 67 |
|
---|
| 68 | return dialog;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
[03bb99] | 71 | Action::state_ptr ParserLoadXyzAction::performCall() {
|
---|
| 72 | string filename;
|
---|
| 73 |
|
---|
[0454de] | 74 | ValueStorage::getInstance().queryCurrentValue(NAME, filename);
|
---|
| 75 |
|
---|
| 76 | DoLog(1) && (Log() << Verbose(1) << "Parsing xyz file for new atoms." << endl);
|
---|
| 77 | // parse xyz file
|
---|
| 78 | ifstream input;
|
---|
| 79 | input.open(filename.c_str());
|
---|
| 80 | if (!input.fail()) {
|
---|
| 81 | XyzParser parser; // briefly instantiate a parser which is removed at end of focus
|
---|
| 82 | parser.load(&input);
|
---|
| 83 | } else {
|
---|
| 84 | DoeLog(1) && (eLog() << Verbose(1) << "Could not open file " << filename << "." << endl);
|
---|
[03bb99] | 85 | }
|
---|
[0454de] | 86 | input.close();
|
---|
| 87 | return Action::success;
|
---|
[03bb99] | 88 | }
|
---|
| 89 |
|
---|
[808fd3] | 90 | Action::state_ptr ParserLoadXyzAction::performUndo(Action::state_ptr _state) {
|
---|
[03bb99] | 91 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
[808fd3] | 92 |
|
---|
| 93 | return Action::failure;
|
---|
[03bb99] | 94 | // string newName = state->mol->getName();
|
---|
| 95 | // state->mol->setName(state->lastName);
|
---|
| 96 | //
|
---|
| 97 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
[808fd3] | 98 | }
|
---|
| 99 |
|
---|
| 100 | Action::state_ptr ParserLoadXyzAction::performRedo(Action::state_ptr _state){
|
---|
| 101 | return Action::failure;
|
---|
| 102 | }
|
---|
[03bb99] | 103 |
|
---|
| 104 | bool ParserLoadXyzAction::canUndo() {
|
---|
| 105 | return false;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | bool ParserLoadXyzAction::shouldUndo() {
|
---|
| 109 | return false;
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | const string ParserLoadXyzAction::getName() {
|
---|
| 113 | return NAME;
|
---|
| 114 | }
|
---|