Skip to content

Commit

Permalink
Update edition of junction shapes. Refs #6945
Browse files Browse the repository at this point in the history
  • Loading branch information
palvarezlopez committed Jul 13, 2020
1 parent 3f39452 commit c00d98e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/netedit/GNEViewNet.cpp
Expand Up @@ -2152,7 +2152,7 @@ GNEViewNet::onCmdEditJunctionShape(FXObject*, FXSelector, void*) {
myNet->computeAndUpdate(OptionsCont::getOptions(), false);
}
// start edit custom shape
myEditShapes.startEditCustomShape(junction, junction->getNBNode()->getShape(), true);
myEditShapes.startEditCustomShape(junction, junction->getNBNode()->getShape());
}
// destroy pop-up and set focus in view net
destroyPopup();
Expand Down Expand Up @@ -2316,7 +2316,7 @@ GNEViewNet::onCmdEditConnectionShape(FXObject*, FXSelector, void*) {
// Obtain connection under mouse
GNEConnection* connection = getConnectionAtPopupPosition();
if (connection) {
myEditShapes.startEditCustomShape(connection, connection->getConnectionShape(), false);
myEditShapes.startEditCustomShape(connection, connection->getConnectionShape());
}
// destroy pop-up and update view Net
destroyPopup();
Expand All @@ -2332,7 +2332,7 @@ GNEViewNet::onCmdEditCrossingShape(FXObject*, FXSelector, void*) {
if (crossing) {
// due crossings haven two shapes, check what has to be edited
PositionVector shape = crossing->getNBCrossing()->customShape.size() > 0 ? crossing->getNBCrossing()->customShape : crossing->getNBCrossing()->shape;
myEditShapes.startEditCustomShape(crossing, shape, false);
myEditShapes.startEditCustomShape(crossing, shape);
}
// destroy pop-up and update view Net
destroyPopup();
Expand Down
54 changes: 47 additions & 7 deletions src/netedit/GNEViewNetHelper.cpp
Expand Up @@ -558,12 +558,15 @@ GNEViewNetHelper::MoveSingleElementValues::beginMoveSingleElementNetworkMode() {
// calculate TAZ movement values (can be entire shape or single geometry points)
return calculateTAZValues();
} else if (myViewNet->myObjectsUnderCursor.getJunctionFront()) {
/*
// set junction moved object
myJunctionToMove = myViewNet->myObjectsUnderCursor.getJunctionFront();
// start junction geometry moving
myJunctionToMove->startGeometryMoving();
// there is moved items, then return true
return true;
*/
return calculateJunctionValues();
} else if (myViewNet->myObjectsUnderCursor.getEdgeFront() || myViewNet->myObjectsUnderCursor.getLaneFront()) {
// calculate Edge movement values (can be entire shape, single geometry points, altitude, etc.)
return calculateEdgeValues();
Expand Down Expand Up @@ -614,8 +617,12 @@ GNEViewNetHelper::MoveSingleElementValues::moveSingleElement() {
// Move POI's geometry without commiting changes
myPOIToMove->movePOIGeometry(offsetMovement);
} else if (myJunctionToMove) {
/*
// Move Junction's geometry without commiting changes
myJunctionToMove->moveGeometry(offsetMovement);
*/
// move edge's geometry without commiting changes
myJunctionToMove->moveShape(offsetMovement);
} else if (myEdgeToMove) {
// check if we're moving the start or end position, or a geometry point
if (myMovingStartPos) {
Expand Down Expand Up @@ -649,9 +656,12 @@ GNEViewNetHelper::MoveSingleElementValues::finishMoveSingleElement() {
myPOIToMove = nullptr;
} else if (myJunctionToMove) {
// check if in the moved position there is another Junction and it will be merged
/*
if (!myViewNet->mergeJunctions(myJunctionToMove)) {
myJunctionToMove->commitGeometryMoving(myViewNet->getUndoList());
}
*/
myJunctionToMove->commitGeometryMoving(myViewNet->getUndoList());
myJunctionToMove = nullptr;
} else if (myEdgeToMove) {
// commit change depending of what was moved
Expand Down Expand Up @@ -769,6 +779,42 @@ GNEViewNetHelper::MoveSingleElementValues::calculateEdgeValues() {
}


bool
GNEViewNetHelper::MoveSingleElementValues::calculateJunctionValues() {
// assign clicked junction to junctionToMove
myJunctionToMove = myViewNet->myObjectsUnderCursor.getJunctionFront();
// calculate junctionShapeOffset
const double junctionShapeOffset = myJunctionToMove->getNBNode()->getShape().nearest_offset_to_point2D(myViewNet->getPositionInformation(), false);
// calculate distance to shape
const double distanceToShape = myJunctionToMove->getNBNode()->getShape().distance2D(myViewNet->getPositionInformation());
// now we have two cases: if we're editing the X-Y coordenade or the altitude (z)
if (myViewNet->myNetworkViewOptions.menuCheckMoveElevation->shown() && myViewNet->myNetworkViewOptions.menuCheckMoveElevation->getCheck() == TRUE) {
// check if we clicked over a vertex index
if (myJunctionToMove->getShapeVertexIndex(myViewNet->getPositionInformation(), false) != -1) {
// start geometry moving
myJunctionToMove->startShapeGeometryMoving(junctionShapeOffset);
// junction values sucesfully calculated, then return true
return true;
} else {
// stop junction moving
myJunctionToMove = nullptr;
// junction values wasn't calculated, then return false
return false;
}
} else if (/*distanceToShape <= myViewNet->getVisualisationSettings().neteditSizeSettings.movingGeometryPointRadius*/ true) {
// start geometry moving
myJunctionToMove->startShapeGeometryMoving(junctionShapeOffset);
// junction values sucesfully calculated, then return true
return true;
} else {
// stop junction moving
myJunctionToMove = nullptr;
// junction values wasn't calculated, then return false
return false;
}
}


bool
GNEViewNetHelper::MoveSingleElementValues::calculateTAZValues() {
// assign clicked TAZ to TAZToMove
Expand Down Expand Up @@ -2805,22 +2851,16 @@ GNEViewNetHelper::DataCheckableButtons::updateDataCheckableButtons() {

GNEViewNetHelper::EditShapes::EditShapes(GNEViewNet* viewNet) :
editedNetworkElement(nullptr),
editingNetworkElementShapes(false),
myPreviousNetworkEditMode(NetworkEditMode::NETWORK_NONE),
myViewNet(viewNet) {
}


void
GNEViewNetHelper::EditShapes::startEditCustomShape(GNENetworkElement* element, const PositionVector& shape, bool fill) {
GNEViewNetHelper::EditShapes::startEditCustomShape(GNENetworkElement* element, const PositionVector& shape) {
if ((editedNetworkElement == nullptr) && (element != nullptr) && (shape.size() > 1)) {
// save current edit mode before starting
myPreviousNetworkEditMode = myViewNet->myEditModes.networkEditMode;
if ((element->getTagProperty().getTag() == SUMO_TAG_CONNECTION) || (element->getTagProperty().getTag() == SUMO_TAG_CROSSING)) {
editingNetworkElementShapes = true;
} else {
editingNetworkElementShapes = false;
}
// set move mode
myViewNet->myEditModes.setNetworkEditMode(NetworkEditMode::NETWORK_MOVE);
// add special GNEPoly fo edit shapes (color is taken from junction color settings)
Expand Down
8 changes: 4 additions & 4 deletions src/netedit/GNEViewNetHelper.h
Expand Up @@ -772,6 +772,9 @@ struct GNEViewNetHelper {
/// calculate Edge movement values (Position, Index, etc.)
bool calculateEdgeValues();

/// calculate junction movement values (Position, Index, etc.)
bool calculateJunctionValues();

/// calculate TAZ movement values (Position, Index, etc.)
bool calculateTAZValues();

Expand Down Expand Up @@ -1135,7 +1138,7 @@ struct GNEViewNetHelper {
EditShapes(GNEViewNet* viewNet);

/// @brief start edit custom shape
void startEditCustomShape(GNENetworkElement* element, const PositionVector& shape, bool fill);
void startEditCustomShape(GNENetworkElement* element, const PositionVector& shape);

/// @brief edit edit shape
void stopEditCustomShape();
Expand All @@ -1146,9 +1149,6 @@ struct GNEViewNetHelper {
/// @brief pointer to edited network element
GNENetworkElement* editedNetworkElement;

/// @brief flag to edit network element shapes
bool editingNetworkElementShapes;

private:
/// @brief the previous edit mode before edit NetworkElement's shapes
NetworkEditMode myPreviousNetworkEditMode;
Expand Down
2 changes: 1 addition & 1 deletion src/netedit/elements/network/GNENetworkElement.cpp
Expand Up @@ -162,7 +162,7 @@ GNENetworkElement::moveShape(const Position& offset) {
}
}
// set new shape
setAttribute(SUMO_ATTR_SHAPE, toString(getShapeBeforeMoving()));
setAttribute(SUMO_ATTR_SHAPE, toString(newShape));
// update geometry
updateGeometry();
}
Expand Down

0 comments on commit c00d98e

Please sign in to comment.