[97ebf8] | 1 | /*
|
---|
| 2 | * FragmentationAction.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: May 9, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #include "Actions/FragmentationAction/FragmentationAction.hpp"
|
---|
| 9 | #include "atom.hpp"
|
---|
| 10 | #include "config.hpp"
|
---|
| 11 | #include "log.hpp"
|
---|
| 12 | #include "molecule.hpp"
|
---|
| 13 | #include "Descriptors/MoleculeDescriptor.hpp"
|
---|
| 14 | #include "stackclass.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 |
|
---|
[e4b5de] | 26 | const char FragmentationFragmentationAction::NAME[] = "fragment-mol";
|
---|
[97ebf8] | 27 |
|
---|
| 28 | FragmentationFragmentationAction::FragmentationFragmentationAction() :
|
---|
| 29 | Action(NAME)
|
---|
| 30 | {}
|
---|
| 31 |
|
---|
| 32 | FragmentationFragmentationAction::~FragmentationFragmentationAction()
|
---|
| 33 | {}
|
---|
| 34 |
|
---|
| 35 | Action::state_ptr FragmentationFragmentationAction::performCall() {
|
---|
| 36 | Dialog *dialog = UIFactory::getInstance().makeDialog();
|
---|
[e4b5de] | 37 | clock_t start,end;
|
---|
| 38 | molecule *mol = NULL;
|
---|
| 39 | double distance = -1.;
|
---|
| 40 | int order = 0;
|
---|
| 41 | config *configuration = World::getInstance().getConfig();
|
---|
| 42 | int ExitFlag = 0;
|
---|
| 43 |
|
---|
| 44 | cout << "pre-dialog"<< endl;
|
---|
| 45 | dialog->queryMolecule(NAME, &mol, MapOfActions::getInstance().getDescription(NAME));
|
---|
| 46 | dialog->queryDouble("distance", &distance, MapOfActions::getInstance().getDescription("distance"));
|
---|
| 47 | dialog->queryInt("order", &order, MapOfActions::getInstance().getDescription("order"));
|
---|
[97ebf8] | 48 |
|
---|
| 49 | if(dialog->display()) {
|
---|
[e4b5de] | 50 | cout << "POST-dialog"<< endl;
|
---|
| 51 | ASSERT(mol != NULL, "No molecule has been picked for fragmentation.");
|
---|
| 52 | DoLog(0) && (Log() << Verbose(0) << "Fragmenting molecule with bond distance " << distance << " angstroem, order of " << order << "." << endl);
|
---|
| 53 | DoLog(0) && (Log() << Verbose(0) << "Creating connection matrix..." << endl);
|
---|
| 54 | start = clock();
|
---|
| 55 | mol->CreateAdjacencyList(distance, configuration->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
|
---|
| 56 | DoLog(0) && (Log() << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl);
|
---|
| 57 | if (mol->hasBondStructure()) {
|
---|
| 58 | ExitFlag = mol->FragmentMolecule(order, configuration);
|
---|
| 59 | }
|
---|
| 60 | World::getInstance().setExitFlag(ExitFlag);
|
---|
| 61 | end = clock();
|
---|
| 62 | DoLog(0) && (Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl);
|
---|
[97ebf8] | 63 | delete dialog;
|
---|
| 64 | return Action::success;
|
---|
| 65 | } else {
|
---|
| 66 | delete dialog;
|
---|
| 67 | return Action::failure;
|
---|
| 68 | }
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | Action::state_ptr FragmentationFragmentationAction::performUndo(Action::state_ptr _state) {
|
---|
| 72 | // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
|
---|
| 73 |
|
---|
| 74 | return Action::failure;
|
---|
| 75 | // string newName = state->mol->getName();
|
---|
| 76 | // state->mol->setName(state->lastName);
|
---|
| 77 | //
|
---|
| 78 | // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | Action::state_ptr FragmentationFragmentationAction::performRedo(Action::state_ptr _state){
|
---|
| 82 | return Action::failure;
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | bool FragmentationFragmentationAction::canUndo() {
|
---|
| 86 | return false;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | bool FragmentationFragmentationAction::shouldUndo() {
|
---|
| 90 | return false;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | const string FragmentationFragmentationAction::getName() {
|
---|
| 94 | return NAME;
|
---|
| 95 | }
|
---|