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