Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/AtomAction/ChangeElementAction.cpp

    r54b953 r047878  
    66 */
    77
     8#include "Helpers/MemDebug.hpp"
     9
    810#include "Actions/AtomAction/ChangeElementAction.hpp"
     11#include "Actions/ActionRegistry.hpp"
    912#include "atom.hpp"
     13#include "element.hpp"
    1014#include "log.hpp"
    1115#include "vector.hpp"
     
    2024#include "UIElements/UIFactory.hpp"
    2125#include "UIElements/Dialog.hpp"
    22 #include "Actions/MapOfActions.hpp"
     26#include "UIElements/ValueStorage.hpp"
    2327
    2428const char AtomChangeElementAction::NAME[] = "change-element";
     
    3135{}
    3236
     37void AtomChangeElement(element *elemental) {
     38  ValueStorage::getInstance().setCurrentValue(AtomChangeElementAction::NAME, elemental);
     39  ActionRegistry::getInstance().getActionByName(AtomChangeElementAction::NAME)->call(Action::NonInteractive);
     40};
     41
     42Dialog* AtomChangeElementAction::fillDialog(Dialog *dialog) {
     43  ASSERT(dialog,"No Dialog given when filling action dialog");
     44
     45  dialog->queryElement(NAME, ValueStorage::getInstance().getDescription(NAME));
     46
     47return dialog;
     48}
     49
    3350Action::state_ptr AtomChangeElementAction::performCall() {
    34   Dialog *dialog = UIFactory::getInstance().makeDialog();
    3551  atom *first = NULL;
    36   std::vector<element *> elements;
     52  element *elemental = NULL;
    3753
    38   dialog->queryAtom(NAME, &first, MapOfActions::getInstance().getDescription(NAME));
    39   dialog->queryElement("element", &elements, MapOfActions::getInstance().getDescription("element"));
     54  ValueStorage::getInstance().queryCurrentValue(NAME, elemental);
    4055
    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;
    5460  }
    55 
     61  return Action::success;
    5662}
    5763
Note: See TracChangeset for help on using the changeset viewer.