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