Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/UndoRedoHelpers.cpp

    r596cfa r8cc22f  
    5252#include "WorldTime.hpp"
    5353
    54 bool MoleCuilder::AddAtomsFromAtomicInfo(const std::vector<AtomicInfo> &atoms)
     54bool MoleCuilder::AddAtomsFromAtomicInfo(std::vector<AtomicInfo> &atoms)
    5555{
    5656  size_t i=0;
     
    6969    for (size_t j=0;j<i;++j)
    7070      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     }
    10271    // and announce the failure
    10372    return false;
     
    204173  for (std::vector<moleculeId_t>::const_iterator iter = ids.begin();
    205174      iter != ids.end(); ++iter) {
    206     molecule * mol = World::getInstance().getMolecule(MoleculeById(*iter));
     175    molecule * const mol = World::getInstance().getMolecule(MoleculeById(*iter));
    207176    if (mol != NULL) {
    208       removeAtomsinMolecule(mol);
    209       // molecules are automatically removed when empty
     177      mol->removeAtomsinMolecule();
     178      World::getInstance().destroyMolecule(mol);
    210179    }
    211180  }
Note: See TracChangeset for help on using the changeset viewer.