ParserConfig.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2020 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #ifndef SDF_PARSER_CONFIG_HH_
19 #define SDF_PARSER_CONFIG_HH_
20 
21 #include <functional>
22 #include <map>
23 #include <string>
24 #include <vector>
25 
26 #include <gz/utils/ImplPtr.hh>
27 
28 #include "sdf/Error.hh"
29 #include "sdf/InterfaceElements.hh"
31 #include "sdf/sdf_config.h"
32 #include "sdf/system_util.hh"
33 
34 
35 namespace sdf
36 {
37 inline namespace SDF_VERSION_NAMESPACE
38 {
41 {
43  ERR,
44 
46  WARN,
47 
49  LOG,
50 };
51 
56 {
60 
64 
70 };
71 
76 {
80  ERR,
81 
85 };
86 
87 // Forward declare private data class.
88 class ParserConfigPrivate;
89 
121 {
123  public: using SchemeToPathMap =
124  std::map<std::string, std::vector<std::string> >;
125 
127  public: ParserConfig();
128 
133  public: static ParserConfig &GlobalConfig();
134 
137  public: const std::function<std::string(const std::string &)> &
139 
153  public: void SetFindCallback(
154  std::function<std::string(const std::string &)> _cb);
155 
158  public: const SchemeToPathMap &URIPathMap() const;
159 
165  public: void AddURIPath(const std::string &_uri, const std::string &_path);
166 
169  public: void SetWarningsPolicy(EnforcementPolicy _policy);
170 
174 
178 
182 
186 
190 
198 
203 
208  ConfigureResolveAutoInertials _configuration);
209 
215 
222 
226  public: void RegisterCustomModelParser(CustomModelParser _modelParser);
227 
230  public: const std::vector<CustomModelParser> &CustomModelParsers() const;
231 
236  CustomInertiaCalculator _inertiaCalculator);
237 
241 
245  public: void URDFSetPreserveFixedJoint(bool _preserveFixedJoint);
246 
250  public: bool URDFPreserveFixedJoint() const;
251 
254  public: void SetStoreResovledURIs(bool _resolveURI);
255 
265  public: void SetStoreResolvedURIs(bool _resolveURI);
266 
270  public: bool StoreResolvedURIs() const;
271 
273  GZ_UTILS_IMPL_PTR(dataPtr)
274 };
275 }
276 }
277 
278 #endif
This class contains configuration options for the libsdformat parser.
Definition: ParserConfig.hh:121
const CustomInertiaCalculator & CustomInertiaCalc() const
Get the registered custom mesh MOI Calculator.
void AddURIPath(const std::string &_uri, const std::string &_path)
Associate paths to a URI.
void URDFSetPreserveFixedJoint(bool _preserveFixedJoint)
Set the preserveFixedJoint flag.
void ResetDeprecatedElementsPolicy()
Resets the policy for deprecated elements so that it follows WarningsPolicy.
void SetDeprecatedElementsPolicy(EnforcementPolicy _policy)
Set the policy for deprecated elements.
void SetUnrecognizedElementsPolicy(EnforcementPolicy _policy)
Set the policy for unrecogonized elements without an xmlns.
void SetFindCallback(std::function< std::string(const std::string &)> _cb)
Set the callback to use when libsdformat can't find a file.
static ParserConfig & GlobalConfig()
Mutable access to a singleton ParserConfig that serves as the global ParserConfig object for all pars...
const std::vector< CustomModelParser > & CustomModelParsers() const
Get the registered custom model parsers.
void SetStoreResolvedURIs(bool _resolveURI)
Set the storeResolvedURIs flag value.
void RegisterCustomModelParser(CustomModelParser _modelParser)
Registers a custom model parser.
EnforcementPolicy UnrecognizedElementsPolicy() const
Get the current unrecognized elements policy.
std::map< std::string, std::vector< std::string > > SchemeToPathMap
type alias for the map from URI scheme to search directories
Definition: ParserConfig.hh:124
EnforcementPolicy WarningsPolicy() const
Get the current warning enforcement policy.
ConfigureResolveAutoInertials CalculateInertialConfiguration() const
Get the current configuration for the CalculateInertial() function.
void SetWarningsPolicy(EnforcementPolicy _policy)
Set the warning enforcment policy.
const SchemeToPathMap & URIPathMap() const
Get the URI scheme to search directories map.
bool URDFPreserveFixedJoint() const
Get the preserveFixedJoint flag value.
bool StoreResolvedURIs() const
Get the storeResolvedURIs flag value.
void SetStoreResovledURIs(bool _resolveURI)
Set the storeResolvedURIs flag value.
const std::function< std::string(const std::string &)> & FindFileCallback() const
Get the find file callback function.
EnforcementPolicy DeprecatedElementsPolicy() const
Get the current deprecated elements policy.
CalculateInertialFailurePolicyType CalculateInertialFailurePolicy() const
Get the current policy for handling failures of the CalculateInertial() function.
void SetCalculateInertialConfiguration(ConfigureResolveAutoInertials _configuration)
Set the configuration for the CalculateInertial() function.
void SetCalculateInertialFailurePolicy(CalculateInertialFailurePolicyType _policy)
Set the policy for handling failures of the CalculateInertial() function.
void RegisterCustomInertiaCalc(CustomInertiaCalculator _inertiaCalculator)
Registers a custom Moment of Inertia Calculator for Meshes.
EnforcementPolicy
Policy to describe how to treat certain conditions when parsing.
Definition: ParserConfig.hh:41
@ WARN
Treat condition as a warning and issue to user.
@ LOG
Ignore condition in favor of best effort parsing.
@ ERR
Policy is to treat condition as an error and fail parsing.
std::function< sdf::InterfaceModelPtr(const sdf::NestedInclude &, Errors &)> CustomModelParser
Defines a custom model parser.
Definition: InterfaceElements.hh:198
ConfigureResolveAutoInertials
Configuration options of how CalculateInertial() function would be used.
Definition: ParserConfig.hh:56
@ SAVE_CALCULATION
If this values is used, CalculateInertial() would be called and the computed inertial values would be...
@ SKIP_CALCULATION_IN_LOAD
If this value is used, CalculateInertial() won't be called from inside the Root::Load() function.
@ SAVE_CALCULATION_IN_ELEMENT
If this values is used, CalculateInertial() would be called and the computed inertial values would be...
std::function< std::optional< gz::math::Inertiald >(sdf::Errors &, const sdf::CustomInertiaCalcProperties &)> CustomInertiaCalculator
Definition: CustomInertiaCalcProperties.hh:84
CalculateInertialFailurePolicyType
Configuration options of how CalculateInertial() failures should be handled.
Definition: ParserConfig.hh:76
@ WARN_AND_USE_DEFAULT_INERTIAL
If this value is used, failures of Geometry::CalculateInertial() will result in default inertial valu...
@ ERR
If this value is used, failures of Geometry::CalculateInertial() will result in a LINK_INERTIA_INVALI...
namespace for Simulation Description Format parser
Definition: Actor.hh:35
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system_util.hh:25