SUMO - Simulation of Urban MObility
GNEAdditionalDialog.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // A abstract class for editing additional elements
18 /****************************************************************************/
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #ifdef _MSC_VER
24 #include <windows_config.h>
25 #else
26 #include <config.h>
27 #endif
28 
29 #include <iostream>
33 
34 #include "GNEAdditionalDialog.h"
35 #include "GNEAdditional.h"
36 #include "GNEViewNet.h"
37 #include "GNEUndoList.h"
38 
39 
40 // ===========================================================================
41 // FOX callback mapping
42 // ===========================================================================
43 
44 FXDEFMAP(GNEAdditionalDialog) GNEAdditionalDialogMap[] = {
45  FXMAPFUNC(SEL_KEYPRESS, 0, GNEAdditionalDialog::onKeyPress),
46  FXMAPFUNC(SEL_KEYRELEASE, 0, GNEAdditionalDialog::onKeyRelease),
47  FXMAPFUNC(SEL_CLOSE, 0, GNEAdditionalDialog::onCmdCancel),
51 };
52 
53 // Object abstract implementation
54 FXIMPLEMENT_ABSTRACT(GNEAdditionalDialog, FXTopWindow, GNEAdditionalDialogMap, ARRAYNUMBER(GNEAdditionalDialogMap))
55 
56 // ===========================================================================
57 // member method definitions
58 // ===========================================================================
59 
60 GNEAdditionalDialog::GNEAdditionalDialog(GNEAdditional* parent, int width, int height) :
61  FXTopWindow(parent->getViewNet(), ("Edit '" + parent->getID() + "' data").c_str(), parent->getIcon(), parent->getIcon(), GUIDesignDialogBoxExplicit, 0, 0, width, height, 0, 0, 0, 0, 4, 4),
62  myChangesDescription("change " + toString(parent->getTag()) + " values"),
63  myNumberOfChanges(0),
64  myUndoList(parent->getViewNet()->getUndoList()) {
65  // create main frame
66  FXVerticalFrame* mainFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);
67  // Create frame for contents
68  myContentFrame = new FXVerticalFrame(mainFrame, GUIDesignContentsFrame);
69  // create buttons centered
70  FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(mainFrame, GUIDesignHorizontalFrame);
71  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
72  myAcceptButton = new FXButton(buttonsFrame, "accept\t\tclose accepting changes", GUIIconSubSys::getIcon(ICON_ACCEPT), this, MID_GNE_ADDITIONALDIALOG_BUTTONACCEPT, GUIDesignButtonAccept);
73  myCancelButton = new FXButton(buttonsFrame, "cancel\t\tclose discarding changes", GUIIconSubSys::getIcon(ICON_CANCEL), this, MID_GNE_ADDITIONALDIALOG_BUTTONCANCEL, GUIDesignButtonCancel);
74  myResetButton = new FXButton(buttonsFrame, "reset\t\treset to previous values", GUIIconSubSys::getIcon(ICON_RESET), this, MID_GNE_ADDITIONALDIALOG_BUTTONRESET, GUIDesignButtonReset);
75  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
76 }
77 
78 
80 
81 
82 FXint
84  // create Dialog
85  create();
86  // show in the given position
87  show(placement);
88  // refresh APP
89  getApp()->refresh();
90  // open as modal dialog (will block all windows until stop() or stopModal() is called)
91  return getApp()->runModalFor(this);
92 }
93 
94 
95 long
96 GNEAdditionalDialog::onKeyPress(FXObject* sender, FXSelector sel, void* ptr) {
97  return FXTopWindow::onKeyPress(sender, sel, ptr);
98 }
99 
100 
101 long
102 GNEAdditionalDialog::onKeyRelease(FXObject* sender, FXSelector sel, void* ptr) {
103  return FXTopWindow::onKeyRelease(sender, sel, ptr);
104 }
105 
106 
107 void
109  // change FXDialogBox title
110  setTitle(newHeader.c_str());
111 }
112 
113 
114 void
116  // init commandGroup
118  // save number of command group changes
120 }
121 
122 
123 void
125  // commit changes or abort last command group depending of number of changes did
126  if (myNumberOfChanges < myUndoList->currentCommandGroupSize()) {
127  myUndoList->p_end();
128  } else {
130  }
131 }
132 
133 
134 void
137 }
138 
139 
140 void
142  // abort last command group an start editing again
145 }
146 
147 /****************************************************************************/
long onKeyRelease(FXObject *sender, FXSelector sel, void *ptr)
event after release a key
void resetChanges()
reset changes did in this dialog.
virtual long onCmdReset(FXObject *, FXSelector, void *)=0
event after press cancel button
#define GUIDesignHorizontalFrame
Definition: GUIDesigns.h:206
~GNEAdditionalDialog()
destructor
#define GUIDesignContentsFrame
design for the main content frame of every frame/dialog
Definition: GUIDesigns.h:255
Dialog to edit sequences, parameters, etc.. of Additionals.
#define GUIDesignButtonCancel
Cancel Button.
Definition: GUIDesigns.h:103
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:84
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frames used to pack another frames extended in all directions ...
Definition: GUIDesigns.h:243
FXDEFMAP(GNEAdditionalDialog) GNEAdditionalDialogMap[]
#define GUIDesignDialogBoxExplicit
design for dialog box with specift width and height (for example, additional dialogs) ...
Definition: GUIDesigns.h:398
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
virtual long onCmdCancel(FXObject *sender, FXSelector sel, void *ptr)=0
event after press cancel button
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise, the sub-group will be added as a new command into parent group. A matching begin() must have been called previously.
Definition: GNEUndoList.cpp:91
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames ...
Definition: GUIDesigns.h:246
GNEUndoList * myUndoList
pointer to UndoList
#define GUIDesignButtonReset
Reset Button.
Definition: GUIDesigns.h:106
virtual long onCmdAccept(FXObject *sender, FXSelector sel, void *ptr)=0
int currentCommandGroupSize() const
get size of current CommandGroup
void p_abortLastCommandGroup()
reverts last command group
std::string myChangesDescription
description of changes did in this additional dialog
#define GUIDesignButtonAccept
Accept Button.
Definition: GUIDesigns.h:100
void acceptChanges()
Accept changes did in this dialog.
void initChanges()
init a new group of changes that will be do it in dialog
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:59
long onKeyPress(FXObject *sender, FXSelector sel, void *ptr)
event after press a key
void cancelChanges()
Cancel changes did in this dialog.
int myNumberOfChanges
number of GNEChanges_... in dialog
FXint openAsModalDialog(FXuint placement=PLACEMENT_CURSOR)
execute dialog as modal
void changeAdditionalDialogHeader(const std::string &newHeader)
change additional dialog header
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon