SUMO - Simulation of Urban MObility
GNEFrame.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 add additional elements
16 /****************************************************************************/
17 
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 
22 #include <config.h>
23 
24 #include <iostream>
43 #include <netedit/GNEUndoList.h>
44 #include <netedit/GNENet.h>
45 #include <netedit/GNEViewParent.h>
46 #include <netedit/GNEViewNet.h>
49 
50 #include "GNEFrame.h"
51 #include "GNEInspectorFrame.h"
52 #include "GNEPolygonFrame.h"
53 #include "GNEDeleteFrame.h"
54 
55 
56 // ===========================================================================
57 // FOX callback mapping
58 // ===========================================================================
59 
60 FXDEFMAP(GNEFrame::ACHierarchy) GNEFrameACHierarchyMap[] = {
65 };
66 
67 FXDEFMAP(GNEFrame::GenericParametersEditor) GenericParametersEditorMap[] = {
70 };
71 
72 // Object implementation
73 FXIMPLEMENT(GNEFrame::ACHierarchy, FXGroupBox, GNEFrameACHierarchyMap, ARRAYNUMBER(GNEFrameACHierarchyMap))
74 FXIMPLEMENT(GNEFrame::GenericParametersEditor, FXGroupBox, GenericParametersEditorMap, ARRAYNUMBER(GenericParametersEditorMap))
75 
76 
77 // ===========================================================================
78 // method definitions
79 // ===========================================================================
80 
81 // ---------------------------------------------------------------------------
82 // GNEFrame::ACHierarchy - methods
83 // ---------------------------------------------------------------------------
84 
86  FXGroupBox(frameParent->myContentFrame, "Hierarchy", GUIDesignGroupBoxFrame),
87  myFrameParent(frameParent),
88  myAC(nullptr) {
89  // Create three list
90  myTreelist = new FXTreeList(this, this, MID_GNE_DELETEFRAME_CHILDS, GUIDesignTreeListFrame);
91  hide();
92 }
93 
94 
96 
97 
98 void
100  myAC = AC;
101  // show ACHierarchy and refresh ACHierarchy
102  if (myAC) {
103  show();
105  }
106 }
107 
108 
109 void
111  myAC = nullptr;
112  hide();
113 }
114 
115 
116 void
118  // clear items
119  myTreelist->clearItems();
120  myTreeItemToACMap.clear();
121  myTreeItemsConnections.clear();
122  // show ACChilds of myAC
123  if (myAC) {
125  }
126 }
127 
128 
129 long
130 GNEFrame::ACHierarchy::onCmdShowChildMenu(FXObject*, FXSelector, void* eventData) {
131  // Obtain event
132  FXEvent* e = (FXEvent*)eventData;
133  // obtain FXTreeItem in the given position
134  FXTreeItem* item = myTreelist->getItemAt(e->win_x, e->win_y);
135  // open Pop-up if FXTreeItem has a Attribute Carrier vinculated
136  if (item && (myTreeItemsConnections.find(item) == myTreeItemsConnections.end())) {
137  createPopUpMenu(e->root_x, e->root_y, myTreeItemToACMap[item]);
138  }
139  return 1;
140 }
141 
142 
143 long
144 GNEFrame::ACHierarchy::onCmdCenterItem(FXObject*, FXSelector, void*) {
145  GUIGlObject* glObject = dynamic_cast<GUIGlObject*>(myRightClickedAC);
146  if (glObject) {
147  myFrameParent->getViewNet()->centerTo(glObject->getGlID(), false);
148  myFrameParent->getViewNet()->update();
149  }
150  return 1;
151 }
152 
153 
154 long
155 GNEFrame::ACHierarchy::onCmdInspectItem(FXObject*, FXSelector, void*) {
156  if ((myAC != nullptr) && (myRightClickedAC != nullptr)) {
158  }
159  return 1;
160 }
161 
162 
163 long
164 GNEFrame::ACHierarchy::onCmdDeleteItem(FXObject*, FXSelector, void*) {
165  // check if Inspector frame was opened before removing
166  const std::vector<GNEAttributeCarrier*>& currentInspectedACs = myFrameParent->getViewNet()->getViewParent()->getInspectorFrame()->getInspectedACs();
167  // Remove Attribute Carrier
170  // check if inspector frame has to be shown again
171  if (currentInspectedACs.size() == 1) {
172  if (currentInspectedACs.front() != myRightClickedAC) {
173  myFrameParent->getViewNet()->getViewParent()->getInspectorFrame()->inspectElement(currentInspectedACs.front());
174  } else {
176  }
177  }
178  return 1;
179 }
180 
181 
182 void
184  // create FXMenuPane
185  FXMenuPane* pane = new FXMenuPane(myTreelist);
186  // set current clicked AC
187  myRightClickedAC = ac;
188  // set name
190  new FXMenuSeparator(pane);
191  // Fill FXMenuCommand
192  new FXMenuCommand(pane, "Center", GUIIconSubSys::getIcon(ICON_RECENTERVIEW), this, MID_GNE_INSPECTORFRAME_CENTER);
193  new FXMenuCommand(pane, "Inspect", GUIIconSubSys::getIcon(ICON_MODEINSPECT), this, MID_GNE_INSPECTORFRAME_INSPECT);
194  new FXMenuCommand(pane, "Delete", GUIIconSubSys::getIcon(ICON_MODEDELETE), this, MID_GNE_INSPECTORFRAME_DELETE);
195  // Center in the mouse position and create pane
196  pane->setX(X);
197  pane->setY(Y);
198  pane->create();
199  pane->show();
200 }
201 
202 
203 FXTreeItem*
205  // Switch gl type of ac
206  switch (myAC->getTag()) {
207  case SUMO_TAG_EDGE: {
208  // obtain Edge
209  GNEEdge* edge = myFrameParent->getViewNet()->getNet()->retrieveEdge(myAC->getID(), false);
210  if (edge) {
211  // insert Junctions of edge in tree (Pararell because a edge has always two Junctions)
212  FXTreeItem* junctionSourceItem = myTreelist->insertItem(nullptr, nullptr, (edge->getGNEJunctionSource()->getHierarchyName() + " origin").c_str(), edge->getGNEJunctionSource()->getIcon(), edge->getGNEJunctionSource()->getIcon());
213  FXTreeItem* junctionDestinyItem = myTreelist->insertItem(nullptr, nullptr, (edge->getGNEJunctionSource()->getHierarchyName() + " destiny").c_str(), edge->getGNEJunctionSource()->getIcon(), edge->getGNEJunctionSource()->getIcon());
214  junctionDestinyItem->setExpanded(true);
215  // Save items in myTreeItemToACMap
216  myTreeItemToACMap[junctionSourceItem] = edge->getGNEJunctionSource();
217  myTreeItemToACMap[junctionDestinyItem] = edge->getGNEJunctionDestiny();
218  // return junction destiny Item
219  return junctionDestinyItem;
220  } else {
221  return nullptr;
222  }
223  }
224  case SUMO_TAG_LANE: {
225  // obtain lane
226  GNELane* lane = myFrameParent->getViewNet()->getNet()->retrieveLane(myAC->getID(), false);
227  if (lane) {
228  // obtain edge parent
230  //inser Junctions of lane of edge in tree (Pararell because a edge has always two Junctions)
231  FXTreeItem* junctionSourceItem = myTreelist->insertItem(nullptr, nullptr, (edge->getGNEJunctionSource()->getHierarchyName() + " origin").c_str(), edge->getGNEJunctionSource()->getIcon(), edge->getGNEJunctionSource()->getIcon());
232  FXTreeItem* junctionDestinyItem = myTreelist->insertItem(nullptr, nullptr, (edge->getGNEJunctionSource()->getHierarchyName() + " destiny").c_str(), edge->getGNEJunctionSource()->getIcon(), edge->getGNEJunctionSource()->getIcon());
233  junctionDestinyItem->setExpanded(true);
234  // Create edge item
235  FXTreeItem* edgeItem = myTreelist->insertItem(nullptr, junctionDestinyItem, edge->getHierarchyName().c_str(), edge->getIcon(), edge->getIcon());
236  edgeItem->setExpanded(true);
237  // Save items in myTreeItemToACMap
238  myTreeItemToACMap[junctionSourceItem] = edge->getGNEJunctionSource();
239  myTreeItemToACMap[junctionDestinyItem] = edge->getGNEJunctionDestiny();
240  myTreeItemToACMap[edgeItem] = edge;
241  // return edge item
242  return edgeItem;
243  } else {
244  return nullptr;
245  }
246  }
247  case SUMO_TAG_POILANE: {
248  // Obtain POILane
249  GNEPOI* POILane = myFrameParent->getViewNet()->getNet()->retrievePOI(myAC->getID(), false);
250  if (POILane) {
251  // obtain lane parent
252  GNELane* lane = myFrameParent->getViewNet()->getNet()->retrieveLane(POILane->getLane()->getID());
253  // obtain edge parent
255  //inser Junctions of lane of edge in tree (Pararell because a edge has always two Junctions)
256  FXTreeItem* junctionSourceItem = myTreelist->insertItem(nullptr, nullptr, (edge->getGNEJunctionSource()->getHierarchyName() + " origin").c_str(), edge->getGNEJunctionSource()->getIcon(), edge->getGNEJunctionSource()->getIcon());
257  FXTreeItem* junctionDestinyItem = myTreelist->insertItem(nullptr, nullptr, (edge->getGNEJunctionSource()->getHierarchyName() + " destiny").c_str(), edge->getGNEJunctionSource()->getIcon(), edge->getGNEJunctionSource()->getIcon());
258  junctionDestinyItem->setExpanded(true);
259  // Create edge item
260  FXTreeItem* edgeItem = myTreelist->insertItem(nullptr, junctionDestinyItem, edge->getHierarchyName().c_str(), edge->getIcon(), edge->getIcon());
261  edgeItem->setExpanded(true);
262  // Create lane item
263  FXTreeItem* laneItem = myTreelist->insertItem(0, edgeItem, lane->getHierarchyName().c_str(), lane->getIcon(), lane->getIcon());
264  laneItem->setExpanded(true);
265  // Save items in myTreeItemToACMap
266  myTreeItemToACMap[junctionSourceItem] = edge->getGNEJunctionSource();
267  myTreeItemToACMap[junctionDestinyItem] = edge->getGNEJunctionDestiny();
268  myTreeItemToACMap[edgeItem] = edge;
269  myTreeItemToACMap[laneItem] = lane;
270  // return Lane item
271  return laneItem;
272  } else {
273  return nullptr;
274  }
275  }
276  case SUMO_TAG_CROSSING: {
277  // obtain Crossing
278  GNECrossing* crossing = myFrameParent->getViewNet()->getNet()->retrieveCrossing(myAC->getID(), false);
279  if (crossing) {
280  // obtain junction
281  GNEJunction* junction = crossing->getParentJunction();
282  // create junction item
283  FXTreeItem* junctionItem = myTreelist->insertItem(nullptr, nullptr, junction->getHierarchyName().c_str(), junction->getIcon(), junction->getIcon());
284  junctionItem->setExpanded(true);
285  // Save items in myTreeItemToACMap
286  myTreeItemToACMap[junctionItem] = junction;
287  // return junction Item
288  return junctionItem;
289  } else {
290  return nullptr;
291  }
292  }
293  case SUMO_TAG_CONNECTION: {
294  // obtain Connection
295  GNEConnection* connection = myFrameParent->getViewNet()->getNet()->retrieveConnection(myAC->getID(), false);
296  if (connection) {
297  // create edge from item
298  FXTreeItem* edgeFromItem = myTreelist->insertItem(nullptr, nullptr, connection->getEdgeFrom()->getHierarchyName().c_str(), connection->getEdgeFrom()->getIcon(), connection->getEdgeFrom()->getIcon());
299  edgeFromItem->setExpanded(true);
300  // create edge to item
301  FXTreeItem* edgeToItem = myTreelist->insertItem(nullptr, nullptr, connection->getEdgeTo()->getHierarchyName().c_str(), connection->getEdgeTo()->getIcon(), connection->getEdgeTo()->getIcon());
302  edgeToItem->setExpanded(true);
303  // create connection item
304  FXTreeItem* connectionItem = myTreelist->insertItem(0, edgeToItem, connection->getHierarchyName().c_str(), connection->getIcon(), connection->getIcon());
305  connectionItem->setExpanded(true);
306  // Save items in myTreeItemToACMap
307  myTreeItemToACMap[edgeFromItem] = connection->getEdgeFrom();
308  myTreeItemToACMap[edgeToItem] = connection->getEdgeTo();
309  myTreeItemToACMap[connectionItem] = connection;
310  // return connection item
311  return connectionItem;
312  } else {
313  return nullptr;
314  }
315  }
316  default: {
317  // obtain tag property (only for improve code legibility)
318  const auto& tagValue = GNEAttributeCarrier::getTagProperties(myAC->getTag());
319  // check if is an additional, and in other case return nullptr
320  if (tagValue.isAdditional()) {
321  // Obtain Additional
323  if (additional) {
324  // first check if additional has another additional as parent (to add it into root)
325  if (tagValue.hasParent()) {
326  GNEAdditional* additionalParent = myFrameParent->getViewNet()->getNet()->retrieveAdditional(tagValue.getParentTag(), additional->getAttribute(GNE_ATTR_PARENT));
327  // create additional parent item
328  FXTreeItem* additionalParentItem = myTreelist->insertItem(0, 0, additionalParent->getHierarchyName().c_str(), additionalParent->getIcon(), additionalParent->getIcon());
329  additionalParentItem->setExpanded(true);
330  // Save it in myTreeItemToACMap
331  myTreeItemToACMap[additionalParentItem] = additionalParent;
332  }
333  if (tagValue.hasAttribute(SUMO_ATTR_EDGE)) {
334  // obtain edge parent
336  //inser Junctions of lane of edge in tree (Pararell because a edge has always two Junctions)
337  FXTreeItem* junctionSourceItem = myTreelist->insertItem(nullptr, nullptr, (edge->getGNEJunctionSource()->getHierarchyName() + " origin").c_str(), edge->getGNEJunctionSource()->getIcon(), edge->getGNEJunctionSource()->getIcon());
338  FXTreeItem* junctionDestinyItem = myTreelist->insertItem(nullptr, nullptr, (edge->getGNEJunctionSource()->getHierarchyName() + " destiny").c_str(), edge->getGNEJunctionSource()->getIcon(), edge->getGNEJunctionSource()->getIcon());
339  junctionDestinyItem->setExpanded(true);
340  // Create edge item
341  FXTreeItem* edgeItem = myTreelist->insertItem(nullptr, junctionDestinyItem, edge->getHierarchyName().c_str(), edge->getIcon(), edge->getIcon());
342  edgeItem->setExpanded(true);
343  // Save items in myTreeItemToACMap
344  myTreeItemToACMap[junctionSourceItem] = edge->getGNEJunctionSource();
345  myTreeItemToACMap[junctionDestinyItem] = edge->getGNEJunctionDestiny();
346  myTreeItemToACMap[edgeItem] = edge;
347  // return edge item
348  return edgeItem;
349  } else if (tagValue.hasAttribute(SUMO_ATTR_LANE)) {
350  // obtain lane parent
352  // obtain edge parent
354  //inser Junctions of lane of edge in tree (Pararell because a edge has always two Junctions)
355  FXTreeItem* junctionSourceItem = myTreelist->insertItem(nullptr, nullptr, (edge->getGNEJunctionSource()->getHierarchyName() + " origin").c_str(), edge->getGNEJunctionSource()->getIcon(), edge->getGNEJunctionSource()->getIcon());
356  FXTreeItem* junctionDestinyItem = myTreelist->insertItem(nullptr, nullptr, (edge->getGNEJunctionSource()->getHierarchyName() + " destiny").c_str(), edge->getGNEJunctionSource()->getIcon(), edge->getGNEJunctionSource()->getIcon());
357  junctionDestinyItem->setExpanded(true);
358  // Create edge item
359  FXTreeItem* edgeItem = myTreelist->insertItem(nullptr, junctionDestinyItem, edge->getHierarchyName().c_str(), edge->getIcon(), edge->getIcon());
360  edgeItem->setExpanded(true);
361  // Create lane item
362  FXTreeItem* laneItem = myTreelist->insertItem(0, edgeItem, lane->getHierarchyName().c_str(), lane->getIcon(), lane->getIcon());
363  laneItem->setExpanded(true);
364  // Save items in myTreeItemToACMap
365  myTreeItemToACMap[junctionSourceItem] = edge->getGNEJunctionSource();
366  myTreeItemToACMap[junctionDestinyItem] = edge->getGNEJunctionDestiny();
367  myTreeItemToACMap[edgeItem] = edge;
368  myTreeItemToACMap[laneItem] = lane;
369  // return lane item
370  return laneItem;
371  }
372  }
373  }
374  return nullptr;
375  }
376  }
377 }
378 
379 
380 void
382  // Switch gl type of ac
383  switch (AC->getTag()) {
384  case SUMO_TAG_JUNCTION: {
385  // retrieve junction
386  GNEJunction* junction = myFrameParent->getViewNet()->getNet()->retrieveJunction(AC->getID(), false);
387  if (junction) {
388  // insert junction item
389  FXTreeItem* junctionItem = addACIntoList(AC, itemParent);
390  // insert edges
391  for (auto i : junction->getGNEEdges()) {
392  showAttributeCarrierChilds(i, junctionItem);
393  }
394  // insert crossings
395  for (auto i : junction->getGNECrossings()) {
396  showAttributeCarrierChilds(i, junctionItem);
397  }
398  }
399  break;
400  }
401  case SUMO_TAG_EDGE: {
402  // retrieve edge
403  GNEEdge* edge = myFrameParent->getViewNet()->getNet()->retrieveEdge(AC->getID(), false);
404  if (edge) {
405  // insert edge item
406  FXTreeItem* edgeItem = addACIntoList(AC, itemParent);
407  // insert lanes
408  for (int i = 0; i < (int)edge->getLanes().size(); i++) {
409  showAttributeCarrierChilds(edge->getLanes().at(i), edgeItem);
410  }
411  // insert additionals of edge
412  for (auto i : edge->getAdditionalChilds()) {
413  showAttributeCarrierChilds(i, edgeItem);
414  }
415  }
416  break;
417  }
418  case SUMO_TAG_LANE: {
419  // retrieve lane
420  GNELane* lane = myFrameParent->getViewNet()->getNet()->retrieveLane(AC->getID(), false);
421  if (lane) {
422  // insert lane item
423  FXTreeItem* laneItem = addACIntoList(AC, itemParent);
424  // insert additionals of lanes
425  for (auto i : lane->getAdditionalChilds()) {
426  showAttributeCarrierChilds(i, laneItem);
427  }
428  // insert incoming connections of lanes (by default isn't expanded)
429  if (lane->getGNEIncomingConnections().size() > 0) {
430  std::vector<GNEConnection*> incomingLaneConnections = lane->getGNEIncomingConnections();
431  FXTreeItem* incomingConnections = myTreelist->insertItem(0, laneItem, "Incomings", incomingLaneConnections.front()->getIcon(), lane->getGNEIncomingConnections().front()->getIcon());
432  myTreeItemsConnections.insert(incomingConnections);
433  incomingConnections->setExpanded(false);
434  // insert incoming connections
435  for (auto i : incomingLaneConnections) {
436  showAttributeCarrierChilds(i, incomingConnections);
437  }
438  }
439  // insert outcoming connections of lanes (by default isn't expanded)
440  if (lane->getGNEOutcomingConnections().size() > 0) {
441  std::vector<GNEConnection*> outcomingLaneConnections = lane->getGNEOutcomingConnections();
442  FXTreeItem* outgoingConnections = myTreelist->insertItem(0, laneItem, "Outcomings", outcomingLaneConnections.front()->getIcon(), lane->getGNEOutcomingConnections().front()->getIcon());
443  myTreeItemsConnections.insert(outgoingConnections);
444  outgoingConnections->setExpanded(false);
445  // insert outcoming connections
446  for (auto i : outcomingLaneConnections) {
447  showAttributeCarrierChilds(i, outgoingConnections);
448  }
449  }
450  }
451  break;
452  }
453  case SUMO_TAG_POI:
454  case SUMO_TAG_POLY:
455  case SUMO_TAG_CROSSING:
456  case SUMO_TAG_CONNECTION: {
457  // insert connection item
458  addACIntoList(AC, itemParent);
459  break;
460  }
461  default: {
462  // check if is an additional
463  if (GNEAttributeCarrier::getTagProperties(AC->getTag()).isAdditional()) {
464  // retrieve additional
465  GNEAdditional* additional = myFrameParent->getViewNet()->getNet()->retrieveAdditional(AC->getTag(), AC->getID(), false);
466  if (additional) {
467  // insert additional item
468  FXTreeItem* additionalItem = addACIntoList(AC, itemParent);
469  // insert additionals childs
470  for (auto i : additional->getAdditionalChilds()) {
471  showAttributeCarrierChilds(i, additionalItem);
472  }
473  }
474  }
475  break;
476  }
477  }
478 }
479 
480 
481 FXTreeItem*
483  FXTreeItem* item = myTreelist->insertItem(0, itemParent, AC->getHierarchyName().c_str(), AC->getIcon(), AC->getIcon());
484  myTreeItemToACMap[item] = AC;
485  item->setExpanded(true);
486  return item;
487 }
488 
489 // ---------------------------------------------------------------------------
490 // GNEFrame::GenericParametersEditor - methods
491 // ---------------------------------------------------------------------------
492 
494  FXGroupBox(inspectorFrameParent->myContentFrame, "Generic parameters", GUIDesignGroupBoxFrame),
495  myFrameParent(inspectorFrameParent),
496  myAC(nullptr),
497  myGenericParameters(nullptr) {
498  // create empty vector with generic parameters
499  myGenericParameters = new std::vector<std::pair<std::string, std::string> >;
500  // create textfield and buttons
502  myEditGenericParameterButton = new FXButton(this, "Edit generic parameter", 0, this, MID_GNE_SET_ATTRIBUTE_DIALOG, GUIDesignButton);
503 }
504 
505 
507  delete myGenericParameters;
508 }
509 
510 
511 void
513  if (AC != nullptr) {
514  myAC = AC;
515  myACs.clear();
516  // obtain a copy of generic parameters of AC
517  if (myAC) {
519  }
520  // refresh GenericParametersEditor
522  // show groupbox
523  show();
524  }
525 }
526 
527 
528 void
530  if (ACs.size() > 0) {
531  myAC = nullptr;
532  myACs = ACs;
533  // check if generic parameters are different
534  bool differentsGenericParameters = false;
535  std::string genericParameter = myACs.front()->getAttribute(GNE_ATTR_GENERIC);
536  for (auto i : myACs) {
537  if (genericParameter != i->getAttribute(GNE_ATTR_GENERIC)) {
538  differentsGenericParameters = true;
539  }
540  }
541  // set generic Parameters editor
542  if (differentsGenericParameters) {
543  myGenericParameters->clear();
544  } else {
545  *myGenericParameters = myACs.front()->getGenericParameters();
546  }
547  // refresh GenericParametersEditor
549  // show groupbox
550  show();
551  }
552 }
553 
554 
555 void
557  myAC = nullptr;
558  // hide groupbox
559  hide();
560 }
561 
562 
563 void
565  // update text field depending of AC
566  if (myAC) {
568  myTextFieldGenericParameter->setTextColor(FXRGB(0, 0, 0));
569  } else if (myACs.size()) {
570  // check if generic parameters of all inspected ACs are different
571  std::string genericParameter = myACs.front()->getAttribute(GNE_ATTR_GENERIC);
572 
573  for (auto i : myACs) {
574  if (genericParameter != i->getAttribute(GNE_ATTR_GENERIC)) {
575  genericParameter = "different generic attributes";
576  }
577  }
578  myTextFieldGenericParameter->setText(genericParameter.c_str());
579  myTextFieldGenericParameter->setTextColor(FXRGB(0, 0, 0));
580  }
581 }
582 
583 
584 std::string
586  std::string result;
587  // Generate an string using the following structure: "key1=value1|key2=value2|...
588  for (auto i = myGenericParameters->begin(); i != myGenericParameters->end(); i++) {
589  result += i->first + "=" + i->second + "|";
590  }
591  // remove the last "|"
592  if (!result.empty()) {
593  result.pop_back();
594  }
595  return result;
596 }
597 
598 
599 long
601  // edit generic parameters using dialog
603  // set values edited in Parameter dialog in Edited AC
604  if (myAC) {
606  } else if (myACs.size() > 0) {
607  myFrameParent->getViewNet()->getUndoList()->p_begin("Change multiple generic attributes");
608  for (auto i : myACs) {
610  }
612  }
613  // Refresh parameter editor
615  }
616  return 1;
617 }
618 
619 
620 long
622  // separate value in a vector of string using | as separator
623  std::vector<std::string> parsedValues;
624  StringTokenizer st(myTextFieldGenericParameter->getText().text(), "|", true);
625  while (st.hasNext()) {
626  parsedValues.push_back(st.next());
627  }
628  // first check if parsed generic parameters are valid
629  for (auto i : parsedValues) {
631  WRITE_WARNING("Invalid format of Generic Parameter (" + i + ")");
632  myTextFieldGenericParameter->setTextColor(FXRGB(255, 0, 0));
633  return 1;
634  }
635  }
636  // now check if there is duplicated parameters
637  std::sort(parsedValues.begin(), parsedValues.end());
638  for (auto i = parsedValues.begin(); i != parsedValues.end(); i++) {
639  if (((i + 1) != parsedValues.end())) {
640  std::vector<std::string> firstKey, secondKey;
641  StringTokenizer stKey1(*i, "=", true);
642  StringTokenizer stKey2(*(i + 1), "=", true);
643  //parse both keys
644  while (stKey1.hasNext()) {
645  firstKey.push_back(stKey1.next());
646  }
647  while (stKey2.hasNext()) {
648  secondKey.push_back(stKey2.next());
649  }
650  // compare both keys and stop if are equal
651  if ((firstKey.size() != 2) || (secondKey.size() != 2) || (firstKey.front() == secondKey.front())) {
652  WRITE_WARNING("Generic Parameters wit the same key aren't allowed (" + (*i) + "," + * (i + 1) + ")");
653  myTextFieldGenericParameter->setTextColor(FXRGB(255, 0, 0));
654  return 1;
655  }
656  }
657  }
658  // parsed generic parameters ok, then set text field black and continue
659  myTextFieldGenericParameter->setTextColor(FXRGB(0, 0, 0));
660  myTextFieldGenericParameter->killFocus();
661  // clear current existent generic parameters and set parsed generic parameters
662  myGenericParameters->clear();
663  for (auto i : parsedValues) {
664  std::vector<std::string> parsedParameters;
665  StringTokenizer stParam(i, "=", true);
666  while (stParam.hasNext()) {
667  parsedParameters.push_back(stParam.next());
668  }
669  // Check that parsed parameters are exactly two and contains valid chracters
670  if (parsedParameters.size() == 2 && SUMOXMLDefinitions::isValidGenericParameterKey(parsedParameters.front()) && SUMOXMLDefinitions::isValidGenericParameterValue(parsedParameters.back())) {
671  myGenericParameters->push_back(std::make_pair(parsedParameters.front(), parsedParameters.back()));
672  }
673  }
674  // if we're editing generic attributes of an AttributeCarrier, set it
675  if (myAC) {
677  } else if (myACs.size() > 0) {
678  myFrameParent->getViewNet()->getUndoList()->p_begin("Change multiple generic attributes");
679  for (auto i : myACs) {
681  }
683  }
684  return 1;
685 }
686 
687 // ---------------------------------------------------------------------------
688 // GNEFrame - methods
689 // ---------------------------------------------------------------------------
690 
691 GNEFrame::GNEFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet, const std::string& frameLabel) :
692  FXVerticalFrame(horizontalFrameParent, GUIDesignAuxiliarFrame),
693  myViewNet(viewNet) {
694 
695  // Create font
696  myFrameHeaderFont = new FXFont(getApp(), "Arial", 14, FXFont::Bold),
697 
698  // Create frame for header
699  myHeaderFrame = new FXHorizontalFrame(this, GUIDesignAuxiliarHorizontalFrame);
700 
701  // Create frame for left elements of header (By default unused)
703  myHeaderLeftFrame->hide();
704 
705  // Create titel frame
706  myFrameHeaderLabel = new FXLabel(myHeaderFrame, frameLabel.c_str(), 0, GUIDesignLabelFrameInformation);
707 
708  // Create frame for right elements of header (By default unused)
710  myHeaderRightFrame->hide();
711 
712  // Add separator
713  new FXHorizontalSeparator(this, GUIDesignHorizontalSeparator);
714 
715  // Create frame for contents
716  myScrollWindowsContents = new FXScrollWindow(this, GUIDesignContentsScrollWindow);
717 
718  // Create frame for contents
720 
721  // Set font of header
723 
724  // Hide Frame
725  FXVerticalFrame::hide();
726 }
727 
728 
730  delete myFrameHeaderFont;
731 }
732 
733 
734 void
736  myFrameHeaderLabel->setFocus();
737 }
738 
739 
740 void
742  // show scroll window
743  FXVerticalFrame::show();
744  // Show and update Frame Area in which this GNEFrame is placed
746 }
747 
748 
749 void
751  // hide scroll window
752  FXVerticalFrame::hide();
753  // Hide Frame Area in which this GNEFrame is placed
755 }
756 
757 
758 void
759 GNEFrame::setFrameWidth(int newWidth) {
760  setWidth(newWidth);
761  myScrollWindowsContents->setWidth(newWidth);
762 }
763 
764 
765 GNEViewNet*
767  return myViewNet;
768 }
769 
770 
771 FXLabel*
773  return myFrameHeaderLabel;
774 }
775 
776 
777 FXFont*
779  return myFrameHeaderFont;
780 }
781 
782 
783 void
785  FXDialogBox* attributesHelpDialog = new FXDialogBox(myScrollWindowsContents, ("Parameters of " + toString(elementTag)).c_str(), GUIDesignDialogBoxResizable, 0, 0, 0, 0, 10, 10, 10, 38, 4, 4);
786  // Create FXTable
787  FXTable* myTable = new FXTable(attributesHelpDialog, attributesHelpDialog, MID_TABLE, GUIDesignTableNotEditable);
788  attributesHelpDialog->setIcon(GUIIconSubSys::getIcon(ICON_MODEINSPECT));
789  const auto& attrs = GNEAttributeCarrier::getTagProperties(elementTag);
790  int sizeColumnDescription = 0;
791  int sizeColumnDefinitions = 0;
792  myTable->setVisibleRows((FXint)(attrs.getNumberOfAttributes()));
793  myTable->setVisibleColumns(3);
794  myTable->setTableSize((FXint)(attrs.getNumberOfAttributes()), 3);
795  myTable->setBackColor(FXRGB(255, 255, 255));
796  myTable->setColumnText(0, "Attribute");
797  myTable->setColumnText(1, "Description");
798  myTable->setColumnText(2, "Definition");
799  myTable->getRowHeader()->setWidth(0);
800  // Iterate over vector of additional parameters
801  int itemIndex = 0;
802  for (auto i : attrs) {
803  // Set attribute
804  FXTableItem* attribute = new FXTableItem(toString(i.first).c_str());
805  attribute->setJustify(FXTableItem::CENTER_X);
806  myTable->setItem(itemIndex, 0, attribute);
807  // Set description of element
808  FXTableItem* type = new FXTableItem("");
809  type->setText(i.second.getDescription().c_str());
810  sizeColumnDescription = MAX2(sizeColumnDescription, (int)i.second.getDescription().size());
811  type->setJustify(FXTableItem::CENTER_X);
812  myTable->setItem(itemIndex, 1, type);
813  // Set definition
814  FXTableItem* definition = new FXTableItem(i.second.getDefinition().c_str());
815  definition->setJustify(FXTableItem::LEFT);
816  myTable->setItem(itemIndex, 2, definition);
817  sizeColumnDefinitions = MAX2(sizeColumnDefinitions, (int)i.second.getDefinition().size());
818  itemIndex++;
819  }
820  // set header
821  FXHeader* header = myTable->getColumnHeader();
822  header->setItemJustify(0, JUSTIFY_CENTER_X);
823  header->setItemSize(0, 120);
824  header->setItemJustify(1, JUSTIFY_CENTER_X);
825  header->setItemSize(1, sizeColumnDescription * 7);
826  header->setItemJustify(2, JUSTIFY_CENTER_X);
827  header->setItemSize(2, sizeColumnDefinitions * 6);
828  // Create horizontal separator
829  new FXHorizontalSeparator(attributesHelpDialog, GUIDesignHorizontalSeparator);
830  // Create frame for OK Button
831  FXHorizontalFrame* myHorizontalFrameOKButton = new FXHorizontalFrame(attributesHelpDialog, GUIDesignAuxiliarHorizontalFrame);
832  // Create Button Close (And two more horizontal frames to center it)
833  new FXHorizontalFrame(myHorizontalFrameOKButton, GUIDesignAuxiliarHorizontalFrame);
834  new FXButton(myHorizontalFrameOKButton, "OK\t\tclose", GUIIconSubSys::getIcon(ICON_ACCEPT), attributesHelpDialog, FXDialogBox::ID_ACCEPT, GUIDesignButtonOK);
835  new FXHorizontalFrame(myHorizontalFrameOKButton, GUIDesignAuxiliarHorizontalFrame);
836  // Write Warning in console if we're in testing mode
837  WRITE_DEBUG("Opening HelpAttributes dialog for tag '" + toString(elementTag) + "' showing " + toString(attrs.getNumberOfAttributes()) + " attributes");
838  // create Dialog
839  attributesHelpDialog->create();
840  // show in the given position
841  attributesHelpDialog->show(PLACEMENT_CURSOR);
842  // refresh APP
843  getApp()->refresh();
844  // open as modal dialog (will block all windows until stop() or stopModal() is called)
845  getApp()->runModalFor(attributesHelpDialog);
846  // Write Warning in console if we're in testing mode
847  WRITE_DEBUG("Closing HelpAttributes dialog for tag '" + toString(elementTag) + "'");
848 }
849 
850 /****************************************************************************/
void hideGenericParametersEditor()
hide netedit attributes editor
Definition: GNEFrame.cpp:556
GNEFrame()
FOX needs this.
Definition: GNEFrame.h:226
SumoXMLTag
Numbers representing SUMO-XML - element names.
GNEInspectorFrame * getInspectorFrame() const
get frame for GNE_MODE_INSPECT
GNEEdge * retrieveEdge(const std::string &id, bool failHard=true)
get edge by id
Definition: GNENet.cpp:907
void hideFramesArea()
hide frames area if all GNEFrames are hidden
std::string next()
void hide()
hide delete frame
void inspectElement(GNEAttributeCarrier *AC)
Inspect a single element.
begin/end of the description of a junction
begin/end of the description of a single lane
FXLabel * getFrameHeaderLabel() const
get the label for the frame&#39;s header
Definition: GNEFrame.cpp:772
FXTreeItem * showAttributeCarrierParents()
show child of current attributeCarrier
Definition: GNEFrame.cpp:204
FXFont * myFrameHeaderFont
Font for the Header.
Definition: GNEFrame.h:251
FXHorizontalFrame * myHeaderRightFrame
fame for right header elements
Definition: GNEFrame.h:244
void showACHierarchy(GNEAttributeCarrier *AC)
show ACHierarchy
Definition: GNEFrame.cpp:99
Definition: GNEPOI.h:44
connectio between two lanes
void hideACHierarchy()
hide ACHierarchy
Definition: GNEFrame.cpp:110
In GNEINSPECTORFRAME, inspect element.
Definition: GUIAppEnum.h:581
GNEViewParent * getViewParent() const
get the net object
std::map< FXTreeItem *, GNEAttributeCarrier * > myTreeItemToACMap
map used to save the Tree items with their AC
Definition: GNEFrame.h:117
GNEConnection * retrieveConnection(const std::string &id, bool failHard=true) const
get Connection by id
Definition: GNENet.cpp:966
long onCmdDeleteItem(FXObject *, FXSelector, void *)
called when user select option "delte item" of child menu
Definition: GNEFrame.cpp:164
void showFramesArea()
show frames area if at least a GNEFrame is showed
#define GUIDesignContentsFrame
design for the main content frame of every frame/dialog
Definition: GUIDesigns.h:267
GNEFrame * myFrameParent
pointer to inspector frame parent
Definition: GNEFrame.h:180
GNEPOI * retrievePOI(const std::string &id, bool failHard=true) const
get POI by id
Definition: GNENet.cpp:953
GNEAttributeCarrier * myRightClickedAC
pointer to current right clicked Attribute Carrier
Definition: GNEFrame.h:123
void refreshGenericParametersEditor()
refresh netedit attributes
Definition: GNEFrame.cpp:564
FXIcon * getIcon() const
get FXIcon associated to this AC
T MAX2(T a, T b)
Definition: StdDefs.h:68
FXScrollWindow * myScrollWindowsContents
scroll windows that holds the content frame
Definition: GNEFrame.h:248
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
FXFont * getFrameHeaderFont() const
get font of the header&#39;s frame
Definition: GNEFrame.cpp:778
FXHorizontalFrame * myHeaderFrame
fame for header elements
Definition: GNEFrame.h:238
begin/end of the description of a Point of interest
#define GUIDesignTreeListFrame
Tree list used in frames to represent childs of elements.
Definition: GUIDesigns.h:487
GNELane * getLane() const
get GNELane
Definition: GNEPOI.cpp:161
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
void openHelpAttributesDialog(SumoXMLTag tag) const
Open help attributes dialog.
Definition: GNEFrame.cpp:784
const std::vector< GNEEdge * > & getGNEEdges() const
Returns all GNEEdges vinculated with this Junction.
FXDEFMAP(GNEFrame::ACHierarchy) GNEFrameACHierarchyMap[]
static bool isValidGenericParameterKey(const std::string &value)
whether the given string is a valid key for a generic parameter
virtual std::vector< std::pair< std::string, std::string > > getGenericParameters() const =0
return generic parameters as vector of pairs format
generic attribute
GNEViewNet * getViewNet() const
get view net
Definition: GNEFrame.cpp:766
GNEFrame * myFrameParent
Frame Parent.
Definition: GNEFrame.h:108
virtual std::string getAttribute(SumoXMLAttr key) const =0
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:242
GNEEdge * getEdgeTo() const
get the name of the edge the vehicles may reach when leaving "from"
FXTreeItem * addACIntoList(GNEAttributeCarrier *AC, FXTreeItem *itemParent)
add item into list
Definition: GNEFrame.cpp:482
std::set< FXTreeItem * > myTreeItemsConnections
set used to save tree items without AC assigned, the Incoming/Outcoming connections ...
Definition: GNEFrame.h:120
long onCmdInspectItem(FXObject *, FXSelector, void *)
called when user select option "inspect item" of child menu
Definition: GNEFrame.cpp:155
GNEViewNet * myViewNet
View Net for changes.
Definition: GNEFrame.h:232
virtual std::string getHierarchyName() const =0
get Hierarchy Name (Used in AC Hierarchy)
std::vector< GNEAttributeCarrier * > myACs
list of edited ACs
Definition: GNEFrame.h:174
const std::vector< GNEAttributeCarrier * > & getInspectedACs() const
get current list of inspected ACs
GNEAdditional * retrieveAdditional(SumoXMLTag type, const std::string &id, bool hardFail=true) const
Returns the named additional.
Definition: GNENet.cpp:1787
Dialog for edit generic parameters.
const std::vector< GNECrossing * > & getGNECrossings() const
Returns GNECrossings.
std::string getGenericParametersStr() const
get generic parameters as string
Definition: GNEFrame.cpp:585
GNEUndoList * getUndoList() const
get the undoList object
#define GUIDesignAuxiliarFrame
design for auxiliar (Without borders) frames used to pack another frames extended in all directions ...
Definition: GUIDesigns.h:255
GNEAttributeCarrier * myAC
edited Attribute Carrier
Definition: GNEFrame.h:171
virtual std::string getPopUpID() const =0
get PopPup ID (Used in AC Hierarchy)
static bool isValidGenericParameterValue(const std::string &value)
whether the given string is a valid value for a generic parameter
#define GUIDesignHorizontalSeparator
Definition: GUIDesigns.h:295
#define GUIDesignTextField
Definition: GUIDesigns.h:34
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:49
FXVerticalFrame * myContentFrame
Vertical frame that holds all widgets of frame.
Definition: GNEFrame.h:235
This object is responsible for drawing a shape and for supplying a a popup menu. Messages are routete...
Definition: GNECrossing.h:45
GNEEdge & getParentEdge()
Returns underlying parent edge.
Definition: GNELane.cpp:1230
std::string getHierarchyName() const
get Hierarchy Name (Used in AC Hierarchy)
void showAttributeCarrierChilds(GNEAttributeCarrier *AC, FXTreeItem *itemParent)
show child of current attributeCarrier
Definition: GNEFrame.cpp:381
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
GNEJunction * retrieveJunction(const std::string &id, bool failHard=true)
get junction by id
Definition: GNENet.cpp:894
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames ...
Definition: GUIDesigns.h:258
#define GUIDesignContentsScrollWindow
design for the content frame of every frame
Definition: GUIDesigns.h:252
GNEEdge * getEdgeFrom() const
get the name of the edge the vehicles leave
static bool isGenericParametersValid(const std::string &value)
check if given string can be parsed to a map/list of generic parameters
FXLabel * myFrameHeaderLabel
the label for the frame&#39;s header
Definition: GNEFrame.h:254
virtual void centerTo(GUIGlID id, bool applyZoom, double zoomDist=20)
centers to the chosen artifact
std::vector< std::pair< std::string, std::string > > * myGenericParameters
pointer to current vector of generic parameters
Definition: GNEFrame.h:177
std::vector< GNEConnection * > getGNEIncomingConnections()
returns a vector with the incoming GNEConnections of this lane
Definition: GNELane.cpp:1236
GNEJunction * getGNEJunctionDestiny() const
returns the destination-junction
Definition: GNEEdge.cpp:453
void refreshACHierarchy()
refresh ACHierarchy
Definition: GNEFrame.cpp:117
FXFont * getBoldFont()
attribute edited trought dialog
Definition: GUIAppEnum.h:543
GUIMainWindow * getGUIMainWindow() const
get GUIMainWindow App
long onCmdShowChildMenu(FXObject *, FXSelector, void *data)
Definition: GNEFrame.cpp:130
void setFrameWidth(int newWidth)
set width of GNEFrame
Definition: GNEFrame.cpp:759
const std::string getID() const
function to support debugging
In GNEINSPECTORFRAME, delete element.
Definition: GUIAppEnum.h:583
void createPopUpMenu(int X, int Y, GNEAttributeCarrier *ac)
Definition: GNEFrame.cpp:183
#define GUIDesignDialogBoxResizable
design for standard dialog box (for example, about dialog)
Definition: GUIDesigns.h:416
#define WRITE_DEBUG(msg)
Definition: MsgHandler.h:249
void focusUpperElement()
focus upper element of frame
Definition: GNEFrame.cpp:735
std::vector< GNEConnection * > getGNEOutcomingConnections()
returns a vector with the outgoing GNEConnections of this lane
Definition: GNELane.cpp:1257
GNEAttributeCarrier * myAC
Attribute carrier.
Definition: GNEFrame.h:111
#define GUIDesignLabelFrameInformation
label extended over frame without thick and with text justify to left, used to show information in fr...
Definition: GUIDesigns.h:184
GNEJunction * getGNEJunctionSource() const
returns the source-junction
Definition: GNEEdge.cpp:447
~ACHierarchy()
destructor
Definition: GNEFrame.cpp:95
~GNEFrame()
destructor
Definition: GNEFrame.cpp:729
begin/end of the description of an edge
GenericParametersEditor()
FOX needs this.
Definition: GNEFrame.h:167
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:50
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition: GUIDesigns.h:46
GNECrossing * retrieveCrossing(const std::string &id, bool failHard=true) const
get Crossing by id
Definition: GNENet.cpp:1002
#define GUIDesignButton
Definition: GUIDesigns.h:54
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
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
void showGenericParametersEditor(GNEAttributeCarrier *AC)
show netedit attributes editor (used for edit generic parameters of an existent AC) ...
Definition: GNEFrame.cpp:512
long onCmdSetGenericParameter(FXObject *, FXSelector, void *)
Called when user udpate the generic parameter text field.
Definition: GNEFrame.cpp:621
crossing between edges for pedestrians
virtual void hide()
hide Frame
Definition: GNEFrame.cpp:750
GNEDeleteFrame * getDeleteFrame() const
get frame for GNE_MODE_DELETE
FXTextField * myTextFieldGenericParameter
text field for write generic parameter
Definition: GNEFrame.h:183
GNENet * getNet() const
get the net object
GUIGlID getGlID() const
Returns the numerical id of the object.
long onCmdCenterItem(FXObject *, FXSelector, void *)
called when user select option "center item" of child Menu
Definition: GNEFrame.cpp:144
attribute edited
Definition: GUIAppEnum.h:535
#define GUIDesignTableNotEditable
design for table extended over frame that cannot be edited
Definition: GUIDesigns.h:438
#define GUIDesignButtonOK
Definition: GUIDesigns.h:96
void removeAttributeCarrier(GNEAttributeCarrier *ac, bool ignoreOptions=false)
remove attribute carrier (element)
virtual std::string getHierarchyName() const =0
get Hierarchy Name (Used in AC Hierarchy)
FXTreeList * myTreelist
tree list to show the childs of the element to erase
Definition: GNEFrame.h:114
void inspectChild(GNEAttributeCarrier *AC, GNEAttributeCarrier *previousElement)
inspect child of already inspected element
const std::vector< GNEAdditional * > & getAdditionalChilds() const
return vector of additionals that have as Parent this edge (For example, Calibrators) ...
parent of an additional element
static const TagValues & getTagProperties(SumoXMLTag tag)
get Tag Properties
In GNEINSPECTORFRAME, center element.
Definition: GUIAppEnum.h:579
begin/end of the description of a Point of interest over Lane (used by Netedit)
const std::vector< GNEAdditional * > & getAdditionalChilds() const
return vector of additionals that have as Parent this edge (For example, Calibrators) ...
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1066
long onCmdEditGenericParameter(FXObject *, FXSelector, void *)
Definition: GNEFrame.cpp:600
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
The Table.
Definition: GUIAppEnum.h:292
FXHorizontalFrame * myHeaderLeftFrame
fame for left header elements
Definition: GNEFrame.h:241
FXButton * myEditGenericParameterButton
button for add generic parameter
Definition: GNEFrame.h:186
begin/end of the description of a polygon
GNEJunction * getParentJunction() const
get parent Junction
Definition: GNECrossing.cpp:98
SumoXMLTag getTag() const
get XML Tag assigned to this object