Skip to content

Commit

Permalink
Fixed #15551
Browse files Browse the repository at this point in the history
  • Loading branch information
palvarezlopez committed Nov 15, 2024
1 parent 066811d commit fbecf9b
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 79 deletions.
73 changes: 8 additions & 65 deletions src/netedit/GNEMoveElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,16 @@ GNEMoveElement::moveElement(const GNEViewNet* viewNet, GNEMoveOperation* moveOpe
// calculate movement over lane
if (moveOperation->lastLane) {
// continue depending of operationType
if (moveOperation->operationType == GNEMoveOperation::OperationType::MULTIPLE_LANES_MOVE_FIRST) {
if ((moveOperation->operationType == GNEMoveOperation::OperationType::MULTIPLE_LANES_MOVE_FIRST) ||
(moveOperation->operationType == GNEMoveOperation::OperationType::MULTIPLE_LANES_MOVE_BOTH_FIRST)) {
// move only first position
calculateMoveResult(moveResult, viewNet, moveOperation->firstLane, moveOperation->firstPosition, offset,
0, moveOperation->firstLane->getLaneShapeLength());
} else if (moveOperation->operationType == GNEMoveOperation::OperationType::MULTIPLE_LANES_MOVE_LAST) {
} else if ((moveOperation->operationType == GNEMoveOperation::OperationType::MULTIPLE_LANES_MOVE_LAST) ||
(moveOperation->operationType == GNEMoveOperation::OperationType::MULTIPLE_LANES_MOVE_BOTH_LAST)) {
// move only last position
calculateMoveResult(moveResult, viewNet, moveOperation->lastLane, moveOperation->lastPosition, offset,
0, moveOperation->lastLane->getLaneShapeLength());
} else if (moveOperation->operationType == GNEMoveOperation::OperationType::MULTIPLE_LANES_MOVE_BOTH) {
// adjust positions
moveBothMultilanePositions(viewNet, moveOperation, moveResult, offset);
}
} else {
if (moveOperation->operationType == GNEMoveOperation::OperationType::SINGLE_LANE) {
Expand Down Expand Up @@ -321,17 +320,16 @@ GNEMoveElement::commitMove(const GNEViewNet* viewNet, GNEMoveOperation* moveOper
moveOperation->moveElement->setMoveShape(moveResult);
// calculate movement over lane
if (moveOperation->lastLane) {
if (moveOperation->operationType == GNEMoveOperation::OperationType::MULTIPLE_LANES_MOVE_FIRST) {
if ((moveOperation->operationType == GNEMoveOperation::OperationType::MULTIPLE_LANES_MOVE_FIRST) ||
(moveOperation->operationType == GNEMoveOperation::OperationType::MULTIPLE_LANES_MOVE_BOTH_FIRST)) {
// move only first position
calculateMoveResult(moveResult, viewNet, moveOperation->firstLane, moveOperation->firstPosition, offset,
0, moveOperation->firstLane->getLaneShapeLength());
} else if (moveOperation->operationType == GNEMoveOperation::OperationType::MULTIPLE_LANES_MOVE_LAST) {
} else if ((moveOperation->operationType == GNEMoveOperation::OperationType::MULTIPLE_LANES_MOVE_LAST) ||
(moveOperation->operationType == GNEMoveOperation::OperationType::MULTIPLE_LANES_MOVE_BOTH_LAST)) {
// move only two position
calculateMoveResult(moveResult, viewNet, moveOperation->lastLane, moveOperation->lastPosition, offset,
0, moveOperation->lastLane->getLaneShapeLength());
} else {
// adjust positions
moveBothMultilanePositions(viewNet, moveOperation, moveResult, offset);
}
// calculate new lane
if (moveOperation->allowChangeLane) {
Expand Down Expand Up @@ -525,61 +523,6 @@ GNEMoveElement::calculateNewLaneChange(const GNEViewNet* viewNet, const GNELane*
}


void
GNEMoveElement::moveBothMultilanePositions(const GNEViewNet* viewNet, const GNEMoveOperation* moveOperation, GNEMoveResult& moveResult, const GNEMoveOffset& offset) {
// get lane shape lengths
const double firstLaneLength = moveOperation->firstLane->getLaneShapeLength();
const double lastLaneLength = moveOperation->lastLane->getLaneShapeLength();


// get lane offset
const double laneOffsetA = calculateLaneOffset(viewNet, moveOperation->firstLane, moveOperation->firstPosition, moveOperation->firstPosition, offset, 0, firstLaneLength);

const double laneOffsetB = calculateLaneOffset(viewNet, moveOperation->lastLane, moveOperation->lastPosition, moveOperation->lastPosition, offset, 0, lastLaneLength);

WRITE_WARNING(toString(laneOffsetA) + " - " + toString(laneOffsetB));
// update moveResult
//moveResult.newFirstPos = (pos - laneOffset) / lane->getLengthGeometryFactor();
//moveResult.newLastPos = 0;


/*
if (moveOperation->operationType == GNEMoveOperation::OperationType::MULTIPLE_LANES_MOVEBOTH_FIRST) {
// move only first position
calculateMoveResult(moveResult, viewNet, moveOperation->firstLane, moveOperation->firstPosition, offset, 0, firstLaneLength);
// calculate last position
moveResult.newLastPos = (moveOperation->lastPosition - (moveOperation->firstPosition - moveResult.newFirstPos));
// adjust positions
if (moveResult.newLastPos < 0) {
moveResult.newFirstPos = (moveOperation->firstPosition - moveOperation->lastPosition);
moveResult.newLastPos = 0;
} else if (moveResult.newLastPos > lastLaneLength) {
moveResult.newFirstPos = (moveOperation->firstPosition + (lastLaneLength - moveOperation->lastPosition));
moveResult.newLastPos = lastLaneLength;
}
} else if (moveOperation->operationType == GNEMoveOperation::OperationType::MULTIPLE_LANES_MOVEBOTH_SECOND) {
// move only last position
calculateMoveResult(moveResult, viewNet, moveOperation->lastLane, moveOperation->lastPosition, offset, 0, lastLaneLength);
// swap (because move results is always stored in newFirstPos)
moveResult.newLastPos = moveResult.newFirstPos;
moveResult.newFirstPos = 0;
// calculate first position
moveResult.newFirstPos = (moveOperation->firstPosition - (moveOperation->lastPosition - moveResult.newLastPos));
// adjust positions
if (moveResult.newFirstPos < 0) {
moveResult.newLastPos = (moveOperation->lastPosition - moveOperation->firstPosition);
moveResult.newFirstPos = 0;
} else if (moveResult.newFirstPos > firstLaneLength) {
moveResult.newLastPos = (moveOperation->lastPosition + (firstLaneLength - moveOperation->firstPosition));
moveResult.newFirstPos = firstLaneLength;
}
} else {
throw ProcessError("Invalid move operationType");
}
*/
}


PositionVector
GNEMoveElement::calculateExtrapolatedVector(const GNEMoveOperation* moveOperation, const GNEMoveResult& moveResult) {
// get original shape half length
Expand Down
6 changes: 2 additions & 4 deletions src/netedit/GNEMoveElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class GNEMoveOperation {
SINGLE_LANE_MOVE_BOTH,
MULTIPLE_LANES_MOVE_FIRST,
MULTIPLE_LANES_MOVE_LAST,
MULTIPLE_LANES_MOVE_BOTH,
MULTIPLE_LANES_MOVE_BOTH_FIRST,
MULTIPLE_LANES_MOVE_BOTH_LAST
};

/// @brief constructor for values with a single position (junctions, E3, ParkingSpaces...)
Expand Down Expand Up @@ -278,9 +279,6 @@ class GNEMoveElement {
/// @brief calculate new lane change
static void calculateNewLaneChange(const GNEViewNet* viewNet, const GNELane* originalLane, const GNELane*& newLane, double& laneOffset);

// @brief move both multilane positions (used moving E2 multilane detectors)
static void moveBothMultilanePositions(const GNEViewNet* viewNet, const GNEMoveOperation* moveOperation, GNEMoveResult& moveResult, const GNEMoveOffset& offset);

/// @brief calculate width/height shape
static PositionVector calculateExtrapolatedVector(const GNEMoveOperation* moveOperation, const GNEMoveResult& moveResult);

Expand Down
12 changes: 9 additions & 3 deletions src/netedit/elements/additional/GNEAdditional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
///
// A abstract class for representation of additional elements
/****************************************************************************/
#include <config.h>

#include <foreign/fontstash/fontstash.h>
#include <netedit/GNENet.h>
#include <netedit/GNESegment.h>
#include <netedit/GNEViewNet.h>
#include <netedit/GNEViewParent.h>
#include <netedit/elements/demand/GNEPlanParents.h>
Expand Down Expand Up @@ -940,8 +941,13 @@ GNEAdditional::getMoveOperationMultiLane(const double startPos, const double end
} else {
auto segment = gViewObjectsHandler.getSelectedSegment(this);
if (segment) {
return new GNEMoveOperation(this, getParentLanes().front(), startPos, getParentLanes().back(), endPos,
false, GNEMoveOperation::OperationType::MULTIPLE_LANES_MOVE_BOTH);
if (segment->getLaneIndex() == 0) {
return new GNEMoveOperation(this, getParentLanes().front(), startPos, getParentLanes().back(), endPos,
false, GNEMoveOperation::OperationType::MULTIPLE_LANES_MOVE_BOTH_FIRST);
} else if (segment->getLaneIndex() == ((int)getParentLanes().size() - 1)) {
return new GNEMoveOperation(this, getParentLanes().front(), startPos, getParentLanes().back(), endPos,
false, GNEMoveOperation::OperationType::MULTIPLE_LANES_MOVE_BOTH_LAST);
}
}
}
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/netedit/elements/additional/GNEDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ GNEDetector::checkDrawMoveContour() const {
return true;
}
} else {
// this is the start and end points
// this is the start or end point
return true;
}
} else {
Expand Down
58 changes: 52 additions & 6 deletions src/netedit/elements/additional/GNELaneAreaDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,9 +684,29 @@ GNELaneAreaDetector::setMoveShape(const GNEMoveResult& moveResult) {
// change only end position
myEndPositionOverLane = moveResult.newFirstPos;
} else {
// change both position
myPositionOverLane = moveResult.newFirstPos;
myEndPositionOverLane = moveResult.newLastPos;
if (moveResult.operationType == GNEMoveOperation::OperationType::MULTIPLE_LANES_MOVE_BOTH_FIRST) {
const auto difference = moveResult.newFirstPos - myPositionOverLane;
// change start position
myPositionOverLane = moveResult.newFirstPos;
myEndPositionOverLane += difference;
} else if (moveResult.operationType == GNEMoveOperation::OperationType::MULTIPLE_LANES_MOVE_BOTH_LAST) {
const auto difference = moveResult.newFirstPos - myEndPositionOverLane;
// change end position
myPositionOverLane += difference;
myEndPositionOverLane = moveResult.newFirstPos;
}
// end position over lane
if (myPositionOverLane < 0) {
myPositionOverLane = 0;
} else if (myPositionOverLane > getParentLanes().front()->getLaneShapeLength()) {
myPositionOverLane = getParentLanes().front()->getLaneShapeLength();
}
// adjust position over lane
if (myEndPositionOverLane < 0) {
myEndPositionOverLane = 0;
} else if (myEndPositionOverLane > getParentLanes().back()->getLaneShapeLength()) {
myEndPositionOverLane = getParentLanes().back()->getLaneShapeLength();
}
}
// update geometry
updateGeometry();
Expand All @@ -707,9 +727,35 @@ GNELaneAreaDetector::commitMoveShape(const GNEMoveResult& moveResult, GNEUndoLis
// set only end position
setAttribute(SUMO_ATTR_ENDPOS, toString(moveResult.newFirstPos), undoList);
} else {
// set both positions
setAttribute(SUMO_ATTR_POSITION, toString(moveResult.newFirstPos), undoList);
setAttribute(SUMO_ATTR_ENDPOS, toString(moveResult.newLastPos), undoList);
double startPos = myPositionOverLane;
double endPos = myEndPositionOverLane;
// set positions
if (moveResult.operationType == GNEMoveOperation::OperationType::MULTIPLE_LANES_MOVE_BOTH_FIRST) {
const auto difference = moveResult.newFirstPos - myPositionOverLane;
// change start position
startPos = moveResult.newFirstPos;
endPos += difference;
} else if (moveResult.operationType == GNEMoveOperation::OperationType::MULTIPLE_LANES_MOVE_BOTH_LAST) {
const auto difference = moveResult.newFirstPos - myEndPositionOverLane;
// change end position
startPos += difference;
endPos = moveResult.newFirstPos;
}
// end position over lane
if (startPos < 0) {
startPos = 0;
} else if (startPos > getParentLanes().front()->getLaneShapeLength()) {
startPos = getParentLanes().front()->getLaneShapeLength();
}
// adjust position over lane
if (endPos < 0) {
endPos = 0;
} else if (endPos > getParentLanes().back()->getLaneShapeLength()) {
endPos = getParentLanes().back()->getLaneShapeLength();
}
// set only end position
setAttribute(SUMO_ATTR_POSITION, toString(startPos), undoList);
setAttribute(SUMO_ATTR_ENDPOS, toString(endPos), undoList);
}
// end change attribute
undoList->end();
Expand Down

0 comments on commit fbecf9b

Please sign in to comment.