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"
|
---|
12 | #include "vector.hpp"
|
---|
13 | #include "verbose.hpp"
|
---|
14 | #include "World.hpp"
|
---|
15 |
|
---|
16 | #include <iostream>
|
---|
17 | #include <string>
|
---|
18 |
|
---|
19 | using namespace std;
|
---|
20 |
|
---|
21 | #include "UIElements/UIFactory.hpp"
|
---|
22 | #include "UIElements/Dialog.hpp"
|
---|
23 | #include "Actions/MapOfActions.hpp"
|
---|
24 |
|
---|
25 | const char WorldRemoveSphereOfAtomsAction::NAME[] = "remove-sphere";
|
---|
26 |
|
---|
27 | WorldRemoveSphereOfAtomsAction::WorldRemoveSphereOfAtomsAction() :
|
---|
28 | Action(NAME)
|
---|
29 | {}
|
---|
30 |
|
---|
31 | WorldRemoveSphereOfAtomsAction::~WorldRemoveSphereOfAtomsAction()
|
---|
32 | {}
|
---|
33 |
|
---|
34 | Action::state_ptr WorldRemoveSphereOfAtomsAction::performCall() {
|
---|
35 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
36 | double radius = 0.;
|
---|
37 | atom *first = NULL;
|
---|
38 |
|
---|
39 | dialog->queryDouble(NAME, &radius, MapOfActions::getInstance().getDescription(NAME));
|
---|
40 | dialog->queryAtom("atom-by-id", &first, MapOfActions::getInstance().getDescription("atom-by-id"));
|
---|
41 |
|
---|
42 | if(dialog->display()) {
|
---|
43 | delete dialog;
|
---|
44 | DoLog(1) && (Log() << Verbose(1) << "Removing atoms around " << first->nr << " with radius " << radius << "." << endl);
|
---|
45 | vector<atom*> AllAtoms = World::getInstance().getAllAtoms();
|
---|
46 | vector<atom*>::iterator AtomAdvancer = AllAtoms.begin();
|
---|
47 | for (vector<atom*>::iterator AtomRunner = AtomAdvancer; AtomRunner != AllAtoms.end(); ) {
|
---|
48 | ++AtomAdvancer;
|
---|
49 | if (first != *AtomRunner) // dont't destroy reference ...
|
---|
50 | if (first->x.DistanceSquared((*AtomRunner)->x) > radius*radius) // distance to first above radius ...
|
---|
51 | World::getInstance().destroyAtom(*AtomRunner);
|
---|
52 | }
|
---|
53 | World::getInstance().destroyAtom(first);
|
---|
54 | return Action::success;
|
---|
55 | } else {
|
---|
56 | delete dialog;
|
---|
57 | return Action::failure;
|
---|
58 | }
|
---|
59 |
|
---|
60 | }
|
---|
61 |
|
---|
62 | Action::state_ptr WorldRemoveSphereOfAtomsAction::performUndo(Action::state_ptr _state) {
|
---|
63 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
64 |
|
---|
65 | return Action::failure;
|
---|
66 | // string newName = state->mol->getName();
|
---|
67 | // state->mol->setName(state->lastName);
|
---|
68 | //
|
---|
69 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
70 | }
|
---|
71 |
|
---|
72 | Action::state_ptr WorldRemoveSphereOfAtomsAction::performRedo(Action::state_ptr _state){
|
---|
73 | return Action::failure;
|
---|
74 | }
|
---|
75 |
|
---|
76 | bool WorldRemoveSphereOfAtomsAction::canUndo() {
|
---|
77 | return false;
|
---|
78 | }
|
---|
79 |
|
---|
80 | bool WorldRemoveSphereOfAtomsAction::shouldUndo() {
|
---|
81 | return false;
|
---|
82 | }
|
---|
83 |
|
---|
84 | const string WorldRemoveSphereOfAtomsAction::getName() {
|
---|
85 | return NAME;
|
---|
86 | }
|
---|