Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2024 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 58140 : SystemFrame::addConfigurationOptions(OptionsCont& oc) {
39 58140 : oc.addOptionSubTopic("Configuration");
40 :
41 58140 : oc.doRegister("configuration-file", 'c', new Option_FileName());
42 116280 : oc.addSynonyme("configuration-file", "configuration");
43 116280 : oc.addDescription("configuration-file", "Configuration", TL("Loads the named config on startup"));
44 116280 : oc.addXMLDefault("configuration-file");
45 :
46 58140 : oc.doRegister("save-configuration", 'C', new Option_FileName());
47 116280 : oc.addSynonyme("save-config", "save-configuration");
48 116280 : oc.addDescription("save-configuration", "Configuration", TL("Saves current configuration into FILE"));
49 :
50 58140 : oc.doRegister("save-configuration.relative", new Option_Bool(false));
51 116280 : oc.addSynonyme("save-config.relative", "save-configuration.relative");
52 116280 : oc.addDescription("save-configuration.relative", "Configuration", TL("Enforce relative paths when saving the configuration"));
53 :
54 58140 : oc.doRegister("save-template", new Option_FileName());
55 116280 : oc.addDescription("save-template", "Configuration", TL("Saves a configuration template (empty) into FILE"));
56 :
57 58140 : oc.doRegister("save-schema", new Option_FileName());
58 116280 : oc.addDescription("save-schema", "Configuration", TL("Saves the configuration schema into FILE"));
59 :
60 58140 : oc.doRegister("save-commented", new Option_Bool(false));
61 116280 : oc.addSynonyme("save-commented", "save-template.commented");
62 116280 : oc.addDescription("save-commented", "Configuration", TL("Adds comments to saved template, configuration, or schema"));
63 58140 : }
64 :
65 :
66 : void
67 58140 : SystemFrame::addReportOptions(OptionsCont& oc) {
68 58140 : oc.addOptionSubTopic("Report");
69 :
70 58140 : oc.doRegister("verbose", 'v', new Option_Bool(false));
71 116280 : oc.addDescription("verbose", "Report", TL("Switches to verbose output"));
72 :
73 58140 : oc.doRegister("print-options", new Option_Bool(false));
74 116280 : oc.addDescription("print-options", "Report", TL("Prints option values before processing"));
75 :
76 58140 : oc.doRegister("help", '?', new Option_BoolExtended(false));
77 116280 : oc.addDescription("help", "Report", TL("Prints this screen or selected topics"));
78 :
79 58140 : oc.doRegister("version", 'V', new Option_Bool(false));
80 116280 : oc.addDescription("version", "Report", TL("Prints the current version"));
81 :
82 116280 : oc.doRegister("xml-validation", 'X', new Option_String("local"));
83 116280 : oc.addDescription("xml-validation", "Report", "Set schema validation scheme of XML inputs (\"never\", \"local\", \"auto\" or \"always\")");
84 :
85 116280 : if (oc.exists("net-file")) {
86 111836 : oc.doRegister("xml-validation.net", new Option_String("never"));
87 111836 : oc.addDescription("xml-validation.net", "Report", "Set schema validation scheme of SUMO network inputs (\"never\", \"local\", \"auto\" or \"always\")");
88 : }
89 :
90 116280 : if (oc.exists("route-files")) {
91 106982 : oc.doRegister("xml-validation.routes", new Option_String("local"));
92 106982 : oc.addDescription("xml-validation.routes", "Report", "Set schema validation scheme of SUMO route inputs (\"never\", \"local\", \"auto\" or \"always\")");
93 : }
94 :
95 58140 : oc.doRegister("no-warnings", 'W', new Option_Bool(false));
96 116280 : oc.addSynonyme("no-warnings", "suppress-warnings", true);
97 116280 : oc.addDescription("no-warnings", "Report", TL("Disables output of warnings"));
98 :
99 58140 : oc.doRegister("aggregate-warnings", new Option_Integer(-1));
100 116280 : oc.addDescription("aggregate-warnings", "Report", TL("Aggregate warnings of the same type whenever more than INT occur"));
101 :
102 58140 : oc.doRegister("log", 'l', new Option_FileName());
103 116280 : oc.addSynonyme("log", "log-file");
104 116280 : oc.addDescription("log", "Report", TL("Writes all messages to FILE (implies verbose)"));
105 :
106 58140 : oc.doRegister("message-log", new Option_FileName());
107 116280 : oc.addDescription("message-log", "Report", TL("Writes all non-error messages to FILE (implies verbose)"));
108 :
109 58140 : oc.doRegister("error-log", new Option_FileName());
110 116280 : oc.addDescription("error-log", "Report", TL("Writes all warnings and errors to FILE"));
111 :
112 58140 : oc.doRegister("log.timestamps", new Option_Bool(false));
113 116280 : oc.addDescription("log.timestamps", "Report", TL("Writes timestamps in front of all messages"));
114 :
115 58140 : oc.doRegister("log.processid", new Option_Bool(false));
116 116280 : oc.addDescription("log.processid", "Report", TL("Writes process ID in front of all messages"));
117 :
118 116280 : oc.doRegister("language", new Option_String(gLanguage));
119 116280 : oc.addDescription("language", "Report", TL("Language to use in messages"));
120 :
121 58140 : oc.doRegister("write-license", new Option_Bool(false));
122 116280 : oc.addDescription("write-license", "Output", TL("Include license info into every output file"));
123 :
124 58140 : oc.doRegister("output-prefix", new Option_String());
125 116280 : oc.addDescription("output-prefix", "Output", TL("Prefix which is applied to all output files. The special string 'TIME' is replaced by the current time."));
126 :
127 58140 : oc.doRegister("precision", new Option_Integer(2));
128 116280 : oc.addDescription("precision", "Output", TL("Defines the number of digits after the comma for floating point output"));
129 :
130 58140 : oc.doRegister("precision.geo", new Option_Integer(6));
131 116280 : oc.addDescription("precision.geo", "Output", TL("Defines the number of digits after the comma for lon,lat output"));
132 :
133 58140 : oc.doRegister("human-readable-time", 'H', new Option_Bool(false));
134 116280 : oc.addDescription("human-readable-time", "Output", TL("Write time values as hour:minute:second or day:hour:minute:second rather than seconds"));
135 58140 : }
136 :
137 :
138 : bool
139 91343 : SystemFrame::checkOptions(OptionsCont& oc) {
140 91343 : gPrecision = oc.getInt("precision");
141 91343 : gPrecisionGeo = oc.getInt("precision.geo");
142 91343 : gHumanReadableTime = oc.getBool("human-readable-time");
143 182686 : if (oc.exists("weights.random-factor")) {
144 88233 : gWeightsRandomFactor = oc.getFloat("weights.random-factor");
145 : }
146 182686 : if (oc.exists("persontrip.walk-opposite-factor")) {
147 88233 : gWeightsWalkOppositeFactor = oc.getFloat("persontrip.walk-opposite-factor");
148 : }
149 304323 : if (oc.exists("xml-validation.routes") && oc.isDefault("xml-validation.routes") && !oc.isDefault("xml-validation")) {
150 159297 : oc.setDefault("xml-validation.routes", oc.getString("xml-validation"));
151 : }
152 103027 : if ((oc.exists("ignore-errors") && oc.getBool("ignore-errors")) || gSimulation) {
153 79341 : gIgnoreUnknownVClass = true;
154 : }
155 91343 : std::cout << std::setprecision(gPrecision);
156 91343 : return true;
157 : }
158 :
159 :
160 : void
161 58362 : SystemFrame::close() {
162 : // flush aggregated warnings
163 58362 : MsgHandler::getWarningInstance()->clear();
164 : // close all output devices
165 58362 : OutputDevice::closeAll();
166 : // close the xml-subsystem
167 58362 : XMLSubSys::close();
168 : // delete build program options
169 58362 : OptionsCont::getOptions().clear();
170 : // delete messages
171 58362 : MsgHandler::cleanupOnEnd();
172 58362 : }
173 :
174 :
175 : /****************************************************************************/
|