Eclipse SUMO - Simulation of Urban MObility
GNEDemandElementDialog.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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // A abstract class for editing additional elements
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
26 #include <netedit/GNEViewNet.h>
27 #include <netedit/GNEUndoList.h>
28 
29 #include "GNEDemandElementDialog.h"
30 
31 // ===========================================================================
32 // FOX callback mapping
33 // ===========================================================================
34 
35 FXDEFMAP(GNEDemandElementDialog) GNEDemandElementDialogMap[] = {
36  FXMAPFUNC(SEL_KEYPRESS, 0, GNEDemandElementDialog::onKeyPress),
37  FXMAPFUNC(SEL_KEYRELEASE, 0, GNEDemandElementDialog::onKeyRelease),
38  FXMAPFUNC(SEL_CLOSE, 0, GNEDemandElementDialog::onCmdCancel),
42 };
43 
44 // Object abstract implementation
45 FXIMPLEMENT_ABSTRACT(GNEDemandElementDialog, FXTopWindow, GNEDemandElementDialogMap, ARRAYNUMBER(GNEDemandElementDialogMap))
46 
47 // ===========================================================================
48 // member method definitions
49 // ===========================================================================
50 
51 GNEDemandElementDialog::GNEDemandElementDialog(GNEDemandElement* editedDemandElement, bool updatingElement, int width, int height) :
52  FXTopWindow(editedDemandElement->getViewNet(), ("Edit '" + editedDemandElement->getID() + "' data").c_str(), editedDemandElement->getIcon(), editedDemandElement->getIcon(), GUIDesignDialogBoxExplicit(width, height)),
53  myEditedDemandElement(editedDemandElement),
54  myUpdatingElement(updatingElement),
55  myChangesDescription("change " + editedDemandElement->getTagStr() + " values"),
56  myNumberOfChanges(0) {
57  // create main frame
58  FXVerticalFrame* mainFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);
59  // Create frame for contents
60  myContentFrame = new FXVerticalFrame(mainFrame, GUIDesignContentsFrame);
61  // create buttons centered
62  FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(mainFrame, GUIDesignHorizontalFrame);
63  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
64  myAcceptButton = new FXButton(buttonsFrame, "accept\t\tclose accepting changes", GUIIconSubSys::getIcon(ICON_ACCEPT), this, MID_GNE_ADDITIONALDIALOG_BUTTONACCEPT, GUIDesignButtonAccept);
65  myCancelButton = new FXButton(buttonsFrame, "cancel\t\tclose discarding changes", GUIIconSubSys::getIcon(ICON_CANCEL), this, MID_GNE_ADDITIONALDIALOG_BUTTONCANCEL, GUIDesignButtonCancel);
66  myResetButton = new FXButton(buttonsFrame, "reset\t\treset to previous values", GUIIconSubSys::getIcon(ICON_RESET), this, MID_GNE_ADDITIONALDIALOG_BUTTONRESET, GUIDesignButtonReset);
67  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
68 }
69 
70 
72  // return focus to GNEViewNet to avoid minimization
73  getParent()->setFocus();
74 }
75 
76 
77 FXint
79  // create Dialog
80  create();
81  // show in the given position
82  show(placement);
83  // refresh APP
84  getApp()->refresh();
85  // open as modal dialog (will block all windows until stop() or stopModal() is called)
86  return getApp()->runModalFor(this);
87 }
88 
89 
92  return myEditedDemandElement;
93 }
94 
95 
96 long
97 GNEDemandElementDialog::onKeyPress(FXObject* sender, FXSelector sel, void* ptr) {
98  return FXTopWindow::onKeyPress(sender, sel, ptr);
99 }
100 
101 
102 long
103 GNEDemandElementDialog::onKeyRelease(FXObject* sender, FXSelector sel, void* ptr) {
104  return FXTopWindow::onKeyRelease(sender, sel, ptr);
105 }
106 
107 
108 void
110  // change FXDialogBox title
111  setTitle(newHeader.c_str());
112 }
113 
114 
115 void
117  // init commandGroup
119  // save number of command group changes
121 }
122 
123 
124 void
126  // commit changes or abort last command group depending of number of changes did
127  if (myNumberOfChanges < myEditedDemandElement->getViewNet()->getUndoList()->currentCommandGroupSize()) {
129  } else {
131  }
132 }
133 
134 
135 void
138 }
139 
140 
141 void
143  // abort last command group an start editing again
146 }
147 
148 /****************************************************************************/
#define GUIDesignHorizontalFrame
Definition: GUIDesigns.h:240
void acceptChanges()
Accept changes did in this dialog.
virtual long onCmdAccept(FXObject *sender, FXSelector sel, void *ptr)=0
int myNumberOfChanges
number of GNEChanges_... in dialog
void cancelChanges()
Cancel changes did in this dialog.
#define GUIDesignContentsFrame
design for the main content frame of every frame/dialog
Definition: GUIDesigns.h:298
GNEDemandElement * myEditedDemandElement
pointer to edited aditional
#define GUIDesignButtonCancel
Cancel Button.
Definition: GUIDesigns.h:120
long onKeyPress(FXObject *sender, FXSelector sel, void *ptr)
event after press a key
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:73
void initChanges()
init a new group of changes that will be do it in dialog
FXDEFMAP(GNEDemandElementDialog) GNEDemandElementDialogMap[]
void changeDemandElementDialogHeader(const std::string &newHeader)
change additional dialog header
virtual long onCmdCancel(FXObject *sender, FXSelector sel, void *ptr)=0
event after press cancel button
void resetChanges()
reset changes did in this dialog.
GNEUndoList * getUndoList() const
get the undoList object
Definition: GNEViewNet.cpp:933
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frames used to pack another frames extended in all directions ...
Definition: GUIDesigns.h:286
#define GUIDesignDialogBoxExplicit(width, height)
design for dialog box with specift width and height (for example, additional dialogs) ...
Definition: GUIDesigns.h:461
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:80
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames ...
Definition: GUIDesigns.h:289
#define GUIDesignButtonReset
Reset Button.
Definition: GUIDesigns.h:123
int currentCommandGroupSize() const
get size of current CommandGroup
void p_abortLastCommandGroup()
reverts last command group
#define GUIDesignButtonAccept
Accept Button.
Definition: GUIDesigns.h:117
GNEDemandElement * getEditedDemandElement() const
get edited DemandElement
long onKeyRelease(FXObject *sender, FXSelector sel, void *ptr)
event after release a key
virtual long onCmdReset(FXObject *, FXSelector, void *)=0
event after press cancel button
Dialog to edit sequences, parameters, etc.. of DemandElements.
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which demand element element is located.
std::string myChangesDescription
description of changes did in this additional dialog
FXint openAsModalDialog(FXuint placement=PLACEMENT_CURSOR)
execute dialog as modal
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
An Element which don&#39;t belongs to GNENet but has influency in the simulation.