| [97ebf8] | 1 | /*
|
|---|
| 2 | * CenterInBoxAction.cpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: May 8, 2010
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| [112b09] | 8 | #include "Helpers/MemDebug.hpp"
|
|---|
| 9 |
|
|---|
| [97ebf8] | 10 | #include "Actions/WorldAction/CenterInBoxAction.hpp"
|
|---|
| [0430e3] | 11 | #include "Actions/ActionRegistry.hpp"
|
|---|
| [4aece0] | 12 | #include "Box.hpp"
|
|---|
| [952f38] | 13 | #include "Helpers/Log.hpp"
|
|---|
| [97ebf8] | 14 | #include "molecule.hpp"
|
|---|
| 15 | #include "World.hpp"
|
|---|
| 16 |
|
|---|
| 17 | #include <iostream>
|
|---|
| 18 | #include <string>
|
|---|
| 19 |
|
|---|
| 20 | using namespace std;
|
|---|
| 21 |
|
|---|
| 22 | #include "UIElements/UIFactory.hpp"
|
|---|
| 23 | #include "UIElements/Dialog.hpp"
|
|---|
| [861874] | 24 | #include "Actions/ValueStorage.hpp"
|
|---|
| [97ebf8] | 25 |
|
|---|
| 26 | const char WorldCenterInBoxAction::NAME[] = "center-in-box";
|
|---|
| 27 |
|
|---|
| 28 | WorldCenterInBoxAction::WorldCenterInBoxAction() :
|
|---|
| 29 | Action(NAME)
|
|---|
| 30 | {}
|
|---|
| 31 |
|
|---|
| 32 | WorldCenterInBoxAction::~WorldCenterInBoxAction()
|
|---|
| 33 | {}
|
|---|
| 34 |
|
|---|
| [a8f6ae] | 35 | void WorldCenterInBox(Box &_box) {
|
|---|
| 36 | ValueStorage::getInstance().setCurrentValue(WorldCenterInBoxAction::NAME, _box);
|
|---|
| 37 | ActionRegistry::getInstance().getActionByName(WorldCenterInBoxAction::NAME)->call(Action::NonInteractive);
|
|---|
| 38 | };
|
|---|
| 39 |
|
|---|
| [047878] | 40 | Dialog* WorldCenterInBoxAction::fillDialog(Dialog *dialog) {
|
|---|
| 41 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
|---|
| [97ebf8] | 42 |
|
|---|
| [4aece0] | 43 | dialog->queryBox(NAME, ValueStorage::getInstance().getDescription(NAME));
|
|---|
| 44 |
|
|---|
| 45 | return dialog;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | Action::state_ptr WorldCenterInBoxAction::performCall() {
|
|---|
| 49 |
|
|---|
| [84c494] | 50 | Box& cell_size = World::getInstance().getDomain();
|
|---|
| [4aece0] | 51 | ValueStorage::getInstance().queryCurrentValue(NAME, cell_size);
|
|---|
| 52 | World::getInstance().setDomain(cell_size.getM());
|
|---|
| 53 |
|
|---|
| 54 | // center
|
|---|
| 55 | vector<molecule *> AllMolecules = World::getInstance().getAllMolecules();
|
|---|
| 56 | for (vector<molecule*>::iterator MolRunner = AllMolecules.begin(); MolRunner != AllMolecules.end(); ++MolRunner) {
|
|---|
| 57 | (*MolRunner)->CenterInBox();
|
|---|
| [97ebf8] | 58 | }
|
|---|
| [4aece0] | 59 | return Action::success;
|
|---|
| [97ebf8] | 60 | }
|
|---|
| 61 |
|
|---|
| 62 | Action::state_ptr WorldCenterInBoxAction::performUndo(Action::state_ptr _state) {
|
|---|
| 63 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
|---|
| 64 |
|
|---|
| 65 | return Action::failure;
|
|---|
| 66 | // string newName = state->mol->getName();
|
|---|
| 67 | // state->mol->setName(state->lastName);
|
|---|
| 68 | //
|
|---|
| 69 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | Action::state_ptr WorldCenterInBoxAction::performRedo(Action::state_ptr _state){
|
|---|
| 73 | return Action::failure;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | bool WorldCenterInBoxAction::canUndo() {
|
|---|
| 77 | return false;
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | bool WorldCenterInBoxAction::shouldUndo() {
|
|---|
| 81 | return false;
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | const string WorldCenterInBoxAction::getName() {
|
|---|
| 85 | return NAME;
|
|---|
| 86 | }
|
|---|