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 /****************************************************************************/
14 // The Widget for editing connection prohibits
15 /****************************************************************************/
16 
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
26 #include <netedit/GNEUndoList.h>
27 #include <netedit/GNENet.h>
28 #include <netedit/GNEViewNet.h>
29 #include <netedit/GNEViewParent.h>
30 
31 #include "GNECreateEdgeFrame.h"
32 #include "GNEInspectorFrame.h"
33 
34 // ===========================================================================
35 // FOX callback mapping
36 // ===========================================================================
37 FXDEFMAP(GNECreateEdgeFrame) GNECreateEdgeFrameMap[] = {
39  FXMAPFUNC(SEL_COMMAND, MID_CANCEL, GNECreateEdgeFrame::onCmdCancel),
40  FXMAPFUNC(SEL_COMMAND, MID_OK, GNECreateEdgeFrame::onCmdOK)
42 };
43 
44 // Object implementation
45 FXIMPLEMENT(GNECreateEdgeFrame, FXVerticalFrame, GNECreateEdgeFrameMap, ARRAYNUMBER(GNECreateEdgeFrameMap))
46 
47 // ===========================================================================
48 // static members
49 // ===========================================================================
50 
51 
52 // ===========================================================================
53 // method definitions
54 // ===========================================================================
55 
56 GNECreateEdgeFrame::GNECreateEdgeFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet) :
57  GNEFrame(horizontalFrameParent, viewNet, "Create Edge"),
58  myCreateEdgeSource(nullptr) {
59 }
60 
61 
63 
64 
65 void
67  GNEViewNetHelper::ObjectsUnderCursor& objectsUnderGrippedCursor, const bool oppositeEdge, const bool chainEdge) {
68  // obtain junction depending of gridEnabled
69  GNEJunction* junction = nullptr;
70  if (objectsUnderCursor.getJunctionFront()) {
71  junction = objectsUnderCursor.getJunctionFront();
72  } else if (objectsUnderGrippedCursor.getJunctionFront()) {
73  junction = objectsUnderGrippedCursor.getJunctionFront();
74  }
75  // begin undo list
77  myViewNet->getUndoList()->p_begin("create new " + toString(SUMO_TAG_EDGE));
78  }
79  // if we didn't clicked over another junction, then create a new
80  if (junction == nullptr) {
81  junction = myViewNet->getNet()->createJunction(myViewNet->snapToActiveGrid(clickedPosition), myViewNet->getUndoList());
82  }
83  // now check if we have to create a new edge
84  if (myCreateEdgeSource == nullptr) {
85  myCreateEdgeSource = junction;
87  update();
88  } else {
89  // make sure that junctions source and destiny are different
90  if (myCreateEdgeSource != junction) {
91  // may fail to prevent double edges
92  GNEEdge* newEdge = myViewNet->getNet()->createEdge(myCreateEdgeSource, junction,
94  // check if edge was sucesfully created
95  if (newEdge) {
96  // create another edge, if create opposite edge is enabled
97  if (oppositeEdge) {
99  myViewNet->getUndoList(), "-" + newEdge->getNBEdge()->getID());
100  }
101  // edge created, then unmark as create edge source
103  // end undo list
106  } else {
107  std::cout << "edge created without an open CommandGroup )-:\n";
108  }
109  // if we're creating edges in chain mode, mark junction as junction edge source
110  if (chainEdge) {
111  myCreateEdgeSource = junction;
113  myViewNet->getUndoList()->p_begin("create new " + toString(SUMO_TAG_EDGE));
114  } else {
115  myCreateEdgeSource = nullptr;
116  }
117  } else {
118  myViewNet->setStatusBarText("An " + toString(SUMO_TAG_EDGE) + " with the same geometry already exists!");
119  }
120  } else {
121  myViewNet->setStatusBarText("Start- and endpoint for an " + toString(SUMO_TAG_EDGE) + " must be distinct!");
122  }
123  update();
124  }
125 }
126 
127 
129  // if myCreateEdgeSource exist, unmark ist as create edge source
130  if (myCreateEdgeSource != nullptr) {
131  // remove current created edge source
133  myCreateEdgeSource = nullptr;
134  }
135 }
136 
137 
138 void
140  GNEFrame::show();
141 }
142 
143 
144 void
146  GNEFrame::hide();
147 }
148 
149 
150 long
151 GNECreateEdgeFrame::onCmdCancel(FXObject*, FXSelector, void*) {
153  return 1;
154 }
155 
156 
157 long
158 GNECreateEdgeFrame::onCmdOK(FXObject*, FXSelector, void*) {
160  return 1;
161 }
162 
163 
164 /****************************************************************************/
GNEJunction::unMarkAsCreateEdgeSource
void unMarkAsCreateEdgeSource()
removes mark as first junction in createEdge-mode
Definition: GNEJunction.cpp:517
GNECreateEdgeFrame.h
GNECreateEdgeFrame::~GNECreateEdgeFrame
~GNECreateEdgeFrame()
Destructor.
Definition: GNECreateEdgeFrame.cpp:62
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:79
GNECreateEdgeFrame::onCmdOK
long onCmdOK(FXObject *, FXSelector, void *)
Definition: GNECreateEdgeFrame.cpp:158
GNEViewNet::setStatusBarText
void setStatusBarText(const std::string &text)
set staturBar text
Definition: GNEViewNet.cpp:523
GNEFrame
Definition: GNEFrame.h:34
GNEViewNet
Definition: GNEViewNet.h:42
FXDEFMAP
FXDEFMAP(GNECreateEdgeFrame) GNECreateEdgeFrameMap[]
GNECreateEdgeFrame::abortEdgeCreation
void abortEdgeCreation()
abort current edge creation
Definition: GNECreateEdgeFrame.cpp:128
MID_CANCEL
@ MID_CANCEL
Cancel-button pressed.
Definition: GUIAppEnum.h:230
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:196
GUIAppEnum.h
GNECreateEdgeFrame::processClick
void processClick(const Position &clickedPosition, GNEViewNetHelper::ObjectsUnderCursor &objectsUnderCursor, GNEViewNetHelper::ObjectsUnderCursor &objectsUnderGrippedCursor, const bool oppositeEdge, const bool chainEdge)
handle processClick and set the relative colouring
Definition: GNECreateEdgeFrame.cpp:66
GNEJunction.h
GNEEdge
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:51
GNEViewNet::getNet
GNENet * getNet() const
get the net object
Definition: GNEViewNet.cpp:1014
GNEInspectorFrame::TemplateEditor::getEdgeTemplate
GNEEdge * getEdgeTemplate() const
get the template edge (to copy attributes from)
Definition: GNEInspectorFrame.cpp:929
GNEJunction::markAsCreateEdgeSource
void markAsCreateEdgeSource()
marks as first junction in createEdge-mode
Definition: GNEJunction.cpp:511
GNEEdge::getNBEdge
NBEdge * getNBEdge() const
returns the internal NBEdge
Definition: GNEEdge.cpp:631
GNEViewNetHelper::ObjectsUnderCursor
class used to group all variables related with objects under cursor after a click over view
Definition: GNEViewNetHelper.h:148
MID_OK
@ MID_OK
Ok-button pressed.
Definition: GUIAppEnum.h:228
GNEViewNet.h
update
SUMO_TAG_EDGE
@ SUMO_TAG_EDGE
begin/end of the description of an edge
Definition: SUMOXMLDefinitions.h:47
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:326
GNEInspectorFrame::getTemplateEditor
TemplateEditor * getTemplateEditor() const
get template editor
Definition: GNEInspectorFrame.cpp:336
GNEViewParent::getInspectorFrame
GNEInspectorFrame * getInspectorFrame() const
get frame for GNE_NMODE_INSPECT
Definition: GNEViewParent.cpp:180
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
GNEEdge.h
GNEFrame::myViewNet
GNEViewNet * myViewNet
View Net.
Definition: GNEFrame.h:121
GNEViewNet::getUndoList
GNEUndoList * getUndoList() const
get the undoList object
Definition: GNEViewNet.cpp:1020
GNEViewNetHelper::ObjectsUnderCursor::getJunctionFront
GNEJunction * getJunctionFront() const
get front junction (or a pointer to nullptr if there isn't)
Definition: GNEViewNetHelper.cpp:258
GNENet::createJunction
GNEJunction * createJunction(const Position &pos, GNEUndoList *undoList)
creates a new junction
Definition: GNENet.cpp:313
GNECreateEdgeFrame::onCmdCancel
long onCmdCancel(FXObject *, FXSelector, void *)
Called when the user presses the Cancel-button discards any edge modifications.
Definition: GNECreateEdgeFrame.cpp:151
GNEViewParent.h
Edge
C++ TraCI client API implementation.
toString
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:47
GNECreateEdgeFrame::hide
void hide()
hide prohibition frame
Definition: GNECreateEdgeFrame.cpp:145
GNEUndoList::hasCommandGroup
bool hasCommandGroup() const
Check if undoList has command group.
Definition: GNEUndoList.cpp:231
GNECreateEdgeFrame::show
void show()
show prohibition frame
Definition: GNECreateEdgeFrame.cpp:139
config.h
GNEInspectorFrame.h
GNEJunction
Definition: GNEJunction.h:47
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:72
GNEFrame::show
virtual void show()
show Frame
Definition: GNEFrame.cpp:107
GNEFrame::hide
virtual void hide()
hide Frame
Definition: GNEFrame.cpp:116
GNECreateEdgeFrame
Definition: GNECreateEdgeFrame.h:32
GNENet.h
GNEViewNet::getViewParent
GNEViewParent * getViewParent() const
get the net object
Definition: GNEViewNet.cpp:1008
GNEUndoList.h
NBEdge::getID
const std::string & getID() const
Definition: NBEdge.h:1380