| [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 | 
 | 
|---|
 | 20 | #include "Helpers/MemDebug.hpp"
 | 
|---|
 | 21 | 
 | 
|---|
 | 22 | #include "Descriptors/AtomTypeDescriptor.hpp"
 | 
|---|
 | 23 | #include "atom.hpp"
 | 
|---|
 | 24 | #include "element.hpp"
 | 
|---|
 | 25 | #include "Helpers/Log.hpp"
 | 
|---|
 | 26 | #include "Helpers/Verbose.hpp"
 | 
|---|
 | 27 | #include "World.hpp"
 | 
|---|
 | 28 | 
 | 
|---|
 | 29 | #include <iostream>
 | 
|---|
 | 30 | #include <string>
 | 
|---|
 | 31 | 
 | 
|---|
 | 32 | using namespace std;
 | 
|---|
 | 33 | 
 | 
|---|
| [1fd675] | 34 | #include "Actions/SelectionAction/AtomByElementAction.hpp"
 | 
|---|
| [51769f] | 35 | 
 | 
|---|
| [1fd675] | 36 | // and construct the stuff
 | 
|---|
 | 37 | #include "AtomByElementAction.def"
 | 
|---|
 | 38 | #include "Action_impl_pre.hpp"
 | 
|---|
 | 39 | /** =========== define the function ====================== */
 | 
|---|
| [51769f] | 40 | Action::state_ptr SelectionAtomByElementAction::performCall() {
 | 
|---|
 | 41 |   std::vector<atom *> selectedAtoms = World::getInstance().getSelectedAtoms();
 | 
|---|
 | 42 | 
 | 
|---|
| [1fd675] | 43 |   // obtain information
 | 
|---|
 | 44 |   getParametersfromValueStorage();
 | 
|---|
| [51769f] | 45 | 
 | 
|---|
| [1fd675] | 46 |   DoLog(1) && (Log() << Verbose(1) << "Selecting atoms of type " << *params.elemental << endl);
 | 
|---|
 | 47 |   World::getInstance().selectAllAtoms(AtomByType(params.elemental));
 | 
|---|
 | 48 |   return Action::state_ptr(new SelectionAtomByElementState(selectedAtoms,params));
 | 
|---|
| [51769f] | 49 | }
 | 
|---|
 | 50 | 
 | 
|---|
 | 51 | Action::state_ptr SelectionAtomByElementAction::performUndo(Action::state_ptr _state) {
 | 
|---|
 | 52 |   SelectionAtomByElementState *state = assert_cast<SelectionAtomByElementState*>(_state.get());
 | 
|---|
 | 53 | 
 | 
|---|
 | 54 |   World::getInstance().clearAtomSelection();
 | 
|---|
 | 55 |   for(std::vector<atom *>::iterator iter = state->selectedAtoms.begin(); iter != state->selectedAtoms.end(); ++iter)
 | 
|---|
 | 56 |     World::getInstance().selectAtom(*iter);
 | 
|---|
 | 57 | 
 | 
|---|
 | 58 |   return Action::state_ptr(_state);
 | 
|---|
 | 59 | }
 | 
|---|
 | 60 | 
 | 
|---|
 | 61 | Action::state_ptr SelectionAtomByElementAction::performRedo(Action::state_ptr _state){
 | 
|---|
 | 62 |   SelectionAtomByElementState *state = assert_cast<SelectionAtomByElementState*>(_state.get());
 | 
|---|
 | 63 | 
 | 
|---|
| [1fd675] | 64 |   World::getInstance().selectAllAtoms(AtomByType(state->params.elemental));
 | 
|---|
| [51769f] | 65 | 
 | 
|---|
 | 66 |   return Action::state_ptr(_state);
 | 
|---|
 | 67 | }
 | 
|---|
 | 68 | 
 | 
|---|
 | 69 | bool SelectionAtomByElementAction::canUndo() {
 | 
|---|
 | 70 |   return true;
 | 
|---|
 | 71 | }
 | 
|---|
 | 72 | 
 | 
|---|
 | 73 | bool SelectionAtomByElementAction::shouldUndo() {
 | 
|---|
 | 74 |   return true;
 | 
|---|
 | 75 | }
 | 
|---|
 | 76 | 
 | 
|---|
 | 77 | const string SelectionAtomByElementAction::getName() {
 | 
|---|
 | 78 |   return NAME;
 | 
|---|
 | 79 | }
 | 
|---|
| [1fd675] | 80 | /** =========== end of function ====================== */
 | 
|---|