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