Ignore:
File:
1 edited

Legend:

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

    re2b47c r047878  
    66 */
    77
     8#include "Helpers/MemDebug.hpp"
     9
    810#include "Actions/WorldAction/RemoveSphereOfAtomsAction.hpp"
     11#include "Actions/ActionRegistry.hpp"
     12#include "Descriptors/AtomDescriptor.hpp"
    913#include "atom.hpp"
    10 #include "Descriptors/AtomDescriptor.hpp"
    1114#include "log.hpp"
    1215#include "molecule.hpp"
     
    2225#include "UIElements/UIFactory.hpp"
    2326#include "UIElements/Dialog.hpp"
    24 #include "Actions/MapOfActions.hpp"
     27#include "UIElements/ValueStorage.hpp"
    2528
    2629const char WorldRemoveSphereOfAtomsAction::NAME[] = "remove-sphere";
     
    3336{}
    3437
     38void WorldRemoveSphereOfAtoms(double radius, Vector &point) {
     39  ValueStorage::getInstance().setCurrentValue(WorldRemoveSphereOfAtomsAction::NAME, radius);
     40  ValueStorage::getInstance().setCurrentValue("position", point);
     41  ActionRegistry::getInstance().getActionByName(WorldRemoveSphereOfAtomsAction::NAME)->call(Action::NonInteractive);
     42};
     43
     44Dialog* WorldRemoveSphereOfAtomsAction::fillDialog(Dialog *dialog) {
     45  ASSERT(dialog,"No Dialog given when filling action dialog");
     46
     47  dialog->queryDouble(NAME, ValueStorage::getInstance().getDescription(NAME));
     48  dialog->queryVector("position", false, ValueStorage::getInstance().getDescription("position"));
     49
     50  return dialog;
     51}
     52
    3553Action::state_ptr WorldRemoveSphereOfAtomsAction::performCall() {
    36   Dialog *dialog = UIFactory::getInstance().makeDialog();
    3754  double radius = 0.;
    3855  Vector point;
    3956
    40   dialog->queryDouble(NAME, &radius, MapOfActions::getInstance().getDescription(NAME));
    41   dialog->queryVector("position", &point, World::getInstance().getDomain(), false, MapOfActions::getInstance().getDescription("position"));
     57  ValueStorage::getInstance().queryCurrentValue(NAME, radius);
     58  ValueStorage::getInstance().queryCurrentValue("position", point);
    4259
    43   if(dialog->display()) {
    44     delete dialog;
    45     DoLog(1) && (Log() << Verbose(1) << "Removing atoms around " << point << " with radius " << radius << "." << endl);
    46     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       }
     60  DoLog(1) && (Log() << Verbose(1) << "Removing atoms around " << point << " with radius " << radius << "." << endl);
     61  vector<atom*> AllAtoms = World::getInstance().getAllAtoms();
     62  vector<molecule *> molecules = World::getInstance().getAllMolecules();
     63  for (vector<atom*>::iterator AtomRunner = AllAtoms.begin(); AtomRunner != AllAtoms.end(); ++AtomRunner) {
     64    if (point.DistanceSquared((*AtomRunner)->x) > radius*radius) { // distance to first above radius ...
     65      // TODO: This is not necessary anymore when atoms are completely handled by World (create/destroy and load/save)
     66      for (vector<molecule *>::iterator iter = molecules.begin();iter != molecules.end();++iter)
     67        (*iter)->erase(*AtomRunner);
     68      World::getInstance().destroyAtom(*AtomRunner);
    5569    }
    56     return Action::success;
    57   } else {
    58     delete dialog;
    59     return Action::failure;
    6070  }
    61 
     71  return Action::success;
    6272}
    6373
Note: See TracChangeset for help on using the changeset viewer.