SUMO - Simulation of Urban MObility
GNEDeleteFrame.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-2018 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 remove network-elements
16 /****************************************************************************/
17 
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
24 #include <iostream>
41 #include <netedit/GNENet.h>
44 #include <netedit/GNEUndoList.h>
45 #include <netedit/GNEViewNet.h>
46 #include <netedit/GNEViewParent.h>
48 
49 #include "GNEInspectorFrame.h"
50 #include "GNEDeleteFrame.h"
51 #include "GNEAdditionalFrame.h"
52 
53 
54 // ---------------------------------------------------------------------------
55 // GNEDeleteFrame::DeleteOptions - methods
56 // ---------------------------------------------------------------------------
57 
59  FXGroupBox(deleteFrameParent->myContentFrame, "Options", GUIDesignGroupBoxFrame),
60  myDeleteFrameParent(deleteFrameParent) {
61 
62  // Create checkbox for enabling/disabling automatic deletion of additionals childs (by default, enabled)
63  myForceDeleteAdditionals = new FXCheckButton(this, "Force deletion of additionals", deleteFrameParent, MID_GNE_DELETEFRAME_AUTODELETEADDITIONALS, GUIDesignCheckButtonAttribute);
64  myForceDeleteAdditionals->setCheck(TRUE);
65 
66  // Create checkbox for enabling/disabling delete only geomtery point(by default, disabled)
67  myDeleteOnlyGeometryPoints = new FXCheckButton(this, "Delete only geometryPoints", deleteFrameParent, MID_GNE_DELETEFRAME_ONLYGEOMETRYPOINTS, GUIDesignCheckButtonAttribute);
68  myDeleteOnlyGeometryPoints->setCheck(FALSE);
69 }
70 
71 
73 
74 
75 bool
77  return (myForceDeleteAdditionals->getCheck() == TRUE);
78 }
79 
80 
81 bool
83  return (myDeleteOnlyGeometryPoints->getCheck() == TRUE);
84 }
85 
86 // ===========================================================================
87 // method definitions
88 // ===========================================================================
89 
90 GNEDeleteFrame::GNEDeleteFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet) :
91  GNEFrame(horizontalFrameParent, viewNet, "Delete") {
92  // create delete options modul
93  myDeleteOptions = new DeleteOptions(this);
94 
95  // Create groupbox and tree list
97 }
98 
99 
101 
102 void
104  if (myViewNet->getNet()->getSelectedAttributeCarriers().size() == 1) {
106  } else {
108  }
109  GNEFrame::show();
110 }
111 
112 
113 void
115 
116  GNEFrame::hide();
117 }
118 
119 
120 void
122  // remove all selected attribute carriers
123  myViewNet->getUndoList()->p_begin("remove selected items");
124  while (myViewNet->getNet()->getSelectedAttributeCarriers().size() > 0) {
126  }
128 }
129 
130 
131 void
133  // obtain clicked position
134  Position clickedPosition = myViewNet->getPositionInformation();
135  if (myDeleteOptions->deleteOnlyGeometryPoints() && !ignoreOptions) {
136  // check type of of GL object
137  switch (ac->getTag()) {
138  case SUMO_TAG_EDGE: {
139  GNEEdge* edge = dynamic_cast<GNEEdge*>(ac);
140  assert(edge);
141  if (edge->getVertexIndex(clickedPosition, false) != -1) {
142  edge->deleteGeometryPoint(clickedPosition);
143  }
144  break;
145  }
146  case SUMO_TAG_POLY: {
147  GNEPoly* polygon = dynamic_cast<GNEPoly*>(ac);
148  assert(polygon);
149  if (polygon->getVertexIndex(clickedPosition, false) != -1) {
150  polygon->deleteGeometryPoint(clickedPosition);
151  }
152  break;
153  }
154  default: {
155  break;
156  }
157  }
158  } else {
159  // check type of of GL object
160  switch (ac->getTag()) {
161  case SUMO_TAG_JUNCTION: {
162  GNEJunction* junction = dynamic_cast<GNEJunction*>(ac);
163  assert(junction);
164  // obtain number of additionals of junction's childs
165  int numberOfAdditionals = 0;
166  for (auto i : junction->getGNEEdges()) {
167  numberOfAdditionals += (int)i->getAdditionalChilds().size();
168  for (auto j : i->getLanes()) {
169  UNUSED_PARAMETER(j);
170  numberOfAdditionals += (int)i->getAdditionalChilds().size();
171  }
172  }
173  // Check if junction can be deleted
174  if (myDeleteOptions->forceDeleteAdditionals() || ignoreOptions) {
176  } else {
177  if (numberOfAdditionals > 0) {
178  // write warning if netedit is running in testing mode
179  WRITE_DEBUG("Opening FXMessageBox 'Force deletion needed'");
180  std::string plural = numberOfAdditionals > 1 ? "s" : "";
181  // Open warning DialogBox
182  FXMessageBox::warning(getViewNet()->getApp(), MBOX_OK, ("Problem deleting " + toString(junction->getTag())).c_str(), "%s",
183  (toString(junction->getTag()) + " '" + junction->getID() + "' cannot be deleted because owns " +
184  toString(numberOfAdditionals) + " additional child" + plural + ".\n Check 'Force deletion of additionals' to force deletion.").c_str());
185  // write warning if netedit is running in testing mode
186  WRITE_DEBUG("Closed FXMessageBox 'Force deletion needed' with 'OK'");
187  } else {
189  }
190  }
191  break;
192  }
193  case SUMO_TAG_EDGE: {
194  GNEEdge* edge = dynamic_cast<GNEEdge*>(ac);
195  assert(edge);
196  // check if click was over a geometry point or over a shape's edge
197  if (edge->getVertexIndex(clickedPosition, false) != -1) {
198  edge->deleteGeometryPoint(clickedPosition);
199  } else {
200  int numberOfAdditionalChilds = (int)edge->getAdditionalChilds().size();
201  int numberOfAdditionalParents = (int)edge->getAdditionalParents().size();
202  // Iterate over lanes and obtain total number of additional childs
203  for (auto i : edge->getLanes()) {
204  numberOfAdditionalChilds += (int)i->getAdditionalChilds().size();
205  }
206  // Check if edge can be deleted
207  if (myDeleteOptions->forceDeleteAdditionals() || ignoreOptions) {
208  // when deleting a single edge, keep all unaffected connections as they were
209  myViewNet->getNet()->deleteEdge(edge, myViewNet->getUndoList(), false);
210  } else {
211  if (numberOfAdditionalChilds > 0) {
212  // write warning if netedit is running in testing mode
213  WRITE_DEBUG("Opening FXMessageBox 'Force deletion needed'");
214  std::string plural = numberOfAdditionalChilds > 1 ? "s" : "";
215  // Open warning DialogBox
216  FXMessageBox::warning(getViewNet()->getApp(), MBOX_OK, ("Problem deleting " + toString(edge->getTag())).c_str(), "%s",
217  (toString(edge->getTag()) + " '" + edge->getID() + "' cannot be deleted because owns " +
218  toString(numberOfAdditionalChilds) + " additional" + plural + ".\n Check 'Force deletion of additionals' to force deletion.").c_str());
219  // write warning if netedit is running in testing mode
220  WRITE_DEBUG("Closed FXMessageBox 'Force deletion needed' with 'OK'");
221  } else if (numberOfAdditionalParents > 0) {
222  // write warning if netedit is running in testing mode
223  WRITE_DEBUG("Opening FXMessageBox 'Force deletion needed'");
224  std::string plural = numberOfAdditionalParents > 1 ? "s" : "";
225  // Open warning DialogBox
226  FXMessageBox::warning(getViewNet()->getApp(), MBOX_OK, ("Problem deleting " + toString(edge->getTag())).c_str(), "%s",
227  (toString(edge->getTag()) + " '" + edge->getID() + "' cannot be deleted because is part of " +
228  toString(numberOfAdditionalParents) + " additional" + plural + ".\n Check 'Force deletion of additionals' to force deletion.").c_str());
229  // write warning if netedit is running in testing mode
230  WRITE_DEBUG("Closed FXMessageBox 'Force deletion needed' with 'OK'");
231  } else {
232  // when deleting a single edge, keep all unaffected connections as they were
233  myViewNet->getNet()->deleteEdge(edge, myViewNet->getUndoList(), false);
234  }
235  }
236  }
237  break;
238  }
239  case SUMO_TAG_LANE: {
240  GNELane* lane = dynamic_cast<GNELane*>(ac);
241  assert(lane);
242  // Check if lane can be deleted
243  if (myDeleteOptions->forceDeleteAdditionals() || ignoreOptions) {
244  // when deleting a single lane, keep all unaffected connections as they were
245  myViewNet->getNet()->deleteLane(lane, myViewNet->getUndoList(), false);
246  } else {
247  if (lane->getAdditionalChilds().size() == 0) {
248  // when deleting a single lane, keep all unaffected connections as they were
249  myViewNet->getNet()->deleteLane(lane, myViewNet->getUndoList(), false);
250  } else {
251  // write warning if netedit is running in testing mode
252  WRITE_DEBUG("Opening FXMessageBox 'Force deletion needed'");
253  // open warning box
254  FXMessageBox::warning(getViewNet()->getApp(), MBOX_OK, ("Problem deleting " + toString(lane->getTag())).c_str(), "%s",
255  (toString(lane->getTag()) + " '" + lane->getID() + "' cannot be deleted because it has " +
256  toString(lane->getAdditionalChilds().size()) + " additional childs.\n Check 'Force deletion of Additionals' to force deletion.").c_str());
257  // write warning if netedit is running in testing mode
258  WRITE_DEBUG("Closed FXMessageBox 'Force deletion needed' with 'OK'");
259  }
260  }
261  break;
262  }
263  case SUMO_TAG_CROSSING: {
264  GNECrossing* crossing = dynamic_cast<GNECrossing*>(ac);
265  assert(crossing);
267  break;
268  }
269  case SUMO_TAG_CONNECTION: {
270  GNEConnection* connection = dynamic_cast<GNEConnection*>(ac);
271  assert(connection);
273  break;
274  }
275  default: {
276  // obtain tag property (only for improve code legibility)
277  const auto& tagValue = GNEAttributeCarrier::getTagProperties(ac->getTag());
278  if (tagValue.isAdditional()) {
279  GNEAdditional* additional = dynamic_cast<GNEAdditional*>(ac);
280  assert(additional);
282  } else if (tagValue.isShape()) {
283  GNEShape* shape = dynamic_cast<GNEShape*>(ac);
284  assert(shape);
286  }
287  break;
288  }
289  }
290  }
291  // update view to show changes
292  myViewNet->update();
293 }
294 
295 
298  return myDeleteOptions;
299 }
300 
301 /****************************************************************************/
DeleteOptions * getDeleteOptions() const
get delete options
#define GUIDesignCheckButtonAttribute
checkButton without thick extended over the frame used for attributes
Definition: GUIDesigns.h:115
void hide()
hide delete frame
begin/end of the description of a junction
begin/end of the description of a single lane
void showACHierarchy(GNEAttributeCarrier *AC)
show ACHierarchy
Definition: GNEFrame.cpp:99
void show()
show delete frame
connectio between two lanes
void hideACHierarchy()
hide ACHierarchy
Definition: GNEFrame.cpp:110
GNEViewParent * getViewParent() const
get the net object
int getVertexIndex(const Position &pos, bool createIfNoExist=true)
return index of a vertex of shape, or of a new vertex if position is over an shape&#39;s edge ...
Definition: GNEPoly.cpp:370
void deleteShape(GNEShape *shape, GNEUndoList *undoList)
remove shape
Definition: GNENet.cpp:596
GNEDeleteFrame(FXHorizontalFrame *horizontalFrameParent, GNEViewNet *viewNet)
Constructor.
automatically delete additional childs
Definition: GUIAppEnum.h:374
FXCheckButton * myDeleteOnlyGeometryPoints
checkbox for enable/disable delete only geometry points
void deleteConnection(GNEConnection *connection, GNEUndoList *undoList)
remove connection
Definition: GNENet.cpp:564
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:47
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:78
ACHierarchy * myACHierarchy
modul for hierarchy
std::vector< GNEAttributeCarrier * > getSelectedAttributeCarriers()
get all selected attribute carriers
Definition: GNENet.cpp:1751
const std::vector< GNEEdge * > & getGNEEdges() const
Returns all GNEEdges vinculated with this Junction.
#define UNUSED_PARAMETER(x)
Definition: StdDefs.h:33
GNEViewNet * getViewNet() const
get view net
Definition: GNEFrame.cpp:766
void deleteGeometryPoint(const Position &pos, bool allowUndo=true)
delete the geometry point closest to the given pos
Definition: GNEEdge.cpp:372
GNEViewNet * myViewNet
View Net for changes.
Definition: GNEFrame.h:232
GNEAdditionalFrame * getAdditionalFrame() const
get frame for GNE_MODE_ADDITIONAL
int getVertexIndex(const Position &pos, bool createIfNoExist=true)
return index of a vertex of shape, or of a new vertex if position is over an shape&#39;s edge ...
Definition: GNEEdge.cpp:261
GNEUndoList * getUndoList() const
get the undoList object
delete only geometry points
Definition: GUIAppEnum.h:372
const std::vector< GNEAdditional * > & getAdditionalParents() const
return vector of additionals that have as Parameter this edge (For example, Rerouters) ...
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
This object is responsible for drawing a shape and for supplying a a popup menu. Messages are routete...
Definition: GNECrossing.h:45
void deleteLane(GNELane *lane, GNEUndoList *undoList, bool recomputeConnections)
removes lane
Definition: GNENet.cpp:528
~GNEDeleteFrame()
Destructor.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
void p_end()
End undo command sub-group. If the sub-group is still empty, it will be deleted; otherwise, the sub-group will be added as a new command into parent group. A matching begin() must have been called previously.
Definition: GNEUndoList.cpp:85
void removeAdditional(GNEAdditional *additional)
remove an additional element previously added
void deleteCrossing(GNECrossing *crossing, GNEUndoList *undoList)
remove crossing
Definition: GNENet.cpp:579
const std::string getID() const
function to support debugging
void deleteGeometryPoint(const Position &pos, bool allowUndo=true)
delete the geometry point closest to the given pos
Definition: GNEPoly.cpp:387
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:249
DeleteOptions * myDeleteOptions
modul for delete options
begin/end of the description of an edge
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:50
const std::vector< GNELane * > & getLanes()
returns a reference to the lane vector
Definition: GNEEdge.cpp:832
virtual void show()
show Frame
Definition: GNEFrame.cpp:741
void deleteEdge(GNEEdge *edge, GNEUndoList *undoList, bool recomputeConnections)
removes edge
Definition: GNENet.cpp:431
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:53
#define GUIDesignGroupBoxFrame
Group box design extended over frame.
Definition: GUIDesigns.h:227
bool deleteOnlyGeometryPoints() const
check if only delete geometry points checkbox is enabled
crossing between edges for pedestrians
virtual void hide()
hide Frame
Definition: GNEFrame.cpp:750
void deleteJunction(GNEJunction *junction, GNEUndoList *undoList)
removes junction and all incident edges
Definition: GNENet.cpp:386
GNENet * getNet() const
get the net object
void removeAttributeCarrier(GNEAttributeCarrier *ac, bool ignoreOptions=false)
remove attribute carrier (element)
const std::vector< GNEAdditional * > & getAdditionalChilds() const
return vector of additionals that have as Parent this edge (For example, Calibrators) ...
Position getPositionInformation() const
Returns the cursor&#39;s x/y position within the network.
static const TagValues & getTagProperties(SumoXMLTag tag)
get Tag Properties
DeleteOptions(GNEDeleteFrame *deleteFrameParent)
constructor
FXCheckButton * myForceDeleteAdditionals
checkbox for enable/disable automatically delete additionals childs
begin/end of the description of a polygon
bool forceDeleteAdditionals() const
check if force delete additionals checkbox is enabled
void removeSelectedAttributeCarriers()
remove selected attribute carriers (element)
SumoXMLTag getTag() const
get XML Tag assigned to this object