Root.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2017 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 #ifndef SDF_ROOT_HH_
18 #define SDF_ROOT_HH_
19 
20 #include <string>
21 #include <gz/utils/ImplPtr.hh>
22 
23 #include "sdf/OutputConfig.hh"
24 #include "sdf/ParserConfig.hh"
25 #include "sdf/SDFImpl.hh"
26 #include "sdf/Types.hh"
27 #include "sdf/sdf_config.h"
28 #include "sdf/system_util.hh"
29 
30 namespace sdf
31 {
32  // Inline bracket to help doxygen filtering.
33  inline namespace SDF_VERSION_NAMESPACE {
34  //
35 
36  // Forward declarations.
37  class Actor;
38  class Light;
39  class Model;
40  class World;
41 
57  {
59  public: Root();
60 
66  public: Errors Load(const std::string &_filename);
67 
74  public: Errors Load(
75  const std::string &_filename, const ParserConfig &_config);
76 
82  public: Errors LoadSdfString(const std::string &_sdf);
83 
91  const std::string &_sdf, const ParserConfig &_config);
92 
98  public: Errors Load(const SDFPtr _sdf);
99 
106  public: Errors Load(const SDFPtr _sdf, const ParserConfig &_config);
107 
112  public: std::string Version() const;
113 
117  public: void SetVersion(const std::string &_version);
118 
121  public: uint64_t WorldCount() const;
122 
128  public: const World *WorldByIndex(const uint64_t _index) const;
129 
135  public: World *WorldByIndex(const uint64_t _index);
136 
140  public: bool WorldNameExists(const std::string &_name) const;
141 
145  public: const sdf::Model *Model() const;
146 
150  public: void SetModel(const sdf::Model &_model);
151 
155  public: const sdf::Light *Light() const;
156 
160  public: void SetLight(const sdf::Light &_light);
161 
165  public: const sdf::Actor *Actor() const;
166 
170  public: void SetActor(const sdf::Actor &_actor);
171 
176  public: sdf::ElementPtr Element() const;
177 
184  public: Errors AddWorld(const World &_world);
185 
187  public: void ClearWorlds();
188 
193  public: sdf::Root Clone() const;
194 
201  public: Errors UpdateGraphs();
202 
210  const OutputConfig &_config = OutputConfig::GlobalConfig()) const;
211 
213  IGN_UTILS_UNIQUE_IMPL_PTR(dataPtr)
214  };
215  }
216 }
217 #endif
Provides a description of an actor.
Definition: Actor.hh:192
Provides a description of a light source.
Definition: Light.hh:64
Definition: Model.hh:55
This class contains configuration options for SDF output.
Definition: OutputConfig.hh:59
static OutputConfig & GlobalConfig()
Mutable access to a singleton OutputConfig that serves as the global OutputConfig object for all pars...
This class contains configuration options for the libsdformat parser.
Definition: ParserConfig.hh:85
Root class that acts as an entry point to the SDF document model.
Definition: Root.hh:57
Root()
Default constructor.
Errors LoadSdfString(const std::string &_sdf, const ParserConfig &_config)
Parse the given SDF string, and generate objects based on types specified in the SDF file.
const sdf::Light * Light() const
Get a pointer to the light object if it exists.
uint64_t WorldCount() const
Get the number of worlds.
const sdf::Actor * Actor() const
Get a pointer to the actor object if it exists.
void SetActor(const sdf::Actor &_actor)
Set the actor object.
Errors Load(const SDFPtr _sdf)
Parse the given SDF pointer, and generate objects based on types specified in the SDF file.
void SetModel(const sdf::Model &_model)
Set the model object.
sdf::Root Clone() const
Deep copy this Root object and return the new Root object.
sdf::ElementPtr ToElement(const OutputConfig &_config=OutputConfig::GlobalConfig()) const
Create and return an SDF element filled with data from this root.
Errors Load(const SDFPtr _sdf, const ParserConfig &_config)
Parse the given SDF pointer, and generate objects based on types specified in the SDF file.
Errors UpdateGraphs()
Recreate the frame and pose graphs for the worlds and model that are children of this Root object.
World * WorldByIndex(const uint64_t _index)
Get a mutable world based on an index.
void SetLight(const sdf::Light &_light)
Set the light object.
const World * WorldByIndex(const uint64_t _index) const
Get a world based on an index.
std::string Version() const
Get the SDF version specified in the parsed file or SDF pointer.
sdf::ElementPtr Element() const
Get a pointer to the SDF element that was generated during load.
bool WorldNameExists(const std::string &_name) const
Get whether a world name exists.
const sdf::Model * Model() const
Get a pointer to the model object if it exists.
void SetVersion(const std::string &_version)
Set the SDF version string.
Errors LoadSdfString(const std::string &_sdf)
Parse the given SDF string, and generate objects based on types specified in the SDF file.
Errors AddWorld(const World &_world)
Add a world to the root.
Errors Load(const std::string &_filename)
Parse the given SDF file, and generate objects based on types specified in the SDF file.
void ClearWorlds()
Remove all worlds.
Errors Load(const std::string &_filename, const ParserConfig &_config)
Parse the given SDF file, and generate objects based on types specified in the SDF file.
Definition: World.hh:58
std::shared_ptr< SDF > SDFPtr
Definition: SDFImpl.hh:52
std::vector< Error > Errors
A vector of Error.
Definition: Types.hh:106
std::shared_ptr< Element > ElementPtr
Definition: Element.hh:54
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