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-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// The Widget for remove network-elements
19/****************************************************************************/
20#include <config.h>
21
23#include <netedit/GNENet.h>
24#include <netedit/GNEViewNet.h>
29
30#include "GNERouteFrame.h"
31
32// ===========================================================================
33// FOX callback mapping
34// ===========================================================================
35
40
41// Object implementation
42FXIMPLEMENT(GNERouteFrame::RouteModeSelector, MFXGroupBoxModule, RouteModeSelectorMap, ARRAYNUMBER(RouteModeSelectorMap))
43
44
45// ===========================================================================
46// method definitions
47// ===========================================================================
48
49// ---------------------------------------------------------------------------
50// GNERouteFrame::RouteModeSelector - methods
51// ---------------------------------------------------------------------------
52
54 MFXGroupBoxModule(routeFrameParent, TL("Route mode")),
55 myRouteFrameParent(routeFrameParent) {
56 // create route template
57 myRouteTemplate = new GNERoute(SUMO_TAG_ROUTE, routeFrameParent->getViewNet()->getNet());
58 // first fill myRouteModesStrings
59 myRouteModesStrings.push_back(std::make_pair(RouteMode::NONCONSECUTIVE_EDGES, "non consecutive edges"));
60 myRouteModesStrings.push_back(std::make_pair(RouteMode::CONSECUTIVE_EDGES, "consecutive edges"));
61 // Create MFXComboBoxIcon for Route mode
62 myRouteModeMatchBox = new MFXComboBoxIcon(getCollapsableFrame(), GUIDesignComboBoxNCol, false, GUIDesignComboBoxVisibleItems,
64 // fill myRouteModeMatchBox with route modes
65 for (const auto& routeMode : myRouteModesStrings) {
66 myRouteModeMatchBox->appendIconItem(routeMode.second.c_str());
67 }
68 // Create MFXComboBoxIcon for VClass
69 myVClassMatchBox = new MFXComboBoxIcon(getCollapsableFrame(), GUIDesignComboBoxNCol, false, GUIDesignComboBoxVisibleItems,
71 // fill myVClassMatchBox with all VCLass
72 for (const auto& vClass : SumoVehicleClassStrings.getStrings()) {
73 myVClassMatchBox->appendIconItem(vClass.c_str());
74 }
75 // set Passenger als default VCLass
76 myVClassMatchBox->setCurrentItem(7);
77 // RouteModeSelector is always shown
78 show();
79}
80
81
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 // check if current mode is valid
108 if ((myCurrentRouteMode != RouteMode::INVALID) && myValidVClass) {
109 // check if create routes consecutively
110 const bool consecutiveEdges = (myCurrentRouteMode == RouteMode::CONSECUTIVE_EDGES);
111 // show route attributes modul
112 myRouteFrameParent->myRouteAttributes->showAttributesCreatorModule(myRouteTemplate, {});
113 // show path creator
114 myRouteFrameParent->myPathCreator->showPathCreatorModule(myRouteTemplate->getTagProperty(), consecutiveEdges);
115 // update edge colors
116 myRouteFrameParent->myPathCreator->updateEdgeColors();
117 // show legend
118 myRouteFrameParent->myPathLegend->showPathLegendModule();
119 } else {
120 // hide all moduls if route mode isnt' valid
121 myRouteFrameParent->myRouteAttributes->hideAttributesCreatorModule();
122 myRouteFrameParent->myPathCreator->hidePathCreatorModule();
123 myRouteFrameParent->myPathLegend->hidePathLegendModule();
124 // reset all flags
125 for (const auto& edge : myRouteFrameParent->myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
126 edge.second->resetCandidateFlags();
127 }
128 // update view net
129 myRouteFrameParent->myViewNet->update();
130 }
131}
132
133
134long
136 // first abort all current operations in moduls
137 myRouteFrameParent->myPathCreator->onCmdAbortPathCreation(0, 0, 0);
138 // set invalid current route mode
139 myCurrentRouteMode = RouteMode::INVALID;
140 // set color of myTypeMatchBox to red (invalid)
141 myRouteModeMatchBox->setTextColor(FXRGB(255, 0, 0));
142 // Check if value of myTypeMatchBox correspond of an allowed additional tags
143 for (const auto& routeMode : myRouteModesStrings) {
144 if (routeMode.second == myRouteModeMatchBox->getText().text()) {
145 // Set new current type
146 myCurrentRouteMode = routeMode.first;
147 // set color of myTypeMatchBox to black (valid)
148 myRouteModeMatchBox->setTextColor(FXRGB(0, 0, 0));
149 // Write Warning in console if we're in testing mode
150 WRITE_DEBUG(("Selected RouteMode '" + myRouteModeMatchBox->getText() + "' in RouteModeSelector").text());
151 }
152 }
153 // check if parameters are valid
154 areParametersValid();
155 return 1;
156}
157
158
159long
161 // first abort all current operations in moduls
162 myRouteFrameParent->myPathCreator->onCmdAbortPathCreation(0, 0, 0);
163 // set vClass flag invalid
164 myValidVClass = false;
165 // set color of myTypeMatchBox to red (invalid)
166 myVClassMatchBox->setTextColor(FXRGB(255, 0, 0));
167 // Check if value of myTypeMatchBox correspond of an allowed additional tags
168 for (const auto& vClass : SumoVehicleClassStrings.getStrings()) {
169 if (vClass == myVClassMatchBox->getText().text()) {
170 // change flag
171 myValidVClass = true;
172 // set color of myTypeMatchBox to black (valid)
173 myVClassMatchBox->setTextColor(FXRGB(0, 0, 0));
174 // set vClass in Path creator
175 myRouteFrameParent->myPathCreator->setVClass(SumoVehicleClassStrings.get(vClass));
176 // Write Warning in console if we're in testing mode
177 WRITE_DEBUG(("Selected VClass '" + myVClassMatchBox->getText() + "' in RouteModeSelector").text());
178 }
179 }
180 // check if parameters are valid
181 areParametersValid();
182 return 1;
183}
184
185// ---------------------------------------------------------------------------
186// GNERouteFrame - methods
187// ---------------------------------------------------------------------------
188
190 GNEFrame(viewParent, viewNet, TL("Routes")),
191 myRouteHandler("", myViewNet->getNet(), myViewNet->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed(), false),
192 myRouteBaseObject(new CommonXMLStructure::SumoBaseObject(nullptr)) {
193
194 // create route mode Selector module
196
197 // Create route parameters
199
200 // create consecutive edges module
201 myPathCreator = new GNEPathCreator(this, viewNet->getNet()->getDemandPathManager());
202
203 // create legend label
205}
206
207
211
212
213void
215 // call are parameters valid
217 // show route frame
219}
220
221
222void
224 // reset candidate edges
225 for (const auto& edge : myViewNet->getNet()->getAttributeCarriers()->getEdges()) {
226 edge.second->resetCandidateFlags();
227 }
229}
230
231
232bool
234 // first check if current vClass and mode are valid and edge exist
236 // add edge in path
237 myPathCreator->addEdge(clickedEdge, mouseButtonKeyPressed.shiftKeyPressed(), mouseButtonKeyPressed.controlKeyPressed());
238 // update view
240 return true;
241 } else {
242 return false;
243 }
244}
245
246
251
252
253bool
254GNERouteFrame::createPath(const bool /*useLastRoute*/) {
255 // check that route attributes are valid
258 } else if (myPathCreator->getSelectedEdges().size() > 0) {
259 // clear base object
261 // set tag
263 // obtain attributes
267 }
268 // add probability (needed for distributions)
270 // declare edge vector
271 std::vector<std::string> edges;
272 for (const auto& path : myPathCreator->getPath()) {
273 for (const auto& edgeID : path.getSubPath()) {
274 // get edge
275 GNEEdge* edge = myViewNet->getNet()->getAttributeCarriers()->retrieveEdge(edgeID->getID());
276 // avoid double edges
277 if (edges.empty() || (edges.back() != edge->getID())) {
278 edges.push_back(edge->getID());
279 }
280 }
281 }
282 // set edges in route base object
284 // create route
286 // abort path creation
288 // refresh route attributes
290 // get new route
292 // compute path route
293 newRoute->computePathElement();
294 // set as last created route
296 return true;
297 }
298 return false;
299}
300
301/****************************************************************************/
FXDEFMAP(GNERouteFrame::RouteModeSelector) RouteModeSelectorMap[]
@ MID_GNE_ROUTEFRAME_ROUTEMODE
select a route mode
@ MID_GNE_ROUTEFRAME_VCLASS
select a VClass
#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
StringBijection< SUMOVehicleClass > SumoVehicleClassStrings(sumoVehicleClassStringInitializer, SVC_CUSTOM2, false)
@ SUMO_TAG_ROUTE
begin/end of the description of a route
@ 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
void addStringAttribute(const SumoXMLAttr attr, const std::string &value)
add string 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)
void getAttributesAndValues(CommonXMLStructure::SumoBaseObject *baseObject, bool includeAll) const
get attributes and their values
bool areValuesValid() const
check if parameters of attributes are valid
void showWarningMessage(std::string extra="") const
show warning message with information about non-valid attributes
void refreshAttributesCreator()
refresh attribute creator
virtual void computePathElement()=0
compute pathElement
A road/street connecting two junctions (netedit-version)
Definition GNEEdge.h:53
GNEViewNet * myViewNet
FOX need this.
Definition GNEFrame.h:115
virtual void show()
show Frame
Definition GNEFrame.cpp:115
virtual void hide()
hide Frame
Definition GNEFrame.cpp:124
std::string generateDemandElementID(SumoXMLTag tag) const
generate demand element id
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:145
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:127
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
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
GNERoute * myRouteTemplate
route template
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
GNEAttributesCreator * myRouteAttributes
internal route attributes
GNEPathLegendModule * myPathLegend
path legend modul
GNERouteHandler myRouteHandler
route handler
~GNERouteFrame()
Destructor.
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
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.
ComboBox with icon.
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