| [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 | 
 | 
|---|
| [1cc87e] | 8 | /*
 | 
|---|
 | 9 |  * NotAllAtomsInsideSphereAction.cpp
 | 
|---|
 | 10 |  *
 | 
|---|
 | 11 |  *  Created on: Aug 9, 2010
 | 
|---|
 | 12 |  *      Author: heber
 | 
|---|
 | 13 |  */
 | 
|---|
 | 14 | 
 | 
|---|
| [bf3817] | 15 | // include config.h
 | 
|---|
 | 16 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 17 | #include <config.h>
 | 
|---|
 | 18 | #endif
 | 
|---|
 | 19 | 
 | 
|---|
| [1cc87e] | 20 | #include "Helpers/MemDebug.hpp"
 | 
|---|
 | 21 | 
 | 
|---|
 | 22 | #include "Descriptors/AtomDescriptor.hpp"
 | 
|---|
 | 23 | #include "Descriptors/AtomShapeDescriptor.hpp"
 | 
|---|
 | 24 | #include "atom.hpp"
 | 
|---|
 | 25 | #include "Helpers/Log.hpp"
 | 
|---|
 | 26 | #include "Helpers/Verbose.hpp"
 | 
|---|
 | 27 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
 | 28 | #include "Shapes/BaseShapes.hpp"
 | 
|---|
 | 29 | #include "Shapes/Shape.hpp"
 | 
|---|
 | 30 | #include "Shapes/ShapeOps.hpp"
 | 
|---|
 | 31 | #include "World.hpp"
 | 
|---|
 | 32 | 
 | 
|---|
 | 33 | #include <iostream>
 | 
|---|
 | 34 | #include <string>
 | 
|---|
 | 35 | 
 | 
|---|
 | 36 | using namespace std;
 | 
|---|
 | 37 | 
 | 
|---|
| [1fd675] | 38 | #include "Actions/SelectionAction/NotAllAtomsInsideSphereAction.hpp"
 | 
|---|
| [1cc87e] | 39 | 
 | 
|---|
| [1fd675] | 40 | // and construct the stuff
 | 
|---|
 | 41 | #include "NotAllAtomsInsideSphereAction.def"
 | 
|---|
 | 42 | #include "Action_impl_pre.hpp"
 | 
|---|
 | 43 | /** =========== define the function ====================== */
 | 
|---|
| [1cc87e] | 44 | Action::state_ptr SelectionNotAllAtomsInsideSphereAction::performCall() {
 | 
|---|
 | 45 |   std::vector<atom *> selectedAtoms = World::getInstance().getSelectedAtoms();
 | 
|---|
 | 46 | 
 | 
|---|
| [1fd675] | 47 |   // obtain information
 | 
|---|
 | 48 |   getParametersfromValueStorage();
 | 
|---|
| [1cc87e] | 49 | 
 | 
|---|
| [1fd675] | 50 |   DoLog(1) && (Log() << Verbose(1) << "Unselecting all atoms inside a sphere at " << params.position << " with radius " << params.radius << "." << endl);
 | 
|---|
 | 51 |   Shape s = translate(resize(Sphere(),params.radius),params.position);
 | 
|---|
| [1cc87e] | 52 |   World::getInstance().unselectAllAtoms(AtomByShape(s));
 | 
|---|
| [1fd675] | 53 |   return Action::state_ptr(new SelectionNotAllAtomsInsideSphereState(selectedAtoms, params));
 | 
|---|
| [1cc87e] | 54 | }
 | 
|---|
 | 55 | 
 | 
|---|
 | 56 | Action::state_ptr SelectionNotAllAtomsInsideSphereAction::performUndo(Action::state_ptr _state) {
 | 
|---|
 | 57 |   SelectionNotAllAtomsInsideSphereState *state = assert_cast<SelectionNotAllAtomsInsideSphereState*>(_state.get());
 | 
|---|
 | 58 | 
 | 
|---|
 | 59 |   World::getInstance().clearAtomSelection();
 | 
|---|
 | 60 |   for(std::vector<atom *>::iterator iter = state->selectedAtoms.begin(); iter != state->selectedAtoms.end(); ++iter)
 | 
|---|
 | 61 |     World::getInstance().selectAtom(*iter);
 | 
|---|
 | 62 | 
 | 
|---|
| [1fd675] | 63 |   return Action::state_ptr(_state);
 | 
|---|
| [1cc87e] | 64 | }
 | 
|---|
 | 65 | 
 | 
|---|
 | 66 | Action::state_ptr SelectionNotAllAtomsInsideSphereAction::performRedo(Action::state_ptr _state){
 | 
|---|
 | 67 |   SelectionNotAllAtomsInsideSphereState *state = assert_cast<SelectionNotAllAtomsInsideSphereState*>(_state.get());
 | 
|---|
 | 68 | 
 | 
|---|
| [1fd675] | 69 |   Shape s = translate(resize(Sphere(),state->params.radius),state->params.position);
 | 
|---|
| [1cc87e] | 70 |   World::getInstance().unselectAllAtoms(AtomByShape(s));
 | 
|---|
 | 71 | 
 | 
|---|
| [1fd675] | 72 |   return Action::state_ptr(_state);
 | 
|---|
| [1cc87e] | 73 | }
 | 
|---|
 | 74 | 
 | 
|---|
 | 75 | bool SelectionNotAllAtomsInsideSphereAction::canUndo() {
 | 
|---|
 | 76 |   return true;
 | 
|---|
 | 77 | }
 | 
|---|
 | 78 | 
 | 
|---|
 | 79 | bool SelectionNotAllAtomsInsideSphereAction::shouldUndo() {
 | 
|---|
 | 80 |   return true;
 | 
|---|
 | 81 | }
 | 
|---|
| [1fd675] | 82 | /** =========== end of function ====================== */
 | 
|---|