| [97ebf8] | 1 | /*
 | 
|---|
 | 2 |  * ChangeElementAction.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/ChangeElementAction.hpp"
 | 
|---|
 | 11 | #include "atom.hpp"
 | 
|---|
 | 12 | #include "log.hpp"
 | 
|---|
 | 13 | #include "vector.hpp"
 | 
|---|
 | 14 | #include "verbose.hpp"
 | 
|---|
 | 15 | #include "World.hpp"
 | 
|---|
 | 16 | 
 | 
|---|
 | 17 | #include <iostream>
 | 
|---|
 | 18 | #include <string>
 | 
|---|
 | 19 | 
 | 
|---|
 | 20 | using namespace std;
 | 
|---|
 | 21 | 
 | 
|---|
 | 22 | #include "UIElements/UIFactory.hpp"
 | 
|---|
 | 23 | #include "UIElements/Dialog.hpp"
 | 
|---|
 | 24 | #include "Actions/MapOfActions.hpp"
 | 
|---|
 | 25 | 
 | 
|---|
 | 26 | const char AtomChangeElementAction::NAME[] = "change-element";
 | 
|---|
 | 27 | 
 | 
|---|
 | 28 | AtomChangeElementAction::AtomChangeElementAction() :
 | 
|---|
 | 29 |   Action(NAME)
 | 
|---|
 | 30 | {}
 | 
|---|
 | 31 | 
 | 
|---|
 | 32 | AtomChangeElementAction::~AtomChangeElementAction()
 | 
|---|
 | 33 | {}
 | 
|---|
 | 34 | 
 | 
|---|
 | 35 | Action::state_ptr AtomChangeElementAction::performCall() {
 | 
|---|
 | 36 |   Dialog *dialog = UIFactory::getInstance().makeDialog();
 | 
|---|
 | 37 |   atom *first = NULL;
 | 
|---|
| [104524] | 38 |   std::vector<element *> elements;
 | 
|---|
| [97ebf8] | 39 | 
 | 
|---|
| [54b953] | 40 |   dialog->queryAtom(NAME, &first, MapOfActions::getInstance().getDescription(NAME));
 | 
|---|
 | 41 |   dialog->queryElement("element", &elements, MapOfActions::getInstance().getDescription("element"));
 | 
|---|
| [97ebf8] | 42 | 
 | 
|---|
 | 43 |   if(dialog->display()) {
 | 
|---|
 | 44 |     delete dialog;
 | 
|---|
| [104524] | 45 |     ASSERT(elements.size() == 1, "Unequal to one element specified when changing an atom's element");
 | 
|---|
| [54b953] | 46 |     ASSERT(first != NULL, "No valid atom specified");
 | 
|---|
| [104524] | 47 |     DoLog(1) && (Log() << Verbose(1) << "Changing atom " << *first << " to element " << elements.at(0) << "." << endl);
 | 
|---|
 | 48 |     if (elements.at(0) != NULL) {
 | 
|---|
 | 49 |       first->type = elements.at(0);
 | 
|---|
| [97ebf8] | 50 |       return Action::success;
 | 
|---|
 | 51 |     } else
 | 
|---|
 | 52 |       return Action::failure;
 | 
|---|
 | 53 |   } else {
 | 
|---|
 | 54 |     delete dialog;
 | 
|---|
 | 55 |     return Action::failure;
 | 
|---|
 | 56 |   }
 | 
|---|
 | 57 | 
 | 
|---|
 | 58 | }
 | 
|---|
 | 59 | 
 | 
|---|
 | 60 | Action::state_ptr AtomChangeElementAction::performUndo(Action::state_ptr _state) {
 | 
|---|
 | 61 | //  ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
 | 
|---|
 | 62 | 
 | 
|---|
 | 63 |   return Action::failure;
 | 
|---|
 | 64 | //  string newName = state->mol->getName();
 | 
|---|
 | 65 | //  state->mol->setName(state->lastName);
 | 
|---|
 | 66 | //
 | 
|---|
 | 67 | //  return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
 | 
|---|
 | 68 | }
 | 
|---|
 | 69 | 
 | 
|---|
 | 70 | Action::state_ptr AtomChangeElementAction::performRedo(Action::state_ptr _state){
 | 
|---|
 | 71 |   return Action::failure;
 | 
|---|
 | 72 | }
 | 
|---|
 | 73 | 
 | 
|---|
 | 74 | bool AtomChangeElementAction::canUndo() {
 | 
|---|
 | 75 |   return false;
 | 
|---|
 | 76 | }
 | 
|---|
 | 77 | 
 | 
|---|
 | 78 | bool AtomChangeElementAction::shouldUndo() {
 | 
|---|
 | 79 |   return false;
 | 
|---|
 | 80 | }
 | 
|---|
 | 81 | 
 | 
|---|
 | 82 | const string AtomChangeElementAction::getName() {
 | 
|---|
 | 83 |   return NAME;
 | 
|---|
 | 84 | }
 | 
|---|