Changeset ea2830
- Timestamp:
- Aug 10, 2010, 12:00:51 PM (15 years ago)
- 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:
- 784708
- Parents:
- f8456c
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/AtomAction/AddAction.cpp
rf8456c rea2830 10 10 #include "Actions/AtomAction/AddAction.hpp" 11 11 #include "Actions/ActionRegistry.hpp" 12 #include "Descriptors/AtomIdDescriptor.hpp" 12 13 #include "atom.hpp" 13 14 #include "element.hpp" … … 26 27 #include "UIElements/Dialog.hpp" 27 28 #include "Actions/ValueStorage.hpp" 29 30 // memento to remember the state when undoing 31 32 class AtomAddState : public ActionState { 33 public: 34 AtomAddState(const Vector &_position, const element *_elemental, const atomId_t _id) : 35 position(_position), 36 elemental(_elemental), 37 id(_id) 38 {} 39 Vector position; 40 const element *elemental; 41 atomId_t id; 42 }; 28 43 29 44 const char AtomAddAction::NAME[] = "add-atom"; … … 70 85 (*iter)->AddAtom(first); 71 86 } 72 return Action::s uccess;87 return Action::state_ptr(new AtomAddState(position, elemental, first->getId())); 73 88 } 74 89 75 90 Action::state_ptr AtomAddAction::performUndo(Action::state_ptr _state) { 76 // ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());91 AtomAddState *state = assert_cast<AtomAddState*>(_state.get()); 77 92 78 return Action::failure; 79 // string newName = state->mol->getName(); 80 // state->mol->setName(state->lastName); 81 // 82 // return Action::state_ptr(new ParserLoadXyzState(state->mol,newName)); 93 DoLog(1) && (Log() << Verbose(1) << "Removing atom with id " << state->id << "." << endl); 94 World::getInstance().destroyAtom(state->id); 95 96 return Action::state_ptr(_state); 83 97 } 84 98 85 99 Action::state_ptr AtomAddAction::performRedo(Action::state_ptr _state){ 86 return Action::failure; 100 AtomAddState *state = assert_cast<AtomAddState*>(_state.get()); 101 102 atom * first = World::getInstance().createAtom(); 103 first->setType(state->elemental); 104 first->setPosition(state->position); 105 DoLog(1) && (Log() << Verbose(1) << "Re-adding new atom with element " << state->elemental->getName() << " at " << state->position << "." << endl); 106 // TODO: remove when all of World's atoms are stored. 107 std::vector<molecule *> molecules = World::getInstance().getAllMolecules(); 108 if (!molecules.empty()) { 109 std::vector<molecule *>::iterator iter = molecules.begin(); 110 (*iter)->AddAtom(first); 111 } 112 if (first->getId() != state->id) 113 if (!first->changeId(state->id)) 114 return Action::failure; 115 return Action::state_ptr(_state); 87 116 } 88 117 89 118 bool AtomAddAction::canUndo() { 90 return false;119 return true; 91 120 } 92 121 93 122 bool AtomAddAction::shouldUndo() { 94 return false;123 return true; 95 124 } 96 125 -
tests/regression/testsuite-simple_configuration.at
rf8456c rea2830 30 30 AT_CHECK([file=test.xyz; diff -I '.*Created by molecuilder.*' $file ${abs_top_srcdir}/${AUTOTEST_PATH}/Simple_configuration/3/post/$file], 0, [ignore], [ignore]) 31 31 AT_CHECK([../../molecuilder -i test2.conf -e ${abs_top_srcdir}/src/ -o mpqc pcp xyz -a 1 --position "0., 0., -1."], 134, [ignore], [ignore]) 32 AT_CLEANUP 33 AT_SETUP([Simple configuration - adding atom with Undo/Redo]) 34 AT_KEYWORDS([configuration]) 35 AT_CHECK([../../molecuilder -i empty.conf -o pcp -a 1 --position "10., 10., 10." --undo], 0, [ignore], [ignore]) 36 AT_CHECK([file=empty.conf; diff $file ${abs_top_srcdir}/${AUTOTEST_PATH}/Simple_configuration/3/post/$file], 0, [ignore], [ignore]) 37 AT_CHECK([../../molecuilder -i test.conf -o mpqc pcp xyz -a 1 --position "10., 10., 10." --undo --redo], 0, [ignore], [ignore]) 38 AT_CHECK([file=test.conf; diff $file ${abs_top_srcdir}/${AUTOTEST_PATH}/Simple_configuration/3/post/$file], 0, [ignore], [ignore]) 39 AT_CHECK([file=test.in; diff $file ${abs_top_srcdir}/${AUTOTEST_PATH}/Simple_configuration/3/post/$file], 0, [ignore], [ignore]) 40 AT_CHECK([file=test.xyz; diff -I '.*Created by molecuilder.*' $file ${abs_top_srcdir}/${AUTOTEST_PATH}/Simple_configuration/3/post/$file], 0, [ignore], [ignore]) 32 41 AT_CLEANUP 33 42
Note:
See TracChangeset
for help on using the changeset viewer.