| [97ebf8] | 1 | /*
|
|---|
| 2 | * RemoveSphereOfAtomsAction.cpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: May 12, 2010
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| [112b09] | 8 | #include "Helpers/MemDebug.hpp"
|
|---|
| 9 |
|
|---|
| [97ebf8] | 10 | #include "Actions/WorldAction/RemoveSphereOfAtomsAction.hpp"
|
|---|
| 11 | #include "CommandLineParser.hpp"
|
|---|
| 12 | #include "atom.hpp"
|
|---|
| 13 | #include "Descriptors/AtomDescriptor.hpp"
|
|---|
| 14 | #include "log.hpp"
|
|---|
| 15 | #include "vector.hpp"
|
|---|
| 16 | #include "verbose.hpp"
|
|---|
| 17 | #include "World.hpp"
|
|---|
| 18 |
|
|---|
| 19 | #include <iostream>
|
|---|
| 20 | #include <string>
|
|---|
| 21 |
|
|---|
| 22 | using namespace std;
|
|---|
| 23 |
|
|---|
| 24 | #include "UIElements/UIFactory.hpp"
|
|---|
| 25 | #include "UIElements/Dialog.hpp"
|
|---|
| 26 | #include "Actions/MapOfActions.hpp"
|
|---|
| 27 |
|
|---|
| 28 | const char WorldRemoveSphereOfAtomsAction::NAME[] = "remove-sphere";
|
|---|
| 29 |
|
|---|
| 30 | WorldRemoveSphereOfAtomsAction::WorldRemoveSphereOfAtomsAction() :
|
|---|
| 31 | Action(NAME)
|
|---|
| 32 | {}
|
|---|
| 33 |
|
|---|
| 34 | WorldRemoveSphereOfAtomsAction::~WorldRemoveSphereOfAtomsAction()
|
|---|
| 35 | {}
|
|---|
| 36 |
|
|---|
| 37 | Action::state_ptr WorldRemoveSphereOfAtomsAction::performCall() {
|
|---|
| 38 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
|---|
| 39 | double radius = 0.;
|
|---|
| 40 | atom *first = NULL;
|
|---|
| 41 |
|
|---|
| 42 | dialog->queryDouble(NAME, &radius, MapOfActions::getInstance().getDescription(NAME));
|
|---|
| 43 | dialog->queryAtom("atom-by-id", &first, MapOfActions::getInstance().getDescription("atom-by-id"));
|
|---|
| 44 |
|
|---|
| 45 | if(dialog->display()) {
|
|---|
| 46 | delete dialog;
|
|---|
| 47 | DoLog(1) && (Log() << Verbose(1) << "Removing atoms around " << first->nr << " with radius " << radius << "." << endl);
|
|---|
| 48 | vector<atom*> AllAtoms = World::getInstance().getAllAtoms();
|
|---|
| 49 | vector<atom*>::iterator AtomAdvancer = AllAtoms.begin();
|
|---|
| 50 | for (vector<atom*>::iterator AtomRunner = AtomAdvancer; AtomRunner != AllAtoms.end(); ) {
|
|---|
| 51 | ++AtomAdvancer;
|
|---|
| 52 | if (first != *AtomRunner) // dont't destroy reference ...
|
|---|
| 53 | if (first->x.DistanceSquared((*AtomRunner)->x) > radius*radius) // distance to first above radius ...
|
|---|
| 54 | World::getInstance().destroyAtom(*AtomRunner);
|
|---|
| 55 | }
|
|---|
| 56 | World::getInstance().destroyAtom(first);
|
|---|
| 57 | return Action::success;
|
|---|
| 58 | } else {
|
|---|
| 59 | delete dialog;
|
|---|
| 60 | return Action::failure;
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | Action::state_ptr WorldRemoveSphereOfAtomsAction::performUndo(Action::state_ptr _state) {
|
|---|
| 66 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
|---|
| 67 |
|
|---|
| 68 | return Action::failure;
|
|---|
| 69 | // string newName = state->mol->getName();
|
|---|
| 70 | // state->mol->setName(state->lastName);
|
|---|
| 71 | //
|
|---|
| 72 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | Action::state_ptr WorldRemoveSphereOfAtomsAction::performRedo(Action::state_ptr _state){
|
|---|
| 76 | return Action::failure;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | bool WorldRemoveSphereOfAtomsAction::canUndo() {
|
|---|
| 80 | return false;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | bool WorldRemoveSphereOfAtomsAction::shouldUndo() {
|
|---|
| 84 | return false;
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | const string WorldRemoveSphereOfAtomsAction::getName() {
|
|---|
| 88 | return NAME;
|
|---|
| 89 | }
|
|---|