Eclipse SUMO - Simulation of Urban MObility
GNETagSelector.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 tags
19 /****************************************************************************/
20 #include <config.h>
21 
22 #include <netedit/GNEViewNet.h>
70 
71 #include "GNETagSelector.h"
72 
73 
74 // ===========================================================================
75 // FOX callback mapping
76 // ===========================================================================
77 
78 FXDEFMAP(GNETagSelector) TagSelectorMap[] = {
80 };
81 
82 // Object implementation
83 FXIMPLEMENT(GNETagSelector, MFXGroupBoxModule, TagSelectorMap, ARRAYNUMBER(TagSelectorMap))
84 
85 
86 // ===========================================================================
87 // method definitions
88 // ===========================================================================
89 
90 GNETagSelector::GNETagSelector(GNEFrame* frameParent, GNETagProperties::TagType type, SumoXMLTag tag, bool onlyDrawables) :
91  MFXGroupBoxModule(frameParent, TL("Element")),
92  myFrameParent(frameParent),
93  myTagType(type),
94  myCurrentTemplateAC(nullptr) {
95  // Create MFXComboBoxIcon
96  myTagsMatchBox = new MFXComboBoxIcon(getCollapsableFrame(), GUIDesignComboBoxNCol, true, GUIDesignComboBoxVisibleItemsLarge,
98  // set current tag type without notifying
99  setCurrentTagType(myTagType, onlyDrawables, false);
100  // set current tag without notifying
101  setCurrentTag(tag, false);
102  // GNETagSelector is always shown
103  show();
104 }
105 
106 
108  // clear myACTemplates and myTagsMatchBox
109  for (const auto& ACTemplate : myACTemplates) {
110  delete ACTemplate;
111  }
112  myACTemplates.clear();
113 }
114 
115 
116 void
118  show();
119 }
120 
121 
122 void
124  hide();
125 }
126 
127 
130  // clear myACTemplates and myTagsMatchBox
131  for (const auto& ACTemplate : myACTemplates) {
132  if (ACTemplate->getAC()->getTagProperty().getTag() == ACTag) {
133  return ACTemplate->getAC();
134  }
135  }
136  return nullptr;
137 }
138 
139 
142  return myCurrentTemplateAC;
143 }
144 
145 
146 void
147 GNETagSelector::setCurrentTagType(GNETagProperties::TagType tagType, const bool onlyDrawables, const bool notifyFrameParent) {
148  // check if net has proj
149  const bool proj = (GeoConvHelper::getFinal().getProjString() != "!");
150  // set new tagType
151  myTagType = tagType;
152  // change GNETagSelector text
153  switch (myTagType) {
154  case GNETagProperties::TagType::NETWORKELEMENT:
155  setText(TL("network elements"));
156  break;
157  case GNETagProperties::TagType::ADDITIONALELEMENT:
158  setText(TL("Additional elements"));
159  break;
160  case GNETagProperties::TagType::SHAPE:
161  setText(TL("Shape elements"));
162  break;
163  case GNETagProperties::TagType::TAZELEMENT:
164  setText(TL("TAZ elements"));
165  break;
166  case GNETagProperties::TagType::WIRE:
167  setText(TL("Wire elements"));
168  break;
169  case GNETagProperties::TagType::VEHICLE:
170  setText(TL("Vehicles"));
171  break;
172  case GNETagProperties::TagType::VEHICLESTOP:
173  setText(TL("Stops"));
174  break;
175  case GNETagProperties::TagType::PERSON:
176  setText(TL("Persons"));
177  break;
178  case GNETagProperties::TagType::PERSONPLAN:
179  setText(TL("Person plans"));
180  break;
181  case GNETagProperties::TagType::CONTAINER:
182  setText(TL("Container"));
183  break;
184  case GNETagProperties::TagType::CONTAINERPLAN:
185  setText(TL("Container plans"));
186  break;
187  case GNETagProperties::TagType::PERSONTRIP:
188  setText(TL("Person trips"));
189  break;
190  case GNETagProperties::TagType::WALK:
191  setText(TL("Walks"));
192  break;
193  case GNETagProperties::TagType::RIDE:
194  setText(TL("Rides"));
195  break;
196  case GNETagProperties::TagType::STOPPERSON:
197  setText(TL("Person stops"));
198  break;
199  default:
200  throw ProcessError("invalid tag property");
201  }
202  // clear myACTemplates and myTagsMatchBox
203  for (const auto& ACTemplate : myACTemplates) {
204  delete ACTemplate;
205  }
206  myACTemplates.clear();
208  // get tag properties
209  const auto tagProperties = GNEAttributeCarrier::getTagPropertiesByType(myTagType);
210  // fill myACTemplates and myTagsMatchBox
211  for (const auto& tagProperty : tagProperties) {
212  if ((!onlyDrawables || tagProperty.isDrawable()) && (!tagProperty.requireProj() || proj)) {
213  myACTemplates.push_back(new ACTemplate(myFrameParent->getViewNet()->getNet(), tagProperty));
214  myTagsMatchBox->appendIconItem(tagProperty.getFieldString().c_str(), GUIIconSubSys::getIcon(tagProperty.getGUIIcon()), tagProperty.getBackGroundColor());
215  }
216  }
217  // set color of myTypeMatchBox to black (valid)
218  myTagsMatchBox->setTextColor(FXRGB(0, 0, 0));
219  myTagsMatchBox->killFocus();
220  // set first myACTemplate as edited AC
221  myCurrentTemplateAC = myACTemplates.front()->getAC();
222  // call tag selected function
223  if (notifyFrameParent) {
225  }
226 }
227 
228 
229 void
230 GNETagSelector::setCurrentTag(SumoXMLTag newTag, const bool notifyFrameParent) {
231  // first reset myCurrentTemplateAC
232  myCurrentTemplateAC = nullptr;
233  // iterate over all myTagsMatchBox
234  for (int i = 0; i < (int)myACTemplates.size(); i++) {
235  if (myACTemplates.at(i)->getAC() && (myACTemplates.at(i)->getAC()->getTagProperty().getTag() == newTag)) {
236  // set current template and currentItem
237  myCurrentTemplateAC = myACTemplates.at(i)->getAC();
239  // set color of myTypeMatchBox to black (valid)
240  myTagsMatchBox->setTextColor(FXRGB(0, 0, 0));
241  myTagsMatchBox->killFocus();
242  }
243  }
244  // call tag selected function
245  if (notifyFrameParent) {
247  }
248 }
249 
250 
251 void
253  // call tag selected function
255 }
256 
257 
258 long
259 GNETagSelector::onCmdSelectTag(FXObject*, FXSelector, void*) {
260  // iterate over all myTagsMatchBox
261  for (int i = 0; i < (int)myACTemplates.size(); i++) {
262  if (myACTemplates.at(i)->getAC() && myACTemplates.at(i)->getAC()->getTagProperty().getFieldString() == myTagsMatchBox->getText().text()) {
263  // set templateAC and currentItem
264  myCurrentTemplateAC = myACTemplates.at(i)->getAC();
266  // set color of myTypeMatchBox to black (valid)
267  myTagsMatchBox->setTextColor(FXRGB(0, 0, 0));
268  myTagsMatchBox->killFocus();
269  // call tag selected function
271  // Write Warning in console if we're in testing mode
272  WRITE_DEBUG(("Selected item '" + myTagsMatchBox->getText() + "' in GNETagSelector").text());
273  return 1;
274  }
275  }
276  // reset templateAC
277  myCurrentTemplateAC = nullptr;
278  // set color of myTypeMatchBox to red (invalid)
279  myTagsMatchBox->setTextColor(FXRGB(255, 0, 0));
280  // Write Warning in console if we're in testing mode
281  WRITE_DEBUG("Selected invalid item in GNETagSelector");
282  // call tag selected function
284  return 1;
285 }
286 
287 
290  return myAC;
291 }
292 
293 
295  myAC(nullptr) {
296  // create attribute carrier depending of tag
297  switch (tagProperty.getTag()) {
298  // additional elements
299  case SUMO_TAG_BUS_STOP:
300  case SUMO_TAG_TRAIN_STOP:
301  myAC = new GNEBusStop(tagProperty.getTag(), net);
302  break;
303  case SUMO_TAG_ACCESS:
304  myAC = new GNEAccess(net);
305  break;
307  myAC = new GNEContainerStop(net);
308  break;
310  myAC = new GNEChargingStation(net);
311  break;
313  myAC = new GNEParkingArea(net);
314  break;
316  myAC = new GNEParkingSpace(net);
317  break;
319  myAC = new GNEInductionLoopDetector(net);
320  break;
323  myAC = new GNELaneAreaDetector(tagProperty.getTag(), net);
324  break;
326  myAC = new GNEMultiEntryExitDetector(net);
327  break;
328  case SUMO_TAG_DET_ENTRY:
329  case SUMO_TAG_DET_EXIT:
330  myAC = new GNEEntryExitDetector(tagProperty.getTag(), net);
331  break;
334  break;
335  case SUMO_TAG_VSS:
336  myAC = new GNEVariableSpeedSign(net);
337  break;
338  case SUMO_TAG_STEP:
339  myAC = new GNEVariableSpeedSignStep(net);
340  break;
341  case SUMO_TAG_CALIBRATOR:
343  myAC = new GNECalibrator(tagProperty.getTag(), net);
344  break;
346  myAC = new GNECalibratorFlow(net);
347  break;
348  case SUMO_TAG_REROUTER:
349  myAC = new GNERerouter(net);
350  break;
351  case SUMO_TAG_INTERVAL:
352  myAC = new GNERerouterInterval(net);
353  break;
355  myAC = new GNEClosingReroute(net);
356  break;
358  myAC = new GNEClosingLaneReroute(net);
359  break;
361  myAC = new GNEDestProbReroute(net);
362  break;
364  myAC = new GNEParkingAreaReroute(net);
365  break;
367  myAC = new GNERouteProbReroute(net);
368  break;
369  case SUMO_TAG_ROUTEPROBE:
370  myAC = new GNERouteProbe(net);
371  break;
372  case SUMO_TAG_VAPORIZER:
373  myAC = new GNEVaporizer(net);
374  break;
375  // symbols
377  myAC = new GNERerouterSymbol(net);
378  break;
379  case GNE_TAG_VSS_SYMBOL:
380  myAC = new GNEVariableSpeedSignSymbol(net);
381  break;
382  // shapes
383  case SUMO_TAG_POLY:
384  myAC = new GNEPoly(tagProperty.getTag(), net);
385  break;
386  case SUMO_TAG_POI:
387  case GNE_TAG_POILANE:
388  case GNE_TAG_POIGEO:
389  myAC = new GNEPOI(tagProperty.getTag(), net);
390  break;
391  // TAZs
392  case SUMO_TAG_TAZ:
393  myAC = new GNETAZ(net);
394  break;
395  case SUMO_TAG_TAZSOURCE:
396  case SUMO_TAG_TAZSINK:
397  myAC = new GNETAZSourceSink(tagProperty.getTag(), net);
398  break;
399  // wires
401  myAC = new GNETractionSubstation(net);
402  break;
404  myAC = new GNEOverheadWire(net);
405  break;
407  myAC = nullptr; // TMP
408  break;
409  // JuPedSim elements
412  myAC = new GNEPoly(tagProperty.getTag(), net);
413  break;
414  // Demand elements
415  case SUMO_TAG_ROUTE:
417  myAC = new GNERoute(tagProperty.getTag(), net);
418  break;
419  case SUMO_TAG_VTYPE:
420  myAC = new GNEVType(net);
421  break;
423  myAC = new GNEVTypeDistribution(net);
424  break;
425  case SUMO_TAG_TRIP:
426  case SUMO_TAG_VEHICLE:
429  case GNE_TAG_TRIP_TAZS:
430  case SUMO_TAG_FLOW:
431  case GNE_TAG_FLOW_ROUTE:
434  case GNE_TAG_FLOW_TAZS:
435  myAC = new GNEVehicle(tagProperty.getTag(), net);
436  break;
437  // stops
438  case GNE_TAG_STOP_LANE:
449  // waypoints
456  myAC = new GNEStop(tagProperty.getTag(), net);
457  break;
458  case SUMO_TAG_PERSON:
459  case SUMO_TAG_PERSONFLOW:
460  myAC = new GNEPerson(tagProperty.getTag(), net);
461  break;
462  case SUMO_TAG_CONTAINER:
464  myAC = new GNEContainer(tagProperty.getTag(), net);
465  break;
466  default:
467  throw ProcessError("Non-supported tagProperty in ACTemplate");
468  break;
469  }
470 }
471 
472 
474  delete myAC;
475 }
476 
477 /****************************************************************************/
FXDEFMAP(GNETagSelector) TagSelectorMap[]
@ MID_GNE_TAG_SELECTED
tag selected in ComboBox
Definition: GUIAppEnum.h:954
#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_TRIP_JUNCTIONS
a trip between junctions
@ SUMO_TAG_TRACTION_SUBSTATION
A traction substation.
@ GNE_TAG_TRIP_TAZS
a single trip definition that uses TAZs
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
@ SUMO_TAG_CLOSING_REROUTE
reroute of type closing
@ SUMO_TAG_REROUTER
A rerouter.
@ GNE_TAG_WAYPOINT_PARKINGAREA
waypoint placed over a parking area
@ GNE_TAG_MULTI_LANE_AREA_DETECTOR
an e2 detector over multiple lanes (placed here due create Additional Frame)
@ SUMO_TAG_ROUTEPROBE
a routeprobe detector
@ GNE_TAG_STOP_PARKINGAREA
stop placed over a parking area
@ SUMO_TAG_TAZ
a traffic assignment zone
@ SUMO_TAG_CHARGING_STATION
A Charging Station.
@ SUMO_TAG_VTYPE
description of a vehicle/person/container type
@ SUMO_TAG_ACCESS
An access point for a train stop.
@ SUMO_TAG_CONTAINER_STOP
A container stop.
@ GNE_TAG_STOP_BUSSTOP
stop placed over a busStop
@ SUMO_TAG_CONTAINERFLOW
@ SUMO_TAG_PARKING_AREA_REROUTE
entry for an alternative parking zone
@ GNE_TAG_WAYPOINT_TRAINSTOP
waypoint placed over a busStop
@ SUMO_TAG_TAZSINK
a sink within a district (connection road)
@ GNE_TAG_WAYPOINT_CONTAINERSTOP
waypoint placed over a containerStop
@ GNE_TAG_STOPCONTAINER_EDGE
@ GNE_TAG_WAYPOINT_BUSSTOP
waypoint placed over a busStop
@ SUMO_TAG_BUS_STOP
A bus stop.
@ SUMO_TAG_POI
begin/end of the description of a Point of interest
@ GNE_TAG_WAYPOINT_CHARGINGSTATION
waypoint placed over a charging station
@ GNE_TAG_STOPPERSON_BUSSTOP
@ SUMO_TAG_STEP
trigger: a step description
@ SUMO_TAG_VEHICLE
description of a vehicle
@ GNE_TAG_FLOW_ROUTE
a flow definition using a route instead of a from-to edges route
@ SUMO_TAG_OVERHEAD_WIRE_CLAMP
An overhead wire clamp (connection of wires in opposite directions)
@ GNE_TAG_VSS_SYMBOL
VSS Symbol.
@ GNE_TAG_FLOW_JUNCTIONS
a flow between junctions
@ GNE_TAG_POIGEO
Point of interest over view with GEO attributes.
@ GNE_TAG_STOP_CONTAINERSTOP
stop placed over a containerStop
@ GNE_TAG_STOPCONTAINER_CONTAINERSTOP
@ GNE_TAG_FLOW_WITHROUTE
description of a vehicle with an embedded route
@ SUMO_TAG_FLOW
a flow definition using from and to edges or a route
@ SUMO_TAG_PARKING_AREA
A parking area.
@ SUMO_TAG_ROUTE_PROB_REROUTE
probability of route of a reroute
@ GNE_TAG_FLOW_TAZS
a flow between TAZs
@ GNE_TAG_CALIBRATOR_LANE
A calibrator placed over lane.
@ SUMO_TAG_DET_ENTRY
an e3 entry point
@ SUMO_TAG_PARKING_SPACE
A parking space for a single vehicle within a parking area.
@ SUMO_TAG_CONTAINER
@ SUMO_TAG_ROUTE
begin/end of the description of a route
@ SUMO_TAG_POLY
begin/end of the description of a polygon
@ SUMO_TAG_OVERHEAD_WIRE_SECTION
An overhead wire section.
@ SUMO_TAG_TRAIN_STOP
A train stop (alias for bus stop)
@ SUMO_TAG_VTYPE_DISTRIBUTION
distribution of a vehicle type
@ SUMO_TAG_INSTANT_INDUCTION_LOOP
An instantenous induction loop.
@ GNE_TAG_VEHICLE_WITHROUTE
description of a vehicle with an embedded route
@ GNE_TAG_CALIBRATOR_FLOW
a flow definition within in Calibrator
@ SUMO_TAG_DEST_PROB_REROUTE
probability of destination of a reroute
@ GNE_TAG_POILANE
Point of interest over Lane.
@ GNE_TAG_WAYPOINT_LANE
waypoint placed over a lane
@ GNE_TAG_JPS_OBSTACLE
polygon used for draw juPedSim obstacles
@ SUMO_TAG_PERSON
@ SUMO_TAG_DET_EXIT
an e3 exit point
@ SUMO_TAG_VAPORIZER
vaporizer of vehicles
@ SUMO_TAG_LANE_AREA_DETECTOR
alternative tag for e2 detector
@ GNE_TAG_REROUTER_SYMBOL
Rerouter Symbol.
@ GNE_TAG_STOP_LANE
stop placed over a lane
@ GNE_TAG_STOPPERSON_TRAINSTOP
@ SUMO_TAG_TAZSOURCE
a source within a district (connection road)
@ SUMO_TAG_CLOSING_LANE_REROUTE
lane of a reroute of type closing
@ GNE_TAG_STOP_TRAINSTOP
stop placed over a trainStop
@ GNE_TAG_STOP_CHARGINGSTATION
stop placed over a charging station
@ GNE_TAG_ROUTE_EMBEDDED
embedded route
@ SUMO_TAG_INDUCTION_LOOP
alternative tag for e1 detector
@ GNE_TAG_JPS_WALKABLEAREA
polygon used for draw juPedSim walkable areas
@ SUMO_TAG_CALIBRATOR
A calibrator placed over edge.
@ SUMO_TAG_ENTRY_EXIT_DETECTOR
alternative tag for e3 detector
@ SUMO_TAG_VSS
A variable speed sign.
@ GNE_TAG_STOPPERSON_EDGE
@ SUMO_TAG_PERSONFLOW
@ SUMO_TAG_TRIP
a single trip definition (used by router)
static const std::vector< GNETagProperties > getTagPropertiesByType(const int tagPropertyCategory)
get tagProperties associated to the given GNETagProperties::TagType (NETWORKELEMENT,...
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
A lane area vehicles can halt at (netedit-version)
Definition: GNEBusStop.h:33
A lane area vehicles can halt at (netedit-version)
virtual void tagSelected()
Tag selected in GNETagSelector.
Definition: GNEFrame.cpp:267
GNEViewNet * getViewNet() const
get view net
Definition: GNEFrame.cpp:150
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
Definition: GNEPOI.h:43
A lane area vehicles can park at (netedit-version)
vehicle space used by GNEParkingAreas
Representation of a RouteProbe in netedit.
Definition: GNERouteProbe.h:32
Definition: GNETAZ.h:34
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
ACTemplate(GNENet *net, const GNETagProperties tagProperty)
constructor
GNEAttributeCarrier * myAC
editedAC
GNEAttributeCarrier * getAC() const
get template AC
GNETagProperties::TagType myTagType
current tagType
MFXComboBoxIcon * myTagsMatchBox
comboBox with the tags
GNEAttributeCarrier * myCurrentTemplateAC
current templateAC;
void refreshTagSelector()
refresh tagSelector (used when frameParent is show)
void showTagSelector()
show item selector
GNEAttributeCarrier * getTemplateAC(SumoXMLTag ACTag) const
get templateAC
long onCmdSelectTag(FXObject *, FXSelector, void *)
GNEFrame * myFrameParent
pointer to Frame Parent
GNEAttributeCarrier * getCurrentTemplateAC() const
get current templateAC
void setCurrentTagType(GNETagProperties::TagType tagType, const bool onlyDrawables, const bool notifyFrameParent=true)
set current type manually
void hideTagSelector()
hide item selector
std::vector< ACTemplate * > myACTemplates
list with ACTemplates
~GNETagSelector()
destructor
void setCurrentTag(SumoXMLTag newTag, const bool notifyFrameParent=true)
set current type manually
Representation of a vaporizer in netedit.
Definition: GNEVaporizer.h:33
GNENet * getNet() const
get the net object
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
const std::string & getProjString() const
Returns the original projection definition.
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
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.
void clearItems()
Remove all items from the list.
FXint appendIconItem(const FXString &text, FXIcon *icon=nullptr, FXColor bgColor=FXRGB(255, 255, 255), void *ptr=nullptr)
append icon item in the last position
MFXGroupBoxModule (based on FXGroupBox)
void setText(const std::string &text)
set text