SUMO - Simulation of Urban MObility
GNEUndoList.h
Go to the documentation of this file.
1 /****************************************************************************/
7 // FXUndoList is pretty dandy but some features are missing:
8 // - we cannot find out wether we have currently begun an undo-group and
9 // thus abort() is hard to use.
10 // - onUpd-methods do not disable undo/redo while in an undo-group
11 //
12 // GNEUndoList inherits from FXUndoList and patches some methods. these are
13 // prefixed with p_
14 /****************************************************************************/
15 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
16 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
17 /****************************************************************************/
18 //
19 // This file is part of SUMO.
20 // SUMO is free software: you can redistribute it and/or modify
21 // it under the terms of the GNU General Public License as published by
22 // the Free Software Foundation, either version 3 of the License, or
23 // (at your option) any later version.
24 //
25 /****************************************************************************/
26 #ifndef GNEUndoList_h
27 #define GNEUndoList_h
28 
29 
30 // ===========================================================================
31 // included modules
32 // ===========================================================================
33 #ifdef _MSC_VER
34 #include <windows_config.h>
35 #else
36 #include <config.h>
37 #endif
38 
39 #include <stack>
40 #include <fx.h>
41 
42 
43 // ===========================================================================
44 // class declarations
45 // ===========================================================================
48 
49 // ===========================================================================
50 // class definitions
51 // ===========================================================================
55 class GNEUndoList : public FXUndoList {
56  FXDECLARE_ABSTRACT(GNEUndoList)
57 
58 
59 public:
61  /* be aware that "parent" may be not fully initialized when stored here,
62  so don't call any methods on it. */
63  GNEUndoList(GNEApplicationWindow* parent) : FXUndoList(), myParent(parent) {}
64 
71  void p_begin(const std::string& description);
72 
79  void p_end();
80 
84  void p_clear();
85 
89  void p_abort();
90 
94  void undo();
95 
99  void redo();
100 
104  void p_add(GNEChange_Attribute* cmd);
105 
106 
107  long p_onUpdUndo(FXObject*, FXSelector, void*);
108  long p_onUpdRedo(FXObject*, FXSelector, void*);
109 
110 
111  bool hasCommandGroup() const {
112  return myCommandGroups.size() != 0;
113  }
114 
115 private:
116 
117  class CommandGroup : public FXCommandGroup {
118  public:
119  CommandGroup(std::string description) : myDescription(description) {}
120 
121  const std::string& getDescription() {
122  return myDescription;
123  }
124  FXString undoName() const {
125  return ("Undo " + myDescription).c_str();
126  }
127  FXString redoName() const {
128  return ("Redo " + myDescription).c_str();
129  }
130 
131  private:
132  const std::string myDescription;
133  };
134 
135  // the stack of currently active command groups
136  std::stack<CommandGroup*> myCommandGroups;
137 
138  // the parent application for this undolist
140 };
141 
142 
143 #endif
144 
145 /****************************************************************************/
146 
The main window of the Netedit.
FXString undoName() const
Definition: GNEUndoList.h:124
const std::string myDescription
Definition: GNEUndoList.h:132
void p_begin(const std::string &description)
Definition: GNEUndoList.cpp:75
void redo()
redo the last command group
void undo()
undo the last command group
void p_clear()
Definition: GNEUndoList.cpp:89
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
the function-object for an editing operation (abstract base)
const std::string & getDescription()
Definition: GNEUndoList.h:121
GNEUndoList(GNEApplicationWindow *parent)
constructor
Definition: GNEUndoList.h:63
void p_end()
Definition: GNEUndoList.cpp:82
std::stack< CommandGroup * > myCommandGroups
Definition: GNEUndoList.h:136
GNEApplicationWindow *const myParent
Definition: GNEUndoList.h:139
void p_abort()
reverts and discards ALL active command groups
Definition: GNEUndoList.cpp:96
long p_onUpdRedo(FXObject *, FXSelector, void *)
bool hasCommandGroup() const
Definition: GNEUndoList.h:111
CommandGroup(std::string description)
Definition: GNEUndoList.h:119
FXString redoName() const
Definition: GNEUndoList.h:127
long p_onUpdUndo(FXObject *, FXSelector, void *)