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