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 | void WorldSetGaussianBasisAction::getParametersfromValueStorage()
|
---|
65 | {};
|
---|
66 |
|
---|
67 | Dialog* WorldSetGaussianBasisAction::fillDialog(Dialog *dialog) {
|
---|
68 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
69 |
|
---|
70 | dialog->queryString(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
71 |
|
---|
72 | return dialog;
|
---|
73 | }
|
---|
74 |
|
---|
75 | Action::state_ptr WorldSetGaussianBasisAction::performCall() {
|
---|
76 | config *configuration = World::getInstance().getConfig();
|
---|
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;
|
---|
83 | }
|
---|
84 |
|
---|
85 | Action::state_ptr WorldSetGaussianBasisAction::performUndo(Action::state_ptr _state) {
|
---|
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;
|
---|
91 |
|
---|
92 | return Action::state_ptr(new WorldSetGaussianBasisState(newName));
|
---|
93 | }
|
---|
94 |
|
---|
95 | Action::state_ptr WorldSetGaussianBasisAction::performRedo(Action::state_ptr _state){
|
---|
96 | return performUndo(_state);
|
---|
97 | }
|
---|
98 |
|
---|
99 | bool WorldSetGaussianBasisAction::canUndo() {
|
---|
100 | return true;
|
---|
101 | }
|
---|
102 |
|
---|
103 | bool WorldSetGaussianBasisAction::shouldUndo() {
|
---|
104 | return true;
|
---|
105 | }
|
---|
106 |
|
---|
107 | const string WorldSetGaussianBasisAction::getName() {
|
---|
108 | return NAME;
|
---|
109 | }
|
---|