Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/frames/demand/GNEDistributionFrame.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 GNEDistributionFrame.cpp
15
/// @author Pablo Alvarez Lopez
16
/// @date Jun 2023
17
///
18
// The Widget for edit distribution elements
19
/****************************************************************************/
20
21
#include <netedit/GNEApplicationWindow.h>
22
#include <netedit/GNENet.h>
23
#include <netedit/GNETagProperties.h>
24
#include <netedit/GNEUndoList.h>
25
#include <netedit/GNEViewParent.h>
26
#include <netedit/changes/GNEChange_DemandElement.h>
27
#include <netedit/elements/demand/GNERouteDistribution.h>
28
#include <netedit/elements/demand/GNEVTypeDistribution.h>
29
#include <netedit/frames/GNEAttributesEditor.h>
30
#include <utils/foxtools/MFXTextFieldIcon.h>
31
#include <utils/gui/div/GUIDesigns.h>
32
33
#include "GNEDistributionFrame.h"
34
35
#define TEMPORAL_FILENAME std::string()
36
37
// ===========================================================================
38
// FOX callback mapping
39
// ===========================================================================
40
41
FXDEFMAP(GNEDistributionFrame::DistributionEditor) DistributionEditorMap[] = {
42
FXMAPFUNC(SEL_COMMAND, MID_GNE_CREATE, GNEDistributionFrame::DistributionEditor::onCmdCreateDistribution),
43
FXMAPFUNC(SEL_COMMAND, MID_GNE_DELETE, GNEDistributionFrame::DistributionEditor::onCmdDeleteDistribution),
44
FXMAPFUNC(SEL_UPDATE, MID_GNE_DELETE, GNEDistributionFrame::DistributionEditor::onUpdDeleteDistribution),
45
};
46
47
FXDEFMAP(GNEDistributionFrame::DistributionSelector) DistributionSelectorMap[] = {
48
FXMAPFUNC(SEL_COMMAND, MID_GNE_SET_TYPE, GNEDistributionFrame::DistributionSelector::onCmdSelectDistribution),
49
FXMAPFUNC(SEL_UPDATE, MID_GNE_SET_TYPE, GNEDistributionFrame::DistributionSelector::onCmdUpdateDistribution)
50
};
51
52
53
FXDEFMAP(GNEDistributionFrame::DistributionRow) DistributionRowMap[] = {
54
FXMAPFUNC(SEL_COMMAND, MID_GNE_SET_TYPE, GNEDistributionFrame::DistributionRow::onCmdSetKey),
55
FXMAPFUNC(SEL_COMMAND, MID_GNE_SET_ATTRIBUTE, GNEDistributionFrame::DistributionRow::onCmdSetProbability),
56
FXMAPFUNC(SEL_COMMAND, MID_GNE_BUTTON_REMOVE, GNEDistributionFrame::DistributionRow::onCmdRemoveRow)
57
};
58
59
FXDEFMAP(GNEDistributionFrame::DistributionValuesEditor) DistributionValuesEditorMap[] = {
60
FXMAPFUNC(SEL_COMMAND, MID_GNE_BUTTON_ADD, GNEDistributionFrame::DistributionValuesEditor::onCmdAddRow),
61
FXMAPFUNC(SEL_UPDATE, MID_GNE_BUTTON_ADD, GNEDistributionFrame::DistributionValuesEditor::onUpdAddRow)
62
};
63
64
// Object implementation
65
FXIMPLEMENT(GNEDistributionFrame::DistributionEditor, MFXGroupBoxModule, DistributionEditorMap, ARRAYNUMBER(DistributionEditorMap))
66
FXIMPLEMENT(GNEDistributionFrame::DistributionSelector, MFXGroupBoxModule, DistributionSelectorMap, ARRAYNUMBER(DistributionSelectorMap))
67
FXIMPLEMENT(GNEDistributionFrame::DistributionRow, FXHorizontalFrame, DistributionRowMap, ARRAYNUMBER(DistributionRowMap))
68
FXIMPLEMENT(GNEDistributionFrame::DistributionValuesEditor, MFXGroupBoxModule, DistributionValuesEditorMap, ARRAYNUMBER(DistributionValuesEditorMap))
69
70
71
// ===========================================================================
72
// method definitions
73
// ===========================================================================
74
75
// ---------------------------------------------------------------------------
76
// GNEDistributionFrame::DistributionEditor - methods
77
// ---------------------------------------------------------------------------
78
79
GNEDistributionFrame::DistributionEditor::DistributionEditor(GNEFrame* frameParent, SumoXMLTag distributionTag, GUIIcon icon) :
80
MFXGroupBoxModule(frameParent, TL("Distribution Editor")),
81
myFrameParent(frameParent),
82
myDistributionTag(distributionTag) {
83
// get staticTooltip menu
84
auto staticTooltipMenu = myFrameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu();
85
// Create new distribution
86
myCreateDistributionButton = new MFXButtonTooltip(getCollapsableFrame(), staticTooltipMenu, TL("New"),
87
GUIIconSubSys::getIcon(icon), this, MID_GNE_CREATE, GUIDesignButton);
88
myCreateDistributionButton->setTipText(TLF("Create new %", toString(myDistributionTag)).c_str()),
89
// Delete distribution
90
myDeleteDistributionButton = new MFXButtonTooltip(getCollapsableFrame(), staticTooltipMenu, TL("Delete"),
91
GUIIconSubSys::getIcon(GUIIcon::MODEDELETE), this, MID_GNE_DELETE, GUIDesignButton);
92
myDeleteDistributionButton->setTipText(TLF("Delete current edited %", toString(myDistributionTag)).c_str()),
93
// show editor
94
show();
95
}
96
97
98
GNEDistributionFrame::DistributionEditor::~DistributionEditor() {}
99
100
101
SumoXMLTag
102
GNEDistributionFrame::DistributionEditor::getDistributionTag() const {
103
return myDistributionTag;
104
}
105
106
107
long
108
GNEDistributionFrame::DistributionEditor::onCmdCreateDistribution(FXObject*, FXSelector, void*) {
109
auto undoList = myFrameParent->getViewNet()->getUndoList();
110
// obtain a new valid ID
111
const auto distributionID = myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->generateDemandElementID(myDistributionTag);
112
// create new distribution
113
GNEDemandElement* distribution = nullptr;
114
if (myDistributionTag == SUMO_TAG_VTYPE_DISTRIBUTION) {
115
distribution = new GNEVTypeDistribution(distributionID, myFrameParent->getViewNet()->getNet(), TEMPORAL_FILENAME, -1);
116
} else if (myDistributionTag == SUMO_TAG_ROUTE_DISTRIBUTION) {
117
distribution = new GNERouteDistribution(distributionID, myFrameParent->getViewNet()->getNet(), TEMPORAL_FILENAME);
118
} else {
119
throw ProcessError("Invalid distribution");
120
}
121
// add it using undoList (to allow undo-redo)
122
undoList->begin(distribution->getTagProperty()->getGUIIcon(), "create distribution");
123
undoList->add(new GNEChange_DemandElement(distribution, true), true);
124
undoList->end();
125
// refresh selector using created distribution
126
myDistributionSelector->setDistribution(distribution);
127
return 1;
128
}
129
130
131
long
132
GNEDistributionFrame::DistributionEditor::onCmdDeleteDistribution(FXObject*, FXSelector, void*) {
133
auto undoList = myFrameParent->getViewNet()->getUndoList();
134
auto currentDistribution = myDistributionSelector->getCurrentDistribution();
135
if (currentDistribution) {
136
// begin undo list operation
137
undoList->begin(currentDistribution->getTagProperty()->getGUIIcon(), "delete " + currentDistribution->getTagProperty()->getTagStr() + " distribution");
138
// remove distribution
139
myFrameParent->getViewNet()->getNet()->deleteDemandElement(myDistributionSelector->getCurrentDistribution(), undoList);
140
// end undo list operation
141
undoList->end();
142
// refresh selector
143
myDistributionSelector->refreshDistributionSelector();
144
}
145
return 1;
146
}
147
148
149
long
150
GNEDistributionFrame::DistributionEditor::onUpdDeleteDistribution(FXObject* sender, FXSelector, void*) {
151
// check if we have a selected distribution
152
if (myDistributionSelector->getCurrentDistribution()) {
153
return sender->handle(this, FXSEL(SEL_COMMAND, ID_ENABLE), nullptr);
154
} else {
155
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
156
}
157
}
158
159
// ---------------------------------------------------------------------------
160
// GNETypeFrame::DistributionSelector - methods
161
// ---------------------------------------------------------------------------
162
163
GNEDistributionFrame::DistributionSelector::DistributionSelector(GNEFrame* frameParent) :
164
MFXGroupBoxModule(frameParent, TL("Distribution selector")),
165
myFrameParent(frameParent) {
166
// Create MFXComboBoxIcon
167
myDistributionsComboBox = new MFXComboBoxIcon(getCollapsableFrame(), frameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),
168
true, GUIDesignComboBoxVisibleItems, this, MID_GNE_SET_TYPE, GUIDesignComboBox);
169
// DistributionSelector is always shown
170
show();
171
}
172
173
174
GNEDistributionFrame::DistributionSelector::~DistributionSelector() {}
175
176
177
void
178
GNEDistributionFrame::DistributionSelector::setDistribution(GNEDemandElement* distribution) {
179
myCurrentDistribution = distribution;
180
refreshDistributionSelector();
181
}
182
183
184
GNEDemandElement*
185
GNEDistributionFrame::DistributionSelector::getCurrentDistribution() const {
186
return myCurrentDistribution;
187
188
}
189
190
191
void
192
GNEDistributionFrame::DistributionSelector::refreshDistributionIDs() {
193
// fill distributions
194
fillDistributionComboBox();
195
// set current item
196
for (int i = 0; i < (int)myDistributionsComboBox->getNumItems(); i++) {
197
if (myDistributionsComboBox->getItemText(i) == myCurrentDistribution->getID()) {
198
myDistributionsComboBox->setCurrentItem(i);
199
}
200
}
201
}
202
203
204
void
205
GNEDistributionFrame::DistributionSelector::refreshDistributionSelector() {
206
// fill distributions
207
const auto distributions = fillDistributionComboBox();
208
// update current distribution (used if myCurrentDistribution was deleted during undo-redo)
209
myCurrentDistribution = myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->retrieveDemandElement(myCurrentDistribution, false);
210
// update comboBox
211
if (myCurrentDistribution) {
212
for (int i = 0; i < (int)myDistributionsComboBox->getNumItems(); i++) {
213
if (myDistributionsComboBox->getItemText(i) == myCurrentDistribution->getID()) {
214
myDistributionsComboBox->setCurrentItem(i);
215
}
216
}
217
} else if (distributions.size() > 0) {
218
// set first distribution
219
myCurrentDistribution = distributions.begin()->second;
220
}
221
// continue depending of myCurrentDistribution
222
if (myCurrentDistribution) {
223
// show modules
224
myAttributesEditor->showAttributesEditor(myCurrentDistribution, true);
225
myDistributionValuesEditor->showDistributionValuesEditor();
226
} else {
227
// hide modules
228
myAttributesEditor->hideAttributesEditor();
229
myDistributionValuesEditor->hideDistributionValuesEditor();
230
}
231
}
232
233
234
long
235
GNEDistributionFrame::DistributionSelector::onCmdSelectDistribution(FXObject*, FXSelector, void*) {
236
const auto viewNet = myFrameParent->getViewNet();
237
const auto& distributions = viewNet->getNet()->getAttributeCarriers()->getDemandElements().at(myDistributionEditor->getDistributionTag());
238
// Check if value of myTypeMatchBox correspond of an allowed additional tags
239
for (const auto& distribution : distributions) {
240
if (distribution.second->getID() == myDistributionsComboBox->getText().text()) {
241
// set pointer
242
myCurrentDistribution = distribution.second;
243
// set color of myTypeMatchBox to black (valid)
244
myDistributionsComboBox->setTextColor(GUIDesignTextColorBlack);
245
// show modules
246
myAttributesEditor->showAttributesEditor(distribution.second, true);
247
myDistributionValuesEditor->showDistributionValuesEditor();
248
// update viewNet
249
viewNet->updateViewNet();
250
return 1;
251
}
252
}
253
// not found, then reset myCurrentDistribution
254
myCurrentDistribution = nullptr;
255
// hide modules
256
myAttributesEditor->hideAttributesEditor();
257
myDistributionValuesEditor->hideDistributionValuesEditor();
258
// set color of myTypeMatchBox to red (invalid)
259
myDistributionsComboBox->setTextColor(GUIDesignTextColorRed);
260
// update viewNet
261
viewNet->updateViewNet();
262
return 1;
263
}
264
265
266
long
267
GNEDistributionFrame::DistributionSelector::onCmdUpdateDistribution(FXObject* sender, FXSelector, void*) {
268
const auto& demandElements = myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getDemandElements();
269
if (demandElements.at(myDistributionEditor->getDistributionTag()).size() > 0) {
270
return sender->handle(this, FXSEL(SEL_COMMAND, ID_ENABLE), nullptr);
271
} else {
272
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
273
}
274
}
275
276
277
std::map<std::string, GNEDemandElement*>
278
GNEDistributionFrame::DistributionSelector::fillDistributionComboBox() {
279
// get ACs
280
const auto& ACs = myFrameParent->getViewNet()->getNet()->getAttributeCarriers();
281
// clear items
282
myDistributionsComboBox->clearItems();
283
// fill with distributions sorted by ID
284
std::map<std::string, GNEDemandElement*> distributions;
285
for (const auto& distribution : ACs->getDemandElements().at(myDistributionEditor->getDistributionTag())) {
286
distributions[distribution.second->getID()] = distribution.second;
287
}
288
for (const auto& distribution : distributions) {
289
myDistributionsComboBox->appendIconItem(distribution.first.c_str(), distribution.second->getACIcon());
290
}
291
// return distributions sorted by ID
292
return distributions;
293
}
294
295
// ---------------------------------------------------------------------------
296
// GNEDistributionFrame::DistributionRow - methods
297
// ---------------------------------------------------------------------------
298
299
GNEDistributionFrame::DistributionRow::DistributionRow(DistributionValuesEditor* attributeEditorParent, const GNEDemandElement* key, const double probability) :
300
FXHorizontalFrame(attributeEditorParent->getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame),
301
myDistributionValuesEditorParent(attributeEditorParent),
302
myKey(key),
303
myProbability(probability) {
304
// get staticTooltip menu
305
auto staticTooltipMenu = attributeEditorParent->getFrameParent()->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu();
306
// create label
307
myIconLabel = new FXLabel(this, "", key->getACIcon(), GUIDesignLabelIconThick);
308
// Create and hide MFXTextFieldIcon for string attributes
309
myComboBoxKeys = new MFXComboBoxIcon(this, staticTooltipMenu, true, GUIDesignComboBoxVisibleItems,
310
this, MID_GNE_SET_TYPE, GUIDesignComboBox);
311
// Create and hide MFXTextFieldIcon for string attributes
312
myProbabilityTextField = new MFXTextFieldIcon(this, staticTooltipMenu, GUIIcon::EMPTY, this, MID_GNE_SET_ATTRIBUTE,
313
GUIDesignTextFieldFixedRestricted(50, TEXTFIELD_REAL));
314
// create delete buton
315
myDeleteRowButton = new MFXButtonTooltip(this, staticTooltipMenu,
316
"", GUIIconSubSys::getIcon(GUIIcon::REMOVE), this, MID_GNE_BUTTON_REMOVE, GUIDesignButtonIcon);
317
myDeleteRowButton->setTipText(TL("Delete distribution value"));
318
// only create if parent was created
319
if (getParent()->id() && attributeEditorParent->myDistributionSelector->getCurrentDistribution()) {
320
// create DistributionRow
321
FXHorizontalFrame::create();
322
// refresh row
323
refreshRow();
324
// Show DistributionRow
325
show();
326
}
327
}
328
329
330
void
331
GNEDistributionFrame::DistributionRow::destroy() {
332
// only destroy if parent was created
333
if (getParent()->id()) {
334
FXHorizontalFrame::destroy();
335
}
336
}
337
338
339
void
340
GNEDistributionFrame::DistributionRow::refreshRow() {
341
/*
342
// get distribution selector
343
const auto currentDistribution = myDistributionValuesEditorParent->myDistributionSelector->getCurrentDistribution();
344
// get possible keys
345
const auto possibleKeys = currentDistribution->getPossibleDistributionKeys(myDistributionValuesEditorParent->myDistributionValueTag);
346
// refill combo Box with possible values
347
myComboBoxKeys->clearItems();
348
myComboBoxKeys->appendIconItem(myKey->getID().c_str());
349
for (const auto& possibleKey : possibleKeys) {
350
myComboBoxKeys->appendIconItem(possibleKey.first.c_str());
351
}
352
myComboBoxKeys->setCurrentItem(0);
353
// adjust combo Box
354
myComboBoxKeys->setTextColor(GUIDesignTextColorBlack);
355
myComboBoxKeys->killFocus();
356
// set probability
357
myProbabilityTextField->setText(toString(myProbability).c_str());
358
myProbabilityTextField->setTextColor(GUIDesignTextColorBlack);
359
myProbabilityTextField->killFocus();
360
*/
361
}
362
363
364
double
365
GNEDistributionFrame::DistributionRow::getProbability() const {
366
return myProbability;
367
}
368
369
370
long
371
GNEDistributionFrame::DistributionRow::onCmdSetKey(FXObject*, FXSelector, void*) {
372
// get Undo list
373
//GNEUndoList* undoList = myDistributionValuesEditorParent->getFrameParent()->getViewNet()->getUndoList();
374
// get current distribution
375
auto currentDistribution = myDistributionValuesEditorParent->myDistributionSelector->getCurrentDistribution();
376
// get ACs
377
//const auto& ACs = myDistributionValuesEditorParent->getFrameParent()->getViewNet()->getNet()->getAttributeCarriers();
378
// continue if we have a distribution to edit
379
if (currentDistribution == nullptr) {
380
return 1;
381
}
382
/*
383
// check if new key is valid
384
if (isValidNewKey()) {
385
myComboBoxKeys->setTextColor(GUIDesignTextColorBlack);
386
// get new key
387
const auto newKey = ACs->retrieveDemandElement(myDistributionValuesEditorParent->myDistributionValueTag, myComboBoxKeys->getText().text());
388
// only change if is different of current key
389
if (myKey != newKey) {
390
// begin undo list
391
undoList->begin(myKey, "edit distribution key");
392
// remove distribution key
393
currentDistribution->removeDistributionKey(myKey, undoList);
394
// sert key and icon
395
myKey = ACs->retrieveDemandElement(myDistributionValuesEditorParent->myDistributionValueTag, myComboBoxKeys->getText().text());
396
myIconLabel->setIcon(myKey->getACIcon());
397
// add distribution key (and probability)
398
currentDistribution->addDistributionKey(myKey, myProbability, undoList);
399
// end undo list
400
undoList->end();
401
// refresh all rows
402
myDistributionValuesEditorParent->refreshRows();
403
}
404
} else {
405
myComboBoxKeys->setTextColor(GUIDesignTextColorRed);
406
myComboBoxKeys->killFocus();
407
}
408
*/
409
return 1;
410
}
411
412
413
long
414
GNEDistributionFrame::DistributionRow::onCmdSetProbability(FXObject*, FXSelector, void*) {
415
// get current distribution
416
auto currentDistribution = myDistributionValuesEditorParent->myDistributionSelector->getCurrentDistribution();
417
// continue if we have a distribution to edit
418
if (currentDistribution == nullptr) {
419
return 1;
420
}
421
// get probability
422
const std::string probabilityStr = myProbabilityTextField->getText().text();
423
//const double probability = GNEAttributeCarrier::canParse<double>(probabilityStr) ? GNEAttributeCarrier::parse<double>(probabilityStr) : -1;
424
// Check if set new probability
425
/*
426
if (probability >= 0) {
427
// set new probability
428
myProbability = probability;
429
// edit distribution value
430
currentDistribution->editDistributionValue(myKey, probability, myDistributionValuesEditorParent->getFrameParent()->getViewNet()->getUndoList());
431
// reset color
432
myProbabilityTextField->setTextColor(GUIDesignTextColorBlack);
433
// update sum label
434
myDistributionValuesEditorParent->updateSumLabel();
435
} else {
436
myProbabilityTextField->setTextColor(GUIDesignTextColorRed);
437
myProbabilityTextField->killFocus();
438
}
439
*/
440
return 1;
441
}
442
443
444
long
445
GNEDistributionFrame::DistributionRow::onCmdRemoveRow(FXObject*, FXSelector, void*) {
446
// get current distribution
447
auto currentDistribution = myDistributionValuesEditorParent->myDistributionSelector->getCurrentDistribution();
448
// continue if we have a distribution to edit
449
if (currentDistribution == nullptr) {
450
return 1;
451
}
452
// remove distribution key
453
//currentDistribution->removeDistributionKey(myKey, myDistributionValuesEditorParent->getFrameParent()->getViewNet()->getUndoList());
454
// remake rows
455
myDistributionValuesEditorParent->remakeRows();
456
return 1;
457
}
458
459
460
bool
461
GNEDistributionFrame::DistributionRow::isValidNewKey() const {
462
/*
463
const auto ACs = myDistributionValuesEditorParent->getFrameParent()->getViewNet()->getNet()->getAttributeCarriers();
464
// get element associated with key
465
//const auto element = ACs->retrieveDemandElement(myDistributionValuesEditorParent->myDistributionValueTag, myComboBoxKeys->getText().text(), false);
466
// first check if element exists
467
if (element) {
468
// avoid duplicated keys
469
return !myKey->keyExists(element);
470
} else {
471
return false;
472
}
473
*/
474
return false;
475
}
476
477
// ---------------------------------------------------------------------------
478
// GNEDistributionFrame::DistributionValuesEditor - methods
479
// ---------------------------------------------------------------------------
480
481
GNEDistributionFrame::DistributionValuesEditor::DistributionValuesEditor(GNEFrame* frameParent, DistributionEditor* distributionEditor,
482
DistributionSelector* distributionSelector, GNEAttributesEditor* attributesEditor, SumoXMLTag distributionValueTag) :
483
MFXGroupBoxModule(frameParent, TL("Distribution values")),
484
myFrameParent(frameParent),
485
myDistributionEditor(distributionEditor),
486
myDistributionSelector(distributionSelector),
487
myAttributesEditor(attributesEditor),
488
myDistributionValueTag(distributionValueTag) {
489
// set relations
490
myDistributionEditor->myDistributionSelector = myDistributionSelector;
491
myDistributionSelector->myDistributionEditor = myDistributionEditor;
492
myDistributionSelector->myAttributesEditor = myAttributesEditor;
493
myDistributionSelector->myDistributionValuesEditor = this;
494
// get staticTooltip menu
495
auto staticTooltipMenu = frameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu();
496
// Create bot frame elements
497
myBotFrame = new FXHorizontalFrame(getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame);
498
auto addButton = new MFXButtonTooltip(myBotFrame, staticTooltipMenu, "", GUIIconSubSys::getIcon(GUIIcon::ADD), this, MID_GNE_BUTTON_ADD, GUIDesignButtonIcon);
499
addButton->setTipText(TL("Add new distribution value"));
500
new FXHorizontalFrame(myBotFrame, GUIDesignAuxiliarHorizontalFrame);
501
new FXLabel(myBotFrame, "", GUIIconSubSys::getIcon(GUIIcon::SUM), GUIDesignLabelIconThick);
502
mySumLabel = new FXLabel(myBotFrame, "", nullptr, GUIDesignLabelThickedFixed(50));
503
new FXLabel(myBotFrame, "", GUIIconSubSys::getIcon(GUIIcon::EMPTY), GUIDesignLabelFixed(GUIDesignHeight));
504
}
505
506
507
void
508
GNEDistributionFrame::DistributionValuesEditor::showDistributionValuesEditor() {
509
// remake rows
510
remakeRows();
511
// show DistributionValuesEditor
512
show();
513
}
514
515
516
void
517
GNEDistributionFrame::DistributionValuesEditor::hideDistributionValuesEditor() {
518
// hide also DistributionValuesEditor
519
hide();
520
}
521
522
523
void
524
GNEDistributionFrame::DistributionValuesEditor::remakeRows() {
525
// first remove all rows
526
for (auto& row : myDistributionRows) {
527
// destroy and delete all rows
528
if (row != nullptr) {
529
row->destroy();
530
delete row;
531
row = nullptr;
532
}
533
}
534
myDistributionRows.clear();
535
/*
536
// continue if we have a distribution to edit
537
if (myDistributionSelector->getCurrentDistribution()) {
538
// Iterate over distribution key-values
539
for (const auto& keyValue : myDistributionSelector->getCurrentDistribution()->getDistributionKeyValues()) {
540
// create distribution row
541
auto distributionRow = new DistributionRow(this, keyValue.first, keyValue.second);
542
// add into distribution rows
543
myDistributionRows.push_back(distributionRow);
544
}
545
}
546
*/
547
// reparent bot frame button (to place it at bottom)
548
myBotFrame->reparent(getCollapsableFrame());
549
}
550
551
552
void
553
GNEDistributionFrame::DistributionValuesEditor::refreshRows() {
554
// refresh rows
555
for (const auto& row : myDistributionRows) {
556
row->refreshRow();
557
}
558
}
559
560
561
GNEFrame*
562
GNEDistributionFrame::DistributionValuesEditor::getFrameParent() const {
563
return myFrameParent;
564
}
565
566
567
void
568
GNEDistributionFrame::DistributionValuesEditor::updateSumLabel() {
569
// update probability
570
double sumProbability = 0;
571
for (const auto& row : myDistributionRows) {
572
sumProbability += row->getProbability();
573
}
574
mySumLabel->setText(toString(sumProbability).c_str());
575
}
576
577
578
long
579
GNEDistributionFrame::DistributionValuesEditor::onCmdAddRow(FXObject*, FXSelector, void*) {
580
if (myDistributionSelector->getCurrentDistribution() == nullptr) {
581
return 1;
582
}
583
/*
584
// get next free key
585
const auto possibleKeys = myDistributionSelector->getCurrentDistribution()->getPossibleDistributionKeys(myDistributionValueTag);
586
if (possibleKeys.empty()) {
587
return 1;
588
}
589
// add first possible key
590
myDistributionSelector->getCurrentDistribution()->addDistributionKey(possibleKeys.begin()->second, 0.5, myFrameParent->getViewNet()->getUndoList());
591
// remake rows
592
remakeRows();
593
*/
594
return 1;
595
}
596
597
598
long
599
GNEDistributionFrame::DistributionValuesEditor::onUpdAddRow(FXObject* sender, FXSelector, void*) {
600
if (myDistributionSelector->getCurrentDistribution() == nullptr) {
601
mySumLabel->setText("");
602
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
603
} else {
604
// update sum label
605
updateSumLabel();
606
/*
607
// enable or disable add button depending of existents distributions
608
if (myDistributionSelector->getCurrentDistribution()->getPossibleDistributionKeys(myDistributionValueTag).size() > 0) {
609
return sender->handle(this, FXSEL(SEL_COMMAND, ID_ENABLE), nullptr);
610
} else {
611
return sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), nullptr);
612
}
613
*/
614
}
615
return 1;
616
}
617
618
/****************************************************************************/
619
620