Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2026 German Aerospace Center (DLR) and others.
4 : // This program and the accompanying materials are made available under the
5 : // terms of the Eclipse Public License 2.0 which is available at
6 : // https://www.eclipse.org/legal/epl-2.0/
7 : // This Source Code may also be made available under the following Secondary
8 : // Licenses when the conditions for such availability set forth in the Eclipse
9 : // Public License 2.0 are satisfied: GNU General Public License, version 2
10 : // or later which is available at
11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 : /****************************************************************************/
14 : /// @file GUISUMOAbstractView.cpp
15 : /// @author Daniel Krajzewicz
16 : /// @author Jakob Erdmann
17 : /// @author Michael Behrisch
18 : /// @author Laura Bieker
19 : /// @author Andreas Gaubatz
20 : /// @date Sept 2002
21 : ///
22 : // The base class for a view
23 : /****************************************************************************/
24 : #include <config.h>
25 :
26 : #include <iostream>
27 : #include <utility>
28 : #include <cmath>
29 : #include <cassert>
30 : #include <limits>
31 : #include <fxkeys.h>
32 : #ifdef HAVE_GL2PS
33 : #include <gl2ps.h>
34 : #endif
35 : #include <foreign/fontstash/fontstash.h>
36 : #include <utils/common/MsgHandler.h>
37 : #include <utils/common/RGBColor.h>
38 : #include <utils/common/StringUtils.h>
39 : #include <utils/common/SysUtils.h>
40 : #include <utils/common/ToString.h>
41 : #include <utils/foxtools/MFXCheckableButton.h>
42 : #include <utils/foxtools/MFXImageHelper.h>
43 : #include <utils/foxtools/MFXSingleEventThread.h>
44 : #include <utils/foxtools/MFXStaticToolTip.h>
45 : #include <utils/geom/GeoConvHelper.h>
46 : #include <utils/geom/GeomHelper.h>
47 : #include <utils/gui/cursors/GUICursorSubSys.h>
48 : #include <utils/gui/div/GLHelper.h>
49 : #include <utils/gui/div/GUIDesigns.h>
50 : #include <utils/gui/div/GUIGlobalSelection.h>
51 : #include <utils/gui/globjects/GLIncludes.h>
52 : #include <utils/gui/globjects/GUICursorDialog.h>
53 : #include <utils/gui/globjects/GUIGlObject.h>
54 : #include <utils/gui/globjects/GUIGLObjectPopupMenu.h>
55 : #include <utils/gui/globjects/GUIGlObjectStorage.h>
56 : #include <utils/gui/globjects/GUIPointOfInterest.h>
57 : #include <utils/gui/globjects/GUIPolygon.h>
58 : #include <utils/gui/images/GUITexturesHelper.h>
59 : #include <utils/gui/settings/GUICompleteSchemeStorage.h>
60 : #include <utils/gui/settings/GUIVisualizationSettings.h>
61 : #include <utils/gui/windows/GUIAppEnum.h>
62 : #include <utils/gui/windows/GUIDialog_ViewSettings.h>
63 : #include <utils/options/OptionsCont.h>
64 : #include <utils/shapes/PointOfInterest.h>
65 :
66 : #include <unordered_set>
67 :
68 : #include "GUISUMOAbstractView.h"
69 : #include "GUIMainWindow.h"
70 : #include "GUIGlChildWindow.h"
71 : #include "GUIDanielPerspectiveChanger.h"
72 : #include "GUIDialog_EditViewport.h"
73 :
74 : #ifdef HAVE_GDAL
75 : #ifdef _MSC_VER
76 : #pragma warning(push)
77 : #pragma warning(disable: 4435 5219 5220)
78 : #endif
79 : #if __GNUC__ > 3
80 : #pragma GCC diagnostic push
81 : #pragma GCC diagnostic ignored "-Wpedantic"
82 : #endif
83 : #include <gdal_priv.h>
84 : #if __GNUC__ > 3
85 : #pragma GCC diagnostic pop
86 : #endif
87 : #ifdef _MSC_VER
88 : #pragma warning(pop)
89 : #endif
90 : #endif
91 :
92 : // ===========================================================================
93 : // debug constants
94 : // ===========================================================================
95 : //#define DEBUG_SNAPSHOT
96 :
97 : // ===========================================================================
98 : // static members
99 : // ===========================================================================
100 :
101 : const double GUISUMOAbstractView::SENSITIVITY = 0.1; // meters
102 :
103 : // ===========================================================================
104 : // FOX callback mapping
105 : // ===========================================================================
106 :
107 : FXDEFMAP(GUISUMOAbstractView) GUISUMOAbstractViewMap[] = {
108 : FXMAPFUNC(SEL_CONFIGURE, 0, GUISUMOAbstractView::onConfigure),
109 : FXMAPFUNC(SEL_PAINT, 0, GUISUMOAbstractView::onPaint),
110 : FXMAPFUNC(SEL_LEFTBUTTONPRESS, 0, GUISUMOAbstractView::onLeftBtnPress),
111 : FXMAPFUNC(SEL_LEFTBUTTONRELEASE, 0, GUISUMOAbstractView::onLeftBtnRelease),
112 : FXMAPFUNC(SEL_MIDDLEBUTTONPRESS, 0, GUISUMOAbstractView::onMiddleBtnPress),
113 : FXMAPFUNC(SEL_MIDDLEBUTTONRELEASE, 0, GUISUMOAbstractView::onMiddleBtnRelease),
114 : FXMAPFUNC(SEL_RIGHTBUTTONPRESS, 0, GUISUMOAbstractView::onRightBtnPress),
115 : FXMAPFUNC(SEL_RIGHTBUTTONRELEASE, 0, GUISUMOAbstractView::onRightBtnRelease),
116 : FXMAPFUNC(SEL_DOUBLECLICKED, 0, GUISUMOAbstractView::onDoubleClicked),
117 : FXMAPFUNC(SEL_MOUSEWHEEL, 0, GUISUMOAbstractView::onMouseWheel),
118 : FXMAPFUNC(SEL_MOTION, 0, GUISUMOAbstractView::onMouseMove),
119 : FXMAPFUNC(SEL_LEAVE, 0, GUISUMOAbstractView::onMouseLeft),
120 : FXMAPFUNC(SEL_KEYPRESS, 0, GUISUMOAbstractView::onKeyPress),
121 : FXMAPFUNC(SEL_KEYRELEASE, 0, GUISUMOAbstractView::onKeyRelease),
122 : FXMAPFUNC(SEL_COMMAND, MID_CLOSE_LANE, GUISUMOAbstractView::onCmdCloseLane),
123 : FXMAPFUNC(SEL_COMMAND, MID_CLOSE_EDGE, GUISUMOAbstractView::onCmdCloseEdge),
124 : FXMAPFUNC(SEL_COMMAND, MID_ADD_REROUTER, GUISUMOAbstractView::onCmdAddRerouter),
125 : FXMAPFUNC(SEL_COMMAND, MID_REACHABILITY, GUISUMOAbstractView::onCmdShowReachability),
126 : FXMAPFUNC(SEL_COMMAND, MID_REACHABILITY, GUISUMOAbstractView::onCmdShowReachability),
127 : FXMAPFUNC(SEL_CHANGED, MID_SIMPLE_VIEW_COLORCHANGE, GUISUMOAbstractView::onVisualizationChange),
128 : };
129 :
130 2270252 : FXIMPLEMENT_ABSTRACT(GUISUMOAbstractView, FXGLCanvas, GUISUMOAbstractViewMap, ARRAYNUMBER(GUISUMOAbstractViewMap))
131 :
132 : // ===========================================================================
133 : // member method definitions
134 : // ===========================================================================
135 :
136 8535 : GUISUMOAbstractView::GUISUMOAbstractView(FXComposite* p, GUIMainWindow& app, GUIGlChildWindow* parent, const SUMORTree& grid, FXGLVisual* glVis, FXGLCanvas* share) :
137 : FXGLCanvas(p, glVis, share, p, MID_GLCANVAS, LAYOUT_SIDE_TOP | LAYOUT_FILL_X | LAYOUT_FILL_Y, 0, 0, 0, 0),
138 8535 : myApp(&app),
139 8535 : myGlChildWindowParent(parent),
140 8535 : myGrid(&grid),
141 8535 : myMouseHotspotX(app.getDefaultCursor()->getHotX()),
142 8535 : myMouseHotspotY(app.getDefaultCursor()->getHotY()),
143 8535 : myWindowCursorPositionX(getWidth() / 2),
144 8535 : myWindowCursorPositionY(getHeight() / 2) {
145 8535 : setTarget(this);
146 8535 : enable();
147 8535 : flags |= FLAG_ENABLED;
148 8535 : myChanger = new GUIDanielPerspectiveChanger(*this, *myGrid);
149 8535 : myVisualizationSettings = &gSchemeStorage.getDefault();
150 8535 : myVisualizationSettings->gaming = myApp->isGaming();
151 8535 : gSchemeStorage.setViewport(this);
152 8535 : myDecals = gSchemeStorage.getDecals();
153 8535 : }
154 :
155 :
156 8508 : GUISUMOAbstractView::~GUISUMOAbstractView() {
157 8508 : gSchemeStorage.setDefault(myVisualizationSettings->name);
158 8508 : delete myPopup;
159 8508 : delete myChanger;
160 8508 : delete myGUIDialogEditViewport;
161 8508 : delete myGUIDialogViewSettings;
162 :
163 : // release GPU textures
164 8508 : if (makeCurrent()) {
165 8508 : for (auto& decal : myDecals) {
166 0 : if (decal.glID > 0) {
167 0 : queueTextureDelete(static_cast<unsigned int>(decal.glID));
168 : }
169 : }
170 8508 : processPendingTextureDeletes();
171 8508 : makeNonCurrent();
172 : }
173 :
174 : // remove all elements
175 8508 : for (auto& additional : myAdditionallyDrawn) {
176 0 : additional.first->removeActiveAddVisualisation(this, ~0);
177 : }
178 17016 : }
179 :
180 :
181 : bool
182 0 : GUISUMOAbstractView::isInEditMode() {
183 0 : return myInEditMode;
184 : }
185 :
186 :
187 : GUIPerspectiveChanger&
188 34053 : GUISUMOAbstractView::getChanger() const {
189 34053 : return *myChanger;
190 : }
191 :
192 :
193 : void
194 0 : GUISUMOAbstractView::updateToolTip() {
195 0 : if (myGlChildWindowParent->getGUIMainWindowParent()->getStaticTooltipView()->isStaticToolTipEnabled()) {
196 0 : update();
197 : }
198 0 : }
199 :
200 :
201 : Position
202 395 : GUISUMOAbstractView::getPositionInformation() const {
203 395 : return screenPos2NetPos(myWindowCursorPositionX, myWindowCursorPositionY);
204 : }
205 :
206 :
207 : Position
208 0 : GUISUMOAbstractView::snapToActiveGrid(const Position& pos, bool snapXY) const {
209 0 : Position result = pos;
210 0 : if (myVisualizationSettings->showGrid) {
211 0 : if (snapXY) {
212 0 : const double xRest = std::fmod(pos.x(), myVisualizationSettings->gridXSize) + (pos.x() < 0 ? myVisualizationSettings->gridXSize : 0);
213 0 : const double yRest = std::fmod(pos.y(), myVisualizationSettings->gridYSize) + (pos.y() < 0 ? myVisualizationSettings->gridYSize : 0);
214 0 : result.setx(pos.x() - xRest + (xRest < myVisualizationSettings->gridXSize * 0.5 ? 0 : myVisualizationSettings->gridXSize));
215 0 : result.sety(pos.y() - yRest + (yRest < myVisualizationSettings->gridYSize * 0.5 ? 0 : myVisualizationSettings->gridYSize));
216 : } else {
217 : // snapZToActiveGrid uses grid Y Size
218 0 : const double zRest = std::fmod(pos.z(), myVisualizationSettings->gridYSize) + (pos.z() < 0 ? myVisualizationSettings->gridYSize : 0);
219 0 : result.setz(pos.z() - zRest + (zRest < myVisualizationSettings->gridYSize * 0.5 ? 0 : myVisualizationSettings->gridYSize));
220 : }
221 : }
222 0 : return result;
223 : }
224 :
225 :
226 : Position
227 395 : GUISUMOAbstractView::screenPos2NetPos(int x, int y) const {
228 395 : Boundary bound = myChanger->getViewport();
229 395 : double xNet = bound.xmin() + bound.getWidth() * x / getWidth();
230 : // cursor origin is in the top-left corner
231 395 : double yNet = bound.ymin() + bound.getHeight() * (getHeight() - y) / getHeight();
232 : // rotate around the viewport center
233 395 : if (myChanger->getRotation() != 0) {
234 0 : return Position(xNet, yNet).rotateAround2D(-DEG2RAD(myChanger->getRotation()), bound.getCenter());
235 : } else {
236 : return Position(xNet, yNet);
237 : }
238 : }
239 :
240 :
241 : void
242 37 : GUISUMOAbstractView::addDecals(const std::vector<Decal>& decals) {
243 : // insert decals but avoid duplicates
244 37 : FXMutexLock lock(myDecalsLockMutex);
245 44 : for (const auto& d : decals) {
246 : bool found = false;
247 13 : for (const auto& existing : myDecals) {
248 6 : if (existing.filename == d.filename &&
249 0 : existing.centerX == d.centerX &&
250 6 : existing.centerY == d.centerY &&
251 0 : existing.centerZ == d.centerZ) {
252 : found = true;
253 : break;
254 : }
255 : }
256 7 : if (!found) {
257 7 : myDecals.push_back(d);
258 7 : myDecals.back().initialised = false;
259 : }
260 : }
261 37 : }
262 :
263 :
264 : void
265 395 : GUISUMOAbstractView::updatePositionInformationLabel() const {
266 395 : Position pos = getPositionInformation();
267 : // set cartesian position
268 395 : if (!myApp->getCartesianLabel()->hasFocus()) {
269 1185 : myApp->getCartesianLabel()->setText(("x:" + toString(pos.x()) + ", y:" + toString(pos.y())).c_str());
270 : }
271 : // set geo position
272 395 : if (!myApp->getGeoLabel()->hasFocus()) {
273 395 : GeoConvHelper::getFinal().cartesian2geo(pos);
274 395 : if (GeoConvHelper::getFinal().usingGeoProjection()) {
275 0 : if (!myApp->getGeoLabel()->isEnabled()) {
276 0 : myApp->getGeoLabel()->enable();
277 0 : myApp->getGeoLabel()->setEditable(true);
278 : }
279 0 : myApp->getGeoLabel()->setText(("lat:" + toString(pos.y(), gPrecisionGeo) + ", lon:" + toString(pos.x(), gPrecisionGeo)).c_str());
280 : } else {
281 395 : myApp->getGeoLabel()->setText(TL("(No projection defined)"));
282 395 : if (myApp->getGeoLabel()->isEnabled()) {
283 0 : myApp->getGeoLabel()->disable();
284 0 : myApp->getGeoLabel()->setEditable(false);
285 : }
286 : }
287 : }
288 : // if enabled, set test position
289 395 : if (myApp->getTestFrame()) {
290 0 : if (OptionsCont::getOptions().getBool("gui-testing")) {
291 0 : myApp->getTestFrame()->show();
292 : // adjust cursor position (24,25) to show exactly the same position as in function netedit.leftClick(match, X, Y)
293 0 : myApp->getTestLabel()->setText(("Test: x:" + toString(getWindowCursorPosition().x() - 24.0) + " y:" + toString(getWindowCursorPosition().y() - 25.0)).c_str());
294 : } else {
295 0 : myApp->getTestFrame()->hide();
296 : }
297 : }
298 395 : }
299 :
300 :
301 : int
302 0 : GUISUMOAbstractView::doPaintGL(int /*mode*/, const Boundary& /*boundary*/) {
303 0 : return 0;
304 : }
305 :
306 :
307 : void
308 8029 : GUISUMOAbstractView::doInit() {
309 8029 : }
310 :
311 :
312 : Boundary
313 3 : GUISUMOAbstractView::getVisibleBoundary() const {
314 3 : return myChanger->getViewport();
315 : }
316 :
317 :
318 : bool
319 18 : GUISUMOAbstractView::is3DView() const {
320 18 : return false;
321 : }
322 :
323 :
324 0 : void GUISUMOAbstractView::zoom2Pos(Position& /* camera */, Position& /* lookAt */, double /* zoom */) {
325 0 : }
326 :
327 :
328 : void
329 805072 : GUISUMOAbstractView::paintGL() {
330 : // reset debug counters
331 805072 : GLHelper::resetMatrixCounter();
332 805072 : GLHelper::resetVertexCounter();
333 805072 : if (getWidth() == 0 || getHeight() == 0) {
334 0 : return;
335 : }
336 :
337 : // process pending texture deletions
338 805072 : processPendingTextureDeletes();
339 :
340 805072 : const long start = SysUtils::getCurrentMillis();
341 :
342 805072 : if (getTrackedID() != GUIGlObject::INVALID_ID) {
343 395 : centerTo(getTrackedID(), false);
344 : }
345 : // draw
346 3220288 : glClearColor(
347 805072 : myVisualizationSettings->backgroundColor.red() / 255.f,
348 805072 : myVisualizationSettings->backgroundColor.green() / 255.f,
349 805072 : myVisualizationSettings->backgroundColor.blue() / 255.f,
350 805072 : myVisualizationSettings->backgroundColor.alpha() / 255.f);
351 805072 : glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
352 805072 : glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
353 :
354 805072 : if (myVisualizationSettings->dither) {
355 0 : glEnable(GL_DITHER);
356 : } else {
357 805072 : glDisable(GL_DITHER);
358 : }
359 805072 : glEnable(GL_BLEND);
360 805072 : glDisable(GL_LINE_SMOOTH);
361 :
362 805072 : Boundary bound = applyGLTransform();
363 805072 : doPaintGL(GL_RENDER, bound);
364 805072 : GLHelper::checkCounterMatrix();
365 805072 : GLHelper::checkCounterName();
366 805072 : displayLegends();
367 805072 : const long end = SysUtils::getCurrentMillis();
368 805072 : myFrameDrawTime = end - start;
369 805072 : if (myVisualizationSettings->fps) {
370 0 : drawFPS();
371 : }
372 : // check if show tooltip
373 805072 : if (myGlChildWindowParent->getGUIMainWindowParent()->getStaticTooltipView()->isStaticToolTipEnabled()) {
374 0 : showToolTipFor(getToolTipID());
375 : } else {
376 805072 : myGlChildWindowParent->getGUIMainWindowParent()->getStaticTooltipView()->hideStaticToolTip();
377 : }
378 805072 : swapBuffers();
379 : }
380 :
381 :
382 : long
383 0 : GUISUMOAbstractView::onCmdCloseLane(FXObject*, FXSelector, void*) {
384 0 : return 1;
385 : }
386 :
387 :
388 : long
389 0 : GUISUMOAbstractView::onCmdCloseEdge(FXObject*, FXSelector, void*) {
390 0 : return 1;
391 : }
392 :
393 :
394 : long
395 0 : GUISUMOAbstractView::onCmdAddRerouter(FXObject*, FXSelector, void*) {
396 0 : return 1;
397 : }
398 :
399 :
400 : long
401 0 : GUISUMOAbstractView::onCmdShowReachability(FXObject*, FXSelector, void*) {
402 0 : return 1;
403 : }
404 :
405 :
406 : long
407 0 : GUISUMOAbstractView::onVisualizationChange(FXObject*, FXSelector, void*) {
408 0 : return 1;
409 : }
410 :
411 :
412 : GUILane*
413 0 : GUISUMOAbstractView::getLaneUnderCursor() {
414 0 : return nullptr;
415 : }
416 :
417 :
418 : GUIGlID
419 0 : GUISUMOAbstractView::getToolTipID() {
420 0 : return getObjectUnderCursor();
421 : }
422 :
423 :
424 : GUIGlID
425 0 : GUISUMOAbstractView::getObjectUnderCursor(double sensitivity) {
426 0 : return getObjectAtPosition(getPositionInformation(), sensitivity);
427 : }
428 :
429 :
430 : std::vector<GUIGlID>
431 0 : GUISUMOAbstractView::getObjectsUnderCursor() {
432 0 : return getObjectsAtPosition(getPositionInformation(), SENSITIVITY);
433 : }
434 :
435 :
436 :
437 : std::vector<GUIGlObject*>
438 0 : GUISUMOAbstractView::getGUIGlObjectsUnderCursor() {
439 0 : return getGUIGlObjectsAtPosition(getPositionInformation(), SENSITIVITY);
440 : }
441 :
442 :
443 : std::vector<GUIGlObject*>
444 0 : GUISUMOAbstractView::getGUIGlObjectsUnderSnappedCursor() {
445 0 : return getGUIGlObjectsAtPosition(snapToActiveGrid(getPositionInformation()), SENSITIVITY);
446 : }
447 :
448 :
449 : GUIGlID
450 0 : GUISUMOAbstractView::getObjectAtPosition(Position pos, double sensitivity) {
451 : // calculate a boundary for the given position
452 0 : Boundary positionBoundary;
453 0 : positionBoundary.add(pos);
454 0 : positionBoundary.grow(sensitivity);
455 0 : const std::vector<GUIGlID> ids = getObjectsInBoundary(positionBoundary);
456 : // Interpret results
457 : int idMax = 0;
458 : double maxLayer = -std::numeric_limits<double>::max();
459 : double minDist = std::numeric_limits<double>::max();
460 : // iterate over obtained GUIGlIDs
461 0 : for (const auto& i : ids) {
462 : // obtain GUIGlObject
463 0 : GUIGlObject* o = GUIGlObjectStorage::gIDStorage.getObjectBlocking(i);
464 : // check that GUIGlObject exist
465 0 : if (o == nullptr) {
466 0 : continue;
467 : }
468 : // check that GUIGlObject isn't the network
469 0 : if (o->getGlID() == 0) {
470 0 : continue;
471 : }
472 : //std::cout << "point selection hit " << o->getMicrosimID() << "\n";
473 0 : double layer = o->getClickPriority();
474 0 : double dist = o->getCenter().distanceTo2D(pos);
475 : // check whether the current object is above a previous one
476 0 : if (layer > maxLayer) {
477 0 : idMax = i;
478 : maxLayer = layer;
479 : minDist = dist;
480 0 : } else if (layer == maxLayer && dist < minDist) {
481 0 : idMax = i;
482 : minDist = dist;
483 : }
484 : // unblock object
485 0 : GUIGlObjectStorage::gIDStorage.unblockObject(i);
486 : }
487 0 : return idMax;
488 0 : }
489 :
490 :
491 : std::vector<GUIGlID>
492 0 : GUISUMOAbstractView::getObjectsAtPosition(Position pos, double radius) {
493 : // declare result vector
494 : std::vector<GUIGlID> result;
495 : // calculate boundary
496 0 : Boundary selection;
497 0 : selection.add(pos);
498 0 : selection.grow(radius);
499 : // obtain GUIGlID of objects in boundary
500 0 : const std::vector<GUIGlID> ids = getObjectsInBoundary(selection);
501 : // iterate over obtained GUIGlIDs
502 0 : for (const auto& i : ids) {
503 : // obtain GUIGlObject
504 0 : GUIGlObject* o = GUIGlObjectStorage::gIDStorage.getObjectBlocking(i);
505 : // check that GUIGlObject exist
506 0 : if (o == nullptr) {
507 0 : continue;
508 : }
509 : // check that GUIGlObject isn't the network
510 0 : if (o->getGlID() == 0) {
511 0 : continue;
512 : }
513 : //std::cout << "point selection hit " << o->getMicrosimID() << "\n";
514 : GUIGlObjectType type = o->getType();
515 : // avoid network
516 0 : if (type != GLO_NETWORK) {
517 0 : result.push_back(i);
518 : }
519 : // unblock object
520 0 : GUIGlObjectStorage::gIDStorage.unblockObject(i);
521 : }
522 0 : return result;
523 0 : }
524 :
525 :
526 : std::vector<GUIGlObject*>
527 0 : GUISUMOAbstractView::getGUIGlObjectsAtPosition(Position pos, double radius) {
528 : // declare result vector
529 : std::vector<GUIGlObject*> result;
530 : // calculate boundary
531 0 : Boundary selection;
532 0 : selection.add(pos);
533 0 : selection.grow(radius);
534 : // obtain GUIGlID of objects in boundary
535 0 : const std::vector<GUIGlID> ids = getObjectsInBoundary(selection);
536 : // iterate over obtained GUIGlIDs
537 0 : for (const auto& i : ids) {
538 : // obtain GUIGlObject
539 0 : GUIGlObject* o = GUIGlObjectStorage::gIDStorage.getObjectBlocking(i);
540 : // check that GUIGlObject exist
541 0 : if (o == nullptr) {
542 0 : continue;
543 : }
544 : // check that GUIGlObject isn't the network
545 0 : if (o->getGlID() == 0) {
546 0 : continue;
547 : }
548 0 : result.push_back(o);
549 : // unblock object
550 0 : GUIGlObjectStorage::gIDStorage.unblockObject(i);
551 : }
552 0 : return result;
553 0 : }
554 :
555 :
556 : std::vector<GUIGlID>
557 0 : GUISUMOAbstractView::getObjectsInBoundary(Boundary bound) {
558 : const int NB_HITS_MAX = 1024 * 1024;
559 : // Prepare the selection mode
560 : static GUIGlID hits[NB_HITS_MAX];
561 : static GLint nb_hits = 0;
562 0 : glSelectBuffer(NB_HITS_MAX, hits);
563 0 : glInitNames();
564 :
565 0 : myVisualizationSettings->scale = m2p(SUMO_const_laneWidth);
566 0 : Boundary oldViewPort = myChanger->getViewport(false); // backup the actual viewPort
567 0 : myChanger->setViewport(bound);
568 0 : bound = applyGLTransform(false);
569 : // enable draw for selecting (to draw objects with less details)
570 0 : myVisualizationSettings->drawForRectangleSelection = true;
571 0 : int hits2 = doPaintGL(GL_SELECT, bound);
572 : // reset flags
573 0 : myVisualizationSettings->drawForRectangleSelection = false;
574 : // Get the results
575 0 : nb_hits = glRenderMode(GL_RENDER);
576 0 : if (nb_hits == -1) {
577 0 : myApp->setStatusBarText("Selection in boundary failed. Try to select fewer than " + toString(hits2) + " items");
578 : }
579 : std::vector<GUIGlID> result;
580 : GLuint numNames;
581 : GLuint* ptr = hits;
582 0 : for (int i = 0; i < nb_hits; ++i) {
583 0 : numNames = *ptr;
584 0 : ptr += 3;
585 0 : for (int j = 0; j < (int)numNames; j++) {
586 0 : result.push_back(*ptr);
587 0 : ptr++;
588 : }
589 : }
590 : // switch viewport back to normal
591 0 : myChanger->setViewport(oldViewPort);
592 0 : return result;
593 0 : }
594 :
595 :
596 : std::vector<GUIGlObject*>
597 0 : GUISUMOAbstractView::filterInternalLanes(const std::vector<GUIGlObject*>& objects) const {
598 : // count number of internal lanes
599 : size_t internalLanes = 0;
600 0 : for (const auto& object : objects) {
601 0 : if ((object->getType() == GLO_LANE) && (object->getMicrosimID().find(':') != std::string::npos)) {
602 0 : internalLanes++;
603 : }
604 : }
605 : // if all objects are internal lanes, return it all
606 0 : if (objects.size() == internalLanes || !myVisualizationSettings->drawJunctionShape) {
607 0 : return objects;
608 : }
609 : // in other case filter internal lanes
610 : std::vector<GUIGlObject*> filteredObjects;
611 0 : for (const auto& object : objects) {
612 0 : if ((object->getType() == GLO_LANE) && (object->getMicrosimID().find(':') != std::string::npos)) {
613 0 : continue;
614 : }
615 0 : filteredObjects.push_back(object);
616 : }
617 : return filteredObjects;
618 0 : }
619 :
620 :
621 : bool
622 0 : GUISUMOAbstractView::showToolTipFor(const GUIGlID idToolTip) {
623 0 : if (idToolTip != GUIGlObject::INVALID_ID) {
624 0 : const GUIGlObject* object = GUIGlObjectStorage::gIDStorage.getObjectBlocking(idToolTip);
625 0 : if (object != nullptr) {
626 0 : myGlChildWindowParent->getGUIMainWindowParent()->getStaticTooltipView()->showStaticToolTip(object->getFullName().c_str());
627 0 : return true;
628 : }
629 : }
630 : // nothing to show
631 0 : myGlChildWindowParent->getGUIMainWindowParent()->getStaticTooltipView()->hideStaticToolTip();
632 0 : return false;
633 : }
634 :
635 :
636 : void
637 0 : GUISUMOAbstractView::paintGLGrid() const {
638 : // obtain minimum grid
639 0 : const double minimumSizeGrid = (myVisualizationSettings->gridXSize < myVisualizationSettings->gridYSize) ? myVisualizationSettings->gridXSize : myVisualizationSettings->gridYSize;
640 : // Check if the distance is enough to draw grid
641 0 : if (myVisualizationSettings->scale * myVisualizationSettings->addSize.getExaggeration(*myVisualizationSettings, nullptr) >= (25 / minimumSizeGrid)) {
642 0 : glEnable(GL_DEPTH_TEST);
643 0 : glLineWidth(1);
644 : // get multiplication values (2 is the margin)
645 0 : const int multXmin = (int)(myChanger->getViewport().xmin() / myVisualizationSettings->gridXSize) - 2;
646 0 : const int multYmin = (int)(myChanger->getViewport().ymin() / myVisualizationSettings->gridYSize) - 2;
647 0 : const int multXmax = (int)(myChanger->getViewport().xmax() / myVisualizationSettings->gridXSize) + 2;
648 0 : const int multYmax = (int)(myChanger->getViewport().ymax() / myVisualizationSettings->gridYSize) + 2;
649 : // obtain references
650 0 : const double xmin = myVisualizationSettings->gridXSize * multXmin;
651 0 : const double ymin = myVisualizationSettings->gridYSize * multYmin;
652 0 : const double xmax = myVisualizationSettings->gridXSize * multXmax;
653 0 : const double ymax = myVisualizationSettings->gridYSize * multYmax;
654 : double xp = xmin;
655 : double yp = ymin;
656 : // move drawing matrix
657 0 : glTranslated(0, 0, .55);
658 0 : glColor3d(0.5, 0.5, 0.5);
659 : // draw horizontal lines
660 0 : glBegin(GL_LINES);
661 0 : while (yp <= ymax) {
662 0 : glVertex2d(xmin, yp);
663 0 : glVertex2d(xmax, yp);
664 0 : yp += myVisualizationSettings->gridYSize;
665 : }
666 : // draw vertical lines
667 0 : while (xp <= xmax) {
668 0 : glVertex2d(xp, ymin);
669 0 : glVertex2d(xp, ymax);
670 0 : xp += myVisualizationSettings->gridXSize;
671 : }
672 0 : glEnd();
673 0 : glTranslated(0, 0, -.55);
674 : }
675 0 : }
676 :
677 :
678 : void
679 805380 : GUISUMOAbstractView::displayLegend() {
680 : // compute the scale bar length
681 : int length = 1;
682 805380 : const std::string text("10000000000");
683 : int noDigits = 1;
684 805380 : int pixelSize = (int) m2p((double) length);
685 2609850 : while (pixelSize <= 20) {
686 1804470 : length *= 10;
687 1804470 : noDigits++;
688 1804470 : if (noDigits > (int)text.length()) {
689 : return;
690 : }
691 1804470 : pixelSize = (int) m2p((double) length);
692 : }
693 805380 : glLineWidth(1.0);
694 :
695 805380 : glMatrixMode(GL_PROJECTION);
696 805380 : GLHelper::pushMatrix();
697 805380 : glLoadIdentity();
698 805380 : glMatrixMode(GL_MODELVIEW);
699 805380 : GLHelper::pushMatrix();
700 805380 : glLoadIdentity();
701 :
702 : // draw the scale bar
703 : const double z = -1;
704 805380 : glDisable(GL_TEXTURE_2D);
705 805380 : glDisable(GL_ALPHA_TEST);
706 805380 : glDisable(GL_BLEND);
707 805380 : glEnable(GL_DEPTH_TEST);
708 805380 : GLHelper::pushMatrix();
709 805380 : glTranslated(0, 0, z);
710 :
711 805380 : double len = (double) pixelSize / (double)(getWidth() - 1) * (double) 2.0;
712 805380 : glColor3d(0, 0, 0);
713 805380 : double o = double(15) / double(getHeight());
714 805380 : double o2 = o + o;
715 805380 : double oo = double(5) / double(getHeight());
716 805380 : glBegin(GL_LINES);
717 : // vertical
718 805380 : glVertex2d(-.98, -1. + o);
719 805380 : glVertex2d(-.98 + len, -1. + o);
720 : // tick at begin
721 805380 : glVertex2d(-.98, -1. + o);
722 805380 : glVertex2d(-.98, -1. + o2);
723 : // tick at end
724 805380 : glVertex2d(-.98 + len, -1. + o);
725 805380 : glVertex2d(-.98 + len, -1. + o2);
726 805380 : glEnd();
727 805380 : GLHelper::popMatrix();
728 :
729 805380 : const double fontHeight = 0.1 * 300. / getHeight();
730 805380 : const double fontWidth = 0.1 * 300. / getWidth();
731 : // draw 0
732 805380 : GLHelper::drawText("0", Position(-.99, -0.99 + o2 + oo), z, fontHeight, RGBColor::BLACK, 0, FONS_ALIGN_LEFT, fontWidth);
733 :
734 : // draw current scale
735 1610760 : GLHelper::drawText((text.substr(0, noDigits) + "m").c_str(), Position(-.99 + len, -0.99 + o2 + oo), z, fontHeight, RGBColor::BLACK, 0, FONS_ALIGN_LEFT, fontWidth);
736 :
737 : // restore matrices
738 805380 : glMatrixMode(GL_PROJECTION);
739 805380 : GLHelper::popMatrix();
740 805380 : glMatrixMode(GL_MODELVIEW);
741 805380 : GLHelper::popMatrix();
742 : }
743 :
744 : void
745 805380 : GUISUMOAbstractView::displayLegends() {
746 805380 : if (myVisualizationSettings->showSizeLegend) {
747 805380 : displayLegend();
748 : }
749 805380 : std::string key = "";
750 805380 : if (myVisualizationSettings->showColorLegend) {
751 0 : auto const& scheme = myVisualizationSettings->getLaneEdgeScheme();
752 0 : if (scheme.getName() == GUIVisualizationSettings::SCHEME_NAME_EDGEDATA_NUMERICAL) {
753 0 : key = myVisualizationSettings->edgeData;
754 0 : } else if (scheme.getName() == GUIVisualizationSettings::SCHEME_NAME_EDGE_PARAM_NUMERICAL) {
755 0 : key = myVisualizationSettings->edgeParam;
756 0 : } else if (scheme.getName() == GUIVisualizationSettings::SCHEME_NAME_LANE_PARAM_NUMERICAL) {
757 0 : key = myVisualizationSettings->laneParam;
758 : }
759 0 : displayColorLegend(scheme, false, key);
760 : }
761 805380 : if (myVisualizationSettings->showVehicleColorLegend) {
762 : auto const& scheme = myVisualizationSettings->vehicleColorer.getScheme();
763 0 : if (scheme.getName() == GUIVisualizationSettings::SCHEME_NAME_PARAM_NUMERICAL) {
764 0 : key = myVisualizationSettings->vehicleParam;
765 : }
766 0 : displayColorLegend(myVisualizationSettings->vehicleColorer.getScheme(), true, key);
767 : }
768 805380 : }
769 :
770 : void
771 0 : GUISUMOAbstractView::displayColorLegend(const GUIColorScheme& scheme, bool leftSide, const std::string& key) {
772 : // compute the scale bar length
773 0 : glLineWidth(1.0);
774 0 : glMatrixMode(GL_PROJECTION);
775 0 : GLHelper::pushMatrix();
776 0 : glLoadIdentity();
777 0 : glMatrixMode(GL_MODELVIEW);
778 0 : GLHelper::pushMatrix();
779 0 : glLoadIdentity();
780 :
781 : const double z = -1;
782 0 : glEnable(GL_DEPTH_TEST);
783 0 : glEnable(GL_BLEND);
784 0 : GLHelper::pushMatrix();
785 0 : glTranslated(0, 0, z);
786 :
787 : const bool fixed = scheme.isFixed();
788 0 : const int numColors = (int)scheme.getColors().size();
789 :
790 : // vertical
791 : double right = 0.98;
792 : double left = 0.95;
793 : double textX = left - 0.01;
794 : double textDir = 1;
795 : FONSalign textAlign = FONS_ALIGN_RIGHT;
796 : const double top = -0.7;
797 : const double bot = 0.9;
798 0 : const double dy = (top - bot) / numColors;
799 0 : const double bot2 = fixed ? bot : bot + dy / 2;
800 : // legend placement
801 0 : if (leftSide) {
802 : right = -right;
803 : left = -left;
804 : std::swap(right, left);
805 : textX = right + 0.01;
806 : textDir *= -1;
807 : textAlign = FONS_ALIGN_LEFT;
808 : }
809 : // draw black boundary around legend colors
810 0 : glColor3d(0, 0, 0);
811 0 : glBegin(GL_LINES);
812 0 : glVertex2d(right, top);
813 0 : glVertex2d(right, bot2);
814 0 : glVertex2d(left, bot2);
815 0 : glVertex2d(left, top);
816 0 : glVertex2d(right, top);
817 0 : glVertex2d(left, top);
818 0 : glVertex2d(right, bot2);
819 0 : glVertex2d(left, bot2);
820 0 : glEnd();
821 :
822 0 : const double fontHeight = 0.20 * 300. / getHeight();
823 0 : const double fontWidth = 0.20 * 300. / getWidth();
824 :
825 0 : const int fadeSteps = fixed ? 1 : 10;
826 0 : double colorStep = dy / fadeSteps;
827 0 : for (int i = 0; i < numColors; i++) {
828 0 : RGBColor col = scheme.getColors()[i];
829 0 : const double topi = top - i * dy;
830 : //const double boti = top - (i + 1) * dy;
831 : //std::cout << " col=" << scheme.getColors()[i] << " i=" << i << " topi=" << topi << " boti=" << boti << "\n";
832 0 : if (i + 1 < numColors) {
833 : // fade
834 0 : RGBColor col2 = scheme.getColors()[i + 1];
835 0 : double thresh2 = scheme.getThresholds()[i + 1];
836 0 : if (!fixed && thresh2 == GUIVisualizationSettings::MISSING_DATA) {
837 : // draw scale end before missing data
838 0 : GLHelper::setColor(col);
839 0 : glBegin(GL_QUADS);
840 0 : glVertex2d(left, topi);
841 0 : glVertex2d(right, topi);
842 0 : glVertex2d(right, topi - 5 * colorStep);
843 0 : glVertex2d(left, topi - 5 * colorStep);
844 0 : glEnd();
845 0 : glColor3d(0, 0, 0);
846 0 : glBegin(GL_LINES);
847 0 : glVertex2d(right, topi - 10 * colorStep);
848 0 : glVertex2d(left, topi - 10 * colorStep);
849 0 : glEnd();
850 0 : glBegin(GL_LINES);
851 0 : glVertex2d(right, topi - 5 * colorStep);
852 0 : glVertex2d(left, topi - 5 * colorStep);
853 0 : glEnd();
854 : } else {
855 : // fade colors
856 0 : for (double j = 0.0; j < fadeSteps; j++) {
857 0 : GLHelper::setColor(RGBColor::interpolate(col, col2, j / fadeSteps));
858 0 : glBegin(GL_QUADS);
859 0 : glVertex2d(left, topi - j * colorStep);
860 0 : glVertex2d(right, topi - j * colorStep);
861 0 : glVertex2d(right, topi - (j + 1) * colorStep);
862 0 : glVertex2d(left, topi - (j + 1) * colorStep);
863 0 : glEnd();
864 : }
865 : }
866 : } else {
867 0 : GLHelper::setColor(col);
868 0 : glBegin(GL_QUADS);
869 0 : glVertex2d(left, topi);
870 0 : glVertex2d(right, topi);
871 0 : glVertex2d(right, bot2);
872 0 : glVertex2d(left, bot2);
873 0 : glEnd();
874 : }
875 :
876 0 : const double threshold = scheme.getThresholds()[i];
877 : std::string name = scheme.getNames()[i];
878 0 : std::string text = fixed || threshold == GUIVisualizationSettings::MISSING_DATA ? name : toString(threshold);
879 :
880 : const double bgShift = 0.0;
881 : const double textShift = 0.01;
882 : const double textXShift = -0.005;
883 :
884 0 : GLHelper::setColor(RGBColor::WHITE);
885 0 : glTranslated(0, 0, 0.1);
886 0 : glBegin(GL_QUADS);
887 0 : glVertex2d(textX, topi + fontHeight * bgShift);
888 0 : glVertex2d(textX - textDir * fontWidth * (double)text.size() / 2.1, topi + fontHeight * bgShift);
889 0 : glVertex2d(textX - textDir * fontWidth * (double)text.size() / 2.1, topi + fontHeight * (0.8 + bgShift));
890 0 : glVertex2d(textX, topi + fontHeight * (0.8 + bgShift));
891 0 : glEnd();
892 0 : glTranslated(0, 0, -0.1);
893 0 : GLHelper::drawText(text, Position(textX + textDir * textXShift, topi + textShift), 0, fontHeight, RGBColor::BLACK, 0, textAlign, fontWidth);
894 : }
895 : // draw scheme name
896 : std::string name = scheme.getName();
897 0 : if (name == GUIVisualizationSettings::SCHEME_NAME_EDGEDATA_NUMERICAL) {
898 0 : name = "edgeData (" + key + ")";
899 0 : } else if (name == GUIVisualizationSettings::SCHEME_NAME_EDGE_PARAM_NUMERICAL) {
900 0 : name = "edgeParam (" + key + ")";
901 0 : } else if (name == GUIVisualizationSettings::SCHEME_NAME_LANE_PARAM_NUMERICAL) {
902 0 : name = "laneParam (" + key + ")";
903 0 : } else if (name == GUIVisualizationSettings::SCHEME_NAME_PARAM_NUMERICAL) {
904 0 : name = "param (" + key + ")";
905 0 : } else if (name == GUIVisualizationSettings::SCHEME_NAME_DATA_ATTRIBUTE_NUMERICAL) {
906 0 : name = "attribute (" + key + ")";
907 0 : } else if (StringUtils::startsWith(name, "by ")) {
908 0 : name = name.substr(3);
909 : }
910 : const double topN = -0.8;
911 : const double bgShift = 0.0;
912 0 : GLHelper::setColor(RGBColor::WHITE);
913 0 : glTranslated(0, 0, 0.1);
914 0 : glBegin(GL_QUADS);
915 0 : glVertex2d(textX + textDir * 0.04, topN + fontHeight * bgShift - 0.01);
916 0 : glVertex2d(textX + textDir * 0.04 - textDir * fontWidth * (double)name.size() / 2.3, topN + fontHeight * bgShift - 0.01);
917 0 : glVertex2d(textX + textDir * 0.04 - textDir * fontWidth * (double)name.size() / 2.3, topN + fontHeight * (0.8 + bgShift));
918 0 : glVertex2d(textX + textDir * 0.04, topN + fontHeight * (0.8 + bgShift));
919 0 : glEnd();
920 0 : glTranslated(0, 0, -0.1);
921 0 : GLHelper::drawText(name, Position(textX + textDir * 0.04, topN), 0, fontHeight, RGBColor::BLACK, 0, textAlign, fontWidth);
922 :
923 0 : GLHelper::popMatrix();
924 : // restore matrices
925 0 : glMatrixMode(GL_PROJECTION);
926 0 : GLHelper::popMatrix();
927 0 : glMatrixMode(GL_MODELVIEW);
928 0 : GLHelper::popMatrix();
929 0 : }
930 :
931 :
932 : double
933 0 : GUISUMOAbstractView::getFPS() const {
934 0 : return 1000.0 / MAX2((long)1, myFrameDrawTime);
935 : }
936 :
937 :
938 : GUIGlChildWindow*
939 0 : GUISUMOAbstractView::getGUIGlChildWindow() {
940 0 : return myGlChildWindowParent;
941 : }
942 :
943 :
944 : void
945 0 : GUISUMOAbstractView::drawFPS() {
946 0 : glMatrixMode(GL_PROJECTION);
947 0 : GLHelper::pushMatrix();
948 0 : glLoadIdentity();
949 0 : glMatrixMode(GL_MODELVIEW);
950 0 : GLHelper::pushMatrix();
951 0 : glLoadIdentity();
952 0 : const double fontHeight = 0.2 * 300. / getHeight();
953 0 : const double fontWidth = 0.2 * 300. / getWidth();
954 0 : GLHelper::drawText(toString((int)getFPS()) + " FPS", Position(0.82, 0.88), -1, fontHeight, RGBColor::RED, 0, FONS_ALIGN_LEFT, fontWidth);
955 : #ifdef CHECK_ELEMENTCOUNTER
956 : GLHelper::drawText(toString(GLHelper::getMatrixCounter()) + " matrix", Position(0.82, 0.79), -1, fontHeight, RGBColor::RED, 0, FONS_ALIGN_LEFT, fontWidth);
957 : GLHelper::drawText(toString(GLHelper::getVertexCounter()) + " vertex", Position(0.82, 0.71), -1, fontHeight, RGBColor::RED, 0, FONS_ALIGN_LEFT, fontWidth);
958 : #endif
959 : // restore matrices
960 0 : glMatrixMode(GL_PROJECTION);
961 0 : GLHelper::popMatrix();
962 0 : glMatrixMode(GL_MODELVIEW);
963 0 : GLHelper::popMatrix();
964 0 : }
965 :
966 :
967 : double
968 3415230 : GUISUMOAbstractView::m2p(double meter) const {
969 3415230 : return meter * getWidth() / myChanger->getViewport().getWidth();
970 : }
971 :
972 :
973 : double
974 0 : GUISUMOAbstractView::p2m(double pixel) const {
975 0 : return pixel * myChanger->getViewport().getWidth() / getWidth();
976 : }
977 :
978 :
979 : void
980 8535 : GUISUMOAbstractView::recenterView() {
981 8535 : myChanger->setViewport(*myGrid);
982 8535 : }
983 :
984 :
985 : void
986 395 : GUISUMOAbstractView::centerTo(GUIGlID id, bool applyZoom, double zoomDist) {
987 395 : GUIGlObject* o = GUIGlObjectStorage::gIDStorage.getObjectBlocking(id);
988 395 : if (o != nullptr && dynamic_cast<GUIGlObject*>(o) != nullptr) {
989 395 : const Boundary& b = o->getCenteringBoundary();
990 395 : if (b.getCenter() != Position::INVALID) {
991 395 : if (applyZoom && zoomDist < 0) {
992 0 : myChanger->setViewport(b);
993 0 : update(); // only update when centering onto an object once
994 : } else {
995 : // called during tracking. update is triggered somewhere else
996 395 : myChanger->centerTo(b.getCenter(), zoomDist, applyZoom);
997 395 : updatePositionInformationLabel();
998 : }
999 : }
1000 : }
1001 395 : GUIGlObjectStorage::gIDStorage.unblockObject(id);
1002 395 : }
1003 :
1004 :
1005 : void
1006 0 : GUISUMOAbstractView::centerToPos(const Position& pos, bool applyZoom, double zoomDist) {
1007 : // called during tracking. update is triggered somewhere else
1008 0 : myChanger->centerTo(pos, zoomDist, applyZoom);
1009 0 : updatePositionInformationLabel();
1010 0 : }
1011 :
1012 :
1013 : void
1014 3 : GUISUMOAbstractView::centerTo(const Boundary& bound) {
1015 3 : myChanger->setViewport(bound);
1016 3 : update();
1017 3 : }
1018 :
1019 :
1020 : GUIMainWindow*
1021 0 : GUISUMOAbstractView::getMainWindow() const {
1022 0 : return myApp;
1023 : }
1024 :
1025 :
1026 : Position
1027 0 : GUISUMOAbstractView::getWindowCursorPosition() const {
1028 0 : return Position(myWindowCursorPositionX, myWindowCursorPositionY);
1029 : }
1030 :
1031 :
1032 : void
1033 0 : GUISUMOAbstractView::setWindowCursorPosition(FXint x, FXint y) {
1034 0 : myWindowCursorPositionX = x + myMouseHotspotX;
1035 0 : myWindowCursorPositionY = y + myMouseHotspotY;
1036 0 : }
1037 :
1038 :
1039 : FXbool
1040 886938 : GUISUMOAbstractView::makeCurrent() {
1041 886938 : FXbool ret = FXGLCanvas::makeCurrent();
1042 886938 : return ret;
1043 : }
1044 :
1045 :
1046 : long
1047 8029 : GUISUMOAbstractView::onConfigure(FXObject*, FXSelector, void*) {
1048 8029 : if (makeCurrent()) {
1049 8029 : glViewport(0, 0, getWidth() - 1, getHeight() - 1);
1050 32116 : glClearColor(
1051 8029 : myVisualizationSettings->backgroundColor.red() / 255.f,
1052 8029 : myVisualizationSettings->backgroundColor.green() / 255.f,
1053 8029 : myVisualizationSettings->backgroundColor.blue() / 255.f,
1054 8029 : myVisualizationSettings->backgroundColor.alpha() / 255.f);
1055 8029 : doInit();
1056 8029 : myAmInitialised = true;
1057 8029 : makeNonCurrent();
1058 8029 : checkSnapshots();
1059 : }
1060 8029 : return 1;
1061 : }
1062 :
1063 :
1064 : long
1065 813203 : GUISUMOAbstractView::onPaint(FXObject*, FXSelector, void*) {
1066 813203 : if (!isEnabled() || !myAmInitialised) {
1067 : return 1;
1068 : }
1069 805072 : if (makeCurrent()) {
1070 805072 : paintGL();
1071 805072 : makeNonCurrent();
1072 : }
1073 : // run tests
1074 805072 : myApp->handle(this, FXSEL(SEL_COMMAND, MID_RUNTESTS), nullptr);
1075 805072 : return 1;
1076 : }
1077 :
1078 :
1079 : GUIGLObjectPopupMenu*
1080 0 : GUISUMOAbstractView::getPopup() const {
1081 0 : return myPopup;
1082 : }
1083 :
1084 :
1085 : const Position&
1086 0 : GUISUMOAbstractView::getPopupPosition() const {
1087 0 : return myPopupPosition;
1088 : }
1089 :
1090 :
1091 : void
1092 0 : GUISUMOAbstractView::destroyPopup() {
1093 0 : if (myPopup != nullptr) {
1094 0 : myPopup->removePopupFromObject();
1095 0 : delete myPopup;
1096 : myPopupPosition.set(0, 0);
1097 0 : myPopup = nullptr;
1098 : myCurrentObjectsDialog.clear();
1099 : }
1100 0 : }
1101 :
1102 :
1103 : void
1104 0 : GUISUMOAbstractView::replacePopup(GUIGLObjectPopupMenu* popUp) {
1105 : // use the same position of old popUp
1106 0 : popUp->move(myPopup->getX(), myPopup->getY());
1107 : // delete and replace popup
1108 0 : myPopup->removePopupFromObject();
1109 0 : delete myPopup;
1110 0 : myPopup = popUp;
1111 : // create and show popUp
1112 0 : myPopup->create();
1113 0 : myPopup->show();
1114 0 : myChanger->onRightBtnRelease(nullptr);
1115 0 : setFocus();
1116 0 : }
1117 :
1118 :
1119 : long
1120 0 : GUISUMOAbstractView::onLeftBtnPress(FXObject*, FXSelector, void* ptr) {
1121 0 : destroyPopup();
1122 0 : setFocus();
1123 : FXEvent* e = (FXEvent*) ptr;
1124 : // check whether the selection-mode is activated
1125 0 : if ((e->state & CONTROLMASK) != 0) {
1126 : // toggle selection of object under cursor
1127 0 : if (makeCurrent()) {
1128 0 : int id = getObjectUnderCursor();
1129 0 : if (id != 0) {
1130 0 : gSelected.toggleSelection(id);
1131 : }
1132 0 : makeNonCurrent();
1133 0 : if (id != 0) {
1134 : // possibly, the selection-coloring is used,
1135 : // so we should update the screen again...
1136 0 : update();
1137 : }
1138 : }
1139 : }
1140 0 : if ((e->state & SHIFTMASK) != 0) {
1141 : // track vehicle or person under cursor
1142 0 : if (makeCurrent()) {
1143 0 : int id = getObjectUnderCursor();
1144 0 : if (id != 0) {
1145 0 : GUIGlObject* o = GUIGlObjectStorage::gIDStorage.getObjectBlocking(id);
1146 0 : if (o != nullptr) {
1147 0 : if (!myApp->isGaming() && (o->getType() == GLO_VEHICLE || o->getType() == GLO_PERSON)) {
1148 0 : startTrack(id);
1149 : }
1150 : }
1151 : }
1152 0 : makeNonCurrent();
1153 : }
1154 : }
1155 0 : myChanger->onLeftBtnPress(ptr);
1156 0 : grab();
1157 : // Check there are double click
1158 0 : if (e->click_count == 2) {
1159 0 : handle(this, FXSEL(SEL_DOUBLECLICKED, 0), ptr);
1160 : }
1161 0 : return 1;
1162 : }
1163 :
1164 :
1165 : long
1166 0 : GUISUMOAbstractView::onLeftBtnRelease(FXObject*, FXSelector, void* ptr) {
1167 0 : destroyPopup();
1168 0 : myChanger->onLeftBtnRelease(ptr);
1169 0 : if (myApp->isGaming()) {
1170 0 : onGamingClick(getPositionInformation());
1171 : }
1172 0 : ungrab();
1173 0 : return 1;
1174 : }
1175 :
1176 :
1177 : long
1178 0 : GUISUMOAbstractView::onMiddleBtnPress(FXObject*, FXSelector, void* ptr) {
1179 0 : destroyPopup();
1180 0 : setFocus();
1181 0 : if (!myApp->isGaming()) {
1182 0 : myChanger->onMiddleBtnPress(ptr);
1183 : }
1184 0 : grab();
1185 : // enable panning
1186 0 : myPanning = true;
1187 : // set cursors
1188 0 : setDefaultCursor(GUICursorSubSys::getCursor(GUICursor::MOVEVIEW));
1189 0 : setDragCursor(GUICursorSubSys::getCursor(GUICursor::MOVEVIEW));
1190 0 : return 1;
1191 : }
1192 :
1193 :
1194 : long
1195 0 : GUISUMOAbstractView::onMiddleBtnRelease(FXObject*, FXSelector, void* ptr) {
1196 0 : destroyPopup();
1197 0 : if (!myApp->isGaming()) {
1198 0 : myChanger->onMiddleBtnRelease(ptr);
1199 : }
1200 0 : ungrab();
1201 : // disable panning
1202 0 : myPanning = false;
1203 : // restore cursors
1204 0 : setDefaultCursor(GUICursorSubSys::getCursor(GUICursor::DEFAULT));
1205 0 : setDragCursor(GUICursorSubSys::getCursor(GUICursor::DEFAULT));
1206 0 : return 1;
1207 : }
1208 :
1209 :
1210 : long
1211 0 : GUISUMOAbstractView::onRightBtnPress(FXObject*, FXSelector, void* ptr) {
1212 0 : destroyPopup();
1213 0 : if (!myApp->isGaming()) {
1214 0 : myChanger->onRightBtnPress(ptr);
1215 : }
1216 0 : grab();
1217 0 : return 1;
1218 : }
1219 :
1220 :
1221 : long
1222 0 : GUISUMOAbstractView::onRightBtnRelease(FXObject* o, FXSelector sel, void* ptr) {
1223 0 : destroyPopup();
1224 0 : onMouseMove(o, sel, ptr);
1225 0 : if (!myChanger->onRightBtnRelease(ptr) && !myApp->isGaming()) {
1226 0 : openObjectDialogAtCursor((FXEvent*)ptr);
1227 : }
1228 0 : if (myApp->isGaming()) {
1229 0 : onGamingRightClick(getPositionInformation());
1230 : }
1231 0 : ungrab();
1232 0 : return 1;
1233 : }
1234 :
1235 :
1236 : long
1237 0 : GUISUMOAbstractView::onDoubleClicked(FXObject*, FXSelector, void*) {
1238 0 : return 1;
1239 : }
1240 :
1241 :
1242 : long
1243 0 : GUISUMOAbstractView::onMouseWheel(FXObject*, FXSelector, void* ptr) {
1244 0 : if (!myApp->isGaming()) {
1245 0 : myChanger->onMouseWheel(ptr);
1246 : // upddate viewport
1247 0 : if (myGUIDialogEditViewport != nullptr) {
1248 0 : myGUIDialogEditViewport->setValues(myChanger->getZoom(),
1249 0 : myChanger->getXPos(), myChanger->getYPos(),
1250 0 : myChanger->getRotation());
1251 : }
1252 0 : updatePositionInformationLabel();
1253 : }
1254 0 : return 1;
1255 : }
1256 :
1257 :
1258 : long
1259 0 : GUISUMOAbstractView::onMouseMove(FXObject*, FXSelector, void* ptr) {
1260 : // check if popup exist
1261 0 : if (myPopup) {
1262 : // check if handle front element
1263 0 : if (myPopupPosition == getPositionInformation()) {
1264 0 : myPopupPosition = Position::INVALID;
1265 0 : myPopup->handle(this, FXSEL(SEL_COMMAND, MID_CURSORDIALOG_FRONT), nullptr);
1266 0 : destroyPopup();
1267 0 : } else if (!myPopup->shown()) {
1268 0 : destroyPopup();
1269 : }
1270 : }
1271 0 : if (myPopup == nullptr) {
1272 0 : if (myGUIDialogEditViewport == nullptr || !myGUIDialogEditViewport->haveGrabbed()) {
1273 0 : myChanger->onMouseMove(ptr);
1274 : }
1275 0 : if (myGUIDialogEditViewport != nullptr) {
1276 0 : myGUIDialogEditViewport->setValues(myChanger->getZoom(),
1277 0 : myChanger->getXPos(), myChanger->getYPos(),
1278 0 : myChanger->getRotation());
1279 : }
1280 0 : updatePositionInformationLabel();
1281 : }
1282 0 : return 1;
1283 : }
1284 :
1285 :
1286 : long
1287 6 : GUISUMOAbstractView::onMouseLeft(FXObject*, FXSelector, void* /*data*/) {
1288 6 : return 1;
1289 : }
1290 :
1291 : std::vector<GUIGlObject*>
1292 0 : GUISUMOAbstractView::filterContextObjects(const std::vector<GUIGlObject*>& objects) {
1293 : // assume input is sorted with ComparatorClickPriority
1294 : std::vector<GUIGlObject*> result;
1295 0 : for (GUIGlObject* o : objects) {
1296 0 : if (o->getClickPriority() != GUIGlObject::INVALID_PRIORITY && (result.empty() || result.back() != o)) {
1297 0 : result.push_back(o);
1298 : }
1299 : }
1300 0 : return result;
1301 0 : }
1302 :
1303 :
1304 : void
1305 0 : GUISUMOAbstractView::openObjectDialogAtCursor(const FXEvent* ev) {
1306 : // release the mouse grab
1307 0 : ungrab();
1308 : // check if alt key is pressed
1309 0 : const bool altKeyPressed = ((ev->state & ALTMASK) != 0);
1310 : // check if SUMO is enabled, initialised and Make OpenGL context current
1311 0 : if (isEnabled() && myAmInitialised && makeCurrent()) {
1312 0 : auto objectsUnderCursor = getGUIGlObjectsUnderCursor();
1313 0 : if (objectsUnderCursor.empty()) {
1314 0 : myPopup = GUIGlObjectStorage::gIDStorage.getNetObject()->getPopUpMenu(*myApp, *this);
1315 : } else {
1316 0 : std::sort(objectsUnderCursor.begin(), objectsUnderCursor.end(), ComparatorClickPriority());
1317 0 : std::vector<GUIGlObject*> filtered = filterContextObjects(objectsUnderCursor);
1318 0 : if (filtered.size() > 1 && (altKeyPressed
1319 0 : || filtered[0]->getClickPriority() == filtered[1]->getClickPriority())) {
1320 : // open dialog for picking among objects (without duplicates)
1321 0 : myPopup = new GUICursorDialog(GUIGLObjectPopupMenu::PopupType::PROPERTIES, this, filtered);
1322 : } else {
1323 0 : myPopup = objectsUnderCursor.front()->getPopUpMenu(*myApp, *this);
1324 : }
1325 0 : }
1326 0 : openPopupDialog();
1327 0 : makeNonCurrent();
1328 0 : }
1329 0 : }
1330 :
1331 :
1332 : void
1333 0 : GUISUMOAbstractView::openObjectDialog(const std::vector<GUIGlObject*>& objects, const bool filter) {
1334 0 : if (objects.size() > 0) {
1335 : // create cursor popup dialog
1336 0 : if (objects.size() == 1) {
1337 0 : myCurrentObjectsDialog = objects;
1338 0 : } else if (filter) {
1339 : // declare filtered objects
1340 : std::vector<GUIGlObject*> filteredGLObjects;
1341 : // fill filtered objects
1342 0 : for (const auto& glObject : objects) {
1343 : // compare type with first element type
1344 0 : if (glObject->getType() == objects.front()->getType()) {
1345 0 : filteredGLObjects.push_back(glObject);
1346 : }
1347 : }
1348 0 : myCurrentObjectsDialog = filteredGLObjects;
1349 0 : } else {
1350 0 : myCurrentObjectsDialog = objects;
1351 : }
1352 0 : if (myCurrentObjectsDialog.size() > 1) {
1353 0 : myPopup = new GUICursorDialog(GUIGLObjectPopupMenu::PopupType::PROPERTIES, this, myCurrentObjectsDialog);
1354 : } else {
1355 0 : myPopup = myCurrentObjectsDialog.front()->getPopUpMenu(*myApp, *this);
1356 : }
1357 : // open popup dialog
1358 0 : openPopupDialog();
1359 : }
1360 0 : }
1361 :
1362 :
1363 : long
1364 0 : GUISUMOAbstractView::onKeyPress(FXObject* o, FXSelector sel, void* ptr) {
1365 : const FXEvent* e = (FXEvent*) ptr;
1366 : // check if process canvas or popup
1367 0 : if (myPopup != nullptr) {
1368 0 : return myPopup->onKeyPress(o, sel, ptr);
1369 : } else {
1370 0 : if (e->state & CONTROLMASK) {
1371 0 : if (e->code == FX::KEY_Page_Up) {
1372 0 : myVisualizationSettings->gridXSize *= 2;
1373 0 : myVisualizationSettings->gridYSize *= 2;
1374 0 : update();
1375 0 : return 1;
1376 0 : } else if (e->code == FX::KEY_Page_Down) {
1377 0 : myVisualizationSettings->gridXSize /= 2;
1378 0 : myVisualizationSettings->gridYSize /= 2;
1379 0 : update();
1380 0 : return 1;
1381 : }
1382 : }
1383 0 : FXGLCanvas::onKeyPress(o, sel, ptr);
1384 0 : return myChanger->onKeyPress(ptr);
1385 : }
1386 : }
1387 :
1388 :
1389 : long
1390 0 : GUISUMOAbstractView::onKeyRelease(FXObject* o, FXSelector sel, void* ptr) {
1391 : // check if process canvas or popup
1392 0 : if (myPopup != nullptr) {
1393 0 : return myPopup->onKeyRelease(o, sel, ptr);
1394 : } else {
1395 0 : FXGLCanvas::onKeyRelease(o, sel, ptr);
1396 0 : return myChanger->onKeyRelease(ptr);
1397 : }
1398 : }
1399 :
1400 : // ------------ Dealing with snapshots
1401 :
1402 : void
1403 308 : GUISUMOAbstractView::addSnapshot(SUMOTime time, const std::string& file, const int w, const int h) {
1404 : #ifdef DEBUG_SNAPSHOT
1405 : std::cout << "add snapshot time=" << time << " file=" << file << "\n";
1406 : #endif
1407 308 : FXMutexLock lock(mySnapshotsMutex);
1408 616 : mySnapshots[time].push_back(std::make_tuple(file, w, h));
1409 308 : }
1410 :
1411 :
1412 : std::string
1413 308 : GUISUMOAbstractView::makeSnapshot(const std::string& destFile, const int w, const int h) {
1414 308 : if (w >= 0) {
1415 3 : resize(w, h);
1416 3 : repaint();
1417 : }
1418 : std::string errorMessage;
1419 308 : FXString ext = FXPath::extension(destFile.c_str());
1420 308 : const bool useGL2PS = ext == "ps" || ext == "eps" || ext == "pdf" || ext == "svg" || ext == "tex" || ext == "pgf";
1421 : #ifdef HAVE_FFMPEG
1422 308 : const bool useVideo = destFile == "" || ext == "h264" || ext == "hevc" || ext == "mp4";
1423 : #endif
1424 308 : for (int i = 0; i < 10 && !makeCurrent(); ++i) {
1425 0 : MFXSingleEventThread::sleep(100);
1426 : }
1427 : // draw
1428 1232 : glClearColor(
1429 308 : myVisualizationSettings->backgroundColor.red() / 255.f,
1430 308 : myVisualizationSettings->backgroundColor.green() / 255.f,
1431 308 : myVisualizationSettings->backgroundColor.blue() / 255.f,
1432 308 : myVisualizationSettings->backgroundColor.alpha() / 255.f);
1433 308 : glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
1434 308 : glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
1435 :
1436 308 : if (myVisualizationSettings->dither) {
1437 0 : glEnable(GL_DITHER);
1438 : } else {
1439 308 : glDisable(GL_DITHER);
1440 : }
1441 308 : glEnable(GL_BLEND);
1442 308 : glDisable(GL_LINE_SMOOTH);
1443 :
1444 308 : applyGLTransform();
1445 :
1446 308 : if (useGL2PS) {
1447 : #ifdef HAVE_GL2PS
1448 : GLint format = GL2PS_PS;
1449 0 : if (ext == "ps") {
1450 : format = GL2PS_PS;
1451 0 : } else if (ext == "eps") {
1452 : format = GL2PS_EPS;
1453 0 : } else if (ext == "pdf") {
1454 : format = GL2PS_PDF;
1455 0 : } else if (ext == "tex") {
1456 : format = GL2PS_TEX;
1457 0 : } else if (ext == "svg") {
1458 : format = GL2PS_SVG;
1459 0 : } else if (ext == "pgf") {
1460 : format = GL2PS_PGF;
1461 : } else {
1462 0 : return "Could not save '" + destFile + "'.\n Unrecognized format '" + std::string(ext.text()) + "'.";
1463 : }
1464 0 : FILE* fp = fopen(destFile.c_str(), "wb");
1465 0 : if (fp == 0) {
1466 0 : return "Could not save '" + destFile + "'.\n Could not open file for writing";
1467 : }
1468 0 : GLHelper::setGL2PS();
1469 : GLint buffsize = 0, state = GL2PS_OVERFLOW;
1470 : GLint viewport[4];
1471 0 : glGetIntegerv(GL_VIEWPORT, viewport);
1472 0 : while (state == GL2PS_OVERFLOW) {
1473 0 : buffsize += 1024 * 1024;
1474 0 : gl2psBeginPage(destFile.c_str(), "sumo-gui; https://sumo.dlr.de", viewport, format, GL2PS_SIMPLE_SORT,
1475 : GL2PS_DRAW_BACKGROUND | GL2PS_USE_CURRENT_VIEWPORT,
1476 : GL_RGBA, 0, NULL, 0, 0, 0, buffsize, fp, "out.eps");
1477 0 : glMatrixMode(GL_MODELVIEW);
1478 0 : GLHelper::pushMatrix();
1479 0 : glDisable(GL_TEXTURE_2D);
1480 0 : glDisable(GL_ALPHA_TEST);
1481 0 : glDisable(GL_BLEND);
1482 0 : glEnable(GL_DEPTH_TEST);
1483 : // draw decals (if not in grabbing mode)
1484 :
1485 0 : drawDecals();
1486 0 : if (myVisualizationSettings->showGrid) {
1487 0 : paintGLGrid();
1488 : }
1489 :
1490 0 : glLineWidth(1);
1491 0 : glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
1492 0 : Boundary viewPort = myChanger->getViewport();
1493 0 : const float minB[2] = { (float)viewPort.xmin(), (float)viewPort.ymin() };
1494 0 : const float maxB[2] = { (float)viewPort.xmax(), (float)viewPort.ymax() };
1495 0 : myVisualizationSettings->scale = m2p(SUMO_const_laneWidth);
1496 0 : glEnable(GL_POLYGON_OFFSET_FILL);
1497 0 : glEnable(GL_POLYGON_OFFSET_LINE);
1498 0 : myGrid->Search(minB, maxB, *myVisualizationSettings);
1499 :
1500 0 : displayLegends();
1501 0 : state = gl2psEndPage();
1502 0 : glFinish();
1503 : }
1504 0 : GLHelper::setGL2PS(false);
1505 0 : fclose(fp);
1506 : #else
1507 : return "Could not save '" + destFile + "', gl2ps was not enabled at compile time.";
1508 : #endif
1509 : } else {
1510 308 : doPaintGL(GL_RENDER, myChanger->getViewport());
1511 308 : displayLegends();
1512 308 : swapBuffers();
1513 308 : glFinish();
1514 : FXColor* buf;
1515 308 : FXMALLOC(&buf, FXColor, getWidth()*getHeight());
1516 : // read from the back buffer
1517 308 : glReadBuffer(GL_BACK);
1518 : // Read the pixels
1519 308 : glReadPixels(0, 0, getWidth(), getHeight(), GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)buf);
1520 308 : makeNonCurrent();
1521 308 : update();
1522 : // mirror
1523 : int mwidth = getWidth();
1524 : int mheight = getHeight();
1525 308 : FXColor* paa = buf;
1526 308 : FXColor* pbb = buf + mwidth * (mheight - 1);
1527 : do {
1528 : FXColor* pa = paa;
1529 40156 : paa += mwidth;
1530 : FXColor* pb = pbb;
1531 40156 : pbb -= mwidth;
1532 : do {
1533 19691440 : FXColor t = *pa;
1534 19691440 : *pa++ = *pb;
1535 19691440 : *pb++ = t;
1536 19691440 : } while (pa < paa);
1537 40156 : } while (paa < pbb);
1538 : try {
1539 : #ifdef HAVE_FFMPEG
1540 308 : if (useVideo) {
1541 : try {
1542 0 : saveFrame(destFile, buf);
1543 : errorMessage = "video";
1544 0 : } catch (std::runtime_error& err) {
1545 0 : errorMessage = err.what();
1546 0 : }
1547 : } else
1548 : #endif
1549 308 : if (!MFXImageHelper::saveImage(destFile, getWidth(), getHeight(), buf)) {
1550 0 : errorMessage = "Could not save '" + destFile + "'.";
1551 : }
1552 3 : } catch (InvalidArgument& e) {
1553 6 : errorMessage = "Could not save '" + destFile + "'.\n" + e.what();
1554 3 : }
1555 308 : FXFREE(&buf);
1556 : }
1557 308 : return errorMessage;
1558 308 : }
1559 :
1560 :
1561 : void
1562 0 : GUISUMOAbstractView::saveFrame(const std::string& destFile, FXColor* buf) {
1563 : UNUSED_PARAMETER(destFile);
1564 : UNUSED_PARAMETER(buf);
1565 0 : }
1566 :
1567 :
1568 : void
1569 13173082 : GUISUMOAbstractView::checkSnapshots() {
1570 13173082 : const SUMOTime time = getCurrentTimeStep() - DELTA_T;
1571 : #ifdef DEBUG_SNAPSHOT
1572 : std::cout << "check snapshots time=" << time << " registeredTimes=" << mySnapshots.size() << "\n";
1573 : #endif
1574 13173082 : FXMutexLock lock(mySnapshotsMutex);
1575 : const auto snapIt = mySnapshots.find(time);
1576 13173082 : if (snapIt == mySnapshots.end()) {
1577 : return;
1578 : }
1579 34 : std::vector<std::tuple<std::string, int, int> > files = snapIt->second;
1580 : lock.unlock();
1581 : // decouple map access and painting to avoid deadlock
1582 342 : for (const auto& entry : files) {
1583 : #ifdef DEBUG_SNAPSHOT
1584 : std::cout << "make snapshot time=" << time << " file=" << file << "\n";
1585 : #endif
1586 308 : const std::string& error = makeSnapshot(std::get<0>(entry), std::get<1>(entry), std::get<2>(entry));
1587 308 : if (error != "" && error != "video") {
1588 9 : WRITE_WARNING(error);
1589 : }
1590 : }
1591 : // synchronization with a waiting run thread
1592 : lock.lock();
1593 : mySnapshots.erase(time);
1594 34 : mySnapshotCondition.signal();
1595 : #ifdef DEBUG_SNAPSHOT
1596 : std::cout << " files=" << toString(files) << " myApplicationSnapshots=" << joinToString(*myApplicationSnapshots, ",") << "\n";
1597 : #endif
1598 34 : }
1599 :
1600 :
1601 : void
1602 13173488 : GUISUMOAbstractView::waitForSnapshots(const SUMOTime snapshotTime) {
1603 13173488 : FXMutexLock lock(mySnapshotsMutex);
1604 : if (mySnapshots.count(snapshotTime) > 0) {
1605 34 : mySnapshotCondition.wait(mySnapshotsMutex);
1606 : }
1607 13173488 : }
1608 :
1609 :
1610 : SUMOTime
1611 0 : GUISUMOAbstractView::getCurrentTimeStep() const {
1612 0 : return 0;
1613 : }
1614 :
1615 :
1616 : void
1617 0 : GUISUMOAbstractView::showViewschemeEditor() {
1618 0 : if (myGUIDialogViewSettings == nullptr) {
1619 0 : myGUIDialogViewSettings = new GUIDialog_ViewSettings(this, myVisualizationSettings);
1620 0 : myGUIDialogViewSettings->create();
1621 : } else {
1622 0 : myGUIDialogViewSettings->setCurrent(myVisualizationSettings);
1623 : }
1624 0 : setFocus();
1625 0 : myGUIDialogViewSettings->show();
1626 0 : }
1627 :
1628 :
1629 : GUIDialog_EditViewport*
1630 0 : GUISUMOAbstractView::getViewportEditor() {
1631 0 : if (myGUIDialogEditViewport == nullptr) {
1632 0 : myGUIDialogEditViewport = new GUIDialog_EditViewport(this, TLC("Labels", "Edit Viewport"));
1633 0 : myGUIDialogEditViewport->create();
1634 : }
1635 0 : updateViewportValues();
1636 0 : return myGUIDialogEditViewport;
1637 : }
1638 :
1639 :
1640 0 : void GUISUMOAbstractView::updateViewportValues() {
1641 0 : myGUIDialogEditViewport->setValues(myChanger->getZoom(),
1642 0 : myChanger->getXPos(), myChanger->getYPos(),
1643 0 : myChanger->getRotation());
1644 0 : }
1645 :
1646 :
1647 : void
1648 0 : GUISUMOAbstractView::showViewportEditor() {
1649 0 : getViewportEditor(); // make sure it exists;
1650 0 : Position p(myChanger->getXPos(), myChanger->getYPos(), myChanger->getZPos());
1651 0 : myGUIDialogEditViewport->setOldValues(p, Position::INVALID, myChanger->getRotation());
1652 0 : myGUIDialogEditViewport->show();
1653 0 : }
1654 :
1655 :
1656 : void
1657 16 : GUISUMOAbstractView::setViewportFromToRot(const Position& lookFrom, const Position& /* lookAt */, double rotation) {
1658 16 : myChanger->setViewportFrom(lookFrom.x(), lookFrom.y(), lookFrom.z());
1659 16 : myChanger->setRotation(rotation);
1660 16 : update();
1661 16 : }
1662 :
1663 :
1664 : void
1665 4 : GUISUMOAbstractView::copyViewportTo(GUISUMOAbstractView* view) {
1666 : // look straight down
1667 4 : view->setViewportFromToRot(Position(myChanger->getXPos(), myChanger->getYPos(), myChanger->getZPos()),
1668 4 : Position(myChanger->getXPos(), myChanger->getYPos(), 0),
1669 4 : myChanger->getRotation());
1670 4 : }
1671 :
1672 :
1673 : bool
1674 0 : GUISUMOAbstractView::setColorScheme(const std::string&) {
1675 0 : return true;
1676 : }
1677 :
1678 :
1679 : const GUIVisualizationSettings&
1680 3 : GUISUMOAbstractView::getVisualisationSettings() const {
1681 3 : return *myVisualizationSettings;
1682 : }
1683 :
1684 :
1685 : GUIVisualizationSettings*
1686 0 : GUISUMOAbstractView::editVisualisationSettings() const {
1687 0 : return myVisualizationSettings;
1688 : }
1689 :
1690 :
1691 : void
1692 0 : GUISUMOAbstractView::remove(GUIDialog_EditViewport*) {
1693 0 : myGUIDialogEditViewport = nullptr;
1694 0 : }
1695 :
1696 :
1697 : void
1698 0 : GUISUMOAbstractView::remove(GUIDialog_ViewSettings*) {
1699 0 : myGUIDialogViewSettings = nullptr;
1700 0 : }
1701 :
1702 :
1703 : double
1704 0 : GUISUMOAbstractView::getGridWidth() const {
1705 0 : return myGrid->getWidth();
1706 : }
1707 :
1708 :
1709 : double
1710 0 : GUISUMOAbstractView::getGridHeight() const {
1711 0 : return myGrid->getHeight();
1712 : }
1713 :
1714 :
1715 : void
1716 0 : GUISUMOAbstractView::startTrack(int /*id*/) {
1717 0 : }
1718 :
1719 :
1720 : void
1721 0 : GUISUMOAbstractView::stopTrack() {
1722 0 : }
1723 :
1724 :
1725 : GUIGlID
1726 0 : GUISUMOAbstractView::getTrackedID() const {
1727 0 : return GUIGlObject::INVALID_ID;
1728 : }
1729 :
1730 :
1731 : void
1732 0 : GUISUMOAbstractView::onGamingClick(Position /*pos*/) {
1733 0 : }
1734 :
1735 : void
1736 0 : GUISUMOAbstractView::onGamingRightClick(Position /*pos*/) {
1737 0 : }
1738 :
1739 :
1740 : std::vector<GUISUMOAbstractView::Decal>&
1741 8505 : GUISUMOAbstractView::getDecals() {
1742 8505 : return myDecals;
1743 : }
1744 :
1745 :
1746 : FXMutex&
1747 0 : GUISUMOAbstractView::getDecalsLockMutex() {
1748 0 : return myDecalsLockMutex;
1749 : }
1750 :
1751 :
1752 : void
1753 7 : GUISUMOAbstractView::queueTextureDelete(unsigned int textureId) {
1754 7 : FXMutexLock lock(myTextureDeleteMutex);
1755 7 : myPendingTextureDeletes.push_back(textureId);
1756 7 : }
1757 :
1758 :
1759 : void
1760 822085 : GUISUMOAbstractView::processPendingTextureDeletes() {
1761 822085 : FXMutexLock lock(myTextureDeleteMutex);
1762 822085 : if (!myPendingTextureDeletes.empty()) {
1763 4 : glDeleteTextures(
1764 : static_cast<GLsizei>(myPendingTextureDeletes.size()),
1765 : myPendingTextureDeletes.data()
1766 : );
1767 : myPendingTextureDeletes.clear();
1768 : }
1769 822085 : }
1770 :
1771 :
1772 : void
1773 8505 : GUISUMOAbstractView::clearDecals() {
1774 8505 : FXMutexLock lock(myDecalsLockMutex);
1775 8512 : for (auto& decal : myDecals) {
1776 7 : if (decal.glID > 0) {
1777 7 : queueTextureDelete(static_cast<unsigned int>(decal.glID));
1778 7 : decal.glID = -1;
1779 : }
1780 7 : decal.initialised = false;
1781 : }
1782 : myDecals.clear();
1783 8505 : }
1784 :
1785 :
1786 : MFXComboBoxIcon*
1787 40 : GUISUMOAbstractView::getColoringSchemesCombo() {
1788 40 : return myGlChildWindowParent->getColoringSchemesCombo();
1789 : }
1790 :
1791 :
1792 : FXImage*
1793 7 : GUISUMOAbstractView::checkGDALImage(Decal& d) {
1794 : #ifdef HAVE_GDAL
1795 7 : GDALAllRegister();
1796 7 : GDALDataset* poDataset = (GDALDataset*)GDALOpen(d.filename.c_str(), GA_ReadOnly);
1797 7 : if (poDataset == 0) {
1798 : return 0;
1799 : }
1800 7 : const int xSize = poDataset->GetRasterXSize();
1801 7 : const int ySize = poDataset->GetRasterYSize();
1802 : // checking for geodata in the picture and try to adapt position and scale
1803 7 : if (d.width <= 0.) {
1804 : double adfGeoTransform[6];
1805 0 : if (poDataset->GetGeoTransform(adfGeoTransform) == CE_None) {
1806 0 : Position topLeft(adfGeoTransform[0], adfGeoTransform[3]);
1807 0 : const double horizontalSize = xSize * adfGeoTransform[1];
1808 0 : const double verticalSize = ySize * adfGeoTransform[5];
1809 0 : Position bottomRight(topLeft.x() + horizontalSize, topLeft.y() + verticalSize);
1810 0 : if (GeoConvHelper::getFinal().usingGeoProjection() && GeoConvHelper::getFinal().x2cartesian_const(topLeft) && GeoConvHelper::getFinal().x2cartesian_const(bottomRight)) {
1811 : //WRITE_MESSAGE("proj: " + toString(poDataset->GetProjectionRef()) + " dim: " + toString(d.width) + "," + toString(d.height) + " center: " + toString(d.centerX) + "," + toString(d.centerY));
1812 : } else {
1813 0 : WRITE_WARNINGF(TL("Could not transform coordinates from WGS84 in decal %, assuming UTM."), d.filename);
1814 0 : topLeft = topLeft + GeoConvHelper::getFinal().getOffset();
1815 0 : bottomRight = bottomRight + GeoConvHelper::getFinal().getOffset();
1816 : }
1817 0 : d.width = bottomRight.x() - topLeft.x();
1818 0 : d.height = topLeft.y() - bottomRight.y();
1819 0 : d.centerX = (topLeft.x() + bottomRight.x()) / 2;
1820 0 : d.centerY = (topLeft.y() + bottomRight.y()) / 2;
1821 : }
1822 : }
1823 : #endif
1824 7 : if (d.width <= 0.) {
1825 0 : d.width = getGridWidth();
1826 0 : d.height = getGridHeight();
1827 : }
1828 :
1829 : // trying to read the picture
1830 : #ifdef HAVE_GDAL
1831 7 : const int picSize = xSize * ySize;
1832 : FXColor* result;
1833 7 : if (!FXMALLOC(&result, FXColor, picSize)) {
1834 0 : WRITE_WARNINGF("Could not allocate memory for %.", d.filename);
1835 0 : return 0;
1836 : }
1837 544775 : for (int j = 0; j < picSize; j++) {
1838 544768 : result[j] = GUIDesignTextColorBlack;
1839 : }
1840 : bool valid = true;
1841 7 : for (int i = 1; i <= poDataset->GetRasterCount(); i++) {
1842 7 : GDALRasterBand* poBand = poDataset->GetRasterBand(i);
1843 : int shift = -1;
1844 7 : if (poBand->GetColorInterpretation() == GCI_RedBand) {
1845 : shift = 0;
1846 7 : } else if (poBand->GetColorInterpretation() == GCI_GreenBand) {
1847 : shift = 1;
1848 7 : } else if (poBand->GetColorInterpretation() == GCI_BlueBand) {
1849 : shift = 2;
1850 7 : } else if (poBand->GetColorInterpretation() == GCI_AlphaBand) {
1851 : shift = 3;
1852 : } else {
1853 : valid = false;
1854 : break;
1855 : }
1856 : assert(xSize == poBand->GetXSize() && ySize == poBand->GetYSize());
1857 0 : if (poBand->RasterIO(GF_Read, 0, 0, xSize, ySize, ((unsigned char*)result) + shift, xSize, ySize, GDT_Byte, 4, 4 * xSize) == CE_Failure) {
1858 : valid = false;
1859 : break;
1860 : }
1861 : }
1862 7 : GDALClose(poDataset);
1863 7 : if (valid) {
1864 0 : return new FXImage(getApp(), result, IMAGE_OWNED | IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP, xSize, ySize);
1865 : }
1866 7 : FXFREE(&result);
1867 : #endif
1868 : return nullptr;
1869 : }
1870 :
1871 :
1872 : void
1873 805380 : GUISUMOAbstractView::drawDecals() {
1874 805380 : GLHelper::pushName(0);
1875 805380 : myDecalsLockMutex.lock();
1876 807709 : for (auto& decal : myDecals) {
1877 2329 : if (decal.skip2D || decal.filename.empty()) {
1878 0 : continue;
1879 : }
1880 2329 : if (!decal.initialised) {
1881 : try {
1882 7 : FXImage* img = checkGDALImage(decal);
1883 7 : if (img == nullptr) {
1884 7 : img = MFXImageHelper::loadImage(getApp(), decal.filename);
1885 : }
1886 7 : MFXImageHelper::scalePower2(img, GUITexturesHelper::getMaxTextureSize());
1887 7 : decal.glID = GUITexturesHelper::add(img);
1888 7 : delete img;
1889 7 : decal.initialised = true;
1890 0 : } catch (InvalidArgument& e) {
1891 0 : WRITE_ERROR("Could not load '" + decal.filename + "'.\n" + e.what());
1892 0 : decal.skip2D = true;
1893 0 : }
1894 : }
1895 2329 : GLHelper::pushMatrix();
1896 2329 : if (decal.screenRelative) {
1897 0 : Position center = screenPos2NetPos((int)decal.centerX, (int)decal.centerY);
1898 0 : glTranslated(center.x(), center.y(), decal.layer);
1899 : } else {
1900 2329 : glTranslated(decal.centerX, decal.centerY, decal.layer);
1901 : }
1902 2329 : glRotated(decal.rot, 0, 0, 1);
1903 2329 : glColor3d(1, 1, 1);
1904 2329 : double halfWidth = decal.width / 2.;
1905 2329 : double halfHeight = decal.height / 2.;
1906 2329 : if (decal.screenRelative) {
1907 0 : halfWidth = p2m(halfWidth);
1908 0 : halfHeight = p2m(halfHeight);
1909 : }
1910 2329 : GUITexturesHelper::drawTexturedBox(decal.glID, -halfWidth, -halfHeight, halfWidth, halfHeight);
1911 2329 : GLHelper::popMatrix();
1912 : }
1913 805380 : myDecalsLockMutex.unlock();
1914 805380 : GLHelper::popName();
1915 805380 : }
1916 :
1917 :
1918 : void
1919 0 : GUISUMOAbstractView::openPopupDialog() {
1920 : int x, y;
1921 : FXuint b;
1922 0 : myApp->getCursorPosition(x, y, b);
1923 0 : int appX = myApp->getX();
1924 0 : int popX = x + appX;
1925 0 : int popY = y + myApp->getY();
1926 0 : myPopup->setX(popX);
1927 0 : myPopup->setY(popY);
1928 0 : myPopup->create();
1929 0 : myPopup->show();
1930 : // TODO: try to stay on screen even on a right secondary screen in multi-monitor setup
1931 : const int rootWidth = getApp()->getRootWindow()->getWidth();
1932 : const int rootHeight = getApp()->getRootWindow()->getHeight();
1933 0 : if (popX <= rootWidth) {
1934 0 : const int maxX = (appX < 0) ? 0 : rootWidth;
1935 0 : popX = MIN2(popX, maxX - myPopup->getWidth() - 10);
1936 : }
1937 0 : popY = MIN2(popY, rootHeight - myPopup->getHeight() - 50);
1938 0 : myPopup->move(popX, popY);
1939 0 : myPopupPosition = getPositionInformation();
1940 0 : myChanger->onRightBtnRelease(nullptr);
1941 0 : setFocus();
1942 0 : }
1943 :
1944 : // ------------ Additional visualisations
1945 :
1946 : bool
1947 9 : GUISUMOAbstractView::addAdditionalGLVisualisation(GUIGlObject* const which) {
1948 9 : if (myAdditionallyDrawn.find(which) == myAdditionallyDrawn.end()) {
1949 9 : myAdditionallyDrawn[which] = 1;
1950 : } else {
1951 0 : myAdditionallyDrawn[which] = myAdditionallyDrawn[which] + 1;
1952 : }
1953 9 : update();
1954 9 : return true;
1955 : }
1956 :
1957 :
1958 : bool
1959 34 : GUISUMOAbstractView::removeAdditionalGLVisualisation(GUIGlObject* const which) {
1960 34 : if (myAdditionallyDrawn.find(which) == myAdditionallyDrawn.end()) {
1961 : return false;
1962 : }
1963 9 : int cnt = myAdditionallyDrawn[which];
1964 9 : if (cnt == 1) {
1965 : myAdditionallyDrawn.erase(which);
1966 : } else {
1967 0 : myAdditionallyDrawn[which] = myAdditionallyDrawn[which] - 1;
1968 : }
1969 9 : update();
1970 9 : return true;
1971 : }
1972 :
1973 :
1974 : bool
1975 0 : GUISUMOAbstractView::isAdditionalGLVisualisationEnabled(GUIGlObject* const which) const {
1976 0 : if (myAdditionallyDrawn.find(which) == myAdditionallyDrawn.end()) {
1977 : return false;
1978 : } else {
1979 0 : return true;
1980 : }
1981 : }
1982 :
1983 :
1984 : Boundary
1985 805380 : GUISUMOAbstractView::applyGLTransform(bool fixRatio) {
1986 805380 : Boundary bound = myChanger->getViewport(fixRatio);
1987 805380 : glMatrixMode(GL_PROJECTION);
1988 805380 : glLoadIdentity();
1989 : // as a rough rule, each GLObject is drawn at z = -GUIGlObjectType
1990 : // thus, objects with a higher value will be closer (drawn on top)
1991 : // // @todo last param should be 0 after modifying all glDraw methods
1992 805380 : glOrtho(0, getWidth(), 0, getHeight(), -GLO_MAX - 1, GLO_MAX + 1);
1993 805380 : glMatrixMode(GL_MODELVIEW);
1994 805380 : glLoadIdentity();
1995 805380 : double scaleX = (double)getWidth() / bound.getWidth();
1996 805380 : double scaleY = (double)getHeight() / bound.getHeight();
1997 805380 : glScaled(scaleX, scaleY, 1);
1998 805380 : glTranslated(-bound.xmin(), -bound.ymin(), 0);
1999 : // rotate around the center of the screen
2000 : //double angle = -90;
2001 805380 : if (myChanger->getRotation() != 0) {
2002 0 : glTranslated(bound.getCenter().x(), bound.getCenter().y(), 0);
2003 0 : glRotated(myChanger->getRotation(), 0, 0, 1);
2004 0 : glTranslated(-bound.getCenter().x(), -bound.getCenter().y(), 0);
2005 0 : Boundary rotBound;
2006 0 : double rad = -DEG2RAD(myChanger->getRotation());
2007 0 : rotBound.add(Position(bound.xmin(), bound.ymin()).rotateAround2D(rad, bound.getCenter()));
2008 0 : rotBound.add(Position(bound.xmin(), bound.ymax()).rotateAround2D(rad, bound.getCenter()));
2009 0 : rotBound.add(Position(bound.xmax(), bound.ymin()).rotateAround2D(rad, bound.getCenter()));
2010 0 : rotBound.add(Position(bound.xmax(), bound.ymax()).rotateAround2D(rad, bound.getCenter()));
2011 : bound = rotBound;
2012 : }
2013 805380 : myVisualizationSettings->angle = myChanger->getRotation();
2014 805380 : return bound;
2015 : }
2016 :
2017 :
2018 : double
2019 0 : GUISUMOAbstractView::getDelay() const {
2020 0 : return myApp->getDelay();
2021 : }
2022 :
2023 :
2024 : void
2025 0 : GUISUMOAbstractView::setDelay(double delay) {
2026 0 : myApp->setDelay(delay);
2027 0 : }
2028 :
2029 :
2030 : void
2031 0 : GUISUMOAbstractView::setBreakpoints(const std::vector<SUMOTime>& breakpoints) {
2032 0 : myApp->setBreakpoints(breakpoints);
2033 0 : }
2034 :
2035 :
2036 : void
2037 0 : GUISUMOAbstractView::buildMinMaxRainbow(const GUIVisualizationSettings& s, GUIColorScheme& scheme,
2038 : const GUIVisualizationRainbowSettings& rs, double minValue, double maxValue, bool hasMissingData) {
2039 0 : if (rs.hideMin && rs.hideMax && minValue == std::numeric_limits<double>::infinity()) {
2040 0 : minValue = rs.minThreshold;
2041 0 : maxValue = rs.maxThreshold;
2042 : }
2043 0 : if (rs.fixRange) {
2044 0 : if (rs.hideMin) {
2045 0 : minValue = rs.minThreshold;
2046 : }
2047 0 : if (rs.hideMax) {
2048 0 : maxValue = rs.maxThreshold;
2049 : }
2050 : }
2051 0 : if (minValue != std::numeric_limits<double>::infinity()) {
2052 0 : scheme.clear();
2053 : // add new thresholds
2054 0 : if (scheme.getName() == GUIVisualizationSettings::SCHEME_NAME_EDGEDATA_NUMERICAL
2055 0 : || scheme.getName() == GUIVisualizationSettings::SCHEME_NAME_EDGE_PARAM_NUMERICAL
2056 0 : || scheme.getName() == GUIVisualizationSettings::SCHEME_NAME_LANE_PARAM_NUMERICAL
2057 0 : || scheme.getName() == GUIVisualizationSettings::SCHEME_NAME_DATA_ATTRIBUTE_NUMERICAL
2058 0 : || scheme.getName() == GUIVisualizationSettings::SCHEME_NAME_PARAM_NUMERICAL
2059 0 : || hasMissingData) {
2060 0 : scheme.addColor(s.COL_MISSING_DATA, s.MISSING_DATA, "missing data");
2061 : }
2062 0 : if (rs.hideMin && !rs.fixRange) {
2063 0 : const double rawRange = maxValue - minValue;
2064 0 : minValue = MAX2(rs.minThreshold + MIN2(1.0, rawRange / 100.0), minValue);
2065 0 : scheme.addColor(RGBColor(204, 204, 204), rs.minThreshold);
2066 : }
2067 0 : if (rs.hideMax && !rs.fixRange) {
2068 0 : const double rawRange = maxValue - minValue;
2069 0 : maxValue = MIN2(rs.maxThreshold - MIN2(1.0, rawRange / 100.0), maxValue);
2070 0 : scheme.addColor(RGBColor(204, 204, 204), rs.maxThreshold);
2071 : }
2072 0 : const double range = maxValue - minValue;
2073 0 : scheme.addColor(rs.colors.front(), minValue);
2074 0 : const int steps = (int)rs.colors.size() - 1;
2075 0 : if (rs.setNeutral) {
2076 0 : const int steps1 = steps / 2;
2077 0 : const int steps2 = steps - steps1;
2078 0 : const double range1 = rs.neutralThreshold - minValue;
2079 0 : const double range2 = maxValue - rs.neutralThreshold;
2080 0 : for (int i = 1; i < steps1; i++) {
2081 0 : scheme.addColor(rs.colors[i], (minValue + range1 * i / steps1));
2082 : }
2083 0 : scheme.addColor(rs.colors[steps1], rs.neutralThreshold);
2084 0 : for (int i = 1; i < steps2; i++) {
2085 0 : scheme.addColor(rs.colors[steps1 + i], (rs.neutralThreshold + range2 * i / steps2));
2086 : }
2087 : } else {
2088 0 : for (int i = 1; i < steps; i++) {
2089 0 : scheme.addColor(rs.colors[i], (minValue + range * i / steps));
2090 : }
2091 : }
2092 0 : scheme.addColor(rs.colors.back(), maxValue);
2093 : }
2094 0 : }
2095 :
2096 :
2097 0 : GUISUMOAbstractView::LayerObject::LayerObject(double layer, GUIGlObject* object) :
2098 0 : myGLObject(object) {
2099 0 : first = layer;
2100 0 : second.first = object->getType();
2101 0 : second.second = object->getMicrosimID();
2102 0 : }
2103 :
2104 :
2105 0 : GUISUMOAbstractView::LayerObject::LayerObject(GUIGlObject* object) :
2106 0 : myGLObject(object) {
2107 0 : first = object->getType();
2108 0 : second.first = object->getType();
2109 0 : second.second = object->getMicrosimID();
2110 0 : }
2111 :
2112 :
2113 : GUIGlObject*
2114 0 : GUISUMOAbstractView::LayerObject::getGLObject() const {
2115 0 : return myGLObject;
2116 : }
2117 :
2118 : /****************************************************************************/
|