- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/AtomAction/AddAction.cpp
rf0a3ec r047878 6 6 */ 7 7 8 #include "Helpers/MemDebug.hpp" 9 8 10 #include "Actions/AtomAction/AddAction.hpp" 11 #include "Actions/ActionRegistry.hpp" 9 12 #include "atom.hpp" 10 13 #include "element.hpp" … … 22 25 #include "UIElements/UIFactory.hpp" 23 26 #include "UIElements/Dialog.hpp" 24 #include " Actions/MapOfActions.hpp"27 #include "UIElements/ValueStorage.hpp" 25 28 26 29 const char AtomAddAction::NAME[] = "add-atom"; … … 33 36 {} 34 37 38 void 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 44 Dialog * 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 35 53 Action::state_ptr AtomAddAction::performCall() { 36 Dialog *dialog = UIFactory::getInstance().makeDialog(); 37 std::vector<element *> elements; 54 element * elemental = NULL; 38 55 Vector position; 39 56 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); 43 60 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); 66 71 } 67 72 return Action::success; 68 73 } 69 74
Note:
See TracChangeset
for help on using the changeset viewer.