Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GNECreateEdgeFrame.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-2024 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/****************************************************************************/
18// The Widget for create edges (and junctions)
19/****************************************************************************/
20#include <config.h>
21
23#include <netedit/GNENet.h>
24#include <netedit/GNEUndoList.h>
25#include <netedit/GNEViewNet.h>
37
38
39#include "GNECreateEdgeFrame.h"
40
41// ===========================================================================
42// FOX callback mapping
43// ===========================================================================
44
53
59
60// Object implementation
61FXIMPLEMENT(GNECreateEdgeFrame::EdgeTypeSelector, MFXGroupBoxModule, EdgeTypeSelectorMap, ARRAYNUMBER(EdgeTypeSelectorMap))
62FXIMPLEMENT(GNECreateEdgeFrame::LaneTypeSelector, MFXGroupBoxModule, LaneTypeSelectorMap, ARRAYNUMBER(LaneTypeSelectorMap))
63
64
65// ===========================================================================
66// method definitions
67// ===========================================================================
68
69// ---------------------------------------------------------------------------
70// GNECreateEdgeFrame::EdgeTypeSelector - methods
71// ---------------------------------------------------------------------------
72
74 MFXGroupBoxModule(createEdgeFrameParent, TL("Template selector")),
75 myCreateEdgeFrameParent(createEdgeFrameParent),
76 myDefaultEdgeType(new GNEEdgeType(createEdgeFrameParent)),
77 myCurrentIndex(0) {
78 // default edge radio button
79 myCreateDefaultEdgeType = new FXRadioButton(getCollapsableFrame(), TL("Create default edge"),
81 // default short radio button
82 myCreateDefaultShortEdgeType = new FXRadioButton(getCollapsableFrame(), TL("Create default edge short"),
84 // checkboxes
85 myNoPedestriansCheckButton = new FXCheckButton(getCollapsableFrame(), TL("Disallow for pedestrians"),
87 myAddSidewalkCheckButton = new FXCheckButton(getCollapsableFrame(), TL("Add sidewalk"),
89 myAddBikelaneCheckButton = new FXCheckButton(getCollapsableFrame(), TL("Add bikelane"),
91 // use custom edge radio button
92 myCreateCustomEdgeType = new FXRadioButton(getCollapsableFrame(), TL("Use edgeType/template"),
94 // edge types combo box
95 myEdgeTypesComboBox = new MFXComboBoxIcon(getCollapsableFrame(), GUIDesignComboBoxNCol, true, GUIDesignComboBoxVisibleItemsMedium,
97 // create horizontal frame
98 FXHorizontalFrame* horizontalFrameButtons = new FXHorizontalFrame(getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame);
99 // create new edge type button
100 myAddEdgeTypeButton = GUIDesigns::buildFXButton(horizontalFrameButtons, TL("Add"), "", TL("Add edge type"), GUIIconSubSys::getIcon(GUIIcon::ADD),
102 // create delete edge type button
103 myDeleteEdgeTypeButton = GUIDesigns::buildFXButton(horizontalFrameButtons, TL("Delete"), "", TL("Delete edge type"), GUIIconSubSys::getIcon(GUIIcon::REMOVE),
105 // create delete edge type button
106 myCreateFromTemplate = GUIDesigns::buildFXButton(getCollapsableFrame(), TL("Create from template"), "", TL("Create edgeType from template"), GUIIconSubSys::getIcon(GUIIcon::EDGE),
108 // by default, create custom edge
109 myCreateDefaultEdgeType->setCheck(TRUE);
110 // check if enable disable pedestrians
111 for (const auto& junction : createEdgeFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getJunctions()) {
112 if (junction.second->getNBNode()->getCrossings().size() > 0) {
113 enableCheckBoxDisablePedestrians();
114 }
115 }
116}
117
118
122
123
124void
126 // get template editor
127 const GNEInspectorFrame::TemplateEditor* templateEditor = myCreateEdgeFrameParent->getViewNet()->getViewParent()->getInspectorFrame()->getTemplateEditor();
128 // get current item
129 const int index = myEdgeTypesComboBox->getCurrentItem();
130 // fill combo box
131 fillComboBox();
132 // continue depending of radio buttons
133 if (myCreateDefaultEdgeType->getCheck() || myCreateDefaultShortEdgeType->getCheck()) {
134 // enable check boxes
135 myAddSidewalkCheckButton->enable();
136 myAddBikelaneCheckButton->enable();
137 myNoPedestriansCheckButton->enable();
138 // disable create from template
139 myCreateFromTemplate->disable();
140 // disable comboBox
141 myEdgeTypesComboBox->disable();
142 // disable buttons
143 myAddEdgeTypeButton->disable();
144 myDeleteEdgeTypeButton->disable();
145 // show default edgeType attributes
146 myCreateEdgeFrameParent->myEdgeTypeAttributes->showAttributesCreatorModule(myDefaultEdgeType, {SUMO_ATTR_ID});
147 // show lane attributes
148 myCreateEdgeFrameParent->myLaneTypeSelector->showLaneTypeSelector();
149 } else if (myCreateCustomEdgeType->getCheck()) {
150 // disable check boxes
151 myAddSidewalkCheckButton->disable();
152 myAddBikelaneCheckButton->disable();
153 myNoPedestriansCheckButton->disable();
154 // enable buttons
155 myAddEdgeTypeButton->enable();
156 myDeleteEdgeTypeButton->enable();
157 // check conditions
158 if (myEdgeTypesComboBox->getNumItems() == 0) {
159 // disable comboBox and edgeType
160 myEdgeTypesComboBox->disable();
161 myDeleteEdgeTypeButton->disable();
162 // hide attributes creators
163 myCreateEdgeFrameParent->myEdgeTypeAttributes->hideAttributesCreatorModule();
164 myCreateEdgeFrameParent->myLaneTypeSelector->hideLaneTypeSelector();
165 } else if (templateEditor->getEdgeTemplate() && (index == 0)) {
166 // enable create from template
167 myCreateFromTemplate->enable();
168 // enable comboBox
169 myEdgeTypesComboBox->enable();
170 // disable delete edge type button (because templates cannot be deleted)
171 myDeleteEdgeTypeButton->disable();
172 // show edgeType attributes and disable
173 myCreateEdgeFrameParent->myEdgeTypeAttributes->showAttributesCreatorModule(templateEditor->getEdgeTemplate(), {SUMO_ATTR_ID});
174 myCreateEdgeFrameParent->myEdgeTypeAttributes->disableAttributesCreator();
175 // show lane attributes (will be automatic disabled)
176 myCreateEdgeFrameParent->myLaneTypeSelector->showLaneTypeSelector();
177 } else {
178 // disable create from template
179 myCreateFromTemplate->disable();
180 // enable comboBox
181 myEdgeTypesComboBox->enable();
182 // get edgeType
183 myEdgeTypeSelected = myCreateEdgeFrameParent->getViewNet()->getNet()->getAttributeCarriers()->retrieveEdgeType(myEdgeTypesComboBox->getText().text(), false);
184 // check if exist
185 if (myEdgeTypeSelected) {
186 // show edgeType attributes
187 myCreateEdgeFrameParent->myEdgeTypeAttributes->showAttributesCreatorModule(myEdgeTypeSelected, {});
188 // show lane attributes
189 myCreateEdgeFrameParent->myLaneTypeSelector->showLaneTypeSelector();
190 } else {
191 // hide edgeType attributes
192 myCreateEdgeFrameParent->myEdgeTypeAttributes->hideAttributesCreatorModule();
193 // hide lane attributes
194 myCreateEdgeFrameParent->myLaneTypeSelector->hideLaneTypeSelector();
195 // set comboBox text
196 myEdgeTypesComboBox->setTextColor(FXRGB(255, 0, 0));
197 }
198 }
199 }
200 // recalc
201 recalc();
202}
203
204
205void
206GNECreateEdgeFrame::EdgeTypeSelector::updateIDinComboBox(const std::string& oldID, const std::string& newID) {
207 for (int i = 0; i < myEdgeTypesComboBox->getNumItems(); i++) {
208 if (myEdgeTypesComboBox->getItemText(i) == oldID) {
209 myEdgeTypesComboBox->updateIconItem(i, newID.c_str());
210 }
211 }
212}
213
214
215bool
217 return (myCreateDefaultEdgeType->getCheck() == TRUE);
218}
219
220
221bool
223 return (myCreateDefaultShortEdgeType->getCheck() == TRUE);
224}
225
226
227bool
229 if (myCreateEdgeFrameParent->getViewNet()->getViewParent()->getInspectorFrame()->getTemplateEditor()->getEdgeTemplate()) {
230 if ((myCreateCustomEdgeType->getCheck() == TRUE) && (myEdgeTypesComboBox->getCurrentItem() == 0)) {
231 return true;
232 } else {
233 return false;
234 }
235 } else {
236 return false;
237 }
238}
239
240
241void
243 myNoPedestriansCheckButton->setCheck(TRUE);
244}
245
246
249 return myDefaultEdgeType;
250}
251
252
255 if ((myCreateDefaultEdgeType->getCheck() == TRUE) || (myCreateDefaultShortEdgeType->getCheck() == TRUE)) {
256 return myDefaultEdgeType;
257 } else {
258 return myEdgeTypeSelected;
259 }
260}
261
262
263bool
265 return (myNoPedestriansCheckButton->getCheck() == TRUE);
266}
267
268
269bool
271 return (myAddSidewalkCheckButton->getCheck() == TRUE);
272}
273
274
275bool
277 return (myAddBikelaneCheckButton->getCheck() == TRUE);
278}
279
280
281void
283 myEdgeTypeSelected = nullptr;
284 myCurrentIndex--;
285 if (myCurrentIndex < 0) {
286 myCurrentIndex = 0;
287 }
288}
289
290
291void
293 for (int i = 0; i < myEdgeTypesComboBox->getNumItems(); i++) {
294 if (myEdgeTypesComboBox->getItemText(i) == edgeType->getID()) {
295 // set current item and index
296 myEdgeTypesComboBox->setCurrentItem(i);
297 myCurrentIndex = i;
298 // set buttons
299 myCreateDefaultEdgeType->setCheck(FALSE);
300 myCreateDefaultShortEdgeType->setCheck(FALSE);
301 myCreateCustomEdgeType->setCheck(TRUE);
302 // refresh
303 refreshEdgeTypeSelector();
304 }
305 }
306}
307
308
309void
311 myCreateDefaultEdgeType->setCheck(FALSE);
312 myCreateDefaultShortEdgeType->setCheck(FALSE);
313 myCreateCustomEdgeType->setCheck(TRUE);
314 refreshEdgeTypeSelector();
315}
316
317
318long
320 // update radio buttons
321 if (obj == myCreateDefaultEdgeType) {
322 myCreateDefaultEdgeType->setCheck(TRUE);
323 myCreateDefaultShortEdgeType->setCheck(FALSE);
324 myCreateCustomEdgeType->setCheck(FALSE);
325 } else if (obj == myCreateDefaultShortEdgeType) {
326 myCreateDefaultEdgeType->setCheck(FALSE);
327 myCreateDefaultShortEdgeType->setCheck(TRUE);
328 myCreateCustomEdgeType->setCheck(FALSE);
329 } else {
330 myCreateDefaultEdgeType->setCheck(FALSE);
331 myCreateDefaultShortEdgeType->setCheck(FALSE);
332 myCreateCustomEdgeType->setCheck(TRUE);
333 }
334 // refresh template selector
335 refreshEdgeTypeSelector();
336 return 0;
337}
338
339
340long
342 // create new edge type
343 GNEEdgeType* edgeType = new GNEEdgeType(myCreateEdgeFrameParent->getViewNet()->getNet());
344 // add it using undoList
345 myCreateEdgeFrameParent->getViewNet()->getUndoList()->begin(edgeType, TL("create new edge type"));
346 myCreateEdgeFrameParent->getViewNet()->getUndoList()->add(new GNEChange_EdgeType(edgeType, true), true);
347 myCreateEdgeFrameParent->getViewNet()->getUndoList()->end();
348 // update myEdgeTypeSelected
349 myEdgeTypeSelected = edgeType;
350 // select last item
351 myCurrentIndex = (myEdgeTypesComboBox->getNumItems() - 1);
352 // refresh EdgeTypeSelector
353 refreshEdgeTypeSelector();
354 return 0;
355}
356
357
358long
360 // first check if we have to reset myEdgeTypeSelected
361 if (myEdgeTypeSelected && (myEdgeTypeSelected->getID() == myEdgeTypesComboBox->getText().text())) {
362 myEdgeTypeSelected = nullptr;
363 }
364 // get edgeType to remove
365 GNEEdgeType* edgeType = myCreateEdgeFrameParent->getViewNet()->getNet()->getAttributeCarriers()->retrieveEdgeType(myEdgeTypesComboBox->getText().text());
366 // remove it using undoList
367 myCreateEdgeFrameParent->getViewNet()->getUndoList()->begin(edgeType, TL("delete edge type"));
368 myCreateEdgeFrameParent->getViewNet()->getUndoList()->add(new GNEChange_EdgeType(edgeType, false), true);
369 myCreateEdgeFrameParent->getViewNet()->getUndoList()->end();
370 // refresh EdgeTypeSelector
371 refreshEdgeTypeSelector();
372 return 0;
373}
374
375
376long
378 // update current index
379 myCurrentIndex = myEdgeTypesComboBox->getCurrentItem();
380 // refresh edgeType selector
381 refreshEdgeTypeSelector();
382 return 0;
383}
384
385
386long
388 if (myCreateEdgeFrameParent->getViewNet()->getViewParent()->getInspectorFrame()->getTemplateEditor()->getEdgeTemplate()) {
389 // create new edge type
390 GNEEdgeType* edgeType = new GNEEdgeType(myCreateEdgeFrameParent->getViewNet()->getNet());
391 // copy all template values
392 edgeType->copyTemplate(myCreateEdgeFrameParent->getViewNet()->getViewParent()->getInspectorFrame()->getTemplateEditor()->getEdgeTemplate());
393 // add it using undoList
394 myCreateEdgeFrameParent->getViewNet()->getUndoList()->begin(edgeType, TL("create new edge type"));
395 myCreateEdgeFrameParent->getViewNet()->getUndoList()->add(new GNEChange_EdgeType(edgeType, true), true);
396 myCreateEdgeFrameParent->getViewNet()->getUndoList()->end();
397 // update myEdgeTypeSelected
398 myEdgeTypeSelected = edgeType;
399 // select last item
400 myCurrentIndex = (myEdgeTypesComboBox->getNumItems() - 1);
401 // refresh EdgeTypeSelector
402 refreshEdgeTypeSelector();
403 }
404 return 0;
405}
406
407
408long
410 if (myAddSidewalkCheckButton->getCheck() == TRUE) {
411 myNoPedestriansCheckButton->setCheck(TRUE);
412 myNoPedestriansCheckButton->disable();
413 } else {
414 myNoPedestriansCheckButton->enable();
415 }
416 // show default edgeType attributes again (for refresh sidewalk and bike widths)
417 myCreateEdgeFrameParent->myEdgeTypeAttributes->showAttributesCreatorModule(myDefaultEdgeType, {SUMO_ATTR_ID});
418 return 1;
419}
420
421
422void
424 // get template editor
425 const GNEInspectorFrame::TemplateEditor* templateEditor = myCreateEdgeFrameParent->getViewNet()->getViewParent()->getInspectorFrame()->getTemplateEditor();
426 // get edge types
427 const auto& edgeTypes = myCreateEdgeFrameParent->getViewNet()->getNet()->getAttributeCarriers()->getEdgeTypes();
428 // clear edge types
429 myEdgeTypesComboBox->clearItems();
430 // set comboBox text color
431 myEdgeTypesComboBox->setTextColor(FXRGB(0, 0, 0));
432 // add template
433 if (templateEditor->getEdgeTemplate()) {
434 myEdgeTypesComboBox->appendIconItem((TL("template: ") + templateEditor->getEdgeTemplate()->getID()).c_str(), nullptr);
435 }
436 if (edgeTypes.size() > 0) {
437 // add edge types
438 for (const auto& edgeType : edgeTypes) {
439 myEdgeTypesComboBox->appendIconItem(edgeType.second->getID().c_str(), edgeType.second->getACIcon());
440 }
441 // set current item
442 if ((myCurrentIndex < 0) || (myCurrentIndex >= myEdgeTypesComboBox->getNumItems())) {
443 myCurrentIndex = myEdgeTypesComboBox->getNumItems() - 1;
444 }
445 myEdgeTypesComboBox->setCurrentItem(myCurrentIndex);
446 myEdgeTypesComboBox->enable();
447 } else {
448 myEdgeTypesComboBox->disable();
449 }
450}
451
452// ---------------------------------------------------------------------------
453// GNECreateEdgeFrame::LaneTypeSelector - methods
454// ---------------------------------------------------------------------------
455
457 MFXGroupBoxModule(createEdgeFrameParent, TL("LaneType selector")),
458 myCreateEdgeFrameParent(createEdgeFrameParent),
459 myLaneIndex(0) {
460 // lane types combo box
463 // create horizontal frame
464 FXHorizontalFrame* horizontalFrameButtons = new FXHorizontalFrame(getCollapsableFrame(), GUIDesignAuxiliarHorizontalFrame);
465 // create new lane type button
466 myAddLaneTypeButton = GUIDesigns::buildFXButton(horizontalFrameButtons, TL("Add"), "", TL("Add lane type"), GUIIconSubSys::getIcon(GUIIcon::ADD),
468 // create delete lane type button
469 myDeleteLaneTypeButton = GUIDesigns::buildFXButton(horizontalFrameButtons, TL("Delete"), "", TL("Delete lane type"), GUIIconSubSys::getIcon(GUIIcon::REMOVE),
471}
472
473
476
477
478void
480 // start at first lane
481 myLaneIndex = 0;
482 // refresh laneTypeSelector
483 refreshLaneTypeSelector();
484 // show
485 show();
486}
487
488
489void
491 // hide attributes creator module
492 myCreateEdgeFrameParent->myLaneTypeAttributes->hideAttributesCreatorModule();
493 // hide
494 hide();
495}
496
497
498void
500 // clear lane types
501 myLaneTypesComboBox->clearItems();
502 // first check if use template
503 if (myCreateEdgeFrameParent->myEdgeTypeSelector->useEdgeTemplate()) {
504 const GNEEdgeTemplate* edgeTemplate = myCreateEdgeFrameParent->getViewNet()->getViewParent()->getInspectorFrame()->getTemplateEditor()->getEdgeTemplate();
505 // fill comboBox
506 for (const auto& laneTemplate : edgeTemplate->getLaneTemplates()) {
507 myLaneTypesComboBox->appendIconItem(laneTemplate->getAttribute(SUMO_ATTR_ID).c_str(), laneTemplate->getACIcon());
508 }
509 // update comboBox
510 updateComboBox();
511 // show laneTypeAttributes
512 myCreateEdgeFrameParent->myLaneTypeAttributes->showAttributesCreatorModule(edgeTemplate->getLaneTemplates().at(myLaneIndex), {SUMO_ATTR_ID});
513 // disable laneAttributes (because is a template)
514 myCreateEdgeFrameParent->myLaneTypeAttributes->disableAttributesCreator();
515 // disable add and remove buttons
516 myAddLaneTypeButton->disable();
517 myDeleteLaneTypeButton->disable();
518 } else {
519 // get edgeType
520 const GNEEdgeType* edgeType = myCreateEdgeFrameParent->myEdgeTypeSelector->getEdgeTypeSelected();
521 // fill comboBox
522 for (const auto& laneType : edgeType->getLaneTypes()) {
523 myLaneTypesComboBox->appendIconItem(laneType->getAttribute(SUMO_ATTR_ID).c_str(), laneType->getACIcon());
524 }
525 // update comboBox
526 updateComboBox();
527 // show laneTypeAttributes
528 myCreateEdgeFrameParent->myLaneTypeAttributes->showAttributesCreatorModule(edgeType->getLaneTypes().at(myLaneIndex), {});
529 // enable add and remove buttons
530 myAddLaneTypeButton->enable();
531 // check if enable or disable remove lane button
532 if (edgeType->getLaneTypes().size() > 1) {
533 myDeleteLaneTypeButton->enable();
534 } else {
535 myDeleteLaneTypeButton->disable();
536 }
537 }
538 // recalc
539 recalc();
540}
541
542
543long
545 // check what edgeType is being edited
546 if (myCreateEdgeFrameParent->myEdgeTypeSelector->useDefaultEdgeType() ||
547 myCreateEdgeFrameParent->myEdgeTypeSelector->useDefaultEdgeTypeShort()) {
548 // add new lane in default edge type
549 myCreateEdgeFrameParent->myEdgeTypeSelector->getDefaultEdgeType()->addLaneType(new GNELaneType(myCreateEdgeFrameParent->myEdgeTypeSelector->getDefaultEdgeType()));
550 // refresh laneTypeSelector
551 refreshLaneTypeSelector();
552 // set combo box
553 myLaneTypesComboBox->setCurrentItem(myLaneTypesComboBox->getNumItems() - 1);
554 } else if (!myCreateEdgeFrameParent->myEdgeTypeSelector->useEdgeTemplate()) {
555 // get selected
556 const auto edgeType = myCreateEdgeFrameParent->myEdgeTypeSelector->getEdgeTypeSelected();
557 if (edgeType) {
558 // create new edgeType
559 GNEEdgeType* newEdgeType = new GNEEdgeType(edgeType);
560 // create laneTypes
561 for (const auto& laneType : edgeType->getLaneTypes()) {
562 newEdgeType->addLaneType(new GNELaneType(newEdgeType, laneType));
563 }
564 // add new lane
565 newEdgeType->addLaneType(new GNELaneType(newEdgeType));
566 // remove old edgeTyp und and newEdgeType
567 myCreateEdgeFrameParent->getViewNet()->getUndoList()->begin(GUIIcon::LANETYPE, TL("add laneType"));
568 myCreateEdgeFrameParent->getViewNet()->getUndoList()->add(new GNEChange_EdgeType(edgeType, false), true);
569 myCreateEdgeFrameParent->getViewNet()->getUndoList()->add(new GNEChange_EdgeType(newEdgeType, true), true);
570 myCreateEdgeFrameParent->getViewNet()->getUndoList()->end();
571 // update index
572 myLaneIndex = myLaneTypesComboBox->getNumItems() - 1;
573 // set current edgeType in selector
574 myCreateEdgeFrameParent->myEdgeTypeSelector->setCurrentEdgeType(newEdgeType);
575 }
576 }
577 return 0;
578}
579
580
581long
583 // check what edgeType is being edited
584 if (myCreateEdgeFrameParent->myEdgeTypeSelector->useDefaultEdgeType() ||
585 myCreateEdgeFrameParent->myEdgeTypeSelector->useDefaultEdgeTypeShort()) {
586 // add new lane in default edge type
587 myCreateEdgeFrameParent->myEdgeTypeSelector->getDefaultEdgeType()->removeLaneType(myLaneIndex);
588 // refresh laneTypeSelector
589 refreshLaneTypeSelector();
590 // set combo box
591 myLaneTypesComboBox->setCurrentItem(0);
592 } else if (!myCreateEdgeFrameParent->myEdgeTypeSelector->useEdgeTemplate()) {
593 // get selected
594 const auto edgeType = myCreateEdgeFrameParent->myEdgeTypeSelector->getEdgeTypeSelected();
595 if (edgeType) {
596 // create new edgeType
597 GNEEdgeType* newEdgeType = new GNEEdgeType(edgeType);
598 // create laneTypes (except current)
599 for (int i = 0; i < (int)edgeType->getLaneTypes().size(); i++) {
600 if (i != myLaneIndex) {
601 newEdgeType->addLaneType(new GNELaneType(newEdgeType, edgeType->getLaneTypes().at(i)));
602 }
603 }
604 // remove old edgeTyp und and newEdgeType
605 myCreateEdgeFrameParent->getViewNet()->getUndoList()->begin(GUIIcon::LANETYPE, TL("remove laneType"));
606 myCreateEdgeFrameParent->getViewNet()->getUndoList()->add(new GNEChange_EdgeType(edgeType, false), true);
607 myCreateEdgeFrameParent->getViewNet()->getUndoList()->add(new GNEChange_EdgeType(newEdgeType, true), true);
608 myCreateEdgeFrameParent->getViewNet()->getUndoList()->end();
609 // update index
610 myLaneIndex = myLaneTypesComboBox->getNumItems() - 1;
611 // set current edgeType in selector
612 myCreateEdgeFrameParent->myEdgeTypeSelector->setCurrentEdgeType(newEdgeType);
613 }
614 }
615 return 0;
616}
617
618
619long
621 // update index
622 myLaneIndex = myLaneTypesComboBox->getCurrentItem();
623 // refresh laneType selector
624 refreshLaneTypeSelector();
625 return 0;
626}
627
628
629void
631 // check lane index
632 if (myLaneIndex > myLaneTypesComboBox->getNumItems()) {
633 myLaneIndex = 0;
634 }
635 // set current item
636 myLaneTypesComboBox->setCurrentItem(myLaneIndex);
637}
638
639// ---------------------------------------------------------------------------
640// GNECreateEdgeFrame::Legend - methods
641// ---------------------------------------------------------------------------
642
644 MFXGroupBoxModule(createEdgeFrameParent, TL("Information")) {
645 std::ostringstream information;
646 // add label for shift+click
647 information
648 << "- " << TL("ESC:") << "\n"
649 << " " << TL("Deselect origin") << "\n"
650 << "- " << TL("Control+Click:") << "\n"
651 << " " << TL("Move view") << "\n"
652 << "- " << TL("Shift+Click:") << "\n"
653 << " " << TL("Splits edge in both directions") << "\n"
654 << "- " << TL("Alt+Shift+Click:") << "\n"
655 << " " << TL("Splits edge in one direction");
656 // create label
657 new MFXDynamicLabel(getCollapsableFrame(), information.str().c_str(), 0, GUIDesignLabelFrameInformation);
658}
659
660
662
663// ---------------------------------------------------------------------------
664// GNECreateEdgeFrame - methods
665// ---------------------------------------------------------------------------
666
668 GNEFrame(viewParent, viewNet, TL("Create Edge")),
669 myJunctionSource(nullptr) {
670 // create custom edge selector
672 // Create edgeType parameters
674 // lane type selector
676 // Create laneType parameters
678 // create edge selector legend
679 myLegend = new Legend(this);
680}
681
682
684
685
686void
688 const bool oppositeEdge, const bool chainEdge) {
689 // first check if there is an edge template, an edge type (default or custom)
692 WRITE_WARNING(TL("Select either default edgeType or short edge or a custom edgeType or template"));
693 } else if (!myEdgeTypeAttributes->areValuesValid()) {
694 WRITE_WARNING(TL("Invalid edge attributes"));
695 } else if (!myLaneTypeAttributes->areValuesValid()) {
696 WRITE_WARNING(TL("Invalid lane attributes"));
697 } else {
698 // if grid is enabled and currently there isn't a junction under mouse, make a new search snapping position to grid
699 if ((viewObjects.getJunctionFront() == nullptr) && myViewNet->getVisualisationSettings().showGrid) {
701 }
702 // obtain junction depending of gridEnabled
703 GNEJunction* junction = viewObjects.getJunctionFront();
704 // begin undo list
706 myViewNet->getUndoList()->begin(GUIIcon::EDGE, TL("create new edge"));
707 }
708 // if we didn't clicked over another junction, then create a new
709 if (junction == nullptr) {
710 junction = myViewNet->getNet()->createJunction(myViewNet->snapToActiveGrid(clickedPosition), myViewNet->getUndoList());
711 }
712 // now check if we have to create a new edge
713 if (myJunctionSource == nullptr) {
714 // check if create edge type short
716 // create new junction
717 auto newJunction = myViewNet->getNet()->createJunction(myViewNet->snapToActiveGrid(clickedPosition) + Position(5, 0), myViewNet->getUndoList());
718 // create new small edge
719 GNEEdge* newEdge = myViewNet->getNet()->createEdge(junction, newJunction, nullptr, myViewNet->getUndoList());
720 // set parameters
722 // check pedestrians and sidewalks
724 disablePedestrians(newEdge);
725 }
726 // check if add bikelane
729 }
730 // check if add sidewalk
733 }
734 // end undo list
737 } else {
738 std::cout << "edge created without an open CommandGroup" << std::endl;
739 }
740 } else {
741 myJunctionSource = junction;
743 }
744 update();
745 } else {
746 // make sure that junctions source and destination are different
747 if (myJunctionSource != junction) {
748 // may fail to prevent double edges
749 GNEEdge* newEdge = myViewNet->getNet()->createEdge(myJunctionSource, junction, nullptr, myViewNet->getUndoList());
750 // check if edge was successfully created
751 if (newEdge) {
752 // set parameters
757 // check pedestrians and sidewalks
759 disablePedestrians(newEdge);
760 }
761 // check if add bikelane
764 }
765 // check if add sidewalk
768 }
769 } else {
771 }
772 // create another edge, if create opposite edge is enabled
773 if (oppositeEdge && (myViewNet->getNet()->getAttributeCarriers()->retrieveEdges(junction, myJunctionSource).size() == 0)) {
774 GNEEdge* newOppositeEdge = myViewNet->getNet()->createEdge(junction, myJunctionSource, nullptr,
775 myViewNet->getUndoList(), "-" + newEdge->getNBEdge()->getID());
776 // set parameters
781 // check pedestrians and sidewalks
783 disablePedestrians(newOppositeEdge);
784 }
785 // check if add bikelane
788 }
789 // check if add sidewalk
792 }
793 } else {
795 }
796 }
797 // edge created, then unmark as create edge source
799 // end undo list
802 } else {
803 std::cout << "edge created without an open CommandGroup" << std::endl;
804 }
805 // if we're creating edges in chain mode, mark junction as junction edge source
806 if (chainEdge) {
807 myJunctionSource = junction;
809 myViewNet->getUndoList()->begin(GUIIcon::EDGE, TL("create new edge"));
810 } else {
811 myJunctionSource = nullptr;
812 }
813 } else {
814 myViewNet->setStatusBarText(TL("An edge with the same geometry already exists!"));
815 }
816 } else {
817 myViewNet->setStatusBarText(TL("Start- and endpoint for an edge must be distinct!"));
818 }
819 update();
820 }
821 }
822}
823
824
825void
827 // if myCreateEdgeSource exist, unmark ist as create edge source
828 if (myJunctionSource != nullptr) {
829 // remove current created edge source
831 myJunctionSource = nullptr;
832 }
833}
834
835
836const GNEJunction*
840
841
842void
844 // refresh template selector
846 // show frame
848}
849
850
851void
853 // hide frame
855}
856
857
862
863
868
869
874
875
880
881
882void
887
888
889void
891 // iterate over lanes
892 for (const auto& lane : edge->getLanes()) {
893 // avoid sidewalks
894 if (lane->getAttribute(SUMO_ATTR_ALLOW) != "pedestrian") {
895 // extract disallow list
896 std::vector<std::string> disallowList = GNEAttributeCarrier::parse<std::vector<std::string> >(lane->getAttribute(SUMO_ATTR_DISALLOW));
897 // check if append pedestrian to disallow
898 if (std::find(disallowList.begin(), disallowList.end(), "pedestrian") == disallowList.end()) {
899 disallowList.push_back("pedestrian");
900 }
901 // update attribute
902 lane->setAttribute(SUMO_ATTR_DISALLOW, toString(disallowList), myViewNet->getUndoList());
903 }
904 }
905}
906
907
908void
909GNECreateEdgeFrame::addBikelane(GNEEdge* edge, const std::string& bikelaneWidth) const {
910 bool bikelaneFound = false;
911 // iterate over lanes
912 for (const auto& lane : edge->getLanes()) {
913 // check if there is already a SideWalk
914 if (lane->getAttribute(SUMO_ATTR_ALLOW) == "bicycle") {
915 bikelaneFound = true;
916 }
917 }
918 // only add if previously there is no bikelanes
919 if (!bikelaneFound) {
920 edge->getNet()->getViewNet()->addRestrictedLane(edge->getLanes().at(0), SVC_BICYCLE, false);
921 // set width
922 if (bikelaneWidth != "default") {
923 edge->getLanes().at(0)->setAttribute(SUMO_ATTR_WIDTH, bikelaneWidth, myViewNet->getUndoList());
924 }
925 }
926}
927
928
929void
930GNECreateEdgeFrame::addSidewalk(GNEEdge* edge, const std::string& sidewalkWidth) const {
931 bool sidewalkFound = false;
932 // iterate over lanes
933 for (const auto& lane : edge->getLanes()) {
934 // check if there is already a SideWalk
935 if (lane->getAttribute(SUMO_ATTR_ALLOW) == "pedestrian") {
936 sidewalkFound = true;
937 }
938 }
939 // only add if previously there is no Sidewalk
940 if (!sidewalkFound) {
941 edge->getNet()->getViewNet()->addRestrictedLane(edge->getLanes().at(0), SVC_PEDESTRIAN, false);
942 // set width
943 if (sidewalkWidth != "default") {
944 edge->getLanes().at(0)->setAttribute(SUMO_ATTR_WIDTH, sidewalkWidth, myViewNet->getUndoList());
945 }
946 }
947}
948
949/****************************************************************************/
FXDEFMAP(GNECreateEdgeFrame::EdgeTypeSelector) EdgeTypeSelectorMap[]
@ MID_GNE_CREATEEDGEFRAME_CREATEFROMTEMPLATE
create edge type from template
@ MID_GNE_CREATEEDGEFRAME_CHECKBUTTON
check button
@ MID_GNE_CREATEEDGEFRAME_SELECTTEMPLATE
select edge template
@ MID_GNE_CREATEEDGEFRAME_DELETE
delete edge type
@ MID_GNE_CREATEEDGEFRAME_ADD
add new edge type
@ MID_GNE_CREATEEDGEFRAME_SELECTLANE
select lane (used for default and template edges)
@ MID_GNE_CREATEEDGEFRAME_SELECTRADIOBUTTON
#define GUIDesignButton
Definition GUIDesigns.h:88
#define GUIDesignComboBoxAttribute
Combo box static (cannot be edited) extended over the matrix column.
Definition GUIDesigns.h:308
#define GUIDesignComboBoxNCol
number of column of every combo box
Definition GUIDesigns.h:317
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames
Definition GUIDesigns.h:405
#define GUIDesignComboBoxVisibleItemsMedium
combo box medium small
Definition GUIDesigns.h:53
#define GUIDesignCheckButton
checkButton placed in left position
Definition GUIDesigns.h:198
#define GUIDesignRadioButton
Definition GUIDesigns.h:235
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition GUIDesigns.h:285
#define WRITE_WARNING(msg)
Definition MsgHandler.h:295
#define TL(string)
Definition MsgHandler.h:315
@ SVC_BICYCLE
vehicle is a bicycle
@ SVC_PEDESTRIAN
pedestrian
@ SUMO_ATTR_DISALLOW
@ SUMO_ATTR_ALLOW
@ SUMO_ATTR_BIKELANEWIDTH
@ SUMO_ATTR_SIDEWALKWIDTH
@ SUMO_ATTR_ID
@ SUMO_ATTR_WIDTH
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
const std::string getID() const
get ID (all Attribute Carriers have one)
GNENet * getNet() const
get pointer to net
bool areValuesValid() const
check if parameters of attributes are valid
GNEEdgeType * getEdgeTypeSelected() const
get edgeType selected
GNEEdgeType * getDefaultEdgeType() const
get default edgeType
bool useEdgeTemplate() const
check if we have to use edge template
bool useDefaultEdgeTypeShort() const
check if we're using default edge type short
long onUpdCheckButtons(FXObject *, FXSelector, void *)
Called when check buttons are updated.
bool isAddBikelaneEnabled() const
check if add bikelane check button is enabled
void updateIDinComboBox(const std::string &oldID, const std::string &newID)
update id in comboBox
long onCmdAddEdgeType(FXObject *, FXSelector, void *)
Called when the user press button for add a new edge type.
void enableCheckBoxDisablePedestrians()
void enable checkbox for disable pedestrians
bool useDefaultEdgeType() const
check if we're using default edge type
long onCmdDeleteEdgeType(FXObject *, FXSelector, void *)
Called when the user press button for delete edge type.
GNEEdgeType * myDefaultEdgeType
default edge type
long onCmdCreateFromTemplate(FXObject *, FXSelector, void *)
Called when the user press create edgeType from Template.
bool isAddSidewalkEnabled() const
check if add sidewalk check button is enabled
void refreshEdgeTypeSelector()
refresh edge type selector
bool isNoPedestriansEnabled() const
check if no pedestrian check button is enabled
long onCmdRadioButton(FXObject *, FXSelector, void *)
void setCurrentEdgeType(const GNEEdgeType *edgeType)
set current edgeType
void clearEdgeTypeSelected()
clear edgeType selected
long onCmdSelectEdgeTypeOrTemplate(FXObject *, FXSelector, void *)
Called when the user press select an edgeType or template in comboBox.
long onCmdSelectLaneType(FXObject *, FXSelector, void *)
Called when the user press select an laneType in comboBox.
FXButton * myDeleteLaneTypeButton
button for delete lane type
MFXComboBoxIcon * myLaneTypesComboBox
ComboBox for lane types.
void showLaneTypeSelector()
show lane type selector
LaneTypeSelector(GNECreateEdgeFrame *createEdgeFrameParent)
FOX-declaration.
void hideLaneTypeSelector()
hide lane type selector
long onCmdAddLaneType(FXObject *, FXSelector, void *)
FXButton * myAddLaneTypeButton
button for create new lane type
long onCmdDeleteLaneType(FXObject *, FXSelector, void *)
Called when the user press button for delete lane type.
void refreshLaneTypeSelector()
refresh LaneTypeSelector
Legend(GNECreateEdgeFrame *createEdgeFrameParent)
constructor
EdgeTypeSelector * getEdgeTypeSelector() const
get edgeType selector
GNEJunction * myJunctionSource
source junction for new edge
void processClick(const Position &clickedPosition, const GNEViewNetHelper::ViewObjectsSelector &viewObjects, const bool oppositeEdge, const bool chainEdge)
handle processClick and set the relative coloring
void abortEdgeCreation()
abort current edge creation
void show()
show create edge frame
GNECreateEdgeFrame::LaneTypeSelector * myLaneTypeSelector
lane type selector
GNEAttributesCreator * getLaneTypeAttributes() const
get laneType attributes
GNEAttributesCreator * myEdgeTypeAttributes
internal edgeType attributes
void addSidewalk(GNEEdge *edge, const std::string &sidewalkWidth) const
add sidewalk in the given edge
GNEAttributesCreator * getEdgeTypeAttributes() const
get edgeType attributes
const GNEJunction * getJunctionSource() const
get junction source for new edge
GNEAttributesCreator * myLaneTypeAttributes
internal laneType attributes
void disablePedestrians(GNEEdge *edge) const
disable pedestrians in the given edge (within undoRedo)
GNECreateEdgeFrame::Legend * myLegend
Legend.
GNECreateEdgeFrame(GNEViewParent *viewParent, GNEViewNet *viewNet)
Constructor.
void addBikelane(GNEEdge *edge, const std::string &bikelaneWidth) const
add bikelane in the given edge
void hide()
hide create edge frame
EdgeTypeSelector * myEdgeTypeSelector
edge type selector
void setUseEdgeTemplate()
set default to using edge template
LaneTypeSelector * getLaneTypeSelector()
get lane type selector
A road/street connecting two junctions (netedit-version)
Definition GNEEdge.h:53
void copyEdgeType(const GNEEdgeType *edgeType, GNEUndoList *undoList)
copy edge attributes from edgeType
Definition GNEEdge.cpp:1078
NBEdge * getNBEdge() const
returns the internal NBEdge
Definition GNEEdge.cpp:781
const std::vector< GNELane * > & getLanes() const
returns a reference to the lane vector
Definition GNEEdge.cpp:1118
void copyTemplate(const GNEEdgeTemplate *edgeTemplate, GNEUndoList *undoList)
copy edge attributes from edgetemplate
Definition GNEEdge.cpp:1055
const std::vector< GNELaneTemplate * > & getLaneTemplates() const
get vector with the lane templates of this edge
void copyTemplate(const GNEEdgeTemplate *edgeTemplate)
copy edge template
const std::vector< GNELaneType * > & getLaneTypes() const
get laneTypes
void addLaneType(GNELaneType *laneType)
add laneType
std::string getAttribute(SumoXMLAttr key) const
GNEViewNet * myViewNet
FOX need this.
Definition GNEFrame.h:117
virtual void show()
show Frame
Definition GNEFrame.cpp:115
virtual void hide()
hide Frame
Definition GNEFrame.cpp:124
GNEEdgeTemplate * getEdgeTemplate() const
get edge template (to copy attributes from)
TemplateEditor * getTemplateEditor() const
get template editor
void markAsCreateEdgeSource()
marks as first junction in createEdge-mode
void unMarkAsCreateEdgeSource()
removes mark as first junction in createEdge-mode
std::vector< GNEEdge * > retrieveEdges(GNEJunction *from, GNEJunction *to) const
get all edges by from and to GNEJunction
GNEEdgeType * retrieveEdgeType(const std::string &id, bool hardFail=true) const
get edge type by id
GNENetHelper::AttributeCarriers * getAttributeCarriers() const
get all attribute carriers used in this net
Definition GNENet.cpp:127
GNEEdge * createEdge(GNEJunction *src, GNEJunction *dest, GNEEdge *edgeTemplate, GNEUndoList *undoList, const std::string &suggestedName="", bool wasSplit=false, bool allowDuplicateGeom=false, bool recomputeConnections=true)
creates a new edge (unless an edge with the same geometry already exists)
Definition GNENet.cpp:248
GNEJunction * createJunction(const Position &pos, GNEUndoList *undoList)
creates a new junction
Definition GNENet.cpp:232
GNEViewNet * getViewNet() const
get view net
Definition GNENet.cpp:2155
void end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
bool hasCommandGroup() const
Check if undoList has command group.
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...
class used to group all variables related with objects under cursor after a click over view
GNEJunction * getJunctionFront() const
get front junction or a pointer to nullptr
GNENet * getNet() const
get the net object
void updateObjectsInPosition(const Position &pos)
update objects and boundaries in position
GNEViewParent * getViewParent() const
get the net object
GNEUndoList * getUndoList() const
get the undoList object
bool addRestrictedLane(GNELane *lane, SUMOVehicleClass vclass, const bool insertAtFront)
add restricted lane
void setStatusBarText(const std::string &text)
set statusBar text
A single child window which contains a view of the simulation area.
GNEInspectorFrame * getInspectorFrame() const
get frame for inspect elements
static FXButton * buildFXButton(FXComposite *p, const std::string &text, const std::string &tip, const std::string &help, FXIcon *ic, FXObject *tgt, FXSelector sel, FXuint opts=BUTTON_NORMAL, FXint x=0, FXint y=0, FXint w=0, FXint h=0, FXint pl=DEFAULT_PAD, FXint pr=DEFAULT_PAD, FXint pt=DEFAULT_PAD, FXint pb=DEFAULT_PAD)
build button
static FXIcon * getIcon(const GUIIcon which)
returns a icon previously defined in the enum GUIIcon
Position snapToActiveGrid(const Position &pos, bool snapXY=true) const
Returns a position that is mapped to the closest grid point if the grid is active.
const GUIVisualizationSettings & getVisualisationSettings() const
get visualization settings (read only)
bool showGrid
Information whether a grid shall be shown.
ComboBox with icon.
A list item which allows for custom coloring.
MFXGroupBoxModule (based on FXGroupBox)
FXVerticalFrame * getCollapsableFrame()
get collapsable frame (used by all elements that will be collapsed if button is toggled)
const std::string & getID() const
Definition NBEdge.h:1528
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37