Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/frames/data/GNETAZRelDataFrame.cpp
169684 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-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 GNETAZRelDataFrame.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date May 2020
17
///
18
// The Widget for add TAZRelationData elements
19
/****************************************************************************/
20
21
#include <netedit/GNEApplicationWindow.h>
22
#include <netedit/GNEViewNet.h>
23
#include <netedit/GNEViewParent.h>
24
#include <netedit/elements/additional/GNETAZ.h>
25
#include <netedit/elements/data/GNEDataHandler.h>
26
#include <netedit/elements/data/GNEDataInterval.h>
27
#include <netedit/frames/GNEAttributesEditor.h>
28
#include <utils/gui/div/GUIDesigns.h>
29
30
#include "GNETAZRelDataFrame.h"
31
32
// ===========================================================================
33
// FOX callback mapping
34
// ===========================================================================
35
36
FXDEFMAP(GNETAZRelDataFrame::ConfirmTAZRelation) ConfirmTAZRelationMap[] = {
37
FXMAPFUNC(SEL_COMMAND, MID_GNE_CREATE, GNETAZRelDataFrame::ConfirmTAZRelation::onCmdConfirmTAZRelation),
38
FXMAPFUNC(SEL_UPDATE, MID_GNE_CREATE, GNETAZRelDataFrame::ConfirmTAZRelation::onUpdConfirmTAZRelation),
39
FXMAPFUNC(SEL_COMMAND, MID_GNE_ABORT, GNETAZRelDataFrame::ConfirmTAZRelation::onCmdClearSelection)
40
};
41
42
// Object implementation
43
FXIMPLEMENT(GNETAZRelDataFrame::ConfirmTAZRelation, MFXGroupBoxModule, ConfirmTAZRelationMap, ARRAYNUMBER(ConfirmTAZRelationMap))
44
45
// ===========================================================================
46
// method definitions
47
// ===========================================================================
48
49
// ---------------------------------------------------------------------------
50
// GNETAZRelDataFrame::ConfirmTAZRelation - methods
51
// ---------------------------------------------------------------------------
52
53
GNETAZRelDataFrame::ConfirmTAZRelation::ConfirmTAZRelation(GNETAZRelDataFrame* TAZRelDataFrame) :
54
MFXGroupBoxModule(TAZRelDataFrame, TL("Confirm TAZRelation")),
55
myTAZRelDataFrame(TAZRelDataFrame) {
56
myConfirmTAZButton = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Create TAZRelation"), "", TL("Click fromTaz and toTaz (confirm hotkey <ENTER>)"), GUIIconSubSys::getIcon(GUIIcon::TAZRELDATA), this, MID_GNE_CREATE, GUIDesignButton);
57
myConfirmTAZButton->disable();
58
myClearTAZButton = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Clear selection"), "", TL("Clear selected TAZs (hotkey <ESC>)"), GUIIconSubSys::getIcon(GUIIcon::CLEARMESSAGEWINDOW), this, MID_GNE_ABORT, GUIDesignButton);
59
myClearTAZButton->disable();
60
}
61
62
63
GNETAZRelDataFrame::ConfirmTAZRelation::~ConfirmTAZRelation() {}
64
65
66
long
67
GNETAZRelDataFrame::ConfirmTAZRelation::onCmdConfirmTAZRelation(FXObject*, FXSelector, void*) {
68
myTAZRelDataFrame->buildTAZRelationData();
69
return 1;
70
}
71
72
73
long
74
GNETAZRelDataFrame::ConfirmTAZRelation::onUpdConfirmTAZRelation(FXObject*, FXSelector, void*) {
75
if (myTAZRelDataFrame->myFirstTAZ && myTAZRelDataFrame->mySecondTAZ) {
76
myConfirmTAZButton->enable();
77
} else {
78
myConfirmTAZButton->disable();
79
}
80
if (myTAZRelDataFrame->myFirstTAZ || myTAZRelDataFrame->mySecondTAZ) {
81
myClearTAZButton->enable();
82
} else {
83
myClearTAZButton->disable();
84
}
85
return 1;
86
}
87
88
89
long
90
GNETAZRelDataFrame::ConfirmTAZRelation::onCmdClearSelection(FXObject*, FXSelector, void*) {
91
myTAZRelDataFrame->clearTAZSelection();
92
myTAZRelDataFrame->getViewNet()->update();
93
return 1;
94
}
95
96
// ---------------------------------------------------------------------------
97
// GNETAZRelDataFrame::TAZRelLegend - methods
98
// ---------------------------------------------------------------------------
99
100
GNETAZRelDataFrame::Legend::Legend(GNETAZRelDataFrame* TAZRelDataFrame) :
101
MFXGroupBoxModule(TAZRelDataFrame, TL("Information")),
102
myFromTAZLabel(nullptr),
103
myToTAZLabel(nullptr) {
104
// create from TAZ label
105
myFromTAZLabel = new FXLabel(getCollapsableFrame(), "From TAZ", 0, GUIDesignLabel(JUSTIFY_LEFT));
106
myFromTAZLabel->setBackColor(MFXUtils::getFXColor(RGBColor::GREEN));
107
// create to TAZ Label
108
myToTAZLabel = new FXLabel(getCollapsableFrame(), "To TAZ", 0, GUIDesignLabel(JUSTIFY_LEFT));
109
myToTAZLabel->setBackColor(MFXUtils::getFXColor(RGBColor::MAGENTA));
110
}
111
112
113
GNETAZRelDataFrame::Legend::~Legend() {}
114
115
116
void
117
GNETAZRelDataFrame::Legend::setLabels(const GNETAZ* fromTAZ, const GNETAZ* toTAZ) {
118
// from TAZ
119
if (fromTAZ) {
120
myFromTAZLabel->setText(("From TAZ: " + fromTAZ->getID()).c_str());
121
} else {
122
myFromTAZLabel->setText(TL("From TAZ"));
123
}
124
// to TAZ
125
if (toTAZ) {
126
myToTAZLabel->setText(("To TAZ: " + toTAZ->getID()).c_str());
127
} else {
128
myToTAZLabel->setText(TL("To TAZ"));
129
}
130
}
131
132
// ---------------------------------------------------------------------------
133
// GNETAZRelDataFrame - methods
134
// ------------------------------------------------------------------------
135
136
GNETAZRelDataFrame::GNETAZRelDataFrame(GNEViewParent* viewParent, GNEViewNet* viewNet) :
137
GNEGenericDataFrame(viewParent, viewNet, SUMO_TAG_TAZREL, false) {
138
// create confirm TAZ Relation
139
myConfirmTAZRelation = new ConfirmTAZRelation(this);
140
// create legend
141
myLegend = new Legend(this);
142
}
143
144
145
GNETAZRelDataFrame::~GNETAZRelDataFrame() {}
146
147
148
bool
149
GNETAZRelDataFrame::setTAZ(const GNEViewNetHelper::ViewObjectsSelector& viewObjects) {
150
// check if myFirstTAZElement is empty
151
if (myFirstTAZ) {
152
if (mySecondTAZ) {
153
// both already defined
154
return false;
155
} else if (viewObjects.getTAZFront()) {
156
mySecondTAZ = viewObjects.getTAZFront();
157
myLegend->setLabels(myFirstTAZ, mySecondTAZ);
158
return true;
159
} else {
160
return false;
161
}
162
} else if (viewObjects.getTAZFront()) {
163
myFirstTAZ = viewObjects.getTAZFront();
164
myLegend->setLabels(myFirstTAZ, mySecondTAZ);
165
return true;
166
} else {
167
return false;
168
}
169
}
170
171
172
void
173
GNETAZRelDataFrame::buildTAZRelationData() {
174
// check conditions
175
if (myFirstTAZ && mySecondTAZ) {
176
if (!myIntervalSelector->getDataInterval()) {
177
WRITE_WARNINGF(TL("A % must be defined within an interval."), toString(SUMO_TAG_TAZREL));
178
} else if ((myFirstTAZ == mySecondTAZ) && myIntervalSelector->getDataInterval()->TAZRelExists(myFirstTAZ)) {
179
WRITE_WARNINGF(TL("There is already a % defined in TAZ'%'."), toString(SUMO_TAG_TAZREL), myFirstTAZ->getID());
180
} else if ((myFirstTAZ != mySecondTAZ) && myIntervalSelector->getDataInterval()->TAZRelExists(myFirstTAZ, mySecondTAZ)) {
181
WRITE_WARNINGF(TL("There is already a % defined between TAZ'%' and '%'."), toString(SUMO_TAG_TAZREL), myFirstTAZ->getID(), mySecondTAZ->getID());
182
} else if (myGenericDataAttributesEditor->checkAttributes(true)) {
183
// declare data handler
184
GNEDataHandler dataHandler(myViewNet->getNet(), "", myViewNet->getViewParent()->getGNEAppWindows()->isUndoRedoAllowed());
185
// build data interval object and fill it
186
CommonXMLStructure::SumoBaseObject* dataIntervalObject = new CommonXMLStructure::SumoBaseObject(nullptr);
187
dataIntervalObject->addStringAttribute(SUMO_ATTR_ID, myIntervalSelector->getDataInterval()->getID());
188
dataIntervalObject->addDoubleAttribute(SUMO_ATTR_BEGIN, myIntervalSelector->getDataInterval()->getAttributeDouble(SUMO_ATTR_BEGIN));
189
dataIntervalObject->addDoubleAttribute(SUMO_ATTR_END, myIntervalSelector->getDataInterval()->getAttributeDouble(SUMO_ATTR_END));
190
// create TAZRelData
191
CommonXMLStructure::SumoBaseObject* TAZRelData = new CommonXMLStructure::SumoBaseObject(dataIntervalObject);
192
// obtain parameters
193
myGenericDataAttributesEditor->fillSumoBaseObject(TAZRelData);
194
// create TAZRelationData
195
dataHandler.buildTAZRelationData(TAZRelData, myFirstTAZ->getID(), mySecondTAZ->getID(), TAZRelData->getParameters());
196
// delete data interval object (and child)
197
delete dataIntervalObject;
198
// reset both TAZs
199
myFirstTAZ = nullptr;
200
mySecondTAZ = nullptr;
201
myLegend->setLabels(myFirstTAZ, mySecondTAZ);
202
}
203
}
204
}
205
206
207
GNEAdditional*
208
GNETAZRelDataFrame::getFirstTAZ() const {
209
return myFirstTAZ;
210
}
211
212
213
GNEAdditional*
214
GNETAZRelDataFrame::getSecondTAZ() const {
215
return mySecondTAZ;
216
}
217
218
219
void
220
GNETAZRelDataFrame::clearTAZSelection() {
221
myFirstTAZ = nullptr;
222
mySecondTAZ = nullptr;
223
myLegend->setLabels(myFirstTAZ, mySecondTAZ);
224
}
225
226
/****************************************************************************/
227
228