Eclipse SUMO - Simulation of Urban MObility
GNECreateEdgeFrame.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-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // The Widget for editing connection prohibits
16 /****************************************************************************/
17 
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
27 #include <netedit/GNEUndoList.h>
28 #include <netedit/GNENet.h>
29 #include <netedit/GNEViewNet.h>
30 #include <netedit/GNEViewParent.h>
31 
32 #include "GNECreateEdgeFrame.h"
33 #include "GNEInspectorFrame.h"
34 
35 // ===========================================================================
36 // FOX callback mapping
37 // ===========================================================================
38 FXDEFMAP(GNECreateEdgeFrame) GNECreateEdgeFrameMap[] = {
40  FXMAPFUNC(SEL_COMMAND, MID_CANCEL, GNECreateEdgeFrame::onCmdCancel),
41  FXMAPFUNC(SEL_COMMAND, MID_OK, GNECreateEdgeFrame::onCmdOK)
43 };
44 
45 // Object implementation
46 FXIMPLEMENT(GNECreateEdgeFrame, FXVerticalFrame, GNECreateEdgeFrameMap, ARRAYNUMBER(GNECreateEdgeFrameMap))
47 
48 // ===========================================================================
49 // static members
50 // ===========================================================================
51 
52 
53 // ===========================================================================
54 // method definitions
55 // ===========================================================================
56 
57 GNECreateEdgeFrame::GNECreateEdgeFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet) :
58  GNEFrame(horizontalFrameParent, viewNet, "Create Edge"),
59  myCreateEdgeSource(nullptr) {
60 }
61 
62 
64 
65 
66 void
67 GNECreateEdgeFrame::processClick(const Position& clickedPosition, GNEViewNetHelper::ObjectsUnderCursor& objectsUnderCursor, bool opossiteEdge, bool chainEdge) {
69  myViewNet->getUndoList()->p_begin("create new " + toString(SUMO_TAG_EDGE));
70  }
71  if (!objectsUnderCursor.getJunctionFront()) {
73  }
74  if (myCreateEdgeSource == nullptr) {
75  myCreateEdgeSource = objectsUnderCursor.getJunctionFront();
77  update();
78  } else {
79  if (myCreateEdgeSource != objectsUnderCursor.getJunctionFront()) {
80  // may fail to prevent double edges
81  GNEEdge* newEdge = myViewNet->getNet()->createEdge(
83  if (newEdge) {
84  // create another edge, if create opposite edge is enabled
85  if (opossiteEdge) {
87  }
89 
92  } else {
93  std::cout << "edge created without an open CommandGroup )-:\n";
94  }
95  if (chainEdge) {
96  myCreateEdgeSource = objectsUnderCursor.getJunctionFront();
98  myViewNet->getUndoList()->p_begin("create new " + toString(SUMO_TAG_EDGE));
99  } else {
100  myCreateEdgeSource = nullptr;
101  }
102  } else {
103  myViewNet->setStatusBarText("An " + toString(SUMO_TAG_EDGE) + " with the same geometry already exists!");
104  }
105  } else {
106  myViewNet->setStatusBarText("Start- and endpoint for an " + toString(SUMO_TAG_EDGE) + " must be distinct!");
107  }
108  update();
109  }
110 }
111 
112 
114  // if myCreateEdgeSource exist, unmark ist as create edge source
115  if (myCreateEdgeSource != nullptr) {
116  // remove current created edge source
118  myCreateEdgeSource = nullptr;
119  }
120 }
121 
122 
123 void
125  GNEFrame::show();
126 }
127 
128 
129 void
131  GNEFrame::hide();
132 }
133 
134 
135 long
136 GNECreateEdgeFrame::onCmdCancel(FXObject*, FXSelector, void*) {
138  return 1;
139 }
140 
141 
142 long
143 GNECreateEdgeFrame::onCmdOK(FXObject*, FXSelector, void*) {
145  return 1;
146 }
147 
148 
149 /****************************************************************************/
GNEJunction::unMarkAsCreateEdgeSource
void unMarkAsCreateEdgeSource()
removes mark as first junction in createEdge-mode
Definition: GNEJunction.cpp:571
GNECreateEdgeFrame.h
GNECreateEdgeFrame::~GNECreateEdgeFrame
~GNECreateEdgeFrame()
Destructor.
Definition: GNECreateEdgeFrame.cpp:63
GNEUndoList::p_end
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise,...
Definition: GNEUndoList.cpp:80
GNECreateEdgeFrame::onCmdOK
long onCmdOK(FXObject *, FXSelector, void *)
Definition: GNECreateEdgeFrame.cpp:143
GNEViewNet::setStatusBarText
void setStatusBarText(const std::string &text)
set staturBar text
Definition: GNEViewNet.cpp:482
GNECreateEdgeFrame::processClick
void processClick(const Position &clickedPosition, GNEViewNetHelper::ObjectsUnderCursor &objectsUnderCursor, bool oppositeEdge, bool chainEdge)
handle processClick and set the relative colouring
Definition: GNECreateEdgeFrame.cpp:67
GNEFrame
Definition: GNEFrame.h:35
GNEViewNet
Definition: GNEViewNet.h:43
FXDEFMAP
FXDEFMAP(GNECreateEdgeFrame) GNECreateEdgeFrameMap[]
GNECreateEdgeFrame::abortEdgeCreation
void abortEdgeCreation()
abort current edge creation
Definition: GNECreateEdgeFrame.cpp:113
GNEViewNetHelper::ObjectsUnderCursor::setCreatedJunction
void setCreatedJunction(GNEJunction *junction)
set created junction
Definition: GNEViewNetHelper.cpp:189
MID_CANCEL
Cancel-button pressed.
Definition: GUIAppEnum.h:215
GUISUMOAbstractView::snapToActiveGrid
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.
Definition: GUISUMOAbstractView.cpp:194
GUIAppEnum.h
GNEJunction.h
GNEEdge
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:50
GNEViewNet::getNet
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:927
GNEInspectorFrame::TemplateEditor::getEdgeTemplate
GNEEdge * getEdgeTemplate() const
get the template edge (to copy attributes from)
Definition: GNEInspectorFrame.cpp:1130
GNEJunction::markAsCreateEdgeSource
void markAsCreateEdgeSource()
marks as first junction in createEdge-mode
Definition: GNEJunction.cpp:565
GNEEdge::getNBEdge
NBEdge * getNBEdge() const
returns the internal NBEdge
Definition: GNEEdge.cpp:625
GNEViewNetHelper::ObjectsUnderCursor
class used to group all variables related with objects under cursor after a click over view
Definition: GNEViewNetHelper.h:149
MID_OK
Ok-button pressed.
Definition: GUIAppEnum.h:213
GNEViewNet.h
update
SUMO_TAG_EDGE
begin/end of the description of an edge
Definition: SUMOXMLDefinitions.h:48
GNENet::createEdge
GNEEdge * createEdge(GNEJunction *src, GNEJunction *dest, GNEEdge *tpl, 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:325
GNEInspectorFrame::getTemplateEditor
TemplateEditor * getTemplateEditor() const
get template editor
Definition: GNEInspectorFrame.cpp:345
GNEViewParent::getInspectorFrame
GNEInspectorFrame * getInspectorFrame() const
get frame for GNE_NMODE_INSPECT
Definition: GNEViewParent.cpp:179
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
GNEEdge.h
GNEFrame::myViewNet
GNEViewNet * myViewNet
View Net.
Definition: GNEFrame.h:120
GNEViewNet::getUndoList
GNEUndoList * getUndoList() const
get the undoList object
Definition: GNEViewNet.cpp:933
GNEViewNetHelper::ObjectsUnderCursor::getJunctionFront
GNEJunction * getJunctionFront() const
get front junction (or a pointer to nullptr if there isn't)
Definition: GNEViewNetHelper.cpp:269
GNENet::createJunction
GNEJunction * createJunction(const Position &pos, GNEUndoList *undoList)
creates a new junction
Definition: GNENet.cpp:314
GNECreateEdgeFrame::onCmdCancel
long onCmdCancel(FXObject *, FXSelector, void *)
Called when the user presses the Cancel-button discards any edge modifications.
Definition: GNECreateEdgeFrame.cpp:136
GNEViewParent.h
Edge
C++ TraCI client API implementation.
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:48
GNECreateEdgeFrame::hide
void hide()
hide prohibition frame
Definition: GNECreateEdgeFrame.cpp:130
GNEUndoList::hasCommandGroup
bool hasCommandGroup() const
Check if undoList has command group.
Definition: GNEUndoList.cpp:199
GNECreateEdgeFrame::show
void show()
show prohibition frame
Definition: GNECreateEdgeFrame.cpp:124
config.h
GNEInspectorFrame.h
GNECreateEdgeFrame::myCreateEdgeSource
GNEJunction * myCreateEdgeSource
source junction for new edge
Definition: GNECreateEdgeFrame.h:78
GNEUndoList::p_begin
void p_begin(const std::string &description)
Begin undo command sub-group. This begins a new group of commands that are treated as a single comman...
Definition: GNEUndoList.cpp:73
GNEFrame::show
virtual void show()
show Frame
Definition: GNEFrame.cpp:108
GNEFrame::hide
virtual void hide()
hide Frame
Definition: GNEFrame.cpp:117
GNECreateEdgeFrame
Definition: GNECreateEdgeFrame.h:33
GNENet.h
GNEViewNet::getViewParent
GNEViewParent * getViewParent() const
get the net object
Definition: GNEViewNet.cpp:921
GNEUndoList.h
NBEdge::getID
const std::string & getID() const
Definition: NBEdge.h:1364