Eclipse SUMO - Simulation of Urban MObility
GNEAdditionalFrame.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 // The Widget for add additional elements
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
31 #include <netedit/GNENet.h>
32 #include <netedit/GNEViewNet.h>
33 
34 #include "GNEAdditionalFrame.h"
35 
36 
37 // ===========================================================================
38 // FOX callback mapping
39 // ===========================================================================
40 
41 FXDEFMAP(GNEAdditionalFrame::SelectorLaneParents) ConsecutiveLaneSelectorMap[] = {
44 };
45 
46 FXDEFMAP(GNEAdditionalFrame::SelectorEdgeChildren) SelectorParentEdgesMap[] = {
52 };
53 
54 FXDEFMAP(GNEAdditionalFrame::SelectorLaneChildren) SelectorParentLanesMap[] = {
60 };
61 
62 // Object implementation
63 FXIMPLEMENT(GNEAdditionalFrame::SelectorLaneParents, FXGroupBox, ConsecutiveLaneSelectorMap, ARRAYNUMBER(ConsecutiveLaneSelectorMap))
64 FXIMPLEMENT(GNEAdditionalFrame::SelectorEdgeChildren, FXGroupBox, SelectorParentEdgesMap, ARRAYNUMBER(SelectorParentEdgesMap))
65 FXIMPLEMENT(GNEAdditionalFrame::SelectorLaneChildren, FXGroupBox, SelectorParentLanesMap, ARRAYNUMBER(SelectorParentLanesMap))
66 
67 
68 // ---------------------------------------------------------------------------
69 // GNEAdditionalFrame::SelectorLaneParents - methods
70 // ---------------------------------------------------------------------------
71 
73  FXGroupBox(additionalFrameParent->myContentFrame, "Lane Selector", GUIDesignGroupBoxFrame),
74  myAdditionalFrameParent(additionalFrameParent) {
75  // create start and stop buttons
76  myStopSelectingButton = new FXButton(this, "Stop selecting", nullptr, this, MID_GNE_ADDITIONALFRAME_STOPSELECTION, GUIDesignButton);
77  myAbortSelectingButton = new FXButton(this, "Abort selecting", nullptr, this, MID_GNE_ADDITIONALFRAME_ABORTSELECTION, GUIDesignButton);
78  // disable stop and abort functions as init
79  myStopSelectingButton->disable();
80  myAbortSelectingButton->disable();
81  // define colors
82  myCandidateLaneColor = RGBColor(0, 64, 0, 255);
83  mySelectedLaneColor = RGBColor::GREEN;
84 }
85 
86 
88 
89 
90 void
92  // abort current selection before show
94  // show FXGroupBox
95  FXGroupBox::show();
96 }
97 
98 
99 void
101  // abort current selection before hide
103  // hide FXGroupBox
104  FXGroupBox::hide();
105 }
106 
107 
108 void
110  // Only start selection if SelectorLaneParents modul is shown
111  if (shown()) {
112  // change buttons
113  myStopSelectingButton->enable();
114  myAbortSelectingButton->enable();
115  // add lane
116  addSelectedLane(lane, clickedPosition);
117  }
118 }
119 
120 
121 bool
123  // obtain tagproperty (only for improve code legibility)
125  // abort if there isn't at least two lanes
126  if (mySelectedLanes.size() < 2) {
128  // abort consecutive lane selector
130  return false;
131  }
132  // Declare map to keep attributes from Frames from Frame
133  std::map<SumoXMLAttr, std::string> valuesMap = myAdditionalFrameParent->myAdditionalAttributes->getAttributesAndValues(true);
134  // fill valuesOfElement with Netedit attributes from Frame
136  // Generate id of element
137  valuesMap[SUMO_ATTR_ID] = myAdditionalFrameParent->generateID(nullptr);
138  // obtain lane IDs
139  std::vector<std::string> laneIDs;
140  for (auto i : mySelectedLanes) {
141  laneIDs.push_back(i.first->getID());
142  }
143  valuesMap[SUMO_ATTR_LANES] = joinToString(laneIDs, " ");
144  // Obtain clicked position over first lane
145  valuesMap[SUMO_ATTR_POSITION] = toString(mySelectedLanes.front().second);
146  // Obtain clicked position over last lane
147  valuesMap[SUMO_ATTR_ENDPOS] = toString(mySelectedLanes.back().second);
148  // parse common attributes
149  if (!myAdditionalFrameParent->buildAdditionalCommonAttributes(valuesMap, tagValues)) {
150  return false;
151  }
152  // show warning dialogbox and stop check if input parameters are valid
155  return false;
156  } else {
157  // declare SUMOSAXAttributesImpl_Cached to convert valuesMap into SUMOSAXAttributes
158  SUMOSAXAttributesImpl_Cached SUMOSAXAttrs(valuesMap, myAdditionalFrameParent->getPredefinedTagsMML(), toString(tagValues.getTag()));
159  // try to build additional
161  // abort consecutive lane selector
163  return true;
164  } else {
165  return false;
166  }
167  }
168 }
169 
170 
171 void
173  // reset color of all candidate lanes
174  for (auto i : myCandidateLanes) {
175  i->setSpecialColor(nullptr);
176  }
177  // clear candidate colors
178  myCandidateLanes.clear();
179  // reset color of all selected lanes
180  for (auto i : mySelectedLanes) {
181  i.first->setSpecialColor(nullptr);
182  }
183  // clear selected lanes
184  mySelectedLanes.clear();
185  // disable buttons
186  myStopSelectingButton->disable();
187  myAbortSelectingButton->disable();
188  // update view (due colors)
190 }
191 
192 
193 bool
195  // first check that lane exist
196  if (lane == nullptr) {
197  return false;
198  }
199  // check that lane wasn't already selected
200  for (auto i : mySelectedLanes) {
201  if (i.first == lane) {
202  WRITE_WARNING("Duplicated lanes aren't allowed");
203  return false;
204  }
205  }
206  // check that there is candidate lanes
207  if (mySelectedLanes.size() > 0) {
208  if (myCandidateLanes.empty()) {
209  WRITE_WARNING("Only candidate lanes are allowed");
210  return false;
211  } else if ((myCandidateLanes.size() > 0) && (std::find(myCandidateLanes.begin(), myCandidateLanes.end(), lane) == myCandidateLanes.end())) {
212  WRITE_WARNING("Only consecutive lanes are allowed");
213  return false;
214  }
215  }
216  // select lane and save the clicked position
217  mySelectedLanes.push_back(std::make_pair(lane, lane->getGeometry().shape.nearest_offset_to_point2D(clickedPosition) / lane->getLengthGeometryFactor()));
218  // change color of selected lane
220  // restore original color of candidates (except already selected)
221  for (auto i : myCandidateLanes) {
222  if (!isLaneSelected(i)) {
223  i->setSpecialColor(nullptr);
224  }
225  }
226  // clear candidate lanes
227  myCandidateLanes.clear();
228  // fill candidate lanes
229  for (auto i : lane->getParentEdge().getGNEConnections()) {
230  // check that possible candidate lane isn't already selected
231  if ((lane == i->getLaneFrom()) && (!isLaneSelected(i->getLaneTo()))) {
232  // set candidate lane
233  i->getLaneTo()->setSpecialColor(&myCandidateLaneColor);
234  myCandidateLanes.push_back(i->getLaneTo());
235  }
236  }
237  // update view (due colors)
239  return true;
240 }
241 
242 
243 void
245  if (mySelectedLanes.size() > 1) {
246  mySelectedLanes.pop_back();
247  } else {
248  WRITE_WARNING("First lane cannot be removed");
249  }
250 }
251 
252 
253 bool
255  return myStopSelectingButton->isEnabled();
256 }
257 
258 
259 bool
261  return shown();
262 }
263 
264 
265 const RGBColor&
267  return mySelectedLaneColor;
268 }
269 
270 
271 const std::vector<std::pair<GNELane*, double> >&
273  return mySelectedLanes;
274 }
275 
276 
277 long
280  return 0;
281 }
282 
283 
284 long
287  return 0;
288 }
289 
290 
291 bool
293  for (auto i : mySelectedLanes) {
294  if (i.first == lane) {
295  return true;
296  }
297  }
298  return false;
299 }
300 
301 // ---------------------------------------------------------------------------
302 // GNEAdditionalFrame::SelectorEdgeChildren - methods
303 // ---------------------------------------------------------------------------
304 
306  FXGroupBox(additionalFrameParent->myContentFrame, "Edges", GUIDesignGroupBoxFrame),
307  myAdditionalFrameParent(additionalFrameParent) {
308  // Create menuCheck for selected edges
309  myUseSelectedEdgesCheckButton = new FXCheckButton(this, ("Use selected " + toString(SUMO_TAG_EDGE) + "s").c_str(), this, MID_GNE_ADDITIONALFRAME_USESELECTED, GUIDesignCheckButton);
310 
311  // Create search box
313 
314  // Create list
315  myList = new FXList(this, this, MID_GNE_ADDITIONALFRAME_SELECT, GUIDesignListFixedHeight, 0, 0, 0, 100);
316 
317  // Create horizontal frame
318  FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
319 
320  // Create button for clear selection
321  myClearEdgesSelection = new FXButton(buttonsFrame, "Clear", nullptr, this, MID_GNE_ADDITIONALFRAME_CLEARSELECTION, GUIDesignButtonRectangular);
322 
323  // Create button for invert selection
324  myInvertEdgesSelection = new FXButton(buttonsFrame, "Invert", nullptr, this, MID_GNE_ADDITIONALFRAME_INVERTSELECTION, GUIDesignButtonRectangular);
325 
326  // Hide List
328 }
329 
330 
332 
333 
334 std::string
336  std::vector<std::string> vectorOfIds;
337  if (myUseSelectedEdgesCheckButton->getCheck()) {
338  // get Selected edges
339  std::vector<GNEEdge*> selectedEdges = myAdditionalFrameParent->getViewNet()->getNet()->retrieveEdges(true);
340  // Iterate over selectedEdges and getId
341  for (auto i : selectedEdges) {
342  vectorOfIds.push_back(i->getID());
343  }
344  } else {
345  // Obtain Id's of list
346  for (int i = 0; i < myList->getNumItems(); i++) {
347  if (myList->isItemSelected(i)) {
348  vectorOfIds.push_back(myList->getItem(i)->getText().text());
349  }
350  }
351  }
352  return joinToString(vectorOfIds, " ");
353 }
354 
355 
356 void
358  // clear list of egdge ids
359  myList->clearItems();
360  // get all edges of net
362  std::vector<GNEEdge*> vectorOfEdges = myAdditionalFrameParent->getViewNet()->getNet()->retrieveEdges(false);
363  // iterate over edges of net
364  for (auto i : vectorOfEdges) {
365  // If search criterium is correct, then append ittem
366  if (i->getID().find(search) != std::string::npos) {
367  myList->appendItem(i->getID().c_str());
368  }
369  }
370  // By default, CheckBox for useSelectedEdges isn't checked
371  myUseSelectedEdgesCheckButton->setCheck(false);
372  // Recalc Frame
373  recalc();
374  // Update Frame
375  update();
376  // Show dialog
377  show();
378 }
379 
380 
381 void
383  FXGroupBox::hide();
384 }
385 
386 
387 void
389  // Enable or disable use selected edges
390  if (myAdditionalFrameParent->getViewNet()->getNet()->retrieveEdges(true).size() > 0) {
392  } else {
394  }
395 }
396 
397 
398 long
400  if (myUseSelectedEdgesCheckButton->getCheck()) {
401  myEdgesSearch->hide();
402  myList->hide();
403  myClearEdgesSelection->hide();
404  myInvertEdgesSelection->hide();
405  } else {
406  myEdgesSearch->show();
407  myList->show();
408  myClearEdgesSelection->show();
409  myInvertEdgesSelection->show();
410  }
411  // Recalc Frame
412  recalc();
413  // Update Frame
414  update();
415  return 1;
416 }
417 
418 
419 long
421  // Show only Id's of SelectorEdgeChildren that contains the searched string
422  showSelectorEdgeChildrenModul(myEdgesSearch->getText().text());
423  return 1;
424 }
425 
426 
427 long
429  return 1;
430 }
431 
432 
433 long
435  for (int i = 0; i < myList->getNumItems(); i++) {
436  if (myList->getItem(i)->isSelected()) {
437  myList->deselectItem(i);
438  }
439  }
440  return 1;
441 }
442 
443 
444 long
446  for (int i = 0; i < myList->getNumItems(); i++) {
447  if (myList->getItem(i)->isSelected()) {
448  myList->deselectItem(i);
449  } else {
450  myList->selectItem(i);
451  }
452  }
453  return 1;
454 }
455 
456 // ---------------------------------------------------------------------------
457 // GNEAdditionalFrame::SelectorLaneChildren - methods
458 // ---------------------------------------------------------------------------
459 
461  FXGroupBox(additionalFrameParent->myContentFrame, "Lanes", GUIDesignGroupBoxFrame),
462  myAdditionalFrameParent(additionalFrameParent) {
463  // Create CheckBox for selected lanes
464  myUseSelectedLanesCheckButton = new FXCheckButton(this, ("Use selected " + toString(SUMO_TAG_LANE) + "s").c_str(), this, MID_GNE_ADDITIONALFRAME_USESELECTED, GUIDesignCheckButton);
465 
466  // Create search box
468 
469  // Create list
470  myList = new FXList(this, this, MID_GNE_ADDITIONALFRAME_SELECT, GUIDesignListFixedHeight, 0, 0, 0, 100);
471 
472  // Create horizontal frame
473  FXHorizontalFrame* buttonsFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
474 
475  // Create button for clear selection
476  clearLanesSelection = new FXButton(buttonsFrame, "clear", nullptr, this, MID_GNE_ADDITIONALFRAME_CLEARSELECTION, GUIDesignButtonRectangular);
477 
478  // Create button for invert selection
479  invertLanesSelection = new FXButton(buttonsFrame, "invert", nullptr, this, MID_GNE_ADDITIONALFRAME_INVERTSELECTION, GUIDesignButtonRectangular);
480 
481  // Hide List
483 }
484 
485 
487 
488 
489 std::string
491  std::vector<std::string> vectorOfIds;
492  if (myUseSelectedLanesCheckButton->getCheck()) {
493  // get Selected lanes
494  std::vector<GNELane*> selectedLanes = myAdditionalFrameParent->getViewNet()->getNet()->retrieveLanes(true);
495  // Iterate over selectedLanes and getId
496  for (auto i : selectedLanes) {
497  vectorOfIds.push_back(i->getID());
498  }
499  } else {
500  // Obtain Id's of list
501  for (int i = 0; i < myList->getNumItems(); i++) {
502  if (myList->isItemSelected(i)) {
503  vectorOfIds.push_back(myList->getItem(i)->getText().text());
504  }
505  }
506  }
507  return joinToString(vectorOfIds, " ");
508 }
509 
510 
511 void
513  myList->clearItems();
514  std::vector<GNELane*> vectorOfLanes = myAdditionalFrameParent->getViewNet()->getNet()->retrieveLanes(false);
515  for (auto i : vectorOfLanes) {
516  if (i->getID().find(search) != std::string::npos) {
517  myList->appendItem(i->getID().c_str());
518  }
519  }
520  // By default, CheckBox for useSelectedLanes isn't checked
521  myUseSelectedLanesCheckButton->setCheck(false);
522  // Show list
523  show();
524 }
525 
526 
527 void
529  FXGroupBox::hide();
530 }
531 
532 
533 void
535  // Enable or disable use selected Lanes
536  if (myAdditionalFrameParent->getViewNet()->getNet()->retrieveLanes(true).size() > 0) {
538  } else {
540  }
541 }
542 
543 
544 long
546  if (myUseSelectedLanesCheckButton->getCheck()) {
547  myLanesSearch->hide();
548  myList->hide();
549  clearLanesSelection->hide();
550  invertLanesSelection->hide();
551  } else {
552  myLanesSearch->show();
553  myList->show();
554  clearLanesSelection->show();
555  invertLanesSelection->show();
556  }
557  // Recalc Frame
558  recalc();
559  // Update Frame
560  update();
561  return 1;
562 }
563 
564 
565 long
567  // Show only Id's of SelectorLaneChildren that contains the searched string
568  showSelectorLaneChildrenModul(myLanesSearch->getText().text());
569  return 1;
570 }
571 
572 
573 long
575  return 1;
576 }
577 
578 
579 long
581  for (int i = 0; i < myList->getNumItems(); i++) {
582  if (myList->getItem(i)->isSelected()) {
583  myList->deselectItem(i);
584  }
585  }
586  return 1;
587 }
588 
589 
590 long
592  for (int i = 0; i < myList->getNumItems(); i++) {
593  if (myList->getItem(i)->isSelected()) {
594  myList->deselectItem(i);
595  } else {
596  myList->selectItem(i);
597  }
598  }
599  return 1;
600 }
601 
602 // ===========================================================================
603 // method definitions
604 // ===========================================================================
605 
606 GNEAdditionalFrame::GNEAdditionalFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet) :
607  GNEFrame(horizontalFrameParent, viewNet, "Additionals") {
608 
609  // create item Selector modul for additionals
610  myAdditionalTagSelector = new GNEFrameModuls::TagSelector(this, GNEAttributeCarrier::TagType::TAGTYPE_ADDITIONAL);
611 
612  // Create additional parameters
614 
615  // Create Netedit parameter
617 
618  // Create consecutive Lane Selector
620 
621  // Create selector parent
623 
626 
629 
630  // set BusStop as default additional
632 }
633 
634 
636 
637 
638 void
640  // refresh item selector
642  // show frame
643  GNEFrame::show();
644 }
645 
646 
647 bool
649  // first check that current selected additional is valid
651  myViewNet->setStatusBarText("Current selected additional isn't valid.");
652  return false;
653  }
654 
655  // obtain tagproperty (only for improve code legibility)
656  const auto& tagValues = myAdditionalTagSelector->getCurrentTagProperties();
657 
658  // Declare map to keep attributes from Frames from Frame
659  std::map<SumoXMLAttr, std::string> valuesMap = myAdditionalAttributes->getAttributesAndValues(true);
660 
661  // fill netedit attributes
662  if (!myNeteditAttributes->getNeteditAttributesAndValues(valuesMap, objectsUnderCursor.getLaneFront())) {
663  return false;
664  }
665 
666  // If element owns an additional parent, get id of parent from AdditionalParentSelector
667  if (tagValues.hasParent() && !buildAdditionalWithParent(valuesMap, objectsUnderCursor.getAdditionalFront(), tagValues)) {
668  return false;
669  }
670 
671  // If consecutive Lane Selector is enabled, it means that either we're selecting lanes or we're finished or we'rent started
672  if (tagValues.hasAttribute(SUMO_ATTR_EDGE) || (tagValues.getTag() == SUMO_TAG_VAPORIZER)) {
673  return buildAdditionalOverEdge(valuesMap, objectsUnderCursor.getLaneFront(), tagValues);
674  } else if (tagValues.hasAttribute(SUMO_ATTR_LANE)) {
675  return buildAdditionalOverLane(valuesMap, objectsUnderCursor.getLaneFront(), tagValues);
676  } else if (tagValues.getTag() == SUMO_TAG_E2DETECTOR_MULTILANE) {
677  return buildAdditionalOverLanes(valuesMap, objectsUnderCursor.getLaneFront(), tagValues);
678  } else {
679  return buildAdditionalOverView(valuesMap, tagValues);
680  }
681 }
682 
683 
684 void
686  // Show frame
687  GNEFrame::show();
688  // Update UseSelectedLane CheckBox
690  // Update UseSelectedLane CheckBox
692 }
693 
694 
697  return mySelectorLaneParents;
698 }
699 
700 
701 void
704  // show additional attributes modul
706  // show netedit attributes
708  // Show myAdditionalFrameParent if we're adding a additional with parent
711  } else {
713  }
714  // Show SelectorEdgeChildren if we're adding an additional that own the attribute SUMO_ATTR_EDGES
717  } else {
719  }
720  // Show SelectorLaneChildren or consecutive lane selector if we're adding an additional that own the attribute SUMO_ATTR_LANES
724  // show selector lane parent and hide selector lane child
727  } else {
728  // show selector lane child and hide selector lane parent
731  }
732  } else {
735  }
736  } else {
737  // hide all moduls if additional isn't valid
744  }
745 }
746 
747 
748 std::string
750  // obtain current number of additionals to generate a new index faster
752  // obtain tag Properties (only for improve code legilibility
753  const auto& tagProperties = myAdditionalTagSelector->getCurrentTagProperties();
754  if (netElement) {
755  // special case for vaporizers
756  if (tagProperties.getTag() == SUMO_TAG_VAPORIZER) {
757  return netElement->getID();
758  } else {
759  // generate ID using netElement
760  while (myViewNet->getNet()->retrieveAdditional(tagProperties.getTag(), tagProperties.getTagStr() + "_" + netElement->getID() + "_" + toString(additionalIndex), false) != nullptr) {
761  additionalIndex++;
762  }
763  return tagProperties.getTagStr() + "_" + netElement->getID() + "_" + toString(additionalIndex);
764  }
765  } else {
766  // generate ID without netElement
767  while (myViewNet->getNet()->retrieveAdditional(tagProperties.getTag(), tagProperties.getTagStr() + "_" + toString(additionalIndex), false) != nullptr) {
768  additionalIndex++;
769  }
770  return tagProperties.getTagStr() + "_" + toString(additionalIndex);
771  }
772 }
773 
774 
775 bool
776 GNEAdditionalFrame::buildAdditionalWithParent(std::map<SumoXMLAttr, std::string>& valuesMap, GNEAdditional* additionalParent, const GNEAttributeCarrier::TagProperties& tagValues) {
777  // if user click over an additional element parent, mark int in AdditionalParentSelector
778  if (additionalParent && (additionalParent->getTagProperty().getTag() == tagValues.getParentTag())) {
779  valuesMap[GNE_ATTR_PARENT] = additionalParent->getID();
780  myAdditionalParent->setIDSelected(additionalParent->getID());
781  }
782  // stop if currently there isn't a valid selected parent
783  if (myAdditionalParent->getIdSelected() != "") {
785  } else {
786  myAdditionalAttributes->showWarningMessage("A " + toString(tagValues.getParentTag()) + " must be selected before insertion of " + myAdditionalTagSelector->getCurrentTagProperties().getTagStr() + ".");
787  return false;
788  }
789  return true;
790 }
791 
792 
793 bool
794 GNEAdditionalFrame::buildAdditionalCommonAttributes(std::map<SumoXMLAttr, std::string>& valuesMap, const GNEAttributeCarrier::TagProperties& tagValues) {
795  // If additional has a interval defined by a begin or end, check that is valid
796  if (tagValues.hasAttribute(SUMO_ATTR_STARTTIME) && tagValues.hasAttribute(SUMO_ATTR_END)) {
797  double begin = GNEAttributeCarrier::parse<double>(valuesMap[SUMO_ATTR_STARTTIME]);
798  double end = GNEAttributeCarrier::parse<double>(valuesMap[SUMO_ATTR_END]);
799  if (begin > end) {
800  myAdditionalAttributes->showWarningMessage("Attribute '" + toString(SUMO_ATTR_STARTTIME) + "' cannot be greater than attribute '" + toString(SUMO_ATTR_END) + "'.");
801  return false;
802  }
803  }
804  // If additional own the attribute SUMO_ATTR_FILE but was't defined, will defined as <ID>.xml
805  if (tagValues.hasAttribute(SUMO_ATTR_FILE) && valuesMap[SUMO_ATTR_FILE] == "") {
807  // SUMO_ATTR_FILE is optional for calibrators and rerouters (fails to load in sumo when given and the file does not exist)
808  valuesMap[SUMO_ATTR_FILE] = (valuesMap[SUMO_ATTR_ID] + ".xml");
809  }
810  }
811  // If element own a list of SelectorEdgeChildren as attribute
812  if (tagValues.hasAttribute(SUMO_ATTR_EDGES) && valuesMap[SUMO_ATTR_EDGES].empty()) {
813  // obtain edge IDs
815  // check if attribute has at least one edge
816  if (valuesMap[SUMO_ATTR_EDGES] == "") {
817  myAdditionalAttributes->showWarningMessage("List of " + toString(SUMO_TAG_EDGE) + "s cannot be empty");
818  return false;
819  }
820  }
821  // get values of mySelectorLaneChildren, if tag correspond to an element that has lanes as children
822  if (tagValues.hasAttribute(SUMO_ATTR_LANES) && valuesMap[SUMO_ATTR_LANES].empty()) {
823  // obtain lane IDs
825  // check if attribute has at least a lane
826  if (valuesMap[SUMO_ATTR_LANES] == "") {
827  myAdditionalAttributes->showWarningMessage("List of " + toString(SUMO_TAG_LANE) + "s cannot be empty");
828  return false;
829  }
830  }
831  // all ok, continue building additionals
832  return true;
833 }
834 
835 
836 bool
837 GNEAdditionalFrame::buildAdditionalOverEdge(std::map<SumoXMLAttr, std::string>& valuesMap, GNELane* lane, const GNEAttributeCarrier::TagProperties& tagValues) {
838  // check that edge exist
839  if (lane) {
840  // Get attribute lane's edge
841  valuesMap[SUMO_ATTR_EDGE] = lane->getParentEdge().getID();
842  // Generate id of element based on the lane's edge
843  valuesMap[SUMO_ATTR_ID] = generateID(&lane->getParentEdge());
844  } else {
845  return false;
846  }
847  // parse common attributes
848  if (!buildAdditionalCommonAttributes(valuesMap, tagValues)) {
849  return false;
850  }
851  // show warning dialogbox and stop check if input parameters are valid
854  return false;
855  } else {
856  // declare SUMOSAXAttributesImpl_Cached to convert valuesMap into SUMOSAXAttributes
857  SUMOSAXAttributesImpl_Cached SUMOSAXAttrs(valuesMap, getPredefinedTagsMML(), toString(tagValues.getTag()));
858  // try to build additional
860  // Refresh additional Parent Selector (For additionals that have a limited number of children)
862  // clear selected eddges and lanes
863  mySelectorEdgeChildren->onCmdClearSelection(nullptr, 0, nullptr);
864  mySelectorLaneChildren->onCmdClearSelection(nullptr, 0, nullptr);
865  return true;
866  } else {
867  return false;
868  }
869  }
870 }
871 
872 
873 bool
874 GNEAdditionalFrame::buildAdditionalOverLane(std::map<SumoXMLAttr, std::string>& valuesMap, GNELane* lane, const GNEAttributeCarrier::TagProperties& tagValues) {
875  // check that lane exist
876  if (lane != nullptr) {
877  // Get attribute lane
878  valuesMap[SUMO_ATTR_LANE] = lane->getID();
879  // Generate id of element based on the lane
880  valuesMap[SUMO_ATTR_ID] = generateID(lane);
881  } else {
882  return false;
883  }
884  // Obtain position of the mouse over lane (limited over grid)
886  // set attribute position as mouse position over lane
887  valuesMap[SUMO_ATTR_POSITION] = toString(mousePositionOverLane);
888  // parse common attributes
889  if (!buildAdditionalCommonAttributes(valuesMap, tagValues)) {
890  return false;
891  }
892  // show warning dialogbox and stop check if input parameters are valid
895  return false;
896  } else {
897  // declare SUMOSAXAttributesImpl_Cached to convert valuesMap into SUMOSAXAttributes
898  SUMOSAXAttributesImpl_Cached SUMOSAXAttrs(valuesMap, getPredefinedTagsMML(), toString(tagValues.getTag()));
899  // try to build additional
901  // Refresh additional Parent Selector (For additionals that have a limited number of children)
903  // clear selected eddges and lanes
904  mySelectorEdgeChildren->onCmdClearSelection(nullptr, 0, nullptr);
905  mySelectorLaneChildren->onCmdClearSelection(nullptr, 0, nullptr);
906  return true;
907  } else {
908  return false;
909  }
910  }
911 }
912 
913 
914 bool
915 GNEAdditionalFrame::buildAdditionalOverLanes(std::map<SumoXMLAttr, std::string>& valuesMap, GNELane* lane, const GNEAttributeCarrier::TagProperties& tagValues) {
916  // stop if lane isn't valid
917  if (lane == nullptr) {
918  return false;
919  }
921  // select clicked lane, but don't build additional
923  return false;
924  } else if (mySelectorLaneParents->getSelectedLanes().empty()) {
925  // if there isn't selected lanes, that means that we will be start selecting lanes
927  return false;
928  } else {
929  // Generate id of element based on the first lane
930  valuesMap[SUMO_ATTR_ID] = generateID(mySelectorLaneParents->getSelectedLanes().front().first);
931  // obtain lane IDs
932  std::vector<std::string> laneIDs;
933  for (auto i : mySelectorLaneParents->getSelectedLanes()) {
934  laneIDs.push_back(i.first->getID());
935  }
936  valuesMap[SUMO_ATTR_LANES] = joinToString(laneIDs, " ");
937  // Check if clicked position over first lane has to be obtained
938  if (tagValues.hasAttribute(SUMO_ATTR_POSITION)) {
939  valuesMap[SUMO_ATTR_POSITION] = toString(mySelectorLaneParents->getSelectedLanes().front().second);
940  }
941  // Check if clicked position over last lane has to be obtained
942  if (tagValues.hasAttribute(SUMO_ATTR_ENDPOS)) {
943  valuesMap[SUMO_ATTR_ENDPOS] = toString(mySelectorLaneParents->getSelectedLanes().back().second);
944  }
945  // parse common attributes
946  if (!buildAdditionalCommonAttributes(valuesMap, tagValues)) {
947  return false;
948  }
949  // show warning dialogbox and stop check if input parameters are valid
950  if (myAdditionalAttributes->areValuesValid() == false) {
952  return false;
953  } else {
954  // declare SUMOSAXAttributesImpl_Cached to convert valuesMap into SUMOSAXAttributes
955  SUMOSAXAttributesImpl_Cached SUMOSAXAttrs(valuesMap, getPredefinedTagsMML(), toString(tagValues.getTag()));
956  // try to build additional
958  // Refresh additional Parent Selector (For additionals that have a limited number of children)
960  // abort lane selector
962  return true;
963  } else {
964  // additional cannot be build
965  return false;
966  }
967  }
968  }
969 }
970 
971 
972 bool
973 GNEAdditionalFrame::buildAdditionalOverView(std::map<SumoXMLAttr, std::string>& valuesMap, const GNEAttributeCarrier::TagProperties& tagValues) {
974  // Generate id of element
975  valuesMap[SUMO_ATTR_ID] = generateID(nullptr);
976  // Obtain position as the clicked position over view
978  // parse common attributes
979  if (!buildAdditionalCommonAttributes(valuesMap, tagValues)) {
980  return false;
981  }
982  // show warning dialogbox and stop check if input parameters are valid
983  if (myAdditionalAttributes->areValuesValid() == false) {
985  return false;
986  } else {
987  // declare SUMOSAXAttributesImpl_Cached to convert valuesMap into SUMOSAXAttributes
988  SUMOSAXAttributesImpl_Cached SUMOSAXAttrs(valuesMap, getPredefinedTagsMML(), toString(tagValues.getTag()));
989  // try to build additional
991  // Refresh additional Parent Selector (For additionals that have a limited number of children)
993  // clear selected eddges and lanes
994  mySelectorEdgeChildren->onCmdClearSelection(nullptr, 0, nullptr);
995  mySelectorLaneChildren->onCmdClearSelection(nullptr, 0, nullptr);
996  return true;
997  } else {
998  return false;
999  }
1000  }
1001 }
1002 
1003 /****************************************************************************/
std::vector< GNELane * > retrieveLanes(bool onlySelected=false)
return all lanes
Definition: GNENet.cpp:1164
FXTextField * myEdgesSearch
text field for search edge IDs
Position snapToActiveGrid(const Position &pos, bool snapXY=true) const
Returns a position that is mapped to the closest grid point if the grid is active.
clear selection of elements
Definition: GUIAppEnum.h:773
FXButton * invertLanesSelection
button for invert selection
PositionVector shape
The shape of the netElement element.
Definition: GNENetElement.h:57
invert selection of eleents
Definition: GUIAppEnum.h:775
const RGBColor & getSelectedLaneColor() const
get selected lane color
FXTextField * myLanesSearch
text field for search lane IDs
GNEFrameAttributesModuls::AttributesCreator * myAdditionalAttributes
internal additional attributes
begin/end of the description of a single lane
void update() const
Mark the entire GNEViewNet to be repainted later.
Definition: GNEViewNet.cpp:292
void showSelectorLaneParentsModul()
show SelectorLaneParents modul
bool addAdditional(const GNEViewNetHelper::ObjectsUnderCursor &objectsUnderCursor)
add additional element
GNEFrameModuls::TagSelector * myAdditionalTagSelector
item selector
FXCheckButton * myUseSelectedLanesCheckButton
CheckBox for selected lanes.
A calibrator placed over edge.
an e2 detector over multiple lanes (used by Netedit)
bool showSelectorParentModul(SumoXMLTag additionalTypeParent)
Show list of SelectorParent Modul.
bool buildAdditionalCommonAttributes(std::map< SumoXMLAttr, std::string > &valuesMap, const GNEAttributeCarrier::TagProperties &tagValues)
build common additional attributes
long onCmdInvertSelection(FXObject *, FXSelector, void *)
called when invert selection button is pressed
void showAttributesCreatorModul(const GNEAttributeCarrier::TagProperties &myTagProperties)
show AttributesCreator modul
struct with the attribute Properties
FXCheckButton * myUseSelectedEdgesCheckButton
CheckBox for selected edges.
const std::vector< GNEConnection * > & getGNEConnections() const
returns a reference to the GNEConnection vector
Definition: GNEEdge.cpp:846
abort selection of consecutive egdes/lanes
Definition: GUIAppEnum.h:781
void setIDSelected(const std::string &id)
select manually a element of the list
bool isShown() const
return true if modul is shown
const std::string & getTagStr() const
get Tag vinculated with this attribute Property in String Format (used to avoid multiple calls to toS...
long onCmdAbortSelection(FXObject *, FXSelector, void *)
Called when the user press abort selection button.
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:46
GNEFrameAttributesModuls::NeteditAttributes * myNeteditAttributes
Netedit parameter.
bool stopConsecutiveLaneSelector()
stop selection of consecutive lanes
void hideNeteditAttributesModul()
hide Netedit attributes modul
long onCmdStopSelection(FXObject *, FXSelector, void *)
std::vector< GNELane * > myCandidateLanes
Vector with the colored lanes.
int getNumberOfAdditionals(SumoXMLTag type=SUMO_TAG_NOTHING) const
Returns the number of additionals of the net.
Definition: GNENet.cpp:2160
long onCmdTypeInSearchBox(FXObject *, FXSelector, void *)
called when user type in search box
long onCmdUseSelectedEdges(FXObject *, FXSelector, void *)
long onCmdUseSelectedLanes(FXObject *, FXSelector, void *)
Encapsulated Xerces-SAX-attributes.
void hideSelectorLaneChildrenModul()
hide SelectorLaneChildren Modul
std::map< SumoXMLAttr, std::string > getAttributesAndValues(bool includeAll) const
get attributes and their values
const std::vector< std::pair< GNELane *, double > > & getSelectedLanes() const
get current selected lanes
GNEAdditionalFrame * myAdditionalFrameParent
pointer to additional frame parent
RGBColor myCandidateLaneColor
color for candidate lanes
static bool buildAdditional(GNEViewNet *viewNet, bool allowUndoRedo, SumoXMLTag tag, const SUMOSAXAttributes &attrs, HierarchyInsertedAdditionals *insertedAdditionals)
Build additionals.
GNEViewNet * getViewNet() const
get view net
Definition: GNEFrame.cpp:133
bool buildAdditionalOverEdge(std::map< SumoXMLAttr, std::string > &valuesMap, GNELane *lane, const GNEAttributeCarrier::TagProperties &tagValues)
build additional over an edge (parent of lane)
const std::map< int, std::string > & getPredefinedTagsMML() const
get predefinedTagsMML
Definition: GNEFrame.cpp:276
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:239
bool areValuesValid() const
check if parameters of attributes are valid
bool hasParent() const
return true if tag correspond to an element that can had another element as parent ...
GNEViewNet * myViewNet
View Net.
Definition: GNEFrame.h:120
FXButton * clearLanesSelection
button for clear selection
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
Definition: GNENet.cpp:2133
#define GUIDesignListFixedHeight
design for FXLists with height fixed
Definition: GUIDesigns.h:532
void showNeteditAttributesModul(const GNEAttributeCarrier::TagProperties &tagValue)
show Netedit attributes modul
GNEAdditionalFrame * myAdditionalFrameParent
pointer to additional frame parent
bool isLaneSelected(GNELane *lane) const
check if certain lane is selected
static const RGBColor GREEN
Definition: RGBColor.h:191
GNEAdditionalFrame::SelectorLaneParents * getConsecutiveLaneSelector() const
getConsecutive Lane Selector
#define GUIDesignTextField
Definition: GUIDesigns.h:34
the edges of a route
void showSelectorEdgeChildrenModul(std::string search="")
Show SelectorEdgeChildren Modul.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
FXVerticalFrame * myContentFrame
Vertical frame that holds all widgets of frame.
Definition: GNEFrame.h:123
void updateUseSelectedEdges()
Update use selectedEdges.
GNEEdge & getParentEdge()
Returns underlying parent edge.
Definition: GNELane.cpp:1292
void removeLastSelectedLane()
remove last added point
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
#define GUIDesignCheckButton
checkButton placed in left position
Definition: GUIDesigns.h:131
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames ...
Definition: GUIDesigns.h:289
std::string getIdSelected() const
get currently additional parent selected
GNEAdditionalFrame * myAdditionalFrameParent
pointer to additionalFrameParent
FXButton * myStopSelectingButton
button for stop selecting
void refreshTagProperties()
due myCurrentTagProperties is a Reference, we need to refresh it when frameParent is show ...
bool buildAdditionalOverLane(std::map< SumoXMLAttr, std::string > &valuesMap, GNELane *lane, const GNEAttributeCarrier::TagProperties &tagValues)
build additional over a single lane
C++ TraCI client API implementation.
FXButton * myClearEdgesSelection
button for clear selection
~GNEAdditionalFrame()
Destructor.
class used to group all variables related with objects under cursor after a click over view ...
double getLengthGeometryFactor() const
get length geometry factor
Definition: GNELane.cpp:1355
GNELane * getLaneFront() const
get front lane (or a pointer to nullptr if there isn&#39;t)
long onCmdSelectLane(FXObject *, FXSelector, void *)
called when user select a lane of the list
FXButton * myAbortSelectingButton
button for abort selecting
const std::string getID() const
function to support debugging
const NetElementGeometry & getGeometry() const
std::vector< std::pair< GNELane *, double > > mySelectedLanes
Vector with the selected lanes and the clicked position.
GNEFrameModuls::SelectorParent * myAdditionalParent
Modul for select a single additional parent.
#define GUIDesignButtonRectangular
little button rectangular (46x23) used in frames (For example, in "help" buttons) ...
Definition: GUIDesigns.h:72
GNEAdditional * getAdditionalFront() const
get front additional element (or a pointer to nullptr if there isn&#39;t)
FXButton * myInvertEdgesSelection
button for invert selection
void hideSelectorEdgeChildrenModul()
hide SelectorEdgeChildren Modul
void setSpecialColor(const RGBColor *Color2, double colorValue=std::numeric_limits< double >::max())
Definition: GNELane.cpp:927
void refreshSelectorParentModul()
Refresh list of Additional Parents Modul.
begin/end of the description of an edge
SelectorLaneChildren * mySelectorLaneChildren
Modul for select lane children.
void tagSelected()
Tag selected in TagSelector.
bool getNeteditAttributesAndValues(std::map< SumoXMLAttr, std::string > &valuesMap, const GNELane *lane) const
fill valuesMap with netedit attributes
FXList * myList
List of SelectorLaneChildren.
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition: GUIDesigns.h:58
FXList * myList
List of SelectorEdgeChildren.
#define GUIDesignButton
Definition: GUIDesigns.h:66
void showSelectorLaneChildrenModul()
show selector lane child and update use selected edges/lanes
virtual void show()
show Frame
Definition: GNEFrame.cpp:108
long onCmdTypeInSearchBox(FXObject *, FXSelector, void *)
called when user type in search box
bool addSelectedLane(GNELane *lane, const Position &clickedPosition)
return true if lane can be selected as consecutive lane
std::string getLaneIdsSelected() const
get list of selecte lane ids in string format
void show()
show Frame
long onCmdClearSelection(FXObject *, FXSelector, void *)
called when clear selection button is pressed
std::vector< GNEEdge * > retrieveEdges(bool onlySelected=false)
return all edges
Definition: GNENet.cpp:1151
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:47
#define GUIDesignGroupBoxFrame
Group box design extended over frame.
Definition: GUIDesigns.h:255
weights: time range end
std::string getEdgeIdsSelected() const
get list of selecte id&#39;s in string format
const GNEAttributeCarrier::TagProperties & getCurrentTagProperties() const
get current type tag
FXDEFMAP(GNEAdditionalFrame::SelectorLaneParents) ConsecutiveLaneSelectorMap[]
SelectorLaneParents * mySelectorLaneParents
Modul for select lane parents (currently only consecutives)
SelectorEdgeChildren * mySelectorEdgeChildren
Modul for select edge children.
RGBColor mySelectedLaneColor
color for selected lanes
bool buildAdditionalOverView(std::map< SumoXMLAttr, std::string > &valuesMap, const GNEAttributeCarrier::TagProperties &tagValues)
build additional over view
void hideSelectorLaneParentsModul()
hide SelectorLaneParents
vaporizer of vehicles
std::string generateID(GNENetElement *netElement) const
generate a ID for an additiona element
void showWarningMessage(std::string extra="") const
show warning message with information about non-valid attributes
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:927
bool buildAdditionalWithParent(std::map< SumoXMLAttr, std::string > &valuesMap, GNEAdditional *parent, const GNEAttributeCarrier::TagProperties &tagValues)
build additional with Parent
void setStatusBarText(const std::string &text)
set staturBar text
Definition: GNEViewNet.cpp:482
bool isSelectingLanes() const
return true if modul is selecting lane
SumoXMLTag getParentTag() const
if Tag owns a parent, return parent tag
bool hasAttribute(SumoXMLAttr attr) const
check if current TagProperties owns the attribute attr
const TagProperties & getTagProperty() const
get Tag Property assigned to this object
void startConsecutiveLaneSelector(GNELane *lane, const Position &clickedPosition)
start selection of consecutive lanes
Position getPositionInformation() const
Returns the cursor&#39;s x/y position within the network.
use selected elements
Definition: GUIAppEnum.h:769
long onCmdClearSelection(FXObject *, FXSelector, void *)
called when clear selection button is pressed
bool buildAdditionalOverLanes(std::map< SumoXMLAttr, std::string > &valuesMap, GNELane *lane, const GNEAttributeCarrier::TagProperties &tagValues)
build additional over lanes
parent of an additional element
void setCurrentTag(SumoXMLTag newTag)
set current type manually
long onCmdInvertSelection(FXObject *, FXSelector, void *)
called when invert selection button is pressed
void hideSelectorParentModul()
hide SelectorParent Modul
long onCmdSelectEdge(FXObject *, FXSelector, void *)
called when user select a edge of the list
GNEAdditionalFrame(FXHorizontalFrame *horizontalFrameParent, GNEViewNet *viewNet)
Constructor.
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
void showSelectorLaneChildrenModul(std::string search="")
Show list of SelectorLaneChildren Modul.
void abortConsecutiveLaneSelector()
abort selection of consecutive lanes
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
Definition: ToString.h:247
stop selection of consecutive egdes/lanes
Definition: GUIAppEnum.h:779