| [97ebf8] | 1 | /*
 | 
|---|
 | 2 |  * SuspendInWaterAction.cpp
 | 
|---|
 | 3 |  *
 | 
|---|
 | 4 |  *  Created on: May 12, 2010
 | 
|---|
 | 5 |  *      Author: heber
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | #include "Actions/MoleculeAction/SuspendInWaterAction.hpp"
 | 
|---|
 | 9 | 
 | 
|---|
 | 10 | #include <iostream>
 | 
|---|
 | 11 | #include <string>
 | 
|---|
 | 12 | 
 | 
|---|
 | 13 | using namespace std;
 | 
|---|
 | 14 | 
 | 
|---|
 | 15 | #include "UIElements/UIFactory.hpp"
 | 
|---|
 | 16 | #include "UIElements/Dialog.hpp"
 | 
|---|
 | 17 | #include "Actions/MapOfActions.hpp"
 | 
|---|
 | 18 | 
 | 
|---|
 | 19 | #include "atom.hpp"
 | 
|---|
 | 20 | #include "boundary.hpp"
 | 
|---|
 | 21 | #include "config.hpp"
 | 
|---|
 | 22 | #include "log.hpp"
 | 
|---|
 | 23 | #include "config.hpp"
 | 
|---|
 | 24 | #include "World.hpp"
 | 
|---|
 | 25 | 
 | 
|---|
 | 26 | /****** MoleculeSuspendInWaterAction *****/
 | 
|---|
 | 27 | 
 | 
|---|
 | 28 | // memento to remember the state when undoing
 | 
|---|
 | 29 | 
 | 
|---|
 | 30 | //class MoleculeSuspendInWaterState : public ActionState {
 | 
|---|
 | 31 | //public:
 | 
|---|
 | 32 | //  MoleculeSuspendInWaterState(molecule* _mol,std::string _lastName) :
 | 
|---|
 | 33 | //    mol(_mol),
 | 
|---|
 | 34 | //    lastName(_lastName)
 | 
|---|
 | 35 | //  {}
 | 
|---|
 | 36 | //  molecule* mol;
 | 
|---|
 | 37 | //  std::string lastName;
 | 
|---|
 | 38 | //};
 | 
|---|
 | 39 | 
 | 
|---|
 | 40 | const char MoleculeSuspendInWaterAction::NAME[] = "suspend-in-water";
 | 
|---|
 | 41 | 
 | 
|---|
 | 42 | MoleculeSuspendInWaterAction::MoleculeSuspendInWaterAction() :
 | 
|---|
 | 43 |   Action(NAME)
 | 
|---|
 | 44 | {}
 | 
|---|
 | 45 | 
 | 
|---|
 | 46 | MoleculeSuspendInWaterAction::~MoleculeSuspendInWaterAction()
 | 
|---|
 | 47 | {}
 | 
|---|
 | 48 | 
 | 
|---|
 | 49 | Action::state_ptr MoleculeSuspendInWaterAction::performCall() {
 | 
|---|
 | 50 |   molecule *mol = NULL;
 | 
|---|
 | 51 |   Dialog *dialog = UIFactory::getInstance().makeDialog();
 | 
|---|
 | 52 |   double density;
 | 
|---|
 | 53 |   double volume = 0.;
 | 
|---|
 | 54 | 
 | 
|---|
 | 55 |   dialog->queryMolecule(NAME, &mol, MapOfActions::getInstance().getDescription(NAME));
 | 
|---|
 | 56 |   dialog->queryDouble("density", &density, MapOfActions::getInstance().getDescription("density"));
 | 
|---|
 | 57 | 
 | 
|---|
 | 58 |   if(dialog->display()) {
 | 
|---|
 | 59 |     DoLog(0) && (Log() << Verbose(0) << "Evaluating necessary cell volume for a cluster suspended in water.");
 | 
|---|
 | 60 |     if (density < 1.0) {
 | 
|---|
 | 61 |       DoeLog(1) && (eLog()<< Verbose(1) << "Density must be greater than 1.0g/cm^3!" << endl);
 | 
|---|
 | 62 |     } else {
 | 
|---|
 | 63 |       PrepareClustersinWater(World::getInstance().getConfig(), mol, volume, density);  // if volume == 0, will calculate from ConvexEnvelope
 | 
|---|
 | 64 |       delete dialog;
 | 
|---|
 | 65 |       return Action::success;
 | 
|---|
 | 66 |     }
 | 
|---|
 | 67 |   }
 | 
|---|
 | 68 |   delete dialog;
 | 
|---|
 | 69 |   return Action::failure;
 | 
|---|
 | 70 | }
 | 
|---|
 | 71 | 
 | 
|---|
 | 72 | Action::state_ptr MoleculeSuspendInWaterAction::performUndo(Action::state_ptr _state) {
 | 
|---|
 | 73 | //  MoleculeSuspendInWaterState *state = assert_cast<MoleculeSuspendInWaterState*>(_state.get());
 | 
|---|
 | 74 | 
 | 
|---|
 | 75 | //  string newName = state->mol->getName();
 | 
|---|
 | 76 | //  state->mol->setName(state->lastName);
 | 
|---|
 | 77 | 
 | 
|---|
 | 78 |   return Action::failure;
 | 
|---|
 | 79 | }
 | 
|---|
 | 80 | 
 | 
|---|
 | 81 | Action::state_ptr MoleculeSuspendInWaterAction::performRedo(Action::state_ptr _state){
 | 
|---|
 | 82 |   // Undo and redo have to do the same for this action
 | 
|---|
 | 83 |   return performUndo(_state);
 | 
|---|
 | 84 | }
 | 
|---|
 | 85 | 
 | 
|---|
 | 86 | bool MoleculeSuspendInWaterAction::canUndo() {
 | 
|---|
 | 87 |   return false;
 | 
|---|
 | 88 | }
 | 
|---|
 | 89 | 
 | 
|---|
 | 90 | bool MoleculeSuspendInWaterAction::shouldUndo() {
 | 
|---|
 | 91 |   return false;
 | 
|---|
 | 92 | }
 | 
|---|
 | 93 | 
 | 
|---|
 | 94 | const string MoleculeSuspendInWaterAction::getName() {
 | 
|---|
 | 95 |   return NAME;
 | 
|---|
 | 96 | }
 | 
|---|