Skip to content

Commit

Permalink
Updated geometry point moving. Refs #13894
Browse files Browse the repository at this point in the history
  • Loading branch information
palvarezlopez committed Dec 19, 2023
1 parent 1571c0e commit 4ea8f7d
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/netedit/GNEViewNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5638,7 +5638,7 @@ GNEViewNet::processLeftButtonPressNetwork(void* eventData) {
// get AC under cursor
auto AC = myObjectsUnderCursor.getAttributeCarrierFront();
// check that AC is an network or additional element
if (AC && (AC->getTagProperty().isNetworkElement() || !AC->getTagProperty().isAdditionalElement())) {
if (AC && (AC->getTagProperty().isNetworkElement() || AC->getTagProperty().isAdditionalElement())) {
// check if we're moving a set of selected items
if (AC->isAttributeCarrierSelected()) {
// move selected ACs
Expand Down
13 changes: 11 additions & 2 deletions src/netedit/GNEViewNetHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,8 +1225,7 @@ GNEViewNetHelper::MoveSingleElementValues::beginMoveSingleElementNetworkMode() {
return false;
}
}
} else if ((myViewNet->myObjectsUnderCursor.getEdgeFront() && (frontAC == myViewNet->myObjectsUnderCursor.getEdgeFront())) ||
(myViewNet->myObjectsUnderCursor.getLaneFront() && (frontAC == myViewNet->myObjectsUnderCursor.getLaneFront()))) {
} else if (myViewNet->myObjectsUnderCursor.getEdgeFront() && (frontAC == myViewNet->myObjectsUnderCursor.getEdgeFront())) {
// calculate Edge movement values (can be entire shape, single geometry points, altitude, etc.)
if (myViewNet->myMouseButtonKeyPressed.shiftKeyPressed()) {
// edit end point
Expand All @@ -1244,6 +1243,16 @@ GNEViewNetHelper::MoveSingleElementValues::beginMoveSingleElementNetworkMode() {
return false;
}
}
} else if (myViewNet->myObjectsUnderCursor.getLaneFront() && (frontAC == myViewNet->myObjectsUnderCursor.getLaneFront())) {
// get move operation
GNEMoveOperation* moveOperation = myViewNet->myObjectsUnderCursor.getLaneFront()->getMoveOperation();
// continue if move operation is valid
if (moveOperation) {
myMoveOperations.push_back(moveOperation);
return true;
} else {
return false;
}
} else {
// there isn't moved items, then return false
return false;
Expand Down
4 changes: 0 additions & 4 deletions src/netedit/elements/additional/GNEBusStop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,6 @@ GNEBusStop::drawGL(const GUIVisualizationSettings& s) const {
myContour.drawDottedContourExtruded(s, d, myAdditionalGeometry.getShape(), stopWidth, 1, true, true, 0,
s.dottedContourSettings.segmentWidth);
}
// check start and end geometry points
if (movingGeometryPoints && (myStartPosition != INVALID_DOUBLE)) {

}
}
}

Expand Down
23 changes: 19 additions & 4 deletions src/netedit/elements/additional/GNEChargingStation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ GNEChargingStation::drawGL(const GUIVisualizationSettings& s) const {
const double chargingStationExaggeration = getExaggeration(s);
// first check if additional has to be drawn
if (myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
// check if draw moving geometry points
const int movingGeometryPoints = drawMovingGeometryPoints(false);
// get detail level
const auto d = s.getDetailLevel(chargingStationExaggeration);
// draw geometry only if we'rent in drawForObjectUnderCursor mode
Expand Down Expand Up @@ -160,10 +162,10 @@ GNEChargingStation::drawGL(const GUIVisualizationSettings& s) const {
// draw sign
drawSign(d, chargingStationExaggeration, baseColor, signColor, "C");
// draw geometry points
if (myStartPosition != INVALID_DOUBLE) {
if (movingGeometryPoints && (myStartPosition != INVALID_DOUBLE)) {
drawLeftGeometryPoint(s, d, myAdditionalGeometry.getShape().front(), myAdditionalGeometry.getShapeRotations().front(), baseColor);
}
if (myEndPosition != INVALID_DOUBLE) {
if (movingGeometryPoints && (myEndPosition != INVALID_DOUBLE)) {
drawRightGeometryPoint(s, d, myAdditionalGeometry.getShape().back(), myAdditionalGeometry.getShapeRotations().back(), baseColor);
}
// pop layer matrix
Expand All @@ -178,8 +180,21 @@ GNEChargingStation::drawGL(const GUIVisualizationSettings& s) const {
// draw stoppingPlace children
drawStoppingPlaceChildren(s);
// draw dotted geometry (don't exaggerate contour)
myContour.drawDottedContourExtruded(s, d, myAdditionalGeometry.getShape(), s.stoppingPlaceSettings.chargingStationWidth, 1, true, true, 0,
s.dottedContourSettings.segmentWidth);
if (movingGeometryPoints) {
if (myStartPosition != INVALID_DOUBLE) {
myContour.drawDottedContourGeometryPoints(s, d, myAdditionalGeometry.getShape(), GNEContour::GeometryPoint::FROM,
s.neteditSizeSettings.additionalGeometryPointRadius, 1,
s.dottedContourSettings.segmentWidth);
}
if (movingGeometryPoints && (myEndPosition != INVALID_DOUBLE)) {
myContour.drawDottedContourGeometryPoints(s, d, myAdditionalGeometry.getShape(), GNEContour::GeometryPoint::TO,
s.neteditSizeSettings.additionalGeometryPointRadius, 1,
s.dottedContourSettings.segmentWidth);
}
} else {
myContour.drawDottedContourExtruded(s, d, myAdditionalGeometry.getShape(), s.stoppingPlaceSettings.chargingStationWidth, 1, true, true, 0,
s.dottedContourSettings.segmentWidth);
}
}
}

Expand Down
23 changes: 19 additions & 4 deletions src/netedit/elements/additional/GNEContainerStop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ GNEContainerStop::drawGL(const GUIVisualizationSettings& s) const {
const double containerStopExaggeration = getExaggeration(s);
// first check if additional has to be drawn
if (myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
// check if draw moving geometry points
const int movingGeometryPoints = drawMovingGeometryPoints(false);
// get detail level
const auto d = s.getDetailLevel(containerStopExaggeration);
// draw geometry only if we'rent in drawForObjectUnderCursor mode
Expand Down Expand Up @@ -157,10 +159,10 @@ GNEContainerStop::drawGL(const GUIVisualizationSettings& s) const {
// draw sign
drawSign(d, containerStopExaggeration, baseColor, signColor, "C");
// draw geometry points
if (myStartPosition != INVALID_DOUBLE) {
if (movingGeometryPoints && (myStartPosition != INVALID_DOUBLE)) {
drawLeftGeometryPoint(s, d, myAdditionalGeometry.getShape().front(), myAdditionalGeometry.getShapeRotations().front(), baseColor);
}
if (myEndPosition != INVALID_DOUBLE) {
if (movingGeometryPoints && (myEndPosition != INVALID_DOUBLE)) {
drawRightGeometryPoint(s, d, myAdditionalGeometry.getShape().back(), myAdditionalGeometry.getShapeRotations().back(), baseColor);
}
// pop layer matrix
Expand All @@ -180,8 +182,21 @@ GNEContainerStop::drawGL(const GUIVisualizationSettings& s) const {
}
}
// draw dotted geometry (don't exaggerate contour)
myContour.drawDottedContourExtruded(s, d, myAdditionalGeometry.getShape(), s.stoppingPlaceSettings.containerStopWidth, 1, true, true, 0,
s.dottedContourSettings.segmentWidth);
if (movingGeometryPoints) {
if (myStartPosition != INVALID_DOUBLE) {
myContour.drawDottedContourGeometryPoints(s, d, myAdditionalGeometry.getShape(), GNEContour::GeometryPoint::FROM,
s.neteditSizeSettings.additionalGeometryPointRadius, 1,
s.dottedContourSettings.segmentWidth);
}
if (movingGeometryPoints && (myEndPosition != INVALID_DOUBLE)) {
myContour.drawDottedContourGeometryPoints(s, d, myAdditionalGeometry.getShape(), GNEContour::GeometryPoint::TO,
s.neteditSizeSettings.additionalGeometryPointRadius, 1,
s.dottedContourSettings.segmentWidth);
}
} else {
myContour.drawDottedContourExtruded(s, d, myAdditionalGeometry.getShape(), s.stoppingPlaceSettings.containerStopWidth, 1, true, true, 0,
s.dottedContourSettings.segmentWidth);
}
}
}

Expand Down
23 changes: 19 additions & 4 deletions src/netedit/elements/additional/GNEParkingArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ GNEParkingArea::drawGL(const GUIVisualizationSettings& s) const {
const double parkingAreaExaggeration = getExaggeration(s);
// first check if additional has to be drawn
if (myNet->getViewNet()->getDataViewOptions().showAdditionals()) {
// check if draw moving geometry points
const int movingGeometryPoints = drawMovingGeometryPoints(false);
// get detail level
const auto d = s.getDetailLevel(parkingAreaExaggeration);
// draw geometry only if we'rent in drawForObjectUnderCursor mode
Expand Down Expand Up @@ -193,10 +195,10 @@ GNEParkingArea::drawGL(const GUIVisualizationSettings& s) const {
}
}
// draw geometry points
if (myStartPosition != INVALID_DOUBLE) {
if (movingGeometryPoints && (myStartPosition != INVALID_DOUBLE)) {
drawLeftGeometryPoint(s, d, myAdditionalGeometry.getShape().front(), myAdditionalGeometry.getShapeRotations().front(), baseColor);
}
if (myEndPosition != INVALID_DOUBLE) {
if (movingGeometryPoints && (myEndPosition != INVALID_DOUBLE)) {
drawRightGeometryPoint(s, d, myAdditionalGeometry.getShape().back(), myAdditionalGeometry.getShapeRotations().back(), baseColor);
}
// pop layer matrix
Expand All @@ -211,8 +213,21 @@ GNEParkingArea::drawGL(const GUIVisualizationSettings& s) const {
// draw stoppingPlace children
drawStoppingPlaceChildren(s);
// draw dotted geometry (don't exaggerate contour)
myContour.drawDottedContourExtruded(s, d, myAdditionalGeometry.getShape(), myWidth * 0.5, 1, true, true, 0,
s.dottedContourSettings.segmentWidth);
if (movingGeometryPoints) {
if (myStartPosition != INVALID_DOUBLE) {
myContour.drawDottedContourGeometryPoints(s, d, myAdditionalGeometry.getShape(), GNEContour::GeometryPoint::FROM,
s.neteditSizeSettings.additionalGeometryPointRadius, 1,
s.dottedContourSettings.segmentWidth);
}
if (movingGeometryPoints && (myEndPosition != INVALID_DOUBLE)) {
myContour.drawDottedContourGeometryPoints(s, d, myAdditionalGeometry.getShape(), GNEContour::GeometryPoint::TO,
s.neteditSizeSettings.additionalGeometryPointRadius, 1,
s.dottedContourSettings.segmentWidth);
}
} else {
myContour.drawDottedContourExtruded(s, d, myAdditionalGeometry.getShape(), myWidth * 0.5, 1, true, true, 0,
s.dottedContourSettings.segmentWidth);
}
}
}

Expand Down
24 changes: 10 additions & 14 deletions src/netedit/elements/additional/GNEStoppingPlace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,20 @@ GNEStoppingPlace::getMoveOperation() {
// get allow change lane
const bool allowChangeLane = myNet->getViewNet()->getViewParent()->getMoveFrame()->getCommonModeOptions()->getAllowChangeLane();
// fist check if we're moving only extremes
if (myNet->getViewNet()->getEditModes().isCurrentSupermodeNetwork() &&
(myNet->getViewNet()->getEditModes().networkEditMode == NetworkEditMode::NETWORK_MOVE) &&
myNet->getViewNet()->getMouseButtonKeyPressed().shiftKeyPressed()) {
// get snap radius
const double snap_radius = myNet->getViewNet()->getVisualisationSettings().neteditSizeSettings.additionalGeometryPointRadius;
// get mouse position
const Position mousePosition = myNet->getViewNet()->getPositionInformation();
// check if we clicked over start or end position
if ((myStartPosition != INVALID_DOUBLE) && (myAdditionalGeometry.getShape().front().distanceSquaredTo2D(mousePosition) <= (snap_radius * snap_radius))) {
// move only start position
if (drawMovingGeometryPoints(false)) {
// get geometry points under cursor
const auto geometryPoints = gPostDrawing.getGeometryPoints(this);
// continue depending of moved element
if (geometryPoints.empty()) {
return nullptr;
} else if (geometryPoints.front() == 0) {
// move start position
return new GNEMoveOperation(this, getParentLanes().front(), myStartPosition, getParentLanes().front()->getLaneShape().length2D() - POSITION_EPS,
allowChangeLane, GNEMoveOperation::OperationType::ONE_LANE_MOVEFIRST);
} else if ((myEndPosition != INVALID_DOUBLE) && (myAdditionalGeometry.getShape().back().distanceSquaredTo2D(mousePosition) <= (snap_radius * snap_radius))) {
// move only end position
} else {
// move end position
return new GNEMoveOperation(this, getParentLanes().front(), 0, myEndPosition,
allowChangeLane, GNEMoveOperation::OperationType::ONE_LANE_MOVESECOND);
} else {
return nullptr;
}
} else if ((myStartPosition != INVALID_DOUBLE) && (myEndPosition != INVALID_DOUBLE)) {
// move both start and end positions
Expand Down
16 changes: 14 additions & 2 deletions src/utils/gui/settings/GUIPostDrawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,25 @@ GUIPostDrawing::getElementsUnderCursor() const {
}


const GUIPostDrawing::GeometryPointsContainer&
GUIPostDrawing::getGeometryPoints(const GUIGlObject* GLObject) const {
// avoid to insert duplicated elements
for (auto &element : myElementsUnderCursor) {
if (element.first == GLObject) {
return element.second;
}
}
return myEmptyGeometryPoints;
}


bool
GUIPostDrawing::addElementUnderCursor(const GUIGlObject* GLObject) {
// avoid to insert duplicated elements
if (isElementUnderCursor(GLObject)) {
return false;
} else {
myElementsUnderCursor.push_back(std::make_pair(GLObject, std::vector<int>()));
myElementsUnderCursor.push_back(std::make_pair(GLObject, GUIPostDrawing::GeometryPointsContainer()));
return true;
}
}
Expand All @@ -131,7 +143,7 @@ GUIPostDrawing::addGeometryPointUnderCursor(const GUIGlObject* GLObject, const i
}
}
// no element found then add it
myElementsUnderCursor.push_back(std::make_pair(GLObject, std::vector<int>()));
myElementsUnderCursor.push_back(std::make_pair(GLObject, GUIPostDrawing::GeometryPointsContainer()));
myElementsUnderCursor.back().second.push_back(newIndex);
return true;
}
Expand Down
9 changes: 8 additions & 1 deletion src/utils/gui/settings/GUIPostDrawing.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ class GUIPostDrawing {

public:
/// @brief typedefs
typedef std::vector<std::pair<const GUIGlObject*, std::vector<int> > > GLObjectsContainer;
typedef std::vector<int> GeometryPointsContainer;
typedef std::vector<std::pair<const GUIGlObject*, GeometryPointsContainer > > GLObjectsContainer;

/// @brief constructor
GUIPostDrawing();
Expand All @@ -66,6 +67,9 @@ class GUIPostDrawing {
/// @brief get all elements under cursor
const GLObjectsContainer& getElementsUnderCursor() const;

/// @brief get geometry points for the given glObject
const GeometryPointsContainer& getGeometryPoints(const GUIGlObject* GLObject) const;

/// @brief recompute boundaries
GUIGlObjectType recomputeBoundaries = GLO_NETWORK;

Expand All @@ -91,6 +95,9 @@ class GUIPostDrawing {
/// @brief elements under cursor and their geometry point indexes
GLObjectsContainer myElementsUnderCursor;

/// @brief empty geometry points
GeometryPointsContainer myEmptyGeometryPoints;

/// @brief add element into list of elements under cursor
bool addElementUnderCursor(const GUIGlObject* GLObject);

Expand Down

0 comments on commit 4ea8f7d

Please sign in to comment.