| 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 |  * MoleculeOfAtomAction.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/MoleculeDescriptor.hpp"
 | 
|---|
| 23 | #include "Descriptors/MoleculeOfAtomSelectionDescriptor.hpp"
 | 
|---|
| 24 | #include "Helpers/Log.hpp"
 | 
|---|
| 25 | #include "Helpers/Verbose.hpp"
 | 
|---|
| 26 | #include "World.hpp"
 | 
|---|
| 27 | 
 | 
|---|
| 28 | #include <boost/foreach.hpp>
 | 
|---|
| 29 | #include <iostream>
 | 
|---|
| 30 | #include <string>
 | 
|---|
| 31 | 
 | 
|---|
| 32 | using namespace std;
 | 
|---|
| 33 | 
 | 
|---|
| 34 | #include "MoleculeOfAtomAction.hpp"
 | 
|---|
| 35 | 
 | 
|---|
| 36 | // and construct the stuff
 | 
|---|
| 37 | #include "MoleculeOfAtomAction.def"
 | 
|---|
| 38 | #include "Action_impl_pre.hpp"
 | 
|---|
| 39 | /** =========== define the function ====================== */
 | 
|---|
| 40 | Action::state_ptr SelectionMoleculeOfAtomAction::performCall() {
 | 
|---|
| 41 |   // obtain information
 | 
|---|
| 42 |   getParametersfromValueStorage();
 | 
|---|
| 43 | 
 | 
|---|
| 44 |   std::vector<molecule *> selectedMolecules = World::getInstance().getSelectedMolecules();
 | 
|---|
| 45 |   DoLog(1) && (Log() << Verbose(1) << "Selecting molecule to currently selected atoms." << endl);
 | 
|---|
| 46 |   World::getInstance().selectAllMolecules(MoleculesByAtomSelection());
 | 
|---|
| 47 |   return Action::state_ptr(new SelectionMoleculeOfAtomState(selectedMolecules, params));
 | 
|---|
| 48 | }
 | 
|---|
| 49 | 
 | 
|---|
| 50 | Action::state_ptr SelectionMoleculeOfAtomAction::performUndo(Action::state_ptr _state) {
 | 
|---|
| 51 |   SelectionMoleculeOfAtomState *state = assert_cast<SelectionMoleculeOfAtomState*>(_state.get());
 | 
|---|
| 52 | 
 | 
|---|
| 53 |   World::getInstance().clearMoleculeSelection();
 | 
|---|
| 54 |   BOOST_FOREACH(molecule *_mol, state->selectedMolecules)
 | 
|---|
| 55 |     World::getInstance().selectMolecule(_mol);
 | 
|---|
| 56 | 
 | 
|---|
| 57 |   return Action::state_ptr(_state);
 | 
|---|
| 58 | }
 | 
|---|
| 59 | 
 | 
|---|
| 60 | Action::state_ptr SelectionMoleculeOfAtomAction::performRedo(Action::state_ptr _state){
 | 
|---|
| 61 |   //SelectionMoleculeOfAtomState *state = assert_cast<SelectionMoleculeOfAtomState*>(_state.get());
 | 
|---|
| 62 | 
 | 
|---|
| 63 |   World::getInstance().selectAllMolecules(MoleculesByAtomSelection());
 | 
|---|
| 64 | 
 | 
|---|
| 65 |   return Action::state_ptr(_state);
 | 
|---|
| 66 | }
 | 
|---|
| 67 | 
 | 
|---|
| 68 | bool SelectionMoleculeOfAtomAction::canUndo() {
 | 
|---|
| 69 |   return true;
 | 
|---|
| 70 | }
 | 
|---|
| 71 | 
 | 
|---|
| 72 | bool SelectionMoleculeOfAtomAction::shouldUndo() {
 | 
|---|
| 73 |   return true;
 | 
|---|
| 74 | }
 | 
|---|
| 75 | /** =========== end of function ====================== */
 | 
|---|