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);
204 const auto distributions = fillDistributionComboBox();
206 myCurrentDistribution = myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->retrieveDemandElement(myCurrentDistribution,
false);
208 if (myCurrentDistribution) {
209 for (
int i = 0; i < (int)myDistributionsComboBox->getNumItems(); i++) {
210 if (myDistributionsComboBox->getItemText(i) == myCurrentDistribution->getID()) {
211 myDistributionsComboBox->setCurrentItem(i);
214 }
else if (distributions.size() > 0) {
216 myCurrentDistribution = distributions.begin()->second;
219 if (myCurrentDistribution) {
221 myAttributesEditor->showAttributesEditor(myCurrentDistribution);
222 myDistributionValuesEditor->showDistributionValuesEditor();
225 myAttributesEditor->hideAttributesEditor();
226 myDistributionValuesEditor->hideDistributionValuesEditor();
233 const auto viewNet = myFrameParent->getViewNet();
234 const auto& distributions = viewNet->getNet()->getAttributeCarriers()->getDemandElements().at(myDistributionEditor->getDistributionTag());
236 for (
const auto& distribution : distributions) {
237 if (distribution.second->getID() == myDistributionsComboBox->getText().text()) {
239 myCurrentDistribution = distribution.second;
241 myDistributionsComboBox->setTextColor(FXRGB(0, 0, 0));
243 myAttributesEditor->showAttributesEditor(distribution.second);
244 myDistributionValuesEditor->showDistributionValuesEditor();
246 WRITE_DEBUG((
"Selected item '" + myDistributionsComboBox->getText() +
"' in DistributionSelector").text());
248 viewNet->updateViewNet();
253 myCurrentDistribution =
nullptr;
255 myAttributesEditor->hideAttributesEditor();
256 myDistributionValuesEditor->hideDistributionValuesEditor();
258 myDistributionsComboBox->setTextColor(FXRGB(255, 0, 0));
260 WRITE_DEBUG(
"Selected invalid item in DistributionSelector");
262 viewNet->updateViewNet();
269 const auto& demandElements = myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getDemandElements();
270 if (demandElements.at(myDistributionEditor->getDistributionTag()).size() > 0) {
271 return sender->handle(
this, FXSEL(SEL_COMMAND, ID_ENABLE),
nullptr);
273 return sender->handle(
this, FXSEL(SEL_COMMAND, ID_DISABLE),
nullptr);
278std::map<std::string, GNEDemandElement*>
281 const auto& ACs = myFrameParent->getViewNet()->getNet()->getAttributeCarriers();
283 myDistributionsComboBox->clearItems();
285 std::map<std::string, GNEDemandElement*> distributions;
286 for (
const auto& distribution : ACs->getDemandElements().at(myDistributionEditor->getDistributionTag())) {
287 distributions[distribution.second->getID()] = distribution.second;
289 for (
const auto& distribution : distributions) {
290 myDistributionsComboBox->appendIconItem(distribution.first.c_str(), distribution.second->getACIcon());
293 return distributions;
302 myDistributionValuesEditorParent(attributeEditorParent),
304 myProbability(probability) {
322 FXHorizontalFrame::create();
334 if (getParent()->
id()) {
335 FXHorizontalFrame::destroy();
343 const auto currentDistribution = myDistributionValuesEditorParent->myDistributionSelector->getCurrentDistribution();
345 const auto possibleKeys = currentDistribution->getPossibleDistributionKeys(myDistributionValuesEditorParent->myDistributionValueTag);
347 myComboBoxKeys->clearItems();
348 myComboBoxKeys->appendIconItem(myKey->getID().c_str());
349 for (
const auto& possibleKey : possibleKeys) {
350 myComboBoxKeys->appendIconItem(possibleKey.first.c_str());
352 myComboBoxKeys->setCurrentItem(0);
354 myComboBoxKeys->setTextColor(FXRGB(0, 0, 0));
355 myComboBoxKeys->killFocus();
357 myProbabilityTextField->setText(
toString(myProbability).c_str());
358 myProbabilityTextField->setTextColor(FXRGB(0, 0, 0));
359 myProbabilityTextField->killFocus();
365 return myProbability;
372 GNEUndoList* undoList = myDistributionValuesEditorParent->getFrameParent()->getViewNet()->getUndoList();
374 auto currentDistribution = myDistributionValuesEditorParent->myDistributionSelector->getCurrentDistribution();
376 const auto& ACs = myDistributionValuesEditorParent->getFrameParent()->getViewNet()->getNet()->getAttributeCarriers();
378 if (currentDistribution ==
nullptr) {
382 if (isValidNewKey()) {
383 myComboBoxKeys->setTextColor(FXRGB(0, 0, 0));
385 const auto newKey = ACs->retrieveDemandElement(myDistributionValuesEditorParent->myDistributionValueTag, myComboBoxKeys->getText().text());
387 if (myKey != newKey) {
389 undoList->
begin(myKey,
"edit distribution key");
391 currentDistribution->removeDistributionKey(myKey, undoList);
393 myKey = ACs->retrieveDemandElement(myDistributionValuesEditorParent->myDistributionValueTag, myComboBoxKeys->getText().text());
394 myIconLabel->setIcon(myKey->getACIcon());
396 currentDistribution->addDistributionKey(myKey, myProbability, undoList);
400 myDistributionValuesEditorParent->refreshRows();
403 myComboBoxKeys->setTextColor(FXRGB(255, 0, 0));
404 myComboBoxKeys->killFocus();
413 auto currentDistribution = myDistributionValuesEditorParent->myDistributionSelector->getCurrentDistribution();
415 if (currentDistribution ==
nullptr) {
419 const std::string probabilityStr = myProbabilityTextField->getText().text();
420 const double probability = GNEAttributeCarrier::canParse<double>(probabilityStr) ? GNEAttributeCarrier::parse<double>(probabilityStr) : -1;
422 if (probability >= 0) {
424 myProbability = probability;
426 currentDistribution->editDistributionValue(myKey, probability, myDistributionValuesEditorParent->getFrameParent()->getViewNet()->getUndoList());
428 myProbabilityTextField->setTextColor(FXRGB(0, 0, 0));
430 myDistributionValuesEditorParent->updateSumLabel();
432 myProbabilityTextField->setTextColor(FXRGB(255, 0, 0));
433 myProbabilityTextField->killFocus();
442 auto currentDistribution = myDistributionValuesEditorParent->myDistributionSelector->getCurrentDistribution();
444 if (currentDistribution ==
nullptr) {
448 currentDistribution->removeDistributionKey(myKey, myDistributionValuesEditorParent->getFrameParent()->getViewNet()->getUndoList());
450 myDistributionValuesEditorParent->remakeRows();
457 const auto ACs = myDistributionValuesEditorParent->getFrameParent()->getViewNet()->getNet()->getAttributeCarriers();
459 const auto element = ACs->retrieveDemandElement(myDistributionValuesEditorParent->myDistributionValueTag, myComboBoxKeys->getText().text(),
false);
463 return !myKey->keyExists(element);
476 myFrameParent(frameParent),
477 myDistributionEditor(distributionEditor),
478 myDistributionSelector(distributionSelector),
479 myAttributesEditor(attributesEditor),
480 myDistributionValueTag(distributionValueTag) {
491 addButton->setTipText(
TL(
"Add new distribution value"));
518 for (
auto& row : myDistributionRows) {
520 if (row !=
nullptr) {
526 myDistributionRows.clear();
528 if (myDistributionSelector->getCurrentDistribution()) {
530 for (
const auto& keyValue : myDistributionSelector->getCurrentDistribution()->getDistributionKeyValues()) {
532 auto distributionRow =
new DistributionRow(
this, keyValue.first, keyValue.second);
534 myDistributionRows.push_back(distributionRow);
538 myBotFrame->reparent(getCollapsableFrame());
545 for (
const auto& row : myDistributionRows) {
553 return myFrameParent;
560 double sumProbability = 0;
561 for (
const auto& row : myDistributionRows) {
562 sumProbability += row->getProbability();
564 mySumLabel->setText(
toString(sumProbability).c_str());
570 if (myDistributionSelector->getCurrentDistribution() ==
nullptr) {
574 const auto possibleKeys = myDistributionSelector->getCurrentDistribution()->getPossibleDistributionKeys(myDistributionValueTag);
575 if (possibleKeys.empty()) {
579 myDistributionSelector->getCurrentDistribution()->addDistributionKey(possibleKeys.begin()->second, 0.5, myFrameParent->getViewNet()->getUndoList());
588 if (myDistributionSelector->getCurrentDistribution() ==
nullptr) {
589 mySumLabel->setText(
"");
590 return sender->handle(
this, FXSEL(SEL_COMMAND, ID_DISABLE),
nullptr);
595 if (myDistributionSelector->getCurrentDistribution()->getPossibleDistributionKeys(myDistributionValueTag).size() > 0) {
596 return sender->handle(
this, FXSEL(SEL_COMMAND, ID_ENABLE),
nullptr);
598 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 GUIDesignTextFieldNCol
Num of column of text field.
#define GUIDesignComboBoxVisibleItems
#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
GNEAttributesEditor * myAttributesEditor
attributes editor
long onCmdUpdateDistribution(FXObject *sender, FXSelector, void *)
update distribution comboBox
~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.
GNEAttributesEditor * myAttributesEditor
attributes editor
void hideDistributionValuesEditor()
hide attribute editor
void refreshRows()
refresh rows
GNEFrame * getFrameParent() const
pointer to GNEFrame parent
DistributionEditor * myDistributionEditor
distribution editor
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
DistributionValuesEditor(GNEFrame *frameParent, DistributionEditor *distributionEditor, DistributionSelector *distributionSelector, GNEAttributesEditor *attributesEditor, SumoXMLTag distributionValueTag)
constructor
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)