[97ebf8] | 1 | /*
|
---|
| 2 | * TranslateAction.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/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 "Actions/MapOfActions.hpp"
|
---|
| 21 |
|
---|
| 22 | #include "atom.hpp"
|
---|
| 23 | #include "log.hpp"
|
---|
| 24 | #include "molecule.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 | Action::state_ptr MoleculeTranslateAction::performCall() {
|
---|
| 52 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
| 53 | molecule *mol = NULL;
|
---|
| 54 | Vector x;
|
---|
| 55 | bool periodic = false;
|
---|
| 56 |
|
---|
[84c494] | 57 | dialog->queryVector(NAME, &x, false, MapOfActions::getInstance().getDescription(NAME));
|
---|
[97ebf8] | 58 | dialog->queryMolecule("molecule-by-id", &mol, MapOfActions::getInstance().getDescription("molecule-by-id"));
|
---|
| 59 | dialog->queryBoolean("periodic", &periodic, MapOfActions::getInstance().getDescription("periodic"));
|
---|
[77b2d7] | 60 | cout << "pre-dialog" << endl;
|
---|
[97ebf8] | 61 |
|
---|
| 62 | if(dialog->display()) {
|
---|
[77b2d7] | 63 | cout << "post-dialog" << endl;
|
---|
[97ebf8] | 64 | DoLog(1) && (Log() << Verbose(1) << "Translating all ions by given vector." << endl);
|
---|
| 65 | if (periodic)
|
---|
| 66 | mol->TranslatePeriodically((const Vector *)&x);
|
---|
| 67 | else
|
---|
| 68 | mol->Translate((const Vector *)&x);
|
---|
| 69 | delete dialog;
|
---|
| 70 | return Action::success;
|
---|
| 71 | }
|
---|
| 72 | delete dialog;
|
---|
| 73 | return Action::failure;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | Action::state_ptr MoleculeTranslateAction::performUndo(Action::state_ptr _state) {
|
---|
| 77 | // MoleculeTranslateState *state = assert_cast<MoleculeTranslateState*>(_state.get());
|
---|
| 78 |
|
---|
| 79 | // string newName = state->mol->getName();
|
---|
| 80 | // state->mol->setName(state->lastName);
|
---|
| 81 |
|
---|
| 82 | return Action::failure;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | Action::state_ptr MoleculeTranslateAction::performRedo(Action::state_ptr _state){
|
---|
| 86 | // Undo and redo have to do the same for this action
|
---|
| 87 | return performUndo(_state);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | bool MoleculeTranslateAction::canUndo() {
|
---|
| 91 | return false;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | bool MoleculeTranslateAction::shouldUndo() {
|
---|
| 95 | return false;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | const string MoleculeTranslateAction::getName() {
|
---|
| 99 | return NAME;
|
---|
| 100 | }
|
---|