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