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