Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNERouteFrame.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-2025 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// The Widget for remove network-elements
19/****************************************************************************/
20
22#include <netedit/GNENet.h>
31
32#include "GNERouteFrame.h"
33
34// ===========================================================================
35// FOX callback mapping
36// ===========================================================================
37
42
43// Object implementation
44FXIMPLEMENT(GNERouteFrame::RouteModeSelector, MFXGroupBoxModule, RouteModeSelectorMap, ARRAYNUMBER(RouteModeSelectorMap))
45
46
47// ===========================================================================
48// method definitions
49// ===========================================================================
50
51// ---------------------------------------------------------------------------
52// GNERouteFrame::RouteModeSelector - methods
53// ---------------------------------------------------------------------------
54
56 MFXGroupBoxModule(routeFrameParent, TL("Route mode")),
57 myRouteFrameParent(routeFrameParent) {
58 const auto statictooltipMenu = routeFrameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu();
59 // first fill myRouteModesStrings
60 myRouteModesStrings.push_back(std::make_pair(RouteMode::NONCONSECUTIVE_EDGES, TL("non consecutive edges")));
61 myRouteModesStrings.push_back(std::make_pair(RouteMode::CONSECUTIVE_EDGES, TL("consecutive edges")));
62 // Create MFXComboBoxIcon for Route mode
63 myRouteModeMatchBox = new MFXComboBoxIcon(getCollapsableFrame(), statictooltipMenu, false, GUIDesignComboBoxVisibleItems,
65 // fill myRouteModeMatchBox with route modes
66 for (const auto& routeMode : myRouteModesStrings) {
67 myRouteModeMatchBox->appendIconItem(routeMode.second.c_str());
68 }
69 // Create MFXComboBoxIcon for VClass
70 myVClassMatchBox = new MFXComboBoxIcon(getCollapsableFrame(), statictooltipMenu, false, GUIDesignComboBoxVisibleItems,
72 // fill myVClassMatchBox with all VCLass
73 for (const auto& vClass : SumoVehicleClassStrings.getStrings()) {
74 myVClassMatchBox->appendIconItem(vClass.c_str());
75 }
76 // set Passenger als default VCLass
77 myVClassMatchBox->setCurrentItem(7);
78 // RouteModeSelector is always shown
79 show();
80}
81
82
85
86
89 return myCurrentRouteMode;
90}
91
92
93bool
95 return (myCurrentRouteMode != RouteMode::INVALID);
96}
97
98
99bool
101 return myValidVClass;
102}
103
104
105void
107 const auto routeTemplate = myRouteFrameParent->getViewNet()->getNet()->getACTemplates()->getTemplateAC(SUMO_TAG_ROUTE);
108 // check if current mode is valid
109 if ((myCurrentRouteMode != RouteMode::INVALID) && myValidVClass) {
110 // check if create routes consecutively
111 const bool consecutiveEdges = (myCurrentRouteMode == RouteMode::CONSECUTIVE_EDGES);
112 // show route attributes modul
113 myRouteFrameParent->myRouteAttributesEditor->showAttributesEditor(routeTemplate, true);
114 // show path creator
115 myRouteFrameParent->myPathCreator->showPathCreatorModule(routeTemplate->getTagProperty(), consecutiveEdges);
116 // update edge colors
117 myRouteFrameParent->myPathCreator->updateEdgeColors();
118 // show legend
119 myRouteFrameParent->myPathLegend->showPathLegendModule();
120 } else {
121 // hide all moduls if route mode isnt' valid
122 myRouteFrameParent->myRouteAttributesEditor->hideAttributesEditor();
123 myRouteFrameParent->myPathCreator->hidePathCreatorModule();
124 myRouteFrameParent->myPathLegend->hidePathLegendModule();
125 // reset all flags
126 for (const auto& edge : myRouteFrameParent->myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
127 edge.second->resetCandidateFlags();
128 }
129 // update view net
130 myRouteFrameParent->myViewNet->update();
131 }
132}
133
134
135long
137 // first abort all current operations in moduls
138 myRouteFrameParent->myPathCreator->onCmdAbortPathCreation(0, 0, 0);
139 // set invalid current route mode
140 myCurrentRouteMode = RouteMode::INVALID;
141 // set color of myTypeMatchBox to red (invalid)
142 myRouteModeMatchBox->setTextColor(GUIDesignTextColorRed);
143 // Check if value of myTypeMatchBox correspond of an allowed additional tags
144 for (const auto& routeMode : myRouteModesStrings) {
145 if (routeMode.second == myRouteModeMatchBox->getText().text()) {
146 // Set new current type
147 myCurrentRouteMode = routeMode.first;
148 // set color of myTypeMatchBox to black (valid)
149 myRouteModeMatchBox->setTextColor(GUIDesignTextColorBlack);
150 }
151 }
152 // check if parameters are valid
153 areParametersValid();
154 return 1;
155}
156
157
158long
160 // first abort all current operations in moduls
161 myRouteFrameParent->myPathCreator->onCmdAbortPathCreation(0, 0, 0);
162 // set vClass flag invalid
163 myValidVClass = false;
164 // set color of myTypeMatchBox to red (invalid)
165 myVClassMatchBox->setTextColor(GUIDesignTextColorRed);
166 // Check if value of myTypeMatchBox correspond of an allowed additional tags
167 for (const auto& vClass : SumoVehicleClassStrings.getStrings()) {
168 if (vClass == myVClassMatchBox->getText().text()) {
169 // change flag
170 myValidVClass = true;
171 // set color of myTypeMatchBox to black (valid)
172 myVClassMatchBox->setTextColor(GUIDesignTextColorBlack);
173 // set vClass in Path creator
174 myRouteFrameParent->myPathCreator->setVClass(SumoVehicleClassStrings.get(vClass));
175 }
176 }
177 // check if parameters are valid
178 areParametersValid();
179 return 1;
180}
181
182// ---------------------------------------------------------------------------
183// GNERouteFrame - methods
184// ---------------------------------------------------------------------------
185
187 GNEFrame(viewParent, viewNet, TL("Routes")),
188 myRouteBaseObject(new CommonXMLStructure::SumoBaseObject(nullptr)) {
189
190 // create route mode Selector module
192
193 // Create route parameters
195
196 // create consecutive edges module
197 myPathCreator = new GNEPathCreator(this, viewNet->getNet()->getDemandPathManager());
198
199 // create legend label
201}
202
203
207
208
209void
211 // call are parameters valid
213 // show route frame
215}
216
217
218void
220 // reset candidate edges
221 for (const auto& edge : myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
222 edge.second->resetCandidateFlags();
223 }
225}
226
227
228bool
230 // first check if current vClass and mode are valid and edge exist
232 // add edge in path
233 myPathCreator->addEdge(clickedEdge, mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
234 // update view
236 return true;
237 } else {
238 return false;
239 }
240}
241
242
247
248
249bool
250GNERouteFrame::createPath(const bool /*useLastRoute*/) {
251 // check that route attributes are valid
253 return false;
254 } else if (myPathCreator->getSelectedEdges().size() > 0) {
255 // clear base object
257 // set tag
259 // obtain attributes
261 // add probability (needed for distributions)
263 // declare edge vector
264 std::vector<std::string> edges;
265 for (const auto& path : myPathCreator->getPath()) {
266 for (const auto& edgeID : path.getSubPath()) {
267 // get edge
268 GNEEdge* edge = myViewNet->getNet()->getAttributeCarriers()->retrieveEdge(edgeID->getID());
269 // avoid double edges
270 if (edges.empty() || (edges.back() != edge->getID())) {
271 edges.push_back(edge->getID());
272 }
273 }
274 }
275 // set edges in route base object
277 // declare route handler
281 // create route
283 // abort path creation
285 // refresh route attributes
287 // get new route
289 // compute path route
290 newRoute->computePathElement();
291 // set as last created route
293 return true;
294 }
295 return false;
296}
297
298/****************************************************************************/
FXDEFMAP(GNERouteFrame::RouteModeSelector) RouteModeSelectorMap[]
@ MID_GNE_ROUTEFRAME_ROUTEMODE
select a route mode
@ MID_GNE_ROUTEFRAME_VCLASS
select a VClass
#define GUIDesignTextColorRed
red color (for invalid text)
Definition GUIDesigns.h:44
#define GUIDesignComboBox
Definition GUIDesigns.h:295
#define GUIDesignComboBoxVisibleItems
Definition GUIDesigns.h:64
#define GUIDesignTextColorBlack
black color (for correct text)
Definition GUIDesigns.h:38
#define TL(string)
Definition MsgHandler.h:304
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
@ SUMO_TAG_ROUTE
description of a route
@ GNE_ATTR_DEMAND_FILE
demand demand file
@ SUMO_ATTR_EDGES
the edges of a route
@ SUMO_ATTR_PROB
@ SUMO_ATTR_ID
bool hasStringAttribute(const SumoXMLAttr attr) const
has function
void setTag(const SumoXMLTag tag)
set SumoBaseObject tag
void addStringListAttribute(const SumoXMLAttr attr, const std::vector< std::string > &value)
add string list attribute into current SumoBaseObject node
void addDoubleAttribute(const SumoXMLAttr attr, const double value)
add double attribute into current SumoBaseObject node
const std::string & getStringAttribute(const SumoXMLAttr attr) const
get string attribute
const std::string getID() const
get ID (all Attribute Carriers have one)
SumoXMLAttr fillSumoBaseObject(CommonXMLStructure::SumoBaseObject *baseObject) const
fill sumo Base object
void refreshAttributesEditor()
refresh attribute editor
bool checkAttributes(const bool showWarning)
check if current edited attributes are valid
GNEViewNet * myViewNet
FOX need this.
Definition GNEFrame.h:121
virtual void show()
show Frame
Definition GNEFrame.cpp:117
virtual void hide()
hide Frame
Definition GNEFrame.cpp:126
const std::map< std::string, GNEEdge * > & getEdges() const
map with the ID and pointer to edges of net
GNEEdge * retrieveEdge(const std::string &id, bool hardFail=true) const
get edge by id
GNEDemandElement * retrieveDemandElement(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named demand element.
GNEPathManager * getDemandPathManager()
get demand path manager
Definition GNENet.cpp:174
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:144
void abortPathCreation()
abort path creation
const std::vector< GNEEdge * > & getSelectedEdges() const
get current selected edges
bool addEdge(GNEEdge *edge, const bool shiftKeyPressed, const bool controlKeyPressed)
add edge
const std::vector< Path > & getPath() const
get path route
virtual void computePathElement()=0
implement in children+
long onCmdSelectVClass(FXObject *, FXSelector, void *)
Called when the user select another VClass.
long onCmdSelectRouteMode(FXObject *, FXSelector, void *)
const RouteMode & getCurrentRouteMode() const
get current route mode
bool isValidMode() const
check if current mode is Valid
bool isValidVehicleClass() const
check if current VClass is Valid
void areParametersValid()
called after setting a new route or vclass, for showing moduls
void show()
show delete frame
CommonXMLStructure::SumoBaseObject * myRouteBaseObject
route base object
GNEPathCreator * myPathCreator
path creator modul
GNEPathLegendModule * myPathLegend
path legend modul
~GNERouteFrame()
Destructor.
GNEAttributesEditor * myRouteAttributesEditor
internal route attributes editor
GNERouteFrame(GNEViewParent *viewParent, GNEViewNet *viewNet)
Constructor.
bool createPath(const bool useLastRoute)
create path
RouteMode
route creation modes
void hide()
hide delete frame
GNEPathCreator * getPathCreator() const
get path creator module
RouteModeSelector * myRouteModeSelector
route mode selector
bool addEdgeRoute(GNEEdge *clickedEdge, const GNEViewNetHelper::MouseButtonKeyPressed &mouseButtonKeyPressed)
add route edge
GNENet * getNet() const
get the net object
GNEViewParent * getViewParent() const
get the net object
void setLastCreatedRoute(GNEDemandElement *lastCreatedRoute)
set last created route
void updateViewNet(const bool ignoreViewUpdater=true) const
Mark the entire GNEViewNet to be repainted later.
A single child window which contains a view of the simulation area.
GNEApplicationWindow * getGNEAppWindows() const
get GNE Application Windows
MFXGroupBoxModule (based on FXGroupBox)
void parseSumoBaseObject(CommonXMLStructure::SumoBaseObject *obj)
parse SumoBaseObject (it's called recursivelly)
C++ TraCI client API implementation.
class used to group all variables related with mouse buttons and key pressed after certain events
bool shiftKeyPressed() const
check if SHIFT is pressed during current event
bool controlKeyPressed() const
check if CONTROL is pressed during current event