Changeset c30959
- Timestamp:
- Apr 23, 2021, 8:51:43 PM (5 years ago)
- Branches:
- Candidate_v1.7.0, stable
- Children:
- f01bb3
- Parents:
- e70818
- git-author:
- Frederik Heber <frederik.heber@…> (11/17/20 22:25:47)
- git-committer:
- Frederik Heber <frederik.heber@…> (04/23/21 20:51:43)
- Location:
- src/Actions/BondAction
- Files:
-
- 2 edited
-
BondAddAction.cpp (modified) (6 diffs)
-
BondAddAction.def (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/BondAction/BondAddAction.cpp
re70818 rc30959 41 41 #include "CodePatterns/Verbose.hpp" 42 42 #include "Descriptors/AtomIdDescriptor.hpp" 43 #include "molecule.hpp" 43 44 #include "World.hpp" 44 45 #include "WorldTime.hpp" … … 63 64 } 64 65 66 // check if we are adding new atoms to a molecule 67 molecules_t molecules; 68 const molecule *add_to_mol_const = NULL; 69 molecules.reserve(world.countSelectedAtoms()); 70 for (World::AtomSelectionConstIterator firstiter = world.beginAtomSelection(); 71 firstiter != world.endAtomSelection(); ++firstiter) { 72 const molecule * const current_mol = firstiter->second->getMolecule(); 73 molecules.push_back(current_mol); 74 if (current_mol != NULL) { 75 if (add_to_mol_const == NULL) 76 add_to_mol_const = current_mol; 77 else if (add_to_mol_const != current_mol) { 78 // we encountered a second molecule, don't set the molecules 79 molecules.clear(); 80 add_to_mol_const = NULL; 81 break; 82 } 83 } 84 } 85 65 86 bondPairIds_t bondPairIds; 66 87 for (World::AtomSelectionConstIterator firstiter = world.beginAtomSelection(); … … 81 102 82 103 // create undo 83 BondAddState *UndoState = new BondAddState(bondPairIds, params); 104 molecule *add_to_mol = NULL; 105 if (add_to_mol_const != NULL) { 106 add_to_mol = world.getMolecule(MoleculeById(add_to_mol_const->getId())); 107 ASSERT( add_to_mol != NULL, 108 "BondAddAction::performCall() - could not obtain molecule from World."); 109 } 110 BondAddState *UndoState = new BondAddState(bondPairIds, molecules, add_to_mol, params); 84 111 85 112 // execute action 86 113 for (bondPairIds_t::const_iterator iter = bondPairIds.begin(); 87 114 iter != bondPairIds.end(); ++iter) { 88 atom * firstatom = world.getAtom(AtomById(iter->first));89 atom * secondatom = world.getAtom(AtomById(iter->second));115 atom * const firstatom = world.getAtom(AtomById(iter->first)); 116 atom * const secondatom = world.getAtom(AtomById(iter->second)); 90 117 ASSERT((firstatom != NULL) && (secondatom != NULL), 91 118 "BondAddAction::performCall() - at least one of the ids " … … 97 124 +toString(*firstatom)+" and "+toString(*secondatom)+" failed."); 98 125 } 126 if (add_to_mol != NULL) 127 for (World::AtomSelectionIterator firstiter = world.beginAtomSelection(); 128 firstiter != world.endAtomSelection(); ++firstiter) { 129 if (firstiter->second->getMolecule() != add_to_mol) 130 add_to_mol->AddAtom(firstiter->second); 131 } 99 132 100 133 return ActionState::ptr(UndoState); … … 120 153 } 121 154 } 155 if (state->add_to_mol != NULL) { 156 molecules_t::const_iterator mol_iter = state->molecules.begin(); 157 for (World::AtomSelectionIterator firstiter = world.beginAtomSelection(); 158 firstiter != world.endAtomSelection(); ++firstiter) { 159 const molecule * const current_mol = *mol_iter++; 160 atom * const Walker = firstiter->second; 161 if (current_mol != Walker->getMolecule()) { 162 if (Walker->getMolecule() != NULL) 163 Walker->removeFromMolecule(); 164 if (current_mol != NULL) { 165 molecule *add_to_mol = world.getMolecule(MoleculeById(current_mol->getId())); 166 add_to_mol->AddAtom(Walker); 167 } 168 } 169 } 170 ASSERT(mol_iter == state->molecules.end(), 171 "BondAddAction::performUndo() - number of molecule ptrs not coinciding with number of selected atoms."); 172 } 122 173 123 174 return ActionState::ptr(_state); … … 143 194 } 144 195 } 196 if (state->add_to_mol != NULL) 197 for (World::AtomSelectionIterator firstiter = world.beginAtomSelection(); 198 firstiter != world.endAtomSelection(); ++firstiter) { 199 if (firstiter->second->getMolecule() != state->add_to_mol) 200 state->add_to_mol->AddAtom(firstiter->second); 201 } 145 202 146 203 return ActionState::ptr(_state); -
src/Actions/BondAction/BondAddAction.def
re70818 rc30959 12 12 13 13 typedef std::vector<std::pair<atomId_t,atomId_t> > bondPairIds_t; 14 typedef std::vector<const molecule*> molecules_t; 14 15 15 16 #include "Parameters/Validators/RangeValidator.hpp" … … 27 28 (RangeValidator<int>(1,10)) 28 29 29 #define statetypes (bondPairIds_t) 30 #define statereferences (bondPairIds) 30 #define statetypes (bondPairIds_t)(molecules_t)(molecule *) 31 #define statereferences (bondPairIds)(molecules)(add_to_mol) 31 32 32 33 // some defines for all the names, you may use ACTION, STATE and PARAMS
Note:
See TracChangeset
for help on using the changeset viewer.
