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