Skip to content

Commit

Permalink
Updated drawDottedContourGeometryPoints. Refs #13894
Browse files Browse the repository at this point in the history
  • Loading branch information
palvarezlopez committed Dec 19, 2023
1 parent 0f9c4ac commit 1571c0e
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 14 deletions.
30 changes: 22 additions & 8 deletions src/netedit/elements/GNEContour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,28 @@ GNEContour::drawDottedContourCircle(const GUIVisualizationSettings& s, const GUI

void
GNEContour::drawDottedContourGeometryPoints(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
const Position& pos, const int index, double radius, const double scale, const double lineWidth) const {
// check if mouse is within geometry (only in rectangle selection mode)
if (s.drawForObjectUnderCursor) {
// build dotted contour
buildDottedContourCircle(s, pos, radius, scale);
gPostDrawing.positionWithinGeometryPoint(myAC->getGUIGlObject(), myAC->getNet()->getViewNet()->getPositionInformation(), index, pos, (radius * scale));
} else {
drawDottedContours(s, d, scale, true, lineWidth);
const PositionVector& shape, GeometryPoint geometryPoints, double radius, const double scale, const double lineWidth) const {
// iterate over all geometry points
for (int i = 0; i < (int)shape.size(); i++) {
const bool first = (i == 0);
const bool last = ((i + 1) == (int)shape.size());
// check conditions
if ((geometryPoints == GeometryPoint::ALL) ||
(first && (geometryPoints == GeometryPoint::FROM)) ||
(last && (geometryPoints == GeometryPoint::TO)) ||
(!first && !last && (geometryPoints == GeometryPoint::MIDDLE))) {
// continue depending if we're checking position within geometry point or drawing dotted contour
if (s.drawForObjectUnderCursor) {
// build dotted contour
gPostDrawing.positionWithinGeometryPoint(myAC->getGUIGlObject(), myAC->getNet()->getViewNet()->getPositionInformation(), i, shape[i], (radius * scale));
} else if (!s.disableDottedContours && (d <= GUIVisualizationSettings::Detail::DottedContours) &&
gPostDrawing.isGeometryPointUnderCursor(myAC->getGUIGlObject(), i)) {
// build dotted contour circle
buildDottedContourCircle(s, shape[i], radius, scale);
// draw geometry point
drawDottedContour(s, GUIDottedGeometry::DottedContourType::MOVE, 0, lineWidth);
}
}
}
}

Expand Down
11 changes: 10 additions & 1 deletion src/netedit/elements/GNEContour.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ class GNEAttributeCarrier;
class GNEContour {

public:
/// @brief enum for check geometryPoints
enum class GeometryPoint {
FROM, // Geometry point from
TO, // Geometry point to
MIDDLE, // All geometry points except from-to
ALL // All geometry points
};

/// @brief Constructor
GNEContour(GNEAttributeCarrier* AC);

Expand Down Expand Up @@ -74,7 +82,8 @@ class GNEContour {

/// @brief draw dotted contour (geometry points elements)
void drawDottedContourGeometryPoints(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
const Position& pos, const int index, double radius, const double scale, const double lineWidth) const;
const PositionVector& shape, GeometryPoint geometryPoints, double radius, const double scale,
const double lineWidth) const;

/// @brief draw dotted contour edge
void drawDottedContourEdge(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
Expand Down
13 changes: 10 additions & 3 deletions src/netedit/elements/additional/GNEBusStop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,16 @@ GNEBusStop::drawGL(const GUIVisualizationSettings& s) const {
drawStoppingPlaceChildren(s);
// draw dotted geometry (don't exaggerate contour)
if (movingGeometryPoints) {
myContour.drawDottedContourGeometryPoints(s, d, myAdditionalGeometry.getShape().front(), 0,
s.neteditSizeSettings.additionalGeometryPointRadius, 1,
s.dottedContourSettings.segmentWidth);
if (myStartPosition != INVALID_DOUBLE) {
myContour.drawDottedContourGeometryPoints(s, d, myAdditionalGeometry.getShape(), GNEContour::GeometryPoint::FROM,
s.neteditSizeSettings.additionalGeometryPointRadius, 1,
s.dottedContourSettings.segmentWidth);
}
if (movingGeometryPoints && (myEndPosition != INVALID_DOUBLE)) {
myContour.drawDottedContourGeometryPoints(s, d, myAdditionalGeometry.getShape(), GNEContour::GeometryPoint::TO,
s.neteditSizeSettings.additionalGeometryPointRadius, 1,
s.dottedContourSettings.segmentWidth);
}
} else {
myContour.drawDottedContourExtruded(s, d, myAdditionalGeometry.getShape(), stopWidth, 1, true, true, 0,
s.dottedContourSettings.segmentWidth);
Expand Down
8 changes: 8 additions & 0 deletions src/utils/gui/div/GUIDottedGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ GUIDottedGeometry::DottedGeometryColor::getColor(const GUIVisualizationSettings&
myColorFlag = true;
return RGBColor::BLUE.changedBrightness(-30);
}
case DottedContourType::MOVE:
if (myColorFlag) {
myColorFlag = false;
return RGBColor::RED;
} else {
myColorFlag = true;
return RGBColor::RED.changedBrightness(-30);
}
case DottedContourType::OVER:
if (myColorFlag) {
myColorFlag = false;
Expand Down
1 change: 1 addition & 0 deletions src/utils/gui/div/GUIDottedGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class GUIDottedGeometry {
INSPECT, // Inspecting element
REMOVE, // Mouse over element to remove
SELECT, // Mouse over element to select
MOVE, // Mouse over element to move
FRONT, // Element marked as "front element"
OVER, // Mouse over element (orange)
FROM, // Element marked as from (green)
Expand Down
4 changes: 2 additions & 2 deletions src/utils/gui/div/GUIGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ GUIGeometry::drawGeometry(const GUIVisualizationSettings::Detail d, const GUIGeo
GLHelper::drawBoxLines(geometry.getShape(), geometry.getShapeRotations(), geometry.getShapeLengths(), width, 0, offset);
} else if (d < GUIVisualizationSettings::Detail::GeometryBoxSimpleLine) {
// set line width
glLineWidth(static_cast<double>(width));
glLineWidth(static_cast<float>(width));
// draw a simple line
GLHelper::drawLine(geometry.getShape());
// restore line width
Expand All @@ -297,7 +297,7 @@ GUIGeometry::drawGeometry(const GUIVisualizationSettings::Detail d, const GUIGeo
// set width
if (d < GUIVisualizationSettings::Detail::GeometryBoxSimpleLine) {
// set line width
glLineWidth(static_cast<double>(width));
glLineWidth(static_cast<float>(width));
// draw a simple line
GLHelper::drawLine(geometry.getShape());
// restore line width
Expand Down
12 changes: 12 additions & 0 deletions src/utils/gui/settings/GUIPostDrawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ GUIPostDrawing::isElementUnderCursor(const GUIGlObject* GLObject) const {
}


bool
GUIPostDrawing::isGeometryPointUnderCursor(const GUIGlObject* GLObject, const int index) const {
// avoid to insert duplicated elements
for (auto &element : myElementsUnderCursor) {
if (element.first == GLObject) {
return std::find(element.second.begin(), element.second.end(), index) != element.second.end();
}
}
return false;
}


bool
GUIPostDrawing::positionWithinCircle(const GUIGlObject* GLObject, const Position &pos, const Position &center, const double radius) {
if (pos.distanceSquaredTo2D(center) <= (radius * radius)) {
Expand Down
3 changes: 3 additions & 0 deletions src/utils/gui/settings/GUIPostDrawing.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class GUIPostDrawing {
/// @brief check if element is under cursor
bool isElementUnderCursor(const GUIGlObject* GLObject) const;

/// @brief check if geometry point is under cursor
bool isGeometryPointUnderCursor(const GUIGlObject* GLObject, const int geometryPoint) const;

/// @brief check if mouse is within elements geometry (for circles)
bool positionWithinCircle(const GUIGlObject* GLObject, const Position &pos, const Position &center, const double radius);

Expand Down

0 comments on commit 1571c0e

Please sign in to comment.