/*
* Project: MoleCuilder
* Description: creates and alters molecular systems
* Copyright (C) 2014 Frederik Heber. All rights reserved.
*
*
* This file is part of MoleCuilder.
*
* MoleCuilder is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* MoleCuilder is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MoleCuilder. If not, see .
*/
/*
* PopAtomsAction.cpp
*
* Created on: Dec 14, 2014
* Author: heber
*/
// include config.h
#ifdef HAVE_CONFIG_H
#include
#endif
#include "CodePatterns/MemDebug.hpp"
#include
#include "CodePatterns/Log.hpp"
#include "Atom/atom.hpp"
#include "World.hpp"
#include "PopAtomsAction.hpp"
using namespace MoleCuilder;
// and construct the stuff
#include "PopAtomsAction.def"
#include "Action_impl_pre.hpp"
/** =========== define the function ====================== */
ActionState::ptr SelectionPopAtomsAction::performCall() {
// create undo state
const std::vector selected_atoms = World::getInstance().getSelectedAtoms();
std::vector selected_atomids(selected_atoms.size(), (atomId_t)-1);
std::transform(
selected_atoms.begin(), selected_atoms.end(),
selected_atomids.begin(),
boost::bind(&atom::getId, _1));
LOG(1, "Popping atom selection.");
World::getInstance().popAtomSelection();
return ActionState::ptr(new SelectionPopAtomsState(selected_atomids, params));
}
ActionState::ptr SelectionPopAtomsAction::performUndo(ActionState::ptr _state) {
SelectionPopAtomsState *state = static_cast(_state.get());
LOG(1, "Popping atom selection.");
World::getInstance().pushAtomSelection();
// and re-create present selection
for(std::vector::const_iterator iter = state->selected_atomids.begin();
iter != state->selected_atomids.end(); ++iter)
World::getInstance().selectAtom(*iter);
return ActionState::ptr(_state);
}
ActionState::ptr SelectionPopAtomsAction::performRedo(ActionState::ptr _state){
LOG(1, "Popping atom selection.");
World::getInstance().popAtomSelection();
return ActionState::ptr(_state);
}
bool SelectionPopAtomsAction::canUndo() {
return true;
}
bool SelectionPopAtomsAction::shouldUndo() {
return true;
}
/** =========== end of function ====================== */