| 1 | /*
 | 
|---|
| 2 |  * SetGaussianBasisAction.cpp
 | 
|---|
| 3 |  *
 | 
|---|
| 4 |  *  Created on: May 8, 2010
 | 
|---|
| 5 |  *      Author: heber
 | 
|---|
| 6 |  */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | #include "Helpers/MemDebug.hpp"
 | 
|---|
| 9 | 
 | 
|---|
| 10 | #include "Actions/WorldAction/SetGaussianBasisAction.hpp"
 | 
|---|
| 11 | #include "Actions/ActionRegistry.hpp"
 | 
|---|
| 12 | #include "config.hpp"
 | 
|---|
| 13 | #include "Helpers/Log.hpp"
 | 
|---|
| 14 | #include "Helpers/Verbose.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"
 | 
|---|
| 24 | #include "Actions/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 | 
 | 
|---|
| 37 | 
 | 
|---|
| 38 | const char WorldSetGaussianBasisAction::NAME[] = "set-basis";
 | 
|---|
| 39 | 
 | 
|---|
| 40 | WorldSetGaussianBasisAction::WorldSetGaussianBasisAction() :
 | 
|---|
| 41 |   Action(NAME)
 | 
|---|
| 42 | {}
 | 
|---|
| 43 | 
 | 
|---|
| 44 | WorldSetGaussianBasisAction::~WorldSetGaussianBasisAction()
 | 
|---|
| 45 | {}
 | 
|---|
| 46 | 
 | 
|---|
| 47 | void WorldSetGaussianBasis(std::string &basisname) {
 | 
|---|
| 48 |   ValueStorage::getInstance().setCurrentValue(WorldSetGaussianBasisAction::NAME, basisname);
 | 
|---|
| 49 |   ActionRegistry::getInstance().getActionByName(WorldSetGaussianBasisAction::NAME)->call(Action::NonInteractive);
 | 
|---|
| 50 | };
 | 
|---|
| 51 | 
 | 
|---|
| 52 | Dialog* WorldSetGaussianBasisAction::fillDialog(Dialog *dialog) {
 | 
|---|
| 53 |   ASSERT(dialog,"No Dialog given when filling action dialog");
 | 
|---|
| 54 | 
 | 
|---|
| 55 |   dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
 | 
|---|
| 56 | 
 | 
|---|
| 57 |   return dialog;
 | 
|---|
| 58 | }
 | 
|---|
| 59 | 
 | 
|---|
| 60 | Action::state_ptr WorldSetGaussianBasisAction::performCall() {
 | 
|---|
| 61 |   config *configuration = World::getInstance().getConfig();
 | 
|---|
| 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;
 | 
|---|
| 68 | }
 | 
|---|
| 69 | 
 | 
|---|
| 70 | Action::state_ptr WorldSetGaussianBasisAction::performUndo(Action::state_ptr _state) {
 | 
|---|
| 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;
 | 
|---|
| 76 | 
 | 
|---|
| 77 |   return Action::state_ptr(new WorldSetGaussianBasisState(newName));
 | 
|---|
| 78 | }
 | 
|---|
| 79 | 
 | 
|---|
| 80 | Action::state_ptr WorldSetGaussianBasisAction::performRedo(Action::state_ptr _state){
 | 
|---|
| 81 |   return performUndo(_state);
 | 
|---|
| 82 | }
 | 
|---|
| 83 | 
 | 
|---|
| 84 | bool WorldSetGaussianBasisAction::canUndo() {
 | 
|---|
| 85 |   return true;
 | 
|---|
| 86 | }
 | 
|---|
| 87 | 
 | 
|---|
| 88 | bool WorldSetGaussianBasisAction::shouldUndo() {
 | 
|---|
| 89 |   return true;
 | 
|---|
| 90 | }
 | 
|---|
| 91 | 
 | 
|---|
| 92 | const string WorldSetGaussianBasisAction::getName() {
 | 
|---|
| 93 |   return NAME;
 | 
|---|
| 94 | }
 | 
|---|