Ignore:
Timestamp:
Oct 20, 2011, 7:04:50 AM (14 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:
a8b9136
Parents:
45f835 (diff), b1ac7a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'MatrixContainer_Serialization_rewrite' into stable

Location:
src/Actions/CommandAction
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/Actions/CommandAction/BondLengthTableAction.cpp

    r45f835 r9c27b0  
    1717#include <config.h>
    1818#endif
     19
     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>
    1923
    2024#include "CodePatterns/MemDebug.hpp"
     
    4448
    4549  DoLog(0) && (Log() << Verbose(0) << "Using " << params.BondGraphFileName << " as bond length table." << endl);
    46   config *configuration = World::getInstance().getConfig();
    47   BondGraph *OldBG = World::getInstance().getBondGraph();
     50  BondGraph *&BG = World::getInstance().getBondGraph();
    4851
    49   BondGraph *BG = new BondGraph(configuration->GetIsAngstroem());
     52  // create undo state
     53  std::stringstream undostream;
     54  boost::archive::text_oarchive oa(undostream);
     55  oa << BG;
     56  CommandBondLengthTableState *UndoState =
     57      new CommandBondLengthTableState(
     58          undostream.str(),
     59          params
     60      );
     61
     62  BG->CleanupBondLengthTable();
    5063  if ((!params.BondGraphFileName.empty())
    5164      && boost::filesystem::exists(params.BondGraphFileName)) {
     
    5467      DoLog(0) && (Log() << Verbose(0) << "Bond length table parsed successfully." << endl);
    5568      input.close();
    56       CommandBondLengthTableState *state = new CommandBondLengthTableState(*OldBG, params);
    57       World::getInstance().setBondGraph(BG);  // Changes OldBG, hence have to copy beforehand
    58       return Action::state_ptr(state);
     69      return Action::state_ptr(UndoState);
    5970    } else {
    6071      DoeLog(1) && (eLog()<< Verbose(1) << "Bond length table parsing failed." << endl);
    6172      input.close();
    62       return Action::failure;
    6373    }
    6474  } else {
    6575    DoeLog(1) && (eLog()<< Verbose(1) << "Bond length table loading failed." << endl);
    66     return Action::failure;
    6776  }
     77  // recover bond graph
     78  boost::archive::text_iarchive ia(undostream);
     79  delete BG;
     80  ia >> BG;
     81  delete UndoState;
     82  return Action::failure;
    6883}
    6984
     
    7186  CommandBondLengthTableState *state = assert_cast<CommandBondLengthTableState*>(_state.get());
    7287
    73   BondGraph *OldBG = World::getInstance().getBondGraph();
    74   CommandBondLengthTableState *restate = new CommandBondLengthTableState(*OldBG, params);
    75   World::getInstance().setBondGraph(new BondGraph(state->OldBG));  // Changes OldBG, hence have to copy beforehand
     88  BondGraph *BG;
     89  std::stringstream undostream(state->undostring);
     90  boost::archive::text_iarchive ia(undostream);
     91  ia >> BG;
     92  World::getInstance().setBondGraph(BG);
    7693
    77   return Action::state_ptr(restate);
     94  return Action::state_ptr(_state);
    7895}
    7996
     
    8198  CommandBondLengthTableState *state = assert_cast<CommandBondLengthTableState*>(_state.get());
    8299
    83   BondGraph *OldBG = World::getInstance().getBondGraph();
    84   CommandBondLengthTableState *restate = new CommandBondLengthTableState(*OldBG, params);
    85   World::getInstance().setBondGraph(new BondGraph(state->OldBG));  // Changes OldBG, hence have to copy beforehand
     100  BondGraph *&BG = World::getInstance().getBondGraph();
     101  BG->CleanupBondLengthTable();
     102  std::ifstream input(state->params.BondGraphFileName.string().c_str());
     103  if ((input.good()) && (BG->LoadBondLengthTable(input))) {
     104    DoLog(0) && (Log() << Verbose(0) << "Bond length table parsed successfully." << endl);
     105    input.close();
     106  }
    86107
    87   return Action::state_ptr(restate);
     108  return Action::state_ptr(_state);
    88109}
    89110
    90111bool CommandBondLengthTableAction::canUndo() {
    91   return false;
     112  return true;
    92113}
    93114
    94115bool CommandBondLengthTableAction::shouldUndo() {
    95   return false;
     116  return true;
    96117}
    97118/** =========== end of function ====================== */
  • TabularUnified src/Actions/CommandAction/BondLengthTableAction.def

    r45f835 r9c27b0  
    1919#define paramreferences (BondGraphFileName)
    2020
    21 #define statetypes (BondGraph)
    22 #define statereferences (OldBG)
     21#define statetypes (std::string)
     22#define statereferences (undostring)
    2323
    2424// some defines for all the names, you may use ACTION, STATE and PARAMS
  • TabularUnified src/Actions/CommandAction/ElementDbAction.cpp

    r45f835 r9c27b0  
    2525
    2626#include "config.hpp"
    27 #include "element.hpp"    // we need element because of serialization!
    28 #include "periodentafel.hpp"
     27#include "Element/element.hpp"    // we need element because of serialization!
     28#include "Element/periodentafel.hpp"
    2929#include "CodePatterns/Log.hpp"
    3030#include "CodePatterns/Verbose.hpp"
Note: See TracChangeset for help on using the changeset viewer.