SUMO - Simulation of Urban MObility
GNEDialog_FixAdditionalPositions.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // Dialog used to fix invalid stopping places
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>
34 #include <utils/common/ToString.h>
37 
39 #include "GNEAdditional.h"
40 #include "GNEStoppingPlace.h"
41 #include "GNELane.h"
42 #include "GNEViewNet.h"
43 #include "GNEUndoList.h"
44 #include "GNEChange_Selection.h"
45 #include "GNEChange_Attribute.h"
46 #include "GNEAdditionalHandler.h"
47 #include "GNEDetectorE2.h"
48 
49 // ===========================================================================
50 // FOX callback mapping
51 // ===========================================================================
52 
53 FXDEFMAP(GNEDialog_FixAdditionalPositions) GNEDialog_FixAdditionalPositionsMap[] = {
57 };
58 
59 // Object implementation
60 FXIMPLEMENT(GNEDialog_FixAdditionalPositions, FXDialogBox, GNEDialog_FixAdditionalPositionsMap, ARRAYNUMBER(GNEDialog_FixAdditionalPositionsMap))
61 
62 // ===========================================================================
63 // member method definitions
64 // ===========================================================================
65 
66 GNEDialog_FixAdditionalPositions::GNEDialog_FixAdditionalPositions(GNEViewNet* viewNet, const std::vector<GNEStoppingPlace*>& invalidStoppingPlaces, const std::vector<GNEDetector*>& invalidDetectors) :
67  FXDialogBox(viewNet->getApp(), ("Fix stoppingPlaces positions"), GUIDesignDialogBoxExplicit, 0, 0, 458, 300, 0, 0, 0, 0),
68  myViewNet(viewNet),
69  myInvalidStoppingPlaces(invalidStoppingPlaces),
70  myInvalidDetectors(invalidDetectors) {
71  // set busStop icon for this dialog
73  // create main frame
74  FXVerticalFrame* mainFrame = new FXVerticalFrame(this, GUIDesignAuxiliarFrame);
75  // create label for table
76  new FXLabel(mainFrame, "List of Stopping places and E2 detectors with conflicts", 0, GUIDesignLabelCenterThick);
77  // Create table, copy intervals and update table
78  myTable = new FXTable(mainFrame, this, MID_GNE_FIXSTOPPINGPLACES_CHANGE, GUIDesignTableAdditionals);
79  myTable->setSelBackColor(FXRGBA(255, 255, 255, 255));
80  myTable->setSelTextColor(FXRGBA(0, 0, 0, 255));
81  myTable->setEditable(false);
82  // clear table
83  myTable->clearItems();
84  // set number of rows
85  myTable->setTableSize(int(myInvalidStoppingPlaces.size() + myInvalidDetectors.size()), 3);
86  // Configure list
87  myTable->setVisibleColumns(4);
88  myTable->setColumnWidth(0, GUIDesignTableIconCellWidth);
89  myTable->setColumnWidth(1, 160);
90  myTable->setColumnWidth(2, 260);
91  myTable->setColumnText(0, "");
92  myTable->setColumnText(1, toString(SUMO_ATTR_ID).c_str());
93  myTable->setColumnText(2, "Conflict");
94  myTable->getRowHeader()->setWidth(0);
95  // Declare index for rows and pointer to FXTableItem
96  int indexRow = 0;
97  FXTableItem* item = 0;
98  // iterate over stopping places
99  for (auto i : myInvalidStoppingPlaces) {
100  // Set icon
101  item = new FXTableItem("", i->getIcon());
102  item->setIconPosition(FXTableItem::CENTER_X);
103  myTable->setItem(indexRow, 0, item);
104  // Set ID
105  item = new FXTableItem(i->getID().c_str());
106  item->setJustify(FXTableItem::LEFT | FXTableItem::CENTER_Y);
107  myTable->setItem(indexRow, 1, item);
108  // Set conflict
109  std::string errorStartPosition, errorEndPosition, separator;
110  // check start position
111  if (i->getAbsoluteStartPosition() < 0) {
112  errorStartPosition = (toString(SUMO_ATTR_STARTPOS) + " < 0");
113  }
114  // check end position
115  if (i->getAbsoluteEndPosition() > i->getLane()->getLaneParametricLength()) {
116  errorEndPosition = (toString(SUMO_ATTR_ENDPOS) + " > lanes's length");
117  }
118  // check separator
119  if ((errorStartPosition.size() > 0) && (errorEndPosition.size() > 0)) {
120  separator = " and ";
121  }
122  item = new FXTableItem((errorStartPosition + separator + errorEndPosition).c_str());
123  item->setJustify(FXTableItem::LEFT | FXTableItem::CENTER_Y);
124  myTable->setItem(indexRow, 2, item);
125  // Update index
126  indexRow++;
127  }
128  // iterate over detectors
129  for (auto i : myInvalidDetectors) {
130  // Set icon
131  item = new FXTableItem("", i->getIcon());
132  item->setIconPosition(FXTableItem::CENTER_X);
133  myTable->setItem(indexRow, 0, item);
134  // Set ID
135  item = new FXTableItem(i->getID().c_str());
136  item->setJustify(FXTableItem::LEFT | FXTableItem::CENTER_Y);
137  myTable->setItem(indexRow, 1, item);
138  // Set conflict
139  std::string errorPosition, errorLenght, separator;
140  // check position over lane
141  if (i->getAbsolutePositionOverLane() < 0) {
142  errorPosition = (toString(SUMO_ATTR_POSITION) + " < 0");
143  } else if (i->getAbsolutePositionOverLane() > i->getLane()->getLaneParametricLength()) {
144  errorPosition = (toString(SUMO_ATTR_POSITION) + " > lanes's length");
145  }
146  GNEDetectorE2* E2Detector = dynamic_cast<GNEDetectorE2*>(i);
147  if ((E2Detector != NULL) && ((E2Detector->getAbsolutePositionOverLane() + E2Detector->getAbsoluteLenght()) > i->getLane()->getLaneParametricLength())) {
148  errorLenght = (toString(SUMO_ATTR_LENGTH) + " > lanes's length");
149  }
150 
151  // check separator
152  if ((errorPosition.size() > 0) && (errorLenght.size() > 0)) {
153  separator = " and ";
154  }
155  item = new FXTableItem((errorPosition + separator + errorLenght).c_str());
156  item->setJustify(FXTableItem::LEFT | FXTableItem::CENTER_Y);
157  myTable->setItem(indexRow, 2, item);
158  // Update index
159  indexRow++;
160  }
161  // create label for elements
162  new FXLabel(mainFrame, "Select a solution:", 0, GUIDesignLabelCenterThick);
163  // create horizontal frames for radio buttons
164  FXHorizontalFrame* RadioButtons = new FXHorizontalFrame(mainFrame, GUIDesignHorizontalFrame);
165  // create Vertical Frame for left options
166  FXVerticalFrame* RadioButtonsLeft = new FXVerticalFrame(RadioButtons, GUIDesignAuxiliarVerticalFrame);
167  myOptionA = new FXRadioButton(RadioButtonsLeft, "Activate friendlyPos and save\t\tFriendly pos parameter will be activated in all stopping places and E2 detectors",
169  myOptionC = new FXRadioButton(RadioButtonsLeft, "Save invalid positions\t\tSave stopping places and E2 detectors with invalid positions",
171  // create Vertical Frame for right options
172  FXVerticalFrame* RadioButtonsRight = new FXVerticalFrame(RadioButtons, GUIDesignAuxiliarVerticalFrame);
173  myOptionB = new FXRadioButton(RadioButtonsRight, "Fix positions and save\t\tPosition of stopping places and E2 detectors will be fixed",
175  myOptionD = new FXRadioButton(RadioButtonsRight, "Select invalid additionals\t\tCancel saving of additionals and select invalid stopping places and E2 detectors",
177  // leave option a as default
178  myOptionA->setCheck(true);
179  // create dialog buttons bot centered
180  FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(mainFrame, GUIDesignHorizontalFrame);
181  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
182  myAcceptButton = new FXButton(buttonsFrame, FXWindow::tr("&Accept"), GUIIconSubSys::getIcon(ICON_ACCEPT), this, MID_GNE_MODE_ADDITIONALDIALOG_ACCEPT, GUIDesignButtonAccept);
183  myCancelButton = new FXButton(buttonsFrame, FXWindow::tr("&Cancel"), GUIIconSubSys::getIcon(ICON_CANCEL), this, MID_GNE_MODE_ADDITIONALDIALOG_CANCEL, GUIDesignButtonCancel);
184  new FXHorizontalFrame(buttonsFrame, GUIDesignAuxiliarHorizontalFrame);
185  // set focus in accept button
186  myAcceptButton->setFocus();
187 }
188 
189 
191 }
192 
193 
194 long
195 GNEDialog_FixAdditionalPositions::onCmdSelectOption(FXObject* obj, FXSelector, void*) {
196  if (obj == myOptionA) {
197  myOptionA->setCheck(true);
198  myOptionB->setCheck(false);
199  myOptionC->setCheck(false);
200  myOptionD->setCheck(false);
201  return 1;
202  } else if (obj == myOptionB) {
203  myOptionA->setCheck(false);
204  myOptionB->setCheck(true);
205  myOptionC->setCheck(false);
206  myOptionD->setCheck(false);
207  return 1;
208  } else if (obj == myOptionC) {
209  myOptionA->setCheck(false);
210  myOptionB->setCheck(false);
211  myOptionC->setCheck(true);
212  myOptionD->setCheck(false);
213  return 1;
214  } else if (obj == myOptionD) {
215  myOptionA->setCheck(false);
216  myOptionB->setCheck(false);
217  myOptionC->setCheck(false);
218  myOptionD->setCheck(true);
219  return 1;
220  } else {
221  return 0;
222  }
223 }
224 
225 
226 long
227 GNEDialog_FixAdditionalPositions::onCmdAccept(FXObject*, FXSelector, void*) {
228  if (myOptionA->getCheck() == TRUE) {
229  myViewNet->getUndoList()->p_begin(toString(SUMO_ATTR_FRIENDLY_POS) + " of invalid additionals");
230  // iterate over invalid stopping places to enable friendly position
231  for (auto i = myInvalidStoppingPlaces.begin(); i != myInvalidStoppingPlaces.end(); i++) {
232  (*i)->setAttribute(SUMO_ATTR_FRIENDLY_POS, "true", myViewNet->getUndoList());
233  }
234  // iterate over invalid detectors to enable friendly position
235  for (auto i = myInvalidDetectors.begin(); i != myInvalidDetectors.end(); i++) {
236  (*i)->setAttribute(SUMO_ATTR_FRIENDLY_POS, "true", myViewNet->getUndoList());
237  }
239  // stop modal with TRUE (continue saving)
240  getApp()->stopModal(this, TRUE);
241  return 1;
242  } else if (myOptionB->getCheck() == TRUE) {
243  myViewNet->getUndoList()->p_begin("Fixed positions of invalid additionals");
244  // iterate over invalid stopping places to fix positions
245  for (auto i = myInvalidStoppingPlaces.begin(); i != myInvalidStoppingPlaces.end(); i++) {
246  GNEStoppingPlace* stoppingPlace = dynamic_cast<GNEStoppingPlace*>(*i);
247  if (stoppingPlace != NULL) {
248  // obtain start and end position
249  double startPos = GNEAttributeCarrier::parse<double>(stoppingPlace->getAttribute(SUMO_ATTR_STARTPOS));
250  double endPos = GNEAttributeCarrier::parse<double>(stoppingPlace->getAttribute(SUMO_ATTR_ENDPOS));
251  // fix start and end positions using fixStoppinPlacePosition
253  // set new start and end positions
254  stoppingPlace->setAttribute(SUMO_ATTR_STARTPOS, toString(startPos), myViewNet->getUndoList());
255  stoppingPlace->setAttribute(SUMO_ATTR_ENDPOS, toString(endPos), myViewNet->getUndoList());
256  }
257  }
258  // iterate over invalid detectors
259  for (auto i = myInvalidDetectors.begin(); i != myInvalidDetectors.end(); i++) {
260  GNEDetectorE2* E2Detector = dynamic_cast<GNEDetectorE2*>(*i);
261  // Check if we're handling a E2 detector o a E1/Entry/Exit
262  if (E2Detector != NULL) {
263  // obtain position and lenght
264  double pos = GNEAttributeCarrier::parse<double>(E2Detector->getAttribute(SUMO_ATTR_POSITION));
265  double length = GNEAttributeCarrier::parse<double>(E2Detector->getAttribute(SUMO_ATTR_LENGTH));
266  // fix pos and lenght using fixE2DetectorPositionPosition
268  // set new position and length
270  E2Detector->setAttribute(SUMO_ATTR_LENGTH, toString(length), myViewNet->getUndoList());
271  } else {
272  // obtain position
273  double pos = GNEAttributeCarrier::parse<double>(E2Detector->getAttribute(SUMO_ATTR_POSITION));
274  // fix pos and lenght checkAndFixDetectorPositionPosition
276  // set new position
278  }
279  }
281  // stop modal with TRUE (continue saving)
282  getApp()->stopModal(this, TRUE);
283  return 1;
284  } else if (myOptionC->getCheck() == TRUE) {
285  // simply stop modal with TRUE to save additionals with invalid positions
286  getApp()->stopModal(this, TRUE);
287  return 1;
288  } else if (myOptionD->getCheck() == TRUE) {
289  std::set<GUIGlID> GLIDsToSelect;
290  myViewNet->getUndoList()->p_begin("select invalid additionals");
291  // clear previous selection
292  myViewNet->getUndoList()->add(new GNEChange_Selection(myViewNet->getNet(), std::set<GUIGlID>(), gSelected.getSelected(), true), true);
293  // iterate over invalid stopping places to select it
294  for (auto i = myInvalidStoppingPlaces.begin(); i != myInvalidStoppingPlaces.end(); i++) {
295  GLIDsToSelect.insert((*i)->getGlID());
296  }
297  // iterate over invalid detectors to enable to select it
298  for (auto i = myInvalidDetectors.begin(); i != myInvalidDetectors.end(); i++) {
299  GLIDsToSelect.insert((*i)->getGlID());
300  }
301  myViewNet->getUndoList()->add(new GNEChange_Selection(myViewNet->getNet(), GLIDsToSelect, std::set<GUIGlID>(), true), true);
303  myViewNet->update();
304  // stop modal with FALSE (abort saving)
305  getApp()->stopModal(this, FALSE);
306  return 0;
307  } else {
308  // stop modal with FALSE (abort saving)
309  getApp()->stopModal(this, FALSE);
310  return 0;
311  }
312 }
313 
314 
315 long
316 GNEDialog_FixAdditionalPositions::onCmdCancel(FXObject*, FXSelector, void*) {
317  // Stop Modal (abort saving)
318  getApp()->stopModal(this, FALSE);
319  return 1;
320 }
321 
322 /****************************************************************************/
#define GUIDesignTableIconCellWidth
width of cells that only contains an Icon
Definition: GUIDesigns.h:412
#define GUIDesignHorizontalFrame
Definition: GUIDesigns.h:204
FXRadioButton * myOptionD
Option "Select invalid stops and cancel".
FXRadioButton * myOptionA
Option "Activate friendlyPos and save".
long onCmdAccept(FXObject *, FXSelector, void *)
event after press accept button
std::string getAttribute(SumoXMLAttr key) const
This functions has to be implemented in allGNEAttributeCarrier.
static bool checkAndFixDetectorPositionPosition(double &pos, const double laneLength, const bool friendlyPos)
check if the position of a detector over a lane is valid
#define GUIDesignButtonCancel
Cancel Button.
Definition: GUIDesigns.h:104
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
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:85
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
method for setting the attribute and letting the object perform additional changes ...
FXRadioButton * myOptionC
Option "Save invalid".
std::vector< GNEStoppingPlace * > myInvalidStoppingPlaces
vector with the invalid stoppingplaces
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:241
const std::set< GUIGlID > & getSelected() const
Returns the set of ids of all selected objects.
#define GUIDesignDialogBoxExplicit
design for dialog box with specift width and height (for example, additional dialogs) ...
Definition: GUIDesigns.h:396
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
GNELane * getLane() const
get lane of additional, or NULL if additional isn&#39;t placed over a Lane
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:92
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames ...
Definition: GUIDesigns.h:244
#define POSITION_EPS
Definition: config.h:176
double getAbsolutePositionOverLane() const
get absolute position over Lane
#define GUIDesignTableAdditionals
design for tables used in additional dialogs
Definition: GUIDesigns.h:409
#define GUIDesignAuxiliarVerticalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames ...
Definition: GUIDesigns.h:247
#define GUIDesignButtonAccept
Accept Button.
Definition: GUIDesigns.h:101
#define GUIDesignLabelCenterThick
label extended over frame with thick and with text justify to center
Definition: GUIDesigns.h:162
static bool fixE2DetectorPositionPosition(double &pos, double &length, const double laneLength, const bool friendlyPos)
check if the position of a detector over a lane is valid
FXRadioButton * myOptionB
Option "Fix Positions and save".
GNENet * getNet() const
get the net object
FXDEFMAP(GNEDialog_FixAdditionalPositions) GNEDialog_FixAdditionalPositionsMap[]
FixStoppingPlaces dialog.
Definition: GUIAppEnum.h:521
virtual std::string getAttribute(SumoXMLAttr key) const =0
This functions has to be implemented in allGNEAttributeCarrier.
std::vector< GNEDetector * > myInvalidDetectors
vector with the invalid stoppingplaces
long onCmdCancel(FXObject *, FXSelector, void *)
event after press cancel button
static bool fixStoppinPlacePosition(double &startPos, double &endPos, const double laneLength, const double minLength, const bool friendlyPos)
check if the position of an stoppingPlace over a lane is valid
#define GUIDesignRadioButton
Definition: GUIDesigns.h:134
double getLaneParametricLength() const
returns the parameteric length of the lane
Definition: GNELane.cpp:719
double getAbsoluteLenght() const
get absolute lenght
GUISelectedStorage gSelected
A global holder of selected objects.
long onCmdSelectOption(FXObject *obj, FXSelector, void *)
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
set type of selection
Definition: GUIAppEnum.h:343