32 moveElement(_moveElement),
33 originalShape({_originalPosition}),
34 shapeToMove({_originalPosition}),
35 allowChangeLane(
false),
36 firstGeometryPoint(
false),
37operationType(OperationType::POSITION) {
43 moveElement(_moveElement),
44 originalShape(_originalShape),
45 shapeToMove(_originalShape),
46 allowChangeLane(false),
47 firstGeometryPoint(false),
53 const bool _firstGeometryPoint,
55 moveElement(_moveElement),
56 originalShape(_originalShape),
57 shapeToMove(_originalShape),
58 allowChangeLane(false),
59 firstGeometryPoint(_firstGeometryPoint),
60 operationType(_operationType) {
65 const std::vector<int> _originalgeometryPoints,
67 const std::vector<int> _geometryPointsToMove) :
68 moveElement(_moveElement),
69 originalShape(_originalShape),
70 originalGeometryPoints(_originalgeometryPoints),
71 shapeToMove(_shapeToMove),
72 geometryPointsToMove(_geometryPointsToMove),
73 allowChangeLane(false),
74 firstGeometryPoint(false),
81 const double _firstPosition,
82 const bool _allowChangeLane) :
83 moveElement(_moveElement),
85 firstPosition(_firstPosition * _lane->getLengthGeometryFactor()),
86 allowChangeLane(_allowChangeLane),
87 firstGeometryPoint(false),
94 const double _firstPosition,
95 const double _secondPosition,
96 const bool _allowChangeLane,
98 moveElement(_moveElement),
100 firstPosition(_firstPosition * _lane->getLengthGeometryFactor()),
101 secondPosition(_secondPosition * _lane->getLengthGeometryFactor()),
102 allowChangeLane(_allowChangeLane),
103 firstGeometryPoint(false),
104 operationType(_operationType) {
110 const double _firstStartPos,
112 const double _secondStartPos,
113 const bool _allowChangeLane,
115 moveElement(_moveElement),
116 firstLane(_firstLane),
118 secondLane(_secondLane),
120 allowChangeLane(_allowChangeLane),
121 firstGeometryPoint(false),
122 operationType(_operationType) {
160 operationType(moveOperation->operationType),
162 newFirstLane(nullptr),
165 newSecondLane(nullptr),
185 myMoveElementLateralOffset(0) {
192 const double squaredSnapRadius = (snapRadius * snapRadius);
196 const int nearestIndex = originalShape.
indexOfClosest(mousePosition);
200 if (nearestIndex == -1) {
206 return new GNEMoveOperation(
this, originalShape, {nearestIndex}, shapeToMove, {nearestIndex});
210 }
else if (mousePosition.
distanceSquaredTo2D(shapeToMove[nearestIndex]) <= squaredSnapRadius) {
212 return new GNEMoveOperation(
this, originalShape, {nearestIndex}, shapeToMove, {nearestIndex});
213 }
else if (!onlyContour || nearestPosition.
distanceSquaredTo2D(mousePosition) <= squaredSnapRadius) {
215 const int newIndex = shapeToMove.
insertAtClosest(nearestPosition,
true);
217 return new GNEMoveOperation(
this, originalShape, {nearestIndex}, shapeToMove, {newIndex});
283 throw ProcessError(
"trying to move an invalid position");
293 geometryPointIndex.
add(offset.
x, offset.
y, offset.
z);
297 throw ProcessError(
"trying to move an invalid position");
406 throw ProcessError(
"trying to move an invalid position");
418 geometryPointIndex.add(offset.
x, offset.
y, offset.
z);
422 throw ProcessError(
"trying to move an invalid position");
441 const GNEMoveOffset& offset,
const double extremFrom,
const double extremTo) {
443 double laneOffset = 0;
445 const double offsetCentralPosition = (firstPosition + secondPosition) * 0.5;
447 const double middleLength = std::abs(secondPosition - firstPosition) * 0.5;
451 laneCentralPosition.
add(offset.
x, offset.
y, offset.
z);
457 if (offsetLaneCentralPositionPerpendicular == -1) {
461 if (offsetLaneCentralPosition == 0) {
462 laneOffset = firstPosition;
468 if ((offsetLaneCentralPositionPerpendicular - middleLength) < extremFrom) {
469 laneOffset = firstPosition + extremFrom;
470 }
else if ((offsetLaneCentralPositionPerpendicular + middleLength) > extremTo) {
471 laneOffset = secondPosition - extremTo;
473 laneOffset = (offsetCentralPosition - offsetLaneCentralPositionPerpendicular);
482 const double pos,
const GNEMoveOffset& offset,
const double extremFrom,
const double extremTo) {
484 const double laneOffset =
calculateLaneOffset(viewNet, lane, pos, pos, offset, extremFrom, extremTo);
493 const double firstPos,
const double secondPos,
const GNEMoveOffset& offset) {
504 const double firstPos,
const GNELane* secondLane,
const double secondPos,
const GNEMoveOffset& offset) {
520 if (lane != originalLane) {
522 const double offSet = lane->getLaneShape().nearest_offset_to_point2D(cursorPosition,
true);
524 const Position posOverLane = lane->getLaneShape().positionAtOffset2D(offSet);
534 laneOffset = posOverLane.
distanceTo2D(posOverMoveOperationLane);
559 }
else if (moveResult.
newSecondPos > secondLaneLength) {
575 }
else if (moveResult.
newFirstPos > firstLaneLength) {
597 double extrapolateValue = (10e5 - offset);
600 if (extrapolateValue < halfLength) {
601 extrapolateValue = (halfLength - POSITION_EPS);
604 if (extrapolateValue > halfLength) {
605 extrapolateValue = (halfLength - POSITION_EPS);
614 return extrapolatedShape;
616 return extrapolatedShape.
reverse();
const double INVALID_DOUBLE
const std::vector< GNELane * > & getLanes() const
returns a reference to the lane vector
This lane is powered by an underlying GNEEdge and basically knows how to draw itself.
const PositionVector & getLaneShape() const
get elements shape
double getLengthGeometryFactor() const
get length geometry factor
int getIndex() const
returns the index of the lane
double getLaneShapeLength() const
returns the length of the lane's shape
GNEEdge * getParentEdge() const
get parent edge
static PositionVector calculateExtrapolatedVector(const GNEMoveOperation *moveOperation, const GNEMoveResult &moveResult)
calculate width/height shape
static void adjustBothPositions(const GNEViewNet *viewNet, const GNEMoveOperation *moveOperation, GNEMoveResult &moveResult, const GNEMoveOffset &offset)
virtual void setMoveShape(const GNEMoveResult &moveResult)=0
set move shape
GNEMoveElement()
constructor
GNEMoveOperation * calculateMoveShapeOperation(const PositionVector originalShape, const Position mousePosition, const double snapRadius, const bool onlyContour)
calculate move shape operation
static void calculateMoveResult(GNEMoveResult &moveResult, const GNEViewNet *viewNet, const GNELane *lane, const double pos, const GNEMoveOffset &offset, const double extremFrom, const double extremTo)
calculate single movement over one lane
static void commitMove(const GNEViewNet *viewNet, GNEMoveOperation *moveOperation, const GNEMoveOffset &offset, GNEUndoList *undoList)
commit move element for the given offset
static double calculateLaneOffset(const GNEViewNet *viewNet, const GNELane *lane, const double firstPosition, const double secondPosition, const GNEMoveOffset &offset, const double extremFrom, const double extremTo)
calculate lane offset
virtual void commitMoveShape(const GNEMoveResult &moveResult, GNEUndoList *undoList)=0
commit move shape
static void calculateNewLane(const GNEViewNet *viewNet, const GNELane *originalLane, const GNELane *&newLane, double &laneOffset)
calculate new lane
static void moveElement(const GNEViewNet *viewNet, GNEMoveOperation *moveOperation, const GNEMoveOffset &offset)
move element the for given offset (note: offset can be X-Y-0, 0-0-Z or X-Y-Z)
GNEMoveOffset()
constructor
~GNEMoveOffset()
destructor
const OperationType operationType
operation type
const PositionVector originalShape
original shape
const std::vector< int > originalGeometryPoints
original shape points to move (of original shape)
const PositionVector shapeToMove
shape to move
GNEMoveOperation(GNEMoveElement *moveElement, const Position originalPosition)
constructor for values with a single position (junctions, E3, ParkingSpaces...)
~GNEMoveOperation()
destructor
const double secondPosition
original second Position
const GNELane * firstLane
original first lane
const GNELane * secondLane
original second lane
const std::vector< int > geometryPointsToMove
shape points to move (of shapeToMove)
const double firstPosition
original first Position
const bool allowChangeLane
allow change lane
@ TWO_LANES_MOVEBOTH_SECOND
@ TWO_LANES_MOVEBOTH_FIRST
GNEMoveElement * moveElement
move element
const bool firstGeometryPoint
first position (used for edit with/height
const GNELane * newFirstLane
new first Lane
double newFirstPos
new first position
GNEMoveResult(const GNEMoveOperation *moveOperation)
constructor
~GNEMoveResult()
destructor
const GNELane * newSecondLane
new second Lane
void clearLanes()
clear lanes
double firstLaneOffset
lane offset
std::vector< int > geometryPointsToMove
shape points to move (of shapeToMove)
double newSecondPos
new second position
PositionVector shapeToUpdate
shape to update (edited in moveElement)
double secondLaneOffset
lane offset
Position snapToActiveGrid(const Position &pos, bool snapXY=true) const
Returns a position that is mapped to the closest grid point if the grid is active.
virtual Position getPositionInformation() const
Returns the cursor's x/y position within the network.
A point in 2D or 3D with translation and scaling methods.
double distanceSquaredTo2D(const Position &p2) const
returns the square of the distance to another position (Only using x and y positions)
static const Position INVALID
used to indicate that a position is valid
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
void add(const Position &pos)
Adds the given position to this one.
double length2D() const
Returns the length.
void add(double xoff, double yoff, double zoff)
double nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
return the nearest offest to point 2D
int indexOfClosest(const Position &p, bool twoD=false) const
void extrapolate2D(const double val, const bool onlyFirst=false)
extrapolate position vector in two dimensions (Z is ignored)
int insertAtClosest(const Position &p, bool interpolateZ)
inserts p between the two closest positions
void removeDoublePoints(double minDist=POSITION_EPS, bool assertLength=false, int beginOffset=0, int endOffset=0, bool resample=false)
Removes positions if too near.
PositionVector reverse() const
reverse position vector
Position positionAtOffset2D(double pos, double lateralOffset=0) const
Returns the position at the given length.