Skip to content

Commit

Permalink
Updated GUIObjectsInPosition. Refs #13894
Browse files Browse the repository at this point in the history
  • Loading branch information
palvarezlopez committed Dec 19, 2023
1 parent 29a7047 commit d37b90b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
28 changes: 14 additions & 14 deletions src/utils/gui/settings/GUIObjectsInPosition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ GUIObjectsInPosition::isElementUnderCursor(const GUIGlObject* GLObject) const {
// avoid to insert duplicated elements
for (auto &elementLayer : myElementsUnderCursor) {
for (auto &element : elementLayer.second) {
if (element.first == GLObject) {
if (element.object == GLObject) {
return true;
}
}
Expand All @@ -63,8 +63,8 @@ GUIObjectsInPosition::isGeometryPointUnderCursor(const GUIGlObject* GLObject, co
// avoid to insert duplicated elements
for (auto &elementLayer : myElementsUnderCursor) {
for (auto &element : elementLayer.second) {
if (element.first == GLObject) {
return std::find(element.second.begin(), element.second.end(), index) != element.second.end();
if (element.object == GLObject) {
return std::find(element.geometryPoints.begin(), element.geometryPoints.end(), index) != element.geometryPoints.end();
}
}
}
Expand Down Expand Up @@ -108,13 +108,13 @@ GUIObjectsInPosition::getElementsUnderCursor() const {
}


const GUIObjectsInPosition::GeometryPointsContainer&
const std::vector<int>&
GUIObjectsInPosition::getGeometryPoints(const GUIGlObject* GLObject) const {
// avoid to insert duplicated elements
for (auto &elementLayer : myElementsUnderCursor) {
for (auto &element : elementLayer.second) {
if (element.first == GLObject) {
return element.second;
if (element.object == GLObject) {
return element.geometryPoints;
}
}
}
Expand All @@ -124,15 +124,15 @@ GUIObjectsInPosition::getGeometryPoints(const GUIGlObject* GLObject) const {

void
GUIObjectsInPosition::updateFrontElement(const GUIGlObject* GLObject) {
GLObjectContainer frontElement(nullptr, {});
ObjectContainer frontElement;
// extract element
for (auto &elementLayer : myElementsUnderCursor) {
auto it = elementLayer.second.begin();
while (it != elementLayer.second.end()) {
if (it->first == GLObject) {
if (it->object == GLObject) {
// copy element to front element
frontElement.first = it->first;
frontElement.second = it->second;
frontElement.object = it->object;
frontElement.geometryPoints = it->geometryPoints;
// remove element from myElementsUnderCursor
it = elementLayer.second.erase(it);
} else {
Expand All @@ -141,7 +141,7 @@ GUIObjectsInPosition::updateFrontElement(const GUIGlObject* GLObject) {
}
}
// add element again wit a new layer
if (frontElement.first) {
if (frontElement.object) {
myElementsUnderCursor[(double)GLO_FRONTELEMENT].push_back(frontElement);
}
}
Expand Down Expand Up @@ -172,15 +172,15 @@ GUIObjectsInPosition::addGeometryPointUnderCursor(const GUIGlObject* GLObject, c
// avoid to insert duplicated elements
for (auto &elementLayer : myElementsUnderCursor) {
for (auto &element : elementLayer.second) {
if (element.first == GLObject) {
if (element.object == GLObject) {
// avoid double points
for (auto &index : element.second) {
for (auto &index : element.geometryPoints) {
if (index == newIndex) {
return false;
}
}
// add new index
element.second.push_back(newIndex);
element.geometryPoints.push_back(newIndex);
return true;
}
}
Expand Down
21 changes: 16 additions & 5 deletions src/utils/gui/settings/GUIObjectsInPosition.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,21 @@ class GNERoute;
class GUIObjectsInPosition {

public:
/// @brief typedefs
typedef std::vector<int> GeometryPointsContainer;
typedef std::pair<const GUIGlObject*, GeometryPointsContainer> GLObjectContainer;
typedef std::map<double, std::vector<GLObjectContainer> > GLObjectsSortedContainer;
/// @brief object container
struct ObjectContainer {

/// @brief object
const GUIGlObject* object = nullptr;

/// @brief vector with geometry points
std::vector<int> geometryPoints;

/// @brief new position
Position newPosition;
};

/// @brief typedef
typedef std::map<double, std::vector<ObjectContainer> > GLObjectsSortedContainer;

/// @brief constructor
GUIObjectsInPosition();
Expand All @@ -69,7 +80,7 @@ class GUIObjectsInPosition {
const GLObjectsSortedContainer& getElementsUnderCursor() const;

/// @brief get geometry points for the given glObject
const GeometryPointsContainer& getGeometryPoints(const GUIGlObject* GLObject) const;
const std::vector<int>& getGeometryPoints(const GUIGlObject* GLObject) const;

/// @brief move front element in elements under cursor (currently used only in netedit)
void updateFrontElement(const GUIGlObject* GLObject);
Expand Down

0 comments on commit d37b90b

Please sign in to comment.