72 #include <gdal_priv.h> 75 #ifdef CHECK_MEMORY_LEAKS 77 #endif // CHECK_MEMORY_LEAKS 104 FXIMPLEMENT_ABSTRACT(
GUISUMOAbstractView, FXGLCanvas, GUISUMOAbstractViewMap, ARRAYNUMBER(GUISUMOAbstractViewMap))
114 FXGLVisual* glVis, FXGLCanvas* share)
116 LAYOUT_SIDE_TOP | LAYOUT_FILL_X | LAYOUT_FILL_Y, 0, 0, 0, 0),
121 myMouseHotspotX(app.getDefaultCursor()->getHotX()),
122 myMouseHotspotY(app.getDefaultCursor()->getHotY()),
124 myUseToolTips(false),
125 myAmInitialised(false),
126 myViewportChooser(0),
127 myWindowCursorPositionX(getWidth() / 2),
128 myWindowCursorPositionY(getHeight() / 2),
129 myVisualizationChanger(0) {
132 flags |= FLAG_ENABLED;
133 myInEditMode =
false;
137 myVisualizationSettings->
gaming = myApp->isGaming();
150 for (std::vector<GUISUMOAbstractView::Decal>::iterator it =
myDecals.begin(); it !=
myDecals.end(); ++it) {
203 if (getWidth() == 0 || getHeight() == 0) {
222 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
223 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
228 glDisable(GL_DITHER);
232 glEnable(GL_POLYGON_SMOOTH);
233 glEnable(GL_LINE_SMOOTH);
236 glDisable(GL_POLYGON_SMOOTH);
237 glDisable(GL_LINE_SMOOTH);
265 selection.
grow(SENSITIVITY);
268 unsigned int idMax = 0;
270 for (std::vector<GUIGlID>::const_iterator it = ids.begin(); it != ids.end(); it++) {
287 layer =
dynamic_cast<Shape*
>(o)->getLayer();
290 if (type ==
GLO_LANE && GUIVisualizationSettings::UseMesoSim) {
296 if (layer > maxLayer) {
311 selection.
grow(radius);
313 std::vector<GUIGlID> result;
315 for (std::vector<GUIGlID>::const_iterator it = ids.begin(); it != ids.end(); it++) {
327 result.push_back(
id);
337 const int NB_HITS_MAX = 1024 * 1024;
339 static GUIGlID hits[NB_HITS_MAX];
340 static GLint nb_hits = 0;
341 glSelectBuffer(NB_HITS_MAX, hits);
353 nb_hits = glRenderMode(GL_RENDER);
357 std::vector<GUIGlID> result;
360 for (
int i = 0; i < nb_hits; ++i) {
363 for (
int j = 0; j < (int)numNames; j++) {
364 result.push_back(*ptr);
390 glEnable(GL_DEPTH_TEST);
400 glTranslated(0, 0, .55);
401 glColor3d(0.5, 0.5, 0.5);
404 for (; ypos < yend;) {
405 glVertex2d(xmin, ypos);
406 glVertex2d(xend, ypos);
410 for (; xpos < xend;) {
411 glVertex2d(xpos, ymin);
412 glVertex2d(xpos, yend);
416 glTranslated(0, 0, -.55);
424 const std::string text(
"10000000000");
426 size_t pixelSize = (size_t)
m2p((
SUMOReal) length);
427 while (pixelSize <= 20) {
430 if (noDigits > text.length()) {
438 glMatrixMode(GL_PROJECTION);
441 glMatrixMode(GL_MODELVIEW);
446 glDisable(GL_TEXTURE_2D);
447 glDisable(GL_ALPHA_TEST);
449 glEnable(GL_DEPTH_TEST);
453 double o = double(15) / double(getHeight());
455 double oo = double(5) / double(getHeight());
458 glVertex2d(-.98, -1. + o);
459 glVertex2d(-.98 + len, -1. + o);
461 glVertex2d(-.98, -1. + o);
462 glVertex2d(-.98, -1. + o2);
464 glVertex2d(-.98 + len, -1. + o);
465 glVertex2d(-.98 + len, -1. + o2);
472 glRotated(180, 1, 0, 0);
474 glRotated(-180, 1, 0, 0);
477 glRotated(180, 1, 0, 0);
479 glRotated(-180, 1, 0, 0);
482 glMatrixMode(GL_PROJECTION);
484 glMatrixMode(GL_MODELVIEW);
510 if (o != 0 && dynamic_cast<GUIGlObject*>(o) != 0) {
511 if (applyZoom && zoomDist < 0) {
546 FXbool ret = FXGLCanvas::makeCurrent();
554 glViewport(0, 0, getWidth() - 1, getHeight() - 1);
593 FXEvent* e = (FXEvent*) data;
595 if ((e->state & CONTROLMASK) != 0) {
696 myApp->getCursorPosition(x, y, b);
711 FXGLCanvas::onKeyPress(o, sel, data);
718 FXGLCanvas::onKeyRelease(o, sel, data);
732 std::string errorMessage;
733 FXString ext = FXPath::extension(destFile.c_str());
734 bool useGL2PS = ext ==
"ps" || ext ==
"eps" || ext ==
"pdf" || ext ==
"svg" || ext ==
"tex" || ext ==
"pgf";
745 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
746 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
751 glDisable(GL_DITHER);
755 glEnable(GL_POLYGON_SMOOTH);
756 glEnable(GL_LINE_SMOOTH);
759 glDisable(GL_POLYGON_SMOOTH);
760 glDisable(GL_LINE_SMOOTH);
766 GLint format = GL2PS_PS;
769 }
else if (ext ==
"eps") {
771 }
else if (ext ==
"pdf") {
773 }
else if (ext ==
"tex") {
775 }
else if (ext ==
"svg") {
777 }
else if (ext ==
"pgf") {
780 return "Could not save '" + destFile +
"'.\n Unrecognized format '" + std::string(ext.text()) +
"'.";
782 FILE* fp = fopen(destFile.c_str(),
"wb");
784 return "Could not save '" + destFile +
"'.\n Could not open file for writing";
786 GLint buffsize = 0, state = GL2PS_OVERFLOW;
788 glGetIntegerv(GL_VIEWPORT, viewport);
789 while (state == GL2PS_OVERFLOW) {
790 buffsize += 1024 * 1024;
791 gl2psBeginPage(destFile.c_str(),
"sumo-gui; http://sumo.dlr.de", viewport, format, GL2PS_SIMPLE_SORT,
792 GL2PS_DRAW_BACKGROUND | GL2PS_USE_CURRENT_VIEWPORT,
793 GL_RGBA, 0, NULL, 0, 0, 0, buffsize, fp,
"out.eps");
794 glMatrixMode(GL_MODELVIEW);
796 glDisable(GL_TEXTURE_2D);
797 glDisable(GL_ALPHA_TEST);
799 glEnable(GL_DEPTH_TEST);
809 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
813 minB[0] = viewPort.
xmin();
814 minB[1] = viewPort.
ymin();
815 maxB[0] = viewPort.
xmax();
816 maxB[1] = viewPort.
ymax();
818 glEnable(GL_POLYGON_OFFSET_FILL);
819 glEnable(GL_POLYGON_OFFSET_LINE);
825 state = gl2psEndPage();
837 FXMALLOC(&buf, FXColor, getWidth()*getHeight());
839 glReadBuffer(GL_BACK);
841 glReadPixels(0, 0, getWidth(), getHeight(), GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)buf);
845 size_t mwidth = getWidth();
846 size_t mheight = getHeight();
848 FXColor* pbb = buf + mwidth * (mheight - 1);
862 errorMessage =
"Could not save '" + destFile +
"'.";
865 errorMessage =
"Could not save '" + destFile +
"'.\n" + e.what();
956 GDALDataset* poDataset = (GDALDataset*)GDALOpen(d.
filename.c_str(), GA_ReadOnly);
957 if (poDataset == 0) {
960 const int xSize = poDataset->GetRasterXSize();
961 const int ySize = poDataset->GetRasterYSize();
964 double adfGeoTransform[6];
965 if (poDataset->GetGeoTransform(adfGeoTransform) == CE_None) {
966 Position topLeft(adfGeoTransform[0], adfGeoTransform[3]);
967 const double horizontalSize = xSize * adfGeoTransform[1];
968 const double verticalSize = ySize * adfGeoTransform[5];
969 Position bottomRight(topLeft.
x() + horizontalSize, topLeft.
y() + verticalSize);
971 d.
width = bottomRight.x() - topLeft.
x();
972 d.
height = topLeft.
y() - bottomRight.y();
973 d.
centerX = (topLeft.
x() + bottomRight.x()) / 2;
974 d.
centerY = (topLeft.
y() + bottomRight.y()) / 2;
989 const int picSize = xSize * ySize;
991 if (!FXMALLOC(&result, FXColor, picSize)) {
995 for (
int j = 0; j < picSize; j++) {
996 result[j] = FXRGB(0, 0, 0);
999 for (
int i = 1; i <= poDataset->GetRasterCount(); i++) {
1000 GDALRasterBand* poBand = poDataset->GetRasterBand(i);
1002 if (poBand->GetColorInterpretation() == GCI_RedBand) {
1004 }
else if (poBand->GetColorInterpretation() == GCI_GreenBand) {
1006 }
else if (poBand->GetColorInterpretation() == GCI_BlueBand) {
1008 }
else if (poBand->GetColorInterpretation() == GCI_AlphaBand) {
1015 assert(xSize == poBand->GetXSize() && ySize == poBand->GetYSize());
1016 if (poBand->RasterIO(GF_Read, 0, 0, xSize, ySize, ((
unsigned char*)result) + shift, xSize, ySize, GDT_Byte, 4, 4 * xSize) == CE_Failure) {
1021 GDALClose(poDataset);
1023 return new FXImage(getApp(), result, IMAGE_OWNED | IMAGE_KEEP | IMAGE_SHMI | IMAGE_SHMP, xSize, ySize);
1035 for (std::vector<GUISUMOAbstractView::Decal>::iterator l =
myDecals.begin(); l !=
myDecals.end(); ++l) {
1059 glRotated(d.
rot, 0, 0, 1);
1106 glMatrixMode(GL_PROJECTION);
1111 glOrtho(0, getWidth(), 0, getHeight(), -
GLO_MAX - 1,
GLO_MAX + 1);
1112 glMatrixMode(GL_MODELVIEW);
1116 glScaled(scaleX, scaleY, 1);
1117 glTranslated(-bound.
xmin(), -bound.
ymin(), 0);
GUIDialog_EditViewport * getViewportEditor()
get the viewport and create it on first access
void paintGLGrid()
paints a grid
A decal (an image) that can be shown.
virtual long onConfigure(FXObject *, FXSelector, void *)
void setValues(SUMOReal zoom, SUMOReal xoff, SUMOReal yoff)
Sets the given values into the dialog.
void showToolTips(bool val)
int pfDrawString(const char *c)
SUMOReal getHeight() const
Returns the height of the boundary.
GUICompleteSchemeStorage gSchemeStorage
bool showSizeLegend
Information whether the size legend shall be drawn.
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
FXImage * checkGDALImage(Decal &d)
check whether we can read image data or position with gdal
virtual void setViewport(SUMOReal zoom, SUMOReal xPos, SUMOReal yPos)=0
Sets the viewport Used for: Adapting a new viewport.
FXImage * image
The image pointer for later cleanup.
const SUMOReal SUMO_const_laneWidth
SUMOReal getWidth() const
Returns the width of the boudary.
void showToolTipFor(unsigned int id)
invokes the tooltip for the given object
virtual SUMOReal getDelay() const
Returns the delay (should be overwritten by subclasses if applicable)
virtual void setViewport(const Position &lookFrom, const Position &lookAt)
applies the given viewport settings
void setDefault(const std::string &name)
Makes the scheme with the given name the default.
Position getCenter() const
Returns the center of the boundary.
virtual void centerTo(GUIGlID id, bool applyZoom, SUMOReal zoomDist=20)
centers to the chosen artifact
bool myAmInitialised
Internal information whether doInit() was called.
void add(const Position &pos)
Adds the given position to this one.
virtual void recenterView()
recenters the view
FXint myWindowCursorPositionY
SUMORTree * myGrid
The visualization speed-up.
static GUIGlID add(FXImage *i)
Adds a texture to use.
void toggleSelection(GUIGlID id)
Toggles selection of an object.
bool gaming
whether the application is in gaming mode or not
virtual long onMouseMove(FXObject *, FXSelector, void *)
virtual SUMOReal getZoom() const =0
Returns the zoom factor computed stored in this changer.
SUMOReal ymin() const
Returns minimum y-coordinate.
The dialog to change the view (gui) settings.
static GeoConvHelper & getProcessing()
the coordinate transformation to use for input conversion and processing
#define GEO_OUTPUT_ACCURACY
bool x2cartesian(Position &from, bool includeInBoundary=true)
GUIMainWindow * myApp
The application.
SUMOReal xmin() const
Returns minimum x-coordinate.
virtual SUMOTime getCurrentTimeStep() const
get the current simulation time
MFXMutex myDecalsLock
The mutex to use before accessing the decals list in order to avoid thread conficts.
void pfSetPosition(SUMOReal x, SUMOReal y)
SUMOReal p2m(SUMOReal pixel) const
pixels-to-meters conversion method
bool addAdditionalGLVisualisation(GUIGlObject *const which)
Adds an object to call its additional visualisation method.
virtual long onLeftBtnPress(FXObject *, FXSelector, void *)
bool myInEditMode
Information whether too-tip informations shall be generated.
virtual void openObjectDialog()
virtual Boundary getCenteringBoundary() const =0
Returns the boundary to which the view shall be centered in order to show the object.
virtual long onKeyRelease(FXObject *o, FXSelector sel, void *data)
GUIGlObject * getNetObject() const
Returns the network object.
SUMOReal getGridHeight() const
int glID
The gl-id of the texture that holds this image.
void setSnapshots(std::map< SUMOTime, std::string > snaps)
Sets the snapshot time to file map.
static const RGBColor BLACK
SUMOReal width
The width of the image (net coordinates in x-direction, in m)
GUIDialog_ViewSettings * myVisualizationChanger
bool isGaming() const
return whether the gui is in gaming mode
GUIDialog_EditViewport * myViewportChooser
A RT-tree for efficient storing of SUMO's GL-objects.
SUMOReal x() const
Returns the x-position.
bool dither
Information whether dithering shall be enabled.
GUIGlID getGlID() const
Returns the numerical id of the object.
SUMOReal xmax() const
Returns maximum x-coordinate.
A class that stores a 2D geometrical boundary.
int myMouseHotspotX
Offset to the mouse-hotspot from the mouse position.
#define WRITE_WARNING(msg)
SUMOReal scale
information about a lane's width (temporary, used for a single view)
unsigned char blue() const
Returns the blue-amount of the color.
virtual int getTrackedID() const
FXLabel & getCartesianLabel()
virtual void setDelay(SUMOReal)
Sets the delay of the parent application.
std::vector< GUIGlID > getObjectsAtPosition(Position pos, SUMOReal radius)
returns the ids of the object at position within the given (rectangular) radius using GL_SELECT ...
std::vector< Decal > myDecals
The list of decals to show.
GUIGlObjectType getType() const
Returns the type of the object as coded in GUIGlObjectType.
GUIGlID getObjectAtPosition(Position pos)
returns the id of the object at position using GL_SELECT
static FXbool scalePower2(FXImage *image, int maxSize=(2<< 29))
virtual int doPaintGL(int, const Boundary &)
bool removeAdditionalGLVisualisation(GUIGlObject *const which)
Removes an object from the list of objects that show additional things.
virtual long onPaint(FXObject *, FXSelector, void *)
std::string name
The name of this setting.
std::map< GUIGlObject *, int > myAdditionallyDrawn
List of objects for which GUIGlObject::drawGLAdditional is called.
Boundary getVisibleBoundary() const
virtual long onMiddleBtnPress(FXObject *, FXSelector, void *)
static void drawTexturedBox(unsigned int which, SUMOReal size)
Draws a named texture as a box with the given size.
virtual void setStatusBarText(const std::string &)
virtual long onKeyPress(FXObject *o, FXSelector sel, void *data)
virtual SUMOReal getXPos() const =0
Returns the x-offset of the field to show stored in this changer.
virtual long onMiddleBtnRelease(FXObject *, FXSelector, void *)
static void sleep(long ms)
bool isInEditMode()
returns true, if the edit button was pressed
A point in 2D or 3D with translation and scaling methods.
SUMOReal centerY
The center of the image in y-direction (net coordinates, in m)
virtual GUIGLObjectPopupMenu * getPopUpMenu(GUIMainWindow &app, GUISUMOAbstractView &parent)=0
Returns an own popup-menu.
FXComboBox & getColoringSchemesCombo()
unsigned char alpha() const
Returns the alpha-amount of the color.
static GUIGlObjectStorage gIDStorage
A single static instance of this class.
SUMOReal z() const
Returns the z-position.
virtual bool onLeftBtnRelease(void *data)
FXComboBox & getColoringSchemesCombo()
bool initialised
Whether this image was initialised (inserted as a texture)
virtual bool onRightBtnRelease(void *data)
virtual long onMouseWheel(FXObject *, FXSelector, void *)
void checkSnapshots()
Checks whether it is time for a snapshot.
virtual ~GUISUMOAbstractView()
destructor
std::string filename
The path to the file the image is located at.
void saveViewport(const SUMOReal x, const SUMOReal y, const SUMOReal zoom)
Makes the given viewport the default.
void pfSetScaleXY(SUMOReal sx, SUMOReal sy)
SUMOReal gridXSize
Information about the grid spacings.
std::map< SUMOTime, std::string > mySnapshots
static FXbool saveImage(const std::string &file, int width, int height, FXColor *data)
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
void updatePositionInformation() const
static void drawTextBox(const std::string &text, const Position &pos, const SUMOReal layer, const SUMOReal size, const RGBColor &txtColor=RGBColor::BLACK, const RGBColor &bgColor=RGBColor::WHITE, const RGBColor &borderColor=RGBColor::BLACK, const SUMOReal angle=0)
draw Text box with given parameters
SUMOReal getDelay() const
Returns the delay of the parent application.
GUIPerspectiveChanger * myChanger
The perspective changer.
std::string makeSnapshot(const std::string &destFile)
Takes a snapshots and writes it into the given file.
virtual void onLeftBtnPress(void *data)
GUIGLObjectPopupMenu * myPopup
The current popup-menu.
RGBColor backgroundColor
The background color to use.
void destroyPopup()
destoys the popup
bool antialiase
Information whether antialiase shall be enabled.
FXint myWindowCursorPositionX
Position of the cursor relative to the window.
Boundary getViewport(bool fixRatio=true)
void unlock()
release mutex lock
virtual void showViewportEditor()
FXbool makeCurrent()
A reimplementation due to some internal reasons.
SUMOReal height
The height of the image (net coordinates in y-direction, in m)
void applyGLTransform(bool fixRatio=true)
virtual long onLeftBtnRelease(FXObject *, FXSelector, void *)
void add(SUMOReal x, SUMOReal y)
Makes the boundary include the given coordinate.
SUMOReal centerX
The center of the image in x-direction (net coordinates, in m)
GUIVisualizationSettings & getDefault()
Returns the default scheme.
Boundary & grow(SUMOReal by)
extends the boundary by the given amount
void setViewport(GUISUMOAbstractView *view)
Sets the default viewport.
GUIVisualizationSettings * myVisualizationSettings
virtual void onMouseWheel(void *data)
SUMOReal m2p(SUMOReal meter) const
meter-to-pixels conversion method
void paintGL()
performs the painting of the simulation
virtual long onKeyPress(void *data)
SUMOReal y() const
Returns the y-position.
void setWindowCursorPosition(FXint x, FXint y)
Returns the information whether rotation is allowd.
void setCurrent(GUIVisualizationSettings *settings)
Sets current settings (called if reopened)
static FXImage * loadImage(FXApp *a, const std::string &file)
SUMOReal getGridWidth() const
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
bool showGrid
Information whether a grid shall be shown.
void drawDecals()
Draws the stored decals.
static int getMaxTextureSize()
return maximum number of pixels in x and y direction
SUMOReal layer
The layer of the image.
virtual int Search(const float a_min[2], const float a_max[2], const GUIVisualizationSettings &c) const
Find all within search rectangle.
virtual void centerTo(const Position &pos, SUMOReal radius, bool applyZoom=true)=0
Centers the view to the given position, setting it to a size that covers the radius. Used for: Centering of vehicles and junctions.
void setDelay(SUMOReal delay)
Sets the delay of the parent application.
bool skip2D
Whether this image should be skipped in 2D-views.
unsigned char green() const
Returns the green-amount of the color.
virtual void onMouseMove(void *data)
void updateToolTip()
A method that updates the tooltip.
A dialog to change the viewport.
SUMOReal ymax() const
Returns maximum y-coordinate.
virtual void onRightBtnPress(void *data)
virtual void onGamingClick(Position)
void unblockObject(GUIGlID id)
Marks an object as unblocked.
virtual SUMOReal getYPos() const =0
Returns the y-offset of the field to show stored in this changer.
void showViewschemeEditor()
virtual long onRightBtnPress(FXObject *, FXSelector, void *)
bool haveGrabbed() const
Returns the information whether one of the spin dialers is grabbed.
virtual long onMouseLeft(FXObject *, FXSelector, void *)
Position getPositionInformation() const
Returns the cursor's x/y position within the network.
GUIGlID getObjectUnderCursor()
returns the id of the object under the cursor using GL_SELECT
bool drawForSelecting
whether drawing is performed for the purpose of selecting objects
#define WRITE_MESSAGE(msg)
GUIGlObject * getObjectBlocking(GUIGlID id)
Returns the object from the container locking it.
virtual long onKeyRelease(void *data)
const std::string & getFullName() const
Returns the full name appearing in the tool tip.
unsigned char red() const
Returns the red-amount of the color.
GUISelectedStorage gSelected
A global holder of selected objects.
FXDEFMAP(GUISUMOAbstractView) GUISUMOAbstractViewMap[]
SUMOReal rot
The rotation of the image in the ground plane (in degrees)
GUIGlChildWindow * myParent
The parent window.
virtual long onRightBtnRelease(FXObject *, FXSelector, void *)
static const Position INVALID
std::vector< GUIGlID > getObjectsInBoundary(const Boundary &bound)
returns the ids of all objects in the given boundary
void setOldValues(const Position &lookFrom, const Position &lookAt)
Resets old values.