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