1 | /*
|
---|
2 | * ChangeElementAction.cpp
|
---|
3 | *
|
---|
4 | * Created on: May 9, 2010
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "Helpers/MemDebug.hpp"
|
---|
9 |
|
---|
10 | #include "Actions/AtomAction/ChangeElementAction.hpp"
|
---|
11 | #include "Actions/ActionRegistry.hpp"
|
---|
12 | #include "atom.hpp"
|
---|
13 | #include "element.hpp"
|
---|
14 | #include "Helpers/Log.hpp"
|
---|
15 | #include "LinearAlgebra/Vector.hpp"
|
---|
16 | #include "Helpers/Verbose.hpp"
|
---|
17 | #include "molecule.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 AtomChangeElementAction::NAME[] = "change-element";
|
---|
30 |
|
---|
31 | AtomChangeElementAction::AtomChangeElementAction() :
|
---|
32 | Action(NAME)
|
---|
33 | {}
|
---|
34 |
|
---|
35 | AtomChangeElementAction::~AtomChangeElementAction()
|
---|
36 | {}
|
---|
37 |
|
---|
38 | void AtomChangeElement(element *elemental) {
|
---|
39 | ValueStorage::getInstance().setCurrentValue(AtomChangeElementAction::NAME, elemental);
|
---|
40 | ActionRegistry::getInstance().getActionByName(AtomChangeElementAction::NAME)->call(Action::NonInteractive);
|
---|
41 | };
|
---|
42 |
|
---|
43 | Dialog* AtomChangeElementAction::fillDialog(Dialog *dialog) {
|
---|
44 | ASSERT(dialog,"No Dialog given when filling action dialog");
|
---|
45 |
|
---|
46 | dialog->queryElement(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
47 |
|
---|
48 | return dialog;
|
---|
49 | }
|
---|
50 |
|
---|
51 | Action::state_ptr AtomChangeElementAction::performCall() {
|
---|
52 | atom *first = NULL;
|
---|
53 | element *elemental = NULL;
|
---|
54 | molecule *mol = NULL;
|
---|
55 |
|
---|
56 | ValueStorage::getInstance().queryCurrentValue(NAME, elemental);
|
---|
57 |
|
---|
58 | for (World::AtomSelectionIterator iter = World::getInstance().beginAtomSelection(); iter != World::getInstance().endAtomSelection(); ++iter) {
|
---|
59 | first = iter->second;
|
---|
60 | DoLog(1) && (Log() << Verbose(1) << "Changing atom " << *first << " to element " << elemental->symbol << "." << endl);
|
---|
61 | mol = first->getMolecule();
|
---|
62 | first->removeFromMolecule(); // remove atom
|
---|
63 | first->setType(elemental);
|
---|
64 | mol->AddAtom(first); // add atom to ensure correctness of formula
|
---|
65 | }
|
---|
66 | return Action::success;
|
---|
67 | }
|
---|
68 |
|
---|
69 | Action::state_ptr AtomChangeElementAction::performUndo(Action::state_ptr _state) {
|
---|
70 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
71 |
|
---|
72 | return Action::failure;
|
---|
73 | // string newName = state->mol->getName();
|
---|
74 | // state->mol->setName(state->lastName);
|
---|
75 | //
|
---|
76 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
77 | }
|
---|
78 |
|
---|
79 | Action::state_ptr AtomChangeElementAction::performRedo(Action::state_ptr _state){
|
---|
80 | return Action::failure;
|
---|
81 | }
|
---|
82 |
|
---|
83 | bool AtomChangeElementAction::canUndo() {
|
---|
84 | return false;
|
---|
85 | }
|
---|
86 |
|
---|
87 | bool AtomChangeElementAction::shouldUndo() {
|
---|
88 | return false;
|
---|
89 | }
|
---|
90 |
|
---|
91 | const string AtomChangeElementAction::getName() {
|
---|
92 | return NAME;
|
---|
93 | }
|
---|