Changes in src/Actions/UndoRedoHelpers.cpp [8cc22f:596cfa]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/UndoRedoHelpers.cpp
r8cc22f r596cfa 52 52 #include "WorldTime.hpp" 53 53 54 bool MoleCuilder::AddAtomsFromAtomicInfo( std::vector<AtomicInfo> &atoms)54 bool MoleCuilder::AddAtomsFromAtomicInfo(const std::vector<AtomicInfo> &atoms) 55 55 { 56 56 size_t i=0; … … 69 69 for (size_t j=0;j<i;++j) 70 70 World::getInstance().destroyAtom(atoms[j].getId()); 71 // and announce the failure 72 return false; 73 } 74 return true; 75 } 76 77 bool MoleCuilder::AddMoleculesFromAtomicInfo(std::map< moleculeId_t, std::vector<AtomicInfo> > &mol_atoms) 78 { 79 bool status = true; 80 for (std::map< moleculeId_t, std::vector<AtomicInfo> >::const_iterator iter = mol_atoms.begin(); 81 iter != mol_atoms.end(); ++iter) { 82 // re-create the atom 83 LOG(3, "DEBUG: Re-adding molecule " << iter->first << "."); 84 molecule *mol_Walker = World::getInstance().createMolecule(); 85 86 // reset the mol id 87 bool status = true; 88 if (mol_Walker->getId() != iter->first) 89 status &= mol_Walker->changeId(iter->first); 90 91 // add all its atoms 92 status &= AddAtomsFromAtomicInfo(iter->second); 93 } 94 if (!status) { 95 // remove all molecules again 96 for (std::map< moleculeId_t, std::vector<AtomicInfo> >::const_iterator iter = mol_atoms.begin(); 97 iter != mol_atoms.end(); ++iter) { 98 molecule * mol = World::getInstance().getMolecule(MoleculeById(iter->first)); 99 if (mol != NULL) 100 removeAtomsinMolecule(mol); 101 } 71 102 // and announce the failure 72 103 return false; … … 173 204 for (std::vector<moleculeId_t>::const_iterator iter = ids.begin(); 174 205 iter != ids.end(); ++iter) { 175 molecule * constmol = World::getInstance().getMolecule(MoleculeById(*iter));206 molecule * mol = World::getInstance().getMolecule(MoleculeById(*iter)); 176 207 if (mol != NULL) { 177 mol->removeAtomsinMolecule();178 World::getInstance().destroyMolecule(mol);208 removeAtomsinMolecule(mol); 209 // molecules are automatically removed when empty 179 210 } 180 211 }
Note:
See TracChangeset
for help on using the changeset viewer.