Skip to content

Commit

Permalink
Refactored GNEViewNet. Refs #13894
Browse files Browse the repository at this point in the history
  • Loading branch information
palvarezlopez committed Dec 19, 2023
1 parent b5c987a commit 42c3760
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 64 deletions.
130 changes: 71 additions & 59 deletions src/netedit/GNEViewNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1289,13 +1289,14 @@ GNEViewNet::getRelDataAttrs() const {

int
GNEViewNet::doPaintGL(int mode, const Boundary& bound) {
if (!myVisualizationSettings->drawForRectangleSelection && myVisualizationSettings->forceDrawForRectangleSelection) {
// first check if force drawing for rectangle selection
if (myVisualizationSettings->forceDrawForRectangleSelection) {
myVisualizationSettings->drawForRectangleSelection = true;
}
// set lefthand and laneIcons
myVisualizationSettings->lefthand = OptionsCont::getOptions().getBool("lefthand");
myVisualizationSettings->disableLaneIcons = OptionsCont::getOptions().getBool("disable-laneIcons");

// set render modes
glRenderMode(mode);
glMatrixMode(GL_MODELVIEW);
GLHelper::pushMatrix();
Expand All @@ -1304,50 +1305,18 @@ GNEViewNet::doPaintGL(int mode, const Boundary& bound) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_DEPTH_TEST);

// visualize rectangular selection
mySelectingArea.drawRectangleSelection(myVisualizationSettings->colorSettings.selectionColor);

// compute lane width
double lw = m2p(SUMO_const_laneWidth);
// draw decals (if not in grabbing mode)
// draw certain elements only if we aren't in rectangle selection mode
if (!myVisualizationSettings->drawForRectangleSelection) {
// draw decals
drawDecals();
// depending of the visualizationSettings, enable or disable check box show grid
if (myVisualizationSettings->showGrid) {
// change show grid
if (!myNetworkViewOptions.menuCheckToggleGrid->amChecked() ||
!myDemandViewOptions.menuCheckToggleGrid->amChecked()) {
// change to true
myNetworkViewOptions.menuCheckToggleGrid->setChecked(true);
myDemandViewOptions.menuCheckToggleGrid->setChecked(true);
// update show grid buttons
myNetworkViewOptions.menuCheckToggleGrid->update();
myNetworkViewOptions.menuCheckToggleGrid->update();
}
// draw grid only in network and demand mode
if (myEditModes.isCurrentSupermodeNetwork() || myEditModes.isCurrentSupermodeDemand()) {
paintGLGrid();
}
} else {
// change show grid
if (myNetworkViewOptions.menuCheckToggleGrid->amChecked() ||
myDemandViewOptions.menuCheckToggleGrid->amChecked()) {
// change to false
myNetworkViewOptions.menuCheckToggleGrid->setChecked(false);
myDemandViewOptions.menuCheckToggleGrid->setChecked(false);
// update show grid buttons
myNetworkViewOptions.menuCheckToggleGrid->update();
myNetworkViewOptions.menuCheckToggleGrid->update();
}
}
// draw grid (and update grid button)
drawGrid();
// update show connections
myNetworkViewOptions.menuCheckShowConnections->setChecked(myVisualizationSettings->showLane2Lane);
}
// draw temporal junction
drawTemporalJunction();
// draw temporal elements
if (!myVisualizationSettings->drawForRectangleSelection) {
// draw temporal junction
drawTemporalJunction();
// draw temporal drawing shape
drawTemporalDrawingShape();
// draw testing elements
Expand Down Expand Up @@ -1380,22 +1349,12 @@ GNEViewNet::doPaintGL(int mode, const Boundary& bound) {
}
// clear pathDraw
myNet->getPathManager()->getPathDraw()->clearPathDraw();
// draw elements
glLineWidth(1);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
const float minB[2] = { (float)bound.xmin(), (float)bound.ymin() };
const float maxB[2] = { (float)bound.xmax(), (float)bound.ymax() };
myVisualizationSettings->scale = lw;
glEnable(GL_POLYGON_OFFSET_FILL);
glEnable(GL_POLYGON_OFFSET_LINE);
// clear post drawing elements
gPostDrawing.clearElements();
// obtain objects included in minB and maxB
int hits2 = myGrid->Search(minB, maxB, *myVisualizationSettings);
// fill objects under cursor
// draw all GL elements
int hits = drawGLElements(bound);
// after draw elements, update objects under cursor
myObjectsUnderCursor.updateObjectUnderCursor();
// begin post drawing
myPostDrawing = true;
myVisualizationSettings->postDrawing = true;
// force draw inspected and front elements (due parent/child lines)
if (!myVisualizationSettings->drawForRectangleSelection) {
// iterate over all inspected ACs
Expand Down Expand Up @@ -1443,8 +1402,8 @@ GNEViewNet::doPaintGL(int mode, const Boundary& bound) {
// execute post drawing tasks
gPostDrawing.executePostDrawingTasks();
// end post drawing
myPostDrawing = false;
return hits2;
myVisualizationSettings->postDrawing = false;
return hits;
}


Expand Down Expand Up @@ -2007,7 +1966,7 @@ GNEViewNet::checkDrawOverContour(const GUIGlObject* GLObject) const {
return false;
}
// check if we're in post drawing
if (myPostDrawing) {
if (myVisualizationSettings->postDrawing) {
// in post-drawing, draw always
return true;
} else {
Expand Down Expand Up @@ -2037,7 +1996,7 @@ GNEViewNet::checkDrawDeleteContour(const GUIGlObject* GLObject, const bool isSel
return false;
}
// check if we're in post drawing
if (myPostDrawing) {
if (myVisualizationSettings->postDrawing) {
// in post-drawing, draw always
return true;
} else {
Expand Down Expand Up @@ -2067,7 +2026,7 @@ GNEViewNet::checkDrawSelectContour(const GUIGlObject* GLObject, const bool isSel
return false;
}
// check if we're in post drawing
if (myPostDrawing) {
if (myVisualizationSettings->postDrawing) {
// in post-drawing, draw always
return true;
} else {
Expand Down Expand Up @@ -3371,6 +3330,59 @@ GNEViewNet::updateCursor() {
}


int
GNEViewNet::drawGLElements(const Boundary& bound) const {
// set default scale
myVisualizationSettings->scale = m2p(SUMO_const_laneWidth);
// calculate boundary extremes
const float minB[2] = { (float)bound.xmin(), (float)bound.ymin() };
const float maxB[2] = { (float)bound.xmax(), (float)bound.ymax() };
// reset gl line to 2
glLineWidth(1);
// set drawing modes
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_POLYGON_OFFSET_FILL);
glEnable(GL_POLYGON_OFFSET_LINE);
// clear post drawing elements
gPostDrawing.clearElements();
// draw all elements between minB and maxB, obtain objects included in minB and maxB
return myGrid->Search(minB, maxB, *myVisualizationSettings);
}


void
GNEViewNet::drawGrid() const {
// depending of the visualizationSettings, enable or disable check box show grid
if (myVisualizationSettings->showGrid) {
// change show grid
if (!myNetworkViewOptions.menuCheckToggleGrid->amChecked() ||
!myDemandViewOptions.menuCheckToggleGrid->amChecked()) {
// change to true
myNetworkViewOptions.menuCheckToggleGrid->setChecked(true);
myDemandViewOptions.menuCheckToggleGrid->setChecked(true);
// update show grid buttons
myNetworkViewOptions.menuCheckToggleGrid->update();
myNetworkViewOptions.menuCheckToggleGrid->update();
}
// draw grid only in network and demand mode
if (myEditModes.isCurrentSupermodeNetwork() || myEditModes.isCurrentSupermodeDemand()) {
paintGLGrid();
}
} else {
// change show grid
if (myNetworkViewOptions.menuCheckToggleGrid->amChecked() ||
myDemandViewOptions.menuCheckToggleGrid->amChecked()) {
// change to false
myNetworkViewOptions.menuCheckToggleGrid->setChecked(false);
myDemandViewOptions.menuCheckToggleGrid->setChecked(false);
// update show grid buttons
myNetworkViewOptions.menuCheckToggleGrid->update();
myNetworkViewOptions.menuCheckToggleGrid->update();
}
}
}


long
GNEViewNet::onCmdResetEdgeEndPoints(FXObject*, FXSelector, void*) {
// Obtain junction under mouse
Expand Down
9 changes: 6 additions & 3 deletions src/netedit/GNEViewNet.h
Original file line number Diff line number Diff line change
Expand Up @@ -718,9 +718,6 @@ class GNEViewNet : public GUISUMOAbstractView {
/// @brief last clicked position
Position myLastClickedPosition = Position::INVALID;

/// @brief flag for post-drawing (used for dotted contours)
bool myPostDrawing = false;

/// @brief flag for mark if during this frame a popup was created (needed to avoid problems in linux with CursorDialogs)
bool myCreatedPopup = false;

Expand Down Expand Up @@ -787,6 +784,12 @@ class GNEViewNet : public GUISUMOAbstractView {
/// @brief draw functions
/// @{

/// @brief draw all gl elements of netedit
int drawGLElements(const Boundary& bound) const;

/// @brief draw grid and update grid button
void drawGrid() const;

/// @brief draw temporal polygon shape in Polygon Mode
void drawTemporalDrawingShape() const;

Expand Down
1 change: 1 addition & 0 deletions src/utils/gui/settings/GUIVisualizationSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ GUIVisualizationSettings::GUIVisualizationSettings(const std::string& _name, boo
selectorFrameScale(1.),
drawForRectangleSelection(false),
forceDrawForRectangleSelection(false),
postDrawing(false),
disableDottedContours(false),
geometryIndices(false, 50, RGBColor(255, 0, 128, 255)),
secondaryShape(false),
Expand Down
3 changes: 3 additions & 0 deletions src/utils/gui/settings/GUIVisualizationSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,9 @@ class GUIVisualizationSettings {
/// @brief flag to force draw for rectangle selection (see drawForRectangleSelection)
bool forceDrawForRectangleSelection;

/// @brief post drawing (used for draw dotted contours of certain elements in netedit)
bool postDrawing;

/// @brief flag for disable dotted contours in netedit
bool disableDottedContours;

Expand Down
2 changes: 1 addition & 1 deletion src/utils/gui/windows/GUISUMOAbstractView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ GUISUMOAbstractView::showToolTipFor(const GUIGlID idToolTip) {


void
GUISUMOAbstractView::paintGLGrid() {
GUISUMOAbstractView::paintGLGrid() const {
// obtain minimum grid
const double minimumSizeGrid = (myVisualizationSettings->gridXSize < myVisualizationSettings->gridYSize) ? myVisualizationSettings->gridXSize : myVisualizationSettings->gridYSize;
// Check if the distance is enough to draw grid
Expand Down
2 changes: 1 addition & 1 deletion src/utils/gui/windows/GUISUMOAbstractView.h
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ class GUISUMOAbstractView : public FXGLCanvas {
virtual void doInit();

/// @brief paints a grid
void paintGLGrid();
void paintGLGrid() const;

/// @brief Draws a line with ticks, and the length information.
void displayLegend();
Expand Down

0 comments on commit 42c3760

Please sign in to comment.