Eclipse SUMO - Simulation of Urban MObility
GNEContainer.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-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
18 // Representation of containers in NETEDIT
19 /****************************************************************************/
20 #include <cmath>
22 #include <netedit/GNENet.h>
23 #include <netedit/GNEUndoList.h>
24 #include <netedit/GNEViewNet.h>
27 #include <utils/gui/div/GLHelper.h>
32 
33 #include "GNEContainer.h"
34 #include "GNERouteHandler.h"
35 
36 
37 // ===========================================================================
38 // FOX callback mapping
39 // ===========================================================================
40 FXDEFMAP(GNEContainer::GNEContainerPopupMenu) containerPopupMenuMap[] = {
42 };
43 
44 FXDEFMAP(GNEContainer::GNESelectedContainersPopupMenu) selectedContainersPopupMenuMap[] = {
46 };
47 
48 // Object implementation
49 FXIMPLEMENT(GNEContainer::GNEContainerPopupMenu, GUIGLObjectPopupMenu, containerPopupMenuMap, ARRAYNUMBER(containerPopupMenuMap))
50 FXIMPLEMENT(GNEContainer::GNESelectedContainersPopupMenu, GUIGLObjectPopupMenu, selectedContainersPopupMenuMap, ARRAYNUMBER(selectedContainersPopupMenuMap))
51 
52 // ===========================================================================
53 // GNEContainer::GNEContainerPopupMenu
54 // ===========================================================================
55 
57  GUIGLObjectPopupMenu(app, parent, *container),
58  myContainer(container),
59  myTransformToContainer(nullptr),
60  myTransformToContainerFlow(nullptr) {
61  // build header
62  myContainer->buildPopupHeader(this, app);
63  // build menu command for center button and copy cursor position to clipboard
64  myContainer->buildCenterPopupEntry(this);
65  myContainer->buildPositionCopyEntry(this, false);
66  // buld menu commands for names
67  GUIDesigns::buildFXMenuCommand(this, ("Copy " + myContainer->getTagStr() + " name to clipboard").c_str(), nullptr, this, MID_COPY_NAME);
68  GUIDesigns::buildFXMenuCommand(this, ("Copy " + myContainer->getTagStr() + " typed name to clipboard").c_str(), nullptr, this, MID_COPY_TYPED_NAME);
69  new FXMenuSeparator(this);
70  // build selection and show parameters menu
71  myContainer->getNet()->getViewNet()->buildSelectionACPopupEntry(this, myContainer);
72  myContainer->buildShowParamsPopupEntry(this);
73  // add transform functions only in demand mode
74  if (myContainer->getNet()->getViewNet()->getEditModes().isCurrentSupermodeDemand()) {
75  // create menu pane for transform operations
76  FXMenuPane* transformOperation = new FXMenuPane(this);
77  this->insertMenuPaneChild(transformOperation);
78  new FXMenuCascade(this, "transform to", nullptr, transformOperation);
79  // Create menu comands for all transformations
80  myTransformToContainer = GUIDesigns::buildFXMenuCommand(transformOperation, "Container", GUIIconSubSys::getIcon(GUIIcon::CONTAINER), this, MID_GNE_CONTAINER_TRANSFORM);
81  myTransformToContainerFlow = GUIDesigns::buildFXMenuCommand(transformOperation, "Container (embedded route)", GUIIconSubSys::getIcon(GUIIcon::CONTAINERFLOW), this, MID_GNE_CONTAINER_TRANSFORM);
82  // check what menu command has to be disabled
83  if (myContainer->getTagProperty().getTag() == SUMO_TAG_CONTAINER) {
84  myTransformToContainer->disable();
85  } else if (myContainer->getTagProperty().getTag() == SUMO_TAG_CONTAINERFLOW) {
86  myTransformToContainerFlow->disable();
87  }
88  }
89 }
90 
91 
93 
94 
95 long
96 GNEContainer::GNEContainerPopupMenu::onCmdTransform(FXObject* obj, FXSelector, void*) {
97  if (obj == myTransformToContainer) {
99  } else if (obj == myTransformToContainerFlow) {
101  }
102  return 1;
103 }
104 
105 
106 // ===========================================================================
107 // GNEContainer::GNESelectedContainersPopupMenu
108 // ===========================================================================
109 
110 GNEContainer::GNESelectedContainersPopupMenu::GNESelectedContainersPopupMenu(GNEContainer* container, const std::vector<GNEContainer*>& selectedContainer, GUIMainWindow& app, GUISUMOAbstractView& parent) :
111  GUIGLObjectPopupMenu(app, parent, *container),
112  myContainerTag(container->getTagProperty().getTag()),
113  mySelectedContainers(selectedContainer),
114  myTransformToContainer(nullptr),
115  myTransformToContainerFlow(nullptr) {
116  // build header
117  container->buildPopupHeader(this, app);
118  // build menu command for center button and copy cursor position to clipboard
119  container->buildCenterPopupEntry(this);
120  container->buildPositionCopyEntry(this, false);
121  // buld menu commands for names
122  GUIDesigns::buildFXMenuCommand(this, ("Copy " + container->getTagStr() + " name to clipboard").c_str(), nullptr, this, MID_COPY_NAME);
123  GUIDesigns::buildFXMenuCommand(this, ("Copy " + container->getTagStr() + " typed name to clipboard").c_str(), nullptr, this, MID_COPY_TYPED_NAME);
124  new FXMenuSeparator(this);
125  // build selection and show parameters menu
126  container->getNet()->getViewNet()->buildSelectionACPopupEntry(this, container);
127  container->buildShowParamsPopupEntry(this);
128  // add transform functions only in demand mode
129  if (container->getNet()->getViewNet()->getEditModes().isCurrentSupermodeDemand()) {
130  // create menu pane for transform operations
131  FXMenuPane* transformOperation = new FXMenuPane(this);
132  this->insertMenuPaneChild(transformOperation);
133  new FXMenuCascade(this, "transform to", nullptr, transformOperation);
134  // Create menu comands for all transformations
137  }
138 }
139 
140 
142 
143 
144 long
146  // iterate over all selected containers
147  for (const auto& i : mySelectedContainers) {
148  if ((obj == myTransformToContainer) &&
149  (i->getTagProperty().getTag() == myContainerTag)) {
151  } else if ((obj == myTransformToContainerFlow) &&
152  (i->getTagProperty().getTag() == myContainerTag)) {
154  }
155  }
156  return 1;
157 }
158 
159 // ===========================================================================
160 // member method definitions
161 // ===========================================================================
162 
165 {}, {}, {}, {}, {}, {}, {}, {}) {
166  // reset default values
167  resetDefaultValues();
168 }
169 
170 
171 GNEContainer::GNEContainer(SumoXMLTag tag, GNENet* net, GNEDemandElement* pType, const SUMOVehicleParameter& containerparameters) :
172  GNEDemandElement(containerparameters.id, net, (tag == SUMO_TAG_CONTAINERFLOW) ? GLO_CONTAINERFLOW : GLO_CONTAINER, tag, GNEPathManager::PathElement::Options::DEMAND_ELEMENT,
173 {}, {}, {}, {}, {}, {}, {pType}, {}),
174 SUMOVehicleParameter(containerparameters) {
175  // set manually vtypeID (needed for saving)
176  vtypeid = pType->getID();
177 }
178 
179 
181 
182 
185  // check first container plan
186  if (getChildDemandElements().front()->getTagProperty().isStopContainer()) {
187  return nullptr;
188  } else {
189  // get lane
190  const GNELane* lane = getChildDemandElements().front()->getParentEdges().front()->getLaneByAllowedVClass(getVClass());
191  // declare departPos
192  double posOverLane = 0;
193  if (canParse<double>(getDepartPos())) {
194  posOverLane = parse<double>(getDepartPos());
195  }
196  // return move operation
197  return new GNEMoveOperation(this, lane, posOverLane, false);
198  }
199 }
200 
201 
202 std::string
204  // obtain depart depending if is a Container, trip or routeFlow
205  std::string departStr;
207  departStr = toString(depart);
208  } else {
209  departStr = getDepart();
210  }
211  // we need to handle depart as a tuple of 20 numbers (format: 000000...00<departTime>)
212  departStr.reserve(20 - departStr.size());
213  // add 0s at the beginning of departStr until we have 20 numbers
214  for (int i = (int)departStr.size(); i < 20; i++) {
215  departStr.insert(departStr.begin(), '0');
216  }
217  return departStr;
218 }
219 
220 
221 void
223  // attribute VType musn't be written if is DEFAULT_PEDTYPE_ID
225  // unset VType parameter
227  // write container attributes (VType will not be written)
229  // set VType parameter again
231  } else {
232  // write container attributes, including VType
234  }
235  // write specific flow attributes
237  // write routeFlow values depending if it was set
240  }
243  }
246  }
249  }
252  }
253  }
254  // write parameters
255  writeParams(device);
256  // write child demand elements associated to this container (Rides, Walks...)
257  for (const auto& i : getChildDemandElements()) {
258  i->writeDemandElement(device);
259  }
260  // close container tag
261  device.closeTag();
262 }
263 
264 
267  // a single container is always valid
268  return Problem::OK;
269 }
270 
271 
272 std::string
274  // A single container cannot habe problem (but their children)
275  return "";
276 }
277 
278 
279 void
281  // nothing to fix
282 }
283 
284 
287  return getParentDemandElements().front()->getVClass();
288 }
289 
290 
291 const RGBColor&
293  return color;
294 }
295 
296 
297 void
299  // only update geometry of childrens
300  for (const auto& demandElement : getChildDemandElements()) {
301  demandElement->updateGeometry();
302  }
303 }
304 
305 
306 Position
309 }
310 
311 
314  // return a GNEContainerPopupMenu
315  return new GNEContainerPopupMenu(this, app, parent);
316 }
317 
318 
319 std::string
321  return getParentDemandElements().front()->getID();
322 }
323 
324 
325 double
327  return s.containerSize.getExaggeration(s, this, 80);
328 }
329 
330 
331 Boundary
333  Boundary containerBoundary;
334  if (getChildDemandElements().size() > 0) {
335  if (getChildDemandElements().front()->getTagProperty().isStopContainer()) {
336  // use boundary of stop center
337  return getChildDemandElements().front()->getCenteringBoundary();
338  } else {
339  containerBoundary.add(getPositionInView());
340  }
341  } else {
342  containerBoundary = Boundary(-0.1, -0.1, 0.1, 0.1);
343  }
344  containerBoundary.grow(20);
345  return containerBoundary;
346 }
347 
348 
349 void
350 GNEContainer::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
351  // geometry of this element cannot be splitted
352 }
353 
354 
355 void
357  bool drawContainer = true;
358  // check if container can be drawn
360  drawContainer = false;
362  drawContainer = false;
364  drawContainer = false;
365  } else if (getChildDemandElements().empty()) {
366  drawContainer = false;
367  }
368  // continue if container can be drawn
369  if (drawContainer) {
370  // obtain exaggeration (and add the special containerExaggeration)
371  const double exaggeration = getExaggeration(s) + s.detailSettings.personExaggeration;
372  // obtain width and length
373  const double length = getParentDemandElements().at(0)->getAttributeDouble(SUMO_ATTR_LENGTH);
374  const double width = getParentDemandElements().at(0)->getAttributeDouble(SUMO_ATTR_WIDTH);
375  // obtain diameter around container (used to calculate distance bewteen cursor and container)
376  const double distanceSquared = pow(exaggeration * std::max(length, width), 2);
377  // obtain img file
378  const std::string file = getParentDemandElements().at(0)->getAttribute(SUMO_ATTR_IMGFILE);
379  // obtain position
380  const Position containerPosition = getAttributePosition(SUMO_ATTR_DEPARTPOS);
381  // check if container can be drawn
382  if (!(s.drawForPositionSelection && (containerPosition.distanceSquaredTo(myNet->getViewNet()->getPositionInformation()) > distanceSquared))) {
383  // push GL ID
385  // push draw matrix
387  // Start with the drawing of the area traslating matrix to origin
389  // translate and rotate
390  glTranslated(containerPosition.x(), containerPosition.y(), 0);
391  glRotated(90, 0, 0, 1);
392  // set container color
393  setColor(s);
394  // set scale
395  glScaled(exaggeration, exaggeration, 1);
396  // draw container depending of detail level
397  if (s.drawDetail(s.detailSettings.personShapes, exaggeration)) {
398  GUIBasePersonHelper::drawAction_drawAsImage(0, length, width, file, SUMOVehicleShape::PEDESTRIAN, exaggeration);
399  } else if (s.drawDetail(s.detailSettings.personCircles, exaggeration)) {
400  GUIBasePersonHelper::drawAction_drawAsCircle(length, width, s.scale * exaggeration);
401  } else if (s.drawDetail(s.detailSettings.personTriangles, exaggeration)) {
403  }
404  // pop matrix
406  // pop name
408  // draw name
409  drawName(containerPosition, s.scale, s.containerName, s.angle);
410  if (s.personValue.show(this)) {
411  Position containerValuePosition = containerPosition + Position(0, 0.6 * s.containerName.scaledSize(s.scale));
412  const double value = getColorValue(s, s.containerColorer.getActive());
413  GLHelper::drawTextSettings(s.personValue, toString(value), containerValuePosition, s.scale, s.angle, GLO_MAX - getType());
414  }
415  // draw lock icon
417  // check if dotted contours has to be drawn
419  // draw using drawDottedSquaredShape
420  GUIDottedGeometry::drawDottedSquaredShape(GUIDottedGeometry::DottedContourType::INSPECT, s, containerPosition, 0.5, 0.5, 0, 0, 0, exaggeration);
421  }
422  if (myNet->getViewNet()->getFrontAttributeCarrier() == this) {
423  // draw using drawDottedSquaredShape
424  GUIDottedGeometry::drawDottedSquaredShape(GUIDottedGeometry::DottedContourType::FRONT, s, containerPosition, 0.5, 0.5, 0, 0, 0, exaggeration);
425  }
426  }
427  }
428 }
429 
430 
431 void
433  // compute all container plan children (because aren't computed in "computeDemandElements()")
434  for (const auto& demandElement : getChildDemandElements()) {
435  demandElement->computePathElement();
436  }
437 }
438 
439 
440 void
441 GNEContainer::drawPartialGL(const GUIVisualizationSettings& /*s*/, const GNELane* /*lane*/, const GNEPathManager::Segment* /*segment*/, const double /*offsetFront*/) const {
442  // Stops don't use drawPartialGL
443 }
444 
445 
446 void
447 GNEContainer::drawPartialGL(const GUIVisualizationSettings& /*s*/, const GNELane* /*fromLane*/, const GNELane* /*toLane*/, const GNEPathManager::Segment* /*segment*/, const double /*offsetFront*/) const {
448  // Stops don't use drawPartialGL
449 }
450 
451 
452 GNELane*
454  // use path lane of first container plan
455  return getChildDemandElements().front()->getFirstPathLane();
456 }
457 
458 
459 GNELane*
461  // use path lane of first container plan
462  return getChildDemandElements().front()->getLastPathLane();
463 }
464 
465 
466 std::string
468  // declare string error
469  std::string error;
470  switch (key) {
471  case SUMO_ATTR_ID:
472  return getID();
473  case SUMO_ATTR_TYPE:
474  return getParentDemandElements().at(0)->getID();
475  case SUMO_ATTR_COLOR:
476  if (wasSet(VEHPARS_COLOR_SET)) {
477  return toString(color);
478  } else {
480  }
481  case SUMO_ATTR_DEPARTPOS:
483  return getDepartPos();
484  } else {
486  }
487  // Specific of containers
488  case SUMO_ATTR_DEPART:
489  return toString(depart);
490  // Specific of containerFlows
491  case SUMO_ATTR_BEGIN:
492  return time2string(depart);
493  case SUMO_ATTR_END:
494  return time2string(repetitionEnd);
496  return toString(3600 / STEPS2TIME(repetitionOffset));
497  case SUMO_ATTR_PERIOD:
499  case SUMO_ATTR_PROB:
501  case SUMO_ATTR_NUMBER:
502  return toString(repetitionNumber);
503  //
504  case GNE_ATTR_SELECTED:
506  case GNE_ATTR_PARAMETERS:
507  return getParametersStr();
508  default:
509  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
510  }
511 }
512 
513 
514 double
516  switch (key) {
517  case SUMO_ATTR_DEPARTPOS:
519  return departPos;
520  } else {
521  return 0;
522  }
523  default:
524  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
525  }
526 }
527 
528 
529 Position
531  switch (key) {
532  case SUMO_ATTR_DEPARTPOS: {
533  // get container plan
534  const GNEDemandElement* containerPlan = getChildDemandElements().front();
535  // first check if first container plan is a stop
536  if (containerPlan->getTagProperty().isStopContainer()) {
537  return containerPlan->getPositionInView();
538  } else {
539  // declare lane lane
540  GNELane* lane = nullptr;
541  // update lane
542  if (containerPlan->getTagProperty().getTag() == GNE_TAG_WALK_ROUTE) {
543  lane = containerPlan->getParentDemandElements().at(1)->getParentEdges().front()->getLaneByAllowedVClass(getVClass());
544  } else {
545  lane = containerPlan->getParentEdges().front()->getLaneByAllowedVClass(getVClass());
546  }
547  // get position over lane shape
548  if (departPos <= 0) {
549  return lane->getLaneShape().front();
550  } else if (departPos >= lane->getLaneShape().length2D()) {
551  return lane->getLaneShape().back();
552  } else {
553  return lane->getLaneShape().positionAtOffset2D(departPos);
554  }
555  }
556  }
557  default:
558  throw InvalidArgument(getTagStr() + " doesn't have a Position attribute of type '" + toString(key) + "'");
559  }
560 }
561 
562 
563 void
564 GNEContainer::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
565  switch (key) {
566  case SUMO_ATTR_ID:
567  case SUMO_ATTR_TYPE:
568  case SUMO_ATTR_COLOR:
569  case SUMO_ATTR_DEPARTPOS:
570  // Specific of containers
571  case SUMO_ATTR_DEPART:
572  // Specific of containerFlows
573  case SUMO_ATTR_BEGIN:
574  case SUMO_ATTR_END:
575  case SUMO_ATTR_NUMBER:
577  case SUMO_ATTR_PERIOD:
578  case SUMO_ATTR_PROB:
579  //
580  case GNE_ATTR_PARAMETERS:
581  case GNE_ATTR_SELECTED:
582  undoList->changeAttribute(new GNEChange_Attribute(this, key, value));
583  break;
584  default:
585  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
586  }
587 }
588 
589 
590 bool
591 GNEContainer::isValid(SumoXMLAttr key, const std::string& value) {
592  // declare string error
593  std::string error;
594  switch (key) {
595  case SUMO_ATTR_ID:
596  // Containers and containerflows share namespace
598  (myNet->getAttributeCarriers()->retrieveDemandElement(SUMO_TAG_CONTAINER, value, false) == nullptr) &&
600  return true;
601  } else {
602  return false;
603  }
604  case SUMO_ATTR_TYPE:
606  case SUMO_ATTR_COLOR:
607  return canParse<RGBColor>(value);
608  case SUMO_ATTR_DEPARTPOS: {
609  double dummyDepartPos;
610  DepartPosDefinition dummyDepartPosProcedure;
611  parseDepartPos(value, toString(SUMO_TAG_VEHICLE), id, dummyDepartPos, dummyDepartPosProcedure, error);
612  // if error is empty, given value is valid
613  return error.empty();
614  }
615  // Specific of containers
616  case SUMO_ATTR_DEPART: {
617  if (canParse<double>(value)) {
618  return (parse<double>(value) >= 0);
619  } else {
620  return false;
621  }
622  }
623  // Specific of containerflows
624  case SUMO_ATTR_BEGIN:
625  if (canParse<double>(value)) {
626  return (parse<double>(value) >= 0);
627  } else {
628  return false;
629  }
630  case SUMO_ATTR_END:
631  if (value.empty()) {
632  return true;
633  } else if (canParse<double>(value)) {
634  return (parse<double>(value) >= 0);
635  } else {
636  return false;
637  }
639  if (value.empty()) {
640  return true;
641  } else if (canParse<double>(value)) {
642  return (parse<double>(value) > 0);
643  } else {
644  return false;
645  }
646  case SUMO_ATTR_PERIOD:
647  if (value.empty()) {
648  return true;
649  } else if (canParse<double>(value)) {
650  return (parse<double>(value) > 0);
651  } else {
652  return false;
653  }
654  case SUMO_ATTR_PROB:
655  if (value.empty()) {
656  return true;
657  } else if (canParse<double>(value)) {
658  return (parse<double>(value) >= 0);
659  } else {
660  return false;
661  }
662  case SUMO_ATTR_NUMBER:
663  if (canParse<int>(value)) {
664  return (parse<int>(value) >= 0);
665  } else {
666  return false;
667  }
668  //
669  case GNE_ATTR_SELECTED:
670  return canParse<bool>(value);
671  case GNE_ATTR_PARAMETERS:
672  return Parameterised::areParametersValid(value);
673  default:
674  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
675  }
676 }
677 
678 
679 void
681  switch (key) {
682  case SUMO_ATTR_END:
683  case SUMO_ATTR_NUMBER:
685  case SUMO_ATTR_PERIOD:
686  case SUMO_ATTR_PROB:
687  undoList->add(new GNEChange_EnableAttribute(this, key, true, parametersSet), true);
688  return;
689  default:
690  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
691  }
692 }
693 
694 
695 void
697  // nothing to disable
698 }
699 
700 
701 bool
703  switch (key) {
704  case SUMO_ATTR_END:
705  return (parametersSet & VEHPARS_END_SET) != 0;
706  case SUMO_ATTR_NUMBER:
707  return (parametersSet & VEHPARS_NUMBER_SET) != 0;
709  return (parametersSet & VEHPARS_VPH_SET) != 0;
710  case SUMO_ATTR_PERIOD:
711  return (parametersSet & VEHPARS_PERIOD_SET) != 0;
712  case SUMO_ATTR_PROB:
713  return (parametersSet & VEHPARS_PROB_SET) != 0;
714  default:
715  return true;
716  }
717 }
718 
719 
720 std::string
722  return getTagStr();
723 }
724 
725 
726 std::string
728  // special case for Trips and flow
730  // check if we're inspecting a Edge
731  if (myNet->getViewNet()->getInspectedAttributeCarriers().front() &&
732  myNet->getViewNet()->getInspectedAttributeCarriers().front()->getTagProperty().getTag() == SUMO_TAG_EDGE) {
733  // check if edge correspond to a "from", "to" or "via" edge
735  return getTagStr() + ": " + getAttribute(SUMO_ATTR_ID) + " (from)";
736  } else if (myNet->getViewNet()->isAttributeCarrierInspected(getParentEdges().front())) {
737  return getTagStr() + ": " + getAttribute(SUMO_ATTR_ID) + " (to)";
738  } else {
739  // iterate over via
740  for (const auto& i : via) {
741  if (i == myNet->getViewNet()->getInspectedAttributeCarriers().front()->getID()) {
742  return getTagStr() + ": " + getAttribute(SUMO_ATTR_ID) + " (via)";
743  }
744  }
745  }
746  }
747  }
748  return getTagStr() + ": " + getAttribute(SUMO_ATTR_ID);
749 }
750 
751 
752 const std::map<std::string, std::string>&
754  return getParametersMap();
755 }
756 
757 // ===========================================================================
758 // protected
759 // ===========================================================================
760 
761 void
763  const GUIColorer& c = s.containerColorer;
764  if (!setFunctionalColor(c.getActive())) {
766  }
767 }
768 
769 
770 bool
771 GNEContainer::setFunctionalColor(int /* activeScheme */) const {
772  /*
773  switch (activeScheme) {
774  case 0: {
775  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
776  GLHelper::setColor(getParameter().color);
777  return true;
778  }
779  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
780  GLHelper::setColor(getVehicleType().getColor());
781  return true;
782  }
783  return false;
784  }
785  case 2: {
786  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
787  GLHelper::setColor(getParameter().color);
788  return true;
789  }
790  return false;
791  }
792  case 3: {
793  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
794  GLHelper::setColor(getVehicleType().getColor());
795  return true;
796  }
797  return false;
798  }
799  case 8: { // color by angle
800  double hue = GeomHelper::naviDegree(getAngle());
801  GLHelper::setColor(RGBColor::fromHSV(hue, 1., 1.));
802  return true;
803  }
804  case 9: { // color randomly (by pointer)
805  const double hue = (long)this % 360; // [0-360]
806  const double sat = (((long)this / 360) % 67) / 100.0 + 0.33; // [0.33-1]
807  GLHelper::setColor(RGBColor::fromHSV(hue, sat, 1.));
808  return true;
809  }
810  default:
811  return false;
812  }
813  */
814  return false;
815 }
816 
817 // ===========================================================================
818 // private
819 // ===========================================================================
820 
822  containerPlan(_containerPlan),
823  edge(nullptr),
824  arrivalPos(-1) {
825 }
826 
827 
829  containerPlan(nullptr),
830  edge(nullptr),
831  arrivalPos(-1) {
832 }
833 
834 
835 void
836 GNEContainer::setAttribute(SumoXMLAttr key, const std::string& value) {
837  // declare string error
838  std::string error;
839  switch (key) {
840  case SUMO_ATTR_ID:
841  // update microsimID
842  setMicrosimID(value);
843  // Change IDs of all container plans children
844  for (const auto& containerPlans : getChildDemandElements()) {
845  containerPlans->setMicrosimID(getID());
846  }
847  break;
848  case SUMO_ATTR_TYPE:
850  // set manually vtypeID (needed for saving)
851  vtypeid = value;
852  break;
853  case SUMO_ATTR_COLOR:
854  if (!value.empty() && (value != myTagProperty.getDefaultValue(key))) {
855  color = parse<RGBColor>(value);
856  // mark parameter as set
858  } else {
859  // set default value
860  color = parse<RGBColor>(myTagProperty.getDefaultValue(key));
861  // unset parameter
863  }
864  break;
865  case SUMO_ATTR_DEPARTPOS:
866  if (!value.empty() && (value != myTagProperty.getDefaultValue(key))) {
868  // mark parameter as set
870  } else {
871  // set default value
873  // unset parameter
875  }
876  // compute container
877  updateGeometry();
878  break;
879  // Specific of containers
880  case SUMO_ATTR_DEPART: {
882  break;
883  }
884  // Specific of containerFlows
885  case SUMO_ATTR_BEGIN: {
886  depart = string2time(value);
887  break;
888  }
889  case SUMO_ATTR_END:
890  repetitionEnd = string2time(value);
891  break;
893  repetitionOffset = TIME2STEPS(3600 / parse<double>(value));
894  break;
895  case SUMO_ATTR_PERIOD:
896  repetitionOffset = string2time(value);
897  break;
898  case SUMO_ATTR_PROB:
899  repetitionProbability = parse<double>(value);
900  break;
901  case SUMO_ATTR_NUMBER:
902  repetitionNumber = parse<int>(value);
903  break;
904  //
905  case GNE_ATTR_SELECTED:
906  if (parse<bool>(value)) {
908  } else {
910  }
911  break;
912  case GNE_ATTR_PARAMETERS:
913  setParametersStr(value);
914  break;
915  default:
916  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
917  }
918 }
919 
920 
921 void
922 GNEContainer::toogleAttribute(SumoXMLAttr key, const bool value, const int previousParameters) {
923  if (value) {
925  } else {
926  parametersSet = previousParameters;
927  }
928 }
929 
930 
931 void GNEContainer::setMoveShape(const GNEMoveResult& moveResult) {
932  // change departPos
934  departPos = moveResult.newFirstPos;
935  // update geometry
936  updateGeometry();
937 }
938 
939 
940 void
942  undoList->begin(GUIIcon::CONTAINER, "departPos of " + getTagStr());
943  // now set departPos
944  setAttribute(SUMO_ATTR_DEPARTPOS, toString(moveResult.newFirstPos), undoList);
945  undoList->end();
946 }
947 
948 /****************************************************************************/
FXDEFMAP(GNEContainer::GNEContainerPopupMenu) containerPopupMenuMap[]
@ MID_GNE_CONTAINER_TRANSFORM
transform container to another container type (ej: container to containerflow)
Definition: GUIAppEnum.h:1184
@ MID_COPY_TYPED_NAME
Copy typed object name - popup entry.
Definition: GUIAppEnum.h:413
@ MID_COPY_NAME
Copy object name - popup entry.
Definition: GUIAppEnum.h:411
@ GLO_MAX
empty max
@ GLO_CONTAINER
a container
@ GLO_CONTAINERFLOW
a person flow
@ CONTAINERFLOW
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
Definition: SUMOTime.cpp:45
#define STEPS2TIME(x)
Definition: SUMOTime.h:53
#define TIME2STEPS(x)
Definition: SUMOTime.h:55
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
const std::string DEFAULT_PEDTYPE_ID
@ PEDESTRIAN
render as a pedestrian
const int VEHPARS_PROB_SET
const int VEHPARS_VPH_SET
const int VEHPARS_END_SET
const int VEHPARS_COLOR_SET
DepartPosDefinition
Possible ways to choose the departure position.
@ GIVEN
The position is given.
const int VEHPARS_DEPARTPOS_SET
const int VEHPARS_NUMBER_SET
const int VEHPARS_PERIOD_SET
const int VEHPARS_VTYPE_SET
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_VTYPE
description of a vehicle/person/container type
@ SUMO_TAG_CONTAINERFLOW
@ SUMO_TAG_VEHICLE
description of a vehicle
@ SUMO_TAG_FLOW
a flow definitio nusing a from-to edges instead of a route (used by router)
@ SUMO_TAG_CONTAINER
@ GNE_TAG_WALK_ROUTE
@ SUMO_TAG_TRIP
a single trip definition (used by router)
@ SUMO_TAG_EDGE
begin/end of the description of an edge
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_NUMBER
@ SUMO_ATTR_DEPART
@ GNE_ATTR_SELECTED
element is selected
@ SUMO_ATTR_BEGIN
weights: time range begin
@ GNE_ATTR_PARAMETERS
parameters "key1=value1|key2=value2|...|keyN=valueN"
@ SUMO_ATTR_CONTAINERSPERHOUR
@ SUMO_ATTR_DEPARTPOS
@ SUMO_ATTR_PERIOD
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_PROB
@ SUMO_ATTR_TYPE
@ SUMO_ATTR_LENGTH
@ SUMO_ATTR_COLOR
A color information.
@ SUMO_ATTR_ID
@ SUMO_ATTR_IMGFILE
@ SUMO_ATTR_WIDTH
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
A class that stores a 2D geometrical boundary.
Definition: Boundary.h:39
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
Definition: Boundary.cpp:77
Boundary & grow(double by)
extends the boundary by the given amount
Definition: Boundary.cpp:299
static void setColor(const RGBColor &c)
Sets the gl-color to this value.
Definition: GLHelper.cpp:507
static void pushName(unsigned int name)
push Name
Definition: GLHelper.cpp:132
static void popMatrix()
pop matrix
Definition: GLHelper.cpp:123
static void popName()
pop Name
Definition: GLHelper.cpp:141
static void pushMatrix()
push matrix
Definition: GLHelper.cpp:114
static void drawTextSettings(const GUIVisualizationTextSettings &settings, const std::string &text, const Position &pos, const double scale, const double angle=0, const double layer=2048, const int align=0)
Definition: GLHelper.cpp:640
bool isAttributeCarrierSelected() const
check if attribute carrier is selected
friend class GNEChange_EnableAttribute
friend class GNEChange_Attribute
declare friend class
const std::string & getTagStr() const
get tag assigned to this object in string format
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
void unselectAttributeCarrier(const bool changeFlag=true)
unselect attribute carrier using GUIGlobalSelection
GNENet * myNet
pointer to net
GNENet * getNet() const
get pointer to net
void selectAttributeCarrier(const bool changeFlag=true)
select attribute carrier using GUIGlobalSelection
const GNETagProperties & myTagProperty
reference to tagProperty associated with this attribute carrier
class used in GUIGLObjectPopupMenu for container transformations
Definition: GNEContainer.h:38
long onCmdTransform(FXObject *obj, FXSelector, void *)
Called to transform the current container to another container type.
class used in GUIGLObjectPopupMenu for single container transformations
Definition: GNEContainer.h:70
long onCmdTransform(FXObject *obj, FXSelector, void *)
Called to transform the current container to another container type.
GNESelectedContainersPopupMenu(GNEContainer *container, const std::vector< GNEContainer * > &selectedContainer, GUIMainWindow &app, GUISUMOAbstractView &parent)
Constructor.
FXMenuCommand * myTransformToContainer
menu command for transform to container
Definition: GNEContainer.h:99
FXMenuCommand * myTransformToContainerFlow
menu command for transform to containerFlow
Definition: GNEContainer.h:102
Position getPositionInView() const
Returns position of demand element in view.
bool setFunctionalColor(int activeScheme) const
sets the color according to the current scheme index and some vehicle function
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
GNELane * getLastPathLane() const
get last path lane
void updateGeometry()
update pre-computed geometry information
std::string getBegin() const
get begin time of demand element
Position getAttributePosition(SumoXMLAttr key) const
Problem isDemandElementValid() const
check if current demand element is valid to be writed into XML (by default true, can be reimplemented...
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
const RGBColor & getColor() const
get color
GNEContainer(SumoXMLTag tag, GNENet *net)
default constructor
void toogleAttribute(SumoXMLAttr key, const bool value, const int previousParameters)
method for enable or disable the attribute and nothing else (used in GNEChange_EnableAttribute)
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
void setColor(const GUIVisualizationSettings &s) const
sets the color according to the currente settings
void drawPartialGL(const GUIVisualizationSettings &s, const GNELane *lane, const GNEPathManager::Segment *segment, const double offsetFront) const
Draws partial object.
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)
commit move shape
void writeDemandElement(OutputDevice &device) const
writte demand element element into a xml file
void computePathElement()
compute pathElement
void disableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
~GNEContainer()
destructor
std::string getDemandElementProblem() const
return a string with the current demand element problem (by default empty, can be reimplemented in ch...
std::string getParentName() const
Returns the name of the parent object.
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
void enableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
double getExaggeration(const GUIVisualizationSettings &s) const
return exaggeration asociated with this GLObject
SUMOVehicleClass getVClass() const
GNEMoveOperation * getMoveOperation()
get move operation
double getAttributeDouble(SumoXMLAttr key) const
bool isAttributeEnabled(SumoXMLAttr key) const
void setMoveShape(const GNEMoveResult &moveResult)
set move shape
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
GNELane * getFirstPathLane() const
get first path lane
const std::map< std::string, std::string > & getACParametersMap() const
get parameters map
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform demand element changes
void fixDemandElementProblem()
fix demand element problem (by default throw an exception, has to be reimplemented in children)
An Element which don't belongs to GNENet but has influency in the simulation.
void replaceDemandElementParent(SumoXMLTag tag, const std::string &value, const int parentIndex)
replace demand element parent
virtual Position getPositionInView() const =0
Returns position of demand element in view.
Problem
enum class for demandElement problems
const std::string & getID() const
get ID
const std::vector< GNEDemandElement * > & getChildDemandElements() const
return child demand elements
const std::vector< GNEDemandElement * > & getParentDemandElements() const
get parent demand elements
const std::vector< GNEEdge * > & getParentEdges() const
get parent edges
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:46
const PositionVector & getLaneShape() const
get elements shape
Definition: GNELane.cpp:131
move operation
move result
double newFirstPos
new first position
GNEDemandElement * retrieveDemandElement(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named demand element.
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:125
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:1964
PathElement()
default constructor
static void transformToContainerFlow(GNEContainer *originalContainer)
transform routeFlow over an existent route
static void setFlowParameters(const SumoXMLAttr attribute, int &parameters)
set flow parameters
static void transformToContainer(GNEContainer *originalContainer)
transform container functions
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
const std::string & getDefaultValue(SumoXMLAttr attr) const
return the default value of the attribute of an element
SumoXMLTag getXMLTag() const
get XML tag
bool isStopContainer() const
return true if tag correspond to a container stop element
void end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
void begin(GUIIcon icon, const std::string &description)
Begin undo command sub-group with current supermode. This begins a new group of commands that are tre...
void add(GNEChange *command, bool doit=false, bool merge=true)
Add new command, executing it if desired. The new command will be merged with the previous command if...
void changeAttribute(GNEChange_Attribute *change)
special method for change attributes, avoid empty changes, always execute
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:537
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:513
const GNEViewNetHelper::NetworkViewOptions & getNetworkViewOptions() const
get network view options
Definition: GNEViewNet.cpp:525
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, double typeOrLayer, const double extraOffset=0)
draw front attributeCarrier
const std::vector< GNEAttributeCarrier * > & getInspectedAttributeCarriers() const
get inspected attribute carriers
void buildSelectionACPopupEntry(GUIGLObjectPopupMenu *ret, GNEAttributeCarrier *AC)
Builds an entry which allows to (de)select the object.
Definition: GNEViewNet.cpp:432
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
const GNEViewNetHelper::DemandViewOptions & getDemandViewOptions() const
get demand view options
Definition: GNEViewNet.cpp:531
static void drawAction_drawAsImage(const double angle, const double length, const double width, const std::string &file, const SUMOVehicleShape guiShape, const double exaggeration)
static void drawAction_drawAsCircle(const double length, const double width, double detail)
static void drawAction_drawAsTriangle(const double angle, const double length, const double width)
static FXMenuCommand * buildFXMenuCommand(FXComposite *p, const std::string &text, FXIcon *icon, FXObject *tgt, FXSelector sel)
build menu command
Definition: GUIDesigns.cpp:42
static void drawDottedSquaredShape(const DottedContourType type, const GUIVisualizationSettings &s, const Position &pos, const double width, const double height, const double offsetX, const double offsetY, const double rot, const double exaggeration)
draw dotted squared contour (used by additionals and demand elements)
The popup menu of a globject.
void insertMenuPaneChild(FXMenuPane *child)
Insert a sub-menu pane in this GUIGLObjectPopupMenu.
void buildPositionCopyEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to copy the cursor position if geo projection is used,...
virtual double getColorValue(const GUIVisualizationSettings &, int) const
Definition: GUIGlObject.h:152
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
virtual void setMicrosimID(const std::string &newID)
Changes the microsimID of the object.
void buildCenterPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to center to the object.
void buildPopupHeader(GUIGLObjectPopupMenu *ret, GUIMainWindow &app, bool addSeparator=true)
Builds the header.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
GUIGlID getGlID() const
Returns the numerical id of the object.
void drawName(const Position &pos, const double scale, const GUIVisualizationTextSettings &settings, const double angle=0, bool forceShow=false) const
draw name of item
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
const T getColor(const double value) const
Position getPositionInformation() const
Returns the cursor's x/y position within the network.
Stores the information about how to visualize structures.
GUIVisualizationSizeSettings containerSize
GUIVisualizationTextSettings personValue
GUIVisualizationDetailSettings detailSettings
detail settings
bool drawForPositionSelection
whether drawing is performed for the purpose of selecting objects with a single click
double scale
information about a lane's width (temporary, used for a single view)
bool drawDetail(const double detail, const double exaggeration) const
check if details can be drawn for the given GUIVisualizationDetailSettings and current scale and exxa...
GUIVisualizationTextSettings containerName
GUIColorer containerColorer
The container colorer.
double angle
The current view rotation angle.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:248
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static bool areParametersValid(const std::string &value, bool report=false, const std::string kvsep="=", const std::string sep="|")
check if given string can be parsed to a parameters map "key1=value1|key2=value2|....
void setParametersStr(const std::string &paramsString, const std::string kvsep="=", const std::string sep="|")
set the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN"
void writeParams(OutputDevice &device) const
write Params in the given outputdevice
std::string getParametersStr(const std::string kvsep="=", const std::string sep="|") const
Returns the inner key/value map in string format "key1=value1|key2=value2|...|keyN=valueN".
const std::map< std::string, std::string > & getParametersMap() const
Returns the inner key/value map.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
double distanceSquaredTo(const Position &p2) const
returns the square of the distance to another position
Definition: Position.h:247
double x() const
Returns the x-position.
Definition: Position.h:55
double y() const
Returns the y-position.
Definition: Position.h:60
double length2D() const
Returns the length.
Position positionAtOffset2D(double pos, double lateralOffset=0) const
Returns the position at the given length.
Structure representing possible vehicle parameter.
double repetitionProbability
The probability for emitting a vehicle per second.
int parametersSet
Information for the router which parameter were set, TraCI may modify this (when changing color)
SumoXMLTag tag
The vehicle tag.
std::string vtypeid
The vehicle's type id.
SUMOTime repetitionOffset
The time offset between vehicle reinsertions.
std::vector< std::string > via
List of the via-edges the vehicle must visit.
void write(OutputDevice &dev, const OptionsCont &oc, const SumoXMLTag altTag=SUMO_TAG_VEHICLE, const std::string &typeID="") const
Writes the parameters as a beginning element.
SUMOTime repetitionEnd
The time at which the flow ends (only needed when using repetitionProbability)
std::string getDepart() const
obtain depart parameter in string format
double departPos
(optional) The position the vehicle shall depart from
RGBColor color
The vehicle's color, TraCI may change this.
double arrivalPos
(optional) The position the vehicle shall arrive on
static bool parseDepart(const std::string &val, const std::string &element, const std::string &id, SUMOTime &depart, DepartDefinition &dd, std::string &error, const std::string &attr="departure")
Validates a given depart value.
bool wasSet(int what) const
Returns whether the given parameter was set.
std::string getDepartPos() const
obtain depart pos parameter in string format
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
static bool parseDepartPos(const std::string &val, const std::string &element, const std::string &id, double &pos, DepartPosDefinition &dpd, std::string &error)
Validates a given departPos value.
DepartPosDefinition departPosProcedure
Information how the vehicle shall choose the departure position.
static bool isValidTypeID(const std::string &value)
whether the given string is a valid id for an edge or vehicle type
static bool isValidVehicleID(const std::string &value)
whether the given string is a valid id for a vehicle or flow
bool showDemandElements() const
check if show demand elements checkbox is enabled
bool showNonInspectedDemandElements(const GNEDemandElement *demandElement) const
check if non inspected element has to be hidden
bool isCurrentSupermodeDemand() const
@check if current supermode is Demand
static void drawLockIcon(const GNEAttributeCarrier *AC, GUIGlObjectType type, const Position viewPosition, const double exaggeration, const double size=0.5, const double offsetx=0, const double offsety=0)
draw lock icon
bool showDemandElements() const
check if show demand elements checkbox is enabled
static const double personShapes
details for draw person as person shapes
static const double personTriangles
details for draw person as triangles
static const double personCircles
details for draw person as circles
static const double personExaggeration
Exaggeration for persons (only used in NETEDIT)
double getExaggeration(const GUIVisualizationSettings &s, const GUIGlObject *o, double factor=20) const
return the drawing size including exaggeration and constantSize values
bool show(const GUIGlObject *o) const
whether to show the text
double scaledSize(double scale, double constFactor=0.1) const
get scale size