Skip to content

Commit

Permalink
Moved functions from GUIGLObject to GUIPostDrawing. Refs #13894
Browse files Browse the repository at this point in the history
  • Loading branch information
palvarezlopez committed Dec 19, 2023
1 parent 1e3b3e8 commit 98c866e
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 78 deletions.
2 changes: 0 additions & 2 deletions src/netedit/GNEViewNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1394,8 +1394,6 @@ GNEViewNet::doPaintGL(int mode, const Boundary& bound) {
glEnable(GL_POLYGON_OFFSET_LINE);
// clear post drawing elements
gPostDrawing.clearElements();
// set current mouse position in gPostDrawing
gPostDrawing.mousePos = getPositionInformation();
// obtain objects included in minB and maxB
int hits2 = myGrid->Search(minB, maxB, *myVisualizationSettings);
// fill objects under cursor
Expand Down
8 changes: 4 additions & 4 deletions src/netedit/elements/GNEContour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ GNEContour::drawDottedContourClosed(const GUIVisualizationSettings& s, const Pos
// first build dotted contour
buildDottedContourClosed(s, shape, scale);
// check if mouse is within geometry
myAC->getGUIGlObject()->positionWithinGeometry(myAC->getNet()->getViewNet()->getPositionInformation(), *myCachedShape);
gPostDrawing.positionWithinClosedShape(myAC->getGUIGlObject(), myAC->getNet()->getViewNet()->getPositionInformation(), *myCachedShape);
// draw dotted contours
drawDottedContours(s, s.drawDottedContour(scale), addOffset, lineWidth);
}
Expand All @@ -86,7 +86,7 @@ GNEContour::drawDottedContourExtruded(const GUIVisualizationSettings& s, const P
// first build dotted contour
buildDottedContourExtruded(s, shape, extrusionWidth, scale, drawFirstExtrem, drawLastExtrem);
// check if mouse is within geometry
myAC->getGUIGlObject()->positionWithinGeometry(myAC->getNet()->getViewNet()->getPositionInformation(), shape, extrusionWidth * scale);
gPostDrawing.positionWithinShapeLine(myAC->getGUIGlObject(), myAC->getNet()->getViewNet()->getPositionInformation(), shape, extrusionWidth * scale);
// draw dotted contours
drawDottedContours(s, scale, true, lineWidth);
}
Expand All @@ -99,7 +99,7 @@ GNEContour::drawDottedContourRectangle(const GUIVisualizationSettings& s, const
// first build dotted contour
buildDottedContourRectangle(s, pos, width, height, offsetX, offsetY, rot, scale);
// check if mouse is within geometry
myAC->getGUIGlObject()->positionWithinGeometry(myAC->getNet()->getViewNet()->getPositionInformation(), *myCachedShape);
gPostDrawing.positionWithinClosedShape(myAC->getGUIGlObject(), myAC->getNet()->getViewNet()->getPositionInformation(), *myCachedShape);
// draw dotted contours
drawDottedContours(s, scale, true, lineWidth);
}
Expand All @@ -111,7 +111,7 @@ GNEContour::drawDottedContourCircle(const GUIVisualizationSettings& s, const Pos
// first build dotted contour
buildDottedContourCircle(s, pos, radius, scale);
// check if mouse is within geometry
myAC->getGUIGlObject()->positionWithinGeometry(myAC->getNet()->getViewNet()->getPositionInformation(), pos, (radius * scale));
gPostDrawing.positionWithinCircle(myAC->getGUIGlObject(), myAC->getNet()->getViewNet()->getPositionInformation(), pos, (radius * scale));
// draw dotted contours
drawDottedContours(s, scale, true, lineWidth);
}
Expand Down
44 changes: 0 additions & 44 deletions src/utils/gui/globjects/GUIGlObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,50 +416,6 @@ GUIGlObject::buildAdditionalsPopupOptions(GUIMainWindow& app, GUIGLObjectPopupMe
}


bool
GUIGlObject::positionWithinGeometry(const Position &pos, const Position center, const double radius) const {
if (pos.distanceSquaredTo2D(center) <= (radius * radius)) {
gPostDrawing.addElementUnderCursor(this);
return true;
} else {
return false;
}
}


bool
GUIGlObject::positionWithinGeometry(const Position &pos, const PositionVector shape) const {
if (shape.around(pos)) {
gPostDrawing.addElementUnderCursor(this);
return true;
} else {
return false;
}
}


bool
GUIGlObject::positionWithinGeometry(const Position &pos, const PositionVector shape, const double width) const {
if (shape.distance2D(pos) <= width) {
gPostDrawing.addElementUnderCursor(this);
return true;
} else {
return false;
}
}


bool
GUIGlObject::positionWithinGeometry(const Position &pos, const PositionVector shape, const double width, GUIGlObject* parent) const {
if (shape.distance2D(pos) <= width) {
gPostDrawing.addElementUnderCursor(parent);
return true;
} else {
return false;
}
}


std::string
GUIGlObject::createFullName() const {
return TypeNames.getString(myGLObjectType) + ":" + getMicrosimID();
Expand Down
13 changes: 0 additions & 13 deletions src/utils/gui/globjects/GUIGlObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,19 +297,6 @@ class GUIGlObject {
/// @brief build basic additional popup options. Used to unify pop-ups menu in netedit and SUMO-GUI
void buildAdditionalsPopupOptions(GUIMainWindow& app, GUIGLObjectPopupMenu* ret, const std::string& type);

public:
/// @brief check if mouse is within elements geometry (for circles)
bool positionWithinGeometry(const Position &pos, const Position center, const double radius) const;

/// @brief check if mouse is within elements geometry (for filled shapes)
bool positionWithinGeometry(const Position &pos, const PositionVector shape) const;

/// @brief check if mouse is within elements geometry (for shapes)
bool positionWithinGeometry(const Position &pos, const PositionVector shape, const double width) const;

/// @brief check if mouse is within elements geometry (for edges)
bool positionWithinGeometry(const Position &pos, const PositionVector shape, const double width, GUIGlObject* parent) const;

private:
/// @brief The numerical id of the object
const GUIGlID myGlID;
Expand Down
49 changes: 40 additions & 9 deletions src/utils/gui/settings/GUIPostDrawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ GUIPostDrawing::clearElements() {
// reset recompute boundaries
recomputeBoundaries = GLO_NETWORK;
myGLObjectsToUpdate.clear();
// reset mouse Pos
mousePos = Position::INVALID;
// clear objects under cursor
myElementsUnderCursor.clear();
// reset marked elements
Expand Down Expand Up @@ -65,18 +63,42 @@ GUIPostDrawing::markGLObjectToUpdate(GUIGlObject* GLObject) {
}


void
GUIPostDrawing::addElementUnderCursor(const GUIGlObject* GLObject) {
// avoid to insert duplicated elements
if (isElementUnderCursor(GLObject) == false) {
myElementsUnderCursor.push_back(GLObject);
bool
GUIPostDrawing::isElementUnderCursor(const GUIGlObject* GLObject) const {
return (std::find(myElementsUnderCursor.begin(), myElementsUnderCursor.end(), GLObject) != myElementsUnderCursor.end());
}


bool
GUIPostDrawing::positionWithinCircle(const GUIGlObject* GLObject, const Position &pos, const Position center, const double radius) {
if (pos.distanceSquaredTo2D(center) <= (radius * radius)) {
addElementUnderCursor(GLObject);
return true;
} else {
return false;
}
}


bool
GUIPostDrawing::isElementUnderCursor(const GUIGlObject* GLObject) const {
return (std::find(myElementsUnderCursor.begin(), myElementsUnderCursor.end(), GLObject) != myElementsUnderCursor.end());
GUIPostDrawing::positionWithinClosedShape(const GUIGlObject* GLObject, const Position &pos, const PositionVector shape) {
if (shape.around(pos)) {
addElementUnderCursor(GLObject);
return true;
} else {
return false;
}
}


bool
GUIPostDrawing::positionWithinShapeLine(const GUIGlObject* GLObject, const Position &pos, const PositionVector shape, const double width) {
if (shape.distance2D(pos) <= width) {
addElementUnderCursor(GLObject);
return true;
} else {
return false;
}
}


Expand All @@ -85,4 +107,13 @@ GUIPostDrawing::getElementsUnderCursor() const {
return myElementsUnderCursor;
}


void
GUIPostDrawing::addElementUnderCursor(const GUIGlObject* GLObject) {
// avoid to insert duplicated elements
if (isElementUnderCursor(GLObject) == false) {
myElementsUnderCursor.push_back(GLObject);
}
}

/****************************************************************************/
18 changes: 12 additions & 6 deletions src/utils/gui/settings/GUIPostDrawing.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,24 @@ class GUIPostDrawing {
/// @brief mark GLObject to update (usually the geometry)
void markGLObjectToUpdate(GUIGlObject* GLObject);

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

/// @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 closed geometry (for filled shapes)
bool positionWithinClosedShape(const GUIGlObject* GLObject, const Position &pos, const PositionVector shape);

/// @brief check if mouse is within elements geometry (for shapes)
bool positionWithinShapeLine(const GUIGlObject* GLObject, const Position &pos, const PositionVector shape, const double width);

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

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

/// @brief mouse position before rendering elements
Position mousePos = Position::INVALID;

/// @brief elements marked for drawing over contour (used in netedit)
const GUIGlObject* markedElementOverContour;

Expand Down Expand Up @@ -100,6 +103,9 @@ class GUIPostDrawing {
/// @brief elements under cursor
std::vector<const GUIGlObject*> myElementsUnderCursor;

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

private:
/// @brief set copy constructor private
GUIPostDrawing(const GUIPostDrawing&) = default;
Expand Down

0 comments on commit 98c866e

Please sign in to comment.