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