[97ebf8] | 1 | /*
|
---|
| 2 | * AddAction.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: May 9, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[112b09] | 8 | #include "Helpers/MemDebug.hpp"
|
---|
| 9 |
|
---|
[97ebf8] | 10 | #include "Actions/AtomAction/AddAction.hpp"
|
---|
[1a8fbf6] | 11 | #include "Actions/ActionCalls.hpp"
|
---|
[97ebf8] | 12 | #include "atom.hpp"
|
---|
| 13 | #include "element.hpp"
|
---|
| 14 | #include "log.hpp"
|
---|
[f0a3ec] | 15 | #include "molecule.hpp"
|
---|
[97ebf8] | 16 | #include "vector.hpp"
|
---|
| 17 | #include "verbose.hpp"
|
---|
| 18 | #include "World.hpp"
|
---|
| 19 |
|
---|
| 20 | #include <iostream>
|
---|
| 21 | #include <string>
|
---|
| 22 |
|
---|
| 23 | using namespace std;
|
---|
| 24 |
|
---|
| 25 | #include "UIElements/UIFactory.hpp"
|
---|
| 26 | #include "UIElements/Dialog.hpp"
|
---|
[9d33ba] | 27 | #include "UIElements/ValueStorage.hpp"
|
---|
[97ebf8] | 28 |
|
---|
| 29 | const char AtomAddAction::NAME[] = "add-atom";
|
---|
| 30 |
|
---|
| 31 | AtomAddAction::AtomAddAction() :
|
---|
| 32 | Action(NAME)
|
---|
| 33 | {}
|
---|
| 34 |
|
---|
| 35 | AtomAddAction::~AtomAddAction()
|
---|
| 36 | {}
|
---|
| 37 |
|
---|
[1a8fbf6] | 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 |
|
---|
[9d33ba] | 44 | Dialog * AtomAddAction::createDialog() {
|
---|
[97ebf8] | 45 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
[9d33ba] | 46 |
|
---|
| 47 | dialog->queryElement(NAME, ValueStorage::getInstance().getDescription(NAME));
|
---|
| 48 | dialog->queryVector("position", true, ValueStorage::getInstance().getDescription("position"));
|
---|
| 49 |
|
---|
| 50 | return dialog;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | Action::state_ptr AtomAddAction::performCall() {
|
---|
[85537a] | 54 | element * elemental = NULL;
|
---|
[97ebf8] | 55 | Vector position;
|
---|
| 56 |
|
---|
[9d33ba] | 57 | // obtain information
|
---|
[85537a] | 58 | ValueStorage::getInstance().queryCurrentValue(NAME, elemental);
|
---|
[9d33ba] | 59 | ValueStorage::getInstance().queryCurrentValue("position", position);
|
---|
| 60 |
|
---|
| 61 | // execute action
|
---|
[85537a] | 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);
|
---|
[97ebf8] | 71 | }
|
---|
[85537a] | 72 | return Action::success;
|
---|
[97ebf8] | 73 | }
|
---|
| 74 |
|
---|
| 75 | Action::state_ptr AtomAddAction::performUndo(Action::state_ptr _state) {
|
---|
| 76 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
| 77 |
|
---|
| 78 | return Action::failure;
|
---|
| 79 | // string newName = state->mol->getName();
|
---|
| 80 | // state->mol->setName(state->lastName);
|
---|
| 81 | //
|
---|
| 82 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | Action::state_ptr AtomAddAction::performRedo(Action::state_ptr _state){
|
---|
| 86 | return Action::failure;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | bool AtomAddAction::canUndo() {
|
---|
| 90 | return false;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | bool AtomAddAction::shouldUndo() {
|
---|
| 94 | return false;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | const string AtomAddAction::getName() {
|
---|
| 98 | return NAME;
|
---|
| 99 | }
|
---|