Eclipse SUMO - Simulation of Urban MObility
GNEUndoList.h
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 // FXUndoList is pretty dandy but some features are missing:
19 // - we cannot find out wether we have currently begun an undo-group and
20 // thus abort() is hard to use.
21 // - onUpd-methods do not disable undo/redo while in an undo-group
22 //
23 // GNEUndoList inherits from FXUndoList and patches some methods. these are
24 // prefixed with p_
25 /****************************************************************************/
26 #pragma once
27 #include <config.h>
28 
29 #include <stack>
30 #include <string>
31 #include <fx.h>
32 
33 
34 // ===========================================================================
35 // class declarations
36 // ===========================================================================
39 
40 // ===========================================================================
41 // class definitions
42 // ===========================================================================
46 class GNEUndoList : public FXUndoList {
48  FXDECLARE_ABSTRACT(GNEUndoList)
49 
50 public:
54 
60  void p_begin(const std::string& description);
61 
67  void p_end();
68 
70  void p_clear();
71 
73  void p_abort();
74 
77 
79  void undo();
80 
82  void redo();
83 
85  void p_add(GNEChange_Attribute* cmd);
86 
88  int currentCommandGroupSize() const;
89 
93  long p_onUpdUndo(FXObject*, FXSelector, void*);
94 
96  long p_onUpdRedo(FXObject*, FXSelector, void*);
98 
100  bool hasCommandGroup() const;
101 
102 private:
104  class CommandGroup : public FXCommandGroup {
105  public:
107  CommandGroup(std::string description);
108 
110  const std::string& getDescription();
111 
113  FXString undoName() const;
114 
116  FXString redoName() const;
117 
118  private:
120  const std::string myDescription;
121  };
122 
123  // @brief the stack of currently active command groups
124  std::stack<CommandGroup*> myCommandGroups;
125 
126  // @brief the parent GNEApplicationWindow for this undolist
128 };
The main window of the Netedit.
the function-object for an editing operation (abstract base)
class CommandGroup
Definition: GNEUndoList.h:104
FXString undoName() const
get undo Name
FXString redoName() const
get redo name
CommandGroup(std::string description)
Constructor.
const std::string myDescription
description of command
Definition: GNEUndoList.h:120
const std::string & getDescription()
get description
bool hasCommandGroup() const
Check if undoList has command group.
void undo()
undo the last command group
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
GNEApplicationWindow *const myGNEApplicationWindowParent
Definition: GNEUndoList.h:127
void p_clear()
clears the undo list (implies abort)
Definition: GNEUndoList.cpp:89
void p_begin(const std::string &description)
Begin undo command sub-group. This begins a new group of commands that are treated as a single comman...
Definition: GNEUndoList.cpp:71
std::stack< CommandGroup * > myCommandGroups
Definition: GNEUndoList.h:124
void redo()
redo the last command group
int currentCommandGroupSize() const
get size of current CommandGroup
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
Definition: GNEUndoList.cpp:78
long p_onUpdUndo(FXObject *, FXSelector, void *)
long p_onUpdRedo(FXObject *, FXSelector, void *)
event after Redo
GNEUndoList(GNEApplicationWindow *parent)
FOX declaration.
Definition: GNEUndoList.cpp:64
void p_abort()
reverts and discards ALL active command groups
void p_abortLastCommandGroup()
reverts last command group