| [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 | 
 | 
|---|
| [51769f] | 8 | /*
 | 
|---|
 | 9 |  * AtomByElementAction.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 | 
 | 
|---|
| [ad011c] | 20 | #include "CodePatterns/MemDebug.hpp"
 | 
|---|
| [51769f] | 21 | 
 | 
|---|
 | 22 | #include "Descriptors/AtomTypeDescriptor.hpp"
 | 
|---|
| [92d756] | 23 | #include "Descriptors/AtomSelectionDescriptor.hpp"
 | 
|---|
| [51769f] | 24 | #include "atom.hpp"
 | 
|---|
| [3bdb6d] | 25 | #include "Element/element.hpp"
 | 
|---|
| [ad011c] | 26 | #include "CodePatterns/Log.hpp"
 | 
|---|
 | 27 | #include "CodePatterns/Verbose.hpp"
 | 
|---|
| [51769f] | 28 | #include "World.hpp"
 | 
|---|
 | 29 | 
 | 
|---|
| [92d756] | 30 | #include <boost/foreach.hpp>
 | 
|---|
| [51769f] | 31 | #include <iostream>
 | 
|---|
 | 32 | #include <string>
 | 
|---|
 | 33 | 
 | 
|---|
| [125002] | 34 | #include "AtomByElementAction.hpp"
 | 
|---|
| [51769f] | 35 | 
 | 
|---|
| [ce7fdc] | 36 | using namespace MoleCuilder;
 | 
|---|
 | 37 | 
 | 
|---|
| [1fd675] | 38 | // and construct the stuff
 | 
|---|
 | 39 | #include "AtomByElementAction.def"
 | 
|---|
 | 40 | #include "Action_impl_pre.hpp"
 | 
|---|
 | 41 | /** =========== define the function ====================== */
 | 
|---|
| [51769f] | 42 | Action::state_ptr SelectionAtomByElementAction::performCall() {
 | 
|---|
| [1fd675] | 43 |   // obtain information
 | 
|---|
 | 44 |   getParametersfromValueStorage();
 | 
|---|
| [51769f] | 45 | 
 | 
|---|
| [47d041] | 46 |   LOG(1, "Selecting atoms of type " << *params.elemental);
 | 
|---|
| [92d756] | 47 |   std::vector<atom *> selectedAtoms = World::getInstance().getAllAtoms(AtomsBySelection());
 | 
|---|
| [1fd675] | 48 |   World::getInstance().selectAllAtoms(AtomByType(params.elemental));
 | 
|---|
| [47d041] | 49 |   LOG(0, World::getInstance().countSelectedAtoms() << " atoms selected.");
 | 
|---|
| [1fd675] | 50 |   return Action::state_ptr(new SelectionAtomByElementState(selectedAtoms,params));
 | 
|---|
| [51769f] | 51 | }
 | 
|---|
 | 52 | 
 | 
|---|
 | 53 | Action::state_ptr SelectionAtomByElementAction::performUndo(Action::state_ptr _state) {
 | 
|---|
 | 54 |   SelectionAtomByElementState *state = assert_cast<SelectionAtomByElementState*>(_state.get());
 | 
|---|
 | 55 | 
 | 
|---|
| [92d756] | 56 |   World::getInstance().unselectAllAtoms(AtomByType(state->params.elemental));
 | 
|---|
 | 57 |   BOOST_FOREACH(atom *_atom, state->selectedAtoms)
 | 
|---|
 | 58 |     World::getInstance().selectAtom(_atom);
 | 
|---|
| [51769f] | 59 | 
 | 
|---|
 | 60 |   return Action::state_ptr(_state);
 | 
|---|
 | 61 | }
 | 
|---|
 | 62 | 
 | 
|---|
 | 63 | Action::state_ptr SelectionAtomByElementAction::performRedo(Action::state_ptr _state){
 | 
|---|
 | 64 |   SelectionAtomByElementState *state = assert_cast<SelectionAtomByElementState*>(_state.get());
 | 
|---|
 | 65 | 
 | 
|---|
| [1fd675] | 66 |   World::getInstance().selectAllAtoms(AtomByType(state->params.elemental));
 | 
|---|
| [51769f] | 67 | 
 | 
|---|
 | 68 |   return Action::state_ptr(_state);
 | 
|---|
 | 69 | }
 | 
|---|
 | 70 | 
 | 
|---|
 | 71 | bool SelectionAtomByElementAction::canUndo() {
 | 
|---|
 | 72 |   return true;
 | 
|---|
 | 73 | }
 | 
|---|
 | 74 | 
 | 
|---|
 | 75 | bool SelectionAtomByElementAction::shouldUndo() {
 | 
|---|
 | 76 |   return true;
 | 
|---|
 | 77 | }
 | 
|---|
| [1fd675] | 78 | /** =========== end of function ====================== */
 | 
|---|