| [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 | 
 | 
|---|
| [e472eab] | 8 | /*
 | 
|---|
 | 9 |  * AllAtomsAction.cpp
 | 
|---|
 | 10 |  *
 | 
|---|
 | 11 |  *  Created on: May 12, 2010
 | 
|---|
 | 12 |  *      Author: heber
 | 
|---|
 | 13 |  */
 | 
|---|
 | 14 | 
 | 
|---|
| [bf3817] | 15 | // include config.h
 | 
|---|
 | 16 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 17 | #include <config.h>
 | 
|---|
 | 18 | #endif
 | 
|---|
 | 19 | 
 | 
|---|
| [e472eab] | 20 | #include "Helpers/MemDebug.hpp"
 | 
|---|
 | 21 | 
 | 
|---|
 | 22 | #include "Actions/SelectionAction/AllAtomsAction.hpp"
 | 
|---|
| [0430e3] | 23 | #include "Actions/ActionRegistry.hpp"
 | 
|---|
| [e472eab] | 24 | #include "Descriptors/AtomDescriptor.hpp"
 | 
|---|
 | 25 | #include "atom.hpp"
 | 
|---|
| [952f38] | 26 | #include "Helpers/Log.hpp"
 | 
|---|
 | 27 | #include "Helpers/Verbose.hpp"
 | 
|---|
| [e472eab] | 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"
 | 
|---|
| [861874] | 37 | #include "Actions/ValueStorage.hpp"
 | 
|---|
| [e472eab] | 38 | 
 | 
|---|
 | 39 | 
 | 
|---|
 | 40 | // memento to remember the state when undoing
 | 
|---|
 | 41 | 
 | 
|---|
 | 42 | class SelectionAllAtomsState : public ActionState {
 | 
|---|
 | 43 | public:
 | 
|---|
 | 44 |   SelectionAllAtomsState(std::vector<atom*> _selectedAtoms) :
 | 
|---|
 | 45 |     selectedAtoms(_selectedAtoms)
 | 
|---|
 | 46 |   {}
 | 
|---|
 | 47 |   std::vector<atom*> selectedAtoms;
 | 
|---|
 | 48 | };
 | 
|---|
 | 49 | 
 | 
|---|
 | 50 | const char SelectionAllAtomsAction::NAME[] = "select-all-atoms";
 | 
|---|
 | 51 | 
 | 
|---|
 | 52 | SelectionAllAtomsAction::SelectionAllAtomsAction() :
 | 
|---|
 | 53 |   Action(NAME)
 | 
|---|
 | 54 | {}
 | 
|---|
 | 55 | 
 | 
|---|
 | 56 | SelectionAllAtomsAction::~SelectionAllAtomsAction()
 | 
|---|
 | 57 | {}
 | 
|---|
 | 58 | 
 | 
|---|
| [3b7dfb] | 59 | void SelectionAllAtoms() {
 | 
|---|
 | 60 |   ActionRegistry::getInstance().getActionByName(SelectionAllAtomsAction::NAME)->call(Action::NonInteractive);
 | 
|---|
 | 61 | };
 | 
|---|
 | 62 | 
 | 
|---|
| [047878] | 63 | Dialog* SelectionAllAtomsAction::fillDialog(Dialog *dialog) {
 | 
|---|
 | 64 |   ASSERT(dialog,"No Dialog given when filling action dialog");
 | 
|---|
| [e472eab] | 65 | 
 | 
|---|
 | 66 |   dialog->queryEmpty(NAME, ValueStorage::getInstance().getDescription(NAME));
 | 
|---|
 | 67 | 
 | 
|---|
 | 68 |   return dialog;
 | 
|---|
 | 69 | }
 | 
|---|
 | 70 | 
 | 
|---|
 | 71 | Action::state_ptr SelectionAllAtomsAction::performCall() {
 | 
|---|
 | 72 |   std::vector<atom *> selectedAtoms = World::getInstance().getSelectedAtoms();
 | 
|---|
 | 73 |   DoLog(1) && (Log() << Verbose(1) << "Selecting all atoms." << endl);
 | 
|---|
 | 74 |   World::getInstance().selectAllAtoms(AllAtoms());
 | 
|---|
 | 75 |   return Action::state_ptr(new SelectionAllAtomsState(selectedAtoms));
 | 
|---|
 | 76 | }
 | 
|---|
 | 77 | 
 | 
|---|
 | 78 | Action::state_ptr SelectionAllAtomsAction::performUndo(Action::state_ptr _state) {
 | 
|---|
 | 79 |   SelectionAllAtomsState *state = assert_cast<SelectionAllAtomsState*>(_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 SelectionAllAtomsState(state->selectedAtoms));
 | 
|---|
 | 86 | }
 | 
|---|
 | 87 | 
 | 
|---|
 | 88 | Action::state_ptr SelectionAllAtomsAction::performRedo(Action::state_ptr _state){
 | 
|---|
 | 89 |   SelectionAllAtomsState *state = assert_cast<SelectionAllAtomsState*>(_state.get());
 | 
|---|
 | 90 | 
 | 
|---|
 | 91 |   World::getInstance().selectAllAtoms(AllAtoms());
 | 
|---|
 | 92 | 
 | 
|---|
 | 93 |   return Action::state_ptr(new SelectionAllAtomsState(state->selectedAtoms));
 | 
|---|
 | 94 | }
 | 
|---|
 | 95 | 
 | 
|---|
 | 96 | bool SelectionAllAtomsAction::canUndo() {
 | 
|---|
 | 97 |   return true;
 | 
|---|
 | 98 | }
 | 
|---|
 | 99 | 
 | 
|---|
 | 100 | bool SelectionAllAtomsAction::shouldUndo() {
 | 
|---|
 | 101 |   return true;
 | 
|---|
 | 102 | }
 | 
|---|
 | 103 | 
 | 
|---|
 | 104 | const string SelectionAllAtomsAction::getName() {
 | 
|---|
 | 105 |   return NAME;
 | 
|---|
 | 106 | }
 | 
|---|