#include <config.h>
#include <string>
#include <map>
#include <fstream>
#include <utils/options/OptionsCont.h>
#include <utils/options/Option.h>
#include <utils/common/MsgHandler.h>
#include <utils/common/FileHelpers.h>
#include <utils/common/RGBColor.h>
#include <utils/common/StdDefs.h>
#include <utils/common/SysUtils.h>
#include <polyconvert/PCPolyContainer.h>
#include <utils/geom/GeomHelper.h>
#include <utils/geom/Boundary.h>
#include <utils/geom/Position.h>
#include <utils/geom/GeoConvHelper.h>
#include <utils/xml/XMLSubSys.h>
#include <utils/geom/GeomConvHelper.h>
#include <utils/xml/SUMOXMLDefinitions.h>
#include "PCLoaderXML.h"
void
PCLoaderXML::loadIfSet(OptionsCont& oc, PCPolyContainer& toFill,
PCTypeMap& tm) {
if (!oc.isSet("xml-files")) {
return;
}
PCLoaderXML handler(toFill, tm, oc);
std::vector<std::string> files = oc.getStringVector("xml");
for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
if (!FileHelpers::isReadable(*file)) {
throw ProcessError(TLF("Could not open xml-file '%'.", *file));
}
const long before = PROGRESS_BEGIN_TIME_MESSAGE("Parsing XML from '" + *file + "'");
if (!XMLSubSys::runParser(handler, *file)) {
throw ProcessError();
}
PROGRESS_TIME_MESSAGE(before);
}
}
PCLoaderXML::PCLoaderXML(PCPolyContainer& toFill,
PCTypeMap& tm, OptionsCont& oc)
: ShapeHandler("xml-poi-definition", toFill),
myTypeMap(tm), myOptions(oc) {}
PCLoaderXML::~PCLoaderXML() {}
void
PCLoaderXML::myStartElement(int element,
const SUMOSAXAttributes& attrs) {
if (element != SUMO_TAG_POI && element != SUMO_TAG_POLY) {
return;
}
bool ok = true;
std::string id = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
std::string type = attrs.getOpt<std::string>(SUMO_ATTR_TYPE, id.c_str(), ok, myOptions.getString("type"));
if (!ok) {
return;
}
bool discard = myOptions.getBool("discard");
if (myTypeMap.has(type)) {
const PCTypeMap::TypeDef& def = myTypeMap.get(type);
discard = def.discard;
setDefaults(def.prefix, def.color, def.icon, def.layer, def.allowFill != PCTypeMap::Filltype::NOFILL);
} else {
setDefaults(myOptions.getString("prefix"), RGBColor::parseColor(myOptions.getString("color")),
myOptions.getString("icon"), myOptions.getFloat("layer"), myOptions.getBool("fill"));
}
if (!discard) {
if (element == SUMO_TAG_POI) {
addPOI(attrs, myOptions.isInStringVector("prune.keep-list", id), true);
}
if (element == SUMO_TAG_POLY) {
addPoly(attrs, myOptions.isInStringVector("prune.keep-list", id), true);
}
}
}
Position
PCLoaderXML::getLanePos(const std::string& poiID, const std::string& laneID, double lanePos, bool friendlyPos, double lanePosLat) {
static_cast<PCPolyContainer&>(myShapeContainer).addLanePos(poiID, laneID, lanePos, friendlyPos, lanePosLat);
return Position::INVALID;
}