Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/UndoRedoHelpers.cpp

    r8cc22f r596cfa  
    5252#include "WorldTime.hpp"
    5353
    54 bool MoleCuilder::AddAtomsFromAtomicInfo(std::vector<AtomicInfo> &atoms)
     54bool MoleCuilder::AddAtomsFromAtomicInfo(const 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
     77bool 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    }
    71102    // and announce the failure
    72103    return false;
     
    173204  for (std::vector<moleculeId_t>::const_iterator iter = ids.begin();
    174205      iter != ids.end(); ++iter) {
    175     molecule * const mol = World::getInstance().getMolecule(MoleculeById(*iter));
     206    molecule * mol = World::getInstance().getMolecule(MoleculeById(*iter));
    176207    if (mol != NULL) {
    177       mol->removeAtomsinMolecule();
    178       World::getInstance().destroyMolecule(mol);
     208      removeAtomsinMolecule(mol);
     209      // molecules are automatically removed when empty
    179210    }
    180211  }
Note: See TracChangeset for help on using the changeset viewer.