Eclipse SUMO - Simulation of Urban MObility
GNEFlowEditor.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2001-2022 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/****************************************************************************/
19/****************************************************************************/
20#include <config.h>
21
22#include <netedit/GNEUndoList.h>
23#include <netedit/GNEViewNet.h>
29
30#include "GNEFlowEditor.h"
31
32
33// ===========================================================================
34// FOX callback mapping
35// ===========================================================================
36
37FXDEFMAP(GNEFlowEditor) FlowEditorMap[] = {
39};
40
41// Object implementation
42FXIMPLEMENT(GNEFlowEditor, MFXGroupBoxModule, FlowEditorMap, ARRAYNUMBER(FlowEditorMap))
43
44
45// ===========================================================================
46// method definitions
47// ===========================================================================
48
50 MFXGroupBoxModule(frameParent, TL("Flow attributes")),
51 myViewNet(viewNet) {
52 // create comboBox for option A
53 FXHorizontalFrame* auxiliarHorizontalFrame = new FXHorizontalFrame(getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame);
54 auto terminatelabel = new FXLabel(auxiliarHorizontalFrame, "terminate", nullptr, GUIDesignLabelAttribute);
55 terminatelabel->setTipText("Terminate attribute");
56 myTerminateComboBox = new FXComboBox(auxiliarHorizontalFrame, GUIDesignComboBoxNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignComboBoxAttribute);
57 // create comboBox for spacing
58 mySpacingFrameComboBox = new FXHorizontalFrame(getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame);
59 auto spacingAttribute = new FXLabel(mySpacingFrameComboBox, "spacing", nullptr, GUIDesignLabelAttribute);
60 spacingAttribute->setTipText("Terminate attribute");
61 mySpacingComboBox = new FXComboBox(mySpacingFrameComboBox, GUIDesignComboBoxNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignComboBoxAttribute);
62 // create textField for option A
63 myTerminateFrameTextField = new FXHorizontalFrame(getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame);
64 myTerminateLabel = new MFXLabelTooltip(myTerminateFrameTextField,
65 frameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(), "A", nullptr, GUIDesignLabelAttribute);
66 myTerminateTextField = new FXTextField(myTerminateFrameTextField, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
67 // create textField for spacing
68 mySpacingFrameTextField = new FXHorizontalFrame(getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame);
69 mySpacingLabel = new MFXLabelTooltip(mySpacingFrameTextField, frameParent->getViewNet()->getViewParent()->getGNEAppWindows()->getStaticTooltipMenu(),
70 "B", nullptr, GUIDesignLabelAttribute);
71 mySpacingTextField = new FXTextField(mySpacingFrameTextField, GUIDesignTextFieldNCol, this, MID_GNE_SET_ATTRIBUTE, GUIDesignTextField);
72 // fill terminate
73 myTerminateComboBox->appendItem(toString(SUMO_ATTR_END).c_str());
74 myTerminateComboBox->appendItem(toString(SUMO_ATTR_NUMBER).c_str());
75 myTerminateComboBox->appendItem((toString(SUMO_ATTR_END) + "-" + toString(SUMO_ATTR_NUMBER)).c_str());
76 myTerminateComboBox->setNumVisible(3);
77 // fill comboBox B
78 mySpacingComboBox->appendItem(toString(SUMO_ATTR_VEHSPERHOUR).c_str());
79 mySpacingComboBox->appendItem(toString(SUMO_ATTR_PERIOD).c_str());
80 mySpacingComboBox->appendItem(toString(GNE_ATTR_POISSON).c_str());
81 mySpacingComboBox->appendItem(toString(SUMO_ATTR_PROB).c_str());
82 mySpacingComboBox->setNumVisible(4);
83}
84
85
87
88
89void
90GNEFlowEditor::showFlowEditor(const std::vector<GNEAttributeCarrier*> editedFlows) {
91 // update flows
92 myEditedFlows = editedFlows;
93 // check number of flows
94 if (myEditedFlows.size() > 0) {
95 // update per hour attr
96 if (myEditedFlows.front()->getTagProperty().hasAttribute(SUMO_ATTR_PERSONSPERHOUR)) {
98 } else if (myEditedFlows.front()->getTagProperty().hasAttribute(SUMO_ATTR_CONTAINERSPERHOUR)) {
100 } else {
102 }
103 // clear and update comboBoxB
104 mySpacingComboBox->clearItems();
105 mySpacingComboBox->appendItem(toString(myPerHourAttr).c_str());
106 mySpacingComboBox->appendItem(toString(SUMO_ATTR_PERIOD).c_str());
107 mySpacingComboBox->appendItem(toString(GNE_ATTR_POISSON).c_str());
108 mySpacingComboBox->appendItem(toString(SUMO_ATTR_PROB).c_str());
109 mySpacingComboBox->setNumVisible(4);
110 // refresh
112 // show
113 show();
114 }
115}
116
117
118void
120 hide();
121}
122
123
124bool
126 return shown();
127}
128
129
130void
132 // show both attributes
135 // reset colors
136 myTerminateTextField->setTextColor(FXRGB(0, 0, 0));
137 myTerminateTextField->killFocus();
138 mySpacingTextField->setTextColor(FXRGB(0, 0, 0));
139 mySpacingTextField->killFocus();
140 // continue depending of number of flow
141 if (myEditedFlows.size() == 1) {
143 } else if (myEditedFlows.size() > 1) {
145 }
146 // recalc
147 recalc();
148}
149
150
151void
153 // case end-number
154 if (myTerminateLabel->getText().text() == toString(SUMO_ATTR_END)) {
155 baseObject->addDoubleAttribute(SUMO_ATTR_END, GNEAttributeCarrier::parse<double>(myTerminateTextField->getText().text()));
156 }
157 if (mySpacingLabel->getText().text() == toString(SUMO_ATTR_NUMBER)) {
158 baseObject->addIntAttribute(SUMO_ATTR_NUMBER, GNEAttributeCarrier::parse<int>(mySpacingTextField->getText().text()));
159 }
160 // other cases
161 if (myTerminateLabel->getText().text() == toString(SUMO_ATTR_NUMBER)) {
162 baseObject->addIntAttribute(SUMO_ATTR_NUMBER, GNEAttributeCarrier::parse<int>(myTerminateTextField->getText().text()));
163 }
164 if (mySpacingLabel->getText().text() == toString(myPerHourAttr)) {
165 baseObject->addDoubleAttribute(myPerHourAttr, GNEAttributeCarrier::parse<double>(mySpacingTextField->getText().text()));
166 }
167 if (mySpacingLabel->getText().text() == toString(SUMO_ATTR_PERIOD)) {
168 baseObject->addDoubleAttribute(SUMO_ATTR_PERIOD, GNEAttributeCarrier::parse<double>(mySpacingTextField->getText().text()));
169 }
170 if (mySpacingLabel->getText() == "rate") {
171 baseObject->addDoubleAttribute(GNE_ATTR_POISSON, GNEAttributeCarrier::parse<double>(mySpacingTextField->getText().text()));
172 }
173 if (mySpacingLabel->getText().text() == toString(SUMO_ATTR_PROB)) {
174 baseObject->addDoubleAttribute(SUMO_ATTR_PROB, GNEAttributeCarrier::parse<double>(mySpacingTextField->getText().text()));
175 }
176}
177
178
179bool
181 // check text fields
182 if (myTerminateFrameTextField->shown() && (myTerminateTextField->getTextColor() == FXRGB(0, 0, 0)) &&
183 mySpacingFrameTextField->shown() && (mySpacingTextField->getTextColor() == FXRGB(0, 0, 0))) {
184 return true;
185 } else {
186 return false;
187 }
188}
189
190
191long
192GNEFlowEditor::onCmdSetFlowAttribute(FXObject* obj, FXSelector, void*) {
193 // check number of flows
194 if (myEditedFlows.front()) {
195 // declare vectors for enable/disable attributes
196 std::vector<SumoXMLAttr> enableAttrs, disableAttrs;
197 // check if all spacing attributes are disabled
198 const bool spacingEnabled = myEditedFlows.front()->isAttributeEnabled(myPerHourAttr) ||
199 myEditedFlows.front()->isAttributeEnabled(SUMO_ATTR_PERIOD) ||
200 myEditedFlows.front()->isAttributeEnabled(GNE_ATTR_POISSON) ||
201 myEditedFlows.front()->isAttributeEnabled(SUMO_ATTR_PROB);
202 // get special case endNumber
203 const bool endNumber = (myTerminateComboBox->getText().text() == (toString(SUMO_ATTR_END) + "-" + toString(SUMO_ATTR_NUMBER)));
204 // get terminate attribute
205 SumoXMLAttr terminateAttribute = SUMO_ATTR_NOTHING;
206 if (myTerminateComboBox->getText().text() == toString(SUMO_ATTR_END) || endNumber) {
207 terminateAttribute = SUMO_ATTR_END;
208 } else if (myTerminateComboBox->getText().text() == toString(SUMO_ATTR_NUMBER)) {
209 terminateAttribute = SUMO_ATTR_NUMBER;
210 }
211 // get spacing attribute
212 SumoXMLAttr spacingAttribute = SUMO_ATTR_NOTHING;
213 if (endNumber) {
214 spacingAttribute = SUMO_ATTR_NUMBER;
215 } else if (mySpacingComboBox->getText().text() == toString(myPerHourAttr)) {
216 spacingAttribute = myPerHourAttr;
217 } else if (mySpacingComboBox->getText().text() == toString(SUMO_ATTR_PERIOD)) {
218 spacingAttribute = SUMO_ATTR_PERIOD;
219 } else if (mySpacingComboBox->getText().text() == toString(GNE_ATTR_POISSON)) {
220 spacingAttribute = GNE_ATTR_POISSON;
221 } else if (mySpacingComboBox->getText().text() == toString(SUMO_ATTR_PROB)) {
222 spacingAttribute = SUMO_ATTR_PROB;
223 }
224 // check if obj is a comboBox or a text field
225 if (obj == myTerminateComboBox) {
226 if (endNumber) {
227 enableAttrs.push_back(SUMO_ATTR_END);
228 enableAttrs.push_back(SUMO_ATTR_NUMBER);
229 // disable others
230 disableAttrs.push_back(myPerHourAttr);
231 disableAttrs.push_back(SUMO_ATTR_PERIOD);
232 disableAttrs.push_back(GNE_ATTR_POISSON);
233 disableAttrs.push_back(SUMO_ATTR_PROB);
234 // reset color
235 myTerminateComboBox->setTextColor(FXRGB(0, 0, 0));
236 myTerminateComboBox->killFocus();
237 } else if (terminateAttribute == SUMO_ATTR_END) {
238 enableAttrs.push_back(SUMO_ATTR_END);
239 disableAttrs.push_back(SUMO_ATTR_NUMBER);
240 // at least enable one spacing attribute
241 if (!spacingEnabled) {
242 enableAttrs.push_back(myPerHourAttr);
243 }
244 // reset color
245 myTerminateComboBox->setTextColor(FXRGB(0, 0, 0));
246 myTerminateComboBox->killFocus();
247 } else if (terminateAttribute == SUMO_ATTR_NUMBER) {
248 disableAttrs.push_back(SUMO_ATTR_END);
249 enableAttrs.push_back(SUMO_ATTR_NUMBER);
250 // at least enable one spacing attribute
251 if (!spacingEnabled) {
252 enableAttrs.push_back(myPerHourAttr);
253 }
254 // reset color
255 myTerminateComboBox->setTextColor(FXRGB(0, 0, 0));
256 myTerminateComboBox->killFocus();
257 } else {
258 // disable both
259 disableAttrs.push_back(SUMO_ATTR_END);
260 disableAttrs.push_back(SUMO_ATTR_NUMBER);
261 // set invalid color
262 myTerminateComboBox->setTextColor(FXRGB(255, 0, 0));
263 }
264 } else if (obj == mySpacingComboBox) {
265 if (spacingAttribute == myPerHourAttr) {
266 enableAttrs.push_back(myPerHourAttr);
267 disableAttrs.push_back(SUMO_ATTR_PERIOD);
268 disableAttrs.push_back(GNE_ATTR_POISSON);
269 disableAttrs.push_back(SUMO_ATTR_PROB);
270 // reset color
271 mySpacingComboBox->setTextColor(FXRGB(0, 0, 0));
272 mySpacingComboBox->killFocus();
273 } else if (spacingAttribute == SUMO_ATTR_PERIOD) {
274 disableAttrs.push_back(myPerHourAttr);
275 enableAttrs.push_back(SUMO_ATTR_PERIOD);
276 disableAttrs.push_back(GNE_ATTR_POISSON);
277 disableAttrs.push_back(SUMO_ATTR_PROB);
278 // reset color
279 mySpacingComboBox->setTextColor(FXRGB(0, 0, 0));
280 mySpacingComboBox->killFocus();
281 } else if (spacingAttribute == GNE_ATTR_POISSON) {
282 disableAttrs.push_back(myPerHourAttr);
283 disableAttrs.push_back(SUMO_ATTR_PERIOD);
284 enableAttrs.push_back(GNE_ATTR_POISSON);
285 disableAttrs.push_back(SUMO_ATTR_PROB);
286 // reset color
287 mySpacingComboBox->setTextColor(FXRGB(0, 0, 0));
288 mySpacingComboBox->killFocus();
289 } else if (spacingAttribute == SUMO_ATTR_PROB) {
290 disableAttrs.push_back(myPerHourAttr);
291 disableAttrs.push_back(SUMO_ATTR_PERIOD);
292 disableAttrs.push_back(GNE_ATTR_POISSON);
293 enableAttrs.push_back(SUMO_ATTR_PROB);
294 // reset color
295 mySpacingComboBox->setTextColor(FXRGB(0, 0, 0));
296 mySpacingComboBox->killFocus();
297 } else {
298 // disable all
299 disableAttrs.push_back(myPerHourAttr);
300 disableAttrs.push_back(SUMO_ATTR_PERIOD);
301 disableAttrs.push_back(GNE_ATTR_POISSON);
302 disableAttrs.push_back(SUMO_ATTR_PROB);
303 // set invalid color
304 mySpacingComboBox->setTextColor(FXRGB(255, 0, 0));
305 }
306 } else if ((obj == myTerminateTextField) && (terminateAttribute != SUMO_ATTR_NOTHING)) {
307 if (myEditedFlows.front()->isValid(terminateAttribute, myTerminateTextField->getText().text())) {
308 // continue depending of flow
309 if (myEditedFlows.front()->isTemplate()) {
310 // change attribute directly
311 myEditedFlows.front()->setAttribute(terminateAttribute, myTerminateTextField->getText().text());
312 } else if (myEditedFlows.size() == 1) {
313 // change using undoList
314 myEditedFlows.front()->setAttribute(terminateAttribute, myTerminateTextField->getText().text(), myViewNet->getUndoList());
315 } else {
316 // change all flows using undoList
317 myViewNet->getUndoList()->begin(myEditedFlows.front()->getTagProperty().getGUIIcon(), "change multiple flow attributes");
318 for (const auto& flow : myEditedFlows) {
319 flow->setAttribute(terminateAttribute, myTerminateTextField->getText().text(), myViewNet->getUndoList());
320 }
322 }
323 // reset color
324 myTerminateTextField->setTextColor(FXRGB(0, 0, 0));
325 myTerminateTextField->killFocus();
326 } else {
327 // set invalid color
328 myTerminateTextField->setTextColor(FXRGB(255, 0, 0));
329 // stop
330 return 1;
331 }
332 } else if ((obj == mySpacingTextField) && (spacingAttribute != SUMO_ATTR_NOTHING)) {
333 if (myEditedFlows.front()->isValid(spacingAttribute, mySpacingTextField->getText().text())) {
334 // continue depending of flow
335 if (myEditedFlows.front()->isTemplate()) {
336 // change attribute directly
337 myEditedFlows.front()->setAttribute(spacingAttribute, mySpacingTextField->getText().text());
338 } else if (myEditedFlows.size() == 1) {
339 // change using undoList
340 myEditedFlows.front()->setAttribute(spacingAttribute, mySpacingTextField->getText().text(), myViewNet->getUndoList());
341 } else {
342 // change all flows using undoList
343 myViewNet->getUndoList()->begin(myEditedFlows.front()->getTagProperty().getGUIIcon(), "change multiple flow attributes");
344 for (const auto& flow : myEditedFlows) {
345 flow->setAttribute(spacingAttribute, mySpacingTextField->getText().text(), myViewNet->getUndoList());
346 }
348 }
349 // reset color
350 mySpacingTextField->setTextColor(FXRGB(0, 0, 0));
351 mySpacingTextField->killFocus();
352 } else {
353 // set invalid color
354 mySpacingTextField->setTextColor(FXRGB(255, 0, 0));
355 // stop
356 return 1;
357 }
358 }
359 // enable and disable attributes
360 for (const auto& attr : enableAttrs) {
361 if (myEditedFlows.front()->isTemplate()) {
362 // enable directly
363 myEditedFlows.front()->toggleAttribute(attr, true);
364 } else if (myEditedFlows.size() == 1) {
365 // enable using undoList
366 myEditedFlows.front()->enableAttribute(attr, myViewNet->getUndoList());
367 } else {
368 // enable in all flow using undoList
369 myViewNet->getUndoList()->begin(myEditedFlows.front()->getTagProperty().getGUIIcon(), "enable multiple flow attributes");
370 for (const auto& flow : myEditedFlows) {
371 flow->enableAttribute(attr, myViewNet->getUndoList());
372 }
374 }
375 }
376 for (const auto& attr : disableAttrs) {
377 if (myEditedFlows.front()->isTemplate()) {
378 // disable directly
379 myEditedFlows.front()->toggleAttribute(attr, false);
380 } else if (myEditedFlows.size() == 1) {
381 // disable using undoList
382 myEditedFlows.front()->disableAttribute(attr, myViewNet->getUndoList());
383 } else {
384 // disable in all flow using undoList
385 myViewNet->getUndoList()->begin(myEditedFlows.front()->getTagProperty().getGUIIcon(), "disable multiple flow attributes");
386 for (const auto& flow : myEditedFlows) {
387 flow->disableAttribute(attr, myViewNet->getUndoList());
388 }
390 }
391 }
392 // refresh flow editor
394 }
395 return 1;
396}
397
398
399void
401 // get flow (only for code legibly)
402 const auto flow = myEditedFlows.front();
403 // continue depending of combinations
404 if (flow->isAttributeEnabled(SUMO_ATTR_END) && flow->isAttributeEnabled(SUMO_ATTR_NUMBER)) {
405 // set first comboBox
406 myTerminateComboBox->setCurrentItem(2),
407 // hide second comboBox
409 // set label
410 myTerminateLabel->setText(toString(SUMO_ATTR_END).c_str());
411 myTerminateLabel->setTipText(flow->getTagProperty().getAttributeProperties(SUMO_ATTR_END).getDefinition().c_str());
412 mySpacingLabel->setText(toString(SUMO_ATTR_NUMBER).c_str());
413 mySpacingLabel->setTipText(flow->getTagProperty().getAttributeProperties(SUMO_ATTR_NUMBER).getDefinition().c_str());
414 // set text fields
417 } else {
418 // show second comboBox
420 // set first attribute
421 if (myTerminateComboBox->getTextColor() == FXRGB(255, 0, 0)) {
422 // invalid combination, disable text field
424 } else if (flow->isAttributeEnabled(SUMO_ATTR_END)) {
425 // set first comboBox
426 myTerminateComboBox->setCurrentItem(0);
427 // set label
428 myTerminateLabel->setText(toString(SUMO_ATTR_END).c_str());
429 // set definition
430 myTerminateLabel->setTipText(flow->getTagProperty().getAttributeProperties(SUMO_ATTR_END).getDefinition().c_str());
431 // set text fields
433 } else if (flow->isAttributeEnabled(SUMO_ATTR_NUMBER)) {
434 // set first comboBox
435 myTerminateComboBox->setCurrentItem(1);
436 // set label
437 myTerminateLabel->setText(toString(SUMO_ATTR_NUMBER).c_str());
438 // set definition
439 myTerminateLabel->setTipText(flow->getTagProperty().getAttributeProperties(SUMO_ATTR_NUMBER).getDefinition().c_str());
440 // set text fields
442 }
443 // set second attribute
444 if (mySpacingComboBox->getTextColor() == FXRGB(255, 0, 0)) {
445 // invalid combination, disable text field
447 } else if (flow->isAttributeEnabled(myPerHourAttr)) {
448 // set first comboBox
449 mySpacingComboBox->setCurrentItem(0),
450 // set label
451 mySpacingLabel->setText(toString(myPerHourAttr).c_str());
452 // set tip text
453 mySpacingLabel->setTipText(flow->getTagProperty().getAttributeProperties(myPerHourAttr).getDefinition().c_str());
454 // set text fields
456 } else if (flow->isAttributeEnabled(SUMO_ATTR_PERIOD)) {
457 // set first comboBox
458 mySpacingComboBox->setCurrentItem(1);
459 // set label
460 mySpacingLabel->setText(toString(SUMO_ATTR_PERIOD).c_str());
461 // set tip text
462 mySpacingLabel->setTipText(flow->getTagProperty().getAttributeProperties(SUMO_ATTR_PERIOD).getDefinition().c_str());
463 // set text fields
465 } else if (flow->isAttributeEnabled(GNE_ATTR_POISSON)) {
466 // set first comboBox
467 mySpacingComboBox->setCurrentItem(2);
468 // set label
469 mySpacingLabel->setText(TL("rate"));
470 // set definition
471 mySpacingLabel->setTipText(flow->getTagProperty().getAttributeProperties(GNE_ATTR_POISSON).getDefinition().c_str());
472 // set text fields
474 } else if (flow->isAttributeEnabled(SUMO_ATTR_PROB)) {
475 // set first comboBox
476 mySpacingComboBox->setCurrentItem(3);
477 // set label
478 mySpacingLabel->setText(toString(SUMO_ATTR_PROB).c_str());
479 // set tip text
480 mySpacingLabel->setTipText(flow->getTagProperty().getAttributeProperties(SUMO_ATTR_PROB).getDefinition().c_str());
481 // set text fields
483 }
484 }
485}
486
487
488void
490 // get first flow (only for code legibly)
491 const auto editedFlow = myEditedFlows.front();
492 // get values of first flow
493 const bool end = editedFlow->isAttributeEnabled(SUMO_ATTR_END);
494 const bool number = editedFlow->isAttributeEnabled(SUMO_ATTR_NUMBER);
495 const bool perhour = editedFlow->isAttributeEnabled(myPerHourAttr);
496 const bool period = editedFlow->isAttributeEnabled(SUMO_ATTR_PERIOD);
497 const bool poisson = editedFlow->isAttributeEnabled(GNE_ATTR_POISSON);
498 const bool probability = editedFlow->isAttributeEnabled(SUMO_ATTR_PROB);
499 // we need to check if attributes are defined differents in flows
500 std::vector<std::string> terminateDifferent;
501 std::vector<std::string> spacingDifferent;
502 // iterate over all flows
503 for (const auto& flow : myEditedFlows) {
504 if (flow->isAttributeEnabled(SUMO_ATTR_END) != end) {
505 terminateDifferent.push_back(toString(SUMO_ATTR_END));
506 }
507 if (flow->isAttributeEnabled(SUMO_ATTR_NUMBER) != number) {
508 terminateDifferent.push_back(toString(SUMO_ATTR_NUMBER));
509 }
510 if (flow->isAttributeEnabled(myPerHourAttr) != perhour) {
511 spacingDifferent.push_back(toString(myPerHourAttr));
512 }
513 if (flow->isAttributeEnabled(SUMO_ATTR_PERIOD) != period) {
514 spacingDifferent.push_back(toString(SUMO_ATTR_PERIOD));
515 }
516 if (flow->isAttributeEnabled(GNE_ATTR_POISSON) != poisson) {
517 spacingDifferent.push_back(toString(GNE_ATTR_POISSON));
518 }
519 if (flow->isAttributeEnabled(SUMO_ATTR_PROB) != probability) {
520 spacingDifferent.push_back(toString(SUMO_ATTR_PROB));
521 }
522 }
523 // special case for end and number
524 if (end && number && terminateDifferent.empty() && spacingDifferent.empty()) {
525 // set first comboBox
526 myTerminateComboBox->setCurrentItem(2),
527 // hide second comboBox
529 // set label
530 myTerminateLabel->setText(toString(SUMO_ATTR_END).c_str());
531 mySpacingLabel->setText(toString(SUMO_ATTR_NUMBER).c_str());
532 // set text fields
535 } else {
536 // show second comboBox
538 // check terminateDifferent
539 if (terminateDifferent.size() > 0) {
540 myTerminateComboBox->setText(("different: " + terminateDifferent.front() + " " + terminateDifferent.back()).c_str());
541 // hide textField
543 } else {
544 // show textField
546 // set first attribute
547 if (myTerminateComboBox->getTextColor() == FXRGB(255, 0, 0)) {
548 // invalid combination, disable text field
550 } else if (end) {
551 // set first comboBox
552 myTerminateComboBox->setCurrentItem(0),
553 // set label
554 myTerminateLabel->setText(toString(SUMO_ATTR_END).c_str());
555 // set text fields
557 } else if (number) {
558 // set first comboBox
559 myTerminateComboBox->setCurrentItem(1),
560 // set label
561 myTerminateLabel->setText(toString(SUMO_ATTR_NUMBER).c_str());
562 // set text fields
564 }
565 }
566 // check terminateDifferent
567 if (spacingDifferent.size() > 0) {
568 mySpacingComboBox->setText(("different: " + spacingDifferent.front() + " " + spacingDifferent.back()).c_str());
569 // hide textField
571 } else {
572 // show textField
574 // set second attribute
575 if (mySpacingComboBox->getTextColor() == FXRGB(255, 0, 0)) {
576 // invalid combination, disable text field
578 } else if (perhour) {
579 // set first comboBox
580 mySpacingComboBox->setCurrentItem(0),
581 // set label
582 mySpacingLabel->setText(toString(myPerHourAttr).c_str());
583 // set text fields
585 } else if (period) {
586 // set first comboBox
587 mySpacingComboBox->setCurrentItem(1),
588 // set label
589 mySpacingLabel->setText(toString(SUMO_ATTR_PERIOD).c_str());
590 // set text fields
592 } else if (poisson) {
593 // set first comboBox
594 mySpacingComboBox->setCurrentItem(2),
595 // set label
596 mySpacingLabel->setText(TL("rate"));
597 // set text fields
599 } else if (probability) {
600 // set first comboBox
601 mySpacingComboBox->setCurrentItem(3),
602 // set label
603 mySpacingLabel->setText(toString(SUMO_ATTR_PROB).c_str());
604 // set text fields
606 }
607 }
608 }
609}
610
611
612const std::string
614 if (myEditedFlows.size() == 1) {
615 return myEditedFlows.front()->getAttribute(attr);
616 } else {
617 std::string solution;
618 std::set<std::string> values;
619 // extract all values (avoiding duplicated)
620 for (const auto& flow : myEditedFlows) {
621 values.insert(flow->getAttribute(attr));
622 }
623 // insert value and space
624 for (const auto& value : values) {
625 solution.append(value + " ");
626 }
627 // remove last space
628 if (solution.size() > 0) {
629 solution.pop_back();
630 }
631 return solution;
632 }
633}
634
635
636/****************************************************************************/
FXDEFMAP(GNEFlowEditor) FlowEditorMap[]
@ MID_GNE_SET_ATTRIBUTE
attribute edited
Definition: GUIAppEnum.h:870
#define GUIDesignComboBoxAttribute
Combo box static (cannot be edited) extended over the matrix column.
Definition: GUIDesigns.h:315
#define GUIDesignComboBoxNCol
number of column of every combo box
Definition: GUIDesigns.h:321
#define GUIDesignTextField
Definition: GUIDesigns.h:48
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition: GUIDesigns.h:397
#define GUIDesignLabelAttribute
label extended over the matrix column with thick frame
Definition: GUIDesigns.h:241
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition: GUIDesigns.h:69
#define TL(string)
Definition: MsgHandler.h:282
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
@ SUMO_ATTR_NUMBER
@ SUMO_ATTR_VEHSPERHOUR
@ GNE_ATTR_POISSON
poisson definition (used in flow)
@ SUMO_ATTR_CONTAINERSPERHOUR
@ SUMO_ATTR_PERIOD
@ SUMO_ATTR_END
weights: time range end
@ SUMO_ATTR_PROB
@ SUMO_ATTR_NOTHING
invalid attribute
@ SUMO_ATTR_PERSONSPERHOUR
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
void addIntAttribute(const SumoXMLAttr attr, const int value)
add int attribute into current SumoBaseObject node
void addDoubleAttribute(const SumoXMLAttr attr, const double value)
add double attribute into current SumoBaseObject node
void getFlowAttributes(CommonXMLStructure::SumoBaseObject *baseObject)
get flow attributes
long onCmdSetFlowAttribute(FXObject *, FXSelector, void *)
void refreshSingleFlow()
refresh single flow
MFXLabelTooltip * mySpacingLabel
Label for spacing.
FXTextField * myTerminateTextField
textField for terminate attribute
Definition: GNEFlowEditor.h:99
FXComboBox * mySpacingComboBox
ComboBox for spacing comboBox (perHour, period, probability)
SumoXMLAttr myPerHourAttr
per hours attr (vehicles/person/container)
GNEViewNet * myViewNet
pointer to viewNet
Definition: GNEFlowEditor.h:87
const std::string getFlowAttribute(SumoXMLAttr attr)
get flow attribute (of the current edited flows)
void refreshFlowEditor()
refresh GNEFlowEditor
FXHorizontalFrame * mySpacingFrameTextField
horizontal frame for spacing textField
MFXLabelTooltip * myTerminateLabel
Label for terminate definition.
Definition: GNEFlowEditor.h:96
~GNEFlowEditor()
destructor
void hideFlowEditor()
hide group box
FXTextField * mySpacingTextField
textField for spacing attribute
std::vector< GNEAttributeCarrier * > myEditedFlows
edited flows
void showFlowEditor(const std::vector< GNEAttributeCarrier * > editedFlows)
show GNEFlowEditor modul
void refreshMultipleFlows()
refresh multiple flows
bool shownFlowEditor() const
shown GNEFlowEditor modul
FXHorizontalFrame * mySpacingFrameComboBox
horizontal frame for terminate options
FXComboBox * myTerminateComboBox
ComboBox for terminate options (end, number, end/number)
Definition: GNEFlowEditor.h:90
FXHorizontalFrame * myTerminateFrameTextField
horizontal frame for terminate definition
Definition: GNEFlowEditor.h:93
bool areFlowValuesValid() const
check if parameters of attributes are valid
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...
GNEUndoList * getUndoList() const
get the undoList object
MFXGroupBoxModule (based on FXGroupBox)