SUMO - Simulation of Urban MObility
GNECalibratorRouteDialog.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software; you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation; either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
30 #include <iostream>
35 
37 #include "GNECalibratorDialog.h"
38 #include "GNECalibrator.h"
39 #include "GNEEdge.h"
40 #include "GNELane.h"
41 #include "GNEViewNet.h"
42 #include "GNENet.h"
43 
44 
45 // ===========================================================================
46 // FOX callback mapping
47 // ===========================================================================
48 
49 FXDEFMAP(GNECalibratorRouteDialog) GNECalibratorRouteDialogMap[] = {
54 };
55 
56 // Object implementation
57 FXIMPLEMENT(GNECalibratorRouteDialog, FXDialogBox, GNECalibratorRouteDialogMap, ARRAYNUMBER(GNECalibratorRouteDialogMap))
58 
59 // ===========================================================================
60 // member method definitions
61 // ===========================================================================
62 
63 GNECalibratorRouteDialog::GNECalibratorRouteDialog(GNECalibratorDialog* calibratorDialog, GNECalibratorRoute& calibratorRoute, bool updatingElement) :
64  GNEAdditionalDialog(calibratorRoute.getCalibratorParent(), 400, 300),
65  myCalibratorDialogParent(calibratorDialog),
66  myCalibratorRoute(&calibratorRoute),
67  myUpdatingElement(updatingElement),
68  myCalibratorRouteValid(true) {
69  // change default header
70  changeAdditionalDialogHeader("Edit " + toString(calibratorRoute.getTag()) + " of " + toString(calibratorRoute.getCalibratorParent()->getTag()) +
71  " '" + calibratorRoute.getCalibratorParent()->getID() + "'");
72 
73  // Create auxiliar frames for data
74  FXHorizontalFrame* columns = new FXHorizontalFrame(myContentFrame, GUIDesignUniformHorizontalFrame);
75  FXVerticalFrame* columnLeft = new FXVerticalFrame(columns, GUIDesignAuxiliarFrame);
76  FXVerticalFrame* columnRight = new FXVerticalFrame(columns, GUIDesignAuxiliarFrame);
77 
78  // create ID's elements
79  new FXLabel(columnLeft, toString(SUMO_ATTR_ID).c_str(), 0, GUIDesignLabelLeftThick);
80  myTextFieldRouteID = new FXTextField(columnRight, GUIDesignTextFieldNCol, this, MID_GNE_CALIBRATORDIALOG_SET_VARIABLE, GUIDesignTextField);
81 
82  // create list of edge's elements
83  new FXLabel(columnLeft, toString(SUMO_ATTR_EDGES).c_str(), 0, GUIDesignLabelLeftThick);
84  myTextFieldEdges = new FXTextField(columnRight, GUIDesignTextFieldNCol, this, MID_GNE_CALIBRATORDIALOG_SET_VARIABLE, GUIDesignTextField);
85 
86  // create color's elements
87  new FXLabel(columnLeft, toString(SUMO_ATTR_COLOR).c_str(), 0, GUIDesignLabelLeftThick);
88  myTextFieldColor = new FXTextField(columnRight, GUIDesignTextFieldNCol, this, MID_GNE_CALIBRATORDIALOG_SET_VARIABLE, GUIDesignTextField);
89 
90  // create Edges of net's elements
91  new FXLabel(columnLeft, (toString(SUMO_TAG_EDGE) + "s of " + toString(SUMO_TAG_NET)).c_str(), 0, GUIDesignLabelLeftThick);
92  myListOfEdgesOfNet = new FXList(columnLeft, this, MID_GNE_CALIBRATORDIALOG_SET_VARIABLE, GUIDesignListExtended);
93 
94  // create Edges of route's elements
95  new FXLabel(columnRight, ("current " + toString(SUMO_TAG_EDGE) + "s of " + toString(SUMO_TAG_ROUTE)).c_str(), 0, GUIDesignLabelLeftThick);
96  myListOfEdgesOfRoute = new FXList(columnRight, this, MID_GNE_CALIBRATORDIALOG_SET_VARIABLE, GUIDesignListExtended);
97 
98  // fill list of net's edges
99  std::vector<GNEEdge*> edgesOfNet = calibratorRoute.getCalibratorParent()->getViewNet()->getNet()->retrieveEdges();
100  for (std::vector<GNEEdge*>::iterator i = edgesOfNet.begin(); i != edgesOfNet.end(); i++) {
101  myListOfEdgesOfNet->appendItem((*i)->getID().c_str());
102  }
103 
104  // create copy of GNECalibratorRoute
105  myCopyOfCalibratorRoute = new GNECalibratorRoute(myCalibratorRoute->getCalibratorParent());
106 
107  // copy all values of myCalibratorRoute into myCopyOfCalibratorRoute to set initial values
108  (*myCopyOfCalibratorRoute) = (*myCalibratorRoute);
109 
110  // update tables
111  updateCalibratorRouteValues();
112 }
113 
114 
116  // delete copy
118 }
119 
120 
121 long
122 GNECalibratorRouteDialog::onCmdAccept(FXObject*, FXSelector, void*) {
123  if (myCalibratorRouteValid == false) {
124  // write warning if netedit is running in testing mode
126  WRITE_WARNING("Opening FXMessageBox of type 'warning'");
127  }
128  FXMessageBox::warning(getApp(), MBOX_OK,
129  ("Error " + std::string((myUpdatingElement == true) ? ("updating") : ("creating")) + " " + toString(myCalibratorRoute->getCalibratorParent()->getTag()) +
130  "'s " + toString(myCalibratorRoute->getTag())).c_str(), "%s",
132  " cannot be " + std::string((myUpdatingElement == true) ? ("updated") : ("created")) + " because parameter " + toString(myInvalidAttr) +
133  " is invalid.").c_str());
134  // write warning if netedit is running in testing mode
136  WRITE_WARNING("Closed FXMessageBox of type 'warning' with 'OK'");
137  }
138  return 0;
139  } else {
140  // copy all values of myCopyOfCalibratorRoute into myCalibratorRoute
141  (*myCalibratorRoute) = (*myCopyOfCalibratorRoute);
142  getApp()->stopModal(this, TRUE);
143  return 1;
144  }
145 }
146 
147 
148 long
149 GNECalibratorRouteDialog::onCmdCancel(FXObject*, FXSelector, void*) {
150  // Stop Modal
151  getApp()->stopModal(this, FALSE);
152  return 1;
153 }
154 
155 
156 long
157 GNECalibratorRouteDialog::onCmdReset(FXObject*, FXSelector, void*) {
158  // copy all values of myCalibratorRoute into myCopyOfCalibratorRoute to set initial values
159  (*myCopyOfCalibratorRoute) = (*myCalibratorRoute);
160  // update fields
162  return 1;
163 }
164 
165 
166 long
167 GNECalibratorRouteDialog::onCmdSetVariable(FXObject*, FXSelector, void*) {
168  // At start we assumed, that all values are valid
169  myCalibratorRouteValid = true;
171 
172  // set color of myTextFieldRouteID, depending if current value is valid or not
173  if (myCopyOfCalibratorRoute->getRouteID() == myTextFieldRouteID->getText().text()) {
174  myTextFieldRouteID->setTextColor(FXRGB(0, 0, 0));
175  } else if (myCopyOfCalibratorRoute->setRouteID(myTextFieldRouteID->getText().text()) == true) {
176  myTextFieldRouteID->setTextColor(FXRGB(0, 0, 0));
177  } else {
178  myTextFieldRouteID->setTextColor(FXRGB(255, 0, 0));
179  myCalibratorRouteValid = false;
181  }
182 
183  // set color of myTextFieldRouteEdges, depending if current value is valEdges or not
184  if (myCopyOfCalibratorRoute->setEdges(myTextFieldEdges->getText().text()) == true) {
185  myTextFieldEdges->setTextColor(FXRGB(0, 0, 0));
186  // fill list of router's edges
187  myListOfEdgesOfRoute->clearItems();
188  std::vector<GNEEdge*> edgesOfRouter = myCopyOfCalibratorRoute->getEdges();
189  for (std::vector<GNEEdge*>::iterator i = edgesOfRouter.begin(); i != edgesOfRouter.end(); i++) {
190  myListOfEdgesOfRoute->appendItem((*i)->getID().c_str());
191  }
192  } else {
193  myTextFieldEdges->setTextColor(FXRGB(255, 0, 0));
194  myCalibratorRouteValid = false;
196  }
197 
198  // set color of myTextFieldColor, depending if current value is valid or not
199  if (myCopyOfCalibratorRoute->getColor() == myTextFieldColor->getText().text()) {
200  myTextFieldColor->setTextColor(FXRGB(0, 0, 0));
201  } else if (myCopyOfCalibratorRoute->setColor(myTextFieldColor->getText().text()) == true) {
202  myTextFieldColor->setTextColor(FXRGB(0, 0, 0));
203  } else {
204  myTextFieldColor->setTextColor(FXRGB(255, 0, 0));
205  myCalibratorRouteValid = false;
207  }
208  return 1;
209 }
210 
211 
212 void
217  // fill list of router's edges
218  myListOfEdgesOfRoute->clearItems();
219  std::vector<GNEEdge*> edgesOfRouter = myCopyOfCalibratorRoute->getEdges();
220  for (std::vector<GNEEdge*>::iterator i = edgesOfRouter.begin(); i != edgesOfRouter.end(); i++) {
221  myListOfEdgesOfRoute->appendItem((*i)->getID().c_str());
222  }
223 }
224 
225 /****************************************************************************/
const std::string & getColor() const
get color of route
FXTextField * myTextFieldColor
color of route
bool setEdges(const std::vector< std::string > &edgeIDs)
set edges of route using IDs
root element of a network file
FXList * myListOfEdgesOfRoute
list of edges of route
bool myCalibratorRouteValid
flag to check if current calibrator vehicleType is valid
long onCmdCancel(FXObject *, FXSelector, void *)
event after press cancel button
SumoXMLTag getTag() const
get tag
Dialog to edit sequences, parameters, etc.. of Additionals.
const std::vector< GNEEdge * > & getEdges() const
get edges
GNECalibratorRoute * myCalibratorRoute
pointer to modified rerouter interval
const std::string & getRouteID() const
get route ID
begin/end of the description of a route
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
void updateCalibratorRouteValues()
update data fields
bool isTestingModeEnabled() const
check if netedit is running in testing mode
Definition: GNEViewNet.cpp:405
GNECalibrator * getCalibratorParent() const
get calibrator parent
SumoXMLAttr myInvalidAttr
current sumo attribute invalid
FXTextField * myTextFieldRouteID
route ID
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frames used to pack another frames extended in all directions ...
Definition: GUIDesigns.h:241
std::vector< std::string > getEdgesIDs() const
get IDs of Edges
long onCmdReset(FXObject *, FXSelector, void *)
event after press reset button
#define GUIDesignTextField
Definition: GUIDesigns.h:41
the edges of a route
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
#define GUIDesignUniformHorizontalFrame
design for horizontal frame used to pack another frames with a uniform width
Definition: GUIDesigns.h:250
invalid attribute
begin/end of the description of an edge
bool setRouteID(std::string routeID)
set route ID
bool myUpdatingElement
flag to indicate if flow are being created or modified
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition: GUIDesigns.h:50
Dialog for edit calibrators.
GNEViewNet * getViewNet() const
Returns a pointer to GNEViewNet in which additional element is located.
Dialog for edit rerouter intervals.
GNECalibratorDialog * myCalibratorDialogParent
pointer to GNECalibratorDialog parent
GNECalibratorRoute * myCopyOfCalibratorRoute
pointer in which save modifications of CalibratorRoute
bool setColor(std::string color="")
set color of route
long onCmdAccept(FXObject *, FXSelector, void *)
#define GUIDesignListExtended
design for FXLists
Definition: GUIDesigns.h:422
FXTextField * myTextFieldEdges
list of edges (string)
FXDEFMAP(GNECalibratorRouteDialog) GNECalibratorRouteDialogMap[]
long onCmdSetVariable(FXObject *, FXSelector, void *)
event after change value
A color information.
#define GUIDesignLabelLeftThick
label extended over frame with thick and with text justify to left
Definition: GUIDesigns.h:156
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:228
SumoXMLTag getTag() const
get XML Tag assigned to this object
GNECalibrator * getCalibratorParent() const
get pointer to calibrator parent