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 "atom.hpp"
|
---|
12 | #include "Descriptors/AtomDescriptor.hpp"
|
---|
13 | #include "log.hpp"
|
---|
14 | #include "molecule.hpp"
|
---|
15 | #include "verbose.hpp"
|
---|
16 | #include "World.hpp"
|
---|
17 |
|
---|
18 | #include <iostream>
|
---|
19 | #include <string>
|
---|
20 |
|
---|
21 | using namespace std;
|
---|
22 |
|
---|
23 | #include "UIElements/UIFactory.hpp"
|
---|
24 | #include "UIElements/Dialog.hpp"
|
---|
25 | #include "UIElements/ValueStorage.hpp"
|
---|
26 |
|
---|
27 | const char AtomRemoveAction::NAME[] = "remove-atom";
|
---|
28 |
|
---|
29 | AtomRemoveAction::AtomRemoveAction() :
|
---|
30 | Action(NAME)
|
---|
31 | {}
|
---|
32 |
|
---|
33 | AtomRemoveAction::~AtomRemoveAction()
|
---|
34 | {}
|
---|
35 |
|
---|
36 | Dialog* AtomRemoveAction::createDialog() {
|
---|
37 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
38 |
|
---|
39 | dialog->queryEmpty(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
40 |
|
---|
41 | return dialog;
|
---|
42 | }
|
---|
43 |
|
---|
44 | Action::state_ptr AtomRemoveAction::performCall() {
|
---|
45 | atom *first = NULL;
|
---|
46 |
|
---|
47 | std::vector<molecule *> molecules = World::getInstance().getAllMolecules();
|
---|
48 | for (World::AtomSelectionIterator iter = World::getInstance().beginAtomSelection(); iter != World::getInstance().endAtomSelection(); ++iter) {
|
---|
49 | first = iter->second;
|
---|
50 | DoLog(1) && (Log() << Verbose(1) << "Removing atom " << first->getId() << "." << endl);
|
---|
51 | // TODO: this is not necessary when atoms and their storing to file are handled by the World
|
---|
52 | // simply try to erase in every molecule found
|
---|
53 | for (std::vector<molecule *>::iterator iter = molecules.begin();iter != molecules.end(); ++iter) {
|
---|
54 | (*iter)->erase(first);
|
---|
55 | }
|
---|
56 | World::getInstance().destroyAtom(first);
|
---|
57 | }
|
---|
58 | return Action::success;
|
---|
59 | }
|
---|
60 |
|
---|
61 | Action::state_ptr AtomRemoveAction::performUndo(Action::state_ptr _state) {
|
---|
62 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
63 |
|
---|
64 | return Action::failure;
|
---|
65 | // string newName = state->mol->getName();
|
---|
66 | // state->mol->setName(state->lastName);
|
---|
67 | //
|
---|
68 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
69 | }
|
---|
70 |
|
---|
71 | Action::state_ptr AtomRemoveAction::performRedo(Action::state_ptr _state){
|
---|
72 | return Action::failure;
|
---|
73 | }
|
---|
74 |
|
---|
75 | bool AtomRemoveAction::canUndo() {
|
---|
76 | return false;
|
---|
77 | }
|
---|
78 |
|
---|
79 | bool AtomRemoveAction::shouldUndo() {
|
---|
80 | return false;
|
---|
81 | }
|
---|
82 |
|
---|
83 | const string AtomRemoveAction::getName() {
|
---|
84 | return NAME;
|
---|
85 | }
|
---|