Eclipse SUMO - Simulation of Urban MObility
GNEPlanSelector.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2001-2024 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 // Frame for select person/container plans
19 /****************************************************************************/
20 #include <config.h>
21 
22 #include <netedit/GNEViewNet.h>
71 
72 #include "GNEPlanSelector.h"
73 
74 
75 // ===========================================================================
76 // FOX callback mapping
77 // ===========================================================================
78 
79 FXDEFMAP(GNEPlanSelector) TagSelectorMap[] = {
81 };
82 
83 // Object implementation
84 FXIMPLEMENT(GNEPlanSelector, MFXGroupBoxModule, TagSelectorMap, ARRAYNUMBER(TagSelectorMap))
85 
86 // ===========================================================================
87 // method definitions
88 // ===========================================================================
89 
91  MFXGroupBoxModule(frameParent, TL("Plan type")),
92  myFrameParent(frameParent) {
93  // Create MFXComboBoxIcon
94  myPlansComboBox = new MFXComboBoxIcon(getCollapsableFrame(), GUIDesignComboBoxNCol, false, GUIDesignComboBoxVisibleItemsLarge,
96  // get net
97  const auto net = myFrameParent->getViewNet()->getNet();
98  // continue depending of plan type
99  if (planType == SUMO_TAG_PERSON) {
100  fillPersonPlanTemplates(net);
101  } else if (planType == SUMO_TAG_CONTAINER) {
102  fillContainerPlanTemplates(net);
103  } else {
104  throw ProcessError("Invalid plan");
105  }
106  // add person plan elements
107  for (const auto& planTemplate : myPlanTemplates) {
108  myPlansComboBox->appendIconItem(planTemplate.first.getTooltipText().c_str(),
109  GUIIconSubSys::getIcon(planTemplate.second->getTagProperty().getGUIIcon()),
110  planTemplate.second->getTagProperty().getBackGroundColor());
111  }
112  // set myCurrentPlanTemplate
113  myCurrentPlanTemplate = myPlanTemplates.front();
114  // set color of myTypeMatchBox to black (valid)
115  myPlansComboBox->setTextColor(FXRGB(0, 0, 0));
116  myPlansComboBox->killFocus();
117  // GNEPlanSelector is always shown
118  show();
119 }
120 
121 
123  for (auto& planTemplate : myPlanTemplates) {
124  delete planTemplate.second;
125  }
126  myPlanTemplates.clear();
127 }
128 
129 
130 void
132  show();
133 }
134 
135 
136 void
138  hide();
139 }
140 
141 
142 const GNETagProperties&
144  return myCurrentPlanTemplate.first;
145 }
146 
147 
150  return myCurrentPlanTemplate.second;
151 }
152 
153 
154 void
156  if (isPlanValid()) {
157  // call tag selected function
159  } else {
160  // set first item
162  }
163 }
164 
165 
166 bool
168  // first check if this modul is shown and selected plan is valid
169  if (isPlanValid()) {
170  return myCurrentPlanTemplate.first.planRoute();
171  } else {
172  return false;
173  }
174 }
175 
176 
177 bool
179  // first check if this modul is shown and selected plan is valid
180  if (isPlanValid()) {
181  return myCurrentPlanTemplate.first.planConsecutiveEdges() ||
182  myCurrentPlanTemplate.first.planEdge() ||
183  myCurrentPlanTemplate.first.planFromEdge() ||
184  myCurrentPlanTemplate.first.planToEdge();
185  } else {
186  return false;
187  }
188 }
189 
190 
191 bool
193  // first check if this modul is shown and selected plan is valid
194  if (isPlanValid()) {
195  return myCurrentPlanTemplate.first.planFromJunction() ||
196  myCurrentPlanTemplate.first.planToJunction();
197  } else {
198  return false;
199  }
200 }
201 
202 
203 bool
205  // first check if this modul is shown and selected plan is valid
206  if (isPlanValid()) {
207  return myCurrentPlanTemplate.first.planStoppingPlace() ||
208  myCurrentPlanTemplate.first.planFromStoppingPlace() ||
209  myCurrentPlanTemplate.first.planToStoppingPlace();
210  } else {
211  return false;
212  }
213 }
214 
215 
216 bool
218  // first check if this modul is shown and selected plan is valid
219  if (isPlanValid()) {
220  return myCurrentPlanTemplate.first.planFromTAZ() ||
221  myCurrentPlanTemplate.first.planToTAZ();
222  } else {
223  return false;
224  }
225 }
226 
227 
228 long
229 GNEPlanSelector::onCmdSelectPlan(FXObject*, FXSelector, void*) {
230  // check if selected plan of comboBox exists in plans
231  for (const auto& planTemplate : myPlanTemplates) {
232  if (planTemplate.first.getTooltipText().c_str() == myPlansComboBox->getText()) {
233  // update myCurrentPlanTemplate
234  myCurrentPlanTemplate = planTemplate;
235  // set color of myTypeMatchBox to black (valid)
236  myPlansComboBox->setTextColor(FXRGB(0, 0, 0));
237  myPlansComboBox->killFocus();
238  // call tag selected function
240  // Write Warning in console if we're in testing mode
241  WRITE_DEBUG(("Selected item '" + myPlansComboBox->getText() + "' in GNEPlanSelector").text());
242  return 1;
243  }
244  }
245  // reset myCurrentPlanTemplate
246  myCurrentPlanTemplate = std::make_pair(GNETagProperties(), nullptr);
247  // set color of myTypeMatchBox to red (invalid)
248  myPlansComboBox->setTextColor(FXRGB(255, 0, 0));
249  // Write Warning in console if we're in testing mode
250  WRITE_DEBUG("Selected invalid item in TemplatePlanSelector");
251  // call tag selected function
253  return 1;
254 }
255 
256 
257 bool
259  if (myCurrentPlanTemplate.second) {
260  return myPlansComboBox->getTextColor() == FXRGB(0, 0, 0);
261  } else {
262  return false;
263  }
264 }
265 
266 
267 void
269  GNETagProperties tagProperty;
270  // person trip
272  GNETagProperties::TagType::PERSONPLAN,
273  GNETagProperties::TagProperty::NO_PROPERTY,
274  GNETagProperties::TagParents::PLAN_FROM_EDGE | GNETagProperties::TagParents::PLAN_TO_EDGE |
275  GNETagProperties::TagParents::PLAN_FROM_TAZ | GNETagProperties::TagParents::PLAN_TO_TAZ |
276  GNETagProperties::TagParents::PLAN_FROM_JUNCTION | GNETagProperties::TagParents::PLAN_TO_JUNCTION |
277  GNETagProperties::TagParents::PLAN_FROM_BUSSTOP | GNETagProperties::TagParents::PLAN_TO_BUSSTOP |
278  GNETagProperties::TagParents::PLAN_FROM_TRAINSTOP | GNETagProperties::TagParents::PLAN_TO_TRAINSTOP |
279  GNETagProperties::TagParents::PLAN_FROM_CONTAINERSTOP | GNETagProperties::TagParents::PLAN_TO_CONTAINERSTOP |
280  GNETagProperties::TagParents::PLAN_FROM_CHARGINGSTATION | GNETagProperties::TagParents::PLAN_TO_CHARGINGSTATION |
281  GNETagProperties::TagParents::PLAN_FROM_PARKINGAREA | GNETagProperties::TagParents::PLAN_TO_PARKINGAREA,
282  GNETagProperties::Conflicts::NO_CONFLICTS,
283  GUIIcon::EMPTY, SUMO_TAG_PERSONTRIP, "PersonTrip");
284  myPlanTemplates.push_back(std::make_pair(tagProperty, new GNEPersonTrip(GNE_TAG_PERSONTRIP_EDGE_EDGE, net)));
285  // ride
286  tagProperty = GNETagProperties(SUMO_TAG_RIDE,
287  GNETagProperties::TagType::PERSONPLAN,
288  GNETagProperties::TagProperty::NO_PROPERTY,
289  GNETagProperties::TagParents::PLAN_FROM_EDGE | GNETagProperties::TagParents::PLAN_TO_EDGE |
290  GNETagProperties::TagParents::PLAN_FROM_TAZ | GNETagProperties::TagParents::PLAN_TO_TAZ |
291  GNETagProperties::TagParents::PLAN_FROM_JUNCTION | GNETagProperties::TagParents::PLAN_TO_JUNCTION |
292  GNETagProperties::TagParents::PLAN_FROM_BUSSTOP | GNETagProperties::TagParents::PLAN_TO_BUSSTOP |
293  GNETagProperties::TagParents::PLAN_FROM_TRAINSTOP | GNETagProperties::TagParents::PLAN_TO_TRAINSTOP |
294  GNETagProperties::TagParents::PLAN_FROM_CONTAINERSTOP | GNETagProperties::TagParents::PLAN_TO_CONTAINERSTOP |
295  GNETagProperties::TagParents::PLAN_FROM_CHARGINGSTATION | GNETagProperties::TagParents::PLAN_TO_CHARGINGSTATION |
296  GNETagProperties::TagParents::PLAN_FROM_PARKINGAREA | GNETagProperties::TagParents::PLAN_TO_PARKINGAREA,
297  GNETagProperties::Conflicts::NO_CONFLICTS,
298  GUIIcon::EMPTY, SUMO_TAG_RIDE, "Ride");
299  myPlanTemplates.push_back(std::make_pair(tagProperty, new GNERide(GNE_TAG_RIDE_EDGE_EDGE, net)));
300  // walk
301  tagProperty = GNETagProperties(SUMO_TAG_WALK,
302  GNETagProperties::TagType::PERSONPLAN,
303  GNETagProperties::TagProperty::NO_PROPERTY,
304  GNETagProperties::TagParents::PLAN_FROM_EDGE | GNETagProperties::TagParents::PLAN_TO_EDGE |
305  GNETagProperties::TagParents::PLAN_FROM_TAZ | GNETagProperties::TagParents::PLAN_TO_TAZ |
306  GNETagProperties::TagParents::PLAN_FROM_JUNCTION | GNETagProperties::TagParents::PLAN_TO_JUNCTION |
307  GNETagProperties::TagParents::PLAN_FROM_BUSSTOP | GNETagProperties::TagParents::PLAN_TO_BUSSTOP |
308  GNETagProperties::TagParents::PLAN_FROM_TRAINSTOP | GNETagProperties::TagParents::PLAN_TO_TRAINSTOP |
309  GNETagProperties::TagParents::PLAN_FROM_CONTAINERSTOP | GNETagProperties::TagParents::PLAN_TO_CONTAINERSTOP |
310  GNETagProperties::TagParents::PLAN_FROM_CHARGINGSTATION | GNETagProperties::TagParents::PLAN_TO_CHARGINGSTATION |
311  GNETagProperties::TagParents::PLAN_FROM_PARKINGAREA | GNETagProperties::TagParents::PLAN_TO_PARKINGAREA,
312  GNETagProperties::Conflicts::NO_CONFLICTS,
313  GUIIcon::EMPTY, SUMO_TAG_WALK, "Walk");
314  myPlanTemplates.push_back(std::make_pair(tagProperty, new GNEWalk(GNE_TAG_WALK_EDGE_EDGE, net)));
315  // walk (edges)
316  tagProperty = GNETagProperties(SUMO_TAG_WALK,
317  GNETagProperties::TagType::PERSONPLAN,
318  GNETagProperties::TagProperty::NO_PROPERTY,
319  GNETagProperties::TagParents::PLAN_CONSECUTIVE_EDGES,
320  GNETagProperties::Conflicts::NO_CONFLICTS,
321  GUIIcon::EMPTY, SUMO_TAG_WALK, "Walk (edges)");
322  myPlanTemplates.push_back(std::make_pair(tagProperty, new GNEWalk(GNE_TAG_WALK_EDGES, net)));
323  // walk (route)
324  tagProperty = GNETagProperties(SUMO_TAG_WALK,
325  GNETagProperties::TagType::PERSONPLAN,
326  GNETagProperties::TagProperty::NO_PROPERTY,
327  GNETagProperties::TagParents::PLAN_ROUTE,
328  GNETagProperties::Conflicts::NO_CONFLICTS,
329  GUIIcon::EMPTY, SUMO_TAG_WALK, "Walk (route)");
330  myPlanTemplates.push_back(std::make_pair(tagProperty, new GNEWalk(GNE_TAG_WALK_ROUTE, net)));
331  // stop
332  tagProperty = GNETagProperties(SUMO_TAG_STOP,
333  GNETagProperties::TagType::PERSONPLAN,
334  GNETagProperties::TagProperty::NO_PROPERTY,
335  GNETagProperties::TagParents::PLAN_EDGE | GNETagProperties::TagParents::PLAN_BUSSTOP |
336  GNETagProperties::TagParents::PLAN_TRAINSTOP | GNETagProperties::TagParents::PLAN_CONTAINERSTOP |
337  GNETagProperties::TagParents::PLAN_CHARGINGSTATION | GNETagProperties::TagParents::PLAN_PARKINGAREA,
338  GNETagProperties::Conflicts::NO_CONFLICTS,
339  GUIIcon::EMPTY, SUMO_TAG_STOP, "Person Stop");
340  myPlanTemplates.push_back(std::make_pair(tagProperty, new GNEStopPlan(GNE_TAG_STOPPERSON_EDGE, net)));
341 }
342 
343 
344 void
346  GNETagProperties tagProperty;
347  // transport
348  tagProperty = GNETagProperties(SUMO_TAG_TRANSPORT, 0, 0,
349  GNETagProperties::TagParents::PLAN_FROM_EDGE | GNETagProperties::TagParents::PLAN_TO_EDGE |
350  //GNETagProperties::TagParents::PLAN_FROM_TAZ | GNETagProperties::TagParents::PLAN_TO_TAZ |
351  //GNETagProperties::TagParents::PLAN_FROM_JUNCTION | GNETagProperties::TagParents::PLAN_TO_JUNCTION |
352  //GNETagProperties::TagParents::PLAN_FROM_BUSSTOP | GNETagProperties::TagParents::PLAN_TO_BUSSTOP |
353  //GNETagProperties::TagParents::PLAN_FROM_TRAINSTOP | GNETagProperties::TagParents::PLAN_TO_TRAINSTOP |
354  GNETagProperties::TagParents::PLAN_FROM_CONTAINERSTOP | GNETagProperties::TagParents::PLAN_TO_CONTAINERSTOP,
355  //GNETagProperties::TagParents::PLAN_FROM_CHARGINGSTATION | GNETagProperties::TagParents::PLAN_TO_CHARGINGSTATION |
356  //GNETagProperties::TagParents::PLAN_FROM_PARKINGAREA | GNETagProperties::TagParents::PLAN_TO_PARKINGAREA,
357  GNETagProperties::Conflicts::NO_CONFLICTS,
358  GUIIcon::EMPTY, SUMO_TAG_PERSONTRIP, "Transport");
359  myPlanTemplates.push_back(std::make_pair(tagProperty, new GNETransport(GNE_TAG_TRANSPORT_EDGE_EDGE, net)));
360  // tranship
361  tagProperty = GNETagProperties(SUMO_TAG_TRANSHIP, 0, 0,
362  GNETagProperties::TagParents::PLAN_FROM_EDGE | GNETagProperties::TagParents::PLAN_TO_EDGE |
363  //GNETagProperties::TagParents::PLAN_FROM_TAZ | GNETagProperties::TagParents::PLAN_TO_TAZ |
364  //GNETagProperties::TagParents::PLAN_FROM_JUNCTION | GNETagProperties::TagParents::PLAN_TO_JUNCTION |
365  //GNETagProperties::TagParents::PLAN_FROM_BUSSTOP | GNETagProperties::TagParents::PLAN_TO_BUSSTOP |
366  //GNETagProperties::TagParents::PLAN_FROM_TRAINSTOP | GNETagProperties::TagParents::PLAN_TO_TRAINSTOP |
367  GNETagProperties::TagParents::PLAN_FROM_CONTAINERSTOP | GNETagProperties::TagParents::PLAN_TO_CONTAINERSTOP,
368  //GNETagProperties::TagParents::PLAN_FROM_CHARGINGSTATION | GNETagProperties::TagParents::PLAN_TO_CHARGINGSTATION |
369  //GNETagProperties::TagParents::PLAN_FROM_PARKINGAREA | GNETagProperties::TagParents::PLAN_TO_PARKINGAREA,
370  GNETagProperties::Conflicts::NO_CONFLICTS,
371  GUIIcon::EMPTY, SUMO_TAG_PERSONTRIP, "Tranship");
372  myPlanTemplates.push_back(std::make_pair(tagProperty, new GNETranship(GNE_TAG_TRANSHIP_EDGE_EDGE, net)));
373  // tranship (edges)
374  tagProperty = GNETagProperties(SUMO_TAG_TRANSHIP, 0, 0,
375  GNETagProperties::TagParents::PLAN_CONSECUTIVE_EDGES,
376  GNETagProperties::Conflicts::NO_CONFLICTS,
377  GUIIcon::EMPTY, SUMO_TAG_PERSONTRIP, "Tranship (edges)");
378  myPlanTemplates.push_back(std::make_pair(tagProperty, new GNETranship(GNE_TAG_TRANSHIP_EDGES, net)));
379  // stop
380  tagProperty = GNETagProperties(SUMO_TAG_STOP, 0, 0,
381  GNETagProperties::TagParents::PLAN_EDGE | GNETagProperties::TagParents::PLAN_BUSSTOP |
382  GNETagProperties::TagParents::PLAN_TRAINSTOP | GNETagProperties::TagParents::PLAN_CONTAINERSTOP |
383  GNETagProperties::TagParents::PLAN_CHARGINGSTATION | GNETagProperties::TagParents::PLAN_PARKINGAREA,
384  GNETagProperties::Conflicts::NO_CONFLICTS,
385  GUIIcon::EMPTY, SUMO_TAG_STOP, "Container Stop");
386  myPlanTemplates.push_back(std::make_pair(tagProperty, new GNEStopPlan(GNE_TAG_STOPCONTAINER_EDGE, net)));
387 }
388 
389 /****************************************************************************/
FXDEFMAP(GNEPlanSelector) TagSelectorMap[]
@ MID_GNE_TAG_SELECTED
tag selected in ComboBox
Definition: GUIAppEnum.h:959
#define GUIDesignComboBox
Definition: GUIDesigns.h:299
#define GUIDesignComboBoxNCol
number of column of every combo box
Definition: GUIDesigns.h:317
#define GUIDesignComboBoxVisibleItemsLarge
combo box large small
Definition: GUIDesigns.h:56
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:306
#define TL(string)
Definition: MsgHandler.h:315
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ GNE_TAG_PERSONTRIP_EDGE_EDGE
@ SUMO_TAG_WALK
@ GNE_TAG_TRANSHIP_EDGE_EDGE
@ SUMO_TAG_TRANSHIP
@ GNE_TAG_WALK_EDGES
@ GNE_TAG_STOPCONTAINER_EDGE
@ SUMO_TAG_STOP
stop for vehicles
@ GNE_TAG_TRANSHIP_EDGES
@ SUMO_TAG_TRANSPORT
@ GNE_TAG_RIDE_EDGE_EDGE
@ GNE_TAG_TRANSPORT_EDGE_EDGE
@ SUMO_TAG_CONTAINER
@ GNE_TAG_WALK_EDGE_EDGE
@ SUMO_TAG_RIDE
@ SUMO_TAG_PERSON
@ SUMO_TAG_PERSONTRIP
@ GNE_TAG_STOPPERSON_EDGE
@ GNE_TAG_WALK_ROUTE
virtual void tagSelected()
Tag selected in GNETagSelector.
Definition: GNEFrame.cpp:267
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
std::vector< std::pair< GNETagProperties, GNEDemandElement * > > myPlanTemplates
list with demand templates
GNEDemandElement * getCurrentPlanTemplate() const
get current plan template
bool markJunctions() const
check if mark junctions with dotted contours
void showPlanSelector()
show plan selector
void fillPersonPlanTemplates(GNENet *net)
fill person templates
bool markRoutes() const
check if mark routes with dotted contours
const GNETagProperties & getCurrentPlanTagProperties() const
get current plan tag properties
void hidePlanSelector()
plan item selector
bool markTAZs() const
check if mark TAZs with dotted contours
~GNEPlanSelector()
destructor
GNEFrame * myFrameParent
pointer to Frame Parent
std::pair< GNETagProperties, GNEDemandElement * > myCurrentPlanTemplate
current plan template;
bool markStoppingPlaces() const
check if mark stoppingPlaces with dotted contours
MFXComboBoxIcon * myPlansComboBox
comboBox with the tags
long onCmdSelectPlan(FXObject *, FXSelector, void *)
Called when the user select an element in ComboBox.
bool markEdges() const
check if mark edges with dotted contours
void refreshPlanSelector()
refresh plan selector (used when frameParent is show)
void fillContainerPlanTemplates(GNENet *net)
fill container templates
bool isPlanValid() const
FOX need this.
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
ComboBox with icon.
long setCurrentItem(const FXint index, FXbool notify=FALSE)
Set the current item (index is zero-based)
FXString getText() const
Get the text.
void setTextColor(FXColor clr)
Change text color.
FXColor getTextColor() const
Return text color.
MFXGroupBoxModule (based on FXGroupBox)