Changeset c5bd60c


Ignore:
Timestamp:
May 18, 2017, 8:05:20 PM (8 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
ForceAnnealing_goodresults, ForceAnnealing_tocheck
Children:
ffd7cd
Parents:
d5c1c8
git-author:
Frederik Heber <frederik.heber@…> (05/18/17 19:33:25)
git-committer:
Frederik Heber <frederik.heber@…> (05/18/17 20:05:20)
Message:

tempcommit: Also SelectionAtomByOrder and unselect actions allow for multiple orders. Merge with d2a077a13.

Location:
src/Actions/SelectionAction
Files:
7 edited

Legend:

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

    rd5c1c8 rc5bd60c  
    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

    rd5c1c8 rc5bd60c  
    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

    rd5c1c8 rc5bd60c  
    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

    rd5c1c8 rc5bd60c  
    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

    rd5c1c8 rc5bd60c  
    5757  const std::vector<int> &indices = params.molindices.get();
    5858  std::vector<const molecule *> mols;
     59  const World &const_world = World::getConstInstance();
     60  World &world = World::getInstance();
    5961  for( std::vector<int>::const_iterator iter = indices.begin();
    6062      iter != indices.end(); ++iter) {
    61     const molecule *mol = const_cast<const World &>(World::getInstance()).
    62         getMolecule(MoleculeByOrder(*iter));
     63    const molecule *mol = const_world.getMolecule(MoleculeByOrder(*iter));
    6364
    6465    if (mol != NULL) {
    65       if (!World::getInstance().isSelected(mol)) {
     66      if (!const_world.isSelected(mol)) {
    6667        //LOG(1, "Selecting molecule " << mol->name);
    67         World::getInstance().selectMolecule(mol);
     68        world.selectMolecule(mol);
    6869        mols.push_back(mol);
     70        ++no_selected;
    6971      }
    7072    } else {
     
    8587  SelectionMoleculeByOrderState *state = assert_cast<SelectionMoleculeByOrderState*>(_state.get());
    8688
     89  World &world = World::getInstance();
    8790  for (std::vector<const molecule *>::const_iterator iter = state->mols.begin();
    8891      iter != state->mols.end(); ++iter)
    89     World::getInstance().unselectMolecule(*iter);
     92    world.unselectMolecule(*iter);
     93
    9094  return ActionState::ptr(_state);
    9195}
     
    9498  SelectionMoleculeByOrderState *state = assert_cast<SelectionMoleculeByOrderState*>(_state.get());
    9599
     100  World &world = World::getInstance();
    96101  for (std::vector<const molecule *>::const_iterator iter = state->mols.begin();
    97102      iter != state->mols.end(); ++iter)
    98     World::getInstance().selectMolecule(*iter);
     103    world.selectMolecule(*iter);
    99104  return ActionState::ptr(_state);
    100105}
  • src/Actions/SelectionAction/Molecules/NotMoleculeByOrderAction.cpp

    rd5c1c8 rc5bd60c  
    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

    rd5c1c8 rc5bd60c  
    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.