Path: blob/main/src/polyconvert/PCNetProjectionLoader.cpp
169665 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file PCNetProjectionLoader.cpp14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @author Michael Behrisch17/// @date Thu, 02.11.200618///19// A reader for a SUMO network's projection description20/****************************************************************************/21#include <config.h>2223#include <string>24#include <map>25#include <fstream>26#include <utils/options/OptionsCont.h>27#include <utils/options/Option.h>28#include <utils/common/FileHelpers.h>29#include <utils/common/MsgHandler.h>30#include <utils/common/RGBColor.h>31#include <utils/common/StdDefs.h>32#include <utils/common/SysUtils.h>33#include <utils/geom/GeomHelper.h>34#include <utils/geom/Boundary.h>35#include <utils/geom/Position.h>36#include <utils/geom/GeoConvHelper.h>37#include <utils/xml/XMLSubSys.h>38#include <utils/xml/SUMOXMLDefinitions.h>39#include <utils/xml/SUMOSAXReader.h>40#include <utils/geom/GeomConvHelper.h>41#include <polyconvert/PCPolyContainer.h>42#include "PCNetProjectionLoader.h"434445// ===========================================================================46// method definitions47// ===========================================================================48// ---------------------------------------------------------------------------49// static interface50// ---------------------------------------------------------------------------51void52PCNetProjectionLoader::load(const std::string& file, double scale) {53if (!FileHelpers::isReadable(file)) {54throw ProcessError(TLF("Could not open net-file '%'.", file));55}56// build handler and parser57PCNetProjectionLoader handler(scale);58handler.setFileName(file);59SUMOSAXReader* parser = XMLSubSys::getSAXReader(handler, true);60const long before = PROGRESS_BEGIN_TIME_MESSAGE("Parsing network projection from '" + file + "'");61if (!parser->parseFirst(file)) {62delete parser;63throw ProcessError(TLF("Can not read XML-file '%'.", handler.getFileName()));64}65// parse66while (parser->parseNext() && !handler.hasReadAll());67// clean up68PROGRESS_TIME_MESSAGE(before);69if (!handler.hasReadAll()) {70throw ProcessError(TL("Could not find projection parameter in net."));71}72delete parser;73}747576// ---------------------------------------------------------------------------77// handler methods78// ---------------------------------------------------------------------------79PCNetProjectionLoader::PCNetProjectionLoader(double scale) :80SUMOSAXHandler("sumo-network"),81myFoundLocation(false),82myScale(scale) {83}848586PCNetProjectionLoader::~PCNetProjectionLoader() {}878889void90PCNetProjectionLoader::myStartElement(int element,91const SUMOSAXAttributes& attrs) {92if (element != SUMO_TAG_LOCATION) {93return;94}95// @todo refactor parsing of location since its duplicated in NLHandler and PCNetProjectionLoader96myFoundLocation = true;97PositionVector s = attrs.get<PositionVector>(SUMO_ATTR_NET_OFFSET, nullptr, myFoundLocation);98Boundary convBoundary = attrs.get<Boundary>(SUMO_ATTR_CONV_BOUNDARY, nullptr, myFoundLocation);99Boundary origBoundary = attrs.get<Boundary>(SUMO_ATTR_ORIG_BOUNDARY, nullptr, myFoundLocation);100std::string proj = attrs.get<std::string>(SUMO_ATTR_ORIG_PROJ, nullptr, myFoundLocation);101if (myFoundLocation) {102OptionsCont& oc = OptionsCont::getOptions();103Position networkOffset = s[0] + Position(oc.getFloat("offset.x"), oc.getFloat("offset.y"));104GeoConvHelper::init(proj, networkOffset, origBoundary, convBoundary, myScale);105}106}107108109bool110PCNetProjectionLoader::hasReadAll() const {111return myFoundLocation;112}113114115/****************************************************************************/116117118