36#define TEMPORAL_FILENAME std::string()
80 myFrameParent(frameParent),
81 myDistributionTag(distributionTag) {
83 auto staticTooltipMenu = myFrameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu();
85 myCreateDistributionButton =
new MFXButtonTooltip(getCollapsableFrame(), staticTooltipMenu,
TL(
"New"),
87 myCreateDistributionButton->setTipText(
TLF(
"Create new %",
toString(myDistributionTag)).c_str()),
89 myDeleteDistributionButton =
new MFXButtonTooltip(getCollapsableFrame(), staticTooltipMenu,
TL(
"Delete"),
91 myDeleteDistributionButton->setTipText(
TLF(
"Delete current edited %",
toString(myDistributionTag)).c_str()),
102 return myDistributionTag;
108 auto undoList = myFrameParent->getViewNet()->getUndoList();
110 const auto distributionID = myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->generateDemandElementID(myDistributionTag);
112 auto bucket = myFrameParent->getViewNet()->getNet()->getACTemplates()->getTemplateAC(myDistributionTag)->getFileBucket();
116 distribution =
new GNEVTypeDistribution(distributionID, myFrameParent->getViewNet()->getNet(), bucket, -1);
118 distribution =
new GNERouteDistribution(distributionID, myFrameParent->getViewNet()->getNet(), bucket);
127 myDistributionSelector->setDistribution(distribution);
134 auto undoList = myFrameParent->getViewNet()->getUndoList();
135 auto currentDistribution = myDistributionSelector->getCurrentDistribution();
136 if (currentDistribution) {
138 undoList->begin(currentDistribution->getTagProperty()->getGUIIcon(),
"delete " + currentDistribution->getTagProperty()->getTagStr() +
" distribution");
140 myFrameParent->getViewNet()->getNet()->deleteDemandElement(myDistributionSelector->getCurrentDistribution(), undoList);
144 myDistributionSelector->refreshDistributionSelector();
153 if (myDistributionSelector->getCurrentDistribution()) {
154 return sender->handle(
this, FXSEL(SEL_COMMAND, ID_ENABLE),
nullptr);
156 return sender->handle(
this, FXSEL(SEL_COMMAND, ID_DISABLE),
nullptr);
166 myFrameParent(frameParent) {
180 myCurrentDistribution = distribution;
181 refreshDistributionSelector();
187 return myCurrentDistribution;
195 fillDistributionComboBox();
197 for (
int i = 0; i < (int)myDistributionsComboBox->getNumItems(); i++) {
198 if (myDistributionsComboBox->getItemText(i) == myCurrentDistribution->getID()) {
199 myDistributionsComboBox->setCurrentItem(i);
208 const auto distributions = fillDistributionComboBox();
210 myCurrentDistribution = myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->retrieveDemandElement(myCurrentDistribution,
false);
212 if (myCurrentDistribution) {
213 for (
int i = 0; i < (int)myDistributionsComboBox->getNumItems(); i++) {
214 if (myDistributionsComboBox->getItemText(i) == myCurrentDistribution->getID()) {
215 myDistributionsComboBox->setCurrentItem(i);
218 }
else if (distributions.size() > 0) {
220 myCurrentDistribution = distributions.begin()->second;
223 if (myCurrentDistribution) {
225 myAttributesEditor->showAttributesEditor(myCurrentDistribution,
true);
226 myDistributionValuesEditor->showDistributionValuesEditor();
229 myAttributesEditor->hideAttributesEditor();
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;
247 myAttributesEditor->showAttributesEditor(distribution.second,
true);
248 myDistributionValuesEditor->showDistributionValuesEditor();
250 viewNet->updateViewNet();
255 myCurrentDistribution =
nullptr;
257 myAttributesEditor->hideAttributesEditor();
258 myDistributionValuesEditor->hideDistributionValuesEditor();
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),
303 myDistributionReference(distributionReference) {
321 FXHorizontalFrame::create();
340 if (getParent()->
id()) {
341 FXHorizontalFrame::destroy();
348 return myDistributionReference;
354 return myDeleteRowButton;
361 if (myProbabilityTextField->getText().empty()) {
362 myProbabilityTextField->setText(myDistributionReference->getTagProperty()->getAttributeProperties(
SUMO_ATTR_PROB)->getDefaultStringValue().c_str());
365 if (myDistributionReference->isValid(
SUMO_ATTR_PROB, myProbabilityTextField->getText().text())) {
366 myDistributionReference->setAttribute(
SUMO_ATTR_PROB, myProbabilityTextField->getText().text(), myDistributionReference->getNet()->getUndoList());
367 myDistributionValuesEditorParent->updateSumLabel();
369 myProbabilityTextField->setText(myDistributionReference->getAttribute(
SUMO_ATTR_PROB).c_str(), FALSE);
371 if (myDistributionReference->isAttributeComputed(
SUMO_ATTR_PROB)) {
376 myProbabilityTextField->killFocus();
390 myFrameParent(frameParent),
391 myDistributionEditor(distributionEditor),
392 myDistributionSelector(distributionSelector),
393 myAttributesEditor(attributesEditor) {
431 for (
auto& row : myDistributionRows) {
433 if (row !=
nullptr) {
439 myDistributionRows.clear();
441 if (myDistributionSelector->getCurrentDistribution()) {
443 for (
const auto& distributionRef : myDistributionSelector->getCurrentDistribution()->getChildDemandElements()) {
444 if (distributionRef->getTagProperty()->isDistributionReference()) {
445 if (distributionRef->getTagProperty()->isDistributionReference() && (distributionRef->getParentDemandElements().front() == myDistributionSelector->getCurrentDistribution())) {
449 myDistributionRows.push_back(distributionRow);
453 distributionRef->updateGeometry();
458 if (myDistributionRows.size() > 0) {
459 myAddButton->enable();
461 myAddButton->disable();
466 myBotFrame->reparent(getCollapsableFrame());
472 return myFrameParent;
490 for (
const auto& row : myDistributionRows) {
491 if (row->getDeleteRowButton() == obj) {
492 myFrameParent->getViewNet()->getNet()->deleteDemandElement(row->getDistributionReference(), myFrameParent->getViewNet()->getUndoList());
503 double sumProbability = 0;
504 if (myDistributionSelector->getCurrentDistribution()) {
505 for (
const auto& distributionRef : myDistributionSelector->getCurrentDistribution()->getChildDemandElements()) {
506 if (distributionRef->getTagProperty()->isDistributionReference()) {
507 sumProbability += distributionRef->getAttributeDouble(
SUMO_ATTR_PROB);
512 const auto& vTypes = myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getDemandElements().at(
SUMO_TAG_VTYPE);
513 if (vTypes.size() == myDistributionRows.size()) {
514 myAddButton->disable();
516 myAddButton->enable();
521 const auto& routes = myFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getDemandElements().at(
SUMO_TAG_ROUTE);
522 if (routes.size() == myDistributionRows.size()) {
523 myAddButton->disable();
525 myAddButton->enable();
529 myAddButton->disable();
531 mySumLabel->setText(
toString(sumProbability).c_str());
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 GUIDesignTextFieldFixed(width)
text field with fixed width
#define GUIDesignTextColorRed
red color (for invalid text)
#define GUIDesignLabelFixed(width)
label, icon before text, text centered and custom width
#define GUIDesignButtonIcon
button only with icon
#define GUIDesignComboBox
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
#define GUIDesignComboBoxVisibleItems
#define GUIDesignTextColorBlack
black color (for correct text)
#define GUIDesignTextFieldRestricted(type)
text field extended over Frame with thick frame (int)
#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_VTYPE
description of a vehicle/person/container type
@ SUMO_TAG_ROUTE_DISTRIBUTION
distribution of a route
@ SUMO_TAG_ROUTE
description of a route
@ SUMO_TAG_VTYPE_DISTRIBUTION
distribution of a vehicle type
int GUIDesignHeight
the default height for GUI elements
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
FXIcon * getACIcon() const
get FXIcon associated to this AC
virtual bool isAttributeComputed(SumoXMLAttr key) const
const GNETagProperties * getTagProperty() const
get tagProperty associated with this Attribute Carrier
virtual std::string getAttribute(SumoXMLAttr key) const =0
Result getResult() const
get result to indicate if this dialog was closed accepting or rejecting changes
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
void destroy()
destroy DistributionRow (but don't delete)
GNEDemandElement * getDistributionReference() const
get pointer to distributionReference
MFXTextFieldIcon * myProbabilityTextField
textField to modify the probability attribute
GNEDemandElement * myDistributionReference
pointer to distributionReference
long onCmdSetProbability(FXObject *, FXSelector, void *)
try to set new probability
DistributionRow(DistributionValuesEditor *attributeEditorParent, GNEDemandElement *distributionReference)
FOX-declaration.
FXLabel * myIconLabel
label
MFXButtonTooltip * getDeleteRowButton() const
get delete row button
MFXTextFieldIcon * myIDTextField
comboBox with ID
DistributionValuesEditor * myDistributionValuesEditorParent
FOX need this.
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
GNEAttributesEditor * myAttributesEditor
attributes editor
void hideDistributionValuesEditor()
hide attribute editor
void refreshRows()
refresh rows
DistributionValuesEditor(GNEFrame *frameParent, DistributionEditor *distributionEditor, DistributionSelector *distributionSelector, GNEAttributesEditor *attributesEditor)
constructor
GNEFrame * getFrameParent() const
pointer to GNEFrame parent
DistributionEditor * myDistributionEditor
distribution editor
long onCmdRemoveRow(FXObject *obj, FXSelector, void *)
Called when user press the add button.
MFXButtonTooltip * myAddButton
add buton
void updateSumLabel()
FOX need this.
long onCmdAddRow(FXObject *, FXSelector, void *)
Called when user press the add button.
FXLabel * mySumLabel
sum label
DistributionSelector * myDistributionSelector
distribution selector
FXHorizontalFrame * myBotFrame
bot frame
void showDistributionValuesEditor()
show attributes of multiple ACs
GNEViewNet * getViewNet() const
get view net
GNEGroupBoxModule (based on FXGroupBox)
FXVerticalFrame * getCollapsableFrame()
get collapsable frame (used by all elements that will be collapsed if button is toggled)
GUIIcon getGUIIcon() const
get GUI icon associated to this tag property
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
virtual void disable()
Disable text field.
void setTextColor(FXColor clr)
Change text color.
void setText(const FXString &text, FXbool notify=FALSE)
Change the text and move cursor to end.
static FXColor getFXColor(const RGBColor &col)
converts FXColor to RGBColor
static const RGBColor BLUE
static const RGBColor BLACK
static const RGBColor RED
named colors