1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010 University of Bonn. All rights reserved.
|
---|
5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * CenterInBoxAction.cpp
|
---|
10 | *
|
---|
11 | * Created on: May 8, 2010
|
---|
12 | * Author: heber
|
---|
13 | */
|
---|
14 |
|
---|
15 | // include config.h
|
---|
16 | #ifdef HAVE_CONFIG_H
|
---|
17 | #include <config.h>
|
---|
18 | #endif
|
---|
19 |
|
---|
20 | #include "Helpers/MemDebug.hpp"
|
---|
21 |
|
---|
22 | #include "Actions/WorldAction/CenterInBoxAction.hpp"
|
---|
23 | #include "Actions/ActionRegistry.hpp"
|
---|
24 | #include "Box.hpp"
|
---|
25 | #include "Helpers/Log.hpp"
|
---|
26 | #include "molecule.hpp"
|
---|
27 | #include "World.hpp"
|
---|
28 |
|
---|
29 | #include <iostream>
|
---|
30 | #include <string>
|
---|
31 |
|
---|
32 | using namespace std;
|
---|
33 |
|
---|
34 | #include "UIElements/UIFactory.hpp"
|
---|
35 | #include "UIElements/Dialog.hpp"
|
---|
36 | #include "Actions/ValueStorage.hpp"
|
---|
37 |
|
---|
38 | const char WorldCenterInBoxAction::NAME[] = "center-in-box";
|
---|
39 |
|
---|
40 | WorldCenterInBoxAction::WorldCenterInBoxAction() :
|
---|
41 | Action(NAME)
|
---|
42 | {}
|
---|
43 |
|
---|
44 | WorldCenterInBoxAction::~WorldCenterInBoxAction()
|
---|
45 | {}
|
---|
46 |
|
---|
47 | void WorldCenterInBox(Box &_box) {
|
---|
48 | ValueStorage::getInstance().setCurrentValue(WorldCenterInBoxAction::NAME, _box);
|
---|
49 | ActionRegistry::getInstance().getActionByName(WorldCenterInBoxAction::NAME)->call(Action::NonInteractive);
|
---|
50 | };
|
---|
51 |
|
---|
52 | void WorldCenterInBoxAction::getParametersfromValueStorage()
|
---|
53 | {};
|
---|
54 |
|
---|
55 | Dialog* WorldCenterInBoxAction::fillDialog(Dialog *dialog) {
|
---|
56 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
57 |
|
---|
58 | dialog->queryBox(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
59 |
|
---|
60 | return dialog;
|
---|
61 | }
|
---|
62 |
|
---|
63 | Action::state_ptr WorldCenterInBoxAction::performCall() {
|
---|
64 |
|
---|
65 | Box& cell_size = World::getInstance().getDomain();
|
---|
66 | ValueStorage::getInstance().queryCurrentValue(NAME, cell_size);
|
---|
67 | World::getInstance().setDomain(cell_size.getM());
|
---|
68 |
|
---|
69 | // center
|
---|
70 | vector<molecule *> AllMolecules = World::getInstance().getAllMolecules();
|
---|
71 | for (vector<molecule*>::iterator MolRunner = AllMolecules.begin(); MolRunner != AllMolecules.end(); ++MolRunner) {
|
---|
72 | (*MolRunner)->CenterInBox();
|
---|
73 | }
|
---|
74 | return Action::success;
|
---|
75 | }
|
---|
76 |
|
---|
77 | Action::state_ptr WorldCenterInBoxAction::performUndo(Action::state_ptr _state) {
|
---|
78 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
79 |
|
---|
80 | return Action::failure;
|
---|
81 | // string newName = state->mol->getName();
|
---|
82 | // state->mol->setName(state->lastName);
|
---|
83 | //
|
---|
84 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
85 | }
|
---|
86 |
|
---|
87 | Action::state_ptr WorldCenterInBoxAction::performRedo(Action::state_ptr _state){
|
---|
88 | return Action::failure;
|
---|
89 | }
|
---|
90 |
|
---|
91 | bool WorldCenterInBoxAction::canUndo() {
|
---|
92 | return false;
|
---|
93 | }
|
---|
94 |
|
---|
95 | bool WorldCenterInBoxAction::shouldUndo() {
|
---|
96 | return false;
|
---|
97 | }
|
---|
98 |
|
---|
99 | const string WorldCenterInBoxAction::getName() {
|
---|
100 | return NAME;
|
---|
101 | }
|
---|