[97ebf8] | 1 | /*
|
---|
| 2 | * SetGaussianBasisAction.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/SetGaussianBasisAction.hpp"
|
---|
[0430e3] | 11 | #include "Actions/ActionRegistry.hpp"
|
---|
[97ebf8] | 12 | #include "config.hpp"
|
---|
[bdaacd] | 13 | #include "log.hpp"
|
---|
| 14 | #include "verbose.hpp"
|
---|
[97ebf8] | 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"
|
---|
[aee3b1] | 24 | #include "UIElements/ValueStorage.hpp"
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 | // memento to remember the state when undoing
|
---|
| 28 |
|
---|
| 29 | class WorldSetGaussianBasisState : public ActionState {
|
---|
| 30 | public:
|
---|
| 31 | WorldSetGaussianBasisState(std::string _lastName) :
|
---|
| 32 | lastName(_lastName)
|
---|
| 33 | {}
|
---|
| 34 | std::string lastName;
|
---|
| 35 | };
|
---|
| 36 |
|
---|
[97ebf8] | 37 |
|
---|
| 38 | const char WorldSetGaussianBasisAction::NAME[] = "set-basis";
|
---|
| 39 |
|
---|
| 40 | WorldSetGaussianBasisAction::WorldSetGaussianBasisAction() :
|
---|
| 41 | Action(NAME)
|
---|
| 42 | {}
|
---|
| 43 |
|
---|
| 44 | WorldSetGaussianBasisAction::~WorldSetGaussianBasisAction()
|
---|
| 45 | {}
|
---|
| 46 |
|
---|
[a8f6ae] | 47 | void WorldSetGaussianBasis(std::string &basisname) {
|
---|
| 48 | ValueStorage::getInstance().setCurrentValue(WorldSetGaussianBasisAction::NAME, basisname);
|
---|
| 49 | ActionRegistry::getInstance().getActionByName(WorldSetGaussianBasisAction::NAME)->call(Action::NonInteractive);
|
---|
| 50 | };
|
---|
| 51 |
|
---|
[047878] | 52 | Dialog* WorldSetGaussianBasisAction::fillDialog(Dialog *dialog) {
|
---|
| 53 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
[aee3b1] | 54 |
|
---|
| 55 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 56 |
|
---|
| 57 | return dialog;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | Action::state_ptr WorldSetGaussianBasisAction::performCall() {
|
---|
[bdaacd] | 61 | config *configuration = World::getInstance().getConfig();
|
---|
[aee3b1] | 62 |
|
---|
| 63 | string lastname = configuration->basis;
|
---|
| 64 | ValueStorage::getInstance().queryCurrentValue(NAME, configuration->basis);
|
---|
| 65 |
|
---|
| 66 | DoLog(1) && (Log() << Verbose(1) << "Setting MPQC basis to " << configuration->basis << "." << endl);
|
---|
| 67 | return Action::success;
|
---|
[97ebf8] | 68 | }
|
---|
| 69 |
|
---|
| 70 | Action::state_ptr WorldSetGaussianBasisAction::performUndo(Action::state_ptr _state) {
|
---|
[aee3b1] | 71 | WorldSetGaussianBasisState *state = assert_cast<WorldSetGaussianBasisState*>(_state.get());
|
---|
| 72 |
|
---|
| 73 | config *configuration = World::getInstance().getConfig();
|
---|
| 74 | string newName = configuration->basis;
|
---|
| 75 | configuration->basis = state->lastName;
|
---|
[97ebf8] | 76 |
|
---|
[aee3b1] | 77 | return Action::state_ptr(new WorldSetGaussianBasisState(newName));
|
---|
[97ebf8] | 78 | }
|
---|
| 79 |
|
---|
| 80 | Action::state_ptr WorldSetGaussianBasisAction::performRedo(Action::state_ptr _state){
|
---|
[aee3b1] | 81 | performUndo(_state);
|
---|
[97ebf8] | 82 | }
|
---|
| 83 |
|
---|
| 84 | bool WorldSetGaussianBasisAction::canUndo() {
|
---|
[aee3b1] | 85 | return true;
|
---|
[97ebf8] | 86 | }
|
---|
| 87 |
|
---|
| 88 | bool WorldSetGaussianBasisAction::shouldUndo() {
|
---|
[aee3b1] | 89 | return true;
|
---|
[97ebf8] | 90 | }
|
---|
| 91 |
|
---|
| 92 | const string WorldSetGaussianBasisAction::getName() {
|
---|
| 93 | return NAME;
|
---|
| 94 | }
|
---|