SUMO - Simulation of Urban MObility
GNEInspectorFrame.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // The Widget for modifying network-element attributes (i.e. lane speed)
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
10 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #ifdef HAVE_VERSION_H
32 #include <version.h>
33 #endif
34 
35 #include <cmath>
36 #include <cassert>
37 #include <iostream>
42 #include "GNEInspectorFrame.h"
43 #include "GNEUndoList.h"
44 #include "GNEEdge.h"
45 #include "GNELane.h"
46 #include "GNEAttributeCarrier.h"
47 #include "GNEAdditional.h"
48 #include "GNEViewNet.h"
49 #include "GNEViewParent.h"
50 #include "GNEConnection.h"
51 #include "GNEViewNet.h"
52 
53 #ifdef CHECK_MEMORY_LEAKS
54 #include <foreign/nvwa/debug_new.h>
55 #endif // CHECK_MEMORY_LEAKS
56 
57 
58 // ===========================================================================
59 // static
60 // ===========================================================================
61 
62 const unsigned int MAXNUMBEROFATTRCONNECTIONS = 50;
63 
64 // ===========================================================================
65 // FOX callback mapping
66 // ===========================================================================
67 
68 FXDEFMAP(GNEInspectorFrame) GNEInspectorFrameMap[] = {
74 };
75 
76 
77 FXDEFMAP(GNEInspectorFrame::AttrInput) AttrInputMap[] = {
80 };
81 
82 FXDEFMAP(GNEInspectorFrame::AttrEditor) AttrEditorMap[] = {
84 };
85 
86 FXDEFMAP(GNEInspectorFrame::AttrConnection) AttrConnectionMap[] = {
89 };
90 
91 // Object implementation
92 FXIMPLEMENT(GNEInspectorFrame, FXScrollWindow, GNEInspectorFrameMap, ARRAYNUMBER(GNEInspectorFrameMap))
93 FXIMPLEMENT(GNEInspectorFrame::AttrInput, FXMatrix, AttrInputMap, ARRAYNUMBER(AttrInputMap))
94 FXIMPLEMENT(GNEInspectorFrame::AttrEditor, FXDialogBox, AttrEditorMap, ARRAYNUMBER(AttrEditorMap))
95 FXIMPLEMENT(GNEInspectorFrame::AttrConnection, FXHorizontalFrame, AttrConnectionMap, ARRAYNUMBER(AttrConnectionMap))
96 
97 // ===========================================================================
98 // method definitions
99 // ===========================================================================
100 
101 GNEInspectorFrame::GNEInspectorFrame(FXComposite* parent, GNEViewNet* viewNet):
102  GNEFrame(parent, viewNet, "Inspector"),
103  myEdgeTemplate(0),
104  myAdditional(0),
105  myPreviousElement(0) {
106 
107  // Create back button
108  myBackButton = new FXButton(myHeaderLeftFrame, "", GUIIconSubSys::getIcon(ICON_NETEDITARROW), this, MID_GNE_INSPECT_GOBACK, ICON_BEFORE_TEXT | FRAME_THICK | FRAME_RAISED | LAYOUT_FILL);
109  myBackButton->hide();
110 
111  // Create groupBox for attributes
112  myGroupBoxForAttributes = new FXGroupBox(myContentFrame, "attributes", GROUPBOX_TITLE_CENTER | FRAME_GROOVE | LAYOUT_FILL_X);
113  myGroupBoxForAttributes->hide();
114 
115  // Create AttrInput
116  for (int i = 0; i < GNEAttributeCarrier::getHigherNumberOfAttributes(); i++) {
117  vectorOfAttrInput.push_back(new AttrInput(myGroupBoxForAttributes, this));
118  }
119 
120  // Create groupBox for templates
121  myGroupBoxForTemplates = new FXGroupBox(myContentFrame, "Templates", GROUPBOX_TITLE_CENTER | FRAME_GROOVE | LAYOUT_FILL_X);
122  myGroupBoxForTemplates->hide();
123 
124  // Create copy template button
125  myCopyTemplateButton = new FXButton(myGroupBoxForTemplates, "", 0, this, MID_GNE_COPY_TEMPLATE, ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED, 0, 0, 0, 0, 4, 4, 3, 3);
126  myCopyTemplateButton->hide();
127 
128  // Create set template button
129  mySetTemplateButton = new FXButton(myGroupBoxForTemplates, "Set as Template\t\t", 0, this, MID_GNE_SET_TEMPLATE, ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED, 0, 0, 0, 0, 4, 4, 3, 3);
130  mySetTemplateButton->hide();
131 
132  // Create groupBox for editor parameters
133  myGroupBoxForEditor = new FXGroupBox(myContentFrame, "editor", GROUPBOX_TITLE_CENTER | FRAME_GROOVE | LAYOUT_FILL_X);
134  myGroupBoxForEditor->hide();
135 
136  // Create check blocked button
137  myCheckBlocked = new FXCheckButton(myGroupBoxForEditor, "Block movement", this, MID_GNE_SET_BLOCKING);
138  myCheckBlocked->hide();
139 
140  // Create groupBox for AttrConnection
141  myGroupBoxForAttrConnections = new FXGroupBox(myContentFrame, "Connections", GROUPBOX_TITLE_CENTER | FRAME_GROOVE | LAYOUT_FILL_X);
142  myGroupBoxForAttrConnections->hide();
143 
144  // Create AttrConnections
145  for (int i = 0; i < MAXNUMBEROFATTRCONNECTIONS; i++) {
146  myAttrConnections.push_back(new AttrConnection(myGroupBoxForAttrConnections, this));
147  }
148 }
149 
151  if (myEdgeTemplate) {
152  myEdgeTemplate->decRef("GNEInspectorFrame::~GNEInspectorFrame");
153  if (myEdgeTemplate->unreferenced()) {
154  delete myEdgeTemplate;
155  }
156  }
157 }
158 
159 
160 void
162  // Show Scroll window
163  FXScrollWindow::show();
164  // Show and update Frame Area in which this GNEFrame is placed
166 }
167 
168 
169 void
171  // Hide ScrollWindow
172  FXScrollWindow::hide();
173  // Hide Frame Area in which this GNEFrame is placed
175 }
176 
177 
178 void
180  // Use the implementation of inspect for multiple AttributeCarriers to avoid repetition of code
181  std::vector<GNEAttributeCarrier*> itemToInspect;
182  itemToInspect.push_back(AC);
183  inspect(itemToInspect, previousElement);
184 }
185 
186 
187 void
188 GNEInspectorFrame::inspect(const std::vector<GNEAttributeCarrier*>& ACs, GNEAttributeCarrier* previousElement) {
189  // Assing ACs to myACs
190  myACs = ACs;
191  // Show back button if previousElement was defined
192  myPreviousElement = previousElement;
193  if (myPreviousElement != NULL) {
194  myHeaderLeftFrame->show();
195  myBackButton->show();
196  } else {
197  myHeaderLeftFrame->hide();
198  myBackButton->hide();
199  }
200  // Hide all elements
201  myGroupBoxForAttributes->hide();
202  myGroupBoxForTemplates->hide();
203  myCopyTemplateButton->hide();
204  mySetTemplateButton->hide();
205  myGroupBoxForEditor->hide();
206  myGroupBoxForEditor->hide();
207  myCheckBlocked->hide();
209  // If vector of attribute Carriers contain data
210  if (myACs.size() > 0) {
211  // Set header
212  std::string headerString;
213  if (myACs.size() > 1) {
214  headerString = "Selection: " + toString(myACs.size()) + " " + toString(myACs.front()->getTag()) + "s";
215  } else {
216  if (dynamic_cast<GNENetElement*>(myACs.front())) {
217  headerString = "Net: " + toString(myACs.front()->getTag());
218  } else if (dynamic_cast<GNEAdditional*>(myACs.front())) {
219  headerString = "Additional: " + toString(myACs.front()->getTag());
220  }
221  }
222  // Set headerString into header label
223  getFrameHeaderLabel()->setText(headerString.c_str());
224 
225  //Show myGroupBoxForAttributes
226  myGroupBoxForAttributes->show();
227 
228  // Hide all AttrInput
229  for (std::vector<GNEInspectorFrame::AttrInput*>::iterator i = vectorOfAttrInput.begin(); i != vectorOfAttrInput.end(); i++) {
230  (*i)->hideAttribute();
231  }
232 
233  // Hide all AttrConnections
234  for (int i = 0; i < MAXNUMBEROFATTRCONNECTIONS; i++) {
235  myAttrConnections.at(i)->hideAttrConnection();
236  }
237 
238  // Gets attributes of element
239  const std::vector<SumoXMLAttr>& attrs = myACs.front()->getAttrs();
240 
241  // Declare iterator over AttrImput
242  std::vector<GNEInspectorFrame::AttrInput*>::iterator itAttrs = vectorOfAttrInput.begin();
243 
244  // Iterate over attributes
245  for (std::vector<SumoXMLAttr>::const_iterator it = attrs.begin(); it != attrs.end(); it++) {
246  if (myACs.size() > 1 && GNEAttributeCarrier::isUnique(*it)) {
247  // disable editing for some attributes in case of multi-selection
248  // even displaying is problematic because of string rendering restrictions
249  continue;
250  }
251  // Declare a set of occuring values and insert attribute's values of item
252  std::set<std::string> occuringValues;
253  for (std::vector<GNEAttributeCarrier*>::const_iterator it_ac = myACs.begin(); it_ac != myACs.end(); it_ac++) {
254  occuringValues.insert((*it_ac)->getAttribute(*it));
255  }
256  // get current value
257  std::ostringstream oss;
258  for (std::set<std::string>::iterator it_val = occuringValues.begin(); it_val != occuringValues.end(); it_val++) {
259  if (it_val != occuringValues.begin()) {
260  oss << " ";
261  }
262  oss << *it_val;
263  }
264  // Show attribute
265  (*itAttrs)->showAttribute(myACs.front()->getTag(), *it, oss.str());
266  itAttrs++;
267  }
268 
269  // If attributes correspond to an Edge
270  if (dynamic_cast<GNEEdge*>(myACs.front())) {
271  // show groupBox for templates
272  myGroupBoxForTemplates->show();
273  // show "Copy Template" (caption supplied via onUpdate)
274  myCopyTemplateButton->show();
275  // show "Set As Template"
276  if (myACs.size() == 1) {
277  mySetTemplateButton->show();
278  }
279  // Obtain connections of edge
280  const std::vector<GNEConnection*>& connections = dynamic_cast<GNEEdge*>(myACs.front())->getGNEConnections();
281  if (connections.size() > 0) {
282  // Check if all connections are editables
283  if (connections.size() > MAXNUMBEROFATTRCONNECTIONS) {
284  WRITE_WARNING("Number of connections of " + myACs.front()->getID() + " is greater than the number of editable connections (" + toString(MAXNUMBEROFATTRCONNECTIONS) + ")");
285  }
286  // Show AttrConnections
287  for (int i = 0; i < (int)connections.size() && i < MAXNUMBEROFATTRCONNECTIONS; i++) {
288  myAttrConnections.at(i)->showConnections(connections.at(i));
289  }
291  }
292  }
293 
294  // If attributes correspond to a lane
295  if (dynamic_cast<GNELane*>(myACs.front())) {
296  // Obtain connections of lane
297  std::vector<GNEConnection*> connections = dynamic_cast<GNELane*>(myACs.front())->getGNEOutcomingConnections();
298  if (connections.size() > 0) {
299  // Check if all connections are editables
300  if (connections.size() > MAXNUMBEROFATTRCONNECTIONS) {
301  WRITE_WARNING("Number of connections of " + myACs.front()->getID() + " is greater than the number of editable connections (" + toString(MAXNUMBEROFATTRCONNECTIONS) + ")");
302  }
303  // Show AttrConnections
304  for (int i = 0; i < (int)connections.size() && i < MAXNUMBEROFATTRCONNECTIONS; i++) {
305  myAttrConnections.at(i)->showConnections(connections.at(i));
306  }
308  }
309  }
310 
311  // If attributes correspond to an Additional
312  if (dynamic_cast<GNEAdditional*>(myACs.front())) {
313  // Get pointer to additional
314  myAdditional = dynamic_cast<GNEAdditional*>(myACs.front());
315  bool showGroupBoxForEditor = false;
316 
317  // Show check blocked if additional is movable
320  myCheckBlocked->show();
321  showGroupBoxForEditor = true;
322  }
323  // Show groupBox for editor Attributes if some of additional attributes are editable
324  if (showGroupBoxForEditor == true) {
325  myGroupBoxForEditor->show();
326  }
327  }
328  } else {
329  getFrameHeaderLabel()->setText("No Object selected");
330  }
331 }
332 
333 GNEEdge*
335  return myEdgeTemplate;
336 }
337 
338 
339 void
341  if (myEdgeTemplate) {
342  myEdgeTemplate->decRef("GNEInspectorFrame::setEdgeTemplate");
343  if (myEdgeTemplate->unreferenced()) {
344  delete myEdgeTemplate;
345  }
346  }
347  myEdgeTemplate = tpl;
348  myEdgeTemplate->incRef("GNEInspectorFrame::setEdgeTemplate");
349 }
350 
351 
352 long
353 GNEInspectorFrame::onCmdCopyTemplate(FXObject*, FXSelector, void*) {
354  for (std::vector<GNEAttributeCarrier*>::iterator it = myACs.begin(); it != myACs.end(); it++) {
355  GNEEdge* edge = dynamic_cast<GNEEdge*>(*it);
356  assert(edge);
358  inspect(myACs);
359  }
360  return 1;
361 }
362 
363 
364 long
365 GNEInspectorFrame::onCmdSetTemplate(FXObject*, FXSelector, void*) {
366  assert(myACs.size() == 1);
367  GNEEdge* edge = dynamic_cast<GNEEdge*>(myACs.front());
368  assert(edge);
369  setEdgeTemplate(edge);
370  return 1;
371 }
372 
373 
374 long
375 GNEInspectorFrame::onUpdCopyTemplate(FXObject* sender, FXSelector, void*) {
376  FXString caption;
377  if (myEdgeTemplate) {
378  caption = ("Copy '" + myEdgeTemplate->getMicrosimID() + "'").c_str();
379  sender->handle(this, FXSEL(SEL_COMMAND, ID_ENABLE), NULL);
380  } else {
381  caption = "No Template Set";
382  sender->handle(this, FXSEL(SEL_COMMAND, ID_DISABLE), NULL);
383  }
384  sender->handle(this, FXSEL(SEL_COMMAND, FXLabel::ID_SETSTRINGVALUE), (void*)&caption);
385  return 1;
386 }
387 
388 
389 long
390 GNEInspectorFrame::onCmdSetBlocking(FXObject*, FXSelector, void*) {
391  if (myAdditional) {
392  if (myCheckBlocked->getCheck() == 1) {
393  myAdditional->setAttribute(GNE_ATTR_BLOCK_MOVEMENT, "true", getViewNet()->getUndoList());
394  } else {
395  myAdditional->setAttribute(GNE_ATTR_BLOCK_MOVEMENT, "false", getViewNet()->getUndoList());
396  }
397  }
398  return 1;
399 }
400 
401 
402 long
403 GNEInspectorFrame::onCmdGoBack(FXObject*, FXSelector, void*) {
404  // Inspect previous element (if was defined)
405  if (myPreviousElement) {
407  }
408  return 1;
409 }
410 
411 
412 const std::vector<GNEAttributeCarrier*>&
414  return myACs;
415 }
416 
417 // ===========================================================================
418 // AttrInput method definitions
419 // ===========================================================================
420 
421 GNEInspectorFrame::AttrInput::AttrInput(FXComposite* parent, GNEInspectorFrame* inspectorFrameParent) :
422  FXMatrix(parent, 8, MATRIX_BY_COLUMNS | LAYOUT_FILL_X | PACK_UNIFORM_WIDTH),
423  myInspectorFrameParent(inspectorFrameParent),
424  myTag(SUMO_TAG_NOTHING),
425  myAttr(SUMO_ATTR_NOTHING) {
426  // Create and hide ButtonCombinableChoices
427  myButtonCombinableChoices = new FXButton(this, "AttributeButton", 0, this, MID_GNE_OPEN_ATTRIBUTE_EDITOR, ICON_BEFORE_TEXT | LAYOUT_FILL_COLUMN | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED);
429  // Create and hide label
430  myLabel = new FXLabel(this, "attributeLabel", 0, FRAME_THICK | LAYOUT_FILL_COLUMN | LAYOUT_FILL_X);
431  myLabel->hide();
432  // Create and hide textField int
433  myTextFieldInt = new FXTextField(this, 1, this, MID_GNE_SET_ATTRIBUTE, FRAME_THICK | TEXTFIELD_INTEGER | LAYOUT_FILL_COLUMN | LAYOUT_FILL_X);
434  myTextFieldInt->hide();
435  // Create and hide textField real
436  myTextFieldReal = new FXTextField(this, 1, this, MID_GNE_SET_ATTRIBUTE, FRAME_THICK | TEXTFIELD_REAL | LAYOUT_FILL_COLUMN | LAYOUT_FILL_X);
437  myTextFieldReal->hide();
438  // Create and hide textField string
439  myTextFieldStrings = new FXTextField(this, 1, this, MID_GNE_SET_ATTRIBUTE, TEXTFIELD_NORMAL | LAYOUT_FILL_COLUMN | LAYOUT_FILL_X);
440  myTextFieldStrings->hide();
441  // Create and hide ComboBox
442  myChoicesCombo = new FXComboBox(this, 1, this, MID_GNE_SET_ATTRIBUTE, FRAME_THICK | LAYOUT_CENTER_Y | LAYOUT_FILL_COLUMN | LAYOUT_FILL_X);
443  myChoicesCombo->hide();
444  // Create and hide checkButton
445  myCheckBox = new FXCheckButton(this, "", this, MID_GNE_SET_ATTRIBUTE, JUSTIFY_LEFT | ICON_BEFORE_TEXT | LAYOUT_FILL_COLUMN | LAYOUT_FILL_X);
446  myCheckBox->hide();
447 }
448 
449 
450 void
452  // Set actual Tag and attribute
453  myTag = tag;
454  myAttr = attr;
455  // ShowLabel
456  myLabel->setText(toString(myAttr).c_str());
457  myLabel->show();
458  // Set field depending of the type of value
460  // set value of checkbox
461  myCheckBox->setCheck(GNEAttributeCarrier::parse<bool>(value));
462  myCheckBox->show();
464  // Obtain choices
465  const std::vector<std::string>& choices = GNEAttributeCarrier::discreteChoices(myTag, myAttr);
466  // Check if are combinable coices
467  if (choices.size() > 0 && GNEAttributeCarrier::discreteCombinableChoices(myTag, myAttr)) {
468  // hide label
469  myLabel->hide();
470  // Show button combinable choices
471  myButtonCombinableChoices->setText(toString(myAttr).c_str());
473  // Show string with the values
474  myTextFieldStrings->setText(value.c_str());
475  myTextFieldStrings->setTextColor(FXRGB(0, 0, 0));
476  myTextFieldStrings->show();
477  } else {
478  // fill comboBox
479  myChoicesCombo->clearItems();
480  for (std::vector<std::string>::const_iterator it = choices.begin(); it != choices.end(); ++it) {
481  myChoicesCombo->appendItem(it->c_str());
482  }
483  myChoicesCombo->setNumVisible((int)choices.size());
484  myChoicesCombo->setCurrentItem(myChoicesCombo->findItem(value.c_str()));
485  myChoicesCombo->show();
486  }
487  } else if (GNEAttributeCarrier::isFloat(myAttr)) {
488  // show TextField for real values
489  myTextFieldReal->setText(value.c_str());
490  myTextFieldReal->setTextColor(FXRGB(0, 0, 0));
491  myTextFieldReal->show();
492  } else if (GNEAttributeCarrier::isInt(myAttr)) {
493  // Show textField for int attributes
494  myTextFieldInt->setText(value.c_str());
495  myTextFieldInt->setTextColor(FXRGB(0, 0, 0));
496  myTextFieldInt->show();
497  } else {
498  // In any other case (String, list, etc.), show value as String
499  myTextFieldStrings->setText(value.c_str());
500  myTextFieldStrings->setTextColor(FXRGB(0, 0, 0));
501  myTextFieldStrings->show();
502  }
503  // Show AttrInput
504  show();
505 }
506 
507 
508 void
510  // Hide all elements
511  myLabel->hide();
512  myTextFieldInt->hide();
513  myTextFieldReal->hide();
514  myTextFieldStrings->hide();
515  myChoicesCombo->hide();
516  myCheckBox->hide();
518  // hide AttrInput
519  hide();
520 }
521 
522 
525  return myTag;
526 }
527 
528 
531  return myAttr;
532 }
533 
534 
535 long
537  // Open AttrEditor
539  return 1;
540 }
541 
542 
543 long
544 GNEInspectorFrame::AttrInput::onCmdSetAttribute(FXObject*, FXSelector, void*) {
545  // Declare changed value
546  std::string newVal;
547  // First, obtain the string value of the new attribute depending of their type
549  // Set true o false depending of the checBox
550  if (myCheckBox->getCheck()) {
551  newVal = "true";
552  } else {
553  newVal = "false";
554  }
556  // Obtain choices
557  const std::vector<std::string>& choices = GNEAttributeCarrier::discreteChoices(myTag, myAttr);
558  // Check if are combinable coices
559  if (choices.size() > 0 && GNEAttributeCarrier::discreteCombinableChoices(myTag, myAttr)) {
560  // Get value obtained using AttrEditor
561  newVal = myTextFieldStrings->getText().text();
562  } else {
563  // Get value of ComboBox
564  newVal = myChoicesCombo->getText().text();
565  }
566  } else if (GNEAttributeCarrier::isFloat(myAttr)) {
567  // obtain value of myTextFieldReal
568  newVal = myTextFieldReal->getText().text();
569  } else if (GNEAttributeCarrier::isInt(myAttr)) {
570  // obtain value of myTextFieldInt
571  newVal = myTextFieldInt->getText().text();
573  // obtain value of myTextFieldStrings
574  newVal = myTextFieldStrings->getText().text();
575  }
576 
577  // Check if newvalue is valid
578  if (myInspectorFrameParent->getACs().front()->isValid(myAttr, newVal)) {
579  // if its valid for the first AC than its valid for all (of the same type)
580  if (myInspectorFrameParent->getACs().size() > 1) {
581  myInspectorFrameParent->getViewNet()->getUndoList()->p_begin("Change multiple attributes");
582  }
583  // Set all attributes
584  for (std::vector<GNEAttributeCarrier*>::const_iterator it_ac = myInspectorFrameParent->getACs().begin(); it_ac != myInspectorFrameParent->getACs().end(); it_ac++) {
585  (*it_ac)->setAttribute(myAttr, newVal, myInspectorFrameParent->getViewNet()->getUndoList());
586  }
587  if (myInspectorFrameParent->getACs().size() > 1) {
589  }
590  // If previously value of TextField was red, change color to black
592  myTextFieldReal->setTextColor(FXRGB(0, 0, 0));
593  myTextFieldReal->killFocus();
595  myTextFieldInt->setTextColor(FXRGB(0, 0, 0));
596  myTextFieldInt->killFocus();
598  myTextFieldStrings->setTextColor(FXRGB(0, 0, 0));
599  myTextFieldStrings->killFocus();
600  }
601  } else {
602  // IF value of TextField isn't valid, change color to Red depending of type
604  myTextFieldReal->setTextColor(FXRGB(255, 0, 0));
606  myTextFieldInt->setTextColor(FXRGB(255, 0, 0));
608  myTextFieldStrings->setTextColor(FXRGB(255, 0, 0));
609  }
610  }
611  // Update view net
612  myInspectorFrameParent->getViewNet()->update();
613  return 1;
614 }
615 
616 
617 void
619  FXMatrix::show();
620 }
621 
622 
623 void
625  FXMatrix::hide();
626 }
627 
628 // ===========================================================================
629 // AttrEditor method definitions
630 // ===========================================================================
631 
632 GNEInspectorFrame::AttrEditor::AttrEditor(AttrInput* attrInputParent, FXTextField* textFieldAttr) :
633  FXDialogBox(attrInputParent->getApp(), ("Editing attribute '" + toString(attrInputParent->getAttr()) + "'").c_str(), DECOR_CLOSE | DECOR_TITLE),
634  myAttrInputParent(attrInputParent),
635  myTextFieldAttr(textFieldAttr) {
636  // Create matrix
637  myCheckBoxMatrix = new FXMatrix(this, 2, MATRIX_BY_COLUMNS);
638 
639  // Obtain vector with the choices
640  const std::vector<std::string>& choices = GNEAttributeCarrier::discreteChoices(myAttrInputParent->getTag(), myAttrInputParent->getAttr());
641 
642  // Get old value
643  const std::string oldValue = myTextFieldAttr->getText().text();
644 
645  // Resize myVectorOfCheckBox
646  myVectorOfCheckBox.resize(choices.size(), NULL);
647 
648  // Iterate over choices
649  for (int i = 0; i < (int)choices.size(); i++) {
650  // Create checkBox
651  myVectorOfCheckBox.at(i) = new FXCheckButton(myCheckBoxMatrix, choices.at(i).c_str());
652  // Set initial value
653  if (oldValue.find(choices.at(i)) != std::string::npos) {
654  myVectorOfCheckBox.at(i)->setCheck(true);
655  }
656  }
657 
658  // Add separator
659  new FXHorizontalSeparator(this, SEPARATOR_GROOVE | LAYOUT_FILL_X, 0, 0, 0, 2, 2, 2, 4, 4);
660 
661  // Create frame for buttons
662  frameButtons = new FXHorizontalFrame(this, LAYOUT_FILL_X);
663 
664  // Create accept button
665  myAcceptButton = new FXButton(frameButtons, "Accept", 0, this, FXDialogBox::ID_ACCEPT, ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED);
666 
667  // Create cancel button
668  myCancelButton = new FXButton(frameButtons, "Cancel", 0, this, FXDialogBox::ID_CANCEL, ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED);
669 
670  // Create reset button
671  myResetButton = new FXButton(frameButtons, "Reset", 0, this, MID_GNE_MODE_INSPECT_RESET, ICON_BEFORE_TEXT | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED);
672 
673  // Execute dialog to make it modal, and if user press button "accept", save attribute
674  if (execute()) {
675  std::vector<std::string> attrSolution;
676  // Iterate over myVectorOfCheckBox
677  for (int i = 0; i < (int)myVectorOfCheckBox.size(); i++) {
678  // If checkBox is cheked, save attribute
679  if (myVectorOfCheckBox.at(i)->getCheck()) {
680  attrSolution.push_back(std::string(myVectorOfCheckBox.at(i)->getText().text()));
681  }
682  }
683  // join to string
684  myTextFieldAttr->setText(joinToString(attrSolution, " ").c_str());
685  // Set attribute
687  }
688 }
689 
690 
692 
693 long
694 GNEInspectorFrame::AttrEditor::onCmdReset(FXObject*, FXSelector, void*) {
695  // Obtain vector with the choices
696  const std::vector<std::string>& choices = GNEAttributeCarrier::discreteChoices(myAttrInputParent->getTag(), myAttrInputParent->getAttr());
697  // Get old value
698  const std::string oldValue = myTextFieldAttr->getText().text();
699  // Reset values
700  for (int i = 0; i < (int)choices.size(); i++) {
701  if (oldValue.find(choices.at(i)) != std::string::npos) {
702  myVectorOfCheckBox.at(i)->setCheck(true);
703  } else {
704  myVectorOfCheckBox.at(i)->setCheck(false);
705  }
706  }
707  return 1;
708 }
709 
710 
711 
712 GNEInspectorFrame::AttrConnection::AttrConnection(FXComposite* parent, GNEInspectorFrame* inspectorFrameParent) :
713  FXHorizontalFrame(parent, LAYOUT_FILL_X),
714  myInspectorFrameParent(inspectorFrameParent),
715  myConnection(NULL) {
716  // Create label for connection
717  myConnectionInfoLabel = new FXLabel(this, "", NULL, FRAME_THICK | LAYOUT_FILL_X);
718  // Create checkButton for show connection
719  myShowConnection = new FXCheckButton(this, "Show", this, MID_GNE_SHOW_CONNECTION);
720  // Create FXButton for inspectConnection
721  myInspectConnection = new FXButton(this, "inspect", 0, this, MID_GNE_INSPECT_CONNECTION, ICON_BEFORE_TEXT | LAYOUT_FILL_COLUMN | LAYOUT_FILL_X | FRAME_THICK | FRAME_RAISED);
722 }
723 
724 
726 
727 
728 void
730  // Set pointer to current connection
731  myConnection = connection;
732  // set Label
734  myConnectionInfoLabel->setText(std::string(
736  "->" + con.toEdge->getLaneID(con.toLane)).c_str());
737  // Show Label
738  myConnectionInfoLabel->show();
739  // set show Connection
741  // show Show Connection
742  myShowConnection->show();
743  // Show AttrConnection
744  show();
745 }
746 
747 
748 void
750  // hide all elements
751  myConnectionInfoLabel->hide();
752  myShowConnection->hide();
753  hide();
754 }
755 
756 
757 long
759  if (myShowConnection->getCheck()) {
761  } else {
763  }
764  // Update view net
765  myInspectorFrameParent->getViewNet()->update();
766  return 1;
767 }
768 
769 
770 long
772  // Inspect connection depending of the checkBox "selectEdges"
775  } else {
777  }
778  return 1;
779 }
780 
781 
782 void
784  FXHorizontalFrame::show();
785 }
786 
787 
788 void
790  FXHorizontalFrame::hide();
791 }
792 
793 
794 /****************************************************************************/
void copyTemplate(GNEEdge *tpl, GNEUndoList *undolist)
copy edge attributes from tpl
Definition: GNEEdge.cpp:453
FXCheckButton * myCheckBox
pointer to checkBox
FXHorizontalFrame * frameButtons
frame for the buttons
SumoXMLTag
Numbers representing SUMO-XML - element names.
bool selectEdges()
whether inspection, selection and inversion should apply to edges or to lanes
Definition: GNEViewNet.cpp:322
A structure which describes a connection between edges or lanes.
Definition: NBEdge.h:157
FXComboBox * myChoicesCombo
pointer to combo box choices
int toLane
The lane the connections yields in.
Definition: NBEdge.h:178
GNEInspectorFrame * myInspectorFrameParent
pointer to GNEInspectorFrame parent
bool isAdditionalBlocked() const
Check if additional item is currently blocked (i.e. cannot be moved with mouse)
void hideFramesArea()
hide frames area if all GNEFrames are hidden
std::vector< AttrConnection * > myAttrConnections
vector of attrConnections
GNEEdge * getEdgeTemplate() const
get the template edge (to copy attributes from)
FXTextField * myTextFieldStrings
textField to modify the value of strings values
SumoXMLAttr myAttr
current Attr
NBEdge * toEdge
The edge the connections yields in.
Definition: NBEdge.h:175
void hide()
set hide as private function
FXLabel * getFrameHeaderLabel() const
get the label for the frame&#39;s header
Definition: GNEFrame.cpp:99
static bool isDiscrete(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is Discrete
FXGroupBox * myGroupBoxForTemplates
groupBox for templates
FXButton * myCopyTemplateButton
copy template button
long onCmdReset(FXObject *, FXSelector, void *)
call when user press button reset
void setDrawConnection(bool drawConnection)
enable or disable draw connection
bool getDrawConnection() const
get Draw connection
GNEViewParent * getViewParent() const
get the net object
Definition: GNEViewNet.cpp:906
void hide()
set hide as private function
const std::vector< GNEAttributeCarrier * > & getACs() const
get current list of ACs
void show()
set show as private function
void showFramesArea()
show frames area if at least a GNEFrame is showed
static int getHigherNumberOfAttributes()
return the number of attributes of the tag with the most highter number of attributes ...
virtual void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)=0
method for setting the attribute and letting the object perform additional changes ...
SumoXMLTag myTag
current tag
FXGroupBox * myGroupBoxForAttrConnections
groupBox for AttrConnection
SumoXMLAttr getAttr() const
get current Attr
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:55
long onCmdSetAttribute(FXObject *, FXSelector, void *)
try to set new attribute value
long onCmdCopyTemplate(FXObject *, FXSelector, void *)
copy edge attributes from edge template
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:86
FXTextField * myTextFieldReal
textField to modify the value of real values
void inspect(GNEAttributeCarrier *AC, GNEAttributeCarrier *previousElement=NULL)
Inspect a single element.
FXButton * myCancelButton
Button Cancel.
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
FXButton * mySetTemplateButton
set template button
GNEAdditional * myAdditional
pointer to additional element
FXButton * myButtonCombinableChoices
pointer to buttonCombinableChoices
long onCmdOpenAttributeEditor(FXObject *, FXSelector, void *)
open model dialog for more comfortable attribute editing
GNEViewNet * getViewNet() const
get view net
Definition: GNEFrame.cpp:93
FXButton * myAcceptButton
Button Accept.
void showAttribute(SumoXMLTag tag, SumoXMLAttr attr, const std::string &value)
show attribute
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
~GNEInspectorFrame()
Destructor.
void showConnections(GNEConnection *connection)
show attribute
GNELane * getLaneFrom() const
get lane of the incoming lane
GNEViewNet * myViewNet
the window to inform when the tls is modfied
Definition: GNEFrame.h:85
GNEConnection * myConnection
pointer to current connection
void hide()
hide Frame
static const std::vector< std::string > & discreteChoices(SumoXMLTag tag, SumoXMLAttr attr)
return a list of discrete choices for this attribute or an empty vector
long onCmdSetBlocking(FXObject *, FXSelector, void *)
called when user toogle the blocking button
NBEdge::Connection & getNBEdgeConnection() const
get Edge::Connection
SumoXMLTag getTag() const
get current tag
GNEUndoList * getUndoList() const
get the undoList object
Definition: GNEViewNet.cpp:918
void show()
set show as private function
GNEAttributeCarrier * myPreviousElement
pointer to previous element (If exist)
long onCmdInspectConnection(FXObject *, FXSelector, void *)
inspect connection
FXGroupBox * myGroupBoxForEditor
GropuBox for editor attributes.
std::string getLaneID(int lane) const
get Lane ID (Secure)
Definition: NBEdge.cpp:2499
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:93
GNEEdge * myEdgeTemplate
the edge template
FXButton * myInspectConnection
FXCheckBox to hide/show connection individually.
GNEEdge * getEdgeFrom() const
get the name of the edge the vehicles leave
FXTextField * myTextFieldInt
textField to modify the value of int values
void setEdgeTemplate(GNEEdge *tpl)
seh the template edge (we assume shared responsibility via reference counting)
FXCheckButton * myShowConnection
FXCheckBox to hide/show connection individually.
AttrInput * myAttrInputParent
Pointer to AttrInput parent.
virtual const std::string & getMicrosimID() const
Returns the id of the object as known to microsim.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
void incRef(const std::string &debugMsg="")
void hideAttrConnection()
show attribute
long onCmdGoBack(FXObject *, FXSelector, void *)
called when user toogle the go back button
void decRef(const std::string &debugMsg="")
FXButton * myResetButton
Button Reset.
static bool isFloat(SumoXMLAttr attr)
whether an attribute is numerical of type float
A road/street connecting two junctions (netedit-version)
Definition: GNEEdge.h:55
long onUpdCopyTemplate(FXObject *, FXSelector, void *)
update the copy button with the name of the template
GNEInspectorFrame * myInspectorFrameParent
pointer to inspectorFrame Parent
static bool isInt(SumoXMLAttr attr)
whether an attribute is numerical or type int
An Element which don&#39;t belongs to GNENet but has influency in the simulation.
Definition: GNEAdditional.h:63
FXLabel * myConnectionInfoLabel
Label for show information of connection.
bool isAdditionalMovable() const
check if additional element is movable
static bool discreteCombinableChoices(SumoXMLTag tag, SumoXMLAttr attr)
return whether the given attribute allows for a combination of discrete values
void show()
show Frame
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:188
static bool isUnique(SumoXMLAttr attr)
whether an attribute is unique (may not be edited for a multi-selection)
FXDEFMAP(GNEInspectorFrame) GNEInspectorFrameMap[]
static bool isString(SumoXMLAttr attr)
whether an attribute is of type string
std::vector< GNEAttributeCarrier * > myACs
the multi-selection currently being inspected
FXLabel * myLabel
pointer to label
void hideAttribute()
show attribute
long onCmdSetShowConnection(FXObject *, FXSelector, void *)
set show connection attribute
const unsigned int MAXNUMBEROFATTRCONNECTIONS
NBEdge * getNBEdge()
returns the internal NBEdge
Definition: GNEEdge.cpp:261
FXButton * myBackButton
back Button
long onCmdSetTemplate(FXObject *, FXSelector, void *)
set current edge as new template
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
static bool isBool(SumoXMLAttr attr)
whether an attribute is of type bool
std::vector< FXCheckButton * > myVectorOfCheckBox
vector of CheckBoxs
FXHorizontalFrame * myHeaderLeftFrame
fame for left header elements
Definition: GNEFrame.h:100
FXGroupBox * myGroupBoxForAttributes
groupBox for attributes
std::vector< GNEInspectorFrame::AttrInput * > vectorOfAttrInput
list of Attribute inputs
FXCheckButton * myCheckBlocked
pointer to check button block