Ignore:
Timestamp:
Apr 6, 2012, 11:44:50 AM (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:
cc9119
Parents:
57dd40
git-author:
Frederik Heber <heber@…> (04/05/12 09:38:33)
git-committer:
Frederik Heber <heber@…> (04/06/12 11:44:50)
Message:

Filler::operator() has param vector of Cluster's that is filled with inserted ones to allow for undoing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/FillAction/FillRegularGridAction.cpp

    r57dd40 r42b6de  
    2020#include "CodePatterns/MemDebug.hpp"
    2121
     22#include "Actions/UndoRedoHelpers.hpp"
    2223#include "Atom/atom.hpp"
     24#include "Atom/AtomicInfo.hpp"
    2325#include "Atom/CopyAtoms/CopyAtoms_withBonds.hpp"
    2426#include "CodePatterns/Log.hpp"
     
    6567  getParametersfromValueStorage();
    6668
    67   // get all present atoms for UndoState
    68   AtomVector presentatoms = World::getInstance().getAllAtoms();
    69 
    7069  // get the filler molecule and move to origin
    7170  const std::vector< molecule *> molecules = World::getInstance().getSelectedMolecules();
     
    10099
    101100  // create predicate, mesh, and filler
     101  std::vector<AtomicInfo> clonedatoms;
    102102  bool successflag = false;
    103103  {
     
    125125      ClusterInterface::Cluster_impl cluster( new Cluster( filler->getAtomIds(), filler->getBoundingShape()) );
    126126      CopyAtoms_withBonds copyMethod;
    127       successflag = (*fillerFunction)(copyMethod, cluster);
     127      Filler::ClusterVector_t ClonedClusters;
     128      successflag = (*fillerFunction)(copyMethod, cluster, ClonedClusters);
    128129      delete fillerFunction;
     130
     131      // append each cluster's atoms to clonedatoms
     132      for (Filler::ClusterVector_t::const_iterator iter = ClonedClusters.begin();
     133          iter != ClonedClusters.end(); ++iter) {
     134        const AtomIdSet &atoms = (*iter)->getAtomIds();
     135        clonedatoms.reserve(clonedatoms.size()+atoms.size());
     136        for (AtomIdSet::const_iterator atomiter = atoms.begin(); atomiter != atoms.end(); ++atomiter)
     137          clonedatoms.push_back( AtomicInfo(*(*atomiter)) );
     138      }
     139      if (!successflag) {
     140        ELOG(1, "Insertion failed, removing inserted clusters again.");
     141        RemoveAtomsFromAtomicInfo(clonedatoms);
     142        clonedatoms.clear();
     143      }
    129144    }
    130145
     
    138153  }
    139154
    140   // generate list of newly created atoms
    141   // (we can in general remove more quickly from a list than a vector)
    142   AtomVector filleratoms = World::getInstance().getAllAtoms();
    143 //  LOG(0, filleratoms.size() << " atoms are present.");
    144   std::list<atom *> filleratoms_list;
    145   std::copy( filleratoms.begin(),  filleratoms.end(), std::back_inserter( filleratoms_list ));
    146 //  LOG(0, filleratoms_list.size() << " atoms have been copied.");
    147   for (AtomVector::const_iterator iter = presentatoms.begin();
    148       iter != presentatoms.end();
    149       ++iter) {
    150     filleratoms_list.remove(*iter);
    151   }
    152 //  LOG(0, filleratoms_list.size() << " atoms left after removal.");
    153   filleratoms.clear();
    154   std::copy(filleratoms_list.begin(), filleratoms_list.end(), std::back_inserter( filleratoms ));
    155 
    156 //  LOG(0, filleratoms.size() << " atoms have been inserted.");
    157 
    158155  if (successflag)
    159     return Action::state_ptr(new FillRegularGridState(filleratoms,params));
     156    return Action::state_ptr(new FillRegularGridState(clonedatoms,params));
    160157  else
    161158    return Action::failure;
     
    163160
    164161Action::state_ptr FillRegularGridAction::performUndo(Action::state_ptr _state) {
    165 //  FillRegularGridState *state = assert_cast<FillRegularGridState*>(_state.get());
    166 //
    167 //  BOOST_FOREACH(atom *_atom, state->filleratoms) {
    168 //    World::getInstance().destroyAtom(Walker);
    169 //  }
    170 //
    171 //  // as atoms and atoms from state are removed, we have to create a new one
    172 //  std::vector<atom*> filleratoms;
    173 //  return Action::state_ptr(new FillRegularGridState(filleratoms,state->params));
    174   return Action::failure;
     162  FillRegularGridState *state = assert_cast<FillRegularGridState*>(_state.get());
     163
     164  // remove all created atoms
     165  RemoveAtomsFromAtomicInfo(state->clonedatoms);
     166
     167  return Action::state_ptr(_state);
    175168}
    176169
    177170Action::state_ptr FillRegularGridAction::performRedo(Action::state_ptr _state){
    178   //FillRegularGridState *state = assert_cast<FillRegularGridState*>(_state.get());
     171  FillRegularGridState *state = assert_cast<FillRegularGridState*>(_state.get());
    179172
    180   return Action::failure;
    181   //return Action::state_ptr(_state);
     173  if (AddAtomsFromAtomicInfo(state->clonedatoms))
     174    return Action::state_ptr(_state);
     175  else
     176    return Action::failure;
    182177}
    183178
    184179bool FillRegularGridAction::canUndo() {
    185   return false;
     180  return true;
    186181}
    187182
    188183bool FillRegularGridAction::shouldUndo() {
    189   return false;
     184  return true;
    190185}
    191186/** =========== end of function ====================== */
Note: See TracChangeset for help on using the changeset viewer.