[1cc87e] | 1 | /*
|
---|
| 2 | * NotAllAtomsInsideSphereAction.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Aug 9, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #include "Helpers/MemDebug.hpp"
|
---|
| 9 |
|
---|
| 10 | #include "Actions/SelectionAction/NotAllAtomsInsideSphereAction.hpp"
|
---|
| 11 | #include "Actions/ActionRegistry.hpp"
|
---|
| 12 | #include "Descriptors/AtomDescriptor.hpp"
|
---|
| 13 | #include "Descriptors/AtomShapeDescriptor.hpp"
|
---|
| 14 | #include "atom.hpp"
|
---|
| 15 | #include "Helpers/Log.hpp"
|
---|
| 16 | #include "Helpers/Verbose.hpp"
|
---|
| 17 | #include "LinearAlgebra/Vector.hpp"
|
---|
| 18 | #include "Shapes/BaseShapes.hpp"
|
---|
| 19 | #include "Shapes/Shape.hpp"
|
---|
| 20 | #include "Shapes/ShapeOps.hpp"
|
---|
| 21 | #include "World.hpp"
|
---|
| 22 |
|
---|
| 23 | #include <iostream>
|
---|
| 24 | #include <string>
|
---|
| 25 |
|
---|
| 26 | using namespace std;
|
---|
| 27 |
|
---|
| 28 | #include "UIElements/UIFactory.hpp"
|
---|
| 29 | #include "UIElements/Dialog.hpp"
|
---|
| 30 | #include "Actions/ValueStorage.hpp"
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 | // memento to remember the state when undoing
|
---|
| 34 |
|
---|
| 35 | class SelectionNotAllAtomsInsideSphereState : public ActionState {
|
---|
| 36 | public:
|
---|
| 37 | SelectionNotAllAtomsInsideSphereState(std::vector<atom*> _selectedAtoms, const Vector &_position, const double _radius) :
|
---|
| 38 | selectedAtoms(_selectedAtoms),
|
---|
| 39 | position(_position),
|
---|
| 40 | radius(_radius)
|
---|
| 41 | {}
|
---|
| 42 | std::vector<atom*> selectedAtoms;
|
---|
| 43 | Vector position;
|
---|
| 44 | double radius;
|
---|
| 45 | };
|
---|
| 46 |
|
---|
| 47 | const char SelectionNotAllAtomsInsideSphereAction::NAME[] = "unselect-atoms-inside-sphere";
|
---|
| 48 |
|
---|
| 49 | SelectionNotAllAtomsInsideSphereAction::SelectionNotAllAtomsInsideSphereAction() :
|
---|
| 50 | Action(NAME)
|
---|
| 51 | {}
|
---|
| 52 |
|
---|
| 53 | SelectionNotAllAtomsInsideSphereAction::~SelectionNotAllAtomsInsideSphereAction()
|
---|
| 54 | {}
|
---|
| 55 |
|
---|
| 56 | void SelectionNotAllAtomsInsideSphere(const Vector &position, const double radius) {
|
---|
| 57 | ValueStorage::getInstance().setCurrentValue(SelectionNotAllAtomsInsideSphereAction::NAME, radius);
|
---|
| 58 | ValueStorage::getInstance().setCurrentValue("position", position);
|
---|
| 59 | ActionRegistry::getInstance().getActionByName(SelectionNotAllAtomsInsideSphereAction::NAME)->call(Action::NonInteractive);
|
---|
| 60 | };
|
---|
| 61 |
|
---|
| 62 | Dialog* SelectionNotAllAtomsInsideSphereAction::fillDialog(Dialog *dialog) {
|
---|
| 63 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
| 64 |
|
---|
| 65 | dialog->queryDouble(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 66 | dialog->queryVector("position", false, ValueStorage::getInstance().getDescription("position"));
|
---|
| 67 |
|
---|
| 68 | return dialog;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | Action::state_ptr SelectionNotAllAtomsInsideSphereAction::performCall() {
|
---|
| 72 | std::vector<atom *> selectedAtoms = World::getInstance().getSelectedAtoms();
|
---|
| 73 | double radius = 0.;
|
---|
| 74 | Vector position;
|
---|
| 75 |
|
---|
| 76 | ValueStorage::getInstance().queryCurrentValue(NAME, radius);
|
---|
| 77 | ValueStorage::getInstance().queryCurrentValue("position", position);
|
---|
| 78 |
|
---|
| 79 | DoLog(1) && (Log() << Verbose(1) << "Unselecting all atoms inside a sphere at " << position << " with radius " << radius << "." << endl);
|
---|
| 80 | Shape s = translate(resize(Sphere(),radius),position);
|
---|
| 81 | World::getInstance().unselectAllAtoms(AtomByShape(s));
|
---|
| 82 | return Action::state_ptr(new SelectionNotAllAtomsInsideSphereState(selectedAtoms, position, radius));
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | Action::state_ptr SelectionNotAllAtomsInsideSphereAction::performUndo(Action::state_ptr _state) {
|
---|
| 86 | SelectionNotAllAtomsInsideSphereState *state = assert_cast<SelectionNotAllAtomsInsideSphereState*>(_state.get());
|
---|
| 87 |
|
---|
| 88 | World::getInstance().clearAtomSelection();
|
---|
| 89 | for(std::vector<atom *>::iterator iter = state->selectedAtoms.begin(); iter != state->selectedAtoms.end(); ++iter)
|
---|
| 90 | World::getInstance().selectAtom(*iter);
|
---|
| 91 |
|
---|
| 92 | return Action::state_ptr(new SelectionNotAllAtomsInsideSphereState(state->selectedAtoms, state->position, state->radius));
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | Action::state_ptr SelectionNotAllAtomsInsideSphereAction::performRedo(Action::state_ptr _state){
|
---|
| 96 | SelectionNotAllAtomsInsideSphereState *state = assert_cast<SelectionNotAllAtomsInsideSphereState*>(_state.get());
|
---|
| 97 |
|
---|
| 98 | Shape s = translate(resize(Sphere(),state->radius),state->position);
|
---|
| 99 | World::getInstance().unselectAllAtoms(AtomByShape(s));
|
---|
| 100 |
|
---|
| 101 | return Action::state_ptr(new SelectionNotAllAtomsInsideSphereState(state->selectedAtoms, state->position, state->radius));
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | bool SelectionNotAllAtomsInsideSphereAction::canUndo() {
|
---|
| 105 | return true;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | bool SelectionNotAllAtomsInsideSphereAction::shouldUndo() {
|
---|
| 109 | return true;
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | const string SelectionNotAllAtomsInsideSphereAction::getName() {
|
---|
| 113 | return NAME;
|
---|
| 114 | }
|
---|