Skip to content

Commit

Permalink
Updated GUIObjectsInPosition. Refs #13894
Browse files Browse the repository at this point in the history
  • Loading branch information
palvarezlopez committed Dec 19, 2023
1 parent 2e71724 commit bd12d65
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 83 deletions.
14 changes: 7 additions & 7 deletions src/netedit/elements/GNEContour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ GNEContour::drawDottedContourClosed(const GUIVisualizationSettings& s, const GUI
if (s.drawForObjectUnderCursor) {
// first build dotted contour
const auto closedShape = buildDottedContourClosed(s, d, shape, scale);
gObjectsInPosition.checkShapeElement(myAC->getGUIGlObject(), closedShape);
gObjectsInPosition.checkShapeElement(d, myAC->getGUIGlObject(), closedShape);
} else {
drawDottedContours(s, d, addOffset, lineWidth);
}
Expand All @@ -86,7 +86,7 @@ GNEContour::drawDottedContourExtruded(const GUIVisualizationSettings& s, const G
if (s.drawForObjectUnderCursor) {
// first build dotted contour
const auto extrudedShape = buildDottedContourExtruded(s, d, shape, extrusionWidth, scale, drawFirstExtrem, drawLastExtrem, offset);
gObjectsInPosition.checkShapeElement(myAC->getGUIGlObject(), extrudedShape);
gObjectsInPosition.checkShapeElement(d, myAC->getGUIGlObject(), extrudedShape);
} else {
drawDottedContours(s, d, true, lineWidth);
}
Expand All @@ -101,7 +101,7 @@ GNEContour::drawDottedContourRectangle(const GUIVisualizationSettings& s, const
if (s.drawForObjectUnderCursor) {
// first build dotted contour
const auto rectangleShape = buildDottedContourRectangle(s, d, pos, width, height, offsetX, offsetY, rot, scale);
gObjectsInPosition.checkShapeElement(myAC->getGUIGlObject(), rectangleShape);
gObjectsInPosition.checkShapeElement(d, myAC->getGUIGlObject(), rectangleShape);
} else {
drawDottedContours(s, d, true, lineWidth);
}
Expand All @@ -115,7 +115,7 @@ GNEContour::drawDottedContourCircle(const GUIVisualizationSettings& s, const GUI
if (s.drawForObjectUnderCursor) {
// build dotted contour
buildDottedContourCircle(s, d, pos, radius, scale);
gObjectsInPosition.checkCircleElement(myAC->getGUIGlObject(), pos, (radius * scale));
gObjectsInPosition.checkCircleElement(d, myAC->getGUIGlObject(), pos, (radius * scale));
} else {
drawDottedContours(s, d, true, lineWidth);
}
Expand All @@ -141,13 +141,13 @@ GNEContour::drawDottedContourGeometryPoints(const GUIVisualizationSettings& s, c
(last && (geometryPoints == GeometryPoint::TO)) ||
(!first && !last && (geometryPoints == GeometryPoint::MIDDLE))) {
// check position within geometry
gObjectsInPosition.checkGeometryPoint(glObject, i, shape[i], scaledRadius);
gObjectsInPosition.checkGeometryPoint(d, glObject, i, shape[i], scaledRadius);
}
}
// check if mouse is over shape
if (s.drawForObjectUnderCursor) {
// check position over shape
gObjectsInPosition.checkPositionOverShape(glObject, shape, scaledRadius);
gObjectsInPosition.checkPositionOverShape(d, glObject, shape, scaledRadius);
}
} else if (!s.disableDottedContours && (d <= GUIVisualizationSettings::Detail::DottedContours)) {
// get all geometry points
Expand Down Expand Up @@ -182,7 +182,7 @@ GNEContour::drawDottedContourEdge(const GUIVisualizationSettings& s, const GUIVi
if (s.drawForObjectUnderCursor) {
// build dotted contour
const auto contourShape = buildDottedContourEdge(s, d, edge, drawFirstExtrem, drawLastExtrem);
gObjectsInPosition.checkShapeElement(myAC->getGUIGlObject(), contourShape);
gObjectsInPosition.checkShapeElement(d, myAC->getGUIGlObject(), contourShape);
} else {
drawDottedContours(s, d, true, lineWidth);
}
Expand Down
6 changes: 3 additions & 3 deletions src/netedit/elements/network/GNEEdge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2462,7 +2462,7 @@ GNEEdge::drawEdgeGeometryPoints(const GUIVisualizationSettings& s, const GUIVisu
// obtain geometry point
const auto geometryPointPos = myNBEdge->getGeometry()[i];
// check if mouse is in geometry point position
const auto mouseOverPos = s.drawForObjectUnderCursor? gObjectsInPosition.checkCircleElement(this, geometryPointPos, circleWidth) : false;
const auto mouseOverPos = s.drawForObjectUnderCursor? gObjectsInPosition.checkCircleElement(d, this, geometryPointPos, circleWidth) : false;
// draw geometry depending of detail
if (d <= GUIVisualizationSettings::Detail::GeometryPoint) {
// obtain color
Expand Down Expand Up @@ -2512,7 +2512,7 @@ GNEEdge::drawStartGeometryPoint(const GUIVisualizationSettings& s, const GUIVisu
// check drawing conditions
if (startPosEdited || forceDraw) {
// check if mouse is over geometry point
const bool mouseOver = gObjectsInPosition.checkCircleElement(this, startGeometryPointPos, circleWidth);
const bool mouseOver = gObjectsInPosition.checkCircleElement(d, this, startGeometryPointPos, circleWidth);
// draw geometry only if we'rent in drawForObjectUnderCursor mode
if (!s.drawForObjectUnderCursor && (d <= GUIVisualizationSettings::Detail::GeometryPoint)) {
// calculate angle betwen first and second geometry point
Expand Down Expand Up @@ -2575,7 +2575,7 @@ GNEEdge::drawEndGeometryPoint(const GUIVisualizationSettings& s, const GUIVisual
// check drawing conditions
if (endPosEdited || forceDraw) {
// check if mouse is over geometry point
const bool mouseOver = gObjectsInPosition.checkCircleElement(this, geometryPointPos, circleWidth);
const bool mouseOver = gObjectsInPosition.checkCircleElement(d, this, geometryPointPos, circleWidth);
// draw geometry only if we'rent in drawForObjectUnderCursor mode
if (!s.drawForObjectUnderCursor && (d <= GUIVisualizationSettings::Detail::GeometryPoint)) {
// calculate angle last and previous geometry point
Expand Down
137 changes: 71 additions & 66 deletions src/utils/gui/settings/GUIObjectsInPosition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,43 +73,40 @@ GUIObjectsInPosition::isElementSelected(const GUIGlObject* GLObject) const {


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


bool
GUIObjectsInPosition::checkCircleElement(const GUIGlObject* GLObject, const Position &center, const double radius) {
GUIObjectsInPosition::checkCircleElement(const GUIVisualizationSettings::Detail d, const GUIGlObject* GLObject,
const Position &center, const double radius) {
// declare squared radius
const double squaredRadius = (radius * radius);
// continue depending if we're selecting a position or a boundary
if (mySelectionBoundary.isInitialised()) {
// make a boundary using center and radius
Boundary b;
b.add(center);
b.grow(radius);
// check if boundary overlaps
if (mySelectionBoundary.overlapsWith(b)) {
return addElementUnderCursor(GLObject);
} else {
// get shape associated with SelectionBoundary
const auto boundaryVertices = mySelectionBoundary.getShape(false);
// check the four vertex
for (const auto &vertex : boundaryVertices) {
if (vertex.distanceSquaredTo2D(center) <= squaredRadius) {
return addElementUnderCursor(GLObject);
// continue depending of detail level
if (d <= GUIVisualizationSettings::Detail::PreciseSelection) {
// make a boundary using center and radius
Boundary b;
b.add(center);
b.grow(radius);
// check if boundary overlaps
if (mySelectionBoundary.overlapsWith(b)) {
return addElementUnderCursor(GLObject);
} else {
// get shape associated with SelectionBoundary
const auto boundaryVertices = mySelectionBoundary.getShape(false);
// check the four vertex
for (const auto &vertex : boundaryVertices) {
if (vertex.distanceSquaredTo2D(center) <= squaredRadius) {
return addElementUnderCursor(GLObject);
}
}
// no intersection, then return false
return false;
}
} else {
// check if center is within mySelectionBoundary
if (mySelectionBoundary.around(center)) {
return addElementUnderCursor(GLObject);
} else {
return false;
}
// no intersection, then return false
return false;
}
} else if (mySelectionPosition != Position::INVALID) {
// check distance between selection position and center
Expand All @@ -125,29 +122,40 @@ GUIObjectsInPosition::checkCircleElement(const GUIGlObject* GLObject, const Posi


bool
GUIObjectsInPosition::checkGeometryPoint(const GUIGlObject* GLObject, const int index, const Position &center, const double radius) {
GUIObjectsInPosition::checkGeometryPoint(const GUIVisualizationSettings::Detail d, const GUIGlObject* GLObject,
const int index, const Position &center, const double radius) {
// declare squared radius
const double squaredRadius = (radius * radius);
// continue depending if we're selecting a position or a boundary
if (mySelectionBoundary.isInitialised()) {
// make a boundary using center and radius
Boundary b;
b.add(center);
b.grow(radius);
// check if boundary overlaps
if (mySelectionBoundary.overlapsWith(b)) {
return addGeometryPointUnderCursor(GLObject, index);
} else {
// get shape associated with SelectionBoundary
const auto boundaryVertices = mySelectionBoundary.getShape(false);
// check the four vertex
for (const auto &vertex : boundaryVertices) {
if (vertex.distanceSquaredTo2D(center) <= squaredRadius) {
return addGeometryPointUnderCursor(GLObject, index);
// continue depending of detail level
if (d <= GUIVisualizationSettings::Detail::PreciseSelection) {
// make a boundary using center and radius
Boundary b;
b.add(center);
b.grow(radius);
// check if boundary overlaps
if (mySelectionBoundary.overlapsWith(b)) {
return addGeometryPointUnderCursor(GLObject, index);
} else {
// get shape associated with SelectionBoundary
const auto boundaryVertices = mySelectionBoundary.getShape(false);
// check the four vertex
for (const auto &vertex : boundaryVertices) {
if (vertex.distanceSquaredTo2D(center) <= squaredRadius) {
return addGeometryPointUnderCursor(GLObject, index);
}
}
// no intersection, then return false
return false;
}
} else {
// check if center is within mySelectionBoundary
if (mySelectionBoundary.around(center)) {
return addElementUnderCursor(GLObject);
} else {
return false;
}
// no intersection, then return false
return false;
}
} else if (mySelectionPosition != Position::INVALID) {
// check distance between selection position and center
Expand All @@ -163,8 +171,9 @@ GUIObjectsInPosition::checkGeometryPoint(const GUIGlObject* GLObject, const int


bool
GUIObjectsInPosition::checkPositionOverShape(const GUIGlObject* GLObject, const PositionVector &shape, const double distance) {
if (mySelectionPosition != Position::INVALID) {
GUIObjectsInPosition::checkPositionOverShape(const GUIVisualizationSettings::Detail d, const GUIGlObject* GLObject,
const PositionVector &shape, const double distance) {
if ((mySelectionPosition != Position::INVALID) && (d <= GUIVisualizationSettings::Detail::PreciseSelection)) {
// obtain nearest position over shape
const auto nearestPos = shape.positionAtOffset2D(shape.nearest_offset_to_point2D(mySelectionPosition));
// check distance nearest position and pos
Expand All @@ -180,26 +189,22 @@ GUIObjectsInPosition::checkPositionOverShape(const GUIGlObject* GLObject, const


bool
GUIObjectsInPosition::checkShapeElement(const GUIGlObject* GLObject, const PositionVector &shape) {
// continue depending if we're selecting a position or a boundary
GUIObjectsInPosition::checkShapeElement(const GUIVisualizationSettings::Detail d, const GUIGlObject* GLObject,
const PositionVector &shape) {
// continue depending if we're selecting a position or a boundary
if (mySelectionBoundary.isInitialised()) {
// get shape boundary
const Boundary shapeBoundary = shape.getBoxBoundary();
// check if boundary overlaps
if (mySelectionBoundary.overlapsWith(shapeBoundary)) {
if (shape.getBoxBoundary().overlapsWith(mySelectionBoundary)) {
return addElementUnderCursor(GLObject);
} else {
// get shape associated with SelectionBoundary
const auto boundaryVertices = mySelectionBoundary.getShape(false);
// check the four vertex
for (const auto &vertex : boundaryVertices) {
if (shape.around(vertex)) {
return addElementUnderCursor(GLObject);
}

XXX Check that shape boundary is contained in mySelectionBoundary

}
for (int i = 1; i < shape.size(); i++) {
if (mySelectionBoundary.crosses(shape[i-1], shape[i])) {
return addElementUnderCursor(GLObject);
}
// no intersection, then return false
return false;
}
return false;
} else if (mySelectionPosition != Position::INVALID) {
// check if selection position is around shape
if (shape.around(mySelectionPosition)) {
Expand Down
16 changes: 9 additions & 7 deletions src/utils/gui/settings/GUIObjectsInPosition.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <vector>
#include <utils/gui/globjects/GUIGlObject.h>
#include <utils/gui/settings/GUIVisualizationSettings.h>

// ===========================================================================
// class declaration
Expand Down Expand Up @@ -74,20 +75,21 @@ class GUIObjectsInPosition {
/// @brief check if element was already selected
bool isElementSelected(const GUIGlObject* GLObject) const;

/// @brief check if the given geometry point is selected
bool isGeometryPointSelected(const GUIGlObject* GLObject, const int geometryPoint) const;

/// @brief check if mouse is within elements geometry (for circles)
bool checkCircleElement(const GUIGlObject* GLObject, const Position &center, const double radius);
bool checkCircleElement(const GUIVisualizationSettings::Detail d, const GUIGlObject* GLObject,
const Position &center, const double radius);

/// @brief check if mouse is within geometry point
bool checkGeometryPoint(const GUIGlObject* GLObject, const int index, const Position &center, const double radius);
bool checkGeometryPoint(const GUIVisualizationSettings::Detail d, const GUIGlObject* GLObject,
const int index, const Position &center, const double radius);

/// @brief check if mouse is within geometry point
bool checkPositionOverShape(const GUIGlObject* GLObject, const PositionVector &shape, const double distance);
bool checkPositionOverShape(const GUIVisualizationSettings::Detail d, const GUIGlObject* GLObject,
const PositionVector &shape, const double distance);

/// @brief check (closed) shape element
bool checkShapeElement(const GUIGlObject* GLObject, const PositionVector &shape);
bool checkShapeElement(const GUIVisualizationSettings::Detail d, const GUIGlObject* GLObject,
const PositionVector &shape);

/// @brief get all elements under cursor sorted by layer
const GLObjectsSortedContainer& getElementsUnderCursor() const;
Expand Down
1 change: 1 addition & 0 deletions src/utils/gui/settings/GUIVisualizationSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ class GUIVisualizationSettings {
GeometryPoint = 1, // draw geometry points
JunctionElement = 1, // crossings, walking area, connections and internal lanes
DottedContoursResampled = 1, // resample dotted contours
PreciseSelection = 1, // precise selection using boundaries

Level2 = 2,
CircleResolution8 = 2, // circle resolution = 8
Expand Down

0 comments on commit bd12d65

Please sign in to comment.