Ignore:
Timestamp:
Jul 12, 2017, 7:10:22 PM (8 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
Action_Thermostats, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_StructOpt_integration_tests, AutomationFragmentation_failures, Candidate_v1.6.1, Candidate_v1.7.0, ChemicalSpaceEvaluator, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, Fix_Verbose_Codepatterns, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, Gui_displays_atomic_force_velocity, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, PythonUI_with_named_parameters, Recreated_GuiChecks, StoppableMakroAction, TremoloParser_IncreasedPrecision, stable
Children:
3b74fa
Parents:
f56e14
git-author:
Frederik Heber <frederik.heber@…> (05/09/17 11:07:11)
git-committer:
Frederik Heber <frederik.heber@…> (07/12/17 19:10:22)
Message:

SelectMoleculeByOrder and SelectionAtomByOrder now allows multiple indices.

  • of course, this is also true for unselection.
Location:
src/Actions/SelectionAction/Atoms
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/SelectionAction/Atoms/AtomByOrderAction.cpp

    rf56e14 r0716eac  
    5454/** =========== define the function ====================== */
    5555ActionState::ptr SelectionAtomByOrderAction::performCall() {
    56   const atom *Walker = const_cast<const World &>(World::getInstance()).
    57       getAtom(AtomByOrder(params.order.get()));
    58   if (Walker != NULL) {
    59     if (!World::getInstance().isSelected(Walker)) {
    60       LOG(1, "Selecting atom " << *Walker);
    61       World::getInstance().selectAtom(Walker);
    62       LOG(0, World::getInstance().countSelectedAtoms() << " atoms selected.");
    63       return ActionState::ptr(new SelectionAtomByOrderState(Walker->getId(), params));
     56  size_t no_selected = 0;
     57  const std::vector<int> &indices = params.orders.get();
     58  std::vector<atomId_t> atomids;
     59  const World &const_world = World::getConstInstance();
     60  World &world = World::getInstance();
     61  for( std::vector<int>::const_iterator iter = indices.begin();
     62      iter != indices.end(); ++iter) {
     63    const atom * const walker = const_world.getAtom(AtomByOrder(*iter));
     64
     65    if (walker != NULL) {
     66      if (!const_world.isSelected(walker)) {
     67        //LOG(1, "Selecting atom " << *walker);
     68        world.selectAtom(walker);
     69        atomids.push_back(walker->getId());
     70        ++no_selected;
     71      }
    6472    } else {
    65       return Action::success;
     73      STATUS("Cannot find atom by given index "+toString(*iter)+".");
     74      return Action::failure;
    6675    }
     76  }
     77
     78  LOG(0, no_selected << " atoms additionally selected.");
     79  if (no_selected != 0) {
     80    return ActionState::ptr(new SelectionAtomByOrderState(atomids, params));
    6781  } else {
    68     STATUS("Cannot find atom by given order of "+toString(params.order.get())+".");
    69     return Action::failure;
     82    return Action::success;
    7083  }
    7184}
     
    7487  SelectionAtomByOrderState *state = assert_cast<SelectionAtomByOrderState*>(_state.get());
    7588
    76   World::getInstance().unselectAllAtoms(AtomById(state->WalkerId));
     89  World &world = World::getInstance();
     90  for (std::vector<atomId_t>::const_iterator iter = state->WalkerIds.begin();
     91      iter != state->WalkerIds.end(); ++iter)
     92    world.unselectAllAtoms(AtomById(*iter));
    7793
    7894  return ActionState::ptr(_state);
     
    8298  SelectionAtomByOrderState *state = assert_cast<SelectionAtomByOrderState*>(_state.get());
    8399
    84   World::getInstance().selectAllAtoms(AtomById(state->WalkerId));
     100  World &world = World::getInstance();
     101  for (std::vector<atomId_t>::const_iterator iter = state->WalkerIds.begin();
     102      iter != state->WalkerIds.end(); ++iter)
     103    world.selectAllAtoms(AtomById(*iter));
    85104
    86105  return ActionState::ptr(_state);
  • src/Actions/SelectionAction/Atoms/AtomByOrderAction.def

    rf56e14 r0716eac  
    99class atom;
    1010
    11 #include "Parameters/Validators/DummyValidator.hpp"
     11#include "Parameters/Validators/STLVectorValidator.hpp"
    1212
    1313// i.e. there is an integer with variable name Z that can be found in
    1414// ValueStorage by the token "Z" -> first column: int, Z, "Z"
    1515// "undefine" if no parameters are required, use (NOPARAM_DEFAULT) for each (undefined) default value
    16 #define paramtypes (int)
     16#define paramtypes (std::vector<int>)
    1717#define paramtokens ("select-atom-by-order")
    18 #define paramdescriptions ("order index")
     18#define paramdescriptions ("order order indices, starting at 1 or -1")
    1919#undef paramdefaults
    20 #define paramreferences (order)
     20#define paramreferences (orders)
    2121#define paramvalids \
    22 (DummyValidator< int >())
     22(STLVectorValidator< std::vector< int > >(1, 99))
    2323
    24 #define statetypes (atomId_t)
    25 #define statereferences (WalkerId)
     24#define statetypes (std::vector<atomId_t>)
     25#define statereferences (WalkerIds)
    2626
    2727// some defines for all the names, you may use ACTION, STATE and PARAMS
  • src/Actions/SelectionAction/Atoms/NotAtomByOrderAction.cpp

    rf56e14 r0716eac  
    5454/** =========== define the function ====================== */
    5555ActionState::ptr SelectionNotAtomByOrderAction::performCall() {
    56   const atom * Walker = const_cast<const World &>(World::getInstance()).
    57       getAtom(AtomByOrder(params.order.get()));
    58   if (Walker != NULL) {
    59     if (World::getInstance().isSelected(Walker)) {
    60       LOG(1, "Unselecting atom " << *Walker);
    61       World::getInstance().unselectAtom(Walker);
    62       LOG(0, World::getInstance().countSelectedAtoms() << " atoms remain selected.");
    63       return ActionState::ptr(new SelectionNotAtomByOrderState(Walker->getId(), params));
     56  size_t no_unselected = 0;
     57  const std::vector<int> &indices = params.orders.get();
     58  std::vector<atomId_t> atomids;
     59  const World &const_world = World::getConstInstance();
     60  World &world = World::getInstance();
     61  for( std::vector<int>::const_iterator iter = indices.begin();
     62      iter != indices.end(); ++iter) {
     63    const atom * const walker = const_world.getAtom(AtomByOrder(*iter));
     64
     65    if (walker != NULL) {
     66      if (const_world.isSelected(walker)) {
     67        //LOG(1, "Unselecting atom " << *walker);
     68        world.unselectAtom(walker);
     69        atomids.push_back(walker->getId());
     70        ++no_unselected;
     71      }
    6472    } else {
    65       return Action::success;
     73      STATUS("Cannot find atom by given index "+toString(*iter)+".");
     74      return Action::failure;
    6675    }
     76  }
     77
     78  LOG(0, no_unselected << " atoms additionally unselected.");
     79  if (no_unselected != 0) {
     80    return ActionState::ptr(new SelectionNotAtomByOrderState(atomids, params));
    6781  } else {
    68     STATUS("Cannot find atom by given order of "+toString(params.order.get())+".");
    69     return Action::failure;
     82    return Action::success;
    7083  }
    7184}
     
    7487  SelectionNotAtomByOrderState *state = assert_cast<SelectionNotAtomByOrderState*>(_state.get());
    7588
    76   World::getInstance().selectAllAtoms(AtomById(state->WalkerId));
     89  World &world = World::getInstance();
     90  for (std::vector<atomId_t>::const_iterator iter = state->WalkerIds.begin();
     91      iter != state->WalkerIds.end(); ++iter)
     92    world.selectAllAtoms(AtomById(*iter));
    7793
    7894  return ActionState::ptr(_state);
     
    8298  SelectionNotAtomByOrderState *state = assert_cast<SelectionNotAtomByOrderState*>(_state.get());
    8399
    84   World::getInstance().unselectAllAtoms(AtomById(state->WalkerId));
     100  World &world = World::getInstance();
     101  for (std::vector<atomId_t>::const_iterator iter = state->WalkerIds.begin();
     102      iter != state->WalkerIds.end(); ++iter)
     103    world.unselectAllAtoms(AtomById(*iter));
    85104
    86105  return ActionState::ptr(_state);
  • src/Actions/SelectionAction/Atoms/NotAtomByOrderAction.def

    rf56e14 r0716eac  
    99class atom;
    1010
    11 #include "Parameters/Validators/DummyValidator.hpp"
     11#include "Parameters/Validators/STLVectorValidator.hpp"
    1212
    1313// i.e. there is an integer with variable name Z that can be found in
    1414// ValueStorage by the token "Z" -> first column: int, Z, "Z"
    1515// "undefine" if no parameters are required, use (NOPARAM_DEFAULT) for each (undefined) default value
    16 #define paramtypes (int)
     16#define paramtypes (std::vector<int>)
    1717#define paramtokens ("unselect-atom-by-order")
    18 #define paramdescriptions ("order index")
     18#define paramdescriptions ("order order indices, starting at 1 or -1")
    1919#undef paramdefaults
    20 #define paramreferences (order)
     20#define paramreferences (orders)
    2121#define paramvalids \
    22 (DummyValidator< int >())
     22(STLVectorValidator< std::vector< int > >(1, 99))
    2323
    24 #define statetypes (atomId_t)
    25 #define statereferences (WalkerId)
     24#define statetypes (std::vector<atomId_t>)
     25#define statereferences (WalkerIds)
    2626
    2727// some defines for all the names, you may use ACTION, STATE and PARAMS
Note: See TracChangeset for help on using the changeset viewer.