/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2010 University of Bonn. All rights reserved. * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. */ /* * ActionHistory.cpp * * Created on: Mar 25, 2010 * Author: crueger */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/MemDebug.hpp" #include "Actions/ActionHistory.hpp" #include #include "CodePatterns/Singleton_impl.hpp" #include "CodePatterns/Assert.hpp" ActionHistory::ActionHistory() {} ActionHistory::~ActionHistory() {} void ActionHistory::undoLast(){ ASSERT(history.size(),"Undo performed when the undo-queue was empty"); HistoryElement elem = history.back(); history.pop_back(); Action::state_ptr newState = elem.action->undo(elem.state); yrotsih.push_back(HistoryElement(elem.action,newState)); } void ActionHistory::redoLast(){ ASSERT(yrotsih.size(),"Redo performed when the redo-queue was empty"); HistoryElement elem = yrotsih.back(); yrotsih.pop_back(); Action::state_ptr oldState = elem.action->redo(elem.state); history.push_back(HistoryElement(elem.action,oldState)); } bool ActionHistory::hasUndo(){ return history.size()>0; } bool ActionHistory::hasRedo(){ return yrotsih.size()>0; } void ActionHistory::addElement(Action* action,Action::state_ptr state){ yrotsih.clear(); history.push_back(HistoryElement(action,state)); } void ActionHistory::clear(){ history.clear(); yrotsih.clear(); } void ActionHistory::init(){ ActionHistory *hist = new ActionHistory(); setInstance(hist); } CONSTRUCT_SINGLETON(ActionHistory) /****************** Contained actions *******************/