1 | /*
|
---|
2 | * RemoveSphereOfAtomsAction.cpp
|
---|
3 | *
|
---|
4 | * Created on: May 12, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "Helpers/MemDebug.hpp"
|
---|
9 |
|
---|
10 | #include "Actions/WorldAction/RemoveSphereOfAtomsAction.hpp"
|
---|
11 | #include "Actions/ActionRegistry.hpp"
|
---|
12 | #include "Descriptors/AtomDescriptor.hpp"
|
---|
13 | #include "atom.hpp"
|
---|
14 | #include "Helpers/Log.hpp"
|
---|
15 | #include "molecule.hpp"
|
---|
16 | #include "LinearAlgebra/Vector.hpp"
|
---|
17 | #include "Helpers/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"
|
---|
27 | #include "Actions/ValueStorage.hpp"
|
---|
28 |
|
---|
29 | const char WorldRemoveSphereOfAtomsAction::NAME[] = "remove-sphere";
|
---|
30 |
|
---|
31 | WorldRemoveSphereOfAtomsAction::WorldRemoveSphereOfAtomsAction() :
|
---|
32 | Action(NAME)
|
---|
33 | {}
|
---|
34 |
|
---|
35 | WorldRemoveSphereOfAtomsAction::~WorldRemoveSphereOfAtomsAction()
|
---|
36 | {}
|
---|
37 |
|
---|
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 |
|
---|
44 | Dialog* WorldRemoveSphereOfAtomsAction::fillDialog(Dialog *dialog) {
|
---|
45 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
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() {
|
---|
54 | double radius = 0.;
|
---|
55 | Vector point;
|
---|
56 |
|
---|
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 ((*AtomRunner)->DistanceSquared(point) > radius*radius) { // distance to first above radius ...
|
---|
65 | // cout << "Removing " << (*AtomRunner)->getType()->symbol << (*AtomRunner)->getId() << " at " << (*AtomRunner)->getPosition() << " as distance is " << sqrt((*AtomRunner)->DistanceSquared(point)) << endl;
|
---|
66 | // TODO: This is not necessary anymore when atoms are completely handled by World (create/destroy and load/save)
|
---|
67 | for (vector<molecule *>::iterator iter = molecules.begin();iter != molecules.end();++iter)
|
---|
68 | (*iter)->erase(*AtomRunner);
|
---|
69 | World::getInstance().destroyAtom(*AtomRunner);
|
---|
70 | }
|
---|
71 | // else {
|
---|
72 | // cout << "Keeping" << (*AtomRunner)->getType()->symbol << (*AtomRunner)->getId() << " at " << (*AtomRunner)->getPosition() << " as distance is " << sqrt((*AtomRunner)->DistanceSquared(point)) << endl;
|
---|
73 | // }
|
---|
74 | }
|
---|
75 | return Action::success;
|
---|
76 | }
|
---|
77 |
|
---|
78 | Action::state_ptr WorldRemoveSphereOfAtomsAction::performUndo(Action::state_ptr _state) {
|
---|
79 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
80 |
|
---|
81 | return Action::failure;
|
---|
82 | // string newName = state->mol->getName();
|
---|
83 | // state->mol->setName(state->lastName);
|
---|
84 | //
|
---|
85 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
86 | }
|
---|
87 |
|
---|
88 | Action::state_ptr WorldRemoveSphereOfAtomsAction::performRedo(Action::state_ptr _state){
|
---|
89 | return Action::failure;
|
---|
90 | }
|
---|
91 |
|
---|
92 | bool WorldRemoveSphereOfAtomsAction::canUndo() {
|
---|
93 | return false;
|
---|
94 | }
|
---|
95 |
|
---|
96 | bool WorldRemoveSphereOfAtomsAction::shouldUndo() {
|
---|
97 | return false;
|
---|
98 | }
|
---|
99 |
|
---|
100 | const string WorldRemoveSphereOfAtomsAction::getName() {
|
---|
101 | return NAME;
|
---|
102 | }
|
---|