Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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>
23#include <netedit/GNENet.h>
72
73#include "GNEPlanSelector.h"
74
75
76// ===========================================================================
77// FOX callback mapping
78// ===========================================================================
79
80FXDEFMAP(GNEPlanSelector) TagSelectorMap[] = {
82};
83
84// Object implementation
85FXIMPLEMENT(GNEPlanSelector, MFXGroupBoxModule, TagSelectorMap, ARRAYNUMBER(TagSelectorMap))
86
87// ===========================================================================
88// method definitions
89// ===========================================================================
90
92 MFXGroupBoxModule(frameParent, TL("Plan type")),
93 myFrameParent(frameParent) {
94 // Create MFXComboBoxIcon
95 myPlansComboBox = new MFXComboBoxIcon(getCollapsableFrame(), GUIDesignComboBoxNCol, false, GUIDesignComboBoxVisibleItems,
97 // get net
98 const auto net = myFrameParent->getViewNet()->getNet();
99 // continue depending of plan type
100 if (planType == SUMO_TAG_PERSON) {
101 fillPersonPlanTemplates(net);
102 } else if (planType == SUMO_TAG_CONTAINER) {
103 fillContainerPlanTemplates(net);
104 } else {
105 throw ProcessError("Invalid plan");
106 }
107 // add person plan elements
108 for (const auto& planTemplate : myPlanTemplates) {
109 myPlansComboBox->appendIconItem(planTemplate.first.getTooltipText().c_str(),
110 GUIIconSubSys::getIcon(planTemplate.second->getTagProperty().getGUIIcon()),
111 planTemplate.second->getTagProperty().getBackGroundColor());
112 }
113 // set myCurrentPlanTemplate
114 myCurrentPlanTemplate = myPlanTemplates.front();
115 // set color of myTypeMatchBox to black (valid)
116 myPlansComboBox->setTextColor(FXRGB(0, 0, 0));
117 myPlansComboBox->killFocus();
118 // GNEPlanSelector is always shown
119 show();
120}
121
122
124 for (auto& planTemplate : myPlanTemplates) {
125 delete planTemplate.second;
126 }
127 myPlanTemplates.clear();
128}
129
130
131void
137
138
139void
145
146
147const GNETagProperties&
151
152
157
158
159void
161 if (isPlanValid()) {
162 // call tag selected function
164 } else {
165 // set first item
167 }
168}
169
170
171bool
173 // first check if this modul is shown and selected plan is valid
174 if (isPlanValid()) {
175 return myCurrentPlanTemplate.first.planRoute();
176 } else {
177 return false;
178 }
179}
180
181
182bool
184 // first check if this modul is shown and selected plan is valid
185 if (isPlanValid()) {
186 return myCurrentPlanTemplate.first.planConsecutiveEdges() ||
187 myCurrentPlanTemplate.first.planEdge() ||
188 myCurrentPlanTemplate.first.planFromEdge() ||
189 myCurrentPlanTemplate.first.planToEdge();
190 } else {
191 return false;
192 }
193}
194
195
196bool
198 // first check if this modul is shown and selected plan is valid
199 if (isPlanValid()) {
200 return myCurrentPlanTemplate.first.planFromJunction() ||
201 myCurrentPlanTemplate.first.planToJunction();
202 } else {
203 return false;
204 }
205}
206
207
208bool
210 // first check if this modul is shown and selected plan is valid
211 if (isPlanValid()) {
212 return myCurrentPlanTemplate.first.planStoppingPlace() ||
213 myCurrentPlanTemplate.first.planFromStoppingPlace() ||
214 myCurrentPlanTemplate.first.planToStoppingPlace();
215 } else {
216 return false;
217 }
218}
219
220
221bool
223 // first check if this modul is shown and selected plan is valid
224 if (isPlanValid()) {
225 return myCurrentPlanTemplate.first.planFromTAZ() ||
226 myCurrentPlanTemplate.first.planToTAZ();
227 } else {
228 return false;
229 }
230}
231
232
233void
235 // clear junction colors
237 // we assume that all junctions don't support pedestrians
238 for (const auto& junction : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getJunctions()) {
239 junction.second->setInvalidCandidate(true);
240 }
241 // mark junctions that supports pedestrian as candidates
242 for (const auto& edge : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getEdges()) {
243 for (int i = 0; i < (int)edge.second->getLanes().size(); i++) {
244 if (edge.second->getNBEdge()->getLanes().at(i).permissions & SVC_PEDESTRIAN) {
245 edge.second->getFromJunction()->setPossibleCandidate(true);
246 edge.second->getToJunction()->setPossibleCandidate(true);
247 }
248 }
249 }
250 // update view net
252}
253
254
255void
257 // clear edge colors
259 // mark edges that supports pedestrian as candidates
260 for (const auto& edge : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getEdges()) {
261 bool allowPedestrian = false;
262 for (int i = 0; i < (int)edge.second->getLanes().size(); i++) {
263 if (edge.second->getNBEdge()->getLanes().at(i).permissions & SVC_PEDESTRIAN) {
264 allowPedestrian = true;
265 }
266 }
267 if (allowPedestrian) {
268 edge.second->setPossibleCandidate(true);
269 } else {
270 edge.second->setInvalidCandidate(true);
271 }
272 }
273 // update view net
275}
276
277
278void
280 // reset all junction flags
281 for (const auto& junction : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getJunctions()) {
282 junction.second->resetCandidateFlags();
283 }
284}
285
286
287void
289 // reset all junction flags
290 for (const auto& edge : myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getEdges()) {
291 edge.second->resetCandidateFlags();
292 }
293}
294
295
296long
297GNEPlanSelector::onCmdSelectPlan(FXObject*, FXSelector, void*) {
298 // check if selected plan of comboBox exists in plans
299 for (const auto& planTemplate : myPlanTemplates) {
300 if (planTemplate.first.getTooltipText().c_str() == myPlansComboBox->getText()) {
301 // update myCurrentPlanTemplate
302 myCurrentPlanTemplate = planTemplate;
303 // set color of myTypeMatchBox to black (valid)
304 myPlansComboBox->setTextColor(FXRGB(0, 0, 0));
305 myPlansComboBox->killFocus();
306 // call tag selected function
308 // Write Warning in console if we're in testing mode
309 WRITE_DEBUG(("Selected item '" + myPlansComboBox->getText() + "' in GNEPlanSelector").text());
310 return 1;
311 }
312 }
313 // reset myCurrentPlanTemplate
314 myCurrentPlanTemplate = std::make_pair(GNETagProperties(), nullptr);
315 // set color of myTypeMatchBox to red (invalid)
316 myPlansComboBox->setTextColor(FXRGB(255, 0, 0));
317 // Write Warning in console if we're in testing mode
318 WRITE_DEBUG("Selected invalid item in TemplatePlanSelector");
319 // call tag selected function
321 return 1;
322}
323
324
325bool
327 if (myCurrentPlanTemplate.second) {
328 return myPlansComboBox->getTextColor() == FXRGB(0, 0, 0);
329 } else {
330 return false;
331 }
332}
333
334
335void
337 GNETagProperties tagProperty;
338 // person trip
351 GUIIcon::EMPTY, SUMO_TAG_PERSONTRIP, "PersonTrip");
352 myPlanTemplates.push_back(std::make_pair(tagProperty, new GNEPersonTrip(GNE_TAG_PERSONTRIP_EDGE_EDGE, net)));
353 // ride
354 tagProperty = GNETagProperties(SUMO_TAG_RIDE,
367 myPlanTemplates.push_back(std::make_pair(tagProperty, new GNERide(GNE_TAG_RIDE_EDGE_EDGE, net)));
368 // walk
369 tagProperty = GNETagProperties(SUMO_TAG_WALK,
382 myPlanTemplates.push_back(std::make_pair(tagProperty, new GNEWalk(GNE_TAG_WALK_EDGE_EDGE, net)));
383 // walk (edges)
384 tagProperty = GNETagProperties(SUMO_TAG_WALK,
389 GUIIcon::EMPTY, SUMO_TAG_WALK, "Walk (edges)");
390 myPlanTemplates.push_back(std::make_pair(tagProperty, new GNEWalk(GNE_TAG_WALK_EDGES, net)));
391 // walk (route)
392 tagProperty = GNETagProperties(SUMO_TAG_WALK,
397 GUIIcon::EMPTY, SUMO_TAG_WALK, "Walk (route)");
398 myPlanTemplates.push_back(std::make_pair(tagProperty, new GNEWalk(GNE_TAG_WALK_ROUTE, net)));
399 // stop
400 tagProperty = GNETagProperties(SUMO_TAG_STOP,
407 GUIIcon::EMPTY, SUMO_TAG_STOP, "Person Stop");
408 myPlanTemplates.push_back(std::make_pair(tagProperty, new GNEStopPlan(GNE_TAG_STOPPERSON_EDGE, net)));
409}
410
411
412void
414 GNETagProperties tagProperty;
415 // transport
416 tagProperty = GNETagProperties(SUMO_TAG_TRANSPORT, 0, 0,
418 //GNETagProperties::TagParents::PLAN_FROM_TAZ | GNETagProperties::TagParents::PLAN_TO_TAZ |
419 //GNETagProperties::TagParents::PLAN_FROM_JUNCTION | GNETagProperties::TagParents::PLAN_TO_JUNCTION |
420 //GNETagProperties::TagParents::PLAN_FROM_BUSSTOP | GNETagProperties::TagParents::PLAN_TO_BUSSTOP |
421 //GNETagProperties::TagParents::PLAN_FROM_TRAINSTOP | GNETagProperties::TagParents::PLAN_TO_TRAINSTOP |
423 //GNETagProperties::TagParents::PLAN_FROM_CHARGINGSTATION | GNETagProperties::TagParents::PLAN_TO_CHARGINGSTATION |
424 //GNETagProperties::TagParents::PLAN_FROM_PARKINGAREA | GNETagProperties::TagParents::PLAN_TO_PARKINGAREA,
426 GUIIcon::EMPTY, SUMO_TAG_PERSONTRIP, "Transport");
427 myPlanTemplates.push_back(std::make_pair(tagProperty, new GNETransport(GNE_TAG_TRANSPORT_EDGE_EDGE, net)));
428 // tranship
429 tagProperty = GNETagProperties(SUMO_TAG_TRANSHIP, 0, 0,
431 //GNETagProperties::TagParents::PLAN_FROM_TAZ | GNETagProperties::TagParents::PLAN_TO_TAZ |
432 //GNETagProperties::TagParents::PLAN_FROM_JUNCTION | GNETagProperties::TagParents::PLAN_TO_JUNCTION |
433 //GNETagProperties::TagParents::PLAN_FROM_BUSSTOP | GNETagProperties::TagParents::PLAN_TO_BUSSTOP |
434 //GNETagProperties::TagParents::PLAN_FROM_TRAINSTOP | GNETagProperties::TagParents::PLAN_TO_TRAINSTOP |
436 //GNETagProperties::TagParents::PLAN_FROM_CHARGINGSTATION | GNETagProperties::TagParents::PLAN_TO_CHARGINGSTATION |
437 //GNETagProperties::TagParents::PLAN_FROM_PARKINGAREA | GNETagProperties::TagParents::PLAN_TO_PARKINGAREA,
440 myPlanTemplates.push_back(std::make_pair(tagProperty, new GNETranship(GNE_TAG_TRANSHIP_EDGE_EDGE, net)));
441 // tranship (edges)
442 tagProperty = GNETagProperties(SUMO_TAG_TRANSHIP, 0, 0,
445 GUIIcon::EMPTY, SUMO_TAG_PERSONTRIP, "Tranship (edges)");
446 myPlanTemplates.push_back(std::make_pair(tagProperty, new GNETranship(GNE_TAG_TRANSHIP_EDGES, net)));
447 // stop
448 tagProperty = GNETagProperties(SUMO_TAG_STOP, 0, 0,
453 GUIIcon::EMPTY, SUMO_TAG_STOP, "Container Stop");
454 myPlanTemplates.push_back(std::make_pair(tagProperty, new GNEStopPlan(GNE_TAG_STOPCONTAINER_EDGE, net)));
455}
456
457/****************************************************************************/
FXDEFMAP(GNEPlanSelector) TagSelectorMap[]
@ MID_GNE_TAG_SELECTED
tag selected in ComboBox
Definition GUIAppEnum.h:963
#define GUIDesignComboBox
Definition GUIDesigns.h:293
#define GUIDesignComboBoxNCol
number of column of every combo box
Definition GUIDesigns.h:311
#define GUIDesignComboBoxVisibleItems
Definition GUIDesigns.h:49
#define WRITE_DEBUG(msg)
Definition MsgHandler.h:306
#define TL(string)
Definition MsgHandler.h:315
@ SVC_PEDESTRIAN
pedestrian
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
GNEViewNet * getViewNet() const
get view net
Definition GNEFrame.cpp:150
const std::map< std::string, GNEEdge * > & getEdges() const
map with the ID and pointer to edges of net
const std::map< std::string, GNEJunction * > & getJunctions() const
get junctions
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:127
void updateJunctionColors()
update junction colors
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
void updateEdgeColors()
update edge colors
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;
void clearEdgeColors()
clear edge colors
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
void clearJunctionColors()
clear junction colors
bool isPlanValid() const
FOX need this.
GNENet * getNet() const
get the net object
void updateViewNet(const bool ignoreViewUpdater=true) const
Mark the entire GNEViewNet to be repainted later.
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)