Eclipse SUMO - Simulation of Urban MObility
GNEPerson.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-2020 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 persons 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 "GNEPerson.h"
34 #include "GNERouteHandler.h"
35 
36 
37 // ===========================================================================
38 // FOX callback mapping
39 // ===========================================================================
40 FXDEFMAP(GNEPerson::GNEPersonPopupMenu) personPopupMenuMap[] = {
42 };
43 
44 FXDEFMAP(GNEPerson::GNESelectedPersonsPopupMenu) selectedPersonsPopupMenuMap[] = {
46 };
47 
48 // Object implementation
49 FXIMPLEMENT(GNEPerson::GNEPersonPopupMenu, GUIGLObjectPopupMenu, personPopupMenuMap, ARRAYNUMBER(personPopupMenuMap))
50 FXIMPLEMENT(GNEPerson::GNESelectedPersonsPopupMenu, GUIGLObjectPopupMenu, selectedPersonsPopupMenuMap, ARRAYNUMBER(selectedPersonsPopupMenuMap))
51 
52 // ===========================================================================
53 // GNEPerson::GNEPersonPopupMenu
54 // ===========================================================================
55 
57  GUIGLObjectPopupMenu(app, parent, *person),
58  myPerson(person),
59  myTransformToPerson(nullptr),
60  myTransformToPersonFlow(nullptr) {
61  // build header
62  myPerson->buildPopupHeader(this, app);
63  // build menu command for center button and copy cursor position to clipboard
64  myPerson->buildCenterPopupEntry(this);
65  myPerson->buildPositionCopyEntry(this, false);
66  // buld menu commands for names
67  GUIDesigns::buildFXMenuCommand(this, ("Copy " + myPerson->getTagStr() + " name to clipboard").c_str(), nullptr, this, MID_COPY_NAME);
68  GUIDesigns::buildFXMenuCommand(this, ("Copy " + myPerson->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  myPerson->getNet()->getViewNet()->buildSelectionACPopupEntry(this, myPerson);
72  myPerson->buildShowParamsPopupEntry(this);
73  // add transform functions only in demand mode
74  if (myPerson->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  myTransformToPerson = GUIDesigns::buildFXMenuCommand(transformOperation, "Person", GUIIconSubSys::getIcon(GUIIcon::PERSON), this, MID_GNE_PERSON_TRANSFORM);
81  myTransformToPersonFlow = GUIDesigns::buildFXMenuCommand(transformOperation, "Person (embedded route)", GUIIconSubSys::getIcon(GUIIcon::PERSONFLOW), this, MID_GNE_PERSON_TRANSFORM);
82  // check what menu command has to be disabled
83  if (myPerson->getTagProperty().getTag() == SUMO_TAG_PERSON) {
84  myTransformToPerson->disable();
85  } else if (myPerson->getTagProperty().getTag() == SUMO_TAG_PERSONFLOW) {
86  myTransformToPersonFlow->disable();
87  }
88  }
89 }
90 
91 
93 
94 
95 long
96 GNEPerson::GNEPersonPopupMenu::onCmdTransform(FXObject* obj, FXSelector, void*) {
97  if (obj == myTransformToPerson) {
99  } else if (obj == myTransformToPersonFlow) {
101  }
102  return 1;
103 }
104 
105 
106 // ===========================================================================
107 // GNEPerson::GNESelectedPersonsPopupMenu
108 // ===========================================================================
109 
110 GNEPerson::GNESelectedPersonsPopupMenu::GNESelectedPersonsPopupMenu(GNEPerson* person, const std::vector<GNEPerson*>& selectedPerson, GUIMainWindow& app, GUISUMOAbstractView& parent) :
111  GUIGLObjectPopupMenu(app, parent, *person),
112  myPersonTag(person->getTagProperty().getTag()),
113  mySelectedPersons(selectedPerson),
114  myTransformToPerson(nullptr),
115  myTransformToPersonFlow(nullptr) {
116  // build header
117  person->buildPopupHeader(this, app);
118  // build menu command for center button and copy cursor position to clipboard
119  person->buildCenterPopupEntry(this);
120  person->buildPositionCopyEntry(this, false);
121  // buld menu commands for names
122  GUIDesigns::buildFXMenuCommand(this, ("Copy " + person->getTagStr() + " name to clipboard").c_str(), nullptr, this, MID_COPY_NAME);
123  GUIDesigns::buildFXMenuCommand(this, ("Copy " + person->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  person->getNet()->getViewNet()->buildSelectionACPopupEntry(this, person);
127  person->buildShowParamsPopupEntry(this);
128  // add transform functions only in demand mode
129  if (person->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 persons
147  for (const auto& i : mySelectedPersons) {
148  if ((obj == myTransformToPerson) &&
149  (i->getTagProperty().getTag() == myPersonTag)) {
151  } else if ((obj == myTransformToPersonFlow) &&
152  (i->getTagProperty().getTag() == myPersonTag)) {
154  }
155  }
156  return 1;
157 }
158 
159 // ===========================================================================
160 // member method definitions
161 // ===========================================================================
162 
164  GNEDemandElement(personparameters.id, net, (tag == SUMO_TAG_PERSONFLOW) ? GLO_PERSONFLOW : GLO_PERSON, tag,
165 {}, {}, {}, {}, {}, {}, {pType}, {}),
166 SUMOVehicleParameter(personparameters) {
167  // set manually vtypeID (needed for saving)
168  vtypeid = pType->getID();
169 }
170 
171 
173 
174 
175 std::string
177  // obtain depart depending if is a Person, trip or routeFlow
178  std::string departStr;
180  departStr = toString(depart);
181  } else {
182  departStr = getDepart();
183  }
184  // we need to handle depart as a tuple of 20 numbers (format: 000000...00<departTime>)
185  departStr.reserve(20 - departStr.size());
186  // add 0s at the beginning of departStr until we have 20 numbers
187  for (int i = (int)departStr.size(); i < 20; i++) {
188  departStr.insert(departStr.begin(), '0');
189  }
190  return departStr;
191 }
192 
193 
194 void
196  // obtain tag depending if tagProperty has a synonym
198  // attribute VType musn't be written if is DEFAULT_PEDTYPE_ID
200  // unset VType parameter
202  // write person attributes (VType will not be written)
203  write(device, OptionsCont::getOptions(), synonymTag);
204  // set VType parameter again
206  } else {
207  // write person attributes, including VType
208  write(device, OptionsCont::getOptions(), synonymTag, getParentDemandElements().at(0)->getID());
209  }
210  // write specific flow attributes
212  // write routeFlow values depending if it was set
215  }
218  }
221  }
224  }
227  }
228  }
229  // write parameters
230  writeParams(device);
231  // write child demand elements associated to this person (Rides, Walks...)
232  for (const auto& i : getChildDemandElements()) {
233  i->writeDemandElement(device);
234  }
235  // close person tag
236  device.closeTag();
237 }
238 
239 
240 bool
242  // a single person is always valid
243  return true;
244 }
245 
246 
247 std::string
249  // A single person cannot habe problem (but their children)
250  return "";
251 }
252 
253 
254 void
256  // nothing to fix
257 }
258 
259 
262  return getParentDemandElements().front()->getVClass();
263 }
264 
265 
266 const RGBColor&
268  return color;
269 }
270 
271 
272 void
274  // Persons cannot be moved
275 }
276 
277 
278 void
280  // Persons cannot be moved
281 }
282 
283 
284 void
286  // Persons cannot be moved
287 }
288 
289 
290 void
292  // Persons cannot be moved
293 }
294 
295 
296 void
298  // only update geometry of childrens
299  for (const auto& i : getChildDemandElements()) {
300  i->updateGeometry();
301  }
302 }
303 
304 
305 void
307  // nothing to compute
308 }
309 
310 
311 void
313  // nothing to invalidate
314 }
315 
316 
317 Position
319  // Position in view depend of first child element
320  if (getChildDemandElements().size() > 0) {
321  if (getChildDemandElements().at(0)->getTagProperty().isPersonStop()) {
322  return getChildDemandElements().at(0)->getDemandElementGeometry().getShape().getLineCenter();
323  } else {
324  // obtain lane (special case for rides)
325  SUMOVehicleClass vClassEdgeFrom = getChildDemandElements().front()->getTagProperty().isRide() ? SVC_PASSENGER : SVC_PEDESTRIAN;
326  GNELane* lane = getChildDemandElements().at(0)->getParentEdges().at(0)->getLaneByAllowedVClass(vClassEdgeFrom);
327  // return position in view depending of lane
328  if (lane->getLaneShape().length() < 2.5) {
329  return lane->getLaneShape().front();
330  } else {
331  Position A = lane->getLaneShape().positionAtOffset(2.5);
332  Position B = lane->getLaneShape().positionAtOffset(2.5);
333  // return Middle point
334  return Position((A.x() + B.x()) / 2, (A.y() + B.y()) / 2);
335  }
336  }
337  } else {
338  return Position(0, 0);
339  }
340 }
341 
342 
345  // return a GNEPersonPopupMenu
346  return new GNEPersonPopupMenu(this, app, parent);
347 }
348 
349 
350 std::string
352  return getParentDemandElements().front()->getID();
353 }
354 
355 
356 Boundary
358  Boundary personBoundary;
359  if (getChildDemandElements().size() > 0) {
360  if (getChildDemandElements().front()->getTagProperty().isPersonStop()) {
361  // use boundary of stop center
362  return getChildDemandElements().front()->getCenteringBoundary();
363  } else {
364  // obtain boundary of first position over edge
365  personBoundary.add(getChildDemandElements().front()->getDemandElementSegmentGeometry().getFirstPosition());
366  }
367  } else {
368  personBoundary = Boundary(-0.1, -0.1, 0.1, 0.1);
369  }
370  personBoundary.grow(20);
371  return personBoundary;
372 }
373 
374 
375 void
376 GNEPerson::splitEdgeGeometry(const double /*splitPosition*/, const GNENetworkElement* /*originalElement*/, const GNENetworkElement* /*newElement*/, GNEUndoList* /*undoList*/) {
377  // geometry of this element cannot be splitted
378 }
379 
380 
381 void
383  bool drawPerson = true;
384  // check if person can be drawn
386  drawPerson = false;
388  drawPerson = false;
390  drawPerson = false;
391  } else if (getChildDemandElements().empty()) {
392  drawPerson = false;
393  }
394  // continue if person can be drawn
395  if (drawPerson) {
396  // obtain exaggeration (and add the special personExaggeration)
397  const double exaggeration = s.personSize.getExaggeration(s, this, 80) + s.detailSettings.personExaggeration;
398  // obtain width and length
399  const double length = getParentDemandElements().at(0)->getAttributeDouble(SUMO_ATTR_LENGTH);
400  const double width = getParentDemandElements().at(0)->getAttributeDouble(SUMO_ATTR_WIDTH);
401  // obtain diameter around person (used to calculate distance bewteen cursor and person)
402  const double distanceSquared = pow(exaggeration * std::max(length, width), 2);
403  // obtain img file
404  const std::string file = getParentDemandElements().at(0)->getAttribute(SUMO_ATTR_IMGFILE);
405  Position personPosition;
406  // obtain position depending of first PersonPlan child
407  if (getChildDemandElements().front()->getTagProperty().isPersonStop()) {
408  // obtain position of stop center
409  personPosition = getChildDemandElements().front()->getPositionInView();
410  } else {
411  // obtain position of first edge
412  personPosition = getChildDemandElements().front()->getDemandElementSegmentGeometry().getFirstPosition();
413  }
414  // check that position is valid and person can be drawn
415  if ((personPosition != Position::INVALID) &&
416  !(s.drawForPositionSelection && (personPosition.distanceSquaredTo(myNet->getViewNet()->getPositionInformation()) > distanceSquared))) {
417  // push GL ID
418  glPushName(getGlID());
419  // push draw matrix
420  glPushMatrix();
421  // Start with the drawing of the area traslating matrix to origin
423  // translate and rotate
424  glTranslated(personPosition.x(), personPosition.y(), 0);
425  glRotated(90, 0, 0, 1);
426  // set person color
427  setColor(s);
428  // set scale
429  glScaled(exaggeration, exaggeration, 1);
430  // draw person depending of detail level
431  if (s.drawDetail(s.detailSettings.personShapes, exaggeration)) {
432  GUIBasePersonHelper::drawAction_drawAsImage(0, length, width, file, SVS_PEDESTRIAN, exaggeration);
433  } else if (s.drawDetail(s.detailSettings.personCircles, exaggeration)) {
435  } else if (s.drawDetail(s.detailSettings.personTriangles, exaggeration)) {
437  }
438  // pop matrix
439  glPopMatrix();
440  // pop name
441  glPopName();
442  // draw name
443  drawName(personPosition, s.scale, s.personName, s.angle);
444  if (s.personValue.show) {
445  Position personValuePosition = personPosition + Position(0, 0.6 * s.personName.scaledSize(s.scale));
446  const double value = getColorValue(s, s.personColorer.getActive());
447  GLHelper::drawTextSettings(s.personValue, toString(value), personValuePosition, s.scale, s.angle, GLO_MAX - getType());
448  }
449  // check if dotted contours has to be drawn
451  // draw using drawDottedSquaredShape
452  GNEGeometry::drawDottedSquaredShape(GNEGeometry::DottedContourType::INSPECT, s, personPosition, 0.5, 0.5, 0, 0, 0, exaggeration);
453  }
454  if (s.drawDottedContour() || myNet->getViewNet()->getFrontAttributeCarrier() == this) {
455  // draw using drawDottedSquaredShape
456  GNEGeometry::drawDottedSquaredShape(GNEGeometry::DottedContourType::FRONT, s, personPosition, 0.5, 0.5, 0, 0, 0, exaggeration);
457  }
458  }
459  }
460 }
461 
462 
463 void
464 GNEPerson::drawPartialGL(const GUIVisualizationSettings& /*s*/, const GNELane* /*lane*/, const double /*offsetFront*/) const {
465  // Stops don't use drawPartialGL
466 }
467 
468 
469 void
470 GNEPerson::drawPartialGL(const GUIVisualizationSettings& /*s*/, const GNELane* /*fromLane*/, const GNELane* /*toLane*/, const double /*offsetFront*/) const {
471  // Stops don't use drawPartialGL
472 }
473 
474 
475 std::string
477  // declare string error
478  std::string error;
479  switch (key) {
480  case SUMO_ATTR_ID:
481  return getID();
482  case SUMO_ATTR_TYPE:
483  return getParentDemandElements().at(0)->getID();
484  case SUMO_ATTR_COLOR:
485  if (wasSet(VEHPARS_COLOR_SET)) {
486  return toString(color);
487  } else {
489  }
490  case SUMO_ATTR_DEPARTPOS:
492  return getDepartPos();
493  } else {
495  }
496  // Specific of persons
497  case SUMO_ATTR_DEPART:
498  return toString(depart);
499  // Specific of personFlows
500  case SUMO_ATTR_BEGIN:
501  return time2string(depart);
502  case SUMO_ATTR_END:
503  return time2string(repetitionEnd);
505  return toString(3600 / STEPS2TIME(repetitionOffset));
506  case SUMO_ATTR_PERIOD:
508  case SUMO_ATTR_PROB:
510  case SUMO_ATTR_NUMBER:
511  return toString(repetitionNumber);
512  //
513  case GNE_ATTR_SELECTED:
515  case GNE_ATTR_PARAMETERS:
516  return getParametersStr();
517  default:
518  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
519  }
520 }
521 
522 
523 double
525  switch (key) {
526  case SUMO_ATTR_DEPARTPOS:
528  return departPos;
529  } else {
530  return 0;
531  }
532  default:
533  throw InvalidArgument(getTagStr() + " doesn't have a double attribute of type '" + toString(key) + "'");
534  }
535 }
536 
537 
538 void
539 GNEPerson::setAttribute(SumoXMLAttr key, const std::string& value, GNEUndoList* undoList) {
540  if (value == getAttribute(key)) {
541  return; //avoid needless changes, later logic relies on the fact that attributes have changed
542  }
543  switch (key) {
544  case SUMO_ATTR_ID:
545  case SUMO_ATTR_TYPE:
546  case SUMO_ATTR_COLOR:
547  case SUMO_ATTR_DEPARTPOS:
548  // Specific of persons
549  case SUMO_ATTR_DEPART:
550  // Specific of personFlows
551  case SUMO_ATTR_BEGIN:
552  case SUMO_ATTR_END:
553  case SUMO_ATTR_NUMBER:
555  case SUMO_ATTR_PERIOD:
556  case SUMO_ATTR_PROB:
557  //
558  case GNE_ATTR_PARAMETERS:
559  case GNE_ATTR_SELECTED:
560  undoList->p_add(new GNEChange_Attribute(this, key, value));
561  break;
562  default:
563  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
564  }
565 }
566 
567 
568 bool
569 GNEPerson::isValid(SumoXMLAttr key, const std::string& value) {
570  // declare string error
571  std::string error;
572  switch (key) {
573  case SUMO_ATTR_ID:
574  // Persons and personflows share namespace
576  (myNet->retrieveDemandElement(SUMO_TAG_PERSON, value, false) == nullptr) &&
577  (myNet->retrieveDemandElement(SUMO_TAG_PERSONFLOW, value, false) == nullptr)) {
578  return true;
579  } else {
580  return false;
581  }
582  case SUMO_ATTR_TYPE:
583  return SUMOXMLDefinitions::isValidTypeID(value) && (myNet->retrieveDemandElement(SUMO_TAG_VTYPE, value, false) != nullptr);
584  case SUMO_ATTR_COLOR:
585  return canParse<RGBColor>(value);
586  case SUMO_ATTR_DEPARTPOS: {
587  double dummyDepartPos;
588  DepartPosDefinition dummyDepartPosProcedure;
589  parseDepartPos(value, toString(SUMO_TAG_VEHICLE), id, dummyDepartPos, dummyDepartPosProcedure, error);
590  // if error is empty, given value is valid
591  return error.empty();
592  }
593  // Specific of persons
594  case SUMO_ATTR_DEPART: {
595  if (canParse<double>(value)) {
596  return (parse<double>(value) >= 0);
597  } else {
598  return false;
599  }
600  }
601  // Specific of personflows
602  case SUMO_ATTR_BEGIN:
603  if (canParse<double>(value)) {
604  return (parse<double>(value) >= 0);
605  } else {
606  return false;
607  }
608  case SUMO_ATTR_END:
609  if (value.empty()) {
610  return true;
611  } else if (canParse<double>(value)) {
612  return (parse<double>(value) >= 0);
613  } else {
614  return false;
615  }
617  if (value.empty()) {
618  return true;
619  } else if (canParse<double>(value)) {
620  return (parse<double>(value) > 0);
621  } else {
622  return false;
623  }
624  case SUMO_ATTR_PERIOD:
625  if (value.empty()) {
626  return true;
627  } else if (canParse<double>(value)) {
628  return (parse<double>(value) > 0);
629  } else {
630  return false;
631  }
632  case SUMO_ATTR_PROB:
633  if (value.empty()) {
634  return true;
635  } else if (canParse<double>(value)) {
636  return (parse<double>(value) >= 0);
637  } else {
638  return false;
639  }
640  case SUMO_ATTR_NUMBER:
641  if (canParse<int>(value)) {
642  return (parse<int>(value) >= 0);
643  } else {
644  return false;
645  }
646  //
647  case GNE_ATTR_SELECTED:
648  return canParse<bool>(value);
649  case GNE_ATTR_PARAMETERS:
650  return Parameterised::areParametersValid(value);
651  default:
652  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
653  }
654 }
655 
656 
657 void
659  // obtain a copy of parameter sets
660  int newParametersSet = parametersSet;
661  // modify newParametersSet
662  GNERouteHandler::setFlowParameters(key, newParametersSet);
663  // add GNEChange_EnableAttribute
664  undoList->add(new GNEChange_EnableAttribute(this, parametersSet, newParametersSet), true);
665 }
666 
667 
668 void
670  // nothing to disable
671 }
672 
673 
674 bool
676  switch (key) {
677  case SUMO_ATTR_END:
678  return (parametersSet & VEHPARS_END_SET) != 0;
679  case SUMO_ATTR_NUMBER:
680  return (parametersSet & VEHPARS_NUMBER_SET) != 0;
682  return (parametersSet & VEHPARS_VPH_SET) != 0;
683  case SUMO_ATTR_PERIOD:
684  return (parametersSet & VEHPARS_PERIOD_SET) != 0;
685  case SUMO_ATTR_PROB:
686  return (parametersSet & VEHPARS_PROB_SET) != 0;
687  default:
688  return true;
689  }
690 }
691 
692 
693 std::string
695  return getTagStr();
696 }
697 
698 
699 std::string
701  // special case for Trips and flow
703  // check if we're inspecting a Edge
704  if (myNet->getViewNet()->getInspectedAttributeCarriers().front() &&
705  myNet->getViewNet()->getInspectedAttributeCarriers().front()->getTagProperty().getTag() == SUMO_TAG_EDGE) {
706  // check if edge correspond to a "from", "to" or "via" edge
708  return getTagStr() + ": " + getAttribute(SUMO_ATTR_ID) + " (from)";
709  } else if (myNet->getViewNet()->isAttributeCarrierInspected(getParentEdges().front())) {
710  return getTagStr() + ": " + getAttribute(SUMO_ATTR_ID) + " (to)";
711  } else {
712  // iterate over via
713  for (const auto& i : via) {
714  if (i == myNet->getViewNet()->getInspectedAttributeCarriers().front()->getID()) {
715  return getTagStr() + ": " + getAttribute(SUMO_ATTR_ID) + " (via)";
716  }
717  }
718  }
719  }
720  }
721  return getTagStr() + ": " + getAttribute(SUMO_ATTR_ID);
722 }
723 
724 
725 const std::map<std::string, std::string>&
727  return getParametersMap();
728 }
729 
730 // ===========================================================================
731 // protected
732 // ===========================================================================
733 
734 void
736  const GUIColorer& c = s.personColorer;
737  if (!setFunctionalColor(c.getActive())) {
739  }
740 }
741 
742 
743 bool
744 GNEPerson::setFunctionalColor(int /* activeScheme */) const {
745  /*
746  switch (activeScheme) {
747  case 0: {
748  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
749  GLHelper::setColor(getParameter().color);
750  return true;
751  }
752  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
753  GLHelper::setColor(getVehicleType().getColor());
754  return true;
755  }
756  return false;
757  }
758  case 2: {
759  if (getParameter().wasSet(VEHPARS_COLOR_SET)) {
760  GLHelper::setColor(getParameter().color);
761  return true;
762  }
763  return false;
764  }
765  case 3: {
766  if (getVehicleType().wasSet(VTYPEPARS_COLOR_SET)) {
767  GLHelper::setColor(getVehicleType().getColor());
768  return true;
769  }
770  return false;
771  }
772  case 8: { // color by angle
773  double hue = GeomHelper::naviDegree(getAngle());
774  GLHelper::setColor(RGBColor::fromHSV(hue, 1., 1.));
775  return true;
776  }
777  case 9: { // color randomly (by pointer)
778  const double hue = (long)this % 360; // [0-360]
779  const double sat = (((long)this / 360) % 67) / 100.0 + 0.33; // [0.33-1]
780  GLHelper::setColor(RGBColor::fromHSV(hue, sat, 1.));
781  return true;
782  }
783  default:
784  return false;
785  }
786  */
787  return false;
788 }
789 
790 // ===========================================================================
791 // private
792 // ===========================================================================
793 
795  personPlan(_personPlan),
796  edge(nullptr),
797  arrivalPos(-1) {
798 }
799 
800 
802  personPlan(nullptr),
803  edge(nullptr),
804  arrivalPos(-1) {
805 }
806 
807 
808 void
809 GNEPerson::setAttribute(SumoXMLAttr key, const std::string& value) {
810  // declare string error
811  std::string error;
812  switch (key) {
813  case SUMO_ATTR_ID:
814  myNet->getAttributeCarriers()->updateID(this, value);
815  // Change IDs of all person plans children
816  for (const auto& personPlans : getChildDemandElements()) {
817  personPlans->setMicrosimID(getID());
818  }
819  break;
820  case SUMO_ATTR_TYPE:
822  // set manually vtypeID (needed for saving)
823  vtypeid = value;
824  break;
825  case SUMO_ATTR_COLOR:
826  if (!value.empty() && (value != myTagProperty.getDefaultValue(key))) {
827  color = parse<RGBColor>(value);
828  // mark parameter as set
830  } else {
831  // set default value
832  color = parse<RGBColor>(myTagProperty.getDefaultValue(key));
833  // unset parameter
835  }
836  break;
837  case SUMO_ATTR_DEPARTPOS:
838  if (!value.empty() && (value != myTagProperty.getDefaultValue(key))) {
840  // mark parameter as set
842  } else {
843  // set default value
845  // unset parameter
847  }
848  // compute person
849  updateGeometry();
850  break;
851  // Specific of persons
852  case SUMO_ATTR_DEPART: {
854  break;
855  }
856  // Specific of personFlows
857  case SUMO_ATTR_BEGIN: {
858  depart = string2time(value);
859  break;
860  }
861  case SUMO_ATTR_END:
862  repetitionEnd = string2time(value);
863  break;
865  repetitionOffset = TIME2STEPS(3600 / parse<double>(value));
866  break;
867  case SUMO_ATTR_PERIOD:
868  repetitionOffset = string2time(value);
869  break;
870  case SUMO_ATTR_PROB:
871  repetitionProbability = parse<double>(value);
872  break;
873  case SUMO_ATTR_NUMBER:
874  repetitionNumber = parse<int>(value);
875  break;
876  //
877  case GNE_ATTR_SELECTED:
878  if (parse<bool>(value)) {
880  } else {
882  }
883  break;
884  case GNE_ATTR_PARAMETERS:
885  setParametersStr(value);
886  break;
887  default:
888  throw InvalidArgument(getTagStr() + " doesn't have an attribute of type '" + toString(key) + "'");
889  }
890 }
891 
892 
893 void
894 GNEPerson::setEnabledAttribute(const int enabledAttributes) {
895  parametersSet = enabledAttributes;
896 }
897 
898 
899 /****************************************************************************/
FXDEFMAP(GNEPerson::GNEPersonPopupMenu) personPopupMenuMap[]
@ MID_COPY_TYPED_NAME
Copy typed object name - popup entry.
Definition: GUIAppEnum.h:403
@ MID_GNE_PERSON_TRANSFORM
transform person to another person type (ej: person to personflow)
Definition: GUIAppEnum.h:1085
@ MID_COPY_NAME
Copy object name - popup entry.
Definition: GUIAppEnum.h:401
@ GLO_MAX
empty max
@ GLO_PERSON
a person
@ GLO_PERSONFLOW
a person flow
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.
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
@ SVC_PEDESTRIAN
pedestrian
const std::string DEFAULT_PEDTYPE_ID
@ SVS_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 type
@ 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_PERSON
@ SUMO_TAG_PTYPE
description of a person type (used in NETEDIT)
@ SUMO_TAG_PERSONFLOW
@ 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_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
@ SUMO_ATTR_PERSONSPERHOUR
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:44
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:446
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:529
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 Tag Property assigned to this object
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
the xml tag to which this attribute carrier corresponds
An Element which don't belongs to GNENet but has influency in the simulation.
const GNEGeometry::SegmentGeometry & getDemandElementSegmentGeometry() const
get demand element segment geometry (stacked)
void replaceDemandElementParent(SumoXMLTag tag, const std::string &value, const int parentIndex)
replace demand element parent
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:45
const PositionVector & getLaneShape() const
Definition: GNELane.cpp:117
void updateID(GNEAttributeCarrier *AC, const std::string newID)
update ID
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:40
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
retrieve all attribute carriers of Net
Definition: GNENet.cpp:130
GNEDemandElement * retrieveDemandElement(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named demand element.
Definition: GNENet.cpp:2435
GNEViewNet * getViewNet() const
get view net
Definition: GNENet.cpp:2245
class used in GUIGLObjectPopupMenu for person transformations
Definition: GNEPerson.h:37
long onCmdTransform(FXObject *obj, FXSelector, void *)
Called to transform the current person to another person type.
Definition: GNEPerson.cpp:96
~GNEPersonPopupMenu()
Destructor.
Definition: GNEPerson.cpp:92
class used in GUIGLObjectPopupMenu for single person transformations
Definition: GNEPerson.h:69
GNESelectedPersonsPopupMenu(GNEPerson *person, const std::vector< GNEPerson * > &selectedPerson, GUIMainWindow &app, GUISUMOAbstractView &parent)
Constructor.
Definition: GNEPerson.cpp:110
long onCmdTransform(FXObject *obj, FXSelector, void *)
Called to transform the current person to another person type.
Definition: GNEPerson.cpp:145
FXMenuCommand * myTransformToPerson
menu command for transform to person
Definition: GNEPerson.h:98
FXMenuCommand * myTransformToPersonFlow
menu command for transform to personFlow
Definition: GNEPerson.h:101
void drawPartialGL(const GUIVisualizationSettings &s, const GNELane *lane, const double offsetFront) const
Draws partial object.
Definition: GNEPerson.cpp:464
void drawGL(const GUIVisualizationSettings &s) const
Draws the object.
Definition: GNEPerson.cpp:382
Position getPositionInView() const
Returns position of demand element in view.
Definition: GNEPerson.cpp:318
GNEPerson(SumoXMLTag tag, GNENet *net, GNEDemandElement *pType, const SUMOVehicleParameter &personparameters)
constructor for persons
Definition: GNEPerson.cpp:163
void updateGeometry()
update pre-computed geometry information
Definition: GNEPerson.cpp:297
const RGBColor & getColor() const
get color
Definition: GNEPerson.cpp:267
bool isAttributeEnabled(SumoXMLAttr key) const
Definition: GNEPerson.cpp:675
void writeDemandElement(OutputDevice &device) const
writte demand element element into a xml file
Definition: GNEPerson.cpp:195
void endGeometryMoving()
end geometry movement
Definition: GNEPerson.cpp:279
void setColor(const GUIVisualizationSettings &s) const
sets the color according to the currente settings
Definition: GNEPerson.cpp:735
void fixDemandElementProblem()
fix demand element problem (by default throw an exception, has to be reimplemented in children)
Definition: GNEPerson.cpp:255
void moveGeometry(const Position &offset)
change the position of the element geometry without saving in undoList
Definition: GNEPerson.cpp:285
void computePath()
compute path
Definition: GNEPerson.cpp:306
bool setFunctionalColor(int activeScheme) const
sets the color according to the current scheme index and some vehicle function
Definition: GNEPerson.cpp:744
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
Definition: GNEPerson.cpp:700
void setEnabledAttribute(const int enabledAttributes)
method for enabling the attribute and nothing else (used in GNEChange_EnableAttribute)
Definition: GNEPerson.cpp:894
bool isDemandElementValid() const
check if current demand element is valid to be writed into XML (by default true, can be reimplemented...
Definition: GNEPerson.cpp:241
std::string getBegin() const
get begin time of demand element
Definition: GNEPerson.cpp:176
void enableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
Definition: GNEPerson.cpp:658
~GNEPerson()
destructor
Definition: GNEPerson.cpp:172
const std::map< std::string, std::string > & getACParametersMap() const
get parameters map
Definition: GNEPerson.cpp:726
SUMOVehicleClass getVClass() const
Definition: GNEPerson.cpp:261
std::string getParentName() const
Returns the name of the parent object.
Definition: GNEPerson.cpp:351
bool isValid(SumoXMLAttr key, const std::string &value)
method for checking if the key and their conrrespond attribute are valids
Definition: GNEPerson.cpp:569
void splitEdgeGeometry(const double splitPosition, const GNENetworkElement *originalElement, const GNENetworkElement *newElement, GNEUndoList *undoList)
split geometry
Definition: GNEPerson.cpp:376
void disableAttribute(SumoXMLAttr key, GNEUndoList *undoList)
Definition: GNEPerson.cpp:669
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform demand element changes
Definition: GNEPerson.cpp:539
std::string getAttribute(SumoXMLAttr key) const
inherited from GNEAttributeCarrier
Definition: GNEPerson.cpp:476
Boundary getCenteringBoundary() const
Returns the boundary to which the view shall be centered in order to show the object.
Definition: GNEPerson.cpp:357
double getAttributeDouble(SumoXMLAttr key) const
Definition: GNEPerson.cpp:524
void commitGeometryMoving(GNEUndoList *undoList)
commit geometry changes in the attributes of an element after use of moveGeometry(....
Definition: GNEPerson.cpp:291
GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)
Returns an own popup-menu.
Definition: GNEPerson.cpp:344
void invalidatePath()
invalidate path
Definition: GNEPerson.cpp:312
std::string getDemandElementProblem() const
return a string with the current demand element problem (by default empty, can be reimplemented in ch...
Definition: GNEPerson.cpp:248
void startGeometryMoving()
Definition: GNEPerson.cpp:273
std::string getPopUpID() const
get PopPup ID (Used in AC Hierarchy)
Definition: GNEPerson.cpp:694
static void setFlowParameters(const SumoXMLAttr attribute, int &parameters)
configure flow parameters
static void transformToPerson(GNEPerson *originalPerson)
transform person functions
static void transformToPersonFlow(GNEPerson *originalPerson)
transform routeFlow over an existent route
bool hasTagSynonym() const
return true if tag correspond to an element that will be written in XML with another tag
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
SumoXMLTag getTagSynonym() const
get tag synonym
const std::string & getDefaultValue(SumoXMLAttr attr) const
return the default value of the attribute of an element
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
const GNEViewNetHelper::DataViewOptions & getDataViewOptions() const
get data view options
Definition: GNEViewNet.cpp:491
const GNEAttributeCarrier * getFrontAttributeCarrier() const
get front attributeCarrier
const GNEViewNetHelper::EditModes & getEditModes() const
get edit modes
Definition: GNEViewNet.cpp:467
const GNEViewNetHelper::NetworkViewOptions & getNetworkViewOptions() const
get network view options
Definition: GNEViewNet.cpp:479
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:368
bool isAttributeCarrierInspected(const GNEAttributeCarrier *AC) const
check if attribute carrier is being inspected
void drawTranslateFrontAttributeCarrier(const GNEAttributeCarrier *AC, GUIGlObjectType objectType, const double extraOffset=0)
draw front attributeCarrier
const GNEViewNetHelper::DemandViewOptions & getDemandViewOptions() const
get demand view options
Definition: GNEViewNet.cpp:485
static void drawAction_drawAsCircle(const double length, const double width)
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_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:40
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:148
void buildShowParamsPopupEntry(GUIGLObjectPopupMenu *ret, bool addSeparator=true)
Builds an entry which allows to open the parameter window.
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) 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.
GUIVisualizationTextSettings personValue
GUIVisualizationDetailSettings detailSettings
detail settings
bool drawForPositionSelection
whether drawing is performed for the purpose of selecting objects with a single click
GUIVisualizationSizeSettings personSize
bool drawDottedContour() const
check if dotted contour can be drawn
GUIColorer personColorer
The person colorer.
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 personName
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:60
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:239
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, ParameterisedAttrType attrType=ParameterisedAttrType::STRING, 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:36
static const Position INVALID
used to indicate that a position is valid
Definition: Position.h:282
double distanceSquaredTo(const Position &p2) const
returns the square of the distance to another position
Definition: Position.h:236
double x() const
Returns the x-position.
Definition: Position.h:54
double y() const
Returns the y-position.
Definition: Position.h:59
double length() const
Returns the length.
Position positionAtOffset(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 tag=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
std::string id
The vehicle's id.
static bool parseDepart(const std::string &val, const std::string &element, const std::string &id, SUMOTime &depart, DepartDefinition &dd, std::string &error)
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
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)
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
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
double scaledSize(double scale, double constFactor=0.1) const
get scale size