33 moveElement(_moveElement),
34 originalShape({_originalPosition}),
35 shapeToMove({_originalPosition}),
36 allowChangeLane(
false),
37 firstGeometryPoint(
false),
38 operationType(OperationType::POSITION) {
44 moveElement(_moveElement),
45 originalShape(_originalShape),
46 shapeToMove(_originalShape),
47 allowChangeLane(false),
48 firstGeometryPoint(false),
54 const bool _firstGeometryPoint,
56 moveElement(_moveElement),
57 originalShape(_originalShape),
58 shapeToMove(_originalShape),
59 allowChangeLane(false),
60 firstGeometryPoint(_firstGeometryPoint),
61 operationType(_operationType) {
66 const std::vector<int> _originalgeometryPoints,
68 const std::vector<int> _geometryPointsToMove) :
69 moveElement(_moveElement),
70 originalShape(_originalShape),
71 originalGeometryPoints(_originalgeometryPoints),
72 shapeToMove(_shapeToMove),
73 geometryPointsToMove(_geometryPointsToMove),
74 allowChangeLane(false),
75 firstGeometryPoint(false),
82 const double _firstPosition,
83 const bool _allowChangeLane) :
84 moveElement(_moveElement),
86 firstPosition(_firstPosition * _lane->getLengthGeometryFactor()),
87 allowChangeLane(_allowChangeLane),
88 firstGeometryPoint(false),
95 const double _firstPosition,
96 const double _secondPosition,
97 const bool _allowChangeLane,
99 moveElement(_moveElement),
101 firstPosition(_firstPosition * _lane->getLengthGeometryFactor()),
102 secondPosition(_secondPosition * _lane->getLengthGeometryFactor()),
103 allowChangeLane(_allowChangeLane),
104 firstGeometryPoint(false),
105 operationType(_operationType) {
111 const double _firstStartPos,
113 const double _secondStartPos,
114 const bool _allowChangeLane,
116 moveElement(_moveElement),
117 firstLane(_firstLane),
119 secondLane(_secondLane),
121 allowChangeLane(_allowChangeLane),
122 firstGeometryPoint(false),
123 operationType(_operationType) {
161 operationType(moveOperation->operationType),
163 newFirstLane(nullptr),
166 newSecondLane(nullptr),
186 myMoveElementLateralOffset(0) {
193 const double squaredSnapRadius = (snapRadius * snapRadius);
197 const int nearestIndex = originalShape.
indexOfClosest(mousePosition);
201 if (nearestIndex == -1) {
207 return new GNEMoveOperation(
this, originalShape, {nearestIndex}, shapeToMove, {nearestIndex});
211 }
else if (mousePosition.
distanceSquaredTo2D(shapeToMove[nearestIndex]) <= squaredSnapRadius) {
213 return new GNEMoveOperation(
this, originalShape, {nearestIndex}, shapeToMove, {nearestIndex});
214 }
else if (!onlyContour || nearestPosition.
distanceSquaredTo2D(mousePosition) <= squaredSnapRadius) {
216 const int newIndex = shapeToMove.
insertAtClosest(nearestPosition,
true);
218 return new GNEMoveOperation(
this, originalShape, {nearestIndex}, shapeToMove, {newIndex});
291 throw ProcessError(
"trying to move an invalid position");
301 geometryPointIndex.
add(offset.
x, offset.
y, offset.
z);
305 throw ProcessError(
"trying to move an invalid position");
415 throw ProcessError(
"trying to move an invalid position");
427 geometryPointIndex.add(offset.
x, offset.
y, offset.
z);
431 throw ProcessError(
"trying to move an invalid position");
450 const GNEMoveOffset& offset,
const double extremFrom,
const double extremTo) {
452 double laneOffset = 0;
454 const double offsetCentralPosition = (firstPosition + secondPosition) * 0.5;
456 const double middleLenght = std::abs(secondPosition - firstPosition) * 0.5;
460 laneCentralPosition.
add(offset.
x, offset.
y, offset.
z);
466 if (offsetLaneCentralPositionPerpendicular == -1) {
470 if (offsetLaneCentralPosition == 0) {
471 laneOffset = firstPosition;
477 if ((offsetLaneCentralPositionPerpendicular - middleLenght) < extremFrom) {
478 laneOffset = firstPosition + extremFrom;
479 }
else if ((offsetLaneCentralPositionPerpendicular + middleLenght) > extremTo) {
480 laneOffset = secondPosition - extremTo;
482 laneOffset = (offsetCentralPosition - offsetLaneCentralPositionPerpendicular);
491 const double pos,
const GNEMoveOffset& offset,
const double extremFrom,
const double extremTo) {
493 const double laneOffset =
calculateLaneOffset(viewNet, lane, pos, pos, offset, extremFrom, extremTo);
502 const double firstPos,
const double secondPos,
const GNEMoveOffset& offset) {
513 const double firstPos,
const GNELane* secondLane,
const double secondPos,
const GNEMoveOffset& offset) {
529 if (lane != originalLane) {
531 const double offSet = lane->getLaneShape().nearest_offset_to_point2D(cursorPosition,
true);
533 const Position posOverLane = lane->getLaneShape().positionAtOffset2D(offSet);
543 laneOffset = posOverLane.
distanceTo2D(posOverMoveOperationLane);
566 double extrapolateValue = (10e5 - offset);
569 if (extrapolateValue < halfLenght) {
570 extrapolateValue = (halfLenght - POSITION_EPS);
573 if (extrapolateValue > halfLenght) {
574 extrapolateValue = (halfLenght - POSITION_EPS);
583 return extrapolatedShape;
585 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 arent edge
static PositionVector calculateExtrapolatedVector(const GNEMoveOperation *moveOperation, const GNEMoveResult &moveResult)
calculate width/height shape
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
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.
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.