Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/WorldAction/RemoveSphereOfAtomsAction.cpp

    re2b47c r112b09  
    66 */
    77
     8#include "Helpers/MemDebug.hpp"
     9
    810#include "Actions/WorldAction/RemoveSphereOfAtomsAction.hpp"
     11#include "CommandLineParser.hpp"
    912#include "atom.hpp"
    1013#include "Descriptors/AtomDescriptor.hpp"
    1114#include "log.hpp"
    12 #include "molecule.hpp"
    1315#include "vector.hpp"
    1416#include "verbose.hpp"
     
    3638  Dialog *dialog = UIFactory::getInstance().makeDialog();
    3739  double radius = 0.;
    38   Vector point;
     40  atom *first = NULL;
    3941
    4042  dialog->queryDouble(NAME, &radius, MapOfActions::getInstance().getDescription(NAME));
    41   dialog->queryVector("position", &point, World::getInstance().getDomain(), false, MapOfActions::getInstance().getDescription("position"));
     43  dialog->queryAtom("atom-by-id", &first, MapOfActions::getInstance().getDescription("atom-by-id"));
    4244
    4345  if(dialog->display()) {
    4446    delete dialog;
    45     DoLog(1) && (Log() << Verbose(1) << "Removing atoms around " << point << " with radius " << radius << "." << endl);
     47    DoLog(1) && (Log() << Verbose(1) << "Removing atoms around " << first->nr << " with radius " << radius << "." << endl);
    4648    vector<atom*> AllAtoms = World::getInstance().getAllAtoms();
    47     vector<molecule *> molecules = World::getInstance().getAllMolecules();
    48     for (vector<atom*>::iterator AtomRunner = AllAtoms.begin(); AtomRunner != AllAtoms.end(); ++AtomRunner) {
    49       if (point.DistanceSquared((*AtomRunner)->x) > radius*radius) { // distance to first above radius ...
    50         // TODO: This is not necessary anymore when atoms are completely handled by World (create/destroy and load/save)
    51         for (vector<molecule *>::iterator iter = molecules.begin();iter != molecules.end();++iter)
    52           (*iter)->erase(*AtomRunner);
    53         World::getInstance().destroyAtom(*AtomRunner);
    54       }
     49    vector<atom*>::iterator AtomAdvancer = AllAtoms.begin();
     50    for (vector<atom*>::iterator AtomRunner = AtomAdvancer; AtomRunner != AllAtoms.end(); ) {
     51      ++AtomAdvancer;
     52      if (first != *AtomRunner) // dont't destroy reference ...
     53        if (first->x.DistanceSquared((*AtomRunner)->x) > radius*radius) // distance to first above radius ...
     54          World::getInstance().destroyAtom(*AtomRunner);
    5555    }
     56    World::getInstance().destroyAtom(first);
    5657    return Action::success;
    5758  } else {
Note: See TracChangeset for help on using the changeset viewer.