| [bcf653] | 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 | 
 | 
|---|
| [97ebf8] | 8 | /*
 | 
|---|
 | 9 |  * SetGaussianBasisAction.cpp
 | 
|---|
 | 10 |  *
 | 
|---|
 | 11 |  *  Created on: May 8, 2010
 | 
|---|
 | 12 |  *      Author: heber
 | 
|---|
 | 13 |  */
 | 
|---|
 | 14 | 
 | 
|---|
| [bf3817] | 15 | // include config.h
 | 
|---|
 | 16 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 17 | #include <config.h>
 | 
|---|
 | 18 | #endif
 | 
|---|
 | 19 | 
 | 
|---|
| [112b09] | 20 | #include "Helpers/MemDebug.hpp"
 | 
|---|
 | 21 | 
 | 
|---|
| [97ebf8] | 22 | #include "Actions/WorldAction/SetGaussianBasisAction.hpp"
 | 
|---|
| [0430e3] | 23 | #include "Actions/ActionRegistry.hpp"
 | 
|---|
| [97ebf8] | 24 | #include "config.hpp"
 | 
|---|
| [952f38] | 25 | #include "Helpers/Log.hpp"
 | 
|---|
 | 26 | #include "Helpers/Verbose.hpp"
 | 
|---|
| [97ebf8] | 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"
 | 
|---|
| [861874] | 36 | #include "Actions/ValueStorage.hpp"
 | 
|---|
| [aee3b1] | 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 | 
 | 
|---|
| [97ebf8] | 49 | 
 | 
|---|
 | 50 | const char WorldSetGaussianBasisAction::NAME[] = "set-basis";
 | 
|---|
 | 51 | 
 | 
|---|
 | 52 | WorldSetGaussianBasisAction::WorldSetGaussianBasisAction() :
 | 
|---|
 | 53 |   Action(NAME)
 | 
|---|
 | 54 | {}
 | 
|---|
 | 55 | 
 | 
|---|
 | 56 | WorldSetGaussianBasisAction::~WorldSetGaussianBasisAction()
 | 
|---|
 | 57 | {}
 | 
|---|
 | 58 | 
 | 
|---|
| [a8f6ae] | 59 | void WorldSetGaussianBasis(std::string &basisname) {
 | 
|---|
 | 60 |   ValueStorage::getInstance().setCurrentValue(WorldSetGaussianBasisAction::NAME, basisname);
 | 
|---|
 | 61 |   ActionRegistry::getInstance().getActionByName(WorldSetGaussianBasisAction::NAME)->call(Action::NonInteractive);
 | 
|---|
 | 62 | };
 | 
|---|
 | 63 | 
 | 
|---|
| [047878] | 64 | Dialog* WorldSetGaussianBasisAction::fillDialog(Dialog *dialog) {
 | 
|---|
 | 65 |   ASSERT(dialog,"No Dialog given when filling action dialog");
 | 
|---|
| [aee3b1] | 66 | 
 | 
|---|
 | 67 |   dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
 | 
|---|
 | 68 | 
 | 
|---|
 | 69 |   return dialog;
 | 
|---|
 | 70 | }
 | 
|---|
 | 71 | 
 | 
|---|
 | 72 | Action::state_ptr WorldSetGaussianBasisAction::performCall() {
 | 
|---|
| [bdaacd] | 73 |   config *configuration = World::getInstance().getConfig();
 | 
|---|
| [aee3b1] | 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;
 | 
|---|
| [97ebf8] | 80 | }
 | 
|---|
 | 81 | 
 | 
|---|
 | 82 | Action::state_ptr WorldSetGaussianBasisAction::performUndo(Action::state_ptr _state) {
 | 
|---|
| [aee3b1] | 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;
 | 
|---|
| [97ebf8] | 88 | 
 | 
|---|
| [aee3b1] | 89 |   return Action::state_ptr(new WorldSetGaussianBasisState(newName));
 | 
|---|
| [97ebf8] | 90 | }
 | 
|---|
 | 91 | 
 | 
|---|
 | 92 | Action::state_ptr WorldSetGaussianBasisAction::performRedo(Action::state_ptr _state){
 | 
|---|
| [680470] | 93 |   return performUndo(_state);
 | 
|---|
| [97ebf8] | 94 | }
 | 
|---|
 | 95 | 
 | 
|---|
 | 96 | bool WorldSetGaussianBasisAction::canUndo() {
 | 
|---|
| [aee3b1] | 97 |   return true;
 | 
|---|
| [97ebf8] | 98 | }
 | 
|---|
 | 99 | 
 | 
|---|
 | 100 | bool WorldSetGaussianBasisAction::shouldUndo() {
 | 
|---|
| [aee3b1] | 101 |   return true;
 | 
|---|
| [97ebf8] | 102 | }
 | 
|---|
 | 103 | 
 | 
|---|
 | 104 | const string WorldSetGaussianBasisAction::getName() {
 | 
|---|
 | 105 |   return NAME;
 | 
|---|
 | 106 | }
 | 
|---|