[97ebf8] | 1 | /*
|
---|
| 2 | * SetGaussianBasisAction.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: May 8, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[bf3817] | 8 | // include config.h
|
---|
| 9 | #ifdef HAVE_CONFIG_H
|
---|
| 10 | #include <config.h>
|
---|
| 11 | #endif
|
---|
| 12 |
|
---|
[112b09] | 13 | #include "Helpers/MemDebug.hpp"
|
---|
| 14 |
|
---|
[97ebf8] | 15 | #include "Actions/WorldAction/SetGaussianBasisAction.hpp"
|
---|
[0430e3] | 16 | #include "Actions/ActionRegistry.hpp"
|
---|
[97ebf8] | 17 | #include "config.hpp"
|
---|
[952f38] | 18 | #include "Helpers/Log.hpp"
|
---|
| 19 | #include "Helpers/Verbose.hpp"
|
---|
[97ebf8] | 20 | #include "World.hpp"
|
---|
| 21 |
|
---|
| 22 | #include <iostream>
|
---|
| 23 | #include <string>
|
---|
| 24 |
|
---|
| 25 | using namespace std;
|
---|
| 26 |
|
---|
| 27 | #include "UIElements/UIFactory.hpp"
|
---|
| 28 | #include "UIElements/Dialog.hpp"
|
---|
[861874] | 29 | #include "Actions/ValueStorage.hpp"
|
---|
[aee3b1] | 30 |
|
---|
| 31 |
|
---|
| 32 | // memento to remember the state when undoing
|
---|
| 33 |
|
---|
| 34 | class WorldSetGaussianBasisState : public ActionState {
|
---|
| 35 | public:
|
---|
| 36 | WorldSetGaussianBasisState(std::string _lastName) :
|
---|
| 37 | lastName(_lastName)
|
---|
| 38 | {}
|
---|
| 39 | std::string lastName;
|
---|
| 40 | };
|
---|
| 41 |
|
---|
[97ebf8] | 42 |
|
---|
| 43 | const char WorldSetGaussianBasisAction::NAME[] = "set-basis";
|
---|
| 44 |
|
---|
| 45 | WorldSetGaussianBasisAction::WorldSetGaussianBasisAction() :
|
---|
| 46 | Action(NAME)
|
---|
| 47 | {}
|
---|
| 48 |
|
---|
| 49 | WorldSetGaussianBasisAction::~WorldSetGaussianBasisAction()
|
---|
| 50 | {}
|
---|
| 51 |
|
---|
[a8f6ae] | 52 | void WorldSetGaussianBasis(std::string &basisname) {
|
---|
| 53 | ValueStorage::getInstance().setCurrentValue(WorldSetGaussianBasisAction::NAME, basisname);
|
---|
| 54 | ActionRegistry::getInstance().getActionByName(WorldSetGaussianBasisAction::NAME)->call(Action::NonInteractive);
|
---|
| 55 | };
|
---|
| 56 |
|
---|
[047878] | 57 | Dialog* WorldSetGaussianBasisAction::fillDialog(Dialog *dialog) {
|
---|
| 58 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
[aee3b1] | 59 |
|
---|
| 60 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 61 |
|
---|
| 62 | return dialog;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | Action::state_ptr WorldSetGaussianBasisAction::performCall() {
|
---|
[bdaacd] | 66 | config *configuration = World::getInstance().getConfig();
|
---|
[aee3b1] | 67 |
|
---|
| 68 | string lastname = configuration->basis;
|
---|
| 69 | ValueStorage::getInstance().queryCurrentValue(NAME, configuration->basis);
|
---|
| 70 |
|
---|
| 71 | DoLog(1) && (Log() << Verbose(1) << "Setting MPQC basis to " << configuration->basis << "." << endl);
|
---|
| 72 | return Action::success;
|
---|
[97ebf8] | 73 | }
|
---|
| 74 |
|
---|
| 75 | Action::state_ptr WorldSetGaussianBasisAction::performUndo(Action::state_ptr _state) {
|
---|
[aee3b1] | 76 | WorldSetGaussianBasisState *state = assert_cast<WorldSetGaussianBasisState*>(_state.get());
|
---|
| 77 |
|
---|
| 78 | config *configuration = World::getInstance().getConfig();
|
---|
| 79 | string newName = configuration->basis;
|
---|
| 80 | configuration->basis = state->lastName;
|
---|
[97ebf8] | 81 |
|
---|
[aee3b1] | 82 | return Action::state_ptr(new WorldSetGaussianBasisState(newName));
|
---|
[97ebf8] | 83 | }
|
---|
| 84 |
|
---|
| 85 | Action::state_ptr WorldSetGaussianBasisAction::performRedo(Action::state_ptr _state){
|
---|
[680470] | 86 | return performUndo(_state);
|
---|
[97ebf8] | 87 | }
|
---|
| 88 |
|
---|
| 89 | bool WorldSetGaussianBasisAction::canUndo() {
|
---|
[aee3b1] | 90 | return true;
|
---|
[97ebf8] | 91 | }
|
---|
| 92 |
|
---|
| 93 | bool WorldSetGaussianBasisAction::shouldUndo() {
|
---|
[aee3b1] | 94 | return true;
|
---|
[97ebf8] | 95 | }
|
---|
| 96 |
|
---|
| 97 | const string WorldSetGaussianBasisAction::getName() {
|
---|
| 98 | return NAME;
|
---|
| 99 | }
|
---|