| 1 | /*
|
|---|
| 2 | * AddAction.cpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: May 9, 2010
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #include "Helpers/MemDebug.hpp"
|
|---|
| 9 |
|
|---|
| 10 | #include "Actions/AtomAction/AddAction.hpp"
|
|---|
| 11 | #include "atom.hpp"
|
|---|
| 12 | #include "element.hpp"
|
|---|
| 13 | #include "log.hpp"
|
|---|
| 14 | #include "molecule.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"
|
|---|
| 26 | #include "UIElements/ValueStorage.hpp"
|
|---|
| 27 |
|
|---|
| 28 | const char AtomAddAction::NAME[] = "add-atom";
|
|---|
| 29 |
|
|---|
| 30 | AtomAddAction::AtomAddAction() :
|
|---|
| 31 | Action(NAME)
|
|---|
| 32 | {}
|
|---|
| 33 |
|
|---|
| 34 | AtomAddAction::~AtomAddAction()
|
|---|
| 35 | {}
|
|---|
| 36 |
|
|---|
| 37 | Dialog * AtomAddAction::createDialog() {
|
|---|
| 38 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
|---|
| 39 |
|
|---|
| 40 | dialog->queryElement(NAME, ValueStorage::getInstance().getDescription(NAME));
|
|---|
| 41 | dialog->queryVector("position", true, ValueStorage::getInstance().getDescription("position"));
|
|---|
| 42 |
|
|---|
| 43 | return dialog;
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | Action::state_ptr AtomAddAction::performCall() {
|
|---|
| 47 | std::vector<element *> elements;
|
|---|
| 48 | Vector position;
|
|---|
| 49 |
|
|---|
| 50 | // obtain information
|
|---|
| 51 | ValueStorage::getInstance().queryCurrentValue(NAME, elements);
|
|---|
| 52 | ValueStorage::getInstance().queryCurrentValue("position", position);
|
|---|
| 53 |
|
|---|
| 54 | // execute action
|
|---|
| 55 | if (elements.size() == 1) {
|
|---|
| 56 | atom * first = World::getInstance().createAtom();
|
|---|
| 57 | first->type = *(elements.begin());
|
|---|
| 58 | first->x = position;
|
|---|
| 59 | DoLog(1) && (Log() << Verbose(1) << "Adding new atom with element " << first->type->name << " at " << (first->x) << "." << endl);
|
|---|
| 60 | // TODO: remove when all of World's atoms are stored.
|
|---|
| 61 | std::vector<molecule *> molecules = World::getInstance().getAllMolecules();
|
|---|
| 62 | if (!molecules.empty()) {
|
|---|
| 63 | std::vector<molecule *>::iterator iter = molecules.begin();
|
|---|
| 64 | (*iter)->AddAtom(first);
|
|---|
| 65 | }
|
|---|
| 66 | return Action::success;
|
|---|
| 67 | } else {
|
|---|
| 68 | DoeLog(1) && (eLog()<< Verbose(1) << "Could not find the specified element." << endl);
|
|---|
| 69 | return Action::failure;
|
|---|
| 70 | }
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | Action::state_ptr AtomAddAction::performUndo(Action::state_ptr _state) {
|
|---|
| 74 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
|---|
| 75 |
|
|---|
| 76 | return Action::failure;
|
|---|
| 77 | // string newName = state->mol->getName();
|
|---|
| 78 | // state->mol->setName(state->lastName);
|
|---|
| 79 | //
|
|---|
| 80 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | Action::state_ptr AtomAddAction::performRedo(Action::state_ptr _state){
|
|---|
| 84 | return Action::failure;
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | bool AtomAddAction::canUndo() {
|
|---|
| 88 | return false;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | bool AtomAddAction::shouldUndo() {
|
|---|
| 92 | return false;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | const string AtomAddAction::getName() {
|
|---|
| 96 | return NAME;
|
|---|
| 97 | }
|
|---|