Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2004-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 SUMOPolygon.cpp
15 : /// @author Daniel Krajzewicz
16 : /// @author Michael Behrisch
17 : /// @author Jakob Erdmann
18 : /// @date Jun 2004
19 : ///
20 : // A 2D-polygon
21 : /****************************************************************************/
22 : #include <config.h>
23 :
24 : #include <utils/iodevices/OutputDevice.h>
25 : #include <utils/common/FileHelpers.h>
26 : #include <utils/common/StringUtils.h>
27 : #include <utils/geom/GeoConvHelper.h>
28 :
29 : #include "SUMOPolygon.h"
30 :
31 : // ===========================================================================
32 : // member definitions
33 : // ===========================================================================
34 113617 : SUMOPolygon::SUMOPolygon(const std::string& id, const std::string& type, const RGBColor& color,
35 : const PositionVector& shape, bool geo, bool fill, double lineWidth,
36 : double layer, double angle, const std::string& imgFile, const std::string& name,
37 113617 : const Parameterised::Map& parameters) :
38 : Shape(id, type, color, layer, angle, imgFile, name),
39 : Parameterised(parameters),
40 : myShape(shape),
41 113617 : myGEO(geo),
42 113617 : myFill(fill),
43 113617 : myLineWidth(lineWidth) {
44 113617 : }
45 :
46 :
47 131573 : SUMOPolygon::~SUMOPolygon() {}
48 :
49 :
50 : const PositionVector&
51 1553572 : SUMOPolygon::getShape() const {
52 1553572 : return myShape;
53 : }
54 :
55 :
56 : const std::vector<PositionVector>&
57 0 : SUMOPolygon::getHoles() const {
58 0 : return myHoles;
59 : }
60 :
61 :
62 : bool
63 12940 : SUMOPolygon::getFill() const {
64 12940 : return myFill;
65 : }
66 :
67 :
68 : double
69 7483 : SUMOPolygon::getLineWidth() const {
70 7483 : return myLineWidth;
71 : }
72 :
73 :
74 : void
75 6 : SUMOPolygon::setFill(bool fill) {
76 6 : myFill = fill;
77 6 : }
78 :
79 :
80 : void
81 6 : SUMOPolygon::setLineWidth(double lineWidth) {
82 6 : myLineWidth = lineWidth;
83 6 : }
84 :
85 :
86 : void
87 3258 : SUMOPolygon::setShape(const PositionVector& shape) {
88 : myShape = shape;
89 3258 : }
90 :
91 : void
92 0 : SUMOPolygon::setHoles(const std::vector<PositionVector>& holes) {
93 0 : myHoles = holes;
94 0 : }
95 :
96 :
97 : void
98 3761 : SUMOPolygon::writeXML(OutputDevice& out, bool geo) const {
99 3761 : out.openTag(SUMO_TAG_POLY);
100 3761 : out.writeAttr(SUMO_ATTR_ID, StringUtils::escapeXML(getID()));
101 3761 : if (getShapeType().size() > 0) {
102 7522 : out.writeAttr(SUMO_ATTR_TYPE, StringUtils::escapeXML(getShapeType()));
103 : }
104 3761 : out.writeAttr(SUMO_ATTR_COLOR, getShapeColor());
105 3761 : out.writeAttr(SUMO_ATTR_FILL, getFill());
106 3761 : if (getLineWidth() != 1) {
107 0 : out.writeAttr(SUMO_ATTR_LINEWIDTH, getLineWidth());
108 : }
109 3761 : out.writeAttr(SUMO_ATTR_LAYER, getShapeLayer());
110 3761 : if (!getShapeName().empty()) {
111 0 : out.writeAttr(SUMO_ATTR_NAME, getShapeName());
112 : }
113 3761 : PositionVector shape = getShape();
114 3761 : if (geo) {
115 143 : out.writeAttr(SUMO_ATTR_GEO, true);
116 1455 : for (int i = 0; i < (int) shape.size(); i++) {
117 1312 : GeoConvHelper::getFinal().cartesian2geo(shape[i]);
118 : }
119 : }
120 3761 : out.setPrecision(gPrecisionGeo);
121 3761 : out.writeAttr(SUMO_ATTR_SHAPE, shape);
122 3761 : out.setPrecision();
123 3761 : if (getShapeNaviDegree() != Shape::DEFAULT_ANGLE) {
124 0 : out.writeAttr(SUMO_ATTR_ANGLE, getShapeNaviDegree());
125 : }
126 3761 : if (getShapeImgFile() != Shape::DEFAULT_IMG_FILE) {
127 0 : out.writeAttr(SUMO_ATTR_IMGFILE, getShapeImgFile());
128 : }
129 3761 : writeParams(out);
130 3761 : out.closeTag();
131 3761 : }
132 :
133 :
134 : /****************************************************************************/
|