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