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