| [bcf653] | 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 |  | 
|---|
| [e212ff] | 8 | /* | 
|---|
|  | 9 | * ClearAllAtomsAction.cpp | 
|---|
|  | 10 | * | 
|---|
|  | 11 | *  Created on: Aug 09, 2010 | 
|---|
|  | 12 | *      Author: heber | 
|---|
|  | 13 | */ | 
|---|
|  | 14 |  | 
|---|
| [bf3817] | 15 | // include config.h | 
|---|
|  | 16 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 17 | #include <config.h> | 
|---|
|  | 18 | #endif | 
|---|
|  | 19 |  | 
|---|
| [e212ff] | 20 | #include "Helpers/MemDebug.hpp" | 
|---|
|  | 21 |  | 
|---|
|  | 22 | #include "Actions/SelectionAction/ClearAllAtomsAction.hpp" | 
|---|
|  | 23 | #include "Actions/ActionRegistry.hpp" | 
|---|
|  | 24 | #include "Descriptors/AtomDescriptor.hpp" | 
|---|
|  | 25 | #include "atom.hpp" | 
|---|
|  | 26 | #include "Helpers/Log.hpp" | 
|---|
|  | 27 | #include "Helpers/Verbose.hpp" | 
|---|
|  | 28 | #include "World.hpp" | 
|---|
|  | 29 |  | 
|---|
|  | 30 | #include <iostream> | 
|---|
|  | 31 | #include <string> | 
|---|
|  | 32 |  | 
|---|
|  | 33 | using namespace std; | 
|---|
|  | 34 |  | 
|---|
|  | 35 | #include "UIElements/UIFactory.hpp" | 
|---|
|  | 36 | #include "UIElements/Dialog.hpp" | 
|---|
|  | 37 | #include "Actions/ValueStorage.hpp" | 
|---|
|  | 38 |  | 
|---|
|  | 39 |  | 
|---|
|  | 40 | // memento to remember the state when undoing | 
|---|
|  | 41 |  | 
|---|
|  | 42 | class SelectionClearAllAtomsState : public ActionState { | 
|---|
|  | 43 | public: | 
|---|
|  | 44 | SelectionClearAllAtomsState(std::vector<atom*> _selectedAtoms) : | 
|---|
|  | 45 | selectedAtoms(_selectedAtoms) | 
|---|
|  | 46 | {} | 
|---|
|  | 47 | std::vector<atom*> selectedAtoms; | 
|---|
|  | 48 | }; | 
|---|
|  | 49 |  | 
|---|
|  | 50 | const char SelectionClearAllAtomsAction::NAME[] = "clear-atom-selection"; | 
|---|
|  | 51 |  | 
|---|
|  | 52 | SelectionClearAllAtomsAction::SelectionClearAllAtomsAction() : | 
|---|
|  | 53 | Action(NAME) | 
|---|
|  | 54 | {} | 
|---|
|  | 55 |  | 
|---|
|  | 56 | SelectionClearAllAtomsAction::~SelectionClearAllAtomsAction() | 
|---|
|  | 57 | {} | 
|---|
|  | 58 |  | 
|---|
|  | 59 | void SelectionClearAllAtoms() { | 
|---|
|  | 60 | ActionRegistry::getInstance().getActionByName(SelectionClearAllAtomsAction::NAME)->call(Action::NonInteractive); | 
|---|
|  | 61 | }; | 
|---|
|  | 62 |  | 
|---|
|  | 63 | Dialog* SelectionClearAllAtomsAction::fillDialog(Dialog *dialog) { | 
|---|
|  | 64 | ASSERT(dialog,"No Dialog given when filling action dialog"); | 
|---|
|  | 65 |  | 
|---|
|  | 66 | dialog->queryEmpty(NAME, ValueStorage::getInstance().getDescription(NAME)); | 
|---|
|  | 67 |  | 
|---|
|  | 68 | return dialog; | 
|---|
|  | 69 | } | 
|---|
|  | 70 |  | 
|---|
|  | 71 | Action::state_ptr SelectionClearAllAtomsAction::performCall() { | 
|---|
|  | 72 | std::vector<atom *> selectedAtoms = World::getInstance().getSelectedAtoms(); | 
|---|
|  | 73 | DoLog(1) && (Log() << Verbose(1) << "Clearing atoms selection." << endl); | 
|---|
|  | 74 | World::getInstance().clearAtomSelection(); | 
|---|
|  | 75 | return Action::state_ptr(new SelectionClearAllAtomsState(selectedAtoms)); | 
|---|
|  | 76 | } | 
|---|
|  | 77 |  | 
|---|
|  | 78 | Action::state_ptr SelectionClearAllAtomsAction::performUndo(Action::state_ptr _state) { | 
|---|
|  | 79 | SelectionClearAllAtomsState *state = assert_cast<SelectionClearAllAtomsState*>(_state.get()); | 
|---|
|  | 80 |  | 
|---|
|  | 81 | World::getInstance().clearAtomSelection(); | 
|---|
|  | 82 | for(std::vector<atom *>::iterator iter = state->selectedAtoms.begin(); iter != state->selectedAtoms.end(); ++iter) | 
|---|
|  | 83 | World::getInstance().selectAtom(*iter); | 
|---|
|  | 84 |  | 
|---|
|  | 85 | return Action::state_ptr(new SelectionClearAllAtomsState(state->selectedAtoms)); | 
|---|
|  | 86 | } | 
|---|
|  | 87 |  | 
|---|
|  | 88 | Action::state_ptr SelectionClearAllAtomsAction::performRedo(Action::state_ptr _state){ | 
|---|
|  | 89 | SelectionClearAllAtomsState *state = assert_cast<SelectionClearAllAtomsState*>(_state.get()); | 
|---|
|  | 90 |  | 
|---|
|  | 91 | World::getInstance().clearAtomSelection(); | 
|---|
|  | 92 |  | 
|---|
|  | 93 | return Action::state_ptr(new SelectionClearAllAtomsState(state->selectedAtoms)); | 
|---|
|  | 94 | } | 
|---|
|  | 95 |  | 
|---|
|  | 96 | bool SelectionClearAllAtomsAction::canUndo() { | 
|---|
|  | 97 | return true; | 
|---|
|  | 98 | } | 
|---|
|  | 99 |  | 
|---|
|  | 100 | bool SelectionClearAllAtomsAction::shouldUndo() { | 
|---|
|  | 101 | return true; | 
|---|
|  | 102 | } | 
|---|
|  | 103 |  | 
|---|
|  | 104 | const string SelectionClearAllAtomsAction::getName() { | 
|---|
|  | 105 | return NAME; | 
|---|
|  | 106 | } | 
|---|