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 4dbae67 commit 3c42629
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 41 deletions.
22 changes: 20 additions & 2 deletions src/netedit/GNEViewNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,12 +495,30 @@ GNEViewNet::updateObjectsInBoundary(const Boundary &boundary) {

void
GNEViewNet::updateObjectsInPosition(const Position &pos) {
// clear post drawing elements
gObjectsInPosition.clearElements();
// set selection position in gObjectsInPosition
gObjectsInPosition.setSelectionPosition(pos);
// create an small boundary
Boundary positionBoundary;
positionBoundary.add(pos);
positionBoundary.grow(POSITION_EPS);
// update objets in the boundary
updateObjectsInBoundary(positionBoundary);
// push matrix
GLHelper::pushMatrix();
// enable draw for object under cursor
myVisualizationSettings->drawForObjectUnderCursor = true;
// draw all GL elements within the small boundary
drawGLElements(positionBoundary);
// restore draw for object under cursor
myVisualizationSettings->drawForObjectUnderCursor = false;
// pop matrix
GLHelper::popMatrix();
// check if update front element
if (myFrontAttributeCarrier) {
gObjectsInPosition.updateFrontElement(myFrontAttributeCarrier->getGUIGlObject());
}
// after draw elements, update objects under cursor
myObjectsUnderCursor.updateObjectUnderCursor();
}


Expand Down
16 changes: 7 additions & 9 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.positionWithinShape(myAC->getGUIGlObject(), myAC->getNet()->getViewNet()->getPositionInformation(), closedShape);
gObjectsInPosition.checkShapeElement(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.positionWithinShape(myAC->getGUIGlObject(), myAC->getNet()->getViewNet()->getPositionInformation(), extrudedShape);
gObjectsInPosition.checkShapeElement(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.positionWithinShape(myAC->getGUIGlObject(), myAC->getNet()->getViewNet()->getPositionInformation(), rectangleShape);
gObjectsInPosition.checkShapeElement(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.positionWithinCircle(myAC->getGUIGlObject(), myAC->getNet()->getViewNet()->getPositionInformation(), pos, (radius * scale));
gObjectsInPosition.checkCircleElement(myAC->getGUIGlObject(), pos, (radius * scale));
} else {
drawDottedContours(s, d, true, lineWidth);
}
Expand All @@ -131,8 +131,6 @@ GNEContour::drawDottedContourGeometryPoints(const GUIVisualizationSettings& s, c
const auto scaledRadius = (radius * scale);
// check if we're calculating the mouse position over geometry or drawing dotted geometry
if (s.drawForObjectUnderCursor) {
// declare pos
const auto pos = myAC->getNet()->getViewNet()->getPositionInformation();
// iterate over all geometry points
for (int i = 0; i < (int)shape.size(); i++) {
const bool first = (i == 0);
Expand All @@ -143,13 +141,13 @@ GNEContour::drawDottedContourGeometryPoints(const GUIVisualizationSettings& s, c
(last && (geometryPoints == GeometryPoint::TO)) ||
(!first && !last && (geometryPoints == GeometryPoint::MIDDLE))) {
// check position within geometry
gObjectsInPosition.positionWithinGeometryPoint(glObject, pos, i, shape[i], scaledRadius);
gObjectsInPosition.checkGeometryPoint(glObject, i, shape[i], scaledRadius);
}
}
// check if mouse is over shape
if (s.drawForObjectUnderCursor) {
// check position over shape
gObjectsInPosition.positionOverShape(glObject, pos, shape, scaledRadius);
gObjectsInPosition.checkPositionOverShape(glObject, shape, scaledRadius);
}
} else if (!s.disableDottedContours && (d <= GUIVisualizationSettings::Detail::DottedContours)) {
// get all geometry points
Expand Down Expand Up @@ -184,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.positionWithinShape(myAC->getGUIGlObject(), myAC->getNet()->getViewNet()->getPositionInformation(), contourShape);
gObjectsInPosition.checkShapeElement(myAC->getGUIGlObject(), contourShape);
} else {
drawDottedContours(s, d, true, lineWidth);
}
Expand Down
4 changes: 2 additions & 2 deletions src/netedit/elements/additional/GNEAdditional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ GNEAdditional::checkDrawFromContour() const {
} else if (TAZRelDataFrame->shown()) {
// check first TAZ
if (TAZRelDataFrame->getFirstTAZ() == nullptr) {
return gObjectsInPosition.isElementUnderCursor(this);
return gObjectsInPosition.isElementSelected(this);
} else if (TAZRelDataFrame->getFirstTAZ() == this) {
return true;
}
Expand Down Expand Up @@ -229,7 +229,7 @@ GNEAdditional::checkDrawToContour() const {
} else if (TAZRelDataFrame->shown() && (TAZRelDataFrame->getFirstTAZ() != nullptr)) {
// check first TAZ
if (TAZRelDataFrame->getSecondTAZ() == nullptr) {
return gObjectsInPosition.isElementUnderCursor(this);
return gObjectsInPosition.isElementSelected(this);
} else if (TAZRelDataFrame->getSecondTAZ() == this) {
return true;
}
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.positionWithinCircle(this, myNet->getViewNet()->getPositionInformation(), geometryPointPos, circleWidth) : false;
const auto mouseOverPos = s.drawForObjectUnderCursor? gObjectsInPosition.checkCircleElement(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.positionWithinCircle(this, myNet->getViewNet()->getPositionInformation(), startGeometryPointPos, circleWidth);
const bool mouseOver = gObjectsInPosition.checkCircleElement(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.positionWithinCircle(this, myNet->getViewNet()->getPositionInformation(), geometryPointPos, circleWidth);
const bool mouseOver = gObjectsInPosition.checkCircleElement(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
4 changes: 2 additions & 2 deletions src/netedit/elements/network/GNEJunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ GNEJunction::checkDrawToContour() const {
// check if we're over a destiny junction
if (junctionSource) {
// don't create edges with the same from-to junction
if ((junctionSource != this) && gObjectsInPosition.isElementUnderCursor(this)) {
if ((junctionSource != this) && gObjectsInPosition.isElementSelected(this)) {
// this junction can be a destiny junction
return true;
}
Expand Down Expand Up @@ -277,7 +277,7 @@ GNEJunction::checkDrawOverContour() const {
// check if vehicle can be placed over from-to junctions
if (vehicleTemplate && vehicleTemplate->getTagProperty().vehicleJunctions()) {
// check if junction is under cursor
return gObjectsInPosition.isElementUnderCursor(this);
return gObjectsInPosition.isElementSelected(this);
} else {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/netedit/elements/network/GNELane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ GNELane::checkDrawOverContour() const {
// check if vehicle can be placed over from-to edges
if (vehicleTemplate && vehicleTemplate->getTagProperty().vehicleEdges()) {
// check if lane is under cursor
return gObjectsInPosition.isElementUnderCursor(this);
return gObjectsInPosition.isElementSelected(this);
} else {
return false;
}
Expand Down
32 changes: 19 additions & 13 deletions src/utils/gui/settings/GUIObjectsInPosition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,15 @@ GUIObjectsInPosition::clearElements() {
}


void
GUIObjectsInPosition::setSelectionPosition(Position pos) {
mySelectionPosition = pos;
mySelectionBoundary.reset();
}


bool
GUIObjectsInPosition::isElementUnderCursor(const GUIGlObject* GLObject) const {
GUIObjectsInPosition::isElementSelected(const GUIGlObject* GLObject) const {
// avoid to insert duplicated elements
for (auto &elementLayer : myElementsUnderCursor) {
for (auto &element : elementLayer.second) {
Expand All @@ -59,7 +66,7 @@ GUIObjectsInPosition::isElementUnderCursor(const GUIGlObject* GLObject) const {


bool
GUIObjectsInPosition::isGeometryPointUnderCursor(const GUIGlObject* GLObject, const int index) const {
GUIObjectsInPosition::isGeometryPointSelected(const GUIGlObject* GLObject, const int index) const {
// avoid to insert duplicated elements
for (auto &elementLayer : myElementsUnderCursor) {
for (auto &element : elementLayer.second) {
Expand All @@ -73,8 +80,8 @@ GUIObjectsInPosition::isGeometryPointUnderCursor(const GUIGlObject* GLObject, co


bool
GUIObjectsInPosition::positionWithinCircle(const GUIGlObject* GLObject, const Position &pos, const Position &center, const double radius) {
if (pos.distanceSquaredTo2D(center) <= (radius * radius)) {
GUIObjectsInPosition::checkCircleElement(const GUIGlObject* GLObject, const Position &center, const double radius) {
if (mySelectionPosition.distanceSquaredTo2D(center) <= (radius * radius)) {
return addElementUnderCursor(GLObject);
} else {
return false;
Expand All @@ -83,8 +90,8 @@ GUIObjectsInPosition::positionWithinCircle(const GUIGlObject* GLObject, const Po


bool
GUIObjectsInPosition::positionWithinGeometryPoint(const GUIGlObject* GLObject, const Position &pos, const int index, const Position &center, const double radius) {
if (pos.distanceSquaredTo2D(center) <= (radius * radius)) {
GUIObjectsInPosition::checkGeometryPoint(const GUIGlObject* GLObject, const int index, const Position &center, const double radius) {
if (mySelectionPosition.distanceSquaredTo2D(center) <= (radius * radius)) {
return addGeometryPointUnderCursor(GLObject, index);
} else {
return false;
Expand All @@ -93,10 +100,10 @@ GUIObjectsInPosition::positionWithinGeometryPoint(const GUIGlObject* GLObject, c


bool
GUIObjectsInPosition::positionOverShape(const GUIGlObject* GLObject, const Position &pos, const PositionVector &shape, const double radius) {
GUIObjectsInPosition::checkPositionOverShape(const GUIGlObject* GLObject, const PositionVector &shape, const double radius) {
// check if mouse is over shape
const auto nearestPos = shape.positionAtOffset2D(shape.nearest_offset_to_point2D(pos));
if (pos.distanceSquaredTo2D(nearestPos) <= (radius * radius)) {
const auto nearestPos = shape.positionAtOffset2D(shape.nearest_offset_to_point2D(mySelectionPosition));
if (mySelectionPosition.distanceSquaredTo2D(nearestPos) <= (radius * radius)) {
return addPositionOverShape(GLObject, nearestPos);
} else {
return false;
Expand All @@ -105,8 +112,8 @@ GUIObjectsInPosition::positionOverShape(const GUIGlObject* GLObject, const Posit


bool
GUIObjectsInPosition::positionWithinShape(const GUIGlObject* GLObject, const Position &pos, const PositionVector &shape) {
if (shape.around(pos)) {
GUIObjectsInPosition::checkShapeElement(const GUIGlObject* GLObject, const PositionVector &shape) {
if (shape.around(mySelectionPosition)) {
return addElementUnderCursor(GLObject);
} else {
return false;
Expand Down Expand Up @@ -176,7 +183,7 @@ GUIObjectsInPosition::updateFrontElement(const GUIGlObject* GLObject) {
bool
GUIObjectsInPosition::addElementUnderCursor(const GUIGlObject* GLObject) {
// avoid to insert duplicated elements
if (isElementUnderCursor(GLObject)) {
if (isElementSelected(GLObject)) {
return false;
} else {
// check if this is an element with an associated layer
Expand Down Expand Up @@ -238,7 +245,6 @@ GUIObjectsInPosition::addPositionOverShape(const GUIGlObject* GLObject, const Po
element.posOverShape = pos;
return true;
}
return true;
}
}
}
Expand Down
27 changes: 18 additions & 9 deletions src/utils/gui/settings/GUIObjectsInPosition.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,26 @@ class GUIObjectsInPosition {
/// @brief clear elements
void clearElements();

/// @brief check if element is under cursor
bool isElementUnderCursor(const GUIGlObject* GLObject) const;
/// @brief set position selection (usually the mouse position)
void setSelectionPosition(Position pos);

/// @brief check if geometry point is under cursor
bool isGeometryPointUnderCursor(const GUIGlObject* GLObject, const int geometryPoint) const;
/// @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 positionWithinCircle(const GUIGlObject* GLObject, const Position &pos, const Position &center, const double radius);
bool checkCircleElement(const GUIGlObject* GLObject, const Position &center, const double radius);

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

/// @brief check if mouse is within geometry point
bool positionOverShape(const GUIGlObject* GLObject, const Position &pos, const PositionVector &shape, const double radius);
bool checkPositionOverShape(const GUIGlObject* GLObject, const PositionVector &shape, const double radius);

/// @brief check if mouse is within closed shapes (for filled shapes)
bool positionWithinShape(const GUIGlObject* GLObject, const Position &pos, const PositionVector &shape);
/// @brief check (closed) shape element
bool checkShapeElement(const GUIGlObject* GLObject, const PositionVector &shape);

/// @brief get all elements under cursor sorted by layer
const GLObjectsSortedContainer& getElementsUnderCursor() const;
Expand Down Expand Up @@ -132,6 +135,12 @@ class GUIObjectsInPosition {
/// @brief add position over shape
bool addPositionOverShape(const GUIGlObject* GLObject, const Position &pos);

/// @brief selection boundary
Boundary mySelectionBoundary;

/// @brief position
Position mySelectionPosition;

private:
/// @brief set copy constructor private
GUIObjectsInPosition(const GUIObjectsInPosition&) = default;
Expand Down

0 comments on commit 3c42629

Please sign in to comment.