NLGeomShapeBuilder.cpp
Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029
00030 #include <string>
00031 #include <utils/common/RGBColor.h>
00032 #include <utils/geom/Position2D.h>
00033 #include <utils/geom/Position2DVector.h>
00034 #include <utils/shapes/Polygon2D.h>
00035 #include <utils/shapes/PointOfInterest.h>
00036 #include <utils/shapes/ShapeContainer.h>
00037 #include "NLGeomShapeBuilder.h"
00038 #include <utils/common/UtilExceptions.h>
00039 #include <microsim/MSNet.h>
00040 #include <microsim/MSLane.h>
00041
00042 #ifdef CHECK_MEMORY_LEAKS
00043 #include <foreign/nvwa/debug_new.h>
00044 #endif // CHECK_MEMORY_LEAKS
00045
00046
00047
00048
00049
00050 NLGeomShapeBuilder::NLGeomShapeBuilder(MSNet &net) throw()
00051 : myShapeContainer(net.getShapeContainer()) {}
00052
00053
00054 NLGeomShapeBuilder::~NLGeomShapeBuilder() throw() {}
00055
00056
00057 void
00058 NLGeomShapeBuilder::polygonBegin(const std::string &name,
00059 int layer,
00060 const std::string &type,
00061 const RGBColor &c,
00062 bool fill) throw() {
00063 myCurrentName = name;
00064 myCurrentType = type;
00065 myCurrentColor = c;
00066 myCurrentLayer = layer;
00067 myFillPoly = fill;
00068 }
00069
00070
00071 void
00072 NLGeomShapeBuilder::polygonEnd(const Position2DVector &shape) throw(InvalidArgument) {
00073 Polygon2D *p =
00074 new Polygon2D(myCurrentName, myCurrentType, myCurrentColor, shape, myFillPoly);
00075 if (!myShapeContainer.add(myCurrentLayer, p)) {
00076 delete p;
00077 throw InvalidArgument("A duplicate of the polygon '" + myCurrentName + "' occured.");
00078 }
00079 }
00080
00081
00082 void
00083 NLGeomShapeBuilder::addPoint(const std::string &name,
00084 int layer,
00085 const std::string &type,
00086 const RGBColor &c,
00087 SUMOReal x, SUMOReal y,
00088 const std::string &lane, SUMOReal posOnLane) throw(InvalidArgument) {
00089 Position2D pos = getPointPosition(x, y, lane, posOnLane);
00090 PointOfInterest *p = new PointOfInterest(name, type, pos, c);
00091 if (!myShapeContainer.add(layer, p)) {
00092 delete p;
00093 throw InvalidArgument("A duplicate of the POI '" + name + "' occured.");
00094 }
00095 }
00096
00097
00098 Position2D
00099 NLGeomShapeBuilder::getPointPosition(SUMOReal x, SUMOReal y,
00100 const std::string &laneID,
00101 SUMOReal posOnLane) const throw(InvalidArgument) {
00102 if (x!=INVALID_POSITION&&y!=INVALID_POSITION) {
00103 return Position2D(x,y);
00104 }
00105 MSLane *lane = MSLane::dictionary(laneID);
00106 if (lane==0) {
00107 throw InvalidArgument("Lane '" + laneID + "' to place a poi on is not known.");
00108 }
00109 if (posOnLane<0) {
00110 posOnLane = lane->getLength() + posOnLane;
00111 }
00112 return lane->getShape().positionAtLengthPosition(posOnLane);
00113 }
00114
00115
00116
00117
00118