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-2018 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 
23 #include <iostream>
28 #include <netedit/GNEViewNet.h>
29 #include <netedit/GNEUndoList.h>
30 
31 #include "GNEAdditionalDialog.h"
32 
33 // ===========================================================================
34 // FOX callback mapping
35 // ===========================================================================
36 
37 FXDEFMAP(GNEAdditionalDialog) GNEAdditionalDialogMap[] = {
38  FXMAPFUNC(SEL_KEYPRESS, 0, GNEAdditionalDialog::onKeyPress),
39  FXMAPFUNC(SEL_KEYRELEASE, 0, GNEAdditionalDialog::onKeyRelease),
40  FXMAPFUNC(SEL_CLOSE, 0, GNEAdditionalDialog::onCmdCancel),
44 };
45 
46 // Object abstract implementation
47 FXIMPLEMENT_ABSTRACT(GNEAdditionalDialog, FXTopWindow, GNEAdditionalDialogMap, ARRAYNUMBER(GNEAdditionalDialogMap))
48 
49 // ===========================================================================
50 // member method definitions
51 // ===========================================================================
52 
53 GNEAdditionalDialog::GNEAdditionalDialog(GNEAdditional* editedAdditional, bool updatingElement, int width, int height) :
54  FXTopWindow(editedAdditional->getViewNet(), ("Edit '" + editedAdditional->getID() + "' data").c_str(), editedAdditional->getIcon(), editedAdditional->getIcon(), GUIDesignDialogBoxExplicit, 0, 0, width, height, 0, 0, 0, 0, 4, 4),
55  myEditedAdditional(editedAdditional),
56  myUpdatingElement(updatingElement),
57  myChangesDescription("change " + editedAdditional->getTagStr() + " values"),
58  myNumberOfChanges(0) {
59  // create main frame
60  FXVerticalFrame* mainFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);
61  // Create frame for contents
62  myContentFrame = new FXVerticalFrame(mainFrame, GUIDesignContentsFrame);
63  // create buttons centered
64  FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(mainFrame, GUIDesignHorizontalFrame);
65  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
66  myAcceptButton = new FXButton(buttonsFrame, "accept\t\tclose accepting changes", GUIIconSubSys::getIcon(ICON_ACCEPT), this, MID_GNE_ADDITIONALDIALOG_BUTTONACCEPT, GUIDesignButtonAccept);
67  myCancelButton = new FXButton(buttonsFrame, "cancel\t\tclose discarding changes", GUIIconSubSys::getIcon(ICON_CANCEL), this, MID_GNE_ADDITIONALDIALOG_BUTTONCANCEL, GUIDesignButtonCancel);
68  myResetButton = new FXButton(buttonsFrame, "reset\t\treset to previous values", GUIIconSubSys::getIcon(ICON_RESET), this, MID_GNE_ADDITIONALDIALOG_BUTTONRESET, GUIDesignButtonReset);
69  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
70 }
71 
72 
74  // return focus to GNEViewNet to avoid minimization
75  getParent()->setFocus();
76 }
77 
78 
79 FXint
81  // create Dialog
82  create();
83  // show in the given position
84  show(placement);
85  // refresh APP
86  getApp()->refresh();
87  // open as modal dialog (will block all windows until stop() or stopModal() is called)
88  return getApp()->runModalFor(this);
89 }
90 
91 
94  return myEditedAdditional;
95 }
96 
97 
98 long
99 GNEAdditionalDialog::onKeyPress(FXObject* sender, FXSelector sel, void* ptr) {
100  return FXTopWindow::onKeyPress(sender, sel, ptr);
101 }
102 
103 
104 long
105 GNEAdditionalDialog::onKeyRelease(FXObject* sender, FXSelector sel, void* ptr) {
106  return FXTopWindow::onKeyRelease(sender, sel, ptr);
107 }
108 
109 
110 void
112  // change FXDialogBox title
113  setTitle(newHeader.c_str());
114 }
115 
116 
117 void
119  // init commandGroup
121  // save number of command group changes
123 }
124 
125 
126 void
128  // commit changes or abort last command group depending of number of changes did
129  if (myNumberOfChanges < myEditedAdditional->getViewNet()->getUndoList()->currentCommandGroupSize()) {
131  } else {
133  }
134 }
135 
136 
137 void
140 }
141 
142 
143 void
145  // abort last command group an start editing again
148 }
149 
150 /****************************************************************************/
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:212
~GNEAdditionalDialog()
destructor
#define GUIDesignContentsFrame
design for the main content frame of every frame/dialog
Definition: GUIDesigns.h:270
Dialog to edit sequences, parameters, etc.. of Additionals.
#define GUIDesignButtonCancel
Cancel Button.
Definition: GUIDesigns.h:102
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
GNEUndoList * getUndoList() const
get the undoList object
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frames used to pack another frames extended in all directions ...
Definition: GUIDesigns.h:258
FXDEFMAP(GNEAdditionalDialog) GNEAdditionalDialogMap[]
#define GUIDesignDialogBoxExplicit
design for dialog box with specift width and height (for example, additional dialogs) ...
Definition: GUIDesigns.h:422
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:80
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames ...
Definition: GUIDesigns.h:261
#define GUIDesignButtonReset
Reset Button.
Definition: GUIDesigns.h:105
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:99
GNEAdditional * myEditedAdditional
pointer to edited aditional
void acceptChanges()
Accept changes did in this dialog.
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
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:48
long onKeyPress(FXObject *sender, FXSelector sel, void *ptr)
event after press a key
void cancelChanges()
Cancel changes did in this dialog.
GNEAdditional * getEditedAdditional() const
get edited Additional
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