1 | /*
|
---|
2 | * TranslateAction.cpp
|
---|
3 | *
|
---|
4 | * Created on: May 10, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "Helpers/MemDebug.hpp"
|
---|
9 |
|
---|
10 | #include "Actions/MoleculeAction/TranslateAction.hpp"
|
---|
11 |
|
---|
12 | #include <iostream>
|
---|
13 | #include <fstream>
|
---|
14 | #include <string>
|
---|
15 |
|
---|
16 | using namespace std;
|
---|
17 |
|
---|
18 | #include "UIElements/UIFactory.hpp"
|
---|
19 | #include "UIElements/Dialog.hpp"
|
---|
20 | #include "UIElements/ValueStorage.hpp"
|
---|
21 |
|
---|
22 | #include "log.hpp"
|
---|
23 | #include "molecule.hpp"
|
---|
24 | #include "vector.hpp"
|
---|
25 | #include "verbose.hpp"
|
---|
26 | #include "World.hpp"
|
---|
27 |
|
---|
28 | /****** MoleculeTranslateAction *****/
|
---|
29 |
|
---|
30 | // memento to remember the state when undoing
|
---|
31 |
|
---|
32 | //class MoleculeTranslateState : public ActionState {
|
---|
33 | //public:
|
---|
34 | // MoleculeTranslateState(molecule* _mol,std::string _lastName) :
|
---|
35 | // mol(_mol),
|
---|
36 | // lastName(_lastName)
|
---|
37 | // {}
|
---|
38 | // molecule* mol;
|
---|
39 | // std::string lastName;
|
---|
40 | //};
|
---|
41 |
|
---|
42 | const char MoleculeTranslateAction::NAME[] = "translate-mol";
|
---|
43 |
|
---|
44 | MoleculeTranslateAction::MoleculeTranslateAction() :
|
---|
45 | Action(NAME)
|
---|
46 | {}
|
---|
47 |
|
---|
48 | MoleculeTranslateAction::~MoleculeTranslateAction()
|
---|
49 | {}
|
---|
50 |
|
---|
51 | Dialog* MoleculeTranslateAction::createDialog() {
|
---|
52 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
53 |
|
---|
54 | dialog->queryVector(NAME, false, ValueStorage::getInstance().getDescription(NAME));
|
---|
55 | dialog->queryBoolean("periodic", ValueStorage::getInstance().getDescription("periodic"));
|
---|
56 |
|
---|
57 | return dialog;
|
---|
58 | }
|
---|
59 |
|
---|
60 | Action::state_ptr MoleculeTranslateAction::performCall() {
|
---|
61 | molecule *mol = NULL;
|
---|
62 | Vector x;
|
---|
63 | bool periodic = false;
|
---|
64 |
|
---|
65 | ValueStorage::getInstance().queryCurrentValue(NAME, x);
|
---|
66 | ValueStorage::getInstance().queryCurrentValue("periodic", periodic);
|
---|
67 |
|
---|
68 | for (World::MoleculeSelectionIterator iter = World::getInstance().beginMoleculeSelection(); iter != World::getInstance().endMoleculeSelection(); ++iter) {
|
---|
69 | mol = iter->second;
|
---|
70 | DoLog(1) && (Log() << Verbose(1) << "Translating all ions by given vector." << endl);
|
---|
71 | if (periodic)
|
---|
72 | mol->TranslatePeriodically((const Vector *)&x);
|
---|
73 | else
|
---|
74 | mol->Translate((const Vector *)&x);
|
---|
75 | }
|
---|
76 | return Action::success;
|
---|
77 | }
|
---|
78 |
|
---|
79 | Action::state_ptr MoleculeTranslateAction::performUndo(Action::state_ptr _state) {
|
---|
80 | // MoleculeTranslateState *state = assert_cast<MoleculeTranslateState*>(_state.get());
|
---|
81 |
|
---|
82 | // string newName = state->mol->getName();
|
---|
83 | // state->mol->setName(state->lastName);
|
---|
84 |
|
---|
85 | return Action::failure;
|
---|
86 | }
|
---|
87 |
|
---|
88 | Action::state_ptr MoleculeTranslateAction::performRedo(Action::state_ptr _state){
|
---|
89 | // Undo and redo have to do the same for this action
|
---|
90 | return performUndo(_state);
|
---|
91 | }
|
---|
92 |
|
---|
93 | bool MoleculeTranslateAction::canUndo() {
|
---|
94 | return false;
|
---|
95 | }
|
---|
96 |
|
---|
97 | bool MoleculeTranslateAction::shouldUndo() {
|
---|
98 | return false;
|
---|
99 | }
|
---|
100 |
|
---|
101 | const string MoleculeTranslateAction::getName() {
|
---|
102 | return NAME;
|
---|
103 | }
|
---|