Eclipse SUMO - Simulation of Urban MObility
GNEWireFrame.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2021-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 editing wires
19 /****************************************************************************/
20 #include <config.h>
21 
22 #include <netedit/GNENet.h>
23 #include <netedit/GNEViewNet.h>
25 
26 #include "GNEWireFrame.h"
27 
28 
29 // ===========================================================================
30 // method definitions
31 // ===========================================================================
32 
33 
35  GNEFrame(viewParent, viewNet, TL("Wires")) {
36 
37  // create item Selector module for wires
38  myWireTagSelector = new GNETagSelector(this, GNETagProperties::TagType::WIRE, SUMO_TAG_TRACTION_SUBSTATION);
39 
40  // Create wire parameters
42 
43  // Create Netedit parameter
45 
46  // Create selector parent
48 
49  // Create list for E2Multilane lane selector
51 }
52 
53 
55  // check if we have to delete base wire object
56  if (myBaseWire) {
57  delete myBaseWire;
58  }
59 }
60 
61 
62 void
64  // refresh tag selector
66  // show frame
68 }
69 
70 
71 bool
73  // first check that current selected wire is valid
74  if (myWireTagSelector->getCurrentTemplateAC() == nullptr) {
75  myViewNet->setStatusBarText(TL("Current selected wire isn't valid."));
76  return false;
77  }
78  // show warning dialogbox and stop check if input parameters are valid
81  return false;
82  }
83  // obtain tagproperty (only for improve code legibility)
84  const auto& tagProperties = myWireTagSelector->getCurrentTemplateAC()->getTagProperty();
85  // create base wire
86  if (!createBaseWireObject(tagProperties)) {
87  return false;
88  }
89  // obtain attributes and values
91  // fill netedit attributes
93  return false;
94  }
95  if (tagProperties.getTag() == SUMO_TAG_OVERHEAD_WIRE_SECTION) {
96  return myConsecutiveLaneSelector->addLane(viewObjects.getLaneFront());
97  } else {
98  // build wire over view
99  return buildWireOverView(tagProperties);
100  }
101 }
102 
103 
107 }
108 
109 
110 bool
111 GNEWireFrame::createPath(const bool /* useLastRoute */) {
112  // obtain tagproperty (only for improve code legibility)
113  const auto& tagProperty = myWireTagSelector->getCurrentTemplateAC()->getTagProperty();
114  // first check that current tag is valid (currently only for overhead wires)
115  if (tagProperty.getTag() == SUMO_TAG_OVERHEAD_WIRE_SECTION) {
116  if (myConsecutiveLaneSelector->getLanePath().size() == 1) {
117  WRITE_WARNINGF(TL("A % needs at least two lane positions"), toString(SUMO_TAG_OVERHEAD_WIRE_SECTION));
118  } else if (createBaseWireObject(tagProperty)) {
119  // get attributes and values
121  // fill netedit attributes
123  // Check if ID has to be generated
126  }
127  // add lane IDs
129  // set positions
132  // show warning dialogbox and stop check if input parameters are valid
135  } else {
136  // declare additional handler
137  GNEAdditionalHandler additionalHandler(getViewNet()->getNet(), true, false);
138  // build additional
139  additionalHandler.parseSumoBaseObject(myBaseWire);
140  // Refresh wire Parent Selector (For additionals that have a limited number of children)
142  // abort overhead wire creation
144  // refresh additional attributes
146  return true;
147  }
148  }
149  }
150  }
151  return false;
152 }
153 
154 
155 void
157  // get template AC
158  const auto templateAC = myWireTagSelector->getCurrentTemplateAC();
159  // check if templateAC Exist
160  if (templateAC) {
161  // show wire attributes module
163  // show netedit attributes
165  // check if we're creating a overhead wire section
166  if (templateAC->getTagProperty().getTag() == SUMO_TAG_OVERHEAD_WIRE_SECTION) {
169  } else {
172  }
173  } else {
174  // hide all modules if wire isn't valid
179  }
180 }
181 
182 
183 bool
185  // check if baseWire exist, and if yes, delete it
186  if (myBaseWire) {
187  // go to base wire root
190  }
191  // delete baseWire (and all children)
192  delete myBaseWire;
193  // reset baseWire
194  myBaseWire = nullptr;
195  }
196  // create a base wire object
198  // check if wire is a overheadWIre
199  if (tagProperty.getTag() == SUMO_TAG_OVERHEAD_WIRE_SECTION) {
200  // get wire under cursor
202  // if user click over a traction substation, mark int in ParentWireSelector
203  if (wireUnderCursor && (wireUnderCursor->getTagProperty().getTag() == SUMO_TAG_TRACTION_SUBSTATION)) {
204  // update parent wire selected
205  mySelectorWireParent->setIDSelected(wireUnderCursor->getID());
206  }
207  // stop if currently there isn't a valid selected parent
208  if (mySelectorWireParent->getIdSelected().empty()) {
209  myWireAttributes->showWarningMessage("A " + toString(SUMO_TAG_TRACTION_SUBSTATION) + " must be selected before insertion of " + toString(SUMO_TAG_TRACTION_SUBSTATION) + ".");
210  return false;
211  } else {
212  // add tractionsubstation id
214  }
215  }
216  // set baseWire tag
217  myBaseWire->setTag(tagProperty.getTag());
218  // BaseWire created, then return true
219  return true;
220 }
221 
222 
223 bool
225  // disable intervals (temporal)
226  if ((tagProperties.getTag() == SUMO_TAG_INTERVAL) ||
227  (tagProperties.getTag() == SUMO_TAG_DEST_PROB_REROUTE) ||
228  (tagProperties.getTag() == SUMO_TAG_CLOSING_REROUTE) ||
229  (tagProperties.getTag() == SUMO_TAG_CLOSING_LANE_REROUTE) ||
230  (tagProperties.getTag() == SUMO_TAG_ROUTE_PROB_REROUTE) ||
231  (tagProperties.getTag() == SUMO_TAG_PARKING_AREA_REROUTE)) {
232  WRITE_WARNING(TL("Currently unsupported. Create rerouter elements using rerouter dialog"));
233  return false;
234  }
235  // disable intervals (temporal)
236  if (tagProperties.getTag() == SUMO_TAG_STEP) {
237  WRITE_WARNING(TL("Currently unsupported. Create VSS steps elements using VSS dialog"));
238  return false;
239  }
240  // Check if ID has to be generated
243  }
244  // Obtain position as the clicked position over view
246  // add position and X-Y-Z attributes
251  // show warning dialogbox and stop check if input parameters are valid
254  return false;
255  } else {
256  // declare additional handler
257  GNEAdditionalHandler additionalHandler(myViewNet->getNet(), true, false);
258  // build wire
259  additionalHandler.parseSumoBaseObject(myBaseWire);
260  // Refresh wire Parent Selector (For wires that have a limited number of children)
262  // refresh wire attributes
264  return true;
265  }
266 }
267 
268 /****************************************************************************/
#define WRITE_WARNINGF(...)
Definition: MsgHandler.h:296
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:295
#define TL(string)
Definition: MsgHandler.h:315
@ SUMO_TAG_TRACTION_SUBSTATION
A traction substation.
@ SUMO_TAG_INTERVAL
an aggreagated-output interval
@ SUMO_TAG_CLOSING_REROUTE
reroute of type closing
@ SUMO_TAG_PARKING_AREA_REROUTE
entry for an alternative parking zone
@ SUMO_TAG_STEP
trigger: a step description
@ SUMO_TAG_ROUTE_PROB_REROUTE
probability of route of a reroute
@ SUMO_TAG_OVERHEAD_WIRE_SECTION
An overhead wire section.
@ SUMO_TAG_DEST_PROB_REROUTE
probability of destination of a reroute
@ SUMO_TAG_CLOSING_LANE_REROUTE
lane of a reroute of type closing
@ SUMO_ATTR_STARTPOS
@ SUMO_ATTR_Y
@ SUMO_ATTR_SUBSTATIONID
id of a traction substation substation
@ SUMO_ATTR_Z
@ SUMO_ATTR_ENDPOS
@ SUMO_ATTR_X
@ SUMO_ATTR_LANES
@ SUMO_ATTR_ID
@ SUMO_ATTR_POSITION
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
void parseSumoBaseObject(CommonXMLStructure::SumoBaseObject *obj)
parse SumoBaseObject (it's called recursivelly)
bool hasStringAttribute(const SumoXMLAttr attr) const
has function
void setTag(const SumoXMLTag tag)
set SumoBaseObject tag
SumoBaseObject * getParentSumoBaseObject() const
get pointer to mySumoBaseObjectParent SumoBaseObject (if is null, then is the root)
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 addPositionAttribute(const SumoXMLAttr attr, const Position &value)
add Position attribute into current SumoBaseObject node
void addStringAttribute(const SumoXMLAttr attr, const std::string &value)
add string attribute into current SumoBaseObject node
Builds additional objects for GNENet (busStops, chargingStations, detectors, etc.....
An Element which don't belong to GNENet but has influence in the simulation.
Definition: GNEAdditional.h:49
const std::string getID() const
get ID (all Attribute Carriers have one)
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
void getAttributesAndValues(CommonXMLStructure::SumoBaseObject *baseObject, bool includeAll) const
get attributes and their values
bool areValuesValid() const
check if parameters of attributes are valid
void showAttributesCreatorModule(GNEAttributeCarrier *templateAC, const std::vector< SumoXMLAttr > &hiddenAttributes)
show GNEAttributesCreator modul
void hideAttributesCreatorModule()
hide group box
void showWarningMessage(std::string extra="") const
show warning message with information about non-valid attributes
void refreshAttributesCreator()
refresh attribute creator
bool addLane(GNELane *lane)
add lane
void abortPathCreation()
abort path creation
void showConsecutiveLaneSelectorModule()
show GNEConsecutiveSelector
const std::vector< std::pair< GNELane *, double > > & getLanePath() const
get vector with lanes and clicked positions
void hideConsecutiveLaneSelectorModule()
show GNEConsecutiveSelector
const std::vector< std::string > getLaneIDPath() const
get lane IDs
GNEViewNet * getViewNet() const
get view net
Definition: GNEFrame.cpp:150
GNEViewNet * myViewNet
FOX need this.
Definition: GNEFrame.h:117
virtual void show()
show Frame
Definition: GNEFrame.cpp:115
std::string generateAdditionalID(SumoXMLTag type) const
generate additional id
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition: GNENet.cpp:121
void showNeteditAttributesModule(GNEAttributeCarrier *templateAC)
show Netedit attributes modul
void hideNeteditAttributesModule()
hide Netedit attributes modul
bool getNeteditAttributesAndValues(CommonXMLStructure::SumoBaseObject *baseObject, const GNELane *lane) const
fill valuesMap with netedit attributes
void setIDSelected(const std::string &id)
select manually a element of the list
void showSelectorParentModule(const std::vector< SumoXMLTag > &parentTags)
Show list of GNESelectorParent Module.
void refreshSelectorParentModule()
Refresh list of Additional Parents Module.
std::string getIdSelected() const
get currently parent additional selected
void hideSelectorParentModule()
hide GNESelectorParent Module
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
void refreshTagSelector()
refresh tagSelector (used when frameParent is show)
GNEAttributeCarrier * getCurrentTemplateAC() const
get current templateAC
class used to group all variables related with objects under cursor after a click over view
GNELane * getLaneFront() const
get front lane or a pointer to nullptr
GNEAdditional * getAdditionalFront() const
get front additional element or a pointer to nullptr
GNENet * getNet() const
get the net object
const GNEViewNetHelper::ViewObjectsSelector & getViewObjectsSelector() const
get objects under cursor
Definition: GNEViewNet.cpp:468
void setStatusBarText(const std::string &text)
set statusBar text
Definition: GNEViewNet.cpp:841
A single child window which contains a view of the simulation area.
Definition: GNEViewParent.h:88
GNEAttributesCreator * myWireAttributes
internal wire attributes
Definition: GNEWireFrame.h:83
void tagSelected()
Tag selected in GNETagSelector.
~GNEWireFrame()
Destructor.
GNEConsecutiveSelector * getConsecutiveLaneSelector() const
get consecutive lane selector
bool createPath(const bool useLastRoute)
create path
GNENeteditAttributes * myNeteditAttributes
Netedit parameter.
Definition: GNEWireFrame.h:86
void show()
show wire frame
bool addWire(const GNEViewNetHelper::ViewObjectsSelector &viewObjects)
add wire element
GNESelectorParent * mySelectorWireParent
Select wire parent.
Definition: GNEWireFrame.h:89
GNETagSelector * myWireTagSelector
item selector
Definition: GNEWireFrame.h:80
bool buildWireOverView(const GNETagProperties &tagValues)
build wire over view
GNEWireFrame(GNEViewParent *viewParent, GNEViewNet *viewNet)
Constructor.
CommonXMLStructure::SumoBaseObject * myBaseWire
SumoBaseObject used for create wire.
Definition: GNEWireFrame.h:67
GNEConsecutiveSelector * myConsecutiveLaneSelector
Module for select consecutive lanes.
Definition: GNEWireFrame.h:92
bool createBaseWireObject(const GNETagProperties &tagProperty)
Position snapToActiveGrid(const Position &pos, bool snapXY=true) const
Returns a position that is mapped to the closest grid point if the grid is active.
virtual Position getPositionInformation() const
Returns the cursor's x/y position within the network.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
double x() const
Returns the x-position.
Definition: Position.h:55
double z() const
Returns the z-position.
Definition: Position.h:65
double y() const
Returns the y-position.
Definition: Position.h:60