Changeset 0ec9f5


Ignore:
Timestamp:
Apr 23, 2021, 9:02:12 PM (5 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
Candidate_v1.7.0, stable
Children:
0fbea3
Parents:
5061d9
git-author:
Frederik Heber <frederik.heber@…> (04/06/21 20:09:39)
git-committer:
Frederik Heber <frederik.heber@…> (04/23/21 21:02:12)
Message:

Added UndoMarkAction.

NOTE: This action is necessary as not all actions are actually recorded
in the history. For example, the UndoAction is an action that is not
pushed into the history deque and also must not as further undos would
then become impossible. There are other actions that just do output
or similar things that do not change the state.
This makes it impossible to undo back to a certain state by blindly
counting actions as one cannot know from the outside whether an action
is stateless or not.

undoing till the set mark.

  • TESTS: added regression test case on undo-mark.
Files:
4 added
12 edited

Legend:

Unmodified
Added
Removed
  • doc/userguide/userguide.xml

    r5061d9 r0ec9f5  
    426426        superfluous but it comes in very handy in the interactive ones. Also
    427427        this should tell you that actions are placed internally in a queue, i.e. a history,
    428         that undo and redo manipulate.</para>
     428        that undo and redo manipulate.</para>
     429        <para>Furthermore, a specific event in the history of actions can be
     430        marked using
     431        <programlisting>... --add-atom H --domain-position &quot;0,0,0&quot; --undo-mark --select-all-atoms --remove-atom</programlisting>
     432        Using this mark (that is unset by <programlisting>--undo-mark 0</programlisting>)
     433        one can then step directly back to that event by undoing all actions in between
     434        the current and the marked event.
     435        <programlisting>--undo --till-mark 1</programlisting>
     436        Here, this will jump back to when the hydrogen atom was just added.
     437        This function is required as not all actions produce an event in the Action
     438        history. Certain events will just calculate something and output, i.e. they
     439        do not change the state. However, thereby one cannot simply count actions
     440        to return back to a specific state. Hence, this function allows to mark a
     441        specific state beforehand.
     442        </para>
    429443        <para>Due to a current limitation of the implementation each command can be used on the command-line only once. Note that this <emphasis role="italic">only</emphasis> applies to the command-line interface. All other interfaces, especially all interactive ones, do not have such a restriction. For the command-line interface there are several ways to work around it. Either by splitting the whole chain of commands into several chunks, each using only unique commands and using the input file (the state) to contain  and transport the intermediate stages as input for the next stage. Or to switch to other commands: often there are several possible ways of achieving a goal, especially when using selections.</para>
    430444        <para>Being done now with the preliminaries we now go through all available actions present in MoleCuilder.</para>
  • src/Actions/ActionHistory.cpp

    r5061d9 r0ec9f5  
    6464  HistoryElement elem = history.back();
    6565  LOG(1, "INFO: Undoing action " << elem.action->getName());
     66  if ((mark != NULL) && (mark == &elem)) {
     67    LOG(2, "DEBUG: Undoing marked item in ActionHistory, hence resetting mark.");
     68    mark = NULL;
     69  }
    6670  history.pop_back();
    6771  ActionState::ptr newState = elem.action->undo(elem.state);
     
    9397}
    9498
     99void ActionHistory::setMark() {
     100  mark = &(history.back());
     101}
     102
     103void ActionHistory::unsetMark() {
     104  mark = NULL;
     105}
     106
     107void ActionHistory::undoTillMark() {
     108  if (mark == NULL) {
     109    undoLast();
     110  } else {
     111    while (mark != &(history.back()))
     112      undoLast();
     113  }
     114}
     115
    95116void ActionHistory::addElement(Action* action,ActionState::ptr state){
    96117  yrotsih.clear();
  • src/Actions/ActionHistory.hpp

    r5061d9 r0ec9f5  
    4343  bool hasRedo();
    4444
     45  void setMark();
     46  void unsetMark();
     47  void undoTillMark();
     48
    4549  void addElement(Action*,ActionState::ptr);
    4650  void clear();
     
    4953  std::deque<HistoryElement> history;
    5054  std::deque<HistoryElement> yrotsih;
     55
     56  //!> marks a specific state in the history to allow undoing directly till that
     57  HistoryElement * mark;
    5158
    5259public:
  • src/Actions/ActionQueue.cpp

    r5061d9 r0ec9f5  
    412412}
    413413
     414void ActionQueue::setMark() {
     415  history->setMark();
     416}
     417
     418void ActionQueue::unsetMark() {
     419  history->unsetMark();
     420}
     421
     422void ActionQueue::undoTillMark()
     423{
     424  history->undoTillMark();
     425}
     426
    414427bool ActionQueue::canUndo() const
    415428{
  • src/Actions/ActionQueue.hpp

    r5061d9 r0ec9f5  
    129129  void outputAsPython(std::ostream &output) const;
    130130
    131   /** Undoes last called Acfriend void ::cleanUp();tion.
     131  /** Undoes last called Action.
    132132   *
    133133   */
     
    138138   */
    139139  void redoLast();
     140
     141  /**
     142   * Marks the current item of the action history to allow returning to that state lateron.
     143   */
     144  void setMark();
     145
     146  /**
     147   * Resets any currently marked item in the action history.
     148   */
     149  void unsetMark();
     150
     151  /** Undoes actions till a set mark in the ActionHistory.
     152   *
     153   */
     154  void undoTillMark();
    140155
    141156  /** Checks whether there is one completed Action stored in ActionHistory in the past.
  • src/Actions/GlobalListOfActions.hpp

    r5061d9 r0ec9f5  
    5454  (CommandSetRandomNumbersDistribution) \
    5555  (CommandStoreSession) \
     56  (CommandUndoMark) \
    5657  (CommandVerbose) \
    5758  (CommandVersion) \
  • src/Actions/Makefile.am

    r5061d9 r0ec9f5  
    207207  Actions/CommandAction/NoDryRunAction.cpp \
    208208  Actions/CommandAction/StoreSessionAction.cpp \
     209  Actions/CommandAction/UndoMarkAction.cpp \
    209210  Actions/CommandAction/VerboseAction.cpp \
    210211  Actions/CommandAction/VersionAction.cpp \
     
    219220  Actions/CommandAction/NoDryRunAction.hpp \
    220221  Actions/CommandAction/StoreSessionAction.hpp \
     222  Actions/CommandAction/UndoMarkAction.hpp \
    221223  Actions/CommandAction/VerboseAction.hpp \
    222224  Actions/CommandAction/VersionAction.hpp \
     
    231233  Actions/CommandAction/NoDryRunAction.def \
    232234  Actions/CommandAction/StoreSessionAction.def \
     235  Actions/CommandAction/UndoMarkAction.def \
    233236  Actions/CommandAction/VerboseAction.def \
    234237  Actions/CommandAction/VersionAction.def \
  • src/Actions/UndoAction.cpp

    r5061d9 r0ec9f5  
    5252ActionState::ptr UndoAction::performCall(){
    5353  // std::cout << "Undo" << std::endl;
    54   ActionQueue::getInstance().undoLast();
     54  if (params.undoTillMark.get())
     55    ActionQueue::getInstance().undoTillMark();
     56  else
     57    ActionQueue::getInstance().undoLast();
    5558  return Action::success;
    5659}
  • src/Actions/UndoAction.def

    r5061d9 r0ec9f5  
    1313// ValueStorage by the token "Z" -> first column: int, Z, "Z"
    1414// "undefine" if no parameters are required, use (NOPARAM_DEFAULT) for each (undefined) default value
    15 #undef paramtypes
    16 #undef paramreferences
    17 #undef paramtokens
    18 #undef paramdescriptions
    19 #undef paramdefaults
     15#define paramtypes (bool)
     16#define paramtokens ("till-mark")
     17#define paramdescriptions ("whether to undo just a single step (false) or until a previously set mark (true)")
     18#define paramdefaults (PARAM_DEFAULT(false))
     19#define paramreferences (undoTillMark)
     20#define paramvalids (DummyValidator<bool>())
    2021
    2122// some defines for all the names, you may use ACTION, STATE and PARAMS
     
    2728
    2829// finally the information stored in the ActionTrait specialization
    29 #define DESCRIPTION "undo last action"
     30#define DESCRIPTION "undo last action or until a given mark"
    3031#undef SHORTFORM
  • tests/Python/AllActions/options.dat

    r5061d9 r0ec9f5  
    250250take_best_of            "5"
    251251tesselation_radius      "5."
     252till-mark       "0"
    252253time_step_zero  "0"
    253254training_file   "training.dat"
     
    255256translate_shapes        "1. 2. 3."
    256257translation     "0. 0. 0."
     258undo-mark       "0"
    257259unselect_atom_by_element        "1"
    258260unselect_atom_by_element        "4"
  • tests/regression/Makefile.am

    r5061d9 r0ec9f5  
    180180        $(srcdir)/Options/Session/testsuite-options-store-session-python.at \
    181181        $(srcdir)/Options/SetDefaultName/testsuite-options-set-default-name.at \
     182        $(srcdir)/Options/UndoMark/testsuite-options-undo-mark.at \
    182183        $(srcdir)/Options/Verbosity/testsuite-options-verbosity.at \
    183184        $(srcdir)/Options/Warranty/testsuite-options-warranty.at \
  • tests/regression/Options/testsuite-options.at

    r5061d9 r0ec9f5  
    5555m4_include([Options/DryRun/testsuite-options-no-dryrun.at])
    5656m4_include([Options/DryRun/testsuite-options-dryrun-storesession.at])
     57
     58# test undo mark
     59m4_include([Options/UndoMark/testsuite-options-undo-mark.at])
Note: See TracChangeset for help on using the changeset viewer.