Changeset 220cf64 for src


Ignore:
Timestamp:
Oct 12, 2011, 2:10:51 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:
c8b17b
Parents:
35a25a
git-author:
Frederik Heber <heber@…> (09/09/11 16:54:58)
git-committer:
Frederik Heber <heber@…> (10/12/11 14:10:51)
Message:

Added Undo/Redo capability to ElementDbAction.

  • thanks to serialization of periodentafel and element.
  • !NOTE! when serializing pointers inside classes: header file of this class must at some point be present (due to the templated serialize function).
  • TESTFIX: Updated regression test for ElementDbAction. Loaded databases are now different and this reflects in .conf output file.
Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/CommandAction/ElementDbAction.cpp

    r35a25a r220cf64  
    1818#endif
    1919
     20// include headers that implement a archive in simple text format
     21#include <boost/archive/text_oarchive.hpp>
     22#include <boost/archive/text_iarchive.hpp>
     23
    2024#include "CodePatterns/MemDebug.hpp"
    2125
    2226#include "config.hpp"
     27#include "element.hpp"    // we need element because of serialization!
     28#include "periodentafel.hpp"
    2329#include "CodePatterns/Log.hpp"
    24 #include "periodentafel.hpp"
    2530#include "CodePatterns/Verbose.hpp"
    2631#include "World.hpp"
    2732
    28 #include <iostream>
    2933#include <string>
    3034
    31 using namespace std;
    3235
    3336#include "Actions/CommandAction/ElementDbAction.hpp"
     
    3538// and construct the stuff
    3639#include "ElementDbAction.def"
    37 #include "Action_impl_pre.hpp"
     40#include "Actions/Action_impl_pre.hpp"
     41
    3842/** =========== define the function ====================== */
    3943Action::state_ptr CommandElementDbAction::performCall() {
    40   ostringstream usage;
     44  std::ostringstream usage;
    4145
    4246  // obtain information
    4347  getParametersfromValueStorage();
     48  periodentafel *periode = World::getInstance().getPeriode();
     49
     50  // create undo state
     51  std::stringstream undostream;
     52  boost::archive::text_oarchive oa(undostream);
     53  oa << periode;
     54  CommandElementDbState *UndoState =
     55      new CommandElementDbState(
     56          undostream.str(),
     57          params
     58          );
    4459
    4560  // get the path
     
    4964
    5065  // load table
     66  if (periode->LoadPeriodentafel(configuration->databasepath)) {
     67    DoLog(0) && (Log() << Verbose(0) << "Element list loaded successfully." << endl);
     68    //periode->Output();
     69    return Action::state_ptr(UndoState);
     70  } else {
     71    DoLog(0) && (Log() << Verbose(0) << "Element list loading failed." << endl);
     72    return Action::failure;
     73  }
     74}
     75
     76Action::state_ptr CommandElementDbAction::performUndo(Action::state_ptr _state) {
     77  CommandElementDbState *state = assert_cast<CommandElementDbState*>(_state.get());
     78
     79  periodentafel *periode;
     80
     81  std::stringstream undostream(state->undostring);
     82  boost::archive::text_iarchive ia(undostream);
     83  ia >> periode;
     84
     85  delete World::getInstance().getPeriode();
     86  World::getInstance().getPeriode() = periode;
     87
     88  return Action::state_ptr(_state);
     89}
     90
     91Action::state_ptr CommandElementDbAction::performRedo(Action::state_ptr _state){
     92  CommandElementDbState *state = assert_cast<CommandElementDbState*>(_state.get());
     93
     94  // get the path
     95  // TODO: Make databasepath a std::string
     96  config *configuration = World::getInstance().getConfig();
     97  strcpy(configuration->databasepath, state->params.databasepath.branch_path().string().c_str());
     98
     99  // load table
    51100  periodentafel *periode = World::getInstance().getPeriode();
    52101  if (periode->LoadPeriodentafel(configuration->databasepath)) {
    53102    DoLog(0) && (Log() << Verbose(0) << "Element list loaded successfully." << endl);
    54103    //periode->Output();
    55     return Action::success;
     104    return Action::state_ptr(_state);
    56105  } else {
    57106    DoLog(0) && (Log() << Verbose(0) << "Element list loading failed." << endl);
    58107    return Action::failure;
    59108  }
    60 
    61 }
    62 
    63 Action::state_ptr CommandElementDbAction::performUndo(Action::state_ptr _state) {
    64 //  ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
    65 
    66   return Action::failure;
    67 //  string newName = state->mol->getName();
    68 //  state->mol->setName(state->lastName);
    69 //
    70 //  return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
    71 }
    72 
    73 Action::state_ptr CommandElementDbAction::performRedo(Action::state_ptr _state){
    74   return Action::failure;
    75109}
    76110
    77111bool CommandElementDbAction::canUndo() {
    78   return false;
     112  return true;
    79113}
    80114
    81115bool CommandElementDbAction::shouldUndo() {
    82   return false;
     116  return true;
    83117}
    84118/** =========== end of function ====================== */
  • src/Actions/CommandAction/ElementDbAction.def

    r35a25a r220cf64  
    77
    88// all includes and forward declarations necessary for non-integral types below
    9 
     9#include <sstream>
    1010
    1111// i.e. there is an integer with variable name Z that can be found in
     
    1818#define paramreferences (databasepath)
    1919
    20 #undef statetypes
    21 #undef statereferences
     20#define statetypes (std::string)
     21#define statereferences (undostring)
    2222
    2323// some defines for all the names, you may use ACTION, STATE and PARAMS
  • src/Actions/CommandAction/ElementDbAction.hpp

    r35a25a r220cf64  
    1818
    1919#include "ElementDbAction.def"
    20 #include "Action_impl_header.hpp"
     20#include "Actions/Action_impl_header.hpp"
    2121
    2222#endif /* ELEMENTDBACTION_HPP_ */
  • src/unittests/PeriodentafelUnitTest.hpp

    r35a25a r220cf64  
    4747};
    4848
     49std::string gatherUndoInformation(const periodentafel &periode);
     50
     51
    4952#endif /* PERIODENTAFELUNITTEST_HPP_ */
Note: See TracChangeset for help on using the changeset viewer.