SUMO - Simulation of Urban MObility

GUISUMOAbstractView.h

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // The base class for a view
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This program is free software; you can redistribute it and/or modify
00014 //   it under the terms of the GNU General Public License as published by
00015 //   the Free Software Foundation; either version 2 of the License, or
00016 //   (at your option) any later version.
00017 //
00018 /****************************************************************************/
00019 #ifndef GUISUMOAbstractView_h
00020 #define GUISUMOAbstractView_h
00021 
00022 
00023 // ===========================================================================
00024 // included modules
00025 // ===========================================================================
00026 #ifdef _MSC_VER
00027 #include <windows_config.h>
00028 #else
00029 #include <config.h>
00030 #endif
00031 
00032 #include <string>
00033 #include <vector>
00034 #include <map>
00035 #include <fx.h>
00036 #include <fx3d.h>
00037 #include <utils/foxtools/MFXMutex.h>
00038 #include <utils/geom/Boundary.h>
00039 #include <utils/geom/Position.h>
00040 #include <utils/common/RGBColor.h>
00041 #include <utils/common/SUMOTime.h>
00042 #include <utils/shapes/Polygon.h>
00043 #include <utils/gui/globjects/GUIGlObjectTypes.h>
00044 #include <foreign/rtree/SUMORTree.h>
00045 
00046 
00047 // ===========================================================================
00048 // class declarations
00049 // ===========================================================================
00050 class GUIGlChildWindow;
00051 class GUIVehicle;
00052 class GUIPerspectiveChanger;
00053 class GUIMainWindow;
00054 class GUIGLObjectPopupMenu;
00055 class GUIGlObject;
00056 class GUIDialog_EditViewport;
00057 class GUIDialog_ViewSettings;
00058 class GUIVisualizationSettings;
00059 
00060 
00061 // ===========================================================================
00062 // class definitions
00063 // ===========================================================================
00070 class GUISUMOAbstractView : public FXGLCanvas {
00071     FXDECLARE(GUISUMOAbstractView)
00072 public:
00074     GUISUMOAbstractView(FXComposite* p, GUIMainWindow& app,
00075                         GUIGlChildWindow* parent, const SUMORTree& grid,
00076                         FXGLVisual* glVis, FXGLCanvas* share);
00077 
00079     virtual ~GUISUMOAbstractView();
00080 
00082     virtual void buildViewToolBars(GUIGlChildWindow&) { }
00083 
00085     void recenterView();
00086 
00092     void centerTo(GUIGlID id, bool applyZoom, SUMOReal zoomDist=20);
00093 
00095     void centerTo(const Boundary& bound);
00096 
00098     virtual void setViewport(SUMOReal zoom, SUMOReal xPos, SUMOReal yPos);
00099 
00101     SUMOReal m2p(SUMOReal meter) const;
00102 
00104     SUMOReal p2m(SUMOReal pixel) const;
00105 
00107 //    bool allowRotation() const;
00108 
00110     void setWindowCursorPosition(FXint x, FXint y);
00111 
00113     FXbool makeCurrent();
00114 
00116     bool isInEditMode();
00117 
00118     GUIPerspectiveChanger& getChanger() const {
00119         return *myChanger;
00120     }
00121 
00122     Boundary getVisibleBoundary() const;
00123 
00124     long onConfigure(FXObject*,FXSelector,void*);
00125     long onPaint(FXObject*,FXSelector,void*);
00126     virtual long onLeftBtnPress(FXObject*,FXSelector,void*);
00127     virtual long onLeftBtnRelease(FXObject*,FXSelector,void*);
00128     virtual long onRightBtnPress(FXObject*,FXSelector,void*);
00129     virtual long onRightBtnRelease(FXObject*,FXSelector,void*);
00130     virtual long onMouseWheel(FXObject*,FXSelector,void*);
00131     virtual long onMouseMove(FXObject*,FXSelector,void*);
00132     virtual long onMouseLeft(FXObject*,FXSelector,void*);
00133 
00134     long onKeyPress(FXObject* o,FXSelector sel,void* data);
00135     long onKeyRelease(FXObject* o,FXSelector sel,void* data);
00136 
00137 
00138     virtual void openObjectDialog();
00139 
00141     void updateToolTip();
00142 
00143 
00146 
00150     void setSnapshots(std::map<SUMOTime, std::string> snaps);
00151 
00152 
00159     std::string makeSnapshot(const std::string& destFile);
00160 
00161 
00164     void checkSnapshots();
00165 
00167     virtual SUMOTime getCurrentTimeStep() const {
00168         return 0;
00169     }
00171 
00172 
00173 
00174     void showViewportEditor();
00175     virtual void showViewschemeEditor() = 0;
00176     void showToolTips(bool val);
00177     virtual bool setColorScheme(const std::string&) {
00178         return true;
00179     }
00180 
00181     void remove(GUIDialog_EditViewport*) {
00182         myViewportChooser = 0;
00183     }
00184 
00185     void remove(GUIDialog_ViewSettings*) {
00186         myVisualizationChanger = 0;
00187     }
00188 
00189 
00190     // @todo: check why this is here
00191     SUMOReal getGridWidth() const;
00192     // @todo: check why this is here
00193     SUMOReal getGridHeight() const;
00194 
00195     virtual void startTrack(int /*id*/) { }
00196     virtual void stopTrack() { }
00197     virtual int getTrackedID() const {
00198         return -1;
00199     }
00200 
00201     virtual void onGamingClick(Position /*pos*/) { }
00202 
00205 
00211     bool addAdditionalGLVisualisation(GUIGlObject* const which);
00212 
00213 
00219     bool removeAdditionalGLVisualisation(GUIGlObject* const which);
00221 
00222 
00224     void destroyPopup();
00225 
00226 
00227 public:
00232     enum JunctionColoringScheme {
00234         VCS_BY_TYPE = 0
00235     };
00236 
00237 
00241     struct Decal {
00243         Decal()
00244             : filename(), centerX(0), centerY(0),
00245               width(1000), height(1000), rot(0),
00246               initialised(false), glID(-1) { }
00247 
00249         std::string filename;
00251         SUMOReal centerX;
00253         SUMOReal centerY;
00255         SUMOReal width;
00257         SUMOReal height;
00259         SUMOReal rot;
00261         bool initialised;
00263         int glID;
00264     };
00265 
00266 
00267 public:
00268     FXComboBox& getColoringSchemesCombo();
00269 
00270 
00274     Position getPositionInformation() const;
00275 
00276     void addDecals(const std::vector<Decal> &decals) {
00277         myDecals.insert(myDecals.end(), decals.begin(), decals.end());
00278     }
00279 
00280 
00281     const GUIVisualizationSettings* getVisualisationSettings() {
00282         return myVisualizationSettings;
00283     }
00284 
00285 
00286 protected:
00288     void paintGL();
00289 
00290     void updatePositionInformation() const;
00291 
00292 
00293     virtual int doPaintGL(int /*mode*/, const Boundary& /*boundary*/) {
00294         return 0;
00295     }
00296 
00297     virtual void doInit() { }
00298 
00300     void paintGLGrid();
00301 
00306     void displayLegend();
00307 
00308 
00310     GUIGlID getObjectUnderCursor();
00311 
00313     GUIGlID getObjectAtPosition(Position pos);
00314 
00316     std::vector<GUIGlID> getObjectsInBoundary(const Boundary& bound);
00317 
00319     void showToolTipFor(unsigned int id);
00320 
00321 
00322 protected:
00325     void drawDecals();
00326 
00327     // applies gl-transformations to fit the Boundary given by myChanger onto
00328     // the canvas. If fixRatio is true, this boundary will be enlarged to
00329     // prevent anisotropic stretching. (this should be set to false when doing
00330     // selections)
00331     void applyGLTransform(bool fixRatio=true);
00332 
00333 protected:
00335     GUIMainWindow* myApp;
00336 
00338     GUIGlChildWindow* myParent;
00339 
00341     SUMORTree* myGrid;
00342 
00344     GUIPerspectiveChanger* myChanger;
00345 
00347     bool myInEditMode;
00348 
00350     FXint myWindowCursorPositionX, myWindowCursorPositionY;
00351 
00353     int myMouseHotspotX, myMouseHotspotY;
00354 
00356     GUIGLObjectPopupMenu* myPopup;
00357 
00358     GUIVisualizationSettings* myVisualizationSettings;
00359 
00360     bool myUseToolTips;
00361 
00363     bool myAmInitialised;
00364 
00365 
00366     GUIDialog_EditViewport* myViewportChooser;
00367     GUIDialog_ViewSettings* myVisualizationChanger;
00368 
00369 
00372 
00374     std::vector<Decal> myDecals;
00375 
00377     MFXMutex myDecalsLock;
00379 
00380 
00381     std::map<SUMOTime, std::string> mySnapshots;
00382 
00383     mutable MFXMutex myPolyDrawLock;
00384 
00386     std::map<GUIGlObject*, int> myAdditionallyDrawn;
00387 
00388 
00389 protected:
00390     GUISUMOAbstractView() { }
00391 
00392 };
00393 
00394 
00395 #endif
00396 
00397 /****************************************************************************/
00398 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines