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 
32 #include <netedit/GNENet.h>
34 #include <netedit/GNEUndoList.h>
35 #include <netedit/GNEViewParent.h>
36 
37 #include "GNEDeleteFrame.h"
38 #include "GNEAdditionalFrame.h"
39 
40 
41 // ---------------------------------------------------------------------------
42 // GNEDeleteFrame::DeleteOptions - methods
43 // ---------------------------------------------------------------------------
44 
46  FXGroupBox(deleteFrameParent->myContentFrame, "Options", GUIDesignGroupBoxFrame),
47  myDeleteFrameParent(deleteFrameParent) {
48 
49  // Create checkbox for enabling/disabling automatic deletion of additionals childs (by default, enabled)
50  myForceDeleteAdditionals = new FXCheckButton(this, "Force deletion of additionals", deleteFrameParent, MID_GNE_DELETEFRAME_AUTODELETEADDITIONALS, GUIDesignCheckButtonAttribute);
51  myForceDeleteAdditionals->setCheck(TRUE);
52 
53  // Create checkbox for enabling/disabling delete only geomtery point(by default, disabled)
54  myDeleteOnlyGeometryPoints = new FXCheckButton(this, "Delete only geometryPoints", deleteFrameParent, MID_GNE_DELETEFRAME_ONLYGEOMETRYPOINTS, GUIDesignCheckButtonAttribute);
55  myDeleteOnlyGeometryPoints->setCheck(FALSE);
56 }
57 
58 
60 
61 
62 bool
64  return (myForceDeleteAdditionals->getCheck() == TRUE);
65 }
66 
67 
68 bool
70  return (myDeleteOnlyGeometryPoints->getCheck() == TRUE);
71 }
72 
73 // ===========================================================================
74 // method definitions
75 // ===========================================================================
76 
77 GNEDeleteFrame::GNEDeleteFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet) :
78  GNEFrame(horizontalFrameParent, viewNet, "Delete") {
79  // create delete options modul
80  myDeleteOptions = new DeleteOptions(this);
81 
82  // Create groupbox and tree list
84 }
85 
86 
88 
89 void
91  if (myViewNet->getNet()->getSelectedAttributeCarriers().size() == 1) {
93  } else {
95  }
97 }
98 
99 
100 void
102 
103  GNEFrame::hide();
104 }
105 
106 
107 void
109  // remove all selected attribute carriers
110  myViewNet->getUndoList()->p_begin("remove selected items");
111  while (myViewNet->getNet()->getSelectedAttributeCarriers().size() > 0) {
113  }
115 }
116 
117 
118 void
120  // obtain clicked position
121  Position clickedPosition = myViewNet->getPositionInformation();
122  if (myDeleteOptions->deleteOnlyGeometryPoints() && !ignoreOptions) {
123  // check type of of GL object
124  switch (ac->getTagProperty().getTag()) {
125  case SUMO_TAG_EDGE: {
126  GNEEdge* edge = dynamic_cast<GNEEdge*>(ac);
127  if (edge && (edge->getVertexIndex(clickedPosition, false, false) != -1)) {
128  edge->deleteGeometryPoint(clickedPosition);
129  }
130  break;
131  }
132  case SUMO_TAG_POLY: {
133  GNEPoly* polygon = dynamic_cast<GNEPoly*>(ac);
134  if (polygon && (polygon->getVertexIndex(clickedPosition, false, false) != -1)) {
135  polygon->deleteGeometryPoint(clickedPosition);
136  }
137  break;
138  }
139  case SUMO_TAG_TAZ: {
140  GNETAZ* TAZ = dynamic_cast<GNETAZ*>(ac);
141  if (TAZ && TAZ->getVertexIndex(clickedPosition, false, false) != -1) {
142  TAZ->deleteGeometryPoint(clickedPosition);
143  }
144  break;
145  }
146  default: {
147  break;
148  }
149  }
150  } else {
151  // check type of of GL object
152  switch (ac->getTagProperty().getTag()) {
153  case SUMO_TAG_JUNCTION: {
154  GNEJunction* junction = dynamic_cast<GNEJunction*>(ac);
155  assert(junction);
156  // obtain number of additionals of junction's childs
157  int numberOfAdditionals = 0;
158  for (auto i : junction->getGNEEdges()) {
159  numberOfAdditionals += (int)i->getAdditionalChilds().size();
160  for (auto j : i->getLanes()) {
161  UNUSED_PARAMETER(j);
162  numberOfAdditionals += (int)i->getAdditionalChilds().size();
163  }
164  }
165  // Check if junction can be deleted
166  if (myDeleteOptions->forceDeleteAdditionals() || ignoreOptions) {
168  } else {
169  if (numberOfAdditionals > 0) {
170  // write warning if netedit is running in testing mode
171  WRITE_DEBUG("Opening FXMessageBox 'Force deletion needed'");
172  std::string plural = numberOfAdditionals > 1 ? "s" : "";
173  // Open warning DialogBox
174  FXMessageBox::warning(getViewNet()->getApp(), MBOX_OK, ("Problem deleting " + junction->getTagStr()).c_str(), "%s",
175  (junction->getTagStr() + " '" + junction->getID() + "' cannot be deleted because owns " +
176  toString(numberOfAdditionals) + " additional child" + plural + ".\n Check 'Force deletion of additionals' to force deletion.").c_str());
177  // write warning if netedit is running in testing mode
178  WRITE_DEBUG("Closed FXMessageBox 'Force deletion needed' with 'OK'");
179  } else {
181  }
182  }
183  break;
184  }
185  case SUMO_TAG_EDGE: {
186  GNEEdge* edge = dynamic_cast<GNEEdge*>(ac);
187  assert(edge);
188  // check if click was over a geometry point or over a shape's edge
189  if (edge->getVertexIndex(clickedPosition, false, false) != -1) {
190  edge->deleteGeometryPoint(clickedPosition);
191  } else {
192  int numberOfAdditionalChilds = (int)edge->getAdditionalChilds().size();
193  int numberOfAdditionalParents = (int)edge->getAdditionalParents().size();
194  // Iterate over lanes and obtain total number of additional childs
195  for (auto i : edge->getLanes()) {
196  numberOfAdditionalChilds += (int)i->getAdditionalChilds().size();
197  }
198  // Check if edge can be deleted
199  if (myDeleteOptions->forceDeleteAdditionals() || ignoreOptions) {
200  // when deleting a single edge, keep all unaffected connections as they were
201  myViewNet->getNet()->deleteEdge(edge, myViewNet->getUndoList(), false);
202  } else {
203  if (numberOfAdditionalChilds > 0) {
204  // write warning if netedit is running in testing mode
205  WRITE_DEBUG("Opening FXMessageBox 'Force deletion needed'");
206  std::string plural = numberOfAdditionalChilds > 1 ? "s" : "";
207  // Open warning DialogBox
208  FXMessageBox::warning(getViewNet()->getApp(), MBOX_OK, ("Problem deleting " + edge->getTagStr()).c_str(), "%s",
209  (edge->getTagStr() + " '" + edge->getID() + "' cannot be deleted because owns " +
210  toString(numberOfAdditionalChilds) + " additional" + plural + ".\n Check 'Force deletion of additionals' to force deletion.").c_str());
211  // write warning if netedit is running in testing mode
212  WRITE_DEBUG("Closed FXMessageBox 'Force deletion needed' with 'OK'");
213  } else if (numberOfAdditionalParents > 0) {
214  // write warning if netedit is running in testing mode
215  WRITE_DEBUG("Opening FXMessageBox 'Force deletion needed'");
216  std::string plural = numberOfAdditionalParents > 1 ? "s" : "";
217  // Open warning DialogBox
218  FXMessageBox::warning(getViewNet()->getApp(), MBOX_OK, ("Problem deleting " + edge->getTagStr()).c_str(), "%s",
219  (edge->getTagStr() + " '" + edge->getID() + "' cannot be deleted because is part of " +
220  toString(numberOfAdditionalParents) + " additional" + plural + ".\n Check 'Force deletion of additionals' to force deletion.").c_str());
221  // write warning if netedit is running in testing mode
222  WRITE_DEBUG("Closed FXMessageBox 'Force deletion needed' with 'OK'");
223  } else {
224  // when deleting a single edge, keep all unaffected connections as they were
225  myViewNet->getNet()->deleteEdge(edge, myViewNet->getUndoList(), false);
226  }
227  }
228  }
229  break;
230  }
231  case SUMO_TAG_LANE: {
232  GNELane* lane = dynamic_cast<GNELane*>(ac);
233  assert(lane);
234  // Check if lane can be deleted
235  if (myDeleteOptions->forceDeleteAdditionals() || ignoreOptions) {
236  // when deleting a single lane, keep all unaffected connections as they were
237  myViewNet->getNet()->deleteLane(lane, myViewNet->getUndoList(), false);
238  } else {
239  if (lane->getAdditionalChilds().size() == 0) {
240  // when deleting a single lane, keep all unaffected connections as they were
241  myViewNet->getNet()->deleteLane(lane, myViewNet->getUndoList(), false);
242  } else {
243  // write warning if netedit is running in testing mode
244  WRITE_DEBUG("Opening FXMessageBox 'Force deletion needed'");
245  // open warning box
246  FXMessageBox::warning(getViewNet()->getApp(), MBOX_OK, ("Problem deleting " + lane->getTagStr()).c_str(), "%s",
247  (lane->getTagStr() + " '" + lane->getID() + "' cannot be deleted because it has " +
248  toString(lane->getAdditionalChilds().size()) + " additional childs.\n Check 'Force deletion of Additionals' to force deletion.").c_str());
249  // write warning if netedit is running in testing mode
250  WRITE_DEBUG("Closed FXMessageBox 'Force deletion needed' with 'OK'");
251  }
252  }
253  break;
254  }
255  case SUMO_TAG_CROSSING: {
256  GNECrossing* crossing = dynamic_cast<GNECrossing*>(ac);
257  assert(crossing);
259  break;
260  }
261  case SUMO_TAG_CONNECTION: {
262  GNEConnection* connection = dynamic_cast<GNEConnection*>(ac);
263  assert(connection);
265  break;
266  }
267  default: {
268  // obtain tag property (only for improve code legibility)
269  const auto& tagValue = ac->getTagProperty();
270  if (tagValue.isAdditional()) {
271  GNEAdditional* additional = dynamic_cast<GNEAdditional*>(ac);
272  assert(additional);
274  } else if (tagValue.isShape()) {
275  GNEShape* shape = dynamic_cast<GNEShape*>(ac);
276  assert(shape);
278  }
279  break;
280  }
281  }
282  }
283  // update view to show changes
284  myViewNet->update();
285 }
286 
287 
290  return myDeleteOptions;
291 }
292 
293 /****************************************************************************/
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
a traffic assignment zone
void showACHierarchy(GNEAttributeCarrier *AC)
show ACHierarchy
Definition: GNEFrame.cpp:576
void show()
show delete frame
connectio between two lanes
void hideACHierarchy()
hide ACHierarchy
Definition: GNEFrame.cpp:587
GNEViewParent * getViewParent() const
get the net object
void deleteShape(GNEShape *shape, GNEUndoList *undoList)
remove shape
Definition: GNENet.cpp:572
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:540
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:73
ACHierarchy * myACHierarchy
modul for hierarchy
int getVertexIndex(Position pos, bool createIfNoExist, bool snapToGrid)
return index of a vertex of shape, or of a new vertex if position is over an shape&#39;s edge ...
Definition: GNEEdge.cpp:271
void deleteGeometryPoint(const Position &pos, bool allowUndo=true)
delete the geometry point closest to the given pos
Definition: GNETAZ.cpp:195
std::vector< GNEAttributeCarrier * > getSelectedAttributeCarriers()
get all selected attribute carriers
Definition: GNENet.cpp:1736
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:1720
void deleteGeometryPoint(const Position &pos, bool allowUndo=true)
delete the geometry point closest to the given pos
Definition: GNEEdge.cpp:383
GNEViewNet * myViewNet
View Net for changes.
Definition: GNEFrame.h:612
GNEAdditionalFrame * getAdditionalFrame() const
get frame for GNE_MODE_ADDITIONAL
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
SumoXMLTag getTag() const
get Tag vinculated with this attribute Property
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:504
~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:80
int getVertexIndex(Position pos, bool createIfNoExist, bool snapToGrid)
return index of a vertex of shape, or of a new vertex if position is over an shape&#39;s edge ...
Definition: GNETAZ.cpp:174
void removeAdditional(GNEAdditional *additional)
remove an additional element previously added
Definition: GNETAZ.h:35
void deleteCrossing(GNECrossing *crossing, GNEUndoList *undoList)
remove crossing
Definition: GNENet.cpp:555
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:386
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:248
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:873
virtual void show()
show Frame
Definition: GNEFrame.cpp:1695
void deleteEdge(GNEEdge *edge, GNEUndoList *undoList, bool recomputeConnections)
removes edge
Definition: GNENet.cpp:407
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:48
#define GUIDesignGroupBoxFrame
Group box design extended over frame.
Definition: GUIDesigns.h:227
bool deleteOnlyGeometryPoints() const
check if only delete geometry points checkbox is enabled
const std::string & getTagStr() const
get tag assigned to this object in string format
crossing between edges for pedestrians
virtual void hide()
hide Frame
Definition: GNEFrame.cpp:1704
void deleteJunction(GNEJunction *junction, GNEUndoList *undoList)
removes junction and all incident edges
Definition: GNENet.cpp:362
GNENet * getNet() const
get the net object
void removeAttributeCarrier(GNEAttributeCarrier *ac, bool ignoreOptions=false)
remove attribute carrier (element)
const TagProperties & getTagProperty() const
get Tag Property assigned to this object
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.
DeleteOptions(GNEDeleteFrame *deleteFrameParent)
constructor
FXCheckButton * myForceDeleteAdditionals
checkbox for enable/disable automatically delete additionals childs
int getVertexIndex(Position pos, bool createIfNoExist, bool snapToGrid)
return index of a vertex of shape, or of a new vertex if position is over an shape&#39;s edge ...
Definition: GNEPoly.cpp:365
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)