| 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 | 
 | 
|---|
| 8 | /*
 | 
|---|
| 9 |  * AllAtomsAction.cpp
 | 
|---|
| 10 |  *
 | 
|---|
| 11 |  *  Created on: May 12, 2010
 | 
|---|
| 12 |  *      Author: heber
 | 
|---|
| 13 |  */
 | 
|---|
| 14 | 
 | 
|---|
| 15 | // include config.h
 | 
|---|
| 16 | #ifdef HAVE_CONFIG_H
 | 
|---|
| 17 | #include <config.h>
 | 
|---|
| 18 | #endif
 | 
|---|
| 19 | 
 | 
|---|
| 20 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| 21 | 
 | 
|---|
| 22 | #include "Descriptors/AtomDescriptor.hpp"
 | 
|---|
| 23 | #include "atom.hpp"
 | 
|---|
| 24 | #include "CodePatterns/Log.hpp"
 | 
|---|
| 25 | #include "CodePatterns/Verbose.hpp"
 | 
|---|
| 26 | #include "World.hpp"
 | 
|---|
| 27 | 
 | 
|---|
| 28 | #include <boost/foreach.hpp>
 | 
|---|
| 29 | #include <iostream>
 | 
|---|
| 30 | #include <string>
 | 
|---|
| 31 | 
 | 
|---|
| 32 | #include "AllAtomsAction.hpp"
 | 
|---|
| 33 | 
 | 
|---|
| 34 | using namespace MoleCuilder;
 | 
|---|
| 35 | 
 | 
|---|
| 36 | // and construct the stuff
 | 
|---|
| 37 | #include "AllAtomsAction.def"
 | 
|---|
| 38 | #include "Action_impl_pre.hpp"
 | 
|---|
| 39 | /** =========== define the function ====================== */
 | 
|---|
| 40 | Action::state_ptr SelectionAllAtomsAction::performCall() {
 | 
|---|
| 41 |   // obtain information
 | 
|---|
| 42 |   getParametersfromValueStorage();
 | 
|---|
| 43 | 
 | 
|---|
| 44 |   std::vector<atom *> selectedAtoms = World::getInstance().getSelectedAtoms();
 | 
|---|
| 45 |   LOG(1, "Selecting all atoms.");
 | 
|---|
| 46 |   World::getInstance().selectAllAtoms(AllAtoms());
 | 
|---|
| 47 |   LOG(0, World::getInstance().countSelectedAtoms() << " atoms selected.");
 | 
|---|
| 48 |   return Action::state_ptr(new SelectionAllAtomsState(selectedAtoms,params));
 | 
|---|
| 49 | }
 | 
|---|
| 50 | 
 | 
|---|
| 51 | Action::state_ptr SelectionAllAtomsAction::performUndo(Action::state_ptr _state) {
 | 
|---|
| 52 |   SelectionAllAtomsState *state = assert_cast<SelectionAllAtomsState*>(_state.get());
 | 
|---|
| 53 | 
 | 
|---|
| 54 |   World::getInstance().clearAtomSelection();
 | 
|---|
| 55 | 
 | 
|---|
| 56 |   BOOST_FOREACH(atom *_atom, state->selectedAtoms)
 | 
|---|
| 57 |     World::getInstance().selectAtom(_atom);
 | 
|---|
| 58 | 
 | 
|---|
| 59 |   return Action::state_ptr(_state);
 | 
|---|
| 60 | }
 | 
|---|
| 61 | 
 | 
|---|
| 62 | Action::state_ptr SelectionAllAtomsAction::performRedo(Action::state_ptr _state){
 | 
|---|
| 63 |   //SelectionAllAtomsState *state = assert_cast<SelectionAllAtomsState*>(_state.get());
 | 
|---|
| 64 | 
 | 
|---|
| 65 |   World::getInstance().selectAllAtoms(AllAtoms());
 | 
|---|
| 66 | 
 | 
|---|
| 67 |   return Action::state_ptr(_state);
 | 
|---|
| 68 | }
 | 
|---|
| 69 | 
 | 
|---|
| 70 | bool SelectionAllAtomsAction::canUndo() {
 | 
|---|
| 71 |   return true;
 | 
|---|
| 72 | }
 | 
|---|
| 73 | 
 | 
|---|
| 74 | bool SelectionAllAtomsAction::shouldUndo() {
 | 
|---|
| 75 |   return true;
 | 
|---|
| 76 | }
 | 
|---|
| 77 | /** =========== end of function ====================== */
 | 
|---|