|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // Base class for all objects that may be displayed within the openGL-gui 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 00020 00021 // =========================================================================== 00022 // included modules 00023 // =========================================================================== 00024 #ifdef _MSC_VER 00025 #include <windows_config.h> 00026 #else 00027 #include <config.h> 00028 #endif 00029 00030 #ifdef WIN32 00031 #include <windows.h> 00032 #endif 00033 00034 #include <GL/gl.h> 00035 00036 #include <string> 00037 #include <stack> 00038 #include <utils/common/ToString.h> 00039 #include <utils/geom/GeoConvHelper.h> 00040 #include <utils/gui/windows/GUISUMOAbstractView.h> 00041 #include <utils/gui/globjects/GUIGLObjectPopupMenu.h> 00042 #include <utils/gui/div/GUIParameterTableWindow.h> 00043 #include <utils/foxtools/MFXMenuHeader.h> 00044 #include <utils/gui/images/GUIIconSubSys.h> 00045 #include <utils/gui/windows/GUIAppEnum.h> 00046 #include <utils/gui/windows/GUIMainWindow.h> 00047 #include <utils/gui/div/GUIGlobalSelection.h> 00048 #include <utils/gui/div/GLHelper.h> 00049 #include "GUIGlObject.h" 00050 #include "GUIGlObjectStorage.h" 00051 00052 #ifdef CHECK_MEMORY_LEAKS 00053 #include <foreign/nvwa/debug_new.h> 00054 #endif // CHECK_MEMORY_LEAKS 00055 00056 // =========================================================================== 00057 // static members 00058 // =========================================================================== 00059 StringBijection<GUIGlObjectType>::Entry GUIGlObject::GUIGlObjectTypeNamesInitializer[] = { 00060 {"network", GLO_NETWORK}, 00061 {"edge", GLO_EDGE}, 00062 {"lane", GLO_LANE}, 00063 {"junction", GLO_JUNCTION}, 00064 {"tlLogic", GLO_TLLOGIC}, 00065 {"detector", GLO_DETECTOR}, 00066 {"trigger", GLO_TRIGGER}, 00067 {"shape", GLO_SHAPE}, 00068 {"vehicle", GLO_VEHICLE}, 00069 {"additional", GLO_ADDITIONAL}, 00070 {"undefined", GLO_MAX} 00071 }; 00072 00073 00074 StringBijection<GUIGlObjectType> GUIGlObject::TypeNames( 00075 GUIGlObjectTypeNamesInitializer, GLO_MAX); 00076 00077 // =========================================================================== 00078 // method definitions 00079 // =========================================================================== 00080 GUIGlObject::GUIGlObject(GUIGlObjectType type, const std::string& microsimID) : 00081 myGLObjectType(type), 00082 myMicrosimID(microsimID), 00083 myPrefix(TypeNames.getString(type)) { 00084 myFullName = createFullName(); 00085 myGlID = GUIGlObjectStorage::gIDStorage.registerObject(this, myFullName); 00086 } 00087 00088 00089 GUIGlObject::GUIGlObject(const std::string& prefix, GUIGlObjectType type, const std::string& microsimID) : 00090 myGLObjectType(type), 00091 myMicrosimID(microsimID), 00092 myPrefix(prefix) { 00093 myFullName = createFullName(); 00094 myGlID = GUIGlObjectStorage::gIDStorage.registerObject(this, myFullName); 00095 } 00096 00097 00098 00099 GUIGlObject::~GUIGlObject() throw() { 00100 for (std::set<GUIParameterTableWindow*>::iterator i=myParamWindows.begin(); i!=myParamWindows.end(); ++i) { 00101 (*i)->removeObject(this); 00102 } 00103 GUIGlObjectStorage::gIDStorage.remove(getGlID()); 00104 } 00105 00106 00107 void 00108 GUIGlObject::setMicrosimID(const std::string& newID) { 00109 myMicrosimID = newID; 00110 myFullName = createFullName(); 00111 } 00112 00113 00114 void 00115 GUIGlObject::buildPopupHeader(GUIGLObjectPopupMenu* ret, GUIMainWindow& app, 00116 bool addSeparator) throw() { 00117 new MFXMenuHeader(ret, app.getBoldFont(), getFullName().c_str(), 0, 0, 0); 00118 if (addSeparator) { 00119 new FXMenuSeparator(ret); 00120 } 00121 } 00122 00123 00124 void 00125 GUIGlObject::buildCenterPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator) throw() { 00126 new FXMenuCommand(ret, "Center", GUIIconSubSys::getIcon(ICON_RECENTERVIEW), ret, MID_CENTER); 00127 if (addSeparator) { 00128 new FXMenuSeparator(ret); 00129 } 00130 } 00131 00132 00133 void 00134 GUIGlObject::buildNameCopyPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator) throw() { 00135 new FXMenuCommand(ret, "Copy name to clipboard", 0, ret, MID_COPY_NAME); 00136 new FXMenuCommand(ret, "Copy typed name to clipboard", 0, ret, MID_COPY_TYPED_NAME); 00137 if (addSeparator) { 00138 new FXMenuSeparator(ret); 00139 } 00140 } 00141 00142 00143 void 00144 GUIGlObject::buildSelectionPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator) throw() { 00145 if (gSelected.isSelected(getType(), getGlID())) { 00146 new FXMenuCommand(ret, "Remove From Selected", GUIIconSubSys::getIcon(ICON_FLAG_MINUS), ret, MID_REMOVESELECT); 00147 } else { 00148 new FXMenuCommand(ret, "Add To Selected", GUIIconSubSys::getIcon(ICON_FLAG_PLUS), ret, MID_ADDSELECT); 00149 } 00150 if (addSeparator) { 00151 new FXMenuSeparator(ret); 00152 } 00153 } 00154 00155 00156 void 00157 GUIGlObject::buildShowParamsPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator) throw() { 00158 new FXMenuCommand(ret, "Show Parameter", GUIIconSubSys::getIcon(ICON_APP_TABLE), ret, MID_SHOWPARS); 00159 if (addSeparator) { 00160 new FXMenuSeparator(ret); 00161 } 00162 } 00163 00164 00165 void 00166 GUIGlObject::buildPositionCopyEntry(GUIGLObjectPopupMenu* ret, bool addSeparator) throw() { 00167 new FXMenuCommand(ret, "Copy cursor position to clipboard", 0, ret, MID_COPY_CURSOR_POSITION); 00168 if (GeoConvHelper::getDefaultInstance().usingGeoProjection()) { 00169 new FXMenuCommand(ret, "Copy cursor geo-position to clipboard", 0, ret, MID_COPY_CURSOR_GEOPOSITION); 00170 } 00171 if (addSeparator) { 00172 new FXMenuSeparator(ret); 00173 } 00174 } 00175 00176 00177 void 00178 GUIGlObject::buildShowManipulatorPopupEntry(GUIGLObjectPopupMenu* ret, bool addSeparator) throw() { 00179 new FXMenuCommand(ret, "Open Manipulator...", GUIIconSubSys::getIcon(ICON_MANIP), ret, MID_MANIP); 00180 if (addSeparator) { 00181 new FXMenuSeparator(ret); 00182 } 00183 } 00184 00185 00186 void 00187 GUIGlObject::addParameterTable(GUIParameterTableWindow* t) throw() { 00188 myParamWindows.insert(t); 00189 } 00190 00191 00192 void 00193 GUIGlObject::removeParameterTable(GUIParameterTableWindow* t) throw() { 00194 std::set<GUIParameterTableWindow*>::iterator i=myParamWindows.find(t); 00195 if (i!=myParamWindows.end()) { 00196 myParamWindows.erase(i); 00197 } 00198 } 00199 00200 00201 void 00202 GUIGlObject::setPrefix(const std::string& prefix) { 00203 myPrefix = prefix; 00204 myFullName = createFullName(); 00205 } 00206 00207 std::string 00208 GUIGlObject::createFullName() const { 00209 return myPrefix + ":" + getMicrosimID(); 00210 } 00211 00212 00213 void 00214 GUIGlObject::drawName(const Position& pos, const SUMOReal scale, 00215 const GUIVisualizationTextSettings& settings, const SUMOReal angle) const { 00216 if (settings.show) { 00217 GLHelper::drawText(getMicrosimID(), pos, GLO_MAX, settings.size / scale, settings.color, angle); 00218 } 00219 } 00220 00221 /****************************************************************************/ 00222