Skip to content

Commit

Permalink
Now GUIPostDrawing supports 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 ce2a535 commit 6003800
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 48 deletions.
24 changes: 11 additions & 13 deletions src/netedit/GNEViewNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1389,8 +1389,6 @@ GNEViewNet::doPaintGL(int mode, const Boundary& bound) {
myNet->getGrid().updateBoundaries(gPostDrawing.recomputeBoundaries);
}
*/
// execute post drawing tasks
gPostDrawing.executePostDrawingTasks();
return hits;
}

Expand Down Expand Up @@ -1983,7 +1981,7 @@ GNEJunction*
GNEViewNet::getJunctionAtPopupPosition() {
// get first object that can be found in their container
for (const auto& glObject : gPostDrawing.getElementsUnderCursor()) {
auto junction = myNet->getAttributeCarriers()->retrieveJunction(glObject, false);
auto junction = myNet->getAttributeCarriers()->retrieveJunction(glObject.first, false);
if (junction) {
return junction;
}
Expand All @@ -1996,7 +1994,7 @@ GNEConnection*
GNEViewNet::getConnectionAtPopupPosition() {
// get first object that can be found in their container
for (const auto& glObject : gPostDrawing.getElementsUnderCursor()) {
auto connection = myNet->getAttributeCarriers()->retrieveConnection(glObject, false);
auto connection = myNet->getAttributeCarriers()->retrieveConnection(glObject.first, false);
if (connection) {
return connection;
}
Expand All @@ -2009,7 +2007,7 @@ GNECrossing*
GNEViewNet::getCrossingAtPopupPosition() {
// get first object that can be found in their container
for (const auto& glObject : gPostDrawing.getElementsUnderCursor()) {
auto crossing = myNet->getAttributeCarriers()->retrieveCrossing(glObject, false);
auto crossing = myNet->getAttributeCarriers()->retrieveCrossing(glObject.first, false);
if (crossing) {
return crossing;
}
Expand All @@ -2022,7 +2020,7 @@ GNEWalkingArea*
GNEViewNet::getWalkingAreaAtPopupPosition() {
// get first object that can be found in their container
for (const auto& glObject : gPostDrawing.getElementsUnderCursor()) {
auto walkingArea = myNet->getAttributeCarriers()->retrieveWalkingArea(glObject, false);
auto walkingArea = myNet->getAttributeCarriers()->retrieveWalkingArea(glObject.first, false);
if (walkingArea) {
return walkingArea;
}
Expand All @@ -2035,7 +2033,7 @@ GNEEdge*
GNEViewNet::getEdgeAtPopupPosition() {
// get first object that can be found in their container
for (const auto& glObject : gPostDrawing.getElementsUnderCursor()) {
auto edge = myNet->getAttributeCarriers()->retrieveEdge(glObject, false);
auto edge = myNet->getAttributeCarriers()->retrieveEdge(glObject.first, false);
if (edge) {
return edge;
}
Expand All @@ -2048,7 +2046,7 @@ GNELane*
GNEViewNet::getLaneAtPopupPosition() {
// get first object that can be found in their container
for (const auto& glObject : gPostDrawing.getElementsUnderCursor()) {
auto lane = myNet->getAttributeCarriers()->retrieveLane(glObject, false);
auto lane = myNet->getAttributeCarriers()->retrieveLane(glObject.first, false);
if (lane) {
return lane;
}
Expand All @@ -2061,7 +2059,7 @@ GNEAdditional*
GNEViewNet::getAdditionalAtPopupPosition() {
// get first object that can be found in their container
for (const auto& glObject : gPostDrawing.getElementsUnderCursor()) {
auto additionalElement = myNet->getAttributeCarriers()->retrieveAdditional(glObject, false);
auto additionalElement = myNet->getAttributeCarriers()->retrieveAdditional(glObject.first, false);
if (additionalElement) {
return additionalElement;
}
Expand All @@ -2074,7 +2072,7 @@ GNEDemandElement*
GNEViewNet::getDemandElementAtPopupPosition() {
// get first object that can be found in their container
for (const auto& glObject : gPostDrawing.getElementsUnderCursor()) {
auto demandElement = myNet->getAttributeCarriers()->retrieveDemandElement(glObject, false);
auto demandElement = myNet->getAttributeCarriers()->retrieveDemandElement(glObject.first, false);
if (demandElement) {
return demandElement;
}
Expand All @@ -2087,7 +2085,7 @@ GNEPoly*
GNEViewNet::getPolygonAtPopupPosition() {
// get first object that can be parsed to poly element
for (const auto& glObject : gPostDrawing.getElementsUnderCursor()) {
auto polygon = dynamic_cast<GNEPoly*>(myNet->getAttributeCarriers()->retrieveAdditional(glObject, false));
auto polygon = dynamic_cast<GNEPoly*>(myNet->getAttributeCarriers()->retrieveAdditional(glObject.first, false));
if (polygon) {
return polygon;
}
Expand All @@ -2100,7 +2098,7 @@ GNEPOI*
GNEViewNet::getPOIAtPopupPosition() {
// get first object that can be parsed to POI element
for (const auto& glObject : gPostDrawing.getElementsUnderCursor()) {
auto POI = dynamic_cast<GNEPOI*>(myNet->getAttributeCarriers()->retrieveAdditional(glObject, false));
auto POI = dynamic_cast<GNEPOI*>(myNet->getAttributeCarriers()->retrieveAdditional(glObject.first, false));
if (POI) {
return POI;
}
Expand All @@ -2113,7 +2111,7 @@ GNETAZ*
GNEViewNet::getTAZAtPopupPosition() {
// get first object that can be parsed to TAZ element
for (const auto& glObject : gPostDrawing.getElementsUnderCursor()) {
auto TAZ = dynamic_cast<GNETAZ*>(myNet->getAttributeCarriers()->retrieveAdditional(glObject, false));
auto TAZ = dynamic_cast<GNETAZ*>(myNet->getAttributeCarriers()->retrieveAdditional(glObject.first, false));
if (TAZ) {
return TAZ;
}
Expand Down
16 changes: 8 additions & 8 deletions src/netedit/GNEViewNetHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1010,16 +1010,16 @@ GNEViewNetHelper::ObjectsUnderCursor::updateGenericDataElements(ObjectsContainer


void
GNEViewNetHelper::ObjectsUnderCursor::processGUIGlObjects(const std::vector<const GUIGlObject*>& glObjects) {
GNEViewNetHelper::ObjectsUnderCursor::processGUIGlObjects(const GUIPostDrawing::GLObjectsContainer& objectsContainer) {
// iterate over filtered edge objects
for (const auto& glObject : glObjects) {
for (const auto& glObject : objectsContainer) {
// update all elements by categories
updateNetworkElements(myObjects, glObject);
updateAdditionalElements(myObjects, glObject);
updateShapeElements(myObjects, glObject);
updateTAZElements(myObjects, glObject);
updateDemandElements(myObjects, glObject);
updateGenericDataElements(myObjects, glObject);
updateNetworkElements(myObjects, glObject.first);
updateAdditionalElements(myObjects, glObject.first);
updateShapeElements(myObjects, glObject.first);
updateTAZElements(myObjects, glObject.first);
updateDemandElements(myObjects, glObject.first);
updateGenericDataElements(myObjects, glObject.first);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/netedit/GNEViewNetHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
#include <utils/foxtools/MFXLCDLabel.h>
#include <utils/gui/globjects/GUIGlObject.h>
#include <utils/gui/globjects/GUIGlObjectTypes.h>
#include <utils/gui/div/GUIGlobalPostDrawing.h>

#include "GNEMoveElement.h"

// ===========================================================================
// enum
// ===========================================================================
Expand Down Expand Up @@ -412,7 +414,7 @@ struct GNEViewNetHelper {
void updateGenericDataElements(ObjectsContainer& container, const GUIGlObject* glObject);

/// @brief process GL objects
void processGUIGlObjects(const std::vector<const GUIGlObject*>& glObjects);
void processGUIGlObjects(const GUIPostDrawing::GLObjectsContainer& objectsContainer);

/// @brief default constructor
ObjectsUnderCursor();
Expand Down
63 changes: 47 additions & 16 deletions src/utils/gui/settings/GUIPostDrawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,32 @@ GUIPostDrawing::clearElements() {
}


void
GUIPostDrawing::executePostDrawingTasks() {
// udate AC geometries
for (const auto& GLObject : myGLObjectsToUpdate) {
GLObject->updateGLObject();
bool
GUIPostDrawing::isElementUnderCursor(const GUIGlObject* GLObject) const {
// avoid to insert duplicated elements
for (auto &element : myElementsUnderCursor) {
if (element.first == GLObject) {
return true;
}
}
return false;
}


bool
GUIPostDrawing::isElementUnderCursor(const GUIGlObject* GLObject) const {
return (std::find(myElementsUnderCursor.begin(), myElementsUnderCursor.end(), GLObject) != myElementsUnderCursor.end());
GUIPostDrawing::positionWithinCircle(const GUIGlObject* GLObject, const Position &pos, const Position &center, const double radius) {
if (pos.distanceSquaredTo2D(center) <= (radius * radius)) {
return addElementUnderCursor(GLObject);
} else {
return false;
}
}


bool
GUIPostDrawing::positionWithinCircle(const GUIGlObject* GLObject, const Position &pos, const Position &center, const double radius) {
GUIPostDrawing::positionWithinGeometryPoint(const GUIGlObject* GLObject, const Position &pos, const int index, const Position &center, const double radius) {
if (pos.distanceSquaredTo2D(center) <= (radius * radius)) {
addElementUnderCursor(GLObject);
return true;
return addGeometryPointUnderCursor(GLObject, index);
} else {
return false;
}
Expand All @@ -71,26 +77,51 @@ GUIPostDrawing::positionWithinCircle(const GUIGlObject* GLObject, const Position
bool
GUIPostDrawing::positionWithinShape(const GUIGlObject* GLObject, const Position &pos, const PositionVector &shape) {
if (shape.around(pos)) {
addElementUnderCursor(GLObject);
return true;
return addElementUnderCursor(GLObject);
} else {
return false;
}
}


const std::vector<const GUIGlObject*>&
const GUIPostDrawing::GLObjectsContainer&
GUIPostDrawing::getElementsUnderCursor() const {
return myElementsUnderCursor;
}


void
bool
GUIPostDrawing::addElementUnderCursor(const GUIGlObject* GLObject) {
// avoid to insert duplicated elements
if (isElementUnderCursor(GLObject) == false) {
myElementsUnderCursor.push_back(GLObject);
if (isElementUnderCursor(GLObject)) {
return false;
} else {
myElementsUnderCursor.push_back(std::make_pair(GLObject, std::vector<int>()));
return true;
}
}


bool
GUIPostDrawing::addGeometryPointUnderCursor(const GUIGlObject* GLObject, const int newIndex) {
// avoid to insert duplicated elements
for (auto &element : myElementsUnderCursor) {
if (element.first == GLObject) {
// avoid double points
for (auto &index : element.second) {
if (index == newIndex) {
return false;
}
}
// add new index
element.second.push_back(newIndex);
return true;
}
}
// no element found then add it
myElementsUnderCursor.push_back(std::make_pair(GLObject, std::vector<int>()));
myElementsUnderCursor.back().second.push_back(newIndex);
return true;
}

/****************************************************************************/
23 changes: 13 additions & 10 deletions src/utils/gui/settings/GUIPostDrawing.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,29 @@ class GNERoute;
class GUIPostDrawing {

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

/// @brief constructor
GUIPostDrawing();

/// @brief clear elements
void clearElements();

/// @brief execute post drawing tasks
void executePostDrawingTasks();

/// @brief check if element is under cursor
bool isElementUnderCursor(const GUIGlObject* GLObject) const;

/// @brief check if mouse is within elements geometry (for circles)
bool positionWithinCircle(const GUIGlObject* GLObject, const Position &pos, const Position &center, const double radius);

/// @brief check if mouse is within geometry point
bool positionWithinGeometryPoint(const GUIGlObject* GLObject, const Position &pos, const int index, const Position &center, const double radius);

/// @brief check if mouse is within closed shapes (for filled shapes)
bool positionWithinShape(const GUIGlObject* GLObject, const Position &pos, const PositionVector &shape);

/// @brief get all elements under cursor
const std::vector<const GUIGlObject*>& getElementsUnderCursor() const;
const GLObjectsContainer& getElementsUnderCursor() const;

/// @brief recompute boundaries
GUIGlObjectType recomputeBoundaries = GLO_NETWORK;
Expand All @@ -82,14 +85,14 @@ class GUIPostDrawing {
const GUIGlObject* markedSecondGeometryPoint = nullptr;

protected:
/// @brief GLObjects to update
std::vector<GUIGlObject*> myGLObjectsToUpdate;

/// @brief elements under cursor
std::vector<const GUIGlObject*> myElementsUnderCursor;
/// @brief elements under cursor and their geometry point indexes
GLObjectsContainer myElementsUnderCursor;

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

/// @brief add geometryPoint into list of elements under cursor
bool addGeometryPointUnderCursor(const GUIGlObject* GLObject, const int newIndex);

private:
/// @brief set copy constructor private
Expand Down

0 comments on commit 6003800

Please sign in to comment.