[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 |
|
---|
[0b2ce9] | 64 | void WorldSetGaussianBasisAction::getParametersfromValueStorage()
|
---|
| 65 | {};
|
---|
| 66 |
|
---|
[047878] | 67 | Dialog* WorldSetGaussianBasisAction::fillDialog(Dialog *dialog) {
|
---|
| 68 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
[aee3b1] | 69 |
|
---|
| 70 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 71 |
|
---|
| 72 | return dialog;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | Action::state_ptr WorldSetGaussianBasisAction::performCall() {
|
---|
[bdaacd] | 76 | config *configuration = World::getInstance().getConfig();
|
---|
[aee3b1] | 77 |
|
---|
| 78 | string lastname = configuration->basis;
|
---|
| 79 | ValueStorage::getInstance().queryCurrentValue(NAME, configuration->basis);
|
---|
| 80 |
|
---|
| 81 | DoLog(1) && (Log() << Verbose(1) << "Setting MPQC basis to " << configuration->basis << "." << endl);
|
---|
| 82 | return Action::success;
|
---|
[97ebf8] | 83 | }
|
---|
| 84 |
|
---|
| 85 | Action::state_ptr WorldSetGaussianBasisAction::performUndo(Action::state_ptr _state) {
|
---|
[aee3b1] | 86 | WorldSetGaussianBasisState *state = assert_cast<WorldSetGaussianBasisState*>(_state.get());
|
---|
| 87 |
|
---|
| 88 | config *configuration = World::getInstance().getConfig();
|
---|
| 89 | string newName = configuration->basis;
|
---|
| 90 | configuration->basis = state->lastName;
|
---|
[97ebf8] | 91 |
|
---|
[aee3b1] | 92 | return Action::state_ptr(new WorldSetGaussianBasisState(newName));
|
---|
[97ebf8] | 93 | }
|
---|
| 94 |
|
---|
| 95 | Action::state_ptr WorldSetGaussianBasisAction::performRedo(Action::state_ptr _state){
|
---|
[680470] | 96 | return performUndo(_state);
|
---|
[97ebf8] | 97 | }
|
---|
| 98 |
|
---|
| 99 | bool WorldSetGaussianBasisAction::canUndo() {
|
---|
[aee3b1] | 100 | return true;
|
---|
[97ebf8] | 101 | }
|
---|
| 102 |
|
---|
| 103 | bool WorldSetGaussianBasisAction::shouldUndo() {
|
---|
[aee3b1] | 104 | return true;
|
---|
[97ebf8] | 105 | }
|
---|
| 106 |
|
---|
| 107 | const string WorldSetGaussianBasisAction::getName() {
|
---|
| 108 | return NAME;
|
---|
| 109 | }
|
---|