Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/polyconvert/PCNetProjectionLoader.cpp
169665 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file PCNetProjectionLoader.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Michael Behrisch
18
/// @date Thu, 02.11.2006
19
///
20
// A reader for a SUMO network's projection description
21
/****************************************************************************/
22
#include <config.h>
23
24
#include <string>
25
#include <map>
26
#include <fstream>
27
#include <utils/options/OptionsCont.h>
28
#include <utils/options/Option.h>
29
#include <utils/common/FileHelpers.h>
30
#include <utils/common/MsgHandler.h>
31
#include <utils/common/RGBColor.h>
32
#include <utils/common/StdDefs.h>
33
#include <utils/common/SysUtils.h>
34
#include <utils/geom/GeomHelper.h>
35
#include <utils/geom/Boundary.h>
36
#include <utils/geom/Position.h>
37
#include <utils/geom/GeoConvHelper.h>
38
#include <utils/xml/XMLSubSys.h>
39
#include <utils/xml/SUMOXMLDefinitions.h>
40
#include <utils/xml/SUMOSAXReader.h>
41
#include <utils/geom/GeomConvHelper.h>
42
#include <polyconvert/PCPolyContainer.h>
43
#include "PCNetProjectionLoader.h"
44
45
46
// ===========================================================================
47
// method definitions
48
// ===========================================================================
49
// ---------------------------------------------------------------------------
50
// static interface
51
// ---------------------------------------------------------------------------
52
void
53
PCNetProjectionLoader::load(const std::string& file, double scale) {
54
if (!FileHelpers::isReadable(file)) {
55
throw ProcessError(TLF("Could not open net-file '%'.", file));
56
}
57
// build handler and parser
58
PCNetProjectionLoader handler(scale);
59
handler.setFileName(file);
60
SUMOSAXReader* parser = XMLSubSys::getSAXReader(handler, true);
61
const long before = PROGRESS_BEGIN_TIME_MESSAGE("Parsing network projection from '" + file + "'");
62
if (!parser->parseFirst(file)) {
63
delete parser;
64
throw ProcessError(TLF("Can not read XML-file '%'.", handler.getFileName()));
65
}
66
// parse
67
while (parser->parseNext() && !handler.hasReadAll());
68
// clean up
69
PROGRESS_TIME_MESSAGE(before);
70
if (!handler.hasReadAll()) {
71
throw ProcessError(TL("Could not find projection parameter in net."));
72
}
73
delete parser;
74
}
75
76
77
// ---------------------------------------------------------------------------
78
// handler methods
79
// ---------------------------------------------------------------------------
80
PCNetProjectionLoader::PCNetProjectionLoader(double scale) :
81
SUMOSAXHandler("sumo-network"),
82
myFoundLocation(false),
83
myScale(scale) {
84
}
85
86
87
PCNetProjectionLoader::~PCNetProjectionLoader() {}
88
89
90
void
91
PCNetProjectionLoader::myStartElement(int element,
92
const SUMOSAXAttributes& attrs) {
93
if (element != SUMO_TAG_LOCATION) {
94
return;
95
}
96
// @todo refactor parsing of location since its duplicated in NLHandler and PCNetProjectionLoader
97
myFoundLocation = true;
98
PositionVector s = attrs.get<PositionVector>(SUMO_ATTR_NET_OFFSET, nullptr, myFoundLocation);
99
Boundary convBoundary = attrs.get<Boundary>(SUMO_ATTR_CONV_BOUNDARY, nullptr, myFoundLocation);
100
Boundary origBoundary = attrs.get<Boundary>(SUMO_ATTR_ORIG_BOUNDARY, nullptr, myFoundLocation);
101
std::string proj = attrs.get<std::string>(SUMO_ATTR_ORIG_PROJ, nullptr, myFoundLocation);
102
if (myFoundLocation) {
103
OptionsCont& oc = OptionsCont::getOptions();
104
Position networkOffset = s[0] + Position(oc.getFloat("offset.x"), oc.getFloat("offset.y"));
105
GeoConvHelper::init(proj, networkOffset, origBoundary, convBoundary, myScale);
106
}
107
}
108
109
110
bool
111
PCNetProjectionLoader::hasReadAll() const {
112
return myFoundLocation;
113
}
114
115
116
/****************************************************************************/
117
118