SUMO - Simulation of Urban MObility
GNEPolygonFrame.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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // The Widget for add polygons
18 /****************************************************************************/
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #ifdef _MSC_VER
24 #include <windows_config.h>
25 #else
26 #include <config.h>
27 #endif
28 
29 #include <iostream>
40 #include <utils/gui/div/GLHelper.h>
42 
43 #include "GNEPolygonFrame.h"
44 #include "GNEViewNet.h"
45 #include "GNEViewParent.h"
46 #include "GNENet.h"
47 #include "GNEUndoList.h"
48 #include "GNEChange_Selection.h"
49 #include "GNEAttributeCarrier.h"
50 #include "GNEPoly.h"
51 #include "GNEPOI.h"
52 #include "GNEPOILane.h"
53 #include "GNELane.h"
54 
55 // ===========================================================================
56 // FOX callback mapping
57 // ===========================================================================
58 
59 FXDEFMAP(GNEPolygonFrame) GNEPolygonFrameMap[] = {
61 };
62 
63 FXDEFMAP(GNEPolygonFrame::ShapeAttributeSingle) GNESingleShapeParameterMap[] = {
67 };
68 
69 FXDEFMAP(GNEPolygonFrame::ShapeAttributes) GNEShapeParametersMap[] = {
71 };
72 
73 // Object implementation
74 FXIMPLEMENT(GNEPolygonFrame, FXVerticalFrame, GNEPolygonFrameMap, ARRAYNUMBER(GNEPolygonFrameMap))
75 FXIMPLEMENT(GNEPolygonFrame::ShapeAttributeSingle, FXHorizontalFrame, GNESingleShapeParameterMap, ARRAYNUMBER(GNESingleShapeParameterMap))
76 FXIMPLEMENT(GNEPolygonFrame::ShapeAttributes, FXGroupBox, GNEShapeParametersMap, ARRAYNUMBER(GNEShapeParametersMap))
77 
78 // ===========================================================================
79 // method definitions
80 // ===========================================================================
81 
82 GNEPolygonFrame::GNEPolygonFrame(FXHorizontalFrame* horizontalFrameParent, GNEViewNet* viewNet):
83  GNEFrame(horizontalFrameParent, viewNet, "Shapes"),
84  myActualShapeType(SUMO_TAG_NOTHING) {
85 
86  // Create groupBox for myShapeMatchBox
87  myGroupBoxForMyShapeMatchBox = new FXGroupBox(myContentFrame, "Shape element", GUIDesignGroupBoxFrame);
88 
89  // Create FXListBox in myGroupBoxForMyShapeMatchBox
90  myShapeMatchBox = new FXComboBox(myGroupBoxForMyShapeMatchBox, GUIDesignComboBoxNCol, this, MID_GNE_ADDITIONALFRAME_SELECTADDITIONALTYPE, GUIDesignComboBox);
91 
92  // Create shape parameters
93  myShapeAttributes = new GNEPolygonFrame::ShapeAttributes(myViewNet, myContentFrame);
94 
95  // Create Netedit parameter
96  myNeteditAttributes = new GNEPolygonFrame::NeteditAttributes(this);
97 
98  // Create drawing controls
99  myDrawingMode = new GNEPolygonFrame::DrawingMode(this);
100 
101  // Add options to myShapeMatchBox
102  for (auto i : GNEAttributeCarrier::allowedShapeTags()) {
103  myShapeMatchBox->appendItem(toString(i).c_str());
104  }
105 
106  // Set visible items
107  myShapeMatchBox->setNumVisible((int)myShapeMatchBox->getNumItems());
108 
109  // If there are shapes
110  if (GNEAttributeCarrier::allowedShapeTags().size() > 0) {
111  // Set myActualShapeType and show
112  myActualShapeType = GNEAttributeCarrier::allowedShapeTags().front();
113  setParametersOfShape(myActualShapeType);
114  // show drawing controls if we're creating a polygon
115  if (myActualShapeType == SUMO_TAG_POLY) {
116  myDrawingMode->showDrawingMode();
117  } else {
118  myDrawingMode->hideDrawingMode();
119  }
120  }
121 }
122 
123 
126 }
127 
128 
130 GNEPolygonFrame::processClick(const Position& clickedPosition, GNELane* lane) {
131  // Declare map to keep values
132  std::map<SumoXMLAttr, std::string> valuesOfElement = myShapeAttributes->getAttributesAndValues();
133  // check if current selected shape is valid
135  // show warning dialogbox and stop if input parameters are invalid
136  if (myShapeAttributes->areValuesValid() == false) {
138  return ADDSHAPE_INVALID;
139  }
140  // generate new ID
142  // obtain position
143  valuesOfElement[SUMO_ATTR_POSITION] = toString(clickedPosition);
144  // obtain block movement value
146  // return ADDSHAPE_SUCCESS if POI was sucesfully created
147  if (addPOI(valuesOfElement)) {
148  return ADDSHAPE_SUCCESS;
149  } else {
150  return ADDSHAPE_INVALID;
151  }
152  } else if (myActualShapeType == SUMO_TAG_POILANE) {
153  // show warning dialogbox and stop if input parameters are invalid
154  if (myShapeAttributes->areValuesValid() == false) {
156  return ADDSHAPE_INVALID;
157  }
158  // abort if lane is NULL
159  if (lane == NULL) {
160  WRITE_WARNING(toString(SUMO_TAG_POILANE) + " can be only placed over lanes");
161  return ADDSHAPE_INVALID;
162  }
163  // generate new ID
165  // obtain Lane
166  valuesOfElement[SUMO_ATTR_LANE] = lane->getID();
167  // obtain position over lane
168  valuesOfElement[SUMO_ATTR_POSITION] = toString(lane->getShape().nearest_offset_to_point2D(clickedPosition));
169  // obtain block movement value
171  // return ADDSHAPE_SUCCESS if POI was sucesfully created
172  if (addPOILane(valuesOfElement)) {
173  return ADDSHAPE_SUCCESS;
174  } else {
175  return ADDSHAPE_INVALID;
176  }
177  } else if (myActualShapeType == SUMO_TAG_POLY) {
178  if (myDrawingMode->isDrawing()) {
179  myDrawingMode->addNewPoint(clickedPosition);
180  return ADDSHAPE_NEWPOINT;
181  } else {
182  // return ADDSHAPE_NOTHING if is drawing isn't enabled
183  return ADDSHAPE_NOTHING;
184  }
185  } else {
186  myViewNet->setStatusBarText("Current selected shape isn't valid.");
187  return ADDSHAPE_INVALID;
188  }
189 }
190 
191 
192 bool
194  // show warning dialogbox and stop check if input parameters are valid
195  if (myShapeAttributes->areValuesValid() == false) {
197  return false;
198  } else {
199  // Declare map to keep values
200  std::map<SumoXMLAttr, std::string> valuesOfElement = myShapeAttributes->getAttributesAndValues();
201 
202  // generate new ID
204 
205  // obtain shape
206  valuesOfElement[SUMO_ATTR_SHAPE] = toString(drawedShape);
207 
208  // obtain geo (by default false)
209  valuesOfElement[SUMO_ATTR_GEO] = "false";
210 
211  // obtain block movement value
213 
214  // obtain block shape value
216 
217  // return ADDSHAPE_SUCCESS if POI was sucesfully created
218  return addPolygon(valuesOfElement);
219  }
220 }
221 
222 
223 long
224 GNEPolygonFrame::onCmdSelectShape(FXObject*, FXSelector, void*) {
225  // Flag to save if name is valid
226  bool shapeNameCorrect = false;
227  // set parameters of shape, if it's correct
228  for (auto i : GNEAttributeCarrier::allowedShapeTags()) {
229  if (toString(i) == myShapeMatchBox->getText().text()) {
230  myShapeMatchBox->setTextColor(FXRGB(0, 0, 0));
231  myShapeAttributes->show();
234  shapeNameCorrect = true;
235  }
236  }
237  // if shape name isn't correct, hidde all
238  if (shapeNameCorrect == false) {
240  myShapeMatchBox->setTextColor(FXRGB(255, 0, 0));
241  myShapeAttributes->hide();
244  } else {
245  // show drawing controls if we're creating a polygon
248  } else {
250  }
251  }
252  return 1;
253 }
254 
255 
256 void
258  // Show frame
259  GNEFrame::show();
260 }
261 
262 
263 std::string
264 GNEPolygonFrame::getIdsSelected(const FXList* list) {
265  // Obtain Id's of list
266  std::string vectorOfIds;
267  for (int i = 0; i < list->getNumItems(); i++) {
268  if (list->isItemSelected(i)) {
269  if (vectorOfIds.size() > 0) {
270  vectorOfIds += " ";
271  }
272  vectorOfIds += (list->getItem(i)->getText()).text();
273  }
274  }
275  return vectorOfIds;
276 }
277 
278 
279 void
281  // Set new actualShapeType
282  myActualShapeType = actualShapeType;
283  // Clear internal attributes
285  // Iterate over attributes of myActualShapeType
289  }
290  }
291  // if there are parmeters, show and Recalc groupBox
294  } else {
296  }
297 }
298 
299 
300 bool
301 GNEPolygonFrame::addPolygon(const std::map<SumoXMLAttr, std::string>& polyValues) {
302  bool ok = true;
303  // parse attributes from polyValues
304  std::string id = polyValues.at(SUMO_ATTR_ID);
305  std::string type = polyValues.at(SUMO_ATTR_TYPE);
306  RGBColor color = RGBColor::parseColor(polyValues.at(SUMO_ATTR_COLOR));
307  double layer = GNEAttributeCarrier::parse<double>(polyValues.at(SUMO_ATTR_LAYER));
308  double angle = GNEAttributeCarrier::parse<double>(polyValues.at(SUMO_ATTR_ANGLE));
309  std::string imgFile = polyValues.at(SUMO_ATTR_IMGFILE);
310  PositionVector shape = GeomConvHelper::parseShapeReporting(polyValues.at(SUMO_ATTR_SHAPE), "user-supplied position", 0, ok, true);
311  bool fill = GNEAttributeCarrier::parse<bool>(polyValues.at(SUMO_ATTR_FILL));
312 
313  // create new Polygon only if number of shape points is greather than 2
315  if ((shape.size() > 0) && myViewNet->getNet()->addPolygon(id, type, color, layer, angle, imgFile, shape, false, fill)) {
316  // set manually attributes use GEO, block movement and block shape
317  GNEPoly* polygon = myViewNet->getNet()->retrievePolygon(id);
321  return true;
322  } else {
323  // abort creation
325  return false;
326  }
327 }
328 
329 
330 bool
331 GNEPolygonFrame::addPOI(const std::map<SumoXMLAttr, std::string>& POIValues) {
332  bool ok = true;
333  // parse attributes from POIValues
334  std::string id = POIValues.at(SUMO_ATTR_ID);
335  std::string type = POIValues.at(SUMO_ATTR_TYPE);
336  RGBColor color = RGBColor::parseColor(POIValues.at(SUMO_ATTR_COLOR));
337  double layer = GNEAttributeCarrier::parse<double>(POIValues.at(SUMO_ATTR_LAYER));
338  Position pos = GeomConvHelper::parseShapeReporting(POIValues.at(SUMO_ATTR_POSITION), "netedit-given", 0, ok, false)[0];
339  double angle = GNEAttributeCarrier::parse<double>(POIValues.at(SUMO_ATTR_ANGLE));
340  std::string imgFile = POIValues.at(SUMO_ATTR_IMGFILE);
341  double widthPOI = GNEAttributeCarrier::parse<double>(POIValues.at(SUMO_ATTR_WIDTH));
342  double heightPOI = GNEAttributeCarrier::parse<double>(POIValues.at(SUMO_ATTR_HEIGHT));
343 
344  // create new POI
346  if (myViewNet->getNet()->addPOI(id, type, color, pos, false, "", 0, 0, layer, angle, imgFile, widthPOI, heightPOI)) {
347  // Set manually the attribute block movement
348  GNEPOI* poi = myViewNet->getNet()->retrievePOI(id);
351  return true;
352  } else {
353  // abort creation
355  return false;
356  }
357 }
358 
359 
360 bool
361 GNEPolygonFrame::addPOILane(const std::map<SumoXMLAttr, std::string>& POIValues) {
362  // parse attributes from POIValues
363  std::string id = POIValues.at(SUMO_ATTR_ID);
364  std::string type = POIValues.at(SUMO_ATTR_TYPE);
365  RGBColor color = RGBColor::parseColor(POIValues.at(SUMO_ATTR_COLOR));
366  double layer = GNEAttributeCarrier::parse<double>(POIValues.at(SUMO_ATTR_LAYER));
367  double angle = GNEAttributeCarrier::parse<double>(POIValues.at(SUMO_ATTR_ANGLE));
368  std::string imgFile = POIValues.at(SUMO_ATTR_IMGFILE);
369  GNELane* lane = myViewNet->getNet()->retrieveLane(POIValues.at(SUMO_ATTR_LANE));
370  double posLane = GNEAttributeCarrier::parse<double>(POIValues.at(SUMO_ATTR_POSITION));
371  double posLat = GNEAttributeCarrier::parse<double>(POIValues.at(SUMO_ATTR_POSITION_LAT));
372  double widthPOI = GNEAttributeCarrier::parse<double>(POIValues.at(SUMO_ATTR_WIDTH));
373  double heightPOI = GNEAttributeCarrier::parse<double>(POIValues.at(SUMO_ATTR_HEIGHT));
374 
375  // create new POILane
377  if (myViewNet->getNet()->addPOI(id, type, color, Position(), false, lane->getID(), posLane, posLat, layer, angle, imgFile, widthPOI, heightPOI)) {
378  // Set manually the attribute block movement
379  GNEPOILane* POILane = myViewNet->getNet()->retrievePOILane(id);
382  return true;
383  } else {
384  // abort creation
386  return false;
387  }
388 }
389 
390 // ---------------------------------------------------------------------------
391 // GNEPolygonFrame::ShapeAttributeSingle - methods
392 // ---------------------------------------------------------------------------
393 
395  FXHorizontalFrame(parent, GUIDesignAuxiliarHorizontalFrame),
396  myShapeTag(SUMO_TAG_NOTHING),
397  myShapeAttr(SUMO_ATTR_NOTHING) {
398  // Create visual elements
399  myLabel = new FXLabel(this, "name", 0, GUIDesignLabelAttribute);
400  mycolorEditor = new FXButton(this, "ColorButton", 0, this, MID_GNE_INSPECTORFRAME_ATTRIBUTEEDITOR, GUIDesignButtonAttribute);
405  // Hide elements
406  hideParameter();
407 }
408 
409 
411 
412 
413 void
415  myShapeTag = shapeTag;
416  myShapeAttr = shapeAttr;
417  myInvalidValue = "";
418  myLabel->setText(toString(myShapeAttr).c_str());
419  myLabel->show();
420  myTextFieldStrings->setTextColor(FXRGB(0, 0, 0));
421  myTextFieldStrings->setText(value.c_str());
422  myTextFieldStrings->show();
423  show();
424 }
425 
426 
427 void
429  myShapeTag = shapeTag;
430  myShapeAttr = shapeAttr;
431  myInvalidValue = "";
432  myLabel->setText(toString(myShapeAttr).c_str());
433  myLabel->show();
434  myTextFieldInt->setTextColor(FXRGB(0, 0, 0));
435  myTextFieldInt->setText(toString(value).c_str());
436  myTextFieldInt->show();
437  show();
438 }
439 
440 
441 void
443  myShapeTag = shapeTag;
444  myShapeAttr = shapeAttr;
445  myInvalidValue = "";
446  myLabel->setText(toString(myShapeAttr).c_str());
447  myLabel->show();
448  myTextFieldReal->setTextColor(FXRGB(0, 0, 0));
449  myTextFieldReal->setText(toString(value).c_str());
450  myTextFieldReal->show();
451  show();
452 }
453 
454 
455 void
457  myShapeTag = shapeTag;
458  myShapeAttr = shapeAttr;
459  myInvalidValue = "";
460  myLabel->setText(toString(myShapeAttr).c_str());
461  myLabel->show();
462  if (value) {
463  myBoolCheckButton->setCheck(true);
464  myBoolCheckButton->setText("true");
465  } else {
466  myBoolCheckButton->setCheck(false);
467  myBoolCheckButton->setText("false");
468  }
469  myBoolCheckButton->show();
470  show();
471 }
472 
473 
474 void
476  myShapeTag = shapeTag;
477  myShapeAttr = shapeAttr;
478  myInvalidValue = "";
479  mycolorEditor->setText(toString(myShapeAttr).c_str());
480  mycolorEditor->show();
481  myTextFieldStrings->setTextColor(FXRGB(0, 0, 0));
482  myTextFieldStrings->setText(toString(value).c_str());
483  myTextFieldStrings->show();
484  show();
485 }
486 
487 
488 void
492  myLabel->hide();
493  myTextFieldInt->hide();
494  myTextFieldReal->hide();
495  myTextFieldStrings->hide();
496  myBoolCheckButton->hide();
497  mycolorEditor->hide();
498  hide();
499 }
500 
501 
504  return myShapeTag;
505 }
506 
507 
510  return myShapeAttr;
511 }
512 
513 
514 std::string
517  return (myBoolCheckButton->getCheck() == 1) ? "true" : "false";
519  return myTextFieldInt->getText().text();
521  return myTextFieldReal->getText().text();
522  } else {
523  return myTextFieldStrings->getText().text();
524  }
525 }
526 
527 
528 const std::string&
530  return myInvalidValue;
531 }
532 
533 
534 long
536  // We assume that current value is valid
537  myInvalidValue = "";
538  // Check if format of current value of myTextField is correct
540  if (GNEAttributeCarrier::canParse<int>(myTextFieldInt->getText().text())) {
541  // convert string to int
542  int intValue = GNEAttributeCarrier::parse<int>(myTextFieldInt->getText().text());
543  // Check if int value must be positive
544  if (GNEAttributeCarrier::isPositive(myShapeTag, myShapeAttr) && (intValue < 0)) {
545  myInvalidValue = "'" + toString(myShapeAttr) + "' cannot be negative";
546  }
547  } else {
548  myInvalidValue = "'" + toString(myShapeAttr) + "' doesn't have a valid 'int' format";
549  }
551  // time attributes work as positive doubles
552  if (GNEAttributeCarrier::canParse<double>(myTextFieldReal->getText().text())) {
553  // convert string to double
554  double doubleValue = GNEAttributeCarrier::parse<double>(myTextFieldReal->getText().text());
555  // Check if parsed value is negative
556  if (doubleValue < 0) {
557  myInvalidValue = "'" + toString(myShapeAttr) + "' cannot be negative";
558  }
559  } else {
560  myInvalidValue = "'" + toString(myShapeAttr) + "' doesn't have a valid 'time' format";
561  }
563  if (GNEAttributeCarrier::canParse<double>(myTextFieldReal->getText().text())) {
564  // convert string to double
565  double doubleValue = GNEAttributeCarrier::parse<double>(myTextFieldReal->getText().text());
566  // Check if double value must be positive
567  if (GNEAttributeCarrier::isPositive(myShapeTag, myShapeAttr) && (doubleValue < 0)) {
568  myInvalidValue = "'" + toString(myShapeAttr) + "' cannot be negative";
569  // check if double value is a probability
570  } else if (GNEAttributeCarrier::isProbability(myShapeTag, myShapeAttr) && ((doubleValue < 0) || doubleValue > 1)) {
571  myInvalidValue = "'" + toString(myShapeAttr) + "' takes only values between 0 and 1";
572  }
573  } else {
574  myInvalidValue = "'" + toString(myShapeAttr) + "' doesn't have a valid 'float' format";
575  }
577  // check if filename format is valid
578  if (GNEAttributeCarrier::canParse<RGBColor>(myTextFieldStrings->getText().text()) == false) {
579  myInvalidValue = "'" + toString(myShapeAttr) + "' doesn't have a valid 'RBGColor' format";
580  }
582  std::string file = myTextFieldStrings->getText().text();
583  // check if filename format is valid
584  if (GNEAttributeCarrier::isValidFilename(file) == false) {
585  myInvalidValue = "input contains invalid characters for a filename";
586  } else if (myShapeAttr == SUMO_ATTR_IMGFILE) {
587  if (!file.empty()) {
588  // only load value if file isn't empty
589  if (GUITexturesHelper::getTextureID(file) == -1) {
590  myInvalidValue = "doesn't exist image '" + file + "'";
591  }
592  }
593  }
594  }
595  // change color of text field depending of myCurrentValueValid
596  if (myInvalidValue.size() == 0) {
597  myTextFieldInt->setTextColor(FXRGB(0, 0, 0));
598  myTextFieldInt->killFocus();
599  myTextFieldReal->setTextColor(FXRGB(0, 0, 0));
600  myTextFieldReal->killFocus();
601  myTextFieldStrings->setTextColor(FXRGB(0, 0, 0));
602  myTextFieldStrings->killFocus();
603  } else {
604  // IF value of TextField isn't valid, change their color to Red
605  myTextFieldInt->setTextColor(FXRGB(255, 0, 0));
606  myTextFieldReal->setTextColor(FXRGB(255, 0, 0));
607  myTextFieldStrings->setTextColor(FXRGB(255, 0, 0));
608  }
609  // Update aditional frame
610  update();
611  return 1;
612 }
613 
614 
615 long
617  if (myBoolCheckButton->getCheck()) {
618  myBoolCheckButton->setText("true");
619  } else {
620  myBoolCheckButton->setText("false");
621  }
622  return 0;
623 }
624 
625 
627  // create FXColorDialog
628  FXColorDialog colordialog(this, tr("Color Dialog"));
629  colordialog.setTarget(this);
630  colordialog.setRGBA(MFXUtils::getFXColor(RGBColor::parseColor(myTextFieldStrings->getText().text())));
631  // execute dialog to get a new color
632  if (colordialog.execute()) {
633  myTextFieldStrings->setText(toString(MFXUtils::getRGBColor(colordialog.getRGBA())).c_str());
634  }
635  return 0;
636 }
637 
638 // ---------------------------------------------------------------------------
639 // GNEPolygonFrame::NeteditAttributes- methods
640 // ---------------------------------------------------------------------------
641 
643  FXGroupBox(parent, "Internal attributes", GUIDesignGroupBoxFrame),
644  myViewNet(viewNet),
645  myIndexParameter(0),
646  myIndexParameterList(0),
647  maxNumberOfParameters(GNEAttributeCarrier::getHigherNumberOfAttributes()),
648  maxNumberOfListParameters(2) {
649 
650  // Create single parameters
651  for (int i = 0; i < maxNumberOfParameters; i++) {
653  }
654 
655  // Create help button
656  helpShape = new FXButton(this, "Help", 0, this, MID_HELP, GUIDesignButtonRectangular);
657 }
658 
659 
661 }
662 
663 
664 void
666  // Hidde al fields
667  for (int i = 0; i < maxNumberOfParameters; i++) {
668  myVectorOfsingleShapeParameter.at(i)->hideParameter();
669  }
670 
671  // Reset indexs
673  myIndexParameter = 0;
674 }
675 
676 
677 void
679  // Set current shape
680  myShapeTag = shapeTag;
681 
683  // Check type of attribute list
684  if (GNEAttributeCarrier::isInt(myShapeTag, ShapeAttributeSingle)) {
685  myVectorOfsingleShapeParameter.at(myIndexParameter)->showParameter(myShapeTag, ShapeAttributeSingle, GNEAttributeCarrier::getDefaultValue<int>(myShapeTag, ShapeAttributeSingle));
686  } else if (GNEAttributeCarrier::isFloat(myShapeTag, ShapeAttributeSingle) || GNEAttributeCarrier::isTime(myShapeTag, ShapeAttributeSingle)) {
687  myVectorOfsingleShapeParameter.at(myIndexParameter)->showParameter(myShapeTag, ShapeAttributeSingle, GNEAttributeCarrier::getDefaultValue<double>(myShapeTag, ShapeAttributeSingle));
688  } else if (GNEAttributeCarrier::isBool(myShapeTag, ShapeAttributeSingle)) {
689  myVectorOfsingleShapeParameter.at(myIndexParameter)->showParameter(myShapeTag, ShapeAttributeSingle, GNEAttributeCarrier::getDefaultValue<bool>(myShapeTag, ShapeAttributeSingle));
690  } else if (GNEAttributeCarrier::isColor(myShapeTag, ShapeAttributeSingle)) {
691  myVectorOfsingleShapeParameter.at(myIndexParameter)->showParameter(myShapeTag, ShapeAttributeSingle, GNEAttributeCarrier::getDefaultValue<RGBColor>(myShapeTag, ShapeAttributeSingle));
692  } else if (GNEAttributeCarrier::isString(myShapeTag, ShapeAttributeSingle)) {
693  myVectorOfsingleShapeParameter.at(myIndexParameter)->showParameter(myShapeTag, ShapeAttributeSingle, GNEAttributeCarrier::getDefaultValue<std::string>(myShapeTag, ShapeAttributeSingle));
694  } else {
695  WRITE_WARNING("Attribute '" + toString(ShapeAttributeSingle) + "' doesn't have a defined type. Check definition in GNEAttributeCarrier");
696  }
697  // Update index parameter
699  } else {
700  WRITE_ERROR("Max number of attributes reached (" + toString(maxNumberOfParameters) + ").");
701  }
702 }
703 
704 
705 void
707  recalc();
708  show();
709 }
710 
711 
712 void
714  hide();
715 }
716 
717 
718 std::map<SumoXMLAttr, std::string>
720  std::map<SumoXMLAttr, std::string> values;
721  // get standar Parameters
722  for (int i = 0; i < myIndexParameter; i++) {
723  values[myVectorOfsingleShapeParameter.at(i)->getAttr()] = myVectorOfsingleShapeParameter.at(i)->getValue();
724  }
725  return values;
726 }
727 
728 
729 void
731  std::string errorMessage;
732  // iterate over standar parameters
733  for (int i = 0; (i < myIndexParameter) && errorMessage.empty(); i++) {
734  // Return string with the error if at least one of the parameter isn't valid
735  std::string attributeValue = myVectorOfsingleShapeParameter.at(i)->isAttributeValid();
736  if (attributeValue.size() != 0) {
737  errorMessage = attributeValue;
738  }
739  }
740  // show warning box if input parameters aren't invalid
741  if (extra.size() == 0) {
742  errorMessage = "Invalid input parameter of " + toString(myShapeTag) + ": " + errorMessage;
743  } else {
744  errorMessage = "Invalid input parameter of " + toString(myShapeTag) + ": " + extra;
745  }
746 
747  // set message in status bar
748  myViewNet->setStatusBarText(errorMessage);
749  // Write Warning in console if we're in testing mode
750  if (OptionsCont::getOptions().getBool("gui-testing-debug")) {
751  WRITE_WARNING(errorMessage);
752  }
753 }
754 
755 
756 bool
758  // iterate over standar parameters
759  for (int i = 0; i < myIndexParameter; i++) {
760  // Return false if error message of attriuve isn't empty
761  if (myVectorOfsingleShapeParameter.at(i)->isAttributeValid().size() != 0) {
762  return false;
763  }
764  }
765  return true;
766 }
767 
768 
769 int
772 }
773 
774 
775 long
776 GNEPolygonFrame::ShapeAttributes::onCmdHelp(FXObject*, FXSelector, void*) {
777  // Create help dialog
778  FXDialogBox* helpDialog = new FXDialogBox(this, ("Parameters of " + toString(myShapeTag)).c_str(), GUIDesignDialogBox);
779  // Create FXTable
780  FXTable* myTable = new FXTable(helpDialog, this, MID_TABLE, TABLE_READONLY);
781  myTable->setVisibleRows((FXint)(myIndexParameter + myIndexParameterList));
782  myTable->setVisibleColumns(3);
783  myTable->setTableSize((FXint)(myIndexParameter + myIndexParameterList), 3);
784  myTable->setBackColor(FXRGB(255, 255, 255));
785  myTable->setColumnText(0, "Name");
786  myTable->setColumnText(1, "Value");
787  myTable->setColumnText(2, "Definition");
788  myTable->getRowHeader()->setWidth(0);
789  FXHeader* header = myTable->getColumnHeader();
790  header->setItemJustify(0, JUSTIFY_CENTER_X);
791  header->setItemSize(0, 120);
792  header->setItemJustify(1, JUSTIFY_CENTER_X);
793  header->setItemSize(1, 80);
794  int maxSizeColumnDefinitions = 0;
795  // Iterate over vector of shape parameters
796  for (int i = 0; i < myIndexParameter; i++) {
797  SumoXMLTag shapeTag = myVectorOfsingleShapeParameter.at(i)->getTag();
798  SumoXMLAttr shapeAttr = myVectorOfsingleShapeParameter.at(i)->getAttr();
799  // Set name of attribute
800  myTable->setItem(i, 0, new FXTableItem(toString(shapeAttr).c_str()));
801  // Set type
802  FXTableItem* type = new FXTableItem("");
803  if (GNEAttributeCarrier::isInt(shapeTag, shapeAttr)) {
804  type->setText("int");
805  } else if (GNEAttributeCarrier::isFloat(shapeTag, shapeAttr)) {
806  type->setText("float");
807  } else if (GNEAttributeCarrier::isTime(shapeTag, shapeAttr)) {
808  type->setText("time");
809  } else if (GNEAttributeCarrier::isBool(shapeTag, shapeAttr)) {
810  type->setText("bool");
811  } else if (GNEAttributeCarrier::isColor(shapeTag, shapeAttr)) {
812  type->setText("color");
813  } else if (GNEAttributeCarrier::isString(shapeTag, shapeAttr)) {
814  type->setText("string");
815  }
816  type->setJustify(FXTableItem::CENTER_X);
817  myTable->setItem(i, 1, type);
818  // Set definition
819  FXTableItem* definition = new FXTableItem(GNEAttributeCarrier::getDefinition(shapeTag, shapeAttr).c_str());
820  definition->setJustify(FXTableItem::LEFT);
821  myTable->setItem(i, 2, definition);
822  if ((int)GNEAttributeCarrier::getDefinition(shapeTag, shapeAttr).size() > maxSizeColumnDefinitions) {
823  maxSizeColumnDefinitions = int(GNEAttributeCarrier::getDefinition(shapeTag, shapeAttr).size());
824  }
825  }
826  // Set size of column
827  header->setItemJustify(2, JUSTIFY_CENTER_X);
828  header->setItemSize(2, maxSizeColumnDefinitions * 6);
829  // Button Close
830  new FXButton(helpDialog, "OK\t\tclose", GUIIconSubSys::getIcon(ICON_ACCEPT), helpDialog, FXDialogBox::ID_ACCEPT, GUIDesignButtonOK);
831  helpDialog->create();
832  helpDialog->show();
833  return 1;
834 }
835 
836 /****************************************************************************/
AddShapeResult processClick(const Position &clickedPosition, GNELane *lane)
process click over Viewnet
void showDrawingMode()
show Drawing mode
Definition: GNEFrame.cpp:369
SumoXMLTag
Numbers representing SUMO-XML - element names.
std::string getValue() const
return value
#define GUIDesignComboBoxNCol
number of column of every combo box
Definition: GUIDesigns.h:199
static RGBColor parseColor(std::string coldef)
Parses a color information.
Definition: RGBColor.cpp:179
bool buildPoly(const PositionVector &drawedShape)
build Polygon using values of Fields and drawed shape return true if was sucesfully created ...
int getNumberOfAddedAttributes() const
get number of added attributes
#define GUIDesignCheckButtonAttribute
checkButton without thick extended over the frame used for attributes
Definition: GUIDesigns.h:116
static bool isFloat(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is numerical of type float
#define GUIDesignButtonAttribute
button extended over over column with thick and raise frame
Definition: GUIDesigns.h:59
void setParametersOfShape(SumoXMLTag actualShapeType)
set parameters depending of the new shapeType
~GNEPolygonFrame()
Destructor.
FXTextField * myTextFieldInt
textField to modify the default value of int/float/string parameters
SumoXMLTag myShapeTag
current XML attribute
block shape of a graphic element (Used mainly in GNEShapes)
AddShapeResult
FOX-declaration.
static const std::vector< SumoXMLTag > & allowedShapeTags()
get all editable for tag shape elements
A layer number.
Definition: GNEPOI.h:46
static RGBColor getRGBColor(FXColor col)
converts FXColor to RGBColor
Definition: MFXUtils.cpp:114
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
Definition: GNEPOI.cpp:196
bool addPOI(const std::string &id, const std::string &type, const RGBColor &color, const Position &pos, bool geo, const std::string &lane, double posOverLane, double posLat, double layer, double angle, const std::string &imgFile, double width, double height, bool ignorePruning=false)
Builds a POI using the given values and adds it to the container.
Definition: GNENet.cpp:251
GNEPOI * retrievePOI(const std::string &id, bool failHard=true) const
get POI by id
Definition: GNENet.cpp:948
void showWarningMessage(std::string extra="") const
show warning message with information about non-valid attributes
long onCmdHelp(FXObject *, FXSelector, void *)
GNEPoly * retrievePolygon(const std::string &id, bool failHard=true) const
get Polygon by id
Definition: GNENet.cpp:935
void remove2Update()
Removes the dialog to be updated.
void hideShapeParameters()
hide group box
static bool isPositive(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is only Positive (i.e. cannot take negative values)
GNEFrame::NeteditAttributes * myNeteditAttributes
Netedit parameter.
Definition: GNEFrame.h:352
std::map< SumoXMLAttr, std::string > getAttributesAndValues() const
get attributes and their values
long onCmdSetBooleanAttribute(FXObject *, FXSelector, void *)
called when user change the value of myBoolCheckButton
change parameter of type text
Definition: GUIAppEnum.h:635
int myIndexParameter
Index for myVectorOfsingleShapeParameter.
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
Definition: GNELane.h:53
GNEViewNet * myViewNet
pointer to viewNet
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:84
FXTextField * myTextFieldReal
textField to modify the default value of real/times parameters
SumoXMLAttr
Numbers representing SUMO-XML - attributes.
begin/end of the description of a Point of interest
void showParameter(SumoXMLTag shapeTag, SumoXMLAttr shapeAttr, std::string value)
show name and value of attribute of type string
static bool isValidFilename(const std::string &value)
true if value is a valid file value
help button
Definition: GUIAppEnum.h:396
static const std::vector< std::pair< SumoXMLAttr, std::string > > & allowedAttributes(SumoXMLTag tag)
get all editable attributes for tag and their default values.
void hideDrawingMode()
hide Drawing mode
Definition: GNEFrame.cpp:377
bool addPolygon(const std::map< SumoXMLAttr, std::string > &POIValues)
add Polygon
bool addPOI(const std::map< SumoXMLAttr, std::string > &POIValues)
add POI
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:199
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
static bool isString(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is of type string
#define GUIDesignComboBox
Definition: GUIDesigns.h:189
std::string generateShapeID(SumoXMLTag shapeTag) const
generate Shape ID
Definition: GNENet.cpp:1939
GNEViewNet * myViewNet
View Net for changes.
Definition: GNEFrame.h:337
GNEPOILane * retrievePOILane(const std::string &id, bool failHard=true) const
get POILane by id
Definition: GNENet.cpp:961
void addAttribute(SumoXMLTag shapeTag, SumoXMLAttr ShapeAttributeSingle)
add attribute
static bool isInt(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is numerical or type int
GNEFrame::DrawingMode * myDrawingMode
drawing mode
Definition: GNEFrame.h:358
static bool isTime(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is time
GNEUndoList * getUndoList() const
get the undoList object
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
Definition: GNEPOILane.cpp:210
FXButton * helpShape
button for help
FXTextField * myTextFieldStrings
textField to modify the default value of string parameters
#define GUIDesignTextField
Definition: GUIDesigns.h:40
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
bool areValuesValid() const
check if parameters of attributes are valid
FXButton * mycolorEditor
Button for open color editor.
static bool isColor(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is of type color for a certain tag
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:91
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
void addNewPoint(const Position &P)
add new point to temporal shape
Definition: GNEFrame.cpp:436
#define GUIDesignAuxiliarHorizontalFrame
design for auxiliar (Without borders) horizontal frame used to pack another frames ...
Definition: GUIDesigns.h:246
A list of positions.
static bool isFilename(SumoXMLTag tag, SumoXMLAttr attr)
whether a string attribute is a filename
void hideParameter()
hide all parameters
bool isBlockShapeEnabled() const
check if block shape is enabled
Definition: GNEFrame.cpp:134
void clearAttributes()
clear attributes
static int getTextureID(const std::string &filename, const bool mirrorX=false)
return texture id for the given filename (initialize on first use)
block movement of a graphic element
bool addPOILane(const std::map< SumoXMLAttr, std::string > &POIValues)
add POILane
invalid attribute
bool addPolygon(const std::string &id, const std::string &type, const RGBColor &color, double layer, double angle, const std::string &imgFile, const PositionVector &shape, bool fill, bool geo, bool ignorePruning=false)
Builds a polygon using the given values and adds it to the container.
Definition: GNENet.cpp:234
edge: the shape in xml-definition
const std::string getID() const
function to support debugging
void setAttribute(SumoXMLAttr key, const std::string &value, GNEUndoList *undoList)
method for setting the attribute and letting the object perform additional changes ...
Definition: GNEPoly.cpp:560
FXDEFMAP(GNEPolygonFrame) GNEPolygonFrameMap[]
void p_abort()
reverts and discards ALL active command groups
#define GUIDesignButtonRectangular
little button rectangular (46x23) used in frames (For example, in "help" buttons) ...
Definition: GUIDesigns.h:62
open edit attribute dialog
Definition: GUIAppEnum.h:579
FXComboBox * myShapeMatchBox
combo box with the list of shape elements
change parameter of tpye bool
Definition: GUIAppEnum.h:637
static bool isUnique(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is unique (may not be edited for a multi-selection and don&#39;t have a default valu...
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:205
#define GUIDesignTextFieldNCol
Num of column of text field.
Definition: GUIDesigns.h:49
SumoXMLTag myActualShapeType
actual shape type selected in the match Box
SumoXMLTag myShapeTag
current shape tag
const PositionVector & getShape() const
returns the shape of the lane
Definition: GNELane.cpp:599
virtual void show()
show Frame
Definition: GNEFrame.cpp:546
static bool isProbability(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is a probability (i.e. oly can values between [0, 1])
#define GUIDesignDialogBox
Definition: GUIDesigns.h:395
int maxNumberOfParameters
max number of parameters (Defined in constructor)
#define GUIDesignGroupBoxFrame
Group box design extended over frame.
Definition: GUIDesigns.h:221
void show()
show shape frame and update use selected edges/lanes
static bool isBool(SumoXMLTag tag, SumoXMLAttr attr)
whether an attribute is of type bool for a certain tag
const std::string & isAttributeValid() const
returns a empty string if current value is valid, a string with information about invalid value in ot...
SumoXMLAttr getAttr() const
return Attr
std::vector< ShapeAttributeSingle * > myVectorOfsingleShapeParameter
vector with the shape parameters
GNEPolygonFrame::ShapeAttributes * myShapeAttributes
shape internal attributes
static std::string getDefinition(SumoXMLTag tag, SumoXMLAttr attr)
return definition of a certain SumoXMLAttr
#define GUIDesignTextFieldInt
text field extended over Frame with thick frame and limited to Integers
Definition: GUIDesigns.h:43
virtual void hide()
hide Frame
Definition: GNEFrame.cpp:555
void hideNeteditAttributes()
hide NeteditAttributes
Definition: GNEFrame.cpp:122
static std::string getIdsSelected(const FXList *list)
get list of selecte id&#39;s in string format
GNENet * getNet() const
get the net object
#define GUIDesignTextFieldReal
text field extended over Frame with thick frame and limited to Doubles/doubles
Definition: GUIDesigns.h:46
void showNeteditAttributes(bool shapeEditing)
show NeteditAttributes
Definition: GNEFrame.cpp:108
static FXColor getFXColor(const RGBColor &col)
converts FXColor to RGBColor
Definition: MFXUtils.cpp:120
int myIndexParameterList
index for myIndexParameterList
SumoXMLTag getTag() const
return tag
#define GUIDesignButtonOK
Definition: GUIDesigns.h:97
void setStatusBarText(const std::string &text)
set staturBar text
Definition: GNEViewNet.cpp:322
void showShapeParameters()
show group box
SumoXMLAttr myShapeAttr
current XML attribute
The Table.
Definition: GUIAppEnum.h:288
begin/end of the description of a Point of interest over Lane (used by Netedit)
#define GUIDesignLabelAttribute
label extended over the matrix column with thick frame and height of 23
Definition: GUIDesigns.h:164
FXCheckButton * myBoolCheckButton
check button to enable/disable the value of boolean parameters
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
bool isDrawing() const
return true if currently a shape is drawed
Definition: GNEFrame.cpp:464
long onCmdSetAttribute(FXObject *, FXSelector, void *)
GUISelectedStorage gSelected
A global holder of selected objects.
GNELane * retrieveLane(const std::string &id, bool failHard=true, bool checkVolatileChange=false)
get lane by id
Definition: GNENet.cpp:1000
A color information.
static FXIcon * getIcon(GUIIcon which)
returns a icon previously defined in the enum GUIIcon
static PositionVector parseShapeReporting(const std::string &shpdef, const std::string &objecttype, const char *objectid, bool &ok, bool allowEmpty, bool report=true)
Builds a PositionVector from a string representation, reporting occured errors.
Fill the polygon.
bool isBlockMovementEnabled() const
check if block movement is enabled
Definition: GNEFrame.cpp:128
begin/end of the description of a polygon
long onCmdSetColorAttribute(FXObject *, FXSelector, void *)
called when user press the "Color" button
std::string myInvalidValue
string which indicates the reason due current value is invalid
long onCmdSelectShape(FXObject *, FXSelector, void *)
FXLabel * myLabel
lael with the name of the parameter