| 1 | /*
|
|---|
| 2 | * LoadXyzAction.cpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: May 8, 2010
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | // include config.h
|
|---|
| 9 | #ifdef HAVE_CONFIG_H
|
|---|
| 10 | #include <config.h>
|
|---|
| 11 | #endif
|
|---|
| 12 |
|
|---|
| 13 | #include "Helpers/MemDebug.hpp"
|
|---|
| 14 |
|
|---|
| 15 | using namespace std;
|
|---|
| 16 |
|
|---|
| 17 | #include "Actions/ParserAction/LoadXyzAction.hpp"
|
|---|
| 18 | #include "Actions/ActionRegistry.hpp"
|
|---|
| 19 | #include "Parser/XyzParser.hpp"
|
|---|
| 20 | #include "atom.hpp"
|
|---|
| 21 | #include "Helpers/Log.hpp"
|
|---|
| 22 | #include "molecule.hpp"
|
|---|
| 23 | #include "Helpers/Verbose.hpp"
|
|---|
| 24 | #include "World.hpp"
|
|---|
| 25 |
|
|---|
| 26 | #include <iostream>
|
|---|
| 27 | #include <set>
|
|---|
| 28 | #include <string>
|
|---|
| 29 | #include <vector>
|
|---|
| 30 |
|
|---|
| 31 | #include "UIElements/UIFactory.hpp"
|
|---|
| 32 | #include "UIElements/Dialog.hpp"
|
|---|
| 33 | #include "Actions/ValueStorage.hpp"
|
|---|
| 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 |
|
|---|
| 49 | const char ParserLoadXyzAction::NAME[] = "parse-xyz";
|
|---|
| 50 |
|
|---|
| 51 | ParserLoadXyzAction::ParserLoadXyzAction() :
|
|---|
| 52 | Action(NAME)
|
|---|
| 53 | {}
|
|---|
| 54 |
|
|---|
| 55 | ParserLoadXyzAction::~ParserLoadXyzAction()
|
|---|
| 56 | {}
|
|---|
| 57 |
|
|---|
| 58 | void ParserLoadXyz(std::string &filename) {
|
|---|
| 59 | ValueStorage::getInstance().setCurrentValue(ParserLoadXyzAction::NAME, filename);
|
|---|
| 60 | ActionRegistry::getInstance().getActionByName(ParserLoadXyzAction::NAME)->call(Action::NonInteractive);
|
|---|
| 61 | };
|
|---|
| 62 |
|
|---|
| 63 | Dialog* ParserLoadXyzAction::fillDialog(Dialog *dialog) {
|
|---|
| 64 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
|---|
| 65 |
|
|---|
| 66 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
|
|---|
| 67 |
|
|---|
| 68 | return dialog;
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | Action::state_ptr ParserLoadXyzAction::performCall() {
|
|---|
| 72 | string filename;
|
|---|
| 73 |
|
|---|
| 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);
|
|---|
| 85 | }
|
|---|
| 86 | input.close();
|
|---|
| 87 | return Action::success;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | Action::state_ptr ParserLoadXyzAction::performUndo(Action::state_ptr _state) {
|
|---|
| 91 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
|---|
| 92 |
|
|---|
| 93 | return Action::failure;
|
|---|
| 94 | // string newName = state->mol->getName();
|
|---|
| 95 | // state->mol->setName(state->lastName);
|
|---|
| 96 | //
|
|---|
| 97 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | Action::state_ptr ParserLoadXyzAction::performRedo(Action::state_ptr _state){
|
|---|
| 101 | return Action::failure;
|
|---|
| 102 | }
|
|---|
| 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 | }
|
|---|