[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 "atom.hpp"
|
---|
| 12 | #include "Descriptors/AtomDescriptor.hpp"
|
---|
| 13 | #include "log.hpp"
|
---|
[e2b47c] | 14 | #include "molecule.hpp"
|
---|
[97ebf8] | 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.;
|
---|
[e2b47c] | 40 | Vector point;
|
---|
[97ebf8] | 41 |
|
---|
| 42 | dialog->queryDouble(NAME, &radius, MapOfActions::getInstance().getDescription(NAME));
|
---|
[84c494] | 43 | dialog->queryVector("position", &point, false, MapOfActions::getInstance().getDescription("position"));
|
---|
[97ebf8] | 44 |
|
---|
| 45 | if(dialog->display()) {
|
---|
| 46 | delete dialog;
|
---|
[e2b47c] | 47 | DoLog(1) && (Log() << Verbose(1) << "Removing atoms around " << point << " with radius " << radius << "." << endl);
|
---|
[97ebf8] | 48 | vector<atom*> AllAtoms = World::getInstance().getAllAtoms();
|
---|
[e2b47c] | 49 | vector<molecule *> molecules = World::getInstance().getAllMolecules();
|
---|
| 50 | for (vector<atom*>::iterator AtomRunner = AllAtoms.begin(); AtomRunner != AllAtoms.end(); ++AtomRunner) {
|
---|
| 51 | if (point.DistanceSquared((*AtomRunner)->x) > radius*radius) { // distance to first above radius ...
|
---|
| 52 | // TODO: This is not necessary anymore when atoms are completely handled by World (create/destroy and load/save)
|
---|
| 53 | for (vector<molecule *>::iterator iter = molecules.begin();iter != molecules.end();++iter)
|
---|
| 54 | (*iter)->erase(*AtomRunner);
|
---|
| 55 | World::getInstance().destroyAtom(*AtomRunner);
|
---|
| 56 | }
|
---|
[97ebf8] | 57 | }
|
---|
| 58 | return Action::success;
|
---|
| 59 | } else {
|
---|
| 60 | delete dialog;
|
---|
| 61 | return Action::failure;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | Action::state_ptr WorldRemoveSphereOfAtomsAction::performUndo(Action::state_ptr _state) {
|
---|
| 67 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
| 68 |
|
---|
| 69 | return Action::failure;
|
---|
| 70 | // string newName = state->mol->getName();
|
---|
| 71 | // state->mol->setName(state->lastName);
|
---|
| 72 | //
|
---|
| 73 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | Action::state_ptr WorldRemoveSphereOfAtomsAction::performRedo(Action::state_ptr _state){
|
---|
| 77 | return Action::failure;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | bool WorldRemoveSphereOfAtomsAction::canUndo() {
|
---|
| 81 | return false;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | bool WorldRemoveSphereOfAtomsAction::shouldUndo() {
|
---|
| 85 | return false;
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | const string WorldRemoveSphereOfAtomsAction::getName() {
|
---|
| 89 | return NAME;
|
---|
| 90 | }
|
---|