78 myFrameParent(frameParent),
79 myDistributionTag(distributionTag) {
81 auto staticTooltipMenu = myFrameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu();
83 myCreateDistributionButton =
new MFXButtonTooltip(getCollapsableFrame(), staticTooltipMenu,
TL(
"New"),
85 myCreateDistributionButton->setTipText(
TLF(
"Create new %",
toString(myDistributionTag)).c_str()),
87 myDeleteDistributionButton =
new MFXButtonTooltip(getCollapsableFrame(), staticTooltipMenu,
TL(
"Delete"),
89 myDeleteDistributionButton->setTipText(
TLF(
"Delete current edited %",
toString(myDistributionTag)).c_str()),
100 return myDistributionTag;
106 auto undoList = myFrameParent->getViewNet()->getUndoList();
108 const auto distributionID = myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->generateDemandElementID(myDistributionTag);
112 distribution =
new GNEVTypeDistribution(myFrameParent->getViewNet()->getNet(), distributionID, -1);
123 myDistributionSelector->setDistribution(distribution);
130 auto undoList = myFrameParent->getViewNet()->getUndoList();
131 auto currentDistribution = myDistributionSelector->getCurrentDistribution();
132 if (currentDistribution) {
134 undoList->begin(currentDistribution->getTagProperty().getGUIIcon(),
"delete " + currentDistribution->getTagProperty().getTagStr() +
" distribution");
136 myFrameParent->getViewNet()->getNet()->deleteDemandElement(myDistributionSelector->getCurrentDistribution(), undoList);
140 myDistributionSelector->refreshDistributionSelector();
149 if (myDistributionSelector->getCurrentDistribution()) {
150 return sender->handle(
this, FXSEL(SEL_COMMAND, ID_ENABLE),
nullptr);
152 return sender->handle(
this, FXSEL(SEL_COMMAND, ID_DISABLE),
nullptr);
162 myFrameParent(frameParent) {
176 myCurrentDistribution = distribution;
177 refreshDistributionSelector();
183 return myCurrentDistribution;
191 fillDistributionComboBox();
193 for (
int i = 0; i < (int)myDistributionsComboBox->getNumItems(); i++) {
194 if (myDistributionsComboBox->getItemText(i) == myCurrentDistribution->getID()) {
195 myDistributionsComboBox->setCurrentItem(i);
203 auto& inspectedElements = myFrameParent->getViewNet()->getInspectedElements();
205 const auto distributions = fillDistributionComboBox();
207 myCurrentDistribution = myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->retrieveDemandElement(myCurrentDistribution,
false);
209 if (myCurrentDistribution) {
210 for (
int i = 0; i < (int)myDistributionsComboBox->getNumItems(); i++) {
211 if (myDistributionsComboBox->getItemText(i) == myCurrentDistribution->getID()) {
212 myDistributionsComboBox->setCurrentItem(i);
215 }
else if (distributions.size() > 0) {
217 myCurrentDistribution = distributions.begin()->second;
220 if (myCurrentDistribution) {
222 inspectedElements.inspectAC(myCurrentDistribution);
224 myAttributesEditor->showAttributeEditorModule(
true);
225 myDistributionValuesEditor->showDistributionValuesEditor();
228 inspectedElements.inspectACs({});
230 myAttributesEditor->hideAttributesEditorModule();
231 myDistributionValuesEditor->hideDistributionValuesEditor();
238 const auto viewNet = myFrameParent->getViewNet();
239 const auto& distributions = viewNet->getNet()->getAttributeCarriers()->getDemandElements().at(myDistributionEditor->getDistributionTag());
241 for (
const auto& distribution : distributions) {
242 if (distribution.second->getID() == myDistributionsComboBox->getText().text()) {
244 myCurrentDistribution = distribution.second;
246 myDistributionsComboBox->setTextColor(FXRGB(0, 0, 0));
248 viewNet->getInspectedElements().inspectAC(distribution.second);
250 myAttributesEditor->showAttributeEditorModule(
true);
251 myDistributionValuesEditor->showDistributionValuesEditor();
253 WRITE_DEBUG((
"Selected item '" + myDistributionsComboBox->getText() +
"' in DistributionSelector").text());
255 viewNet->updateViewNet();
260 myCurrentDistribution =
nullptr;
262 myAttributesEditor->hideAttributesEditorModule();
263 myDistributionValuesEditor->hideDistributionValuesEditor();
265 myDistributionsComboBox->setTextColor(FXRGB(255, 0, 0));
267 WRITE_DEBUG(
"Selected invalid item in DistributionSelector");
269 viewNet->updateViewNet();
276 const auto& demandElements = myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getDemandElements();
277 if (demandElements.at(myDistributionEditor->getDistributionTag()).size() > 0) {
278 return sender->handle(
this, FXSEL(SEL_COMMAND, ID_ENABLE),
nullptr);
280 return sender->handle(
this, FXSEL(SEL_COMMAND, ID_DISABLE),
nullptr);
285std::map<std::string, GNEDemandElement*>
288 const auto& ACs = myFrameParent->getViewNet()->getNet()->getAttributeCarriers();
290 myDistributionsComboBox->clearItems();
292 std::map<std::string, GNEDemandElement*> distributions;
293 for (
const auto& distribution : ACs->getDemandElements().at(myDistributionEditor->getDistributionTag())) {
294 distributions[distribution.second->getID()] = distribution.second;
296 for (
const auto& distribution : distributions) {
297 myDistributionsComboBox->appendIconItem(distribution.first.c_str(), distribution.second->getACIcon());
300 return distributions;
309 myDistributionValuesEditorParent(attributeEditorParent),
311 myProbability(probability) {
329 FXHorizontalFrame::create();
341 if (getParent()->
id()) {
342 FXHorizontalFrame::destroy();
350 const auto currentDistribution = myDistributionValuesEditorParent->myDistributionSelector->getCurrentDistribution();
352 const auto possibleKeys = currentDistribution->getPossibleDistributionKeys(myDistributionValuesEditorParent->myDistributionValueTag);
354 myComboBoxKeys->clearItems();
355 myComboBoxKeys->appendIconItem(myKey->getID().c_str());
356 for (
const auto& possibleKey : possibleKeys) {
357 myComboBoxKeys->appendIconItem(possibleKey.first.c_str());
359 myComboBoxKeys->setCurrentItem(0);
361 myComboBoxKeys->setTextColor(FXRGB(0, 0, 0));
362 myComboBoxKeys->killFocus();
364 myProbabilityTextField->setText(
toString(myProbability).c_str());
365 myProbabilityTextField->setTextColor(FXRGB(0, 0, 0));
366 myProbabilityTextField->killFocus();
372 return myProbability;
379 GNEUndoList* undoList = myDistributionValuesEditorParent->getFrameParent()->getViewNet()->getUndoList();
381 auto currentDistribution = myDistributionValuesEditorParent->myDistributionSelector->getCurrentDistribution();
383 const auto& ACs = myDistributionValuesEditorParent->getFrameParent()->getViewNet()->getNet()->getAttributeCarriers();
385 if (currentDistribution ==
nullptr) {
389 if (isValidNewKey()) {
390 myComboBoxKeys->setTextColor(FXRGB(0, 0, 0));
392 const auto newKey = ACs->retrieveDemandElement(myDistributionValuesEditorParent->myDistributionValueTag, myComboBoxKeys->getText().text());
394 if (myKey != newKey) {
396 undoList->
begin(myKey,
"edit distribution key");
398 currentDistribution->removeDistributionKey(myKey, undoList);
400 myKey = ACs->retrieveDemandElement(myDistributionValuesEditorParent->myDistributionValueTag, myComboBoxKeys->getText().text());
401 myIconLabel->setIcon(myKey->getACIcon());
403 currentDistribution->addDistributionKey(myKey, myProbability, undoList);
407 myDistributionValuesEditorParent->refreshRows();
410 myComboBoxKeys->setTextColor(FXRGB(255, 0, 0));
411 myComboBoxKeys->killFocus();
420 auto currentDistribution = myDistributionValuesEditorParent->myDistributionSelector->getCurrentDistribution();
422 if (currentDistribution ==
nullptr) {
426 const std::string probabilityStr = myProbabilityTextField->getText().text();
427 const double probability = GNEAttributeCarrier::canParse<double>(probabilityStr) ? GNEAttributeCarrier::parse<double>(probabilityStr) : -1;
429 if (probability >= 0) {
431 myProbability = probability;
433 currentDistribution->editDistributionValue(myKey, probability, myDistributionValuesEditorParent->getFrameParent()->getViewNet()->getUndoList());
435 myProbabilityTextField->setTextColor(FXRGB(0, 0, 0));
437 myDistributionValuesEditorParent->updateSumLabel();
439 myProbabilityTextField->setTextColor(FXRGB(255, 0, 0));
440 myProbabilityTextField->killFocus();
449 auto currentDistribution = myDistributionValuesEditorParent->myDistributionSelector->getCurrentDistribution();
451 if (currentDistribution ==
nullptr) {
455 currentDistribution->removeDistributionKey(myKey, myDistributionValuesEditorParent->getFrameParent()->getViewNet()->getUndoList());
457 myDistributionValuesEditorParent->remakeRows();
464 const auto ACs = myDistributionValuesEditorParent->getFrameParent()->getViewNet()->getNet()->getAttributeCarriers();
466 const auto element = ACs->retrieveDemandElement(myDistributionValuesEditorParent->myDistributionValueTag, myComboBoxKeys->getText().text(),
false);
470 return !myKey->keyExists(element);
483 myFrameParent(frameParent),
484 myDistributionEditor(distributionEditor),
485 myDistributionSelector(distributionSelector),
486 myAttributesEditor(attributesEditor),
487 myDistributionValueTag(distributionValueTag) {
498 addButton->setTipText(
TL(
"Add new distribution value"));
525 for (
auto& row : myDistributionRows) {
527 if (row !=
nullptr) {
533 myDistributionRows.clear();
535 if (myDistributionSelector->getCurrentDistribution()) {
537 for (
const auto& keyValue : myDistributionSelector->getCurrentDistribution()->getDistributionKeyValues()) {
539 auto distributionRow =
new DistributionRow(
this, keyValue.first, keyValue.second);
541 myDistributionRows.push_back(distributionRow);
545 myBotFrame->reparent(getCollapsableFrame());
552 for (
const auto& row : myDistributionRows) {
560 return myFrameParent;
567 double sumProbability = 0;
568 for (
const auto& row : myDistributionRows) {
569 sumProbability += row->getProbability();
571 mySumLabel->setText(
toString(sumProbability).c_str());
577 if (myDistributionSelector->getCurrentDistribution() ==
nullptr) {
581 const auto possibleKeys = myDistributionSelector->getCurrentDistribution()->getPossibleDistributionKeys(myDistributionValueTag);
582 if (possibleKeys.empty()) {
586 myDistributionSelector->getCurrentDistribution()->addDistributionKey(possibleKeys.begin()->second, 0.5, myFrameParent->getViewNet()->getUndoList());
595 if (myDistributionSelector->getCurrentDistribution() ==
nullptr) {
596 mySumLabel->setText(
"");
597 return sender->handle(
this, FXSEL(SEL_COMMAND, ID_DISABLE),
nullptr);
602 if (myDistributionSelector->getCurrentDistribution()->getPossibleDistributionKeys(myDistributionValueTag).size() > 0) {
603 return sender->handle(
this, FXSEL(SEL_COMMAND, ID_ENABLE),
nullptr);
605 return sender->handle(
this, FXSEL(SEL_COMMAND, ID_DISABLE),
nullptr);
FXDEFMAP(GNEDistributionFrame::DistributionEditor) DistributionEditorMap[]
@ MID_GNE_DELETE
delete element
@ MID_GNE_SET_ATTRIBUTE
attribute edited
@ MID_GNE_BUTTON_REMOVE
remove button
@ MID_GNE_BUTTON_ADD
add button
@ MID_GNE_CREATE
create element
@ MID_GNE_SET_TYPE
used to select a type of element in a combo box
#define GUIDesignLabelFixed(width)
label, icon before text, text centered and custom width
#define GUIDesignButtonIcon
button only with icon
#define GUIDesignComboBox
#define GUIDesignComboBoxNCol
number of column of every combo box
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
#define GUIDesignComboBoxVisibleItemsMedium
combo box medium small
#define GUIDesignTextFieldNCol
Num of column of text field.
#define GUIDesignTextFieldFixedRestricted(width, type)
text field with fixed width
#define GUIDesignLabelThickedFixed(width)
label thicked, icon before text, text centered and custom width
#define GUIDesignLabelIconThick
label squared over frame with thick and with text justify to center
GUIIcon
An enumeration of icons used by the gui applications.
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_ROUTE_DISTRIBUTION
distribution of a route
@ SUMO_TAG_VTYPE_DISTRIBUTION
distribution of a vehicle type
int GUIDesignHeight
the default size for GUI elements
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
const GNETagProperties & getTagProperty() const
get tagProperty associated with this Attribute Carrier
long onCmdDeleteDistribution(FXObject *, FXSelector, void *)
Called when "Delete distribution" button is clicked.
SumoXMLTag getDistributionTag() const
get distribution tag
long onUpdDeleteDistribution(FXObject *sender, FXSelector, void *)
Called when "Delete distribution" button is updated.
long onCmdCreateDistribution(FXObject *, FXSelector, void *)
Called when "create distribution" button is clicked.
~DistributionEditor()
destructor
DistributionSelector * myDistributionSelector
distribution selector
bool isValidNewKey() const
FOX need this.
void destroy()
destroy DistributionRow (but don't delete)
long onCmdSetProbability(FXObject *, FXSelector, void *)
try to set new probability
MFXComboBoxIcon * myComboBoxKeys
comboBox with keys
void refreshRow()
refresh comboBox
FXLabel * myIconLabel
label
long onCmdRemoveRow(FXObject *, FXSelector, void *)
remove row
long onCmdSetKey(FXObject *, FXSelector, void *)
try to set new key
DistributionRow(DistributionValuesEditor *attributeEditorParent, const GNEDemandElement *key, const double probability)
FOX-declaration.
double getProbability() const
get current probability
MFXTextFieldTooltip * myProbabilityTextField
textField to modify the probability attribute
MFXButtonTooltip * myDeleteRowButton
delete row button
GNEDemandElement * getCurrentDistribution() const
current distribution
void refreshDistributionSelector()
refresh modul
DistributionValuesEditor * myDistributionValuesEditor
distribution values editor
std::map< std::string, GNEDemandElement * > fillDistributionComboBox()
FOX need this.
long onCmdSelectDistribution(FXObject *, FXSelector, void *)
Called when the user select distribution in ComboBox.
void refreshDistributionIDs()
refresh distribution IDs (only call when user change ID in internal attributes)
MFXComboBoxIcon * myDistributionsComboBox
comboBox with the list of distributions
DistributionEditor * myDistributionEditor
pointer to distribution editor
long onCmdUpdateDistribution(FXObject *sender, FXSelector, void *)
update distribution comboBox
GNEFrameAttributeModules::AttributesEditor * myAttributesEditor
attributes editor
~DistributionSelector()
destructor
void setDistribution(GNEDemandElement *distribution)
refresh modul
DistributionSelector(GNEFrame *frameParent)
constructor
long onUpdAddRow(FXObject *sender, FXSelector, void *)
Called when sum button button is updated.
void hideDistributionValuesEditor()
hide attribute editor
void refreshRows()
refresh rows
GNEFrame * getFrameParent() const
pointer to GNEFrame parent
DistributionEditor * myDistributionEditor
distribution editor
DistributionValuesEditor(GNEFrame *frameParent, DistributionEditor *distributionEditor, DistributionSelector *distributionSelector, GNEFrameAttributeModules::AttributesEditor *attributesEditor, SumoXMLTag distributionValueTag)
constructor
void updateSumLabel()
update sum label
long onCmdAddRow(FXObject *, FXSelector, void *)
Called when user press the add button.
FXLabel * mySumLabel
sum label
DistributionSelector * myDistributionSelector
distribution selector
void remakeRows()
destroy and remake rows
GNEFrameAttributeModules::AttributesEditor * myAttributesEditor
attributes editor
FXHorizontalFrame * myBotFrame
bot frame
void showDistributionValuesEditor()
show attributes of multiple ACs
GNEViewNet * getViewNet() const
get view net
GUIIcon getGUIIcon() const
get GUI icon associated to this Tag
void end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
void begin(GUIIcon icon, const std::string &description)
Begin undo command sub-group with current supermode. This begins a new group of commands that are tre...
GNEViewParent * getViewParent() const
get the net object
GNEApplicationWindow * getGNEAppWindows() const
get GNE Application Windows
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
MFXStaticToolTip * getStaticTooltipMenu() const
get static toolTip for menus
MFXGroupBoxModule (based on FXGroupBox)
FXVerticalFrame * getCollapsableFrame()
get collapsable frame (used by all elements that will be collapsed if button is toggled)