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 | * Action.cpp
|
---|
10 | *
|
---|
11 | * Created on: Dec 8, 2009
|
---|
12 | * Author: crueger
|
---|
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 <string>
|
---|
23 |
|
---|
24 | #include "Actions/Action.hpp"
|
---|
25 | #include "Actions/ActionRegistry.hpp"
|
---|
26 | #include "Actions/ActionHistory.hpp"
|
---|
27 | #include "Exceptions/MissingValueException.hpp"
|
---|
28 | #include "UIElements/Dialog.hpp"
|
---|
29 | #include "Helpers/MemDebug.hpp"
|
---|
30 | #include "UIElements/UIFactory.hpp"
|
---|
31 |
|
---|
32 | #include "Helpers/Log.hpp"
|
---|
33 | #include "Helpers/Verbose.hpp"
|
---|
34 |
|
---|
35 | using namespace std;
|
---|
36 |
|
---|
37 | Action::state_ptr getEmptyState() {
|
---|
38 | return Action::state_ptr(Memory::ignore(new ActionState()));
|
---|
39 | }
|
---|
40 |
|
---|
41 | // An empty state to indicate success
|
---|
42 | Action::state_ptr Action::success = getEmptyState();
|
---|
43 | Action::state_ptr Action::failure = getEmptyState();
|
---|
44 |
|
---|
45 | Action::Action(std::string _name,bool _doRegister) :
|
---|
46 | name(_name)
|
---|
47 | {
|
---|
48 | if(_doRegister){
|
---|
49 | ActionRegistry::getInstance().registerInstance(this);
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | Action::~Action()
|
---|
54 | {}
|
---|
55 |
|
---|
56 | const string Action::getName(){
|
---|
57 | return name;
|
---|
58 | }
|
---|
59 |
|
---|
60 | Dialog * Action::createDialog(){
|
---|
61 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
62 | return fillDialog(dialog);
|
---|
63 | }
|
---|
64 |
|
---|
65 | void Action::call(enum QueryOptions flag){
|
---|
66 | if(!isActive()){
|
---|
67 | return;
|
---|
68 | }
|
---|
69 | // forward to private virtual
|
---|
70 | if (flag == Interactive) {
|
---|
71 | Dialog* dialog = createDialog();
|
---|
72 | if (dialog->hasQueries()) {
|
---|
73 | dialog->display();
|
---|
74 | }
|
---|
75 | delete(dialog);
|
---|
76 | }
|
---|
77 | state_ptr state = Action::failure;
|
---|
78 | // try {
|
---|
79 | state = performCall();
|
---|
80 | // } catch(MissingValueException&) {
|
---|
81 | // DoeLog(0) && (eLog() << Verbose(0) << "There is a value missing for action " << getName() << endl);
|
---|
82 | // };
|
---|
83 |
|
---|
84 | if(shouldUndo() && state != failure){
|
---|
85 | if(canUndo()){
|
---|
86 | ActionHistory::getInstance().addElement(this,state);
|
---|
87 | }
|
---|
88 | else{
|
---|
89 | ActionHistory::getInstance().clear();
|
---|
90 | }
|
---|
91 | }
|
---|
92 | }
|
---|
93 | Action::state_ptr Action::undo(state_ptr _state) {
|
---|
94 | // forward to private virtual
|
---|
95 | return performUndo(_state);
|
---|
96 | }
|
---|
97 | Action::state_ptr Action::redo(state_ptr _state) {
|
---|
98 | // forward to private virtual
|
---|
99 | return performRedo(_state);
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 | bool Action::isActive(){
|
---|
104 | return true;
|
---|
105 | }
|
---|