Eclipse SUMO - Simulation of Urban MObility
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-2024 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 
23 #include <netedit/GNEUndoList.h>
24 
25 #include "GNEUndoListDialog.h"
26 
27 
28 // ===========================================================================
29 // FOX callback mapping
30 // ===========================================================================
31 
32 FXDEFMAP(GNEUndoListDialog) GNEUndoListDialogMap[] = {
33  FXMAPFUNC(SEL_CLOSE, 0, GNEUndoListDialog::onCmdClose),
36 };
37 
38 // Object implementation
39 FXIMPLEMENT(GNEUndoListDialog, FXTopWindow, GNEUndoListDialogMap, ARRAYNUMBER(GNEUndoListDialogMap))
40 
41 // ===========================================================================
42 // member method definitions
43 // ===========================================================================
44 
46  FXTopWindow(GNEApp->getApp(), TL("Undo/Redo history"), GUIIconSubSys::getIcon(GUIIcon::UNDOLIST), GUIIconSubSys::getIcon(GUIIcon::UNDOLIST), GUIDesignDialogBoxExplicit(560, 400)),
47  myGNEApp(GNEApp) {
48  // create main frame
49  auto mainFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);
50  // create scroll windows for rows
51  auto* scrollWindowsContents = new FXScrollWindow(mainFrame, GUIDesignContentsScrollUndoList);
52  myRowFrame = new FXVerticalFrame(scrollWindowsContents, GUIDesignAuxiliarFrame);
53  // add separator
54  new FXSeparator(mainFrame);
55  // create buttons centered
56  FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(mainFrame, GUIDesignHorizontalFrame);
57  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
59  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
60 }
61 
62 
64 
65 
66 void
68  // recalc list
69  recalcList();
70  // show
71  FXTopWindow::show(PLACEMENT_SCREEN);
72  // open as modal dialog (will block all windows until stop() or stopModal() is called)
73  myGNEApp->getApp()->runModalFor(this);
74 
75 }
76 
77 
78 void
80  // stop modal
81  myGNEApp->getApp()->stopModal(this);
82  FXTopWindow::hide();
83 }
84 
85 
86 bool
88  return FXWindow::shown();
89 }
90 
91 
92 void
94  FXWindow::setFocus();
95 }
96 
97 
98 long
99 GNEUndoListDialog::onCmdClose(FXObject*, FXSelector, void*) {
100  // close dialog
101  hide();
102  return 1;
103 }
104 
105 
106 long
107 GNEUndoListDialog::onCmdSelectRow(FXObject* obj, FXSelector, void*) {
108  int index = 0;
109  // search button
110  for (const auto& row : myGUIRows) {
111  if (row->getRadioButton() == obj) {
112  index = row->getIndex();
113  }
114  }
115  // now apply undo-redos
116  if (index < 0) {
117  for (int i = 0; i < (index * -1); i++) {
118  myGNEApp->getUndoList()->undo();
119  }
120  } else {
121  for (int i = 0; i < index; i++) {
122  myGNEApp->getUndoList()->redo();
123  }
124  }
125  // update list again
126  updateList();
127  return 1;
128 }
129 
130 
131 void
133  // declare vector of undoListRows
134  std::vector<UndoListRow> undoListRows;
135  // declare redo iterator over UndoList
137  // declare index
138  int index = 1;
139  // fill undoListRows rows with elements to redo (in inverse)
140  while (!itRedo.end()) {
141  undoListRows.push_back(UndoListRow(index, itRedo.getIcon(), itRedo.getDescription(), itRedo.getTimeStamp()));
142  // update counters
143  itRedo++;
144  index++;
145  }
146  // reverse undoListRows rows (because redo are inserted inverted)
147  std::reverse(undoListRows.begin(), undoListRows.end());
148  // declare undo iterator over UndoList
150  // reset index
151  index = 0;
152  // fill undoListRows with elements to undo
153  while (!itUndo.end()) {
154  undoListRows.push_back(UndoListRow(index, itUndo.getIcon(), itUndo.getDescription(), itUndo.getTimeStamp()));
155  // update counters
156  itUndo++;
157  index--;
158  }
159  // fill GUIRows with undoListRows
160  for (int i = 0; i < (int)undoListRows.size(); i++) {
161  myGUIRows.at(i)->update(undoListRows.at(i));
162  if (undoListRows.at(i).index < 0) {
163  myGUIRows.at(i)->setBlueBackground();
164  } else if (undoListRows.at(i).index > 0) {
165  myGUIRows.at(i)->setRedBackground();
166  } else {
167  myGUIRows.at(i)->checkRow();
168  }
169  }
170 }
171 
172 
173 void
175  // first clear rows
176  for (auto& GUIRow : myGUIRows) {
177  delete GUIRow;
178  }
179  myGUIRows.clear();
180  // declare redo iterator over undoList and fill rows
182  while (!itRedo.end()) {
183  myGUIRows.push_back(new GUIRow(this, myRowFrame, myGNEApp->getStaticTooltipView()));
184  itRedo++;
185  }
186  // declare undo iterator over undoList and fill rows
188  while (!itUndo.end()) {
189  myGUIRows.push_back(new GUIRow(this, myRowFrame, myGNEApp->getStaticTooltipView()));
190  itUndo++;
191  }
192  // recalc frame and update list
193  myRowFrame->recalc();
194  updateList();
195 }
196 
197 
198 GNEUndoListDialog::UndoListRow::UndoListRow(const int index_, FXIcon* icon_, const std::string description_, const std::string timestamp_) :
199  index(index_),
200  icon(icon_),
201  description(description_),
202  timestamp(timestamp_) {}
203 
204 
205 GNEUndoListDialog::GUIRow::GUIRow(GNEUndoListDialog* undoListDialog, FXVerticalFrame* mainFrame, MFXStaticToolTip* staticToolTip) {
206  FXHorizontalFrame* horizontalFrame = new FXHorizontalFrame(mainFrame, GUIDesignAuxiliarHorizontalFrame);
207  // build radio button
208  myRadioButton = new FXRadioButton(horizontalFrame, "", undoListDialog, MID_CHOOSEN_OPERATION, GUIDesignRadioButtonSquared);
209  // build icon label
210  myIcon = new FXLabel(horizontalFrame, "", nullptr, GUIDesignLabelIconThick);
211  // build description label
212  myTextFieldDescription = new MFXTextFieldTooltip(horizontalFrame, staticToolTip, GUIDesignTextFieldNCol, undoListDialog, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
213  myTextFieldDescription->setEditable(false);
214  // build text label
215  myTextFieldTimeStamp = new FXTextField(horizontalFrame, GUIDesignTextFieldNCol, undoListDialog, MID_GNE_SET_ATTRIBUTE, GUIDesignTextFieldFixed(70));
216  myTextFieldTimeStamp->setEditable(false);
217  // create elements
218  horizontalFrame->create();
219  myIcon->create();
220  myTextFieldDescription->create();
221  myTextFieldTimeStamp->create();
222 }
223 
224 
226  delete myRadioButton;
227  delete myIcon;
228  delete myTextFieldDescription;
229  delete myTextFieldTimeStamp;
230 }
231 
232 
233 void
235  myIndex = row.index;
236  myIcon->setIcon(row.icon);
237  // check if text must be trimmed
238  if (row.description.size() > 57) {
239  std::string textFieldTrimmed;
240  for (int i = 0; i < 57; i++) {
241  textFieldTrimmed.push_back(row.description.at(i));
242  }
243  textFieldTrimmed.append("...");
244  myTextFieldDescription->setText(textFieldTrimmed.c_str());
245  myTextFieldDescription->setToolTipText(row.description.c_str());
246  } else {
247  myTextFieldDescription->setText(row.description.c_str());
248  myTextFieldDescription->setToolTipText("");
249  }
250  myTextFieldTimeStamp->setText(row.timestamp.c_str());
251 }
252 
253 
254 int
256  return myIndex;
257 }
258 
259 
260 const FXRadioButton*
262  return myRadioButton;
263 }
264 
265 
266 void
268  myRadioButton->setCheck(FALSE);
269  myRadioButton->setBackColor(FXRGBA(255, 213, 213, 255));
270 }
271 
272 
273 void
275  myRadioButton->setCheck(FALSE);
276  myRadioButton->setBackColor(FXRGBA(210, 233, 255, 255));
277 }
278 
279 
280 void
282  myRadioButton->setCheck(TRUE);
283  myRadioButton->setBackColor(FXRGBA(240, 255, 205, 255));
284 }
FXDEFMAP(GNEUndoListDialog) GNEUndoListDialogMap[]
@ MID_GNE_SET_ATTRIBUTE
attribute edited
Definition: GUIAppEnum.h:935
@ MID_CHOOSEN_OPERATION
set type of selection
Definition: GUIAppEnum.h:597
@ MID_GNE_BUTTON_ACCEPT
accept button
Definition: GUIAppEnum.h:1419
#define GUIDesignDialogBoxExplicit(width, height)
design for dialog box with specific width and height (for example, additional dialogs)
Definition: GUIDesigns.h:617
#define GUIDesignTextFieldFixed(width)
text field with fixed width
Definition: GUIDesigns.h:71
#define GUIDesignButtonAccept
Accept Button.
Definition: GUIDesigns.h:162
#define GUIDesignTextField
Definition: GUIDesigns.h:65
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition: GUIDesigns.h:405
#define GUIDesignRadioButtonSquared
design for radio button squared
Definition: GUIDesigns.h:238
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition: GUIDesigns.h:80
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frame extended in all directions
Definition: GUIDesigns.h:396
#define GUIDesignHorizontalFrame
Horizontal frame extended over frame parent with padding and spacing.
Definition: GUIDesigns.h:334
#define GUIDesignContentsScrollUndoList
design for the content scroll of UndoList
Definition: GUIDesigns.h:387
#define GUIDesignLabelIconThick
label squared over frame with thick and with text justify to center
Definition: GUIDesigns.h:261
GUIIcon
An enumeration of icons used by the gui applications.
Definition: GUIIcons.h:33
#define TL(string)
Definition: MsgHandler.h:315
The main window of Netedit.
GNEUndoList * getUndoList()
get pointer to undoList
const std::string getTimeStamp() const
get timeStamp
Definition: GNEUndoList.cpp:77
const std::string getDescription() const
get description
Definition: GNEUndoList.cpp:70
bool end() const
check if iterator is at the end
Definition: GNEUndoList.cpp:58
FXIcon * getIcon() const
get icon
Definition: GNEUndoList.cpp:83
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
Definition: GUIDesigns.cpp:128
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