1 | /*
|
---|
2 | * LinearInterpolationofTrajectoriesAction.cpp
|
---|
3 | *
|
---|
4 | * Created on: May 10, 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 | #include "Actions/MoleculeAction/LinearInterpolationofTrajectoriesAction.hpp"
|
---|
16 | #include "Actions/ActionRegistry.hpp"
|
---|
17 | #include "atom.hpp"
|
---|
18 | #include "defs.hpp"
|
---|
19 | #include "Helpers/Log.hpp"
|
---|
20 | #include "molecule.hpp"
|
---|
21 | #include "Helpers/Verbose.hpp"
|
---|
22 | #include "World.hpp"
|
---|
23 |
|
---|
24 | #include <iostream>
|
---|
25 | #include <fstream>
|
---|
26 | #include <string>
|
---|
27 |
|
---|
28 | using namespace std;
|
---|
29 |
|
---|
30 | #include "UIElements/UIFactory.hpp"
|
---|
31 | #include "UIElements/Dialog.hpp"
|
---|
32 | #include "Actions/ValueStorage.hpp"
|
---|
33 |
|
---|
34 |
|
---|
35 | /****** MoleculeLinearInterpolationofTrajectoriesAction *****/
|
---|
36 |
|
---|
37 | // memento to remember the state when undoing
|
---|
38 |
|
---|
39 | //class MoleculeLinearInterpolationofTrajectoriesState : public ActionState {
|
---|
40 | //public:
|
---|
41 | // MoleculeLinearInterpolationofTrajectoriesState(molecule* _mol,std::string _lastName) :
|
---|
42 | // mol(_mol),
|
---|
43 | // lastName(_lastName)
|
---|
44 | // {}
|
---|
45 | // molecule* mol;
|
---|
46 | // std::string lastName;
|
---|
47 | //};
|
---|
48 |
|
---|
49 | const char MoleculeLinearInterpolationofTrajectoriesAction::NAME[] = "linear-interpolate";
|
---|
50 |
|
---|
51 | MoleculeLinearInterpolationofTrajectoriesAction::MoleculeLinearInterpolationofTrajectoriesAction() :
|
---|
52 | Action(NAME)
|
---|
53 | {}
|
---|
54 |
|
---|
55 | MoleculeLinearInterpolationofTrajectoriesAction::~MoleculeLinearInterpolationofTrajectoriesAction()
|
---|
56 | {}
|
---|
57 |
|
---|
58 | void MoleculeLinearInterpolationofTrajectories(std::string &filename, int start, int end, bool IdMapping) {
|
---|
59 | ValueStorage::getInstance().setCurrentValue(MoleculeLinearInterpolationofTrajectoriesAction::NAME, filename);
|
---|
60 | ValueStorage::getInstance().setCurrentValue("start-step", start);
|
---|
61 | ValueStorage::getInstance().setCurrentValue("end-step", end);
|
---|
62 | ValueStorage::getInstance().setCurrentValue("id-mapping", IdMapping);
|
---|
63 | ActionRegistry::getInstance().getActionByName(MoleculeLinearInterpolationofTrajectoriesAction::NAME)->call(Action::NonInteractive);
|
---|
64 | };
|
---|
65 |
|
---|
66 | Dialog* MoleculeLinearInterpolationofTrajectoriesAction::fillDialog(Dialog *dialog) {
|
---|
67 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
68 |
|
---|
69 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
70 | dialog->queryInt("start-step", ValueStorage::getInstance().getDescription("start-step"));
|
---|
71 | dialog->queryInt("end-step", ValueStorage::getInstance().getDescription("end-step"));
|
---|
72 | dialog->queryBoolean("id-mapping", ValueStorage::getInstance().getDescription("id-mapping"));
|
---|
73 |
|
---|
74 | return dialog;
|
---|
75 | }
|
---|
76 |
|
---|
77 | Action::state_ptr MoleculeLinearInterpolationofTrajectoriesAction::performCall() {
|
---|
78 | string filename;
|
---|
79 | molecule *mol = NULL;
|
---|
80 | int start = -1;
|
---|
81 | int end = -1;
|
---|
82 | bool IdMapping = true;
|
---|
83 |
|
---|
84 | ValueStorage::getInstance().queryCurrentValue(NAME, filename);
|
---|
85 | ValueStorage::getInstance().queryCurrentValue("start-step", start);
|
---|
86 | ValueStorage::getInstance().queryCurrentValue("end-step", end);
|
---|
87 | ValueStorage::getInstance().queryCurrentValue("id-mapping", IdMapping);
|
---|
88 |
|
---|
89 | for (World::MoleculeSelectionIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) {
|
---|
90 | mol = iter->second;
|
---|
91 | DoLog(1) && (Log() << Verbose(1) << "Linear interpolation between configuration " << start << " and " << end << "." << endl);
|
---|
92 | if (IdMapping)
|
---|
93 | DoLog(1) && (Log() << Verbose(1) << "Using Identity for the permutation map." << endl);
|
---|
94 | if (!mol->LinearInterpolationBetweenConfiguration(start, end, filename, *(World::getInstance().getConfig()), IdMapping))
|
---|
95 | DoLog(2) && (Log() << Verbose(2) << "Could not store " << filename << " files." << endl);
|
---|
96 | else
|
---|
97 | DoLog(2) && (Log() << Verbose(2) << "Steps created and " << filename << " files stored." << endl);
|
---|
98 | }
|
---|
99 | return Action::success;
|
---|
100 | }
|
---|
101 |
|
---|
102 | Action::state_ptr MoleculeLinearInterpolationofTrajectoriesAction::performUndo(Action::state_ptr _state) {
|
---|
103 | // MoleculeLinearInterpolationofTrajectoriesState *state = assert_cast<MoleculeLinearInterpolationofTrajectoriesState*>(_state.get());
|
---|
104 |
|
---|
105 | // string newName = state->mol->getName();
|
---|
106 | // state->mol->setName(state->lastName);
|
---|
107 |
|
---|
108 | return Action::failure;
|
---|
109 | }
|
---|
110 |
|
---|
111 | Action::state_ptr MoleculeLinearInterpolationofTrajectoriesAction::performRedo(Action::state_ptr _state){
|
---|
112 | // Undo and redo have to do the same for this action
|
---|
113 | return performUndo(_state);
|
---|
114 | }
|
---|
115 |
|
---|
116 | bool MoleculeLinearInterpolationofTrajectoriesAction::canUndo() {
|
---|
117 | return false;
|
---|
118 | }
|
---|
119 |
|
---|
120 | bool MoleculeLinearInterpolationofTrajectoriesAction::shouldUndo() {
|
---|
121 | return false;
|
---|
122 | }
|
---|
123 |
|
---|
124 | const string MoleculeLinearInterpolationofTrajectoriesAction::getName() {
|
---|
125 | return NAME;
|
---|
126 | }
|
---|