/* * NonConvexEnvelopeAction.cpp * * Created on: May 10, 2010 * Author: heber */ #include "Actions/TesselationAction/NonConvexEnvelopeAction.hpp" #include #include using namespace std; #include "UIElements/UIFactory.hpp" #include "UIElements/Dialog.hpp" #include "Actions/MapOfActions.hpp" #include "atom.hpp" #include "boundary.hpp" #include "linkedcell.hpp" #include "log.hpp" #include "molecule.hpp" #include "verbose.hpp" #include "World.hpp" /****** TesselationNonConvexEnvelopeAction *****/ // memento to remember the state when undoing //class TesselationNonConvexEnvelopeState : public ActionState { //public: // TesselationNonConvexEnvelopeState(molecule* _mol,std::string _lastName) : // mol(_mol), // lastName(_lastName) // {} // molecule* mol; // std::string lastName; //}; const char TesselationNonConvexEnvelopeAction::NAME[] = "nonconvex-envelope"; TesselationNonConvexEnvelopeAction::TesselationNonConvexEnvelopeAction() : Action(NAME) {} TesselationNonConvexEnvelopeAction::~TesselationNonConvexEnvelopeAction() {} Action::state_ptr TesselationNonConvexEnvelopeAction::performCall() { string filename; Dialog *dialog = UIFactory::getInstance().makeDialog(); molecule * Boundary = NULL; double SphereRadius = 0; bool Success = false; clock_t start,end; dialog->queryDouble(NAME, &SphereRadius, MapOfActions::getInstance().getDescription(NAME)); dialog->queryString("output", &filename, MapOfActions::getInstance().getDescription("output")); dialog->queryMolecule("molecule-by-id", &Boundary, MapOfActions::getInstance().getDescription("molecule-by-id")); if(dialog->display()) { class Tesselation *T = NULL; const LinkedCell *LCList = NULL; DoLog(0) && (Log() << Verbose(0) << "Evaluating non-convex envelope of molecule." << Boundary->getId() << endl); DoLog(1) && (Log() << Verbose(1) << "Using rolling ball of radius " << SphereRadius << " and storing tecplot data in " << filename << "." << endl); DoLog(1) && (Log() << Verbose(1) << "Specified molecule has " << Boundary->getAtomCount() << " atoms." << endl); start = clock(); LCList = new LinkedCell(Boundary, SphereRadius*2.); Success = FindNonConvexBorder(Boundary, T, LCList, SphereRadius, filename.c_str()); //FindDistributionOfEllipsoids(T, &LCList, N, number, filename.c_str()); end = clock(); DoLog(0) && (Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl); delete(LCList); delete(T); delete dialog; if (Success) return Action::success; else return Action::failure; } delete dialog; return Action::failure; } Action::state_ptr TesselationNonConvexEnvelopeAction::performUndo(Action::state_ptr _state) { // TesselationNonConvexEnvelopeState *state = assert_cast(_state.get()); // string newName = state->mol->getName(); // state->mol->setName(state->lastName); return Action::failure; } Action::state_ptr TesselationNonConvexEnvelopeAction::performRedo(Action::state_ptr _state){ // Undo and redo have to do the same for this action return performUndo(_state); } bool TesselationNonConvexEnvelopeAction::canUndo() { return false; } bool TesselationNonConvexEnvelopeAction::shouldUndo() { return false; } const string TesselationNonConvexEnvelopeAction::getName() { return NAME; }