Changeset 0716eac for src/Actions


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, 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
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
Files:
8 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
  • src/Actions/SelectionAction/Molecules/MoleculeByOrderAction.cpp

    rf56e14 r0716eac  
    5454
    5555ActionState::ptr SelectionMoleculeByOrderAction::performCall() {
    56   const molecule *mol = const_cast<const World &>(World::getInstance()).
    57       getMolecule(MoleculeByOrder(params.molindex.get()));
     56  size_t no_selected = 0;
     57  const std::vector<int> &indices = params.molindices.get();
     58  std::vector<const molecule *> mols;
     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 molecule *mol = const_world.getMolecule(MoleculeByOrder(*iter));
    5864
    59   if (mol != NULL) {
    60     if (!World::getInstance().isSelected(mol)) {
    61       LOG(1, "Selecting molecule " << mol->name);
    62       World::getInstance().selectMolecule(mol);
    63       LOG(0, World::getInstance().countSelectedMolecules() << " molecules selected.");
    64       return ActionState::ptr(new SelectionMoleculeByOrderState(mol, params));
     65    if (mol != NULL) {
     66      if (!const_world.isSelected(mol)) {
     67        //LOG(1, "Selecting molecule " << mol->name);
     68        world.selectMolecule(mol);
     69        mols.push_back(mol);
     70        ++no_selected;
     71      }
    6572    } else {
    66       return Action::success;
     73      STATUS("Cannot find molecule by given index "+toString(*iter)+".");
     74      return Action::failure;
    6775    }
     76  }
     77
     78  LOG(0, no_selected << " molecules additionally selected.");
     79  if (no_selected != 0) {
     80    return ActionState::ptr(new SelectionMoleculeByOrderState(mols, params));
    6881  } else {
    69     STATUS("Cannot find molecule by given index "+toString(params.molindex.get())+".");
    70     return Action::failure;
     82    return Action::success;
    7183  }
    7284}
     
    7587  SelectionMoleculeByOrderState *state = assert_cast<SelectionMoleculeByOrderState*>(_state.get());
    7688
    77   World::getInstance().unselectMolecule(state->mol);
     89  World &world = World::getInstance();
     90  for (std::vector<const molecule *>::const_iterator iter = state->mols.begin();
     91      iter != state->mols.end(); ++iter)
     92    world.unselectMolecule(*iter);
     93
    7894  return ActionState::ptr(_state);
    7995}
     
    8298  SelectionMoleculeByOrderState *state = assert_cast<SelectionMoleculeByOrderState*>(_state.get());
    8399
    84   World::getInstance().selectMolecule(state->mol);
     100  World &world = World::getInstance();
     101  for (std::vector<const molecule *>::const_iterator iter = state->mols.begin();
     102      iter != state->mols.end(); ++iter)
     103    world.selectMolecule(*iter);
    85104  return ActionState::ptr(_state);
    86105}
  • src/Actions/SelectionAction/Molecules/MoleculeByOrderAction.def

    rf56e14 r0716eac  
    99class molecule;
    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-molecule-by-order")
    18 #define paramdescriptions ("molecule order index, start at 1 or -1")
     18#define paramdescriptions ("molecule order indices, starting at 1 or -1")
    1919#undef paramdefaults
    20 #define paramreferences (molindex)
     20#define paramreferences (molindices)
    2121#define paramvalids \
    22 (DummyValidator< int >())
     22(STLVectorValidator< std::vector< int > >(1, 99))
    2323
    24 #define statetypes (const molecule *)
    25 #define statereferences (mol)
     24#define statetypes (std::vector<const molecule *>)
     25#define statereferences (mols)
    2626
    2727// some defines for all the names, you may use ACTION, STATE and PARAMS
  • src/Actions/SelectionAction/Molecules/NotMoleculeByOrderAction.cpp

    rf56e14 r0716eac  
    5454
    5555ActionState::ptr SelectionNotMoleculeByOrderAction::performCall() {
    56   const molecule *mol = const_cast<const World &>(World::getInstance()).
    57       getMolecule(MoleculeByOrder(params.molindex.get()));
     56  size_t no_unselected = 0;
     57  const std::vector<int> &indices = params.molindices.get();
     58  std::vector<const molecule *> mols;
     59  for( std::vector<int>::const_iterator iter = indices.begin();
     60      iter != indices.end(); ++iter) {
     61    const molecule *mol = const_cast<const World &>(World::getInstance()).
     62        getMolecule(MoleculeByOrder(*iter));
    5863
    59   if (mol != NULL) {
    60     if (World::getInstance().isSelected(mol)) {
    61       LOG(1, "Unselecting molecule " << mol->name);
    62       World::getInstance().unselectMolecule(mol);
    63       LOG(0, World::getInstance().countSelectedMolecules() << " molecules remain selected.");
    64       return ActionState::ptr(new SelectionNotMoleculeByOrderState(mol, params));
     64    if (mol != NULL) {
     65      if (World::getInstance().isSelected(mol)) {
     66        //LOG(1, "Unselecting molecule " << mol->name);
     67        World::getInstance().unselectMolecule(mol);
     68        mols.push_back(mol);
     69        ++no_unselected;
     70      }
    6571    } else {
    66       return Action::success;
     72      STATUS("Cannot find molecule by given index "+toString(*iter)+".");
     73      return Action::failure;
    6774    }
     75  }
     76
     77  LOG(0, no_unselected << " molecules additionally unselected.");
     78  if (no_unselected != 0) {
     79    return ActionState::ptr(new SelectionNotMoleculeByOrderState(mols, params));
    6880  } else {
    69     STATUS("Cannot find molecule by given index "+toString(params.molindex.get())+".");
    70     return Action::failure;
     81    return Action::success;
    7182  }
    7283}
     
    7586  SelectionNotMoleculeByOrderState *state = assert_cast<SelectionNotMoleculeByOrderState*>(_state.get());
    7687
    77   World::getInstance().selectMolecule(state->mol);
     88  World &world = World::getInstance();
     89  for (std::vector<const molecule *>::const_iterator iter = state->mols.begin();
     90      iter != state->mols.end(); ++iter)
     91    world.selectMolecule(*iter);
     92
    7893  return ActionState::ptr(_state);
    7994}
     
    8297  SelectionNotMoleculeByOrderState *state = assert_cast<SelectionNotMoleculeByOrderState*>(_state.get());
    8398
    84   World::getInstance().unselectMolecule(state->mol);
     99  World &world = World::getInstance();
     100  for (std::vector<const molecule *>::const_iterator iter = state->mols.begin();
     101      iter != state->mols.end(); ++iter)
     102    world.unselectMolecule(*iter);
     103
    85104  return ActionState::ptr(_state);
    86105}
  • src/Actions/SelectionAction/Molecules/NotMoleculeByOrderAction.def

    rf56e14 r0716eac  
    99class molecule;
    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-molecule-by-order")
    18 #define paramdescriptions ("molecule order index, start at 1 or -1")
     18#define paramdescriptions ("molecule order indices, starting at 1 or -1")
    1919#undef paramdefaults
    20 #define paramreferences (molindex)
     20#define paramreferences (molindices)
    2121#define paramvalids \
    22 (DummyValidator< int >())
     22(STLVectorValidator< std::vector< int > >(1, 99))
    2323
    24 #define statetypes (const molecule *)
    25 #define statereferences (mol)
     24#define statetypes (std::vector<const molecule *>)
     25#define statereferences (mols)
    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.