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 myFrameParent->getViewNet()->setInspectedAttributeCarriers({myCurrentDistribution});
223 myAttributesEditor->showAttributeEditorModule(
true);
224 myDistributionValuesEditor->showDistributionValuesEditor();
227 myFrameParent->getViewNet()->setInspectedAttributeCarriers({});
229 myAttributesEditor->hideAttributesEditorModule();
230 myDistributionValuesEditor->hideDistributionValuesEditor();
237 const auto viewNet = myFrameParent->getViewNet();
238 const auto& distributions = viewNet->getNet()->getAttributeCarriers()->getDemandElements().at(myDistributionEditor->getDistributionTag());
240 for (
const auto& distribution : distributions) {
241 if (distribution.second->getID() == myDistributionsComboBox->getText().text()) {
243 myCurrentDistribution = distribution.second;
245 myDistributionsComboBox->setTextColor(FXRGB(0, 0, 0));
247 viewNet->setInspectedAttributeCarriers({distribution.second});
249 myAttributesEditor->showAttributeEditorModule(
true);
250 myDistributionValuesEditor->showDistributionValuesEditor();
252 WRITE_DEBUG((
"Selected item '" + myDistributionsComboBox->getText() +
"' in DistributionSelector").text());
254 viewNet->updateViewNet();
259 myCurrentDistribution =
nullptr;
261 myAttributesEditor->hideAttributesEditorModule();
262 myDistributionValuesEditor->hideDistributionValuesEditor();
264 myDistributionsComboBox->setTextColor(FXRGB(255, 0, 0));
266 WRITE_DEBUG(
"Selected invalid item in DistributionSelector");
268 viewNet->updateViewNet();
275 const auto& demandElements = myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getDemandElements();
276 if (demandElements.at(myDistributionEditor->getDistributionTag()).size() > 0) {
277 return sender->handle(
this, FXSEL(SEL_COMMAND, ID_ENABLE),
nullptr);
279 return sender->handle(
this, FXSEL(SEL_COMMAND, ID_DISABLE),
nullptr);
284std::map<std::string, GNEDemandElement*>
287 const auto& ACs = myFrameParent->getViewNet()->getNet()->getAttributeCarriers();
289 myDistributionsComboBox->clearItems();
291 std::map<std::string, GNEDemandElement*> distributions;
292 for (
const auto& distribution : ACs->getDemandElements().at(myDistributionEditor->getDistributionTag())) {
293 distributions[distribution.second->getID()] = distribution.second;
295 for (
const auto& distribution : distributions) {
296 myDistributionsComboBox->appendIconItem(distribution.first.c_str(), distribution.second->getACIcon());
299 return distributions;
308 myDistributionValuesEditorParent(attributeEditorParent),
310 myProbability(probability) {
328 FXHorizontalFrame::create();
340 if (getParent()->
id()) {
341 FXHorizontalFrame::destroy();
349 const auto currentDistribution = myDistributionValuesEditorParent->myDistributionSelector->getCurrentDistribution();
351 const auto possibleKeys = currentDistribution->getPossibleDistributionKeys(myDistributionValuesEditorParent->myDistributionValueTag);
353 myComboBoxKeys->clearItems();
354 myComboBoxKeys->appendIconItem(myKey->getID().c_str());
355 for (
const auto& possibleKey : possibleKeys) {
356 myComboBoxKeys->appendIconItem(possibleKey.first.c_str());
358 myComboBoxKeys->setCurrentItem(0);
360 myComboBoxKeys->setTextColor(FXRGB(0, 0, 0));
361 myComboBoxKeys->killFocus();
363 myProbabilityTextField->setText(
toString(myProbability).c_str());
364 myProbabilityTextField->setTextColor(FXRGB(0, 0, 0));
365 myProbabilityTextField->killFocus();
371 return myProbability;
378 GNEUndoList* undoList = myDistributionValuesEditorParent->getFrameParent()->getViewNet()->getUndoList();
380 auto currentDistribution = myDistributionValuesEditorParent->myDistributionSelector->getCurrentDistribution();
382 const auto& ACs = myDistributionValuesEditorParent->getFrameParent()->getViewNet()->getNet()->getAttributeCarriers();
384 if (currentDistribution ==
nullptr) {
388 if (isValidNewKey()) {
389 myComboBoxKeys->setTextColor(FXRGB(0, 0, 0));
391 const auto newKey = ACs->retrieveDemandElement(myDistributionValuesEditorParent->myDistributionValueTag, myComboBoxKeys->getText().text());
393 if (myKey != newKey) {
395 undoList->
begin(myKey,
"edit distribution key");
397 currentDistribution->removeDistributionKey(myKey, undoList);
399 myKey = ACs->retrieveDemandElement(myDistributionValuesEditorParent->myDistributionValueTag, myComboBoxKeys->getText().text());
400 myIconLabel->setIcon(myKey->getACIcon());
402 currentDistribution->addDistributionKey(myKey, myProbability, undoList);
406 myDistributionValuesEditorParent->refreshRows();
409 myComboBoxKeys->setTextColor(FXRGB(255, 0, 0));
410 myComboBoxKeys->killFocus();
419 auto currentDistribution = myDistributionValuesEditorParent->myDistributionSelector->getCurrentDistribution();
421 if (currentDistribution ==
nullptr) {
425 const std::string probabilityStr = myProbabilityTextField->getText().text();
426 const double probability = GNEAttributeCarrier::canParse<double>(probabilityStr) ? GNEAttributeCarrier::parse<double>(probabilityStr) : -1;
428 if (probability >= 0) {
430 myProbability = probability;
432 currentDistribution->editDistributionValue(myKey, probability, myDistributionValuesEditorParent->getFrameParent()->getViewNet()->getUndoList());
434 myProbabilityTextField->setTextColor(FXRGB(0, 0, 0));
436 myDistributionValuesEditorParent->updateSumLabel();
438 myProbabilityTextField->setTextColor(FXRGB(255, 0, 0));
439 myProbabilityTextField->killFocus();
448 auto currentDistribution = myDistributionValuesEditorParent->myDistributionSelector->getCurrentDistribution();
450 if (currentDistribution ==
nullptr) {
454 currentDistribution->removeDistributionKey(myKey, myDistributionValuesEditorParent->getFrameParent()->getViewNet()->getUndoList());
456 myDistributionValuesEditorParent->remakeRows();
463 const auto ACs = myDistributionValuesEditorParent->getFrameParent()->getViewNet()->getNet()->getAttributeCarriers();
465 const auto element = ACs->retrieveDemandElement(myDistributionValuesEditorParent->myDistributionValueTag, myComboBoxKeys->getText().text(),
false);
469 return !myKey->keyExists(element);
482 myFrameParent(frameParent),
483 myDistributionEditor(distributionEditor),
484 myDistributionSelector(distributionSelector),
485 myAttributesEditor(attributesEditor),
486 myDistributionValueTag(distributionValueTag) {
497 addButton->setTipText(
TL(
"Add new distribution value"));
524 for (
auto& row : myDistributionRows) {
526 if (row !=
nullptr) {
532 myDistributionRows.clear();
534 if (myDistributionSelector->getCurrentDistribution()) {
536 for (
const auto& keyValue : myDistributionSelector->getCurrentDistribution()->getDistributionKeyValues()) {
538 auto distributionRow =
new DistributionRow(
this, keyValue.first, keyValue.second);
540 myDistributionRows.push_back(distributionRow);
544 myBotFrame->reparent(getCollapsableFrame());
551 for (
const auto& row : myDistributionRows) {
559 return myFrameParent;
566 double sumProbability = 0;
567 for (
const auto& row : myDistributionRows) {
568 sumProbability += row->getProbability();
570 mySumLabel->setText(
toString(sumProbability).c_str());
576 if (myDistributionSelector->getCurrentDistribution() ==
nullptr) {
580 const auto possibleKeys = myDistributionSelector->getCurrentDistribution()->getPossibleDistributionKeys(myDistributionValueTag);
581 if (possibleKeys.empty()) {
585 myDistributionSelector->getCurrentDistribution()->addDistributionKey(possibleKeys.begin()->second, 0.5, myFrameParent->getViewNet()->getUndoList());
594 if (myDistributionSelector->getCurrentDistribution() ==
nullptr) {
595 mySumLabel->setText(
"");
596 return sender->handle(
this, FXSEL(SEL_COMMAND, ID_DISABLE),
nullptr);
601 if (myDistributionSelector->getCurrentDistribution()->getPossibleDistributionKeys(myDistributionValueTag).size() > 0) {
602 return sender->handle(
this, FXSEL(SEL_COMMAND, ID_ENABLE),
nullptr);
604 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)