- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/AtomAction/ChangeElementAction.cpp
r54b953 r047878 6 6 */ 7 7 8 #include "Helpers/MemDebug.hpp" 9 8 10 #include "Actions/AtomAction/ChangeElementAction.hpp" 11 #include "Actions/ActionRegistry.hpp" 9 12 #include "atom.hpp" 13 #include "element.hpp" 10 14 #include "log.hpp" 11 15 #include "vector.hpp" … … 20 24 #include "UIElements/UIFactory.hpp" 21 25 #include "UIElements/Dialog.hpp" 22 #include " Actions/MapOfActions.hpp"26 #include "UIElements/ValueStorage.hpp" 23 27 24 28 const char AtomChangeElementAction::NAME[] = "change-element"; … … 31 35 {} 32 36 37 void AtomChangeElement(element *elemental) { 38 ValueStorage::getInstance().setCurrentValue(AtomChangeElementAction::NAME, elemental); 39 ActionRegistry::getInstance().getActionByName(AtomChangeElementAction::NAME)->call(Action::NonInteractive); 40 }; 41 42 Dialog* AtomChangeElementAction::fillDialog(Dialog *dialog) { 43 ASSERT(dialog,"No Dialog given when filling action dialog"); 44 45 dialog->queryElement(NAME, ValueStorage::getInstance().getDescription(NAME)); 46 47 return dialog; 48 } 49 33 50 Action::state_ptr AtomChangeElementAction::performCall() { 34 Dialog *dialog = UIFactory::getInstance().makeDialog();35 51 atom *first = NULL; 36 std::vector<element *> elements;52 element *elemental = NULL; 37 53 38 dialog->queryAtom(NAME, &first, MapOfActions::getInstance().getDescription(NAME)); 39 dialog->queryElement("element", &elements, MapOfActions::getInstance().getDescription("element")); 54 ValueStorage::getInstance().queryCurrentValue(NAME, elemental); 40 55 41 if(dialog->display()) { 42 delete dialog; 43 ASSERT(elements.size() == 1, "Unequal to one element specified when changing an atom's element"); 44 ASSERT(first != NULL, "No valid atom specified"); 45 DoLog(1) && (Log() << Verbose(1) << "Changing atom " << *first << " to element " << elements.at(0) << "." << endl); 46 if (elements.at(0) != NULL) { 47 first->type = elements.at(0); 48 return Action::success; 49 } else 50 return Action::failure; 51 } else { 52 delete dialog; 53 return Action::failure; 56 for (World::AtomSelectionIterator iter = World::getInstance().beginAtomSelection(); iter != World::getInstance().endAtomSelection(); ++iter) { 57 first = iter->second; 58 DoLog(1) && (Log() << Verbose(1) << "Changing atom " << *first << " to element " << elemental->symbol << "." << endl); 59 first->type = elemental; 54 60 } 55 61 return Action::success; 56 62 } 57 63
Note:
See TracChangeset
for help on using the changeset viewer.