[bcf653] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[0aa122] | 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
[bcf653] | 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[97ebf8] | 8 | /*
|
---|
| 9 | * RemoveAction.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: May 9, 2010
|
---|
| 12 | * Author: heber
|
---|
| 13 | */
|
---|
| 14 |
|
---|
[bf3817] | 15 | // include config.h
|
---|
| 16 | #ifdef HAVE_CONFIG_H
|
---|
| 17 | #include <config.h>
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
[ad011c] | 20 | #include "CodePatterns/MemDebug.hpp"
|
---|
[112b09] | 21 |
|
---|
[57dd40] | 22 | #include "Actions/UndoRedoHelpers.hpp"
|
---|
[6f0841] | 23 | #include "Atom/atom.hpp"
|
---|
| 24 | #include "Atom/AtomicInfo.hpp"
|
---|
[97ebf8] | 25 | #include "Descriptors/AtomDescriptor.hpp"
|
---|
[ad011c] | 26 | #include "CodePatterns/Log.hpp"
|
---|
[d55743e] | 27 | #include "molecule.hpp"
|
---|
[ad011c] | 28 | #include "CodePatterns/Verbose.hpp"
|
---|
[97ebf8] | 29 | #include "World.hpp"
|
---|
| 30 |
|
---|
| 31 | #include <iostream>
|
---|
| 32 | #include <string>
|
---|
| 33 |
|
---|
[1fd675] | 34 | #include "Actions/AtomAction/RemoveAction.hpp"
|
---|
[5cb3cb] | 35 |
|
---|
[ce7fdc] | 36 | using namespace MoleCuilder;
|
---|
| 37 |
|
---|
[1fd675] | 38 | // and construct the stuff
|
---|
| 39 | #include "RemoveAction.def"
|
---|
| 40 | #include "Action_impl_pre.hpp"
|
---|
| 41 | /** =========== define the function ====================== */
|
---|
[5cb3cb] | 42 | Action::state_ptr AtomRemoveAction::performCall() {
|
---|
[e41c48] | 43 | // create undo state
|
---|
| 44 | std::vector<AtomicInfo> Walkers;
|
---|
[38f991] | 45 | for (World::AtomSelectionConstIterator iter = World::getInstance().beginAtomSelection();
|
---|
| 46 | iter != World::getInstance().endAtomSelection();
|
---|
| 47 | ++iter) {
|
---|
[e41c48] | 48 | Walkers.push_back(AtomicInfo(*(iter->second)));
|
---|
| 49 | }
|
---|
[1fd675] | 50 | AtomRemoveState *UndoState = new AtomRemoveState(Walkers, params);
|
---|
[e41c48] | 51 |
|
---|
| 52 | // remove all selected atoms
|
---|
[38f991] | 53 | for (World::AtomSelectionConstIterator iter = World::getInstance().beginAtomSelection();
|
---|
| 54 | iter != World::getInstance().endAtomSelection();
|
---|
| 55 | iter = World::getInstance().beginAtomSelection()) {
|
---|
[47d041] | 56 | LOG(1, "Removing atom " << (iter->second)->getId() << ".");
|
---|
[38f991] | 57 | World::getInstance().destroyAtom((iter->second));
|
---|
[97ebf8] | 58 | }
|
---|
[e41c48] | 59 | return Action::state_ptr(UndoState);
|
---|
[97ebf8] | 60 | }
|
---|
| 61 |
|
---|
| 62 | Action::state_ptr AtomRemoveAction::performUndo(Action::state_ptr _state) {
|
---|
[e41c48] | 63 | AtomRemoveState *state = assert_cast<AtomRemoveState*>(_state.get());
|
---|
| 64 |
|
---|
[57dd40] | 65 | // add all removed atoms again
|
---|
| 66 | if (AddAtomsFromAtomicInfo(state->Walkers))
|
---|
| 67 | return Action::state_ptr(_state);
|
---|
| 68 | else
|
---|
[e41c48] | 69 | return Action::failure;
|
---|
[97ebf8] | 70 | }
|
---|
| 71 |
|
---|
| 72 | Action::state_ptr AtomRemoveAction::performRedo(Action::state_ptr _state){
|
---|
[e41c48] | 73 | AtomRemoveState *state = assert_cast<AtomRemoveState*>(_state.get());
|
---|
| 74 |
|
---|
| 75 | // simple remove again all previously added atoms
|
---|
[57dd40] | 76 | RemoveAtomsFromAtomicInfo(state->Walkers);
|
---|
[e41c48] | 77 |
|
---|
| 78 | return Action::state_ptr(_state);
|
---|
[97ebf8] | 79 | }
|
---|
| 80 |
|
---|
| 81 | bool AtomRemoveAction::canUndo() {
|
---|
[e41c48] | 82 | return true;
|
---|
[97ebf8] | 83 | }
|
---|
| 84 |
|
---|
| 85 | bool AtomRemoveAction::shouldUndo() {
|
---|
[e41c48] | 86 | return true;
|
---|
[97ebf8] | 87 | }
|
---|
[1fd675] | 88 | /** =========== end of function ====================== */
|
---|