Eclipse SUMO - Simulation of Urban MObility
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GNEUndoListDialog.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2025 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// Dialog for show undo-list
19/****************************************************************************/
20
22#include <netedit/GNEUndoList.h>
24
25#include "GNEUndoListDialog.h"
26
27// ===========================================================================
28// FOX callback mapping
29// ===========================================================================
30
31FXDEFMAP(GNEUndoListDialog) GNEUndoListDialogMap[] = {
32 FXMAPFUNC(SEL_CLOSE, 0, GNEUndoListDialog::onCmdClose),
35};
36
37// Object implementation
38FXIMPLEMENT(GNEUndoListDialog, FXTopWindow, GNEUndoListDialogMap, ARRAYNUMBER(GNEUndoListDialogMap))
39
40// ===========================================================================
41// member method definitions
42// ===========================================================================
43
45 FXTopWindow(GNEApp->getApp(), TL("Undo/Redo history"), GUIIconSubSys::getIcon(GUIIcon::UNDOLIST), GUIIconSubSys::getIcon(GUIIcon::UNDOLIST), GUIDesignDialogBoxExplicit(560, 400)),
46 myGNEApp(GNEApp) {
47 // create main frame
48 auto mainFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);
49 // create scroll windows for rows
50 auto* scrollWindowsContents = new FXScrollWindow(mainFrame, GUIDesignContentsScrollUndoList);
51 myRowFrame = new FXVerticalFrame(scrollWindowsContents, GUIDesignAuxiliarFrame);
52 // add separator
53 new FXSeparator(mainFrame);
54 // create buttons centered
55 FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(mainFrame, GUIDesignHorizontalFrame);
56 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
58 new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
59}
60
61
63
64
65void
67 // recalc list
68 recalcList();
69 // show
70 FXTopWindow::show(PLACEMENT_SCREEN);
71 // open as modal dialog (will block all windows until stop() or stopModal() is called)
72 myGNEApp->getApp()->runModalFor(this);
73
74}
75
76
77void
79 // stop modal
80 myGNEApp->getApp()->stopModal(this);
81 FXTopWindow::hide();
82}
83
84
85bool
87 return FXWindow::shown();
88}
89
90
91void
93 FXWindow::setFocus();
94}
95
96
97long
98GNEUndoListDialog::onCmdClose(FXObject*, FXSelector, void*) {
99 // close dialog
100 hide();
101 return 1;
102}
103
104
105long
106GNEUndoListDialog::onCmdSelectRow(FXObject* obj, FXSelector, void*) {
107 int index = 0;
108 // search button
109 for (const auto& row : myGUIRows) {
110 if (row->getRadioButton() == obj) {
111 index = row->getIndex();
112 }
113 }
114 // now apply undo-redos
115 if (index < 0) {
116 for (int i = 0; i < (index * -1); i++) {
118 }
119 } else {
120 for (int i = 0; i < index; i++) {
122 }
123 }
124 // update list again
125 updateList();
126 return 1;
127}
128
129
130void
132 // declare vector of undoListRows
133 std::vector<UndoListRow> undoListRows;
134 // declare redo iterator over UndoList
136 // declare index
137 int index = 1;
138 // fill undoListRows rows with elements to redo (in inverse)
139 while (!itRedo.end()) {
140 undoListRows.push_back(UndoListRow(index, itRedo.getIcon(), itRedo.getDescription(), itRedo.getTimeStamp()));
141 // update counters
142 itRedo++;
143 index++;
144 }
145 // reverse undoListRows rows (because redo are inserted inverted)
146 std::reverse(undoListRows.begin(), undoListRows.end());
147 // declare undo iterator over UndoList
149 // reset index
150 index = 0;
151 // fill undoListRows with elements to undo
152 while (!itUndo.end()) {
153 undoListRows.push_back(UndoListRow(index, itUndo.getIcon(), itUndo.getDescription(), itUndo.getTimeStamp()));
154 // update counters
155 itUndo++;
156 index--;
157 }
158 // fill GUIRows with undoListRows
159 for (int i = 0; i < (int)undoListRows.size(); i++) {
160 myGUIRows.at(i)->update(undoListRows.at(i));
161 if (undoListRows.at(i).index < 0) {
162 myGUIRows.at(i)->setBlueBackground();
163 } else if (undoListRows.at(i).index > 0) {
164 myGUIRows.at(i)->setRedBackground();
165 } else {
166 myGUIRows.at(i)->checkRow();
167 }
168 }
169}
170
171
172void
174 // first clear rows
175 for (auto& GUIRow : myGUIRows) {
176 delete GUIRow;
177 }
178 myGUIRows.clear();
179 // declare redo iterator over undoList and fill rows
181 while (!itRedo.end()) {
182 myGUIRows.push_back(new GUIRow(this, myRowFrame, myGNEApp->getStaticTooltipView()));
183 itRedo++;
184 }
185 // declare undo iterator over undoList and fill rows
187 while (!itUndo.end()) {
188 myGUIRows.push_back(new GUIRow(this, myRowFrame, myGNEApp->getStaticTooltipView()));
189 itUndo++;
190 }
191 // recalc frame and update list
192 myRowFrame->recalc();
193 updateList();
194}
195
196
197GNEUndoListDialog::UndoListRow::UndoListRow(const int index_, FXIcon* icon_, const std::string description_, const std::string timestamp_) :
198 index(index_),
199 icon(icon_),
200 description(description_),
201 timestamp(timestamp_) {}
202
203
204GNEUndoListDialog::GUIRow::GUIRow(GNEUndoListDialog* undoListDialog, FXVerticalFrame* mainFrame, MFXStaticToolTip* staticToolTip) {
205 FXHorizontalFrame* horizontalFrame = new FXHorizontalFrame(mainFrame, GUIDesignAuxiliarHorizontalFrame);
206 // build radio button
207 myRadioButton = new FXRadioButton(horizontalFrame, "", undoListDialog, MID_CHOOSEN_OPERATION, GUIDesignRadioButtonSquared);
208 // build icon label
209 myIcon = new FXLabel(horizontalFrame, "", nullptr, GUIDesignLabelIconThick);
210 // build description label
211 myTextFieldDescription = new MFXTextFieldTooltip(horizontalFrame, staticToolTip, GUIDesignTextFieldNCol, undoListDialog, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
212 myTextFieldDescription->setEditable(false);
213 // build text label
214 myTextFieldTimeStamp = new FXTextField(horizontalFrame, GUIDesignTextFieldNCol, undoListDialog, MID_GNE_SET_ATTRIBUTE, GUIDesignTextFieldFixed(70));
215 myTextFieldTimeStamp->setEditable(false);
216 // create elements
217 horizontalFrame->create();
218 myIcon->create();
219 myTextFieldDescription->create();
220 myTextFieldTimeStamp->create();
221}
222
223
225 delete myRadioButton;
226 delete myIcon;
227 delete myTextFieldDescription;
228 delete myTextFieldTimeStamp;
229}
230
231
232void
234 myIndex = row.index;
235 myIcon->setIcon(row.icon);
236 // check if text must be trimmed
237 if (row.description.size() > 57) {
238 std::string textFieldTrimmed;
239 for (int i = 0; i < 57; i++) {
240 textFieldTrimmed.push_back(row.description.at(i));
241 }
242 textFieldTrimmed.append("...");
243 myTextFieldDescription->setText(textFieldTrimmed.c_str());
244 myTextFieldDescription->setToolTipText(row.description.c_str());
245 } else {
246 myTextFieldDescription->setText(row.description.c_str());
247 myTextFieldDescription->setToolTipText("");
248 }
249 myTextFieldTimeStamp->setText(row.timestamp.c_str());
250}
251
252
253int
255 return myIndex;
256}
257
258
259const FXRadioButton*
261 return myRadioButton;
262}
263
264
265void
267 myRadioButton->setCheck(FALSE);
268 myRadioButton->setBackColor(FXRGBA(255, 213, 213, 255));
269}
270
271
272void
274 myRadioButton->setCheck(FALSE);
275 myRadioButton->setBackColor(FXRGBA(210, 233, 255, 255));
276}
277
278
279void
281 myRadioButton->setCheck(TRUE);
282 myRadioButton->setBackColor(FXRGBA(240, 255, 205, 255));
283}
FXDEFMAP(GNEUndoListDialog) GNEUndoListDialogMap[]
@ MID_GNE_SET_ATTRIBUTE
attribute edited
Definition GUIAppEnum.h:939
@ MID_CHOOSEN_OPERATION
set type of selection
Definition GUIAppEnum.h:597
@ MID_GNE_BUTTON_ACCEPT
accept button
#define GUIDesignDialogBoxExplicit(width, height)
design for dialog box with specific width and height (for example, additional dialogs)
Definition GUIDesigns.h:614
#define GUIDesignTextFieldFixed(width)
text field with fixed width
Definition GUIDesigns.h:65
#define GUIDesignButtonAccept
Accept Button.
Definition GUIDesigns.h:156
#define GUIDesignTextField
Definition GUIDesigns.h:59
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:399
#define GUIDesignRadioButtonSquared
design for radio button squared
Definition GUIDesigns.h:232
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition GUIDesigns.h:74
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frame extended in all directions
Definition GUIDesigns.h:390
#define GUIDesignHorizontalFrame
Horizontal frame extended over frame parent with padding and spacing.
Definition GUIDesigns.h:328
#define GUIDesignContentsScrollUndoList
design for the content scroll of UndoList
Definition GUIDesigns.h:381
#define GUIDesignLabelIconThick
label squared over frame with thick and with text justify to center
Definition GUIDesigns.h:255
GUIIcon
An enumeration of icons used by the gui applications.
Definition GUIIcons.h:33
#define TL(string)
Definition MsgHandler.h:305
The main window of Netedit.
GNEUndoList * getUndoList()
get pointer to undoList
const std::string getTimeStamp() const
get timeStamp
const std::string getDescription() const
get description
bool end() const
check if iterator is at the end
FXIcon * getIcon() const
get icon
row used for show GUI row elements
void checkRow()
check row and set background green
const FXRadioButton * getRadioButton() const
get radio button (read only)
int getIndex() const
get index
void setBlueBackground()
set blue background
void setRedBackground()
set red background
GUIRow(GNEUndoListDialog *undoListDialog, FXVerticalFrame *mainFrame, MFXStaticToolTip *staticToolTip)
constructor
void update(const UndoListRow &row)
update row
Dialog for edit rerouters.
void updateList()
FOX needs this.
long onCmdSelectRow(FXObject *, FXSelector, void *)
event after select row
~GNEUndoListDialog()
destructor
void show()
show window
long onCmdClose(FXObject *, FXSelector, void *)
bool shown() const
check if dialog is shown
void setFocus()
Move the focus to this window.
void hide()
hide window
GNEApplicationWindow * myGNEApp
pointer to GNEApplicationWindow
FXVerticalFrame * myRowFrame
frame for rows
std::vector< GUIRow * > myGUIRows
vector with rows
void recalcList()
recalc list destroying and creating rows
void undo()
undo the last command group
void redo()
redo the last command group
static FXButton * buildFXButton(FXComposite *p, const std::string &text, const std::string &tip, const std::string &help, FXIcon *ic, FXObject *tgt, FXSelector sel, FXuint opts=BUTTON_NORMAL, FXint x=0, FXint y=0, FXint w=0, FXint h=0, FXint pl=DEFAULT_PAD, FXint pr=DEFAULT_PAD, FXint pt=DEFAULT_PAD, FXint pb=DEFAULT_PAD)
build button
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
MFXStaticToolTip * getStaticTooltipView() const
get static toolTip for view
MFXStaticToolTip (based on FXToolTip)
int index
index uses for count undo/redos
FXIcon * icon
icon associated with undo/redo operation
UndoListRow(const int index_, FXIcon *icon_, const std::string description_, const std::string timestamp_)
constructor
std::string description
definition of undo/redo operation