Skip to content

Commit

Permalink
Updated calculation of geometry points. Refs #13894
Browse files Browse the repository at this point in the history
  • Loading branch information
palvarezlopez committed Dec 19, 2023
1 parent e5955d0 commit fd223e4
Show file tree
Hide file tree
Showing 22 changed files with 230 additions and 172 deletions.
6 changes: 3 additions & 3 deletions src/netedit/GNEMoveElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ GNEMoveElement::GNEMoveElement() :


GNEMoveOperation*
GNEMoveElement::calculateMoveShapeOperation(const GUIGlObject* obj, const PositionVector originalShape,
const bool onlyContour, const bool maintainShapeClosed) {
GNEMoveElement::calculateMoveShapeOperation(const GUIGlObject* obj, const PositionVector originalShape,
const bool maintainShapeClosed) {
// get moved geometry points
const auto geometryPoints = gViewObjectsHandler.getGeometryPoints(obj);
// get pos over shape
Expand All @@ -207,7 +207,7 @@ GNEMoveElement::calculateMoveShapeOperation(const GUIGlObject* obj, const Positi
} else {
return new GNEMoveOperation(this, originalShape, {geometryPoints.front()}, shapeToMove, {geometryPoints.front()});
}
} else if (!onlyContour && (posOverShape != Position::INVALID)) {
} else if (posOverShape != Position::INVALID) {
// create new geometry point and keep new index (if we clicked near of shape)
const int newIndex = shapeToMove.insertAtClosest(posOverShape, true);
return new GNEMoveOperation(this, originalShape, {shapeToMove.indexOfClosest(posOverShape)}, shapeToMove, {newIndex});
Expand Down
2 changes: 1 addition & 1 deletion src/netedit/GNEMoveElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ class GNEMoveElement {
double myMoveElementLateralOffset;

/// @brief calculate move shape operation
GNEMoveOperation* calculateMoveShapeOperation(const GUIGlObject* obj, const PositionVector originalShape, const bool onlyContour, const bool maintainShapeClosed);
GNEMoveOperation* calculateMoveShapeOperation(const GUIGlObject* obj, const PositionVector originalShape, const bool maintainShapeClosed);

private:
/// @brief set move shape
Expand Down
159 changes: 105 additions & 54 deletions src/netedit/elements/GNEContour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,60 +113,6 @@ GNEContour::calculateContourCircleShape(const GUIVisualizationSettings& s, const
}
}


void
GNEContour::calculateContourGeometryPoints(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
const GUIGlObject* glObject, const PositionVector& shape, GeometryPoint geometryPoints,
double radius, const double scale, const double lineWidth) const {
return;
// declare distance
const auto scaledRadius = (radius * scale);
// check if we're calculating the mouse position over geometry or drawing dotted geometry
if (s.drawForObjectUnderCursor) {
// iterate over all geometry points
for (int i = 0; i < (int)shape.size(); i++) {
const bool first = (i == 0);
const bool last = ((i + 1) == (int)shape.size());
// check conditions
if ((geometryPoints == GeometryPoint::ALL) ||
(first && (geometryPoints == GeometryPoint::FROM)) ||
(last && (geometryPoints == GeometryPoint::TO)) ||
(!first && !last && (geometryPoints == GeometryPoint::MIDDLE))) {
// check position within geometry
gViewObjectsHandler.checkGeometryPoint(d, glObject, i, shape[i], scaledRadius);
}
}
// check if mouse is over shape
if (s.drawForObjectUnderCursor) {
// check position over shape
gViewObjectsHandler.checkPositionOverShape(d, glObject, shape, scaledRadius);
}
} else if (!s.disableDottedContours && (d <= GUIVisualizationSettings::Detail::DottedContours)) {
// get all geometry points
const auto &geometryPointIndexes = gViewObjectsHandler.getGeometryPoints(glObject);
// either draw geometry point indexes or pos over shape, but not together
if (geometryPointIndexes.size() > 0) {
// draw all geometry points
for (const auto &geometryPointIndex : geometryPointIndexes) {
// build dotted contour circle
buildContourCircle(s, d, shape[geometryPointIndex], radius, scale);
// draw geometry point
drawDottedContour(s, GUIDottedGeometry::DottedContourType::MOVE, lineWidth, 0);
}
} else {
// check if draw dotted contour over shape
const auto &posOverShape = gViewObjectsHandler.getPositionOverShape(glObject);
if (posOverShape != Position::INVALID) {
// build dotted contour circle
buildContourCircle(s, d, posOverShape, radius, scale);
// draw geometry point
drawDottedContour(s, GUIDottedGeometry::DottedContourType::MOVE, lineWidth, 0);
}
}
}
}


void
GNEContour::calculateContourEdge(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
const GNEEdge* edge, const bool closeFirstExtrem, const bool closeLastExtrem) const {
Expand All @@ -188,6 +134,63 @@ GNEContour::calculateContourEdges(const GUIVisualizationSettings& s, const GUIVi
}


void
GNEContour::calculateContourFirstGeometryPoint(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
const GUIGlObject* glObject, const PositionVector& shape, double radius,
const double scale) const {
// check if we're in drawForObjectUnderCursor
if (s.drawForObjectUnderCursor && (shape.size() > 0)) {
// check position within geometry of first geometry point
gViewObjectsHandler.checkGeometryPoint(d, glObject, shape, 0, (radius * scale));
}
}


void
GNEContour::calculateContourLastGeometryPoint(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
const GUIGlObject* glObject, const PositionVector& shape, double radius,
const double scale) const {
// check if we're in drawForObjectUnderCursor
if (s.drawForObjectUnderCursor && (shape.size() > 0)) {
// check position within geometry of last geometry point
gViewObjectsHandler.checkGeometryPoint(d, glObject, shape, (int)shape.size() - 1, (radius * scale));
}
}


void
GNEContour::calculateContourMiddleGeometryPoints(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
const GUIGlObject* glObject, const PositionVector& shape, double radius,
const double scale) const {
// check if we're in drawForObjectUnderCursor
if (s.drawForObjectUnderCursor) {
// check position within geometry of middle geometry points
for (int i = 1; i < (int)shape.size() - 1; i++) {
gViewObjectsHandler.checkGeometryPoint(d, glObject, shape, i, (radius * scale));
}
// also calculate position over shape
gViewObjectsHandler.checkPositionOverShape(d, glObject, shape, (radius * scale));
}
}

void
GNEContour::calculateContourAllGeometryPoints(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
const GUIGlObject* glObject, const PositionVector& shape, double radius,
const double scale, const bool calculatePosOverShape) const {
// check if we're in drawForObjectUnderCursor
if (s.drawForObjectUnderCursor) {
// check position within geometry of middle geometry points
for (int i = 0; i < (int)shape.size(); i++) {
gViewObjectsHandler.checkGeometryPoint(d, glObject, shape, i, (radius * scale));
}
// check if calculate position over shape
if (calculatePosOverShape) {
gViewObjectsHandler.checkPositionOverShape(d, glObject, shape, (radius * scale));
}
}
}


void
GNEContour::drawDottedContours(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
const GNEAttributeCarrier *AC, const double lineWidth, const bool addOffset) const {
Expand Down Expand Up @@ -226,6 +229,54 @@ GNEContour::drawDottedContours(const GUIVisualizationSettings& s, const GUIVisua
}


void
GNEContour::drawDottedContourGeometryPoints(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
const GUIGlObject* glObject, const PositionVector &shape, const double radius,
const double scale, const double lineWidth) const {
// first check if draw dotted contour
if (!s.disableDottedContours && (d <= GUIVisualizationSettings::Detail::DottedContours)) {
// get geometry points
const auto &geometryPoints = gViewObjectsHandler.getGeometryPoints(glObject);
// draw every geometry point
for (const auto &geometryPoint : geometryPoints) {
// create circle shape
const auto circleShape = GUIGeometry::getVertexCircleAroundPosition(shape[geometryPoint], radius * scale, 16);
// calculate dotted geometry
const auto dottedGeometry = GUIDottedGeometry(s, d, circleShape, true);
// reset dotted geometry color
myDottedGeometryColor.reset();
// Push draw matrix
GLHelper::pushMatrix();
// translate to front
glTranslated(0, 0, GLO_DOTTEDCONTOUR);
// draw dotted geometries
dottedGeometry.drawDottedGeometry(s, GUIDottedGeometry::DottedContourType::MOVE, myDottedGeometryColor, lineWidth, 0);
// pop matrix
GLHelper::popMatrix();
}
// get temporal position over shape
const auto &posOverShape = gViewObjectsHandler.getPositionOverShape(glObject);
// draw if is defined
if (posOverShape != Position::INVALID) {
// create circle shape
const auto circleShape = GUIGeometry::getVertexCircleAroundPosition(posOverShape, radius * scale, 16);
// calculate dotted geometry
const auto dottedGeometry = GUIDottedGeometry(s, d, circleShape, true);
// reset dotted geometry color
myDottedGeometryColor.reset();
// Push draw matrix
GLHelper::pushMatrix();
// translate to front
glTranslated(0, 0, GLO_DOTTEDCONTOUR);
// draw dotted geometries
dottedGeometry.drawDottedGeometry(s, GUIDottedGeometry::DottedContourType::MOVE, myDottedGeometryColor, lineWidth, 0);
// pop matrix
GLHelper::popMatrix();
}
}
}


void
GNEContour::drawInnenContourClosed(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
const PositionVector& shape, const double scale, const double lineWidth) const {
Expand Down
39 changes: 25 additions & 14 deletions src/netedit/elements/GNEContour.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ class GNEAttributeCarrier;
class GNEContour {

public:
/// @brief enum for check geometryPoints
enum class GeometryPoint {
FROM, // Geometry point from
TO, // Geometry point to
MIDDLE, // All geometry points except from-to
ALL // All geometry points
};

/// @brief Constructor
GNEContour();

Expand Down Expand Up @@ -76,19 +68,33 @@ class GNEContour {
void calculateContourCircleShape(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
const GUIGlObject* glObject, const Position& pos, double radius, const double scale) const;

/// @brief calculate contour (geometry points elements)
void calculateContourGeometryPoints(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
const GUIGlObject* glObject, const PositionVector& shape, GeometryPoint geometryPoints,
double radius, const double scale, const double lineWidth) const;

/// @brief calculate contour edge
void calculateContourEdge(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
const GNEEdge* edge, const bool closeFirstExtrem, const bool closeLastExtrem) const;

/// @brief calculate contour between two consecutive edges
void calculateContourEdges(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
const GNEEdge* fromEdge, const GNEEdge* toEdge) const;


/// @brief calculate contour for first geometry point
void calculateContourFirstGeometryPoint(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
const GUIGlObject* glObject, const PositionVector& shape, const double radius,
const double scale) const;

/// @brief calculate contour for last geometry point
void calculateContourLastGeometryPoint(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
const GUIGlObject* glObject, const PositionVector& shape, const double radius,
const double scale) const;

/// @brief calculate contour for middle geometry point
void calculateContourMiddleGeometryPoints(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
const GUIGlObject* glObject, const PositionVector& shape, const double radius,
const double scale) const;

/// @brief calculate contour for all geometry points
void calculateContourAllGeometryPoints(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
const GUIGlObject* glObject, const PositionVector& shape, const double radius,
const double scale, const bool calculatePosOverShape) const;
/// @}

/// @brief drawing contour functions
Expand All @@ -98,6 +104,11 @@ class GNEContour {
void drawDottedContours(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
const GNEAttributeCarrier *AC, const double lineWidth, const bool addOffset) const;

/// @brief draw dotted contour for geometry points
void drawDottedContourGeometryPoints(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
const GUIGlObject* glObject, const PositionVector &shape, const double radius,
const double scale, const double lineWidth) const;

/// @brief draw innen contour (currently used only in walkingAreas)
void drawInnenContourClosed(const GUIVisualizationSettings& s, const GUIVisualizationSettings::Detail d,
const PositionVector& shape, const double scale, const double lineWidth) const;
Expand Down
7 changes: 4 additions & 3 deletions src/netedit/elements/additional/GNEAdditional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1005,11 +1005,12 @@ GNEAdditional::calculateContourPolygons(const GUIVisualizationSettings& s, const
const auto &editModes = myNet->getViewNet()->getEditModes();
// check if draw geometry points
if (editModes.isCurrentSupermodeNetwork() && !myNet->getViewNet()->getViewParent()->getMoveFrame()->getNetworkModeOptions()->getMoveWholePolygons()) {
// check if we're in move mode
const bool moveMode = (editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE);
// get geometry point radius (size depends if we're in move mode)
const double geometryPointRaidus = s.neteditSizeSettings.additionalGeometryPointRadius * ((editModes.networkEditMode == NetworkEditMode::NETWORK_MOVE)? 1 : 0.5);
const double geometryPointRaidus = s.neteditSizeSettings.polygonGeometryPointRadius * (moveMode? 1 : 0.5);
// calculate contour geometry points
myAdditionalContour.calculateContourGeometryPoints(s, d, this, myAdditionalGeometry.getShape(), GNEContour::GeometryPoint::ALL,
geometryPointRaidus, exaggeration, s.dottedContourSettings.segmentWidth);
myAdditionalContour.calculateContourAllGeometryPoints(s, d, this, myAdditionalGeometry.getShape(), geometryPointRaidus, exaggeration, moveMode);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/netedit/elements/additional/GNEBusStop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ GNEBusStop::drawGL(const GUIVisualizationSettings& s) const {
drawAdditionalName(s);
// draw dotted contour
myAdditionalContour.drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);
// draw dotted contours for geometry points
myAdditionalContour.drawDottedContourGeometryPoints(s, d, this, myAdditionalGeometry.getShape(), s.neteditSizeSettings.additionalGeometryPointRadius,
1, s.dottedContourSettings.segmentWidthSmall);
}
// draw demand element children
drawDemandElementChildren(s);
Expand Down
3 changes: 3 additions & 0 deletions src/netedit/elements/additional/GNEChargingStation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ GNEChargingStation::drawGL(const GUIVisualizationSettings& s) const {
drawAdditionalName(s);
// draw dotted contour
myAdditionalContour.drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);
// draw dotted contours for geometry points
myAdditionalContour.drawDottedContourGeometryPoints(s, d, this, myAdditionalGeometry.getShape(), s.neteditSizeSettings.additionalGeometryPointRadius,
1, s.dottedContourSettings.segmentWidthSmall);
}
// draw stoppingPlace children
drawDemandElementChildren(s);
Expand Down
3 changes: 3 additions & 0 deletions src/netedit/elements/additional/GNEContainerStop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ GNEContainerStop::drawGL(const GUIVisualizationSettings& s) const {
drawAdditionalName(s);
// draw dotted contour
myAdditionalContour.drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);
// draw dotted contours for geometry points
myAdditionalContour.drawDottedContourGeometryPoints(s, d, this, myAdditionalGeometry.getShape(), s.neteditSizeSettings.additionalGeometryPointRadius,
1, s.dottedContourSettings.segmentWidthSmall);
}
// draw demand element children
drawDemandElementChildren(s);
Expand Down
3 changes: 3 additions & 0 deletions src/netedit/elements/additional/GNEParkingArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ GNEParkingArea::drawGL(const GUIVisualizationSettings& s) const {
drawAdditionalName(s);
// draw dotted contour
myAdditionalContour.drawDottedContours(s, d, this, s.dottedContourSettings.segmentWidth, true);
// draw dotted contours for geometry points
myAdditionalContour.drawDottedContourGeometryPoints(s, d, this, myAdditionalGeometry.getShape(), s.neteditSizeSettings.additionalGeometryPointRadius,
1, s.dottedContourSettings.segmentWidthSmall);
}
// draw demand element children
drawDemandElementChildren(s);
Expand Down

0 comments on commit fd223e4

Please sign in to comment.