Ignore:
File:
1 edited

Legend:

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

    r112b09 re2b47c  
    66 */
    77
    8 #include "Helpers/MemDebug.hpp"
    9 
    108#include "Actions/WorldAction/RemoveSphereOfAtomsAction.hpp"
    11 #include "CommandLineParser.hpp"
    129#include "atom.hpp"
    1310#include "Descriptors/AtomDescriptor.hpp"
    1411#include "log.hpp"
     12#include "molecule.hpp"
    1513#include "vector.hpp"
    1614#include "verbose.hpp"
     
    3836  Dialog *dialog = UIFactory::getInstance().makeDialog();
    3937  double radius = 0.;
    40   atom *first = NULL;
     38  Vector point;
    4139
    4240  dialog->queryDouble(NAME, &radius, MapOfActions::getInstance().getDescription(NAME));
    43   dialog->queryAtom("atom-by-id", &first, MapOfActions::getInstance().getDescription("atom-by-id"));
     41  dialog->queryVector("position", &point, World::getInstance().getDomain(), false, MapOfActions::getInstance().getDescription("position"));
    4442
    4543  if(dialog->display()) {
    4644    delete dialog;
    47     DoLog(1) && (Log() << Verbose(1) << "Removing atoms around " << first->nr << " with radius " << radius << "." << endl);
     45    DoLog(1) && (Log() << Verbose(1) << "Removing atoms around " << point << " with radius " << radius << "." << endl);
    4846    vector<atom*> AllAtoms = World::getInstance().getAllAtoms();
    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);
     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      }
    5555    }
    56     World::getInstance().destroyAtom(first);
    5756    return Action::success;
    5857  } else {
Note: See TracChangeset for help on using the changeset viewer.