1 | /*
|
---|
2 | * RemoveAction.cpp
|
---|
3 | *
|
---|
4 | * Created on: May 9, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "Helpers/MemDebug.hpp"
|
---|
9 |
|
---|
10 | #include "Actions/AtomAction/RemoveAction.hpp"
|
---|
11 | #include "Actions/ActionRegistry.hpp"
|
---|
12 | #include "atom.hpp"
|
---|
13 | #include "Descriptors/AtomDescriptor.hpp"
|
---|
14 | #include "Helpers/Log.hpp"
|
---|
15 | #include "molecule.hpp"
|
---|
16 | #include "Helpers/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 "Actions/ValueStorage.hpp"
|
---|
27 |
|
---|
28 | const char AtomRemoveAction::NAME[] = "remove-atom";
|
---|
29 |
|
---|
30 | AtomRemoveAction::AtomRemoveAction() :
|
---|
31 | Action(NAME)
|
---|
32 | {}
|
---|
33 |
|
---|
34 | AtomRemoveAction::~AtomRemoveAction()
|
---|
35 | {}
|
---|
36 |
|
---|
37 | void AtomRemove() {
|
---|
38 | ActionRegistry::getInstance().getActionByName(AtomRemoveAction::NAME)->call(Action::NonInteractive);
|
---|
39 | };
|
---|
40 |
|
---|
41 | Dialog* AtomRemoveAction::fillDialog(Dialog *dialog) {
|
---|
42 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
43 |
|
---|
44 | dialog->queryEmpty(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
45 |
|
---|
46 | return dialog;
|
---|
47 | }
|
---|
48 |
|
---|
49 | Action::state_ptr AtomRemoveAction::performCall() {
|
---|
50 | atom *first = NULL;
|
---|
51 |
|
---|
52 | std::vector<molecule *> molecules = World::getInstance().getAllMolecules();
|
---|
53 | for (World::AtomSelectionIterator iter = World::getInstance().beginAtomSelection(); iter != World::getInstance().endAtomSelection(); ++iter) {
|
---|
54 | first = iter->second;
|
---|
55 | DoLog(1) && (Log() << Verbose(1) << "Removing atom " << first->getId() << "." << endl);
|
---|
56 | // TODO: this is not necessary when atoms and their storing to file are handled by the World
|
---|
57 | // simply try to erase in every molecule found
|
---|
58 | for (std::vector<molecule *>::iterator iter = molecules.begin();iter != molecules.end(); ++iter) {
|
---|
59 | (*iter)->erase(first);
|
---|
60 | }
|
---|
61 | World::getInstance().destroyAtom(first);
|
---|
62 | }
|
---|
63 | return Action::success;
|
---|
64 | }
|
---|
65 |
|
---|
66 | Action::state_ptr AtomRemoveAction::performUndo(Action::state_ptr _state) {
|
---|
67 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
68 |
|
---|
69 | return Action::failure;
|
---|
70 | // string newName = state->mol->getName();
|
---|
71 | // state->mol->setName(state->lastName);
|
---|
72 | //
|
---|
73 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
74 | }
|
---|
75 |
|
---|
76 | Action::state_ptr AtomRemoveAction::performRedo(Action::state_ptr _state){
|
---|
77 | return Action::failure;
|
---|
78 | }
|
---|
79 |
|
---|
80 | bool AtomRemoveAction::canUndo() {
|
---|
81 | return false;
|
---|
82 | }
|
---|
83 |
|
---|
84 | bool AtomRemoveAction::shouldUndo() {
|
---|
85 | return false;
|
---|
86 | }
|
---|
87 |
|
---|
88 | const string AtomRemoveAction::getName() {
|
---|
89 | return NAME;
|
---|
90 | }
|
---|