Changeset 78d5b2 for src


Ignore:
Timestamp:
Oct 10, 2011, 4:58:17 PM (13 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
f08ae7
Parents:
aa8cc2
git-author:
Frederik Heber <heber@…> (09/05/11 17:25:14)
git-committer:
Frederik Heber <heber@…> (10/10/11 16:58:17)
Message:

Added Undo/Redo capability to LoadAction.

  • Added cloning of FormatParser_Parameters before the file is loaded such that FormatParser (here only MpqcParser) is returned to original state.
  • Additionally, we just store molecule's id and the file's prefix and suffix in the undo state.
  • TESTCHANGE: Removed XFAIL's from all Parser load's Undo/Redo tests.
Location:
src/Actions/MoleculeAction
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/MoleculeAction/LoadAction.cpp

    raa8cc2 r78d5b2  
    2222#include "CodePatterns/Log.hpp"
    2323#include "CodePatterns/Verbose.hpp"
     24#include "Descriptors/MoleculeIdDescriptor.hpp"
    2425#include "Parser/FormatParserStorage.hpp"
     26#include "Parser/FormatParser_Parameters.hpp"
    2527#include "molecule.hpp"
    2628#include "World.hpp"
     
    4547  if (!boost::filesystem::exists(params.filename)) {
    4648    DoLog(1) && (Log() << Verbose(1) << "Specified input file " << params.filename << " not found." << endl);
    47     // DONT FAIL: it's just empty and we use the name. // return Action::failure;
     49    return Action::failure;
    4850  } else {
    4951    DoLog(1) && (Log() << Verbose(1) << "Specified input file found, parsing ... ");
     
    6668    }
    6769
     70    // get undo state for parser
     71    enum ParserTypes type = FormatParserStorage::getInstance().getTypeFromSuffix(FilenameSuffix);
     72    FormatParser_Parameters *ParserParams = FormatParserStorage::getInstance().get(type).parameters;
     73    if (ParserParams != NULL)
     74      ParserParams = ParserParams->clone();
     75    else
     76      ParserParams = NULL;
     77
    6878    // parse the file
    6979    boost::filesystem::ifstream input;
     
    7686    (*iter)->SetNameFromFilename(FilenamePrefix.c_str());
    7787    DoLog(0) && (Log() << Verbose(0) << "Chemical formula is " << (*iter)->getFormula() << std::endl);
     88
     89    return Action::state_ptr(
     90        new MoleculeLoadState((*iter)->getId(),FilenamePrefix,FilenameSuffix,boost::shared_ptr<FormatParser_Parameters>(ParserParams),params)
     91    );
    7892  }
    79   return Action::success;
    8093}
    8194
    8295Action::state_ptr MoleculeLoadAction::performUndo(Action::state_ptr _state) {
    83 //  ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
     96  MoleculeLoadState *state = assert_cast<MoleculeLoadState*>(_state.get());
    8497
    85   return Action::failure;
    86 //  string newName = state->mol->getName();
    87 //  state->mol->setName(state->lastName);
    88 //
    89 //  return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
     98  // remove loaded molecule and its atoms
     99  molecule *mol = World::getInstance().getMolecule(MoleculeById(state->molId));
     100  for(molecule::iterator iter = mol->begin(); !mol->empty(); iter = mol->begin())
     101    World::getInstance().destroyAtom(*iter);
     102  //World::getInstance().destroyMolecule(mol);
     103
     104  // undo changes to FormatParser
     105  enum ParserTypes type = FormatParserStorage::getInstance().getTypeFromSuffix(state->FilenameSuffix);
     106  FormatParser_Parameters *ParserParams = FormatParserStorage::getInstance().get(type).parameters;
     107  if (ParserParams != NULL)
     108    ParserParams->makeClone(*state->ParserParameters);
     109
     110  return Action::state_ptr(_state);
    90111}
    91112
    92113Action::state_ptr MoleculeLoadAction::performRedo(Action::state_ptr _state){
    93   return Action::failure;
     114  MoleculeLoadState *state = assert_cast<MoleculeLoadState*>(_state.get());
     115
     116  // get undo state for parser
     117  enum ParserTypes type = FormatParserStorage::getInstance().getTypeFromSuffix(state->FilenameSuffix);
     118  FormatParser_Parameters *ParserParams = FormatParserStorage::getInstance().get(type).parameters;
     119  if (ParserParams != NULL)
     120    ParserParams = ParserParams->clone();
     121  else
     122    ParserParams = NULL;
     123
     124  // parse the file
     125  boost::filesystem::ifstream input;
     126  input.open(state->params.filename);
     127  FormatParserStorage::getInstance().load(input, state->FilenameSuffix);
     128  input.close();
     129
     130  // set file name of last molecule
     131  MoleculeList::const_reverse_iterator iter = World::getInstance().getMolecules()->ListOfMolecules.rbegin();
     132  (*iter)->SetNameFromFilename(state->FilenamePrefix.c_str());
     133  (*iter)->setId(state->molId);
     134  DoLog(0) && (Log() << Verbose(0) << "Chemical formula is " << (*iter)->getFormula() << std::endl);
     135
     136  return Action::state_ptr(
     137      new MoleculeLoadState((*iter)->getId(),state->FilenamePrefix,state->FilenameSuffix,boost::shared_ptr<FormatParser_Parameters>(ParserParams),params)
     138  );
    94139}
    95140
  • src/Actions/MoleculeAction/LoadAction.def

    raa8cc2 r78d5b2  
    77
    88// all includes and forward declarations necessary for non-integral types below
     9#include "Parser/FormatParser_Parameters.hpp"
    910
     11#include <boost/shared_ptr.hpp>
    1012
    1113// i.e. there is an integer with variable name Z that can be found in
     
    1820#define paramreferences (filename)
    1921
    20 #undef statetypes
    21 #undef statereferences
     22#define statetypes (moleculeId_t)(std::string)(std::string)(boost::shared_ptr<FormatParser_Parameters>)
     23#define statereferences (molId)(FilenamePrefix)(FilenameSuffix)(ParserParameters)
    2224
    2325// some defines for all the names, you may use ACTION, STATE and PARAMS
Note: See TracChangeset for help on using the changeset viewer.