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  if (!myWarnedExperimental) {
69  FXMessageBox::warning(getApp(), MBOX_OK, TL("Experimental Part"), "%s", TL("Warning: The netedit overhead editor is still in experimental state."));
70  myWarnedExperimental = true;
71  }
72 }
73 
74 
75 bool
77  // first check that current selected wire is valid
78  if (myWireTagSelector->getCurrentTemplateAC() == nullptr) {
79  myViewNet->setStatusBarText(TL("Current selected wire isn't valid."));
80  return false;
81  }
82  // show warning dialogbox and stop check if input parameters are valid
85  return false;
86  }
87  // obtain tagproperty (only for improve code legibility)
88  const auto& tagProperties = myWireTagSelector->getCurrentTemplateAC()->getTagProperty();
89  // create base wire
90  if (!createBaseWireObject(tagProperties)) {
91  return false;
92  }
93  // obtain attributes and values
95  // fill netedit attributes
97  return false;
98  }
99  if (tagProperties.getTag() == SUMO_TAG_OVERHEAD_WIRE_SECTION) {
100  return myConsecutiveLaneSelector->addLane(viewObjects.getLaneFront());
101  } else {
102  // build wire over view
103  return buildWireOverView(tagProperties);
104  }
105 }
106 
107 
111 }
112 
113 
114 bool
115 GNEWireFrame::createPath(const bool /* useLastRoute */) {
116  // obtain tagproperty (only for improve code legibility)
117  const auto& tagProperty = myWireTagSelector->getCurrentTemplateAC()->getTagProperty();
118  // first check that current tag is valid (currently only for overhead wires)
119  if (tagProperty.getTag() == SUMO_TAG_OVERHEAD_WIRE_SECTION) {
120  if (myConsecutiveLaneSelector->getLanePath().size() == 1) {
121  WRITE_WARNINGF(TL("A % needs at least two lane positions"), toString(SUMO_TAG_OVERHEAD_WIRE_SECTION));
122  } else if (createBaseWireObject(tagProperty)) {
123  // get attributes and values
125  // fill netedit attributes
127  // Check if ID has to be generated
130  }
131  // add lane IDs
133  // set positions
136  // show warning dialogbox and stop check if input parameters are valid
139  } else {
140  // declare additional handler
141  GNEAdditionalHandler additionalHandler(getViewNet()->getNet(), true, false);
142  // build additional
143  additionalHandler.parseSumoBaseObject(myBaseWire);
144  // Refresh wire Parent Selector (For additionals that have a limited number of children)
146  // abort overhead wire creation
148  // refresh additional attributes
150  return true;
151  }
152  }
153  }
154  }
155  return false;
156 }
157 
158 
159 void
161  // get template AC
162  const auto templateAC = myWireTagSelector->getCurrentTemplateAC();
163  // check if templateAC Exist
164  if (templateAC) {
165  // show wire attributes module
167  // show netedit attributes
169  // check if we're creating a overhead wire section
170  if (templateAC->getTagProperty().getTag() == SUMO_TAG_OVERHEAD_WIRE_SECTION) {
173  } else {
176  }
177  } else {
178  // hide all modules if wire isn't valid
183  }
184 }
185 
186 
187 bool
189  // check if baseWire exist, and if yes, delete it
190  if (myBaseWire) {
191  // go to base wire root
194  }
195  // delete baseWire (and all children)
196  delete myBaseWire;
197  // reset baseWire
198  myBaseWire = nullptr;
199  }
200  // create a base wire object
202  // check if wire is a overheadWIre
203  if (tagProperty.getTag() == SUMO_TAG_OVERHEAD_WIRE_SECTION) {
204  // get wire under cursor
206  // if user click over a traction substation, mark int in ParentWireSelector
207  if (wireUnderCursor && (wireUnderCursor->getTagProperty().getTag() == SUMO_TAG_TRACTION_SUBSTATION)) {
208  // update parent wire selected
209  mySelectorWireParent->setIDSelected(wireUnderCursor->getID());
210  }
211  // stop if currently there isn't a valid selected parent
212  if (mySelectorWireParent->getIdSelected().empty()) {
213  myWireAttributes->showWarningMessage("A " + toString(SUMO_TAG_TRACTION_SUBSTATION) + " must be selected before insertion of " + toString(SUMO_TAG_TRACTION_SUBSTATION) + ".");
214  return false;
215  } else {
216  // add tractionsubstation id
218  }
219  }
220  // set baseWire tag
221  myBaseWire->setTag(tagProperty.getTag());
222  // BaseWire created, then return true
223  return true;
224 }
225 
226 
227 bool
229  // disable intervals (temporal)
230  if ((tagProperties.getTag() == SUMO_TAG_INTERVAL) ||
231  (tagProperties.getTag() == SUMO_TAG_DEST_PROB_REROUTE) ||
232  (tagProperties.getTag() == SUMO_TAG_CLOSING_REROUTE) ||
233  (tagProperties.getTag() == SUMO_TAG_CLOSING_LANE_REROUTE) ||
234  (tagProperties.getTag() == SUMO_TAG_ROUTE_PROB_REROUTE) ||
235  (tagProperties.getTag() == SUMO_TAG_PARKING_AREA_REROUTE)) {
236  WRITE_WARNING(TL("Currently unsupported. Create rerouter elements using rerouter dialog"));
237  return false;
238  }
239  // disable intervals (temporal)
240  if (tagProperties.getTag() == SUMO_TAG_STEP) {
241  WRITE_WARNING(TL("Currently unsupported. Create VSS steps elements using VSS dialog"));
242  return false;
243  }
244  // Check if ID has to be generated
247  }
248  // Obtain position as the clicked position over view
250  // add position and X-Y-Z attributes
255  // show warning dialogbox and stop check if input parameters are valid
258  return false;
259  } else {
260  // declare additional handler
261  GNEAdditionalHandler additionalHandler(myViewNet->getNet(), true, false);
262  // build wire
263  additionalHandler.parseSumoBaseObject(myBaseWire);
264  // Refresh wire Parent Selector (For wires that have a limited number of children)
266  // refresh wire attributes
268  return true;
269  }
270 }
271 
272 /****************************************************************************/
#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:123
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:477
void setStatusBarText(const std::string &text)
set statusBar text
Definition: GNEViewNet.cpp:827
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 myWarnedExperimental
Warn about experimental state.
Definition: GNEWireFrame.h:95
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