source: src/Actions/Action.cpp

Candidate_v1.6.1
Last change on this file was 9eb71b3, checked in by Frederik Heber <frederik.heber@…>, 8 years ago

Commented out MemDebug include and Memory::ignore.

  • MemDebug clashes with various allocation operators that use a specific placement in memory. It is so far not possible to wrap new/delete fully. Hence, we stop this effort which so far has forced us to put ever more includes (with clashes) into MemDebug and thereby bloat compilation time.
  • MemDebug does not add that much usefulness which is not also provided by valgrind.
  • Property mode set to 100644
File size: 4.9 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * Action.cpp
25 *
26 * Created on: Dec 8, 2009
27 * Author: crueger
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35//#include "CodePatterns/MemDebug.hpp"
36
37#include <iostream>
38#include <sstream>
39#include <string>
40
41#include "Actions/Action.hpp"
42#include "Actions/ActionExceptions.hpp"
43#include "Actions/ActionQueue.hpp"
44#include "Actions/ActionRegistry.hpp"
45#include "UIElements/Dialog.hpp"
46#include "CodePatterns/Assert.hpp"
47//#include "CodePatterns/MemDebug.hpp"
48#include "UIElements/UIFactory.hpp"
49
50#include "CodePatterns/Log.hpp"
51#include "CodePatterns/Verbose.hpp"
52
53using namespace MoleCuilder;
54
55ActionState::ptr getEmptyState() {
56 return ActionState::ptr(
57 /* Memory::ignore( */
58 new ActionState())
59 /* ) */
60 ;
61}
62
63void Action::removeStaticStateEntities()
64{
65 Action::success.reset();
66 Action::failure.reset();
67}
68
69void Action::createStaticStateEntities()
70{
71 Action::success = getEmptyState();
72 Action::failure = getEmptyState();
73}
74
75// An empty state to indicate success, these are (de)initialized by ActionHistory
76ActionState::ptr Action::success;
77ActionState::ptr Action::failure;
78
79Action::Action(const ActionTrait &_Traits) :
80 Traits(_Traits)
81{}
82
83Action::~Action()
84{}
85
86const string Action::getName() const
87{
88 return Traits.getName();
89}
90
91const std::string Action::help() const
92{
93 std::stringstream outputstream;
94 outputstream << "Description for Action '" << getName() << "': " << Traits.getDescription()
95 << std::endl;
96 if (!Traits.hasOption(getName())) {
97 outputstream << "\tNote that this Action does not take an argument." << std::endl;
98 }
99 outputstream << "Options available for action '" << getName() << "':" << std::endl;
100 for (ActionTrait::options_const_iterator iter = Traits.getBeginIter();
101 iter != Traits.getEndIter();
102 ++iter) {
103 outputstream << "Option '" << iter->first << "':" << std::endl;
104 outputstream << "\tDescription: " << iter->second->getDescription() << "." << std::endl;
105 outputstream << "\tArgument's type: " << iter->second->getTypeName() << "." << std::endl;
106 outputstream << "\tDefault value: ";
107 if (iter->second->hasDefaultValue()) {
108 outputstream << "Yes, is '" << iter->second->getDefaultValue() << "'";
109 } else {
110 outputstream << "None";
111 }
112 outputstream << "." << std::endl;
113 }
114
115 return outputstream.str();
116}
117
118void Action::prepare(enum QueryOptions flag)
119{
120 // fill with
121 if (flag == Interactive) {
122 Dialog* dialog = createDialog();
123 if (dialog->hasQueries()) {
124 if (!dialog->display())
125 // dialog error or aborted -> throw exception
126 throw ActionFailureException() << ActionNameString(getName());
127 }
128 delete(dialog);
129 }
130}
131
132Dialog * Action::createDialog(){
133 Dialog *dialog = UIFactory::getInstance().makeDialog(Traits.getName());
134 return fillDialog(dialog);
135}
136
137void Action::call(){
138 if(!isActive()){
139 return;
140 }
141 ActionState::ptr state = Action::failure;
142 startTimer();
143 try {
144 state = performCall();
145 } catch (ParameterException &e) {
146 if( const std::string *name=boost::get_error_info<ParameterName>(e) )
147 ELOG(1, "The following parameter value is not valid: " << *name << ".");
148 state = Action::failure;
149 }
150 endTimer();
151
152 if (shouldUndo() && state != Action::failure) {
153 if (canUndo()) {
154 ActionQueue::getInstance().addElement(this,state);
155 }
156// else{
157// ActionQueue::getInstance().clear();
158// }
159 }
160
161 // throw an exception that can be caught in case of failure
162 if (state == Action::failure)
163 throw ActionFailureException() << ActionNameString(getName());
164}
165ActionState::ptr Action::undo(ActionState::ptr _state) {
166 // forward to private virtual
167 return performUndo(_state);
168}
169ActionState::ptr Action::redo(ActionState::ptr _state) {
170 // forward to private virtual
171 return performRedo(_state);
172}
173
174void Action::insertAction(Action *_action, enum Action::QueryOptions state)
175{
176 ActionQueue::getInstance().insertAction(_action, state);
177}
178
179bool Action::isActive() const {
180 return true;
181}
182
183void Action::pushStatus(const std::string& _msg)
184{
185 ActionQueue::getInstance().pushStatus(_msg);
186}
187
Note: See TracBrowser for help on using the repository browser.