Ignore:
File:
1 edited

Legend:

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

    rf0a3ec r047878  
    66 */
    77
     8#include "Helpers/MemDebug.hpp"
     9
    810#include "Actions/AtomAction/AddAction.hpp"
     11#include "Actions/ActionRegistry.hpp"
    912#include "atom.hpp"
    1013#include "element.hpp"
     
    2225#include "UIElements/UIFactory.hpp"
    2326#include "UIElements/Dialog.hpp"
    24 #include "Actions/MapOfActions.hpp"
     27#include "UIElements/ValueStorage.hpp"
    2528
    2629const char AtomAddAction::NAME[] = "add-atom";
     
    3336{}
    3437
     38void AtomAdd(element *elemental, Vector &position) {
     39  ValueStorage::getInstance().setCurrentValue(AtomAddAction::NAME, elemental);
     40  ValueStorage::getInstance().setCurrentValue("position", elemental);
     41  ActionRegistry::getInstance().getActionByName(AtomAddAction::NAME)->call(Action::NonInteractive);
     42};
     43
     44Dialog * AtomAddAction::fillDialog(Dialog *dialog) {
     45  ASSERT(dialog,"No Dialog given when filling action dialog");
     46
     47  dialog->queryElement(NAME, ValueStorage::getInstance().getDescription(NAME));
     48  dialog->queryVector("position", true, ValueStorage::getInstance().getDescription("position"));
     49
     50  return dialog;
     51}
     52
    3553Action::state_ptr AtomAddAction::performCall() {
    36   Dialog *dialog = UIFactory::getInstance().makeDialog();
    37   std::vector<element *> elements;
     54  element * elemental = NULL;
    3855  Vector position;
    3956
    40   dialog->queryElement(NAME, &elements, MapOfActions::getInstance().getDescription(NAME));
    41   dialog->queryVector("position", &position, World::getInstance().getDomain(), true, MapOfActions::getInstance().getDescription("position"));
    42   cout << "pre-dialog" << endl;
     57  // obtain information
     58  ValueStorage::getInstance().queryCurrentValue(NAME, elemental);
     59  ValueStorage::getInstance().queryCurrentValue("position", position);
    4360
    44   if(dialog->display()) {
    45     cout << "post-dialog" << endl;
    46     delete dialog;
    47     if (elements.size() == 1) {
    48       atom * first = World::getInstance().createAtom();
    49       first->type = *(elements.begin());
    50       first->x = position;
    51       DoLog(1) && (Log() << Verbose(1) << "Adding new atom with element " << first->type->name << " at " << (first->x) << "." << endl);
    52       // TODO: remove when all of World's atoms are stored.
    53       std::vector<molecule *> molecules = World::getInstance().getAllMolecules();
    54       if (!molecules.empty()) {
    55         std::vector<molecule *>::iterator iter = molecules.begin();
    56         (*iter)->AddAtom(first);
    57       }
    58       return Action::success;
    59     } else {
    60       DoeLog(1) && (eLog()<< Verbose(1) << "Could not find the specified element." << endl);
    61       return Action::failure;
    62     }
    63   } else {
    64     delete dialog;
    65     return Action::failure;
     61  // execute action
     62  atom * first = World::getInstance().createAtom();
     63  first->type = elemental;
     64  first->x = position;
     65  DoLog(1) && (Log() << Verbose(1) << "Adding new atom with element " << first->type->name << " at " << (first->x) << "." << endl);
     66  // TODO: remove when all of World's atoms are stored.
     67  std::vector<molecule *> molecules = World::getInstance().getAllMolecules();
     68  if (!molecules.empty()) {
     69    std::vector<molecule *>::iterator iter = molecules.begin();
     70    (*iter)->AddAtom(first);
    6671  }
    67 
     72  return Action::success;
    6873}
    6974
Note: See TracChangeset for help on using the changeset viewer.