Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/frames/network/GNEWireFrame.cpp
169685 views
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
/****************************************************************************/
14
/// @file GNEWireFrame.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Nov 2021
17
///
18
// The Widget for editing wires
19
/****************************************************************************/
20
21
#include <netedit/GNEApplicationWindow.h>
22
#include <netedit/GNENet.h>
23
#include <netedit/GNEViewParent.h>
24
#include <netedit/dialogs/basic/GNEWarningBasicDialog.h>
25
#include <netedit/elements/additional/GNEAdditionalHandler.h>
26
#include <netedit/frames/GNEAttributesEditor.h>
27
#include <netedit/frames/GNEConsecutiveSelector.h>
28
#include <netedit/frames/GNESelectorParent.h>
29
#include <netedit/frames/GNETagSelector.h>
30
31
#include "GNEWireFrame.h"
32
33
// ===========================================================================
34
// method definitions
35
// ===========================================================================
36
37
GNEWireFrame::GNEWireFrame(GNEViewParent* viewParent, GNEViewNet* viewNet) :
38
GNEFrame(viewParent, viewNet, TL("Wires")) {
39
40
// create item Selector module for wires
41
myWireTagSelector = new GNETagSelector(this, GNETagProperties::Type::WIRE, SUMO_TAG_TRACTION_SUBSTATION);
42
43
// Create wire parameters
44
myWireAttributesEditor = new GNEAttributesEditor(this, GNEAttributesEditorType::EditorType::CREATOR);
45
46
// Create selector parent
47
mySelectorWireParent = new GNESelectorParent(this);
48
49
// Create list for E2Multilane lane selector
50
myConsecutiveLaneSelector = new GNEConsecutiveSelector(this, true);
51
}
52
53
54
GNEWireFrame::~GNEWireFrame() {
55
// check if we have to delete base wire object
56
if (myBaseWire) {
57
delete myBaseWire;
58
}
59
}
60
61
62
void
63
GNEWireFrame::show() {
64
// refresh tag selector
65
myWireTagSelector->refreshTagSelector();
66
// show frame
67
GNEFrame::show();
68
if (!myWarnedExperimental) {
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."));
72
myWarnedExperimental = true;
73
}
74
}
75
76
77
bool
78
GNEWireFrame::addWire(const GNEViewNetHelper::ViewObjectsSelector& viewObjects) {
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
105
GNEConsecutiveSelector*
106
GNEWireFrame::getConsecutiveLaneSelector() const {
107
return myConsecutiveLaneSelector;
108
}
109
110
111
bool
112
GNEWireFrame::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
153
void
154
GNEWireFrame::tagSelected() {
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
178
bool
179
GNEWireFrame::createBaseWireObject(const GNETagProperties* tagProperty) {
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
192
myBaseWire = new CommonXMLStructure::SumoBaseObject(nullptr);
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
218
bool
219
GNEWireFrame::buildWireOverView(const GNETagProperties* tagProperty) {
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
/****************************************************************************/
265
266