Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
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-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 editing wires
19/****************************************************************************/
20
22#include <netedit/GNENet.h>
30
31#include "GNEWireFrame.h"
32
33// ===========================================================================
34// method definitions
35// ===========================================================================
36
38 GNEFrame(viewParent, viewNet, TL("Wires")) {
39
40 // create item Selector module for wires
42
43 // Create wire parameters
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
62void
64 // refresh tag selector
65 myWireTagSelector->refreshTagSelector();
66 // show frame
69 // show warning dialogbox about experimental state (only once)
70 GNEWarningBasicDialog(myViewNet->getViewParent()->getGNEAppWindows(), TL("Experimental Part"),
71 TL("Warning: The netedit overhead editor is still in experimental state."));
73 }
74}
75
76
77bool
79 // first check that current selected wire is valid
80 if (myWireTagSelector->getCurrentTemplateAC() == nullptr) {
81 myViewNet->setStatusBarText(TL("Current selected wire isn't valid."));
82 return false;
83 }
84 // show warning dialogbox and stop check if input parameters are valid
85 if (!myWireAttributesEditor->checkAttributes(true)) {
86 return false;
87 }
88 // obtain tagproperty (only for improve code legibility)
89 const auto& tagProperties = myWireTagSelector->getCurrentTemplateAC()->getTagProperty();
90 // create base wire
91 if (!createBaseWireObject(tagProperties)) {
92 return false;
93 }
94 // obtain attributes and values
95 myWireAttributesEditor->fillSumoBaseObject(myBaseWire);
96 if (tagProperties->getTag() == SUMO_TAG_OVERHEAD_WIRE_SECTION) {
97 return myConsecutiveLaneSelector->addLane(viewObjects.getLaneFront());
98 } else {
99 // build wire over view
100 return buildWireOverView(tagProperties);
101 }
102}
103
104
109
110
111bool
112GNEWireFrame::createPath(const bool /* useLastRoute */) {
113 // obtain tagproperty (only for improve code legibility)
114 const auto tagProperty = myWireTagSelector->getCurrentTemplateAC()->getTagProperty();
115 // first check that current tag is valid (currently only for overhead wires)
116 if (tagProperty->getTag() == SUMO_TAG_OVERHEAD_WIRE_SECTION) {
117 if (myConsecutiveLaneSelector->getLanePath().size() == 1) {
118 WRITE_WARNINGF(TL("A % needs at least two lane positions"), toString(SUMO_TAG_OVERHEAD_WIRE_SECTION));
119 } else if (createBaseWireObject(tagProperty)) {
120 // get attributes and values
121 myWireAttributesEditor->fillSumoBaseObject(myBaseWire);
122 // Check if ID has to be generated
123 if (!myBaseWire->hasStringAttribute(SUMO_ATTR_ID)) {
124 myBaseWire->addStringAttribute(SUMO_ATTR_ID, myViewNet->getNet()->getAttributeCarriers()->generateAdditionalID(tagProperty->getTag()));
125 }
126 // add lane IDs
127 myBaseWire->addStringListAttribute(SUMO_ATTR_LANES, myConsecutiveLaneSelector->getLaneIDPath());
128 // set positions
129 myBaseWire->addDoubleAttribute(SUMO_ATTR_STARTPOS, myConsecutiveLaneSelector->getLanePath().front().second);
130 myBaseWire->addDoubleAttribute(SUMO_ATTR_ENDPOS, myConsecutiveLaneSelector->getLanePath().back().second);
131 // show warning dialogbox and stop check if input parameters are valid
132 if (myWireAttributesEditor->checkAttributes(true)) {
133 // declare additional handler
134 GNEAdditionalHandler additionalHandler(myViewNet->getNet(), myBaseWire->hasStringAttribute(GNE_ATTR_ADDITIONAL_FILE) ?
135 myBaseWire->getStringAttribute(GNE_ATTR_ADDITIONAL_FILE) : "",
136 myViewNet->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed());
137 // build additional
138 additionalHandler.parseSumoBaseObject(myBaseWire);
139 // Refresh wire Parent Selector (For additionals that have a limited number of children)
140 mySelectorWireParent->refreshSelectorParentModule();
141 // abort overhead wire creation
142 myConsecutiveLaneSelector->abortPathCreation();
143 // refresh additional attributes
144 myWireAttributesEditor->refreshAttributesEditor();
145 return true;
146 }
147 }
148 }
149 return false;
150}
151
152
153void
155 // get template AC
156 const auto templateAC = myWireTagSelector->getCurrentTemplateAC();
157 // check if templateAC Exist
158 if (templateAC) {
159 // show wire attributes module
160 myWireAttributesEditor->showAttributesEditor(templateAC, true);
161 // check if we're creating a overhead wire section
162 if (templateAC->getTagProperty()->getTag() == SUMO_TAG_OVERHEAD_WIRE_SECTION) {
163 myConsecutiveLaneSelector->showConsecutiveLaneSelectorModule();
164 mySelectorWireParent->showSelectorParentModule({SUMO_TAG_TRACTION_SUBSTATION});
165 } else {
166 myConsecutiveLaneSelector->hideConsecutiveLaneSelectorModule();
167 mySelectorWireParent->hideSelectorParentModule();
168 }
169 } else {
170 // hide all modules if wire isn't valid
171 myWireAttributesEditor->hideAttributesEditor();
172 myConsecutiveLaneSelector->hideConsecutiveLaneSelectorModule();
173 mySelectorWireParent->hideSelectorParentModule();
174 }
175}
176
177
178bool
180 // check if baseWire exist, and if yes, delete it
181 if (myBaseWire) {
182 // go to base wire root
183 while (myBaseWire->getParentSumoBaseObject()) {
184 myBaseWire = myBaseWire->getParentSumoBaseObject();
185 }
186 // delete baseWire (and all children)
187 delete myBaseWire;
188 // reset baseWire
189 myBaseWire = nullptr;
190 }
191 // create a base wire object
193 // check if wire is a overheadWIre
194 if (tagProperty->getTag() == SUMO_TAG_OVERHEAD_WIRE_SECTION) {
195 // get wire under cursor
196 const GNEAdditional* wireUnderCursor = myViewNet->getViewObjectsSelector().getAdditionalFront();
197 // if user click over a traction substation, mark int in ParentWireSelector
198 if (wireUnderCursor && (wireUnderCursor->getTagProperty()->getTag() == SUMO_TAG_TRACTION_SUBSTATION)) {
199 // update parent wire selected
200 mySelectorWireParent->setIDSelected(wireUnderCursor->getID());
201 }
202 // stop if currently there isn't a valid selected parent
203 if (mySelectorWireParent->getIdSelected().empty()) {
204 WRITE_WARNING(TLF("A % must be selected before insertion of %.", toString(SUMO_TAG_TRACTION_SUBSTATION), toString(SUMO_TAG_TRACTION_SUBSTATION)));
205 return false;
206 } else {
207 // add tractionsubstation id
208 myBaseWire->addStringAttribute(SUMO_ATTR_SUBSTATIONID, mySelectorWireParent->getIdSelected());
209 }
210 }
211 // set baseWire tag
212 myBaseWire->setTag(tagProperty->getTag());
213 // BaseWire created, then return true
214 return true;
215}
216
217
218bool
220 // disable intervals (temporal)
221 if ((tagProperty->getTag() == SUMO_TAG_INTERVAL) ||
222 (tagProperty->getTag() == SUMO_TAG_DEST_PROB_REROUTE) ||
223 (tagProperty->getTag() == SUMO_TAG_CLOSING_REROUTE) ||
224 (tagProperty->getTag() == SUMO_TAG_CLOSING_LANE_REROUTE) ||
225 (tagProperty->getTag() == SUMO_TAG_ROUTE_PROB_REROUTE) ||
226 (tagProperty->getTag() == SUMO_TAG_PARKING_AREA_REROUTE)) {
227 WRITE_WARNING(TL("Currently unsupported. Create rerouter elements using rerouter dialog"));
228 return false;
229 }
230 // disable intervals (temporal)
231 if (tagProperty->getTag() == SUMO_TAG_STEP) {
232 WRITE_WARNING(TL("Currently unsupported. Create VSS steps elements using VSS dialog"));
233 return false;
234 }
235 // Check if ID has to be generated
236 if (!myBaseWire->hasStringAttribute(SUMO_ATTR_ID)) {
237 myBaseWire->addStringAttribute(SUMO_ATTR_ID, myViewNet->getNet()->getAttributeCarriers()->generateAdditionalID(tagProperty->getTag()));
238 }
239 // Obtain position as the clicked position over view
240 const Position viewPos = myViewNet->snapToActiveGrid(myViewNet->getPositionInformation());
241 // add position and X-Y-Z attributes
242 myBaseWire->addPositionAttribute(SUMO_ATTR_POSITION, viewPos);
243 myBaseWire->addDoubleAttribute(SUMO_ATTR_X, viewPos.x());
244 myBaseWire->addDoubleAttribute(SUMO_ATTR_Y, viewPos.y());
245 myBaseWire->addDoubleAttribute(SUMO_ATTR_Z, viewPos.z());
246 // show warning dialogbox and stop check if input parameters are valid
247 if (!myWireAttributesEditor->checkAttributes(true)) {
248 return false;
249 } else {
250 // declare additional handler
251 GNEAdditionalHandler additionalHandler(myViewNet->getNet(), myBaseWire->hasStringAttribute(GNE_ATTR_ADDITIONAL_FILE) ?
252 myBaseWire->getStringAttribute(GNE_ATTR_ADDITIONAL_FILE) : "",
253 myViewNet->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed());
254 // build wire
255 additionalHandler.parseSumoBaseObject(myBaseWire);
256 // Refresh wire Parent Selector (For wires that have a limited number of children)
257 mySelectorWireParent->refreshSelectorParentModule();
258 // refresh wire attributes
259 myWireAttributesEditor->refreshAttributesEditor();
260 return true;
261 }
262}
263
264/****************************************************************************/
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:287
#define WRITE_WARNING(msg)
Definition MsgHandler.h:286
#define TL(string)
Definition MsgHandler.h:304
#define TLF(string,...)
Definition MsgHandler.h:306
@ 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
@ GNE_ATTR_ADDITIONAL_FILE
additional save file
@ 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)
const std::string getID() const override
get ID (all Attribute Carriers have one)
const GNETagProperties * getTagProperty() const
get tagProperty associated with this Attribute Carrier
GNEViewNet * myViewNet
FOX need this.
Definition GNEFrame.h:122
virtual void show()
show Frame
Definition GNEFrame.cpp:110
GNEFrame(GNEViewParent *viewParent, GNEViewNet *viewNet, const std::string &frameLabel)
Constructor.
Definition GNEFrame.cpp:42
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
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
A single child window which contains a view of the simulation area.
void tagSelected()
Tag selected in GNETagSelector.
GNEAttributesEditor * myWireAttributesEditor
internal wire attributes
~GNEWireFrame()
Destructor.
GNEConsecutiveSelector * getConsecutiveLaneSelector() const
get consecutive lane selector
bool createPath(const bool useLastRoute)
create path
bool buildWireOverView(const GNETagProperties *tagProperty)
build wire over view
bool createBaseWireObject(const GNETagProperties *tagProperty)
void show()
show wire frame
bool myWarnedExperimental
Warn about experimental state.
bool addWire(const GNEViewNetHelper::ViewObjectsSelector &viewObjects)
add wire element
GNESelectorParent * mySelectorWireParent
Select wire parent.
GNETagSelector * myWireTagSelector
item selector
GNEWireFrame(GNEViewParent *viewParent, GNEViewNet *viewNet)
Constructor.
CommonXMLStructure::SumoBaseObject * myBaseWire
SumoBaseObject used for create wire.
GNEConsecutiveSelector * myConsecutiveLaneSelector
Module for select consecutive lanes.
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:52
double z() const
Returns the z-position.
Definition Position.h:62
double y() const
Returns the y-position.
Definition Position.h:57