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