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