Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/elements/data/GNEGenericData.cpp
193700 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2026 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 GNEGenericData.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Jan 2020
17
///
18
// A abstract class for generic datas
19
/****************************************************************************/
20
21
#include <netedit/GNENet.h>
22
#include <netedit/GNETagPropertiesDatabase.h>
23
#include <netedit/GNEViewParent.h>
24
#include <netedit/frames/common/GNESelectorFrame.h>
25
#include <netedit/frames/data/GNEEdgeDataFrame.h>
26
#include <utils/gui/div/GLHelper.h>
27
#include <utils/gui/div/GUIDesigns.h>
28
#include <utils/gui/div/GUIParameterTableWindow.h>
29
#include <utils/gui/globjects/GUIGLObjectPopupMenu.h>
30
31
#include "GNEDataInterval.h"
32
#include "GNEGenericData.h"
33
34
// ===========================================================================
35
// member method definitions
36
// ===========================================================================
37
38
GNEGenericData::GNEGenericData(SumoXMLTag tag, GNENet* net) :
39
GNEAttributeCarrier(tag, net),
40
GUIGlObject(net->getTagPropertiesDatabase()->getTagProperty(tag, true)->getGLType(), "",
41
GUIIconSubSys::getIcon(net->getTagPropertiesDatabase()->getTagProperty(tag, true)->getGUIIcon())),
42
GNEPathElement(GNEPathElement::Options::DATA_ELEMENT),
43
myDataIntervalParent(nullptr) {
44
}
45
46
47
GNEGenericData::GNEGenericData(const SumoXMLTag tag, GNEDataInterval* dataIntervalParent, const Parameterised::Map& parameters) :
48
GNEAttributeCarrier(tag, dataIntervalParent->getNet(), dataIntervalParent->getFileBucket()),
49
GUIGlObject(dataIntervalParent->getNet()->getTagPropertiesDatabase()->getTagProperty(tag, true)->getGLType(), dataIntervalParent->getID(),
50
GUIIconSubSys::getIcon(dataIntervalParent->getNet()->getTagPropertiesDatabase()->getTagProperty(tag, true)->getGUIIcon())),
51
GNEPathElement(GNEPathElement::Options::DATA_ELEMENT),
52
Parameterised(parameters),
53
myDataIntervalParent(dataIntervalParent) {
54
}
55
56
57
GNEGenericData::~GNEGenericData() {}
58
59
60
GNEHierarchicalElement*
61
GNEGenericData::getHierarchicalElement() {
62
return this;
63
}
64
65
66
GNEMoveElement*
67
GNEGenericData::getMoveElement() const {
68
return nullptr;
69
}
70
71
72
Parameterised*
73
GNEGenericData::getParameters() {
74
return this;
75
}
76
77
78
const Parameterised*
79
GNEGenericData::getParameters() const {
80
return this;
81
}
82
83
84
GUIGlObject*
85
GNEGenericData::getGUIGlObject() {
86
return this;
87
}
88
89
90
const GUIGlObject*
91
GNEGenericData::getGUIGlObject() const {
92
return this;
93
}
94
95
96
FileBucket*
97
GNEGenericData::getFileBucket() const {
98
if (isTemplate()) {
99
return nullptr;
100
} else {
101
return myDataIntervalParent->getFileBucket();
102
}
103
}
104
105
106
GNEDataInterval*
107
GNEGenericData::getDataIntervalParent() const {
108
return myDataIntervalParent;
109
}
110
111
112
void
113
GNEGenericData::drawAttribute(const PositionVector& shape) const {
114
if ((myTagProperty->getTag() == GNE_TAG_EDGEREL_SINGLE) && (shape.length() > 0)) {
115
// obtain pointer to edge data frame (only for code legibly)
116
const GNEEdgeDataFrame* edgeDataFrame = myDataIntervalParent->getNet()->getViewParent()->getEdgeDataFrame();
117
// check if we have to filter generic data
118
if (edgeDataFrame->shown()) {
119
// check attribute
120
if ((edgeDataFrame->getAttributeSelector()->getFilteredAttribute().size() > 0) &&
121
(getParametersMap().count(edgeDataFrame->getAttributeSelector()->getFilteredAttribute()) > 0)) {
122
// get value
123
const std::string value = getParametersMap().at(edgeDataFrame->getAttributeSelector()->getFilteredAttribute());
124
// calculate center position
125
const Position centerPosition = shape.positionAtOffset2D(shape.length2D() / 2);
126
// Add a draw matrix
127
GLHelper::pushMatrix();
128
GLHelper::drawText(value, centerPosition, GLO_MAX, 2, RGBColor::BLUE);
129
// pop draw matrix
130
GLHelper::popMatrix();
131
}
132
}
133
}
134
}
135
136
137
bool
138
GNEGenericData::checkDrawFromContour() const {
139
return false;
140
}
141
142
143
bool
144
GNEGenericData::checkDrawToContour() const {
145
return false;
146
}
147
148
149
bool
150
GNEGenericData::checkDrawRelatedContour() const {
151
// check opened popup
152
if (myNet->getViewNet()->getPopup()) {
153
return myNet->getViewNet()->getPopup()->getGLObject() == this;
154
}
155
return false;
156
}
157
158
159
bool
160
GNEGenericData::checkDrawOverContour() const {
161
return false;
162
}
163
164
165
bool
166
GNEGenericData::checkDrawDeleteContour() const {
167
// get edit modes
168
const auto& editModes = myNet->getViewNet()->getEditModes();
169
// check if we're in delete mode
170
if (editModes.isCurrentSupermodeData() && (editModes.dataEditMode == DataEditMode::DATA_DELETE)) {
171
return myNet->getViewNet()->checkOverLockedElement(this, mySelected);
172
} else {
173
return false;
174
}
175
}
176
177
178
bool
179
GNEGenericData::checkDrawDeleteContourSmall() const {
180
return false;
181
}
182
183
184
bool
185
GNEGenericData::checkDrawSelectContour() const {
186
// get edit modes
187
const auto& editModes = myNet->getViewNet()->getEditModes();
188
// check if we're in select mode
189
if (editModes.isCurrentSupermodeData() && (editModes.dataEditMode == DataEditMode::DATA_SELECT)) {
190
return myNet->getViewNet()->checkOverLockedElement(this, mySelected);
191
} else {
192
return false;
193
}
194
}
195
196
197
bool
198
GNEGenericData::checkDrawMoveContour() const {
199
return false;
200
}
201
202
203
bool
204
GNEGenericData::isGenericDataValid() const {
205
return true;
206
}
207
208
209
std::string
210
GNEGenericData::getGenericDataProblem() const {
211
return "";
212
}
213
214
215
void
216
GNEGenericData::fixGenericDataProblem() {
217
throw InvalidArgument(getTagStr() + " cannot fix any problem");
218
}
219
220
221
GUIGLObjectPopupMenu*
222
GNEGenericData::getPopUpMenu(GUIMainWindow& app, GUISUMOAbstractView& parent) {
223
// create popup
224
GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, this);
225
// build common options
226
buildPopUpMenuCommonOptions(ret, app, myNet->getViewNet(), myTagProperty->getTag(), mySelected);
227
// show option to open additional dialog
228
if (myTagProperty->hasDialog()) {
229
GUIDesigns::buildFXMenuCommand(ret, (TLF("Open % Dialog", getTagStr())).c_str(), getACIcon(), &parent, MID_OPEN_ADDITIONAL_DIALOG);
230
new FXMenuSeparator(ret);
231
} else {
232
GUIDesigns::buildFXMenuCommand(ret, (TL("Cursor position in view: ") + toString(getPositionInView().x()) + "," + toString(getPositionInView().y())).c_str(), nullptr, nullptr, 0);
233
}
234
return ret;
235
}
236
237
238
GUIParameterTableWindow*
239
GNEGenericData::getParameterWindow(GUIMainWindow& app, GUISUMOAbstractView& /* parent */) {
240
// Create table
241
GUIParameterTableWindow* ret = new GUIParameterTableWindow(app, *this);
242
// Iterate over attributes
243
for (const auto& tagProperty : myTagProperty->getAttributeProperties()) {
244
// Add attribute and set it dynamic if aren't unique
245
if (tagProperty->isUnique()) {
246
ret->mkItem(tagProperty->getAttrStr().c_str(), false, getAttribute(tagProperty->getAttr()));
247
} else {
248
ret->mkItem(tagProperty->getAttrStr().c_str(), true, getAttribute(tagProperty->getAttr()));
249
}
250
}
251
// close building
252
ret->closeBuilding();
253
return ret;
254
}
255
256
257
void
258
GNEGenericData::deleteGLObject() {
259
myNet->deleteGenericData(this, myNet->getUndoList());
260
}
261
262
263
void
264
GNEGenericData::selectGLObject() {
265
if (isAttributeCarrierSelected()) {
266
unselectAttributeCarrier();
267
} else {
268
selectAttributeCarrier();
269
}
270
// update information label
271
myNet->getViewParent()->getSelectorFrame()->getSelectionInformation()->updateInformationLabel();
272
}
273
274
275
void
276
GNEGenericData::updateGLObject() {
277
updateGeometry();
278
}
279
280
281
Position
282
GNEGenericData::getAttributePosition(SumoXMLAttr key) const {
283
return getCommonAttributePosition(key);
284
}
285
286
287
PositionVector
288
GNEGenericData::getAttributePositionVector(SumoXMLAttr key) const {
289
return getCommonAttributePositionVector(key);
290
}
291
292
293
bool
294
GNEGenericData::isPathElementSelected() const {
295
return mySelected;
296
}
297
298
// ---------------------------------------------------------------------------
299
// GNEGenericData - protected methods
300
// ---------------------------------------------------------------------------
301
302
void
303
GNEGenericData::drawFilteredAttribute(const GUIVisualizationSettings& s, const PositionVector& laneShape, const std::string& attribute, const GNEDataInterval* dataIntervalParent) const {
304
if ((myDataIntervalParent == dataIntervalParent) && (getParametersMap().count(attribute) > 0)) {
305
const Position pos = laneShape.positionAtOffset2D(laneShape.length2D() * 0.5);
306
const double rot = laneShape.rotationDegreeAtOffset(laneShape.length2D() * 0.5);
307
// Add a draw matrix for details
308
GLHelper::pushMatrix();
309
// draw value
310
GLHelper::drawText(getParameter(attribute), pos, GLO_MAX - 1, 2, RGBColor::BLACK, s.getTextAngle(rot + 90));
311
// pop draw matrix
312
GLHelper::popMatrix();
313
}
314
}
315
316
317
bool
318
GNEGenericData::isVisibleInspectDeleteSelect() const {
319
// get toolbar
320
const GNEViewNetHelper::IntervalBar& toolBar = myNet->getViewNet()->getIntervalBar();
321
// declare flag
322
bool draw = true;
323
// check filter by generic data type
324
if ((toolBar.getGenericDataType() != SUMO_TAG_NOTHING) && (toolBar.getGenericDataType() != myTagProperty->getTag())) {
325
draw = false;
326
}
327
// check filter by data set
328
if (toolBar.getDataSet() && (toolBar.getDataSet() != myDataIntervalParent->getDataSetParent())) {
329
draw = false;
330
}
331
// check filter by begin
332
if ((toolBar.getBegin() != INVALID_DOUBLE) && (toolBar.getBegin() > myDataIntervalParent->getAttributeDouble(SUMO_ATTR_BEGIN))) {
333
draw = false;
334
}
335
// check filter by end
336
if ((toolBar.getEnd() != INVALID_DOUBLE) && (toolBar.getEnd() < myDataIntervalParent->getAttributeDouble(SUMO_ATTR_END))) {
337
draw = false;
338
}
339
// check filter by attribute
340
if ((toolBar.getParameter().size() > 0) && (getParametersMap().count(toolBar.getParameter()) == 0)) {
341
draw = false;
342
}
343
// return flag
344
return draw;
345
}
346
347
void
348
GNEGenericData::replaceFirstParentEdge(const std::string& value) {
349
auto newEdge = myNet->getAttributeCarriers()->retrieveEdge(value);
350
GNEHierarchicalElement::updateParent(this, 0, newEdge);
351
}
352
353
354
void
355
GNEGenericData::replaceLastParentEdge(const std::string& value) {
356
auto newEdge = myNet->getAttributeCarriers()->retrieveEdge(value);
357
GNEHierarchicalElement::updateParent(this, (int)getParentEdges().size() - 1, newEdge);
358
}
359
360
361
void
362
GNEGenericData::replaceParentTAZElement(const int index, const std::string& value) {
363
std::vector<GNEAdditional*> newTAZs = getParentAdditionals();
364
auto TAZ = myNet->getAttributeCarriers()->retrieveAdditional(SUMO_TAG_TAZ, value);
365
// continue depending of index and number of TAZs
366
if (index == 0) {
367
if (newTAZs.size() == 2) {
368
if (newTAZs.at(1)->getID() == value) {
369
newTAZs = {TAZ};
370
} else {
371
newTAZs[0] = TAZ;
372
}
373
} else if (newTAZs.at(0) != TAZ) {
374
newTAZs = {TAZ, newTAZs.at(0)};
375
}
376
} else if (index == 1) {
377
if (newTAZs.size() == 2) {
378
if (newTAZs.at(0)->getID() == value) {
379
newTAZs = {TAZ};
380
} else {
381
newTAZs[1] = TAZ;
382
}
383
} else if (newTAZs.at(0) != TAZ) {
384
newTAZs = {newTAZs.at(0), TAZ};
385
}
386
} else {
387
throw ProcessError(TL("Invalid index"));
388
}
389
GNEHierarchicalElement::updateParents(this, newTAZs);
390
}
391
392
393
std::string
394
GNEGenericData::getPartialID() const {
395
return getDataIntervalParent()->getDataSetParent()->getID() + "[" +
396
getDataIntervalParent()->getAttribute(SUMO_ATTR_BEGIN) + "," +
397
getDataIntervalParent()->getAttribute(SUMO_ATTR_END) + "]:";
398
}
399
400
/****************************************************************************/
401
402