Skip to content

Commit

Permalink
Updated calculateMoveShapeOperation function. Refs #13894
Browse files Browse the repository at this point in the history
  • Loading branch information
palvarezlopez committed Dec 19, 2023
1 parent 49716d1 commit 5fc6407
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 52 deletions.
43 changes: 13 additions & 30 deletions src/netedit/GNEMoveElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,45 +189,28 @@ GNEMoveElement::GNEMoveElement() :


GNEMoveOperation*
GNEMoveElement::calculateMoveShapeOperation(const PositionVector originalShape, const Position mousePosition,
const double snapRadius, const bool onlyContour, const bool maintainShapeClosed) {
// calculate squared snapRadius
const double squaredSnapRadius = (snapRadius * snapRadius);
GNEMoveElement::calculateMoveShapeOperation(const GUIGlObject* obj, const PositionVector originalShape,
const bool onlyContour, const bool maintainShapeClosed) {
// get moved geometry points
const auto geometryPoints = gObjectsInPosition.getGeometryPoints(obj);
// get pos over shape
const auto posOverShape = gObjectsInPosition.getPositionOverShape(obj);
// declare shape to move
PositionVector shapeToMove = originalShape;
const int lastIndex = (int)shapeToMove.size() - 1;
// obtain nearest index
const int nearestIndex = originalShape.indexOfClosest(mousePosition);
// obtain nearest position
const Position nearestPosition = originalShape.positionAtOffset2D(originalShape.nearest_offset_to_point2D(mousePosition));
// check conditions
if (nearestIndex == -1) {
return nullptr;
} else if (nearestPosition == Position::INVALID) {
// special case for extremes
if (mousePosition.distanceSquaredTo2D(shapeToMove[nearestIndex]) <= squaredSnapRadius) {
// move geometry point without creating new geometry point
if (maintainShapeClosed && ((nearestIndex == 0) || (nearestIndex == lastIndex))) {
// move first and last point
return new GNEMoveOperation(this, originalShape, {0, lastIndex}, shapeToMove, {0, lastIndex});
} else {
return new GNEMoveOperation(this, originalShape, {nearestIndex}, shapeToMove, {nearestIndex});
}
} else {
return nullptr;
}
} else if (mousePosition.distanceSquaredTo2D(shapeToMove[nearestIndex]) <= squaredSnapRadius) {
// check if move existent geometry points or create new
if (geometryPoints.size() > 0) {
// move geometry point without creating new geometry point
if (maintainShapeClosed && ((nearestIndex == 0) || (nearestIndex == lastIndex))) {
if (maintainShapeClosed && ((geometryPoints.front() == 0) || (geometryPoints.front() == lastIndex))) {
// move first and last point
return new GNEMoveOperation(this, originalShape, {0, lastIndex}, shapeToMove, {0, lastIndex});
} else {
return new GNEMoveOperation(this, originalShape, {nearestIndex}, shapeToMove, {nearestIndex});
return new GNEMoveOperation(this, originalShape, {geometryPoints.front()}, shapeToMove, {geometryPoints.front()});
}
} else if (!onlyContour || nearestPosition.distanceSquaredTo2D(mousePosition) <= squaredSnapRadius) {
} else if (!onlyContour || (posOverShape != Position::INVALID)) {
// create new geometry point and keep new index (if we clicked near of shape)
const int newIndex = shapeToMove.insertAtClosest(nearestPosition, true);
return new GNEMoveOperation(this, originalShape, {nearestIndex}, shapeToMove, {newIndex});
const int newIndex = shapeToMove.insertAtClosest(posOverShape, true);
return new GNEMoveOperation(this, originalShape, {shapeToMove.indexOfClosest(posOverShape)}, shapeToMove, {newIndex});
} else {
return nullptr;
}
Expand Down
4 changes: 2 additions & 2 deletions src/netedit/GNEMoveElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class GNELane;
class GNEMoveElement;
class GNEUndoList;
class GNEViewNet;
class GUIGlObject;

// ===========================================================================
// class definitions
Expand Down Expand Up @@ -250,8 +251,7 @@ class GNEMoveElement {
double myMoveElementLateralOffset;

/// @brief calculate move shape operation
GNEMoveOperation* calculateMoveShapeOperation(const PositionVector originalShape, const Position mousePosition,
const double snapRadius, const bool onlyContour, const bool maintainShapeClosed);
GNEMoveOperation* calculateMoveShapeOperation(const GUIGlObject* obj, const PositionVector originalShape, const bool onlyContour, const bool maintainShapeClosed);

private:
/// @brief set move shape
Expand Down
4 changes: 2 additions & 2 deletions src/netedit/elements/additional/GNEPoly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ GNEPoly::getMoveOperation() {
case GNE_TAG_JPS_WALKABLEAREA:
case GNE_TAG_JPS_OBSTACLE:
// calculate move shape operation maintain shape closed
return calculateMoveShapeOperation(myShape, myNet->getViewNet()->getPositionInformation(), radius, true, true);
return calculateMoveShapeOperation(this, myShape, true, true);
default:
// calculate move shape operation maintain shape closed
return calculateMoveShapeOperation(myShape, myNet->getViewNet()->getPositionInformation(), radius, true, false);
return calculateMoveShapeOperation(this, myShape, true, false);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/netedit/elements/additional/GNETAZ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ GNETAZ::getMoveOperation() {
return new GNEMoveOperation(this, myShape);
} else {
// calculate move shape operation
return calculateMoveShapeOperation(myShape, myNet->getViewNet()->getPositionInformation(), snap_radius, true, true);
return calculateMoveShapeOperation(this, myShape, true, true);
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/netedit/elements/network/GNEConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,7 @@ GNEConnection::getMoveOperation() {
// get connection
const auto& connection = getNBEdgeConnection();
// calculate move shape operation
return calculateMoveShapeOperation(connection.customShape.size() > 0 ? connection.customShape : myConnectionGeometry.getShape(),
myNet->getViewNet()->getPositionInformation(),
myNet->getViewNet()->getVisualisationSettings().neteditSizeSettings.connectionGeometryPointRadius,
return calculateMoveShapeOperation(this, connection.customShape.size() > 0 ? connection.customShape : myConnectionGeometry.getShape(),
true, false);
} else {
return nullptr;
Expand Down
4 changes: 1 addition & 3 deletions src/netedit/elements/network/GNECrossing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ GNECrossing::getMoveOperation() {
// edit depending if shape is being edited
if (isShapeEdited()) {
// calculate move shape operation
return calculateMoveShapeOperation(getCrossingShape(), myNet->getViewNet()->getPositionInformation(),
myNet->getViewNet()->getVisualisationSettings().neteditSizeSettings.crossingGeometryPointRadius,
true, false);
return calculateMoveShapeOperation(this, getCrossingShape(), true, false);
} else {
return nullptr;
}
Expand Down
4 changes: 2 additions & 2 deletions src/netedit/elements/network/GNEEdge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,11 @@ GNEEdge::getMoveOperation() {
}
} else {
// calculate move shape operation (because there are only an edge selected)
return calculateMoveShapeOperation(myNBEdge->getGeometry(), myNet->getViewNet()->getPositionInformation(), circleWidth, false, false);
return calculateMoveShapeOperation(this, myNBEdge->getGeometry(), false, false);
}
} else {
// calculate move shape operation
return calculateMoveShapeOperation(myNBEdge->getGeometry(), myNet->getViewNet()->getPositionInformation(), circleWidth, false, false);
return calculateMoveShapeOperation(this, myNBEdge->getGeometry(), false, false);
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/netedit/elements/network/GNEJunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,7 @@ GNEJunction::getMoveOperation() {
// edit depending if shape is being edited
if (isShapeEdited()) {
// calculate move shape operation
return calculateMoveShapeOperation(myNBNode->getShape(), myNet->getViewNet()->getPositionInformation(),
myNet->getViewNet()->getVisualisationSettings().neteditSizeSettings.junctionGeometryPointRadius,
true, false);
return calculateMoveShapeOperation(this, myNBNode->getShape(), true, false);
} else {
// return move junction position
return new GNEMoveOperation(this, myNBNode->getPosition());
Expand Down
4 changes: 1 addition & 3 deletions src/netedit/elements/network/GNELane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,7 @@ GNELane::getMoveOperation() {
// edit depending if shape is being edited
if (isShapeEdited()) {
// calculate move shape operation
return calculateMoveShapeOperation(getLaneShape(), myNet->getViewNet()->getPositionInformation(),
myNet->getViewNet()->getVisualisationSettings().neteditSizeSettings.laneGeometryPointRadius,
true, false);
return calculateMoveShapeOperation(this, getLaneShape(), true, false);
} else {
return nullptr;
}
Expand Down
4 changes: 1 addition & 3 deletions src/netedit/elements/network/GNEWalkingArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ GNEWalkingArea::getMoveOperation() {
// edit depending if shape is being edited
if (isShapeEdited()) {
// calculate move shape operation
return calculateMoveShapeOperation(getNBWalkingArea().shape, myNet->getViewNet()->getPositionInformation(),
myNet->getViewNet()->getVisualisationSettings().neteditSizeSettings.crossingGeometryPointRadius,
true, false);
return calculateMoveShapeOperation(this, getNBWalkingArea().shape, true, false);
} else {
return nullptr;
}
Expand Down

0 comments on commit 5fc6407

Please sign in to comment.