Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2026 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 SystemFrame.cpp
15 : /// @author Daniel Krajzewicz
16 : /// @author Jakob Erdmann
17 : /// @author Michael Behrisch
18 : /// @date Mon, 23.06.2003
19 : ///
20 : // A set of actions common to all applications
21 : /****************************************************************************/
22 : #include <config.h>
23 :
24 : #include <string>
25 : #include <utils/xml/XMLSubSys.h>
26 : #include <utils/common/StdDefs.h>
27 : #include <utils/common/MsgHandler.h>
28 : #include <utils/options/OptionsCont.h>
29 : #include <utils/iodevices/OutputDevice.h>
30 : #include "RandHelper.h"
31 : #include "SystemFrame.h"
32 :
33 :
34 : // ===========================================================================
35 : // method definitions
36 : // ===========================================================================
37 : void
38 55069 : SystemFrame::addConfigurationOptions(OptionsCont& oc) {
39 55069 : oc.addOptionSubTopic("Configuration");
40 :
41 55069 : oc.doRegister("configuration-file", 'c', new Option_FileName());
42 110138 : oc.addSynonyme("configuration-file", "configuration");
43 110138 : oc.addDescription("configuration-file", "Configuration", TL("Loads the named config on startup"));
44 110138 : oc.addXMLDefault("configuration-file");
45 :
46 55069 : oc.doRegister("save-configuration", 'C', new Option_FileName());
47 110138 : oc.addSynonyme("save-config", "save-configuration");
48 110138 : oc.addDescription("save-configuration", "Configuration", TL("Saves current configuration into FILE"));
49 :
50 55069 : oc.doRegister("save-configuration.relative", new Option_Bool(false));
51 110138 : oc.addSynonyme("save-config.relative", "save-configuration.relative");
52 110138 : oc.addDescription("save-configuration.relative", "Configuration", TL("Enforce relative paths when saving the configuration"));
53 :
54 55069 : oc.doRegister("save-template", new Option_FileName());
55 110138 : oc.addDescription("save-template", "Configuration", TL("Saves a configuration template (empty) into FILE"));
56 :
57 55069 : oc.doRegister("save-schema", new Option_FileName());
58 110138 : oc.addDescription("save-schema", "Configuration", TL("Saves the configuration schema into FILE"));
59 :
60 55069 : oc.doRegister("save-commented", new Option_Bool(false));
61 110138 : oc.addSynonyme("save-commented", "save-template.commented");
62 110138 : oc.addDescription("save-commented", "Configuration", TL("Adds comments to saved template, configuration, or schema"));
63 55069 : }
64 :
65 :
66 : void
67 55069 : SystemFrame::addReportOptions(OptionsCont& oc) {
68 55069 : oc.addOptionSubTopic("Report");
69 :
70 55069 : oc.doRegister("verbose", 'v', new Option_Bool(false));
71 110138 : oc.addDescription("verbose", "Report", TL("Switches to verbose output"));
72 :
73 55069 : oc.doRegister("print-options", new Option_Bool(false));
74 110138 : oc.addDescription("print-options", "Report", TL("Prints option values before processing"));
75 :
76 55069 : oc.doRegister("help", '?', new Option_BoolExtended(false));
77 110138 : oc.addDescription("help", "Report", TL("Prints this screen or selected topics"));
78 :
79 55069 : oc.doRegister("version", 'V', new Option_Bool(false));
80 110138 : oc.addDescription("version", "Report", TL("Prints the current version"));
81 :
82 110138 : oc.doRegister("xml-validation", 'X', new Option_String("local"));
83 110138 : oc.addDescription("xml-validation", "Report", "Set schema validation scheme of XML inputs (\"never\", \"local\", \"auto\" or \"always\")");
84 :
85 110138 : if (oc.exists("net-file")) {
86 105676 : oc.doRegister("xml-validation.net", new Option_String("never"));
87 105676 : oc.addDescription("xml-validation.net", "Report", "Set schema validation scheme of SUMO network inputs (\"never\", \"local\", \"auto\" or \"always\")");
88 : }
89 :
90 110138 : if (oc.exists("route-files")) {
91 99714 : oc.doRegister("xml-validation.routes", new Option_String("local"));
92 99714 : oc.addDescription("xml-validation.routes", "Report", "Set schema validation scheme of SUMO route inputs (\"never\", \"local\", \"auto\" or \"always\")");
93 : }
94 :
95 55069 : oc.doRegister("no-warnings", 'W', new Option_Bool(false));
96 110138 : oc.addSynonyme("no-warnings", "suppress-warnings", true);
97 110138 : oc.addDescription("no-warnings", "Report", TL("Disables output of warnings"));
98 :
99 55069 : oc.doRegister("aggregate-warnings", new Option_Integer(-1));
100 110138 : oc.addDescription("aggregate-warnings", "Report", TL("Aggregate warnings of the same type whenever more than INT occur"));
101 :
102 55069 : oc.doRegister("log", 'l', new Option_FileName());
103 110138 : oc.addSynonyme("log", "log-file");
104 110138 : oc.addDescription("log", "Report", TL("Writes all messages to FILE (implies verbose)"));
105 :
106 55069 : oc.doRegister("message-log", new Option_FileName());
107 110138 : oc.addDescription("message-log", "Report", TL("Writes all non-error messages to FILE (implies verbose)"));
108 :
109 55069 : oc.doRegister("error-log", new Option_FileName());
110 110138 : oc.addDescription("error-log", "Report", TL("Writes all warnings and errors to FILE"));
111 :
112 55069 : oc.doRegister("log.timestamps", new Option_Bool(false));
113 110138 : oc.addDescription("log.timestamps", "Report", TL("Writes timestamps in front of all messages"));
114 :
115 55069 : oc.doRegister("log.processid", new Option_Bool(false));
116 110138 : oc.addDescription("log.processid", "Report", TL("Writes process ID in front of all messages"));
117 :
118 110138 : oc.doRegister("language", new Option_String(gLanguage));
119 110138 : oc.addDescription("language", "Report", TL("Language to use in messages"));
120 :
121 55069 : oc.doRegister("write-license", new Option_Bool(false));
122 110138 : oc.addDescription("write-license", "Output", TL("Include license info into every output file"));
123 :
124 55069 : oc.doRegister("write-metadata", new Option_Bool(false));
125 110138 : oc.addDescription("write-metadata", "Output", TL("Write parsable metadata (configuration etc.) instead of comments"));
126 :
127 55069 : oc.doRegister("output-prefix", new Option_String());
128 110138 : oc.addDescription("output-prefix", "Output", TL("Prefix which is applied to all output files. The special string 'TIME' is replaced by the current time."));
129 :
130 55069 : oc.doRegister("output-suffix", new Option_String());
131 110138 : oc.addDescription("output-suffix", "Output", TL("Suffix which is applied to all output files. The special string 'TIME' is replaced by the current time."));
132 :
133 55069 : oc.doRegister("precision", new Option_Integer(2));
134 110138 : oc.addDescription("precision", "Output", TL("Defines the number of digits after the comma for floating point output"));
135 :
136 55069 : oc.doRegister("precision.geo", new Option_Integer(6));
137 110138 : oc.addDescription("precision.geo", "Output", TL("Defines the number of digits after the comma for lon,lat output"));
138 :
139 55069 : oc.doRegister("output.compression", new Option_String());
140 110138 : oc.addDescription("output.compression", "Output", TL("Defines the standard compression algorithm (currently only for parquet output)"));
141 :
142 110138 : oc.doRegister("output.format", new Option_String("xml"));
143 110138 : oc.addDescription("output.format", "Output", TL("Defines the standard output format if not derivable from the file name ('xml', 'csv', 'parquet')"));
144 :
145 110138 : oc.doRegister("output.column-header", new Option_String("auto"));
146 110138 : oc.addDescription("output.column-header", "Output", TL("How to derive column headers from attribute names ('none', 'tag', 'auto', 'plain', 'full')"));
147 :
148 110138 : oc.doRegister("output.column-separator", new Option_String(";"));
149 110138 : oc.addDescription("output.column-separator", "Output", TL("Separator in CSV output"));
150 :
151 55069 : oc.doRegister("human-readable-time", 'H', new Option_Bool(false));
152 110138 : oc.addDescription("human-readable-time", "Output", TL("Write time values as hour:minute:second or day:hour:minute:second rather than seconds"));
153 55069 : }
154 :
155 :
156 : bool
157 88070 : SystemFrame::checkOptions(OptionsCont& oc) {
158 88070 : gPrecision = oc.getInt("precision");
159 176140 : if (oc.exists("emission-output.precision")) {
160 80889 : gPrecisionEmissions = oc.getInt("emission-output.precision");
161 : }
162 88070 : gPrecisionGeo = oc.getInt("precision.geo");
163 88070 : gHumanReadableTime = oc.getBool("human-readable-time");
164 176140 : if (oc.exists("weights.random-factor")) {
165 84391 : gWeightsRandomFactor = oc.getFloat("weights.random-factor");
166 : }
167 176140 : if (oc.exists("persontrip.walk-opposite-factor")) {
168 84391 : gWeightsWalkOppositeFactor = oc.getFloat("persontrip.walk-opposite-factor");
169 : }
170 292963 : if (oc.exists("xml-validation.routes") && oc.isDefault("xml-validation.routes") && !oc.isDefault("xml-validation")) {
171 149115 : oc.setDefault("xml-validation.routes", oc.getString("xml-validation"));
172 : }
173 94692 : if ((oc.exists("ignore-errors") && oc.getBool("ignore-errors")) || gSimulation) {
174 81368 : gIgnoreUnknownVClass = true;
175 : }
176 88070 : std::cout << std::setprecision(gPrecision);
177 88070 : return true;
178 : }
179 :
180 :
181 : void
182 55416 : SystemFrame::close() {
183 : // flush aggregated warnings
184 55416 : MsgHandler::getWarningInstance()->clear();
185 : // close all output devices
186 55416 : OutputDevice::closeAll();
187 : // close the xml-subsystem
188 55416 : XMLSubSys::close();
189 : // delete build program options
190 55416 : OptionsCont::getOptions().clear();
191 : // delete messages
192 55416 : MsgHandler::cleanupOnEnd();
193 55416 : }
194 :
195 :
196 : /****************************************************************************/
|