Skip to content

Commit

Permalink
Fixed #14561
Browse files Browse the repository at this point in the history
  • Loading branch information
palvarezlopez committed Mar 31, 2024
1 parent 671e37e commit 50d9510
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 71 deletions.
117 changes: 57 additions & 60 deletions src/netedit/elements/network/GNEEdge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ GNEEdge::drawGL(const GUIVisualizationSettings& s) const {
// draw edge stopOffset
drawLaneStopOffset(s, d);
// draw edge name
drawEdgeName(s, d);
drawEdgeName(s);
// draw lock icon
GNEViewNetHelper::LockIcon::drawLockIcon(d, this, getType(), getPositionInView(), 1);
// draw dotted contour
Expand Down Expand Up @@ -2687,65 +2687,62 @@ GNEEdge::drawEndGeometryPoint(const GUIVisualizationSettings& s, const GUIVisual


void
GNEEdge::drawEdgeName(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d) const {
// check if we can draw it
if (d <= GUIVisualizationSettings::Detail::Names) {
// draw the name and/or the street name
const bool drawStreetName = s.streetName.show(this) && (myNBEdge->getStreetName() != "");
const bool spreadSuperposed = s.spreadSuperposed && myNBEdge->getBidiEdge() != nullptr;
// check conditions
if (s.edgeName.show(this) || drawStreetName || s.edgeValue.show(this)) {
// get first and last lanes
const GNELane* firstLane = myLanes[0];
const GNELane* lastLane = myLanes[myLanes.size() - 1];
// calculate draw position
Position drawPosition = firstLane->getLaneShape().positionAtOffset(firstLane->getLaneShape().length() / (double) 2.);
drawPosition.add(lastLane->getLaneShape().positionAtOffset(lastLane->getLaneShape().length() / (double) 2.));
drawPosition.mul(.5);
if (spreadSuperposed) {
// move name to the right of the edge and towards its beginning
const double dist = 0.6 * s.edgeName.scaledSize(s.scale);
const double shiftA = firstLane->getLaneShape().rotationAtOffset(firstLane->getLaneShape().length() / (double) 2.) - DEG2RAD(135);
const Position shift(dist * cos(shiftA), dist * sin(shiftA));
drawPosition.add(shift);
}
// calculate drawing angle
double drawAngle = firstLane->getLaneShape().rotationDegreeAtOffset(firstLane->getLaneShape().length() / (double) 2.);
drawAngle += 90;
// avoid draw inverted text
if (drawAngle > 90 && drawAngle < 270) {
drawAngle -= 180;
}
// draw edge name
if (s.edgeName.show(this)) {
drawName(drawPosition, s.scale, s.edgeName, drawAngle);
}
// draw street name
if (drawStreetName) {
GLHelper::drawTextSettings(s.streetName, myNBEdge->getStreetName(), drawPosition, s.scale, drawAngle);
}
// draw edge values
if (s.edgeValue.show(this)) {
// get current scheme
const int activeScheme = s.laneColorer.getActive();
// calculate value depending of active scheme
std::string value;
if (activeScheme == 12) {
// edge param, could be non-numerical
value = getNBEdge()->getParameter(s.edgeParam, "");
} else if (activeScheme == 13) {
// lane param, could be non-numerical
value = getNBEdge()->getLaneStruct(lastLane->getIndex()).getParameter(s.laneParam, "");
} else {
// use numerical value value of leftmost lane to hopefully avoid sidewalks, bikelanes etc
const double doubleValue = lastLane->getColorValue(s, activeScheme);
const RGBColor color = s.laneColorer.getScheme().getColor(doubleValue);
value = color.alpha() == 0 ? "" : toString(doubleValue);
}
// check if value is empty
if (value != "") {
GLHelper::drawTextSettings(s.edgeValue, value, drawPosition, s.scale, drawAngle);
}
GNEEdge::drawEdgeName(const GUIVisualizationSettings& s) const {
// draw the name and/or the street name
const bool drawStreetName = s.streetName.show(this) && (myNBEdge->getStreetName() != "");
const bool spreadSuperposed = s.spreadSuperposed && myNBEdge->getBidiEdge() != nullptr;
// check conditions
if (s.edgeName.show(this) || drawStreetName || s.edgeValue.show(this)) {
// get first and last lanes
const GNELane* firstLane = myLanes[0];
const GNELane* lastLane = myLanes[myLanes.size() - 1];
// calculate draw position
Position drawPosition = firstLane->getLaneShape().positionAtOffset(firstLane->getLaneShape().length() / (double) 2.);
drawPosition.add(lastLane->getLaneShape().positionAtOffset(lastLane->getLaneShape().length() / (double) 2.));
drawPosition.mul(.5);
if (spreadSuperposed) {
// move name to the right of the edge and towards its beginning
const double dist = 0.6 * s.edgeName.scaledSize(s.scale);
const double shiftA = firstLane->getLaneShape().rotationAtOffset(firstLane->getLaneShape().length() / (double) 2.) - DEG2RAD(135);
const Position shift(dist * cos(shiftA), dist * sin(shiftA));
drawPosition.add(shift);
}
// calculate drawing angle
double drawAngle = firstLane->getLaneShape().rotationDegreeAtOffset(firstLane->getLaneShape().length() / (double) 2.);
drawAngle += 90;
// avoid draw inverted text
if (drawAngle > 90 && drawAngle < 270) {
drawAngle -= 180;
}
// draw edge name
if (s.edgeName.show(this)) {
drawName(drawPosition, s.scale, s.edgeName, drawAngle);
}
// draw street name
if (drawStreetName) {
GLHelper::drawTextSettings(s.streetName, myNBEdge->getStreetName(), drawPosition, s.scale, drawAngle);
}
// draw edge values
if (s.edgeValue.show(this)) {
// get current scheme
const int activeScheme = s.laneColorer.getActive();
// calculate value depending of active scheme
std::string value;
if (activeScheme == 12) {
// edge param, could be non-numerical
value = getNBEdge()->getParameter(s.edgeParam, "");
} else if (activeScheme == 13) {
// lane param, could be non-numerical
value = getNBEdge()->getLaneStruct(lastLane->getIndex()).getParameter(s.laneParam, "");
} else {
// use numerical value value of leftmost lane to hopefully avoid sidewalks, bikelanes etc
const double doubleValue = lastLane->getColorValue(s, activeScheme);
const RGBColor color = s.laneColorer.getScheme().getColor(doubleValue);
value = color.alpha() == 0 ? "" : toString(doubleValue);
}
// check if value is empty
if (value != "") {
GLHelper::drawTextSettings(s.edgeValue, value, drawPosition, s.scale, drawAngle);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/netedit/elements/network/GNEEdge.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ class GNEEdge : public GNENetworkElement, public GNECandidateElement {
const double geometryPointRadius, const double exaggeration) const;

/// @brief draw edge name
void drawEdgeName(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d) const;
void drawEdgeName(const GUIVisualizationSettings& s) const;

/// @brief draw edgeStopOffset
void drawLaneStopOffset(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d) const;
Expand Down
13 changes: 5 additions & 8 deletions src/netedit/elements/network/GNEJunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ GNEJunction::drawGL(const GUIVisualizationSettings& s) const {
// draw lock icon
GNEViewNetHelper::LockIcon::drawLockIcon(d, this, getType(), getPositionInView(), 1);
// draw junction name
drawJunctionName(s, d);
drawJunctionName(s);
// draw dotted contour for shape
myNetworkElementContour.drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);
// draw dotted contour for bubble
Expand Down Expand Up @@ -1713,13 +1713,10 @@ GNEJunction::drawElevation(const GUIVisualizationSettings& s, const GUIVisualiza


void
GNEJunction::drawJunctionName(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d) const {
// draw name and ID
if (d <= GUIVisualizationSettings::Detail::Names) {
drawName(myNBNode->getPosition(), s.scale, s.junctionID);
if (s.junctionName.show(this) && myNBNode->getName() != "") {
GLHelper::drawTextSettings(s.junctionName, myNBNode->getName(), myNBNode->getPosition(), s.scale, s.angle);
}
GNEJunction::drawJunctionName(const GUIVisualizationSettings& s) const {
drawName(myNBNode->getPosition(), s.scale, s.junctionID);
if (s.junctionName.show(this) && myNBNode->getName() != "") {
GLHelper::drawTextSettings(s.junctionName, myNBNode->getName(), myNBNode->getPosition(), s.scale, s.angle);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/netedit/elements/network/GNEJunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ class GNEJunction : public GNENetworkElement, public GNECandidateElement {
void drawElevation(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d) const;

/// @brief draw junction name
void drawJunctionName(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d) const;
void drawJunctionName(const GUIVisualizationSettings& s) const;

/// @brief draw junction childs
void drawJunctionChildren(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d) const;
Expand Down
1 change: 0 additions & 1 deletion src/utils/gui/settings/GUIVisualizationSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,6 @@ class GUIVisualizationSettings {
CircleResolution8 = 2, // circle resolution = 8
DrawPolygonSquare = 2, // draw polygons as squares
VehicleTriangle = 2, // draw vehicles as triangles
Names = 2, // draw element names
Additionals = 2, // draw additional elements
DottedContours = 2, // draw dotted contours
GeometryBoxLines = 2, // draw lines instead boxes in GUIGeometry::drawGeometry
Expand Down

0 comments on commit 50d9510

Please sign in to comment.