SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00010 // The base class for a view 00011 /****************************************************************************/ 00012 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00013 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00014 /****************************************************************************/ 00015 // 00016 // This file is part of SUMO. 00017 // SUMO is free software: you can redistribute it and/or modify 00018 // it under the terms of the GNU General Public License as published by 00019 // the Free Software Foundation, either version 3 of the License, or 00020 // (at your option) any later version. 00021 // 00022 /****************************************************************************/ 00023 #ifndef GUISUMOAbstractView_h 00024 #define GUISUMOAbstractView_h 00025 00026 00027 // =========================================================================== 00028 // included modules 00029 // =========================================================================== 00030 #ifdef _MSC_VER 00031 #include <windows_config.h> 00032 #else 00033 #include <config.h> 00034 #endif 00035 00036 #include <string> 00037 #include <vector> 00038 #include <map> 00039 #include <fx.h> 00040 #include <fx3d.h> 00041 #include <utils/foxtools/MFXMutex.h> 00042 #include <utils/geom/Boundary.h> 00043 #include <utils/geom/Position.h> 00044 #include <utils/common/RGBColor.h> 00045 #include <utils/common/SUMOTime.h> 00046 #include <utils/shapes/Polygon.h> 00047 #include <utils/gui/globjects/GUIGlObjectTypes.h> 00048 #include <foreign/rtree/SUMORTree.h> 00049 00050 00051 // =========================================================================== 00052 // class declarations 00053 // =========================================================================== 00054 class GUIGlChildWindow; 00055 class GUIVehicle; 00056 class GUIPerspectiveChanger; 00057 class GUIMainWindow; 00058 class GUIGLObjectPopupMenu; 00059 class GUIGlObject; 00060 class GUIDialog_EditViewport; 00061 class GUIDialog_ViewSettings; 00062 class GUIVisualizationSettings; 00063 00064 00065 // =========================================================================== 00066 // class definitions 00067 // =========================================================================== 00074 class GUISUMOAbstractView : public FXGLCanvas { 00075 FXDECLARE(GUISUMOAbstractView) 00076 public: 00078 GUISUMOAbstractView(FXComposite* p, GUIMainWindow& app, 00079 GUIGlChildWindow* parent, const SUMORTree& grid, 00080 FXGLVisual* glVis, FXGLCanvas* share); 00081 00083 virtual ~GUISUMOAbstractView(); 00084 00086 virtual void buildViewToolBars(GUIGlChildWindow&) { } 00087 00089 void recenterView(); 00090 00097 void centerTo(GUIGlID id, bool applyZoom, SUMOReal zoomDist = 20); 00098 00100 void centerTo(const Boundary& bound); 00101 00103 virtual void setViewport(SUMOReal zoom, SUMOReal xPos, SUMOReal yPos); 00104 00106 SUMOReal m2p(SUMOReal meter) const; 00107 00109 SUMOReal p2m(SUMOReal pixel) const; 00110 00112 // bool allowRotation() const; 00113 00115 void setWindowCursorPosition(FXint x, FXint y); 00116 00118 FXbool makeCurrent(); 00119 00121 bool isInEditMode(); 00122 00123 GUIPerspectiveChanger& getChanger() const { 00124 return *myChanger; 00125 } 00126 00127 Boundary getVisibleBoundary() const; 00128 00129 virtual long onConfigure(FXObject*, FXSelector, void*); 00130 virtual long onPaint(FXObject*, FXSelector, void*); 00131 virtual long onLeftBtnPress(FXObject*, FXSelector, void*); 00132 virtual long onLeftBtnRelease(FXObject*, FXSelector, void*); 00133 virtual long onRightBtnPress(FXObject*, FXSelector, void*); 00134 virtual long onRightBtnRelease(FXObject*, FXSelector, void*); 00135 virtual long onMouseWheel(FXObject*, FXSelector, void*); 00136 virtual long onMouseMove(FXObject*, FXSelector, void*); 00137 virtual long onMouseLeft(FXObject*, FXSelector, void*); 00138 00139 virtual long onKeyPress(FXObject* o, FXSelector sel, void* data); 00140 virtual long onKeyRelease(FXObject* o, FXSelector sel, void* data); 00141 00142 00143 virtual void openObjectDialog(); 00144 00146 void updateToolTip(); 00147 00148 00151 00155 void setSnapshots(std::map<SUMOTime, std::string> snaps); 00156 00157 00164 std::string makeSnapshot(const std::string& destFile); 00165 00166 00169 void checkSnapshots(); 00170 00172 virtual SUMOTime getCurrentTimeStep() const { 00173 return 0; 00174 } 00176 00177 00178 00179 void showViewportEditor(); 00180 virtual void showViewschemeEditor() = 0; 00181 void showToolTips(bool val); 00182 virtual bool setColorScheme(const std::string&) { 00183 return true; 00184 } 00185 00186 void remove(GUIDialog_EditViewport*) { 00187 myViewportChooser = 0; 00188 } 00189 00190 void remove(GUIDialog_ViewSettings*) { 00191 myVisualizationChanger = 0; 00192 } 00193 00194 00195 // @todo: check why this is here 00196 SUMOReal getGridWidth() const; 00197 // @todo: check why this is here 00198 SUMOReal getGridHeight() const; 00199 00200 virtual void startTrack(int /*id*/) { } 00201 virtual void stopTrack() { } 00202 virtual int getTrackedID() const { 00203 return -1; 00204 } 00205 00206 virtual void onGamingClick(Position /*pos*/) { } 00207 00210 00216 bool addAdditionalGLVisualisation(GUIGlObject* const which); 00217 00218 00224 bool removeAdditionalGLVisualisation(GUIGlObject* const which); 00226 00227 00229 void destroyPopup(); 00230 00231 00232 public: 00237 enum JunctionColoringScheme { 00239 VCS_BY_TYPE = 0 00240 }; 00241 00242 00246 struct Decal { 00248 Decal() 00249 : filename(), centerX(0), centerY(0), 00250 width(1000), height(1000), rot(0), 00251 initialised(false), glID(-1) { } 00252 00254 std::string filename; 00256 SUMOReal centerX; 00258 SUMOReal centerY; 00260 SUMOReal width; 00262 SUMOReal height; 00264 SUMOReal rot; 00266 bool initialised; 00268 int glID; 00269 }; 00270 00271 00272 public: 00273 FXComboBox& getColoringSchemesCombo(); 00274 00275 00279 Position getPositionInformation() const; 00280 00281 void addDecals(const std::vector<Decal> &decals) { 00282 myDecals.insert(myDecals.end(), decals.begin(), decals.end()); 00283 } 00284 00285 00286 const GUIVisualizationSettings* getVisualisationSettings() { 00287 return myVisualizationSettings; 00288 } 00289 00290 00291 protected: 00293 void paintGL(); 00294 00295 void updatePositionInformation() const; 00296 00297 00298 virtual int doPaintGL(int /*mode*/, const Boundary& /*boundary*/) { 00299 return 0; 00300 } 00301 00302 virtual void doInit() { } 00303 00305 void paintGLGrid(); 00306 00311 void displayLegend(); 00312 00313 00315 GUIGlID getObjectUnderCursor(); 00316 00318 GUIGlID getObjectAtPosition(Position pos); 00319 00321 std::vector<GUIGlID> getObjectsInBoundary(const Boundary& bound); 00322 00324 void showToolTipFor(unsigned int id); 00325 00326 00327 protected: 00330 void drawDecals(); 00331 00332 // applies gl-transformations to fit the Boundary given by myChanger onto 00333 // the canvas. If fixRatio is true, this boundary will be enlarged to 00334 // prevent anisotropic stretching. (this should be set to false when doing 00335 // selections) 00336 void applyGLTransform(bool fixRatio = true); 00337 00338 protected: 00340 GUIMainWindow* myApp; 00341 00343 GUIGlChildWindow* myParent; 00344 00346 SUMORTree* myGrid; 00347 00349 GUIPerspectiveChanger* myChanger; 00350 00352 bool myInEditMode; 00353 00355 FXint myWindowCursorPositionX, myWindowCursorPositionY; 00356 00358 int myMouseHotspotX, myMouseHotspotY; 00359 00361 GUIGLObjectPopupMenu* myPopup; 00362 00363 GUIVisualizationSettings* myVisualizationSettings; 00364 00365 bool myUseToolTips; 00366 00368 bool myAmInitialised; 00369 00370 00371 GUIDialog_EditViewport* myViewportChooser; 00372 GUIDialog_ViewSettings* myVisualizationChanger; 00373 00374 00377 00379 std::vector<Decal> myDecals; 00380 00382 MFXMutex myDecalsLock; 00384 00385 00386 std::map<SUMOTime, std::string> mySnapshots; 00387 00388 mutable MFXMutex myPolyDrawLock; 00389 00391 std::map<GUIGlObject*, int> myAdditionallyDrawn; 00392 00393 00394 protected: 00395 GUISUMOAbstractView() { } 00396 00397 }; 00398 00399 00400 #endif 00401 00402 /****************************************************************************/ 00403