World.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_WORLD_HH_
18 #define SDF_WORLD_HH_
19 
20 #include <memory>
21 #include <optional>
22 #include <string>
23 #include <ignition/math/SphericalCoordinates.hh>
24 #include <ignition/math/Vector3.hh>
25 #include <ignition/utils/ImplPtr.hh>
26 
27 #include "sdf/Atmosphere.hh"
28 #include "sdf/Element.hh"
29 #include "sdf/Gui.hh"
30 #include "sdf/Scene.hh"
31 #include "sdf/Types.hh"
32 #include "sdf/sdf_config.h"
33 #include "sdf/system_util.hh"
34 
35 namespace sdf
36 {
37  // Inline bracket to help doxygen filtering.
38  inline namespace SDF_VERSION_NAMESPACE {
39  //
40 
41  // Forward declare private data class.
42  class Actor;
43  class Frame;
44  class InterfaceModel;
45  class Light;
46  class Model;
47  class ParserConfig;
48  class Physics;
49  class NestedInclude;
50  struct PoseRelativeToGraph;
51  struct FrameAttachedToGraph;
52  template <typename T> class ScopedGraph;
53 
55  {
57  public: World();
58 
65  public: Errors Load(ElementPtr _sdf);
66 
74  public: Errors Load(sdf::ElementPtr _sdf, const ParserConfig &_config);
75 
80  public: Errors ValidateGraphs() const;
81 
84  public: std::string Name() const;
85 
88  public: void SetName(const std::string &_name);
89 
94  public: std::string AudioDevice() const;
95 
100  public: void SetAudioDevice(const std::string &_device);
101 
106  public: ignition::math::Vector3d WindLinearVelocity() const;
107 
112  public: void SetWindLinearVelocity(const ignition::math::Vector3d &_wind);
113 
119  public: ignition::math::Vector3d Gravity() const;
120 
124  public: void SetGravity(const ignition::math::Vector3d &_gravity);
125 
132  public: ignition::math::Vector3d MagneticField() const;
133 
140  public: void SetMagneticField(const ignition::math::Vector3d &_mag);
141 
144  public: const ignition::math::SphericalCoordinates *
146 
150  const ignition::math::SphericalCoordinates &_coord);
151 
157  public: uint64_t ModelCount() const;
158 
165  public: const Model *ModelByIndex(const uint64_t _index) const;
166 
174  public: const Model *ModelByName(const std::string &_name) const;
175 
181  public: bool ModelNameExists(const std::string &_name) const;
182 
187  public: bool AddModel(const Model &_model);
188 
193  public: bool AddActor(const Actor &_actor);
194 
199  public: bool AddLight(const Light &_light);
200 
202  public: void ClearModels();
203 
205  public: void ClearActors();
206 
208  public: void ClearLights();
209 
212  public: uint64_t ActorCount() const;
213 
219  public: const Actor *ActorByIndex(const uint64_t _index) const;
220 
224  public: bool ActorNameExists(const std::string &_name) const;
225 
231  public: uint64_t FrameCount() const;
232 
240  public: const Frame *FrameByIndex(const uint64_t _index) const;
241 
248  public: const Frame *FrameByName(const std::string &_name) const;
249 
255  public: bool FrameNameExists(const std::string &_name) const;
256 
259  public: uint64_t LightCount() const;
260 
266  public: const Light *LightByIndex(const uint64_t _index) const;
267 
271  public: bool LightNameExists(const std::string &_name) const;
272 
277  public: const sdf::Atmosphere *Atmosphere() const;
278 
281  public: void SetAtmosphere(const sdf::Atmosphere &_atmosphere);
282 
287  public: const sdf::Gui *Gui() const;
288 
291  public: void SetGui(const sdf::Gui &_gui);
292 
297  public: const sdf::Scene *Scene() const;
298 
301  public: void SetScene(const sdf::Scene &_scene);
302 
307  public: sdf::ElementPtr Element() const;
308 
311  public: uint64_t PhysicsCount() const;
312 
319  public: const Physics *PhysicsByIndex(const uint64_t _index) const;
320 
323  public: const Physics *PhysicsDefault() const;
324 
328  public: bool PhysicsNameExists(const std::string &_name) const;
329 
334  public: uint64_t InterfaceModelCount() const;
335 
342  public: std::shared_ptr<const InterfaceModel> InterfaceModelByIndex(
343  const uint64_t _index) const;
344 
353  const uint64_t _index) const;
354 
359  private: void SetPoseRelativeToGraph(
361 
366  private: void SetFrameAttachedToGraph(
368 
371  friend class Root;
372 
374  IGN_UTILS_IMPL_PTR(dataPtr)
375  };
376  }
377 }
378 #endif
Provides a description of an actor.
Definition: Actor.hh:191
The Atmosphere class contains information about an atmospheric model and related parameters such as t...
Definition: Atmosphere.hh:46
A Frame element descibes the properties associated with an explicit frame defined in a Model or World...
Definition: Frame.hh:43
Definition: Gui.hh:31
Provides a description of a light source.
Definition: Light.hh:64
Definition: Model.hh:49
Contains the necessary information about an included model file for custom model parsers to be able t...
Definition: InterfaceElements.hh:45
This class contains configuration options for the libsdformat parser.
Definition: ParserConfig.hh:85
The physics element specifies the type and properties of a dynamics engine.
Definition: Physics.hh:37
Root class that acts as an entry point to the SDF document model.
Definition: Root.hh:55
Definition: Scene.hh:34
Definition: Collision.hh:39
Definition: World.hh:55
void SetWindLinearVelocity(const ignition::math::Vector3d &_wind)
Set the wind linear velocity in the global/world coordinate frame.
std::shared_ptr< const InterfaceModel > InterfaceModelByIndex(const uint64_t _index) const
Get an immediate (not recursively nested) child interface model based on an index.
sdf::ElementPtr Element() const
Get a pointer to the SDF element that was used during load.
bool AddLight(const Light &_light)
Add a light to the world.
const Model * ModelByName(const std::string &_name) const
Get a model based on a name.
Errors Load(sdf::ElementPtr _sdf, const ParserConfig &_config)
Load the world based on a element pointer.
const Actor * ActorByIndex(const uint64_t _index) const
Get an actor based on an index.
ignition::math::Vector3d Gravity() const
Get the acceleration due to gravity.
bool AddModel(const Model &_model)
Add a model to the world.
uint64_t ModelCount() const
Get the number of models that are immediate (not nested) children of this World object.
void SetScene(const sdf::Scene &_scene)
Set the Scene parameters associated with this world.
const sdf::Scene * Scene() const
Get a pointer to the Scene associated with this world.
World()
Default constructor.
void SetName(const std::string &_name)
Set the name of the world.
bool LightNameExists(const std::string &_name) const
Get whether a light name exists.
void SetMagneticField(const ignition::math::Vector3d &_mag)
Set the magnetic vector in Tesla, expressed in a coordinate frame defined by the SphericalCoordinate.
void SetAudioDevice(const std::string &_device)
Set the audio device name.
const Physics * PhysicsDefault() const
Get the default physics profile.
const NestedInclude * InterfaceModelNestedIncludeByIndex(const uint64_t _index) const
Get the nested include information of an immediate (not recursively nested) child interface model bas...
const Frame * FrameByIndex(const uint64_t _index) const
Get an immediate (not nested) child explicit frame based on an index.
bool ModelNameExists(const std::string &_name) const
Get whether a model name exists.
Errors ValidateGraphs() const
Check that the FrameAttachedToGraph and PoseRelativeToGraph are valid.
uint64_t FrameCount() const
Get the number of explicit frames that are immediate (not nested) children of this World object.
const sdf::Atmosphere * Atmosphere() const
Get a pointer to the atmosphere model associated with this world.
void ClearModels()
Remove all models.
uint64_t InterfaceModelCount() const
Get the number of nested interface models that are immediate (not recursively nested) children of thi...
void SetGui(const sdf::Gui &_gui)
Set the Gui parameters associated with this world.
ignition::math::Vector3d MagneticField() const
Get the magnetic vector in Tesla, expressed in a coordinate frame defined by the SphericalCoordinates...
void SetSphericalCoordinates(const ignition::math::SphericalCoordinates &_coord)
Set the spherical coordinates for the world origin.
bool FrameNameExists(const std::string &_name) const
Get whether an explicit frame name exists.
void SetGravity(const ignition::math::Vector3d &_gravity)
Set the acceleration due to gravity.
const Physics * PhysicsByIndex(const uint64_t _index) const
Get a physics profile based on an index.
const Model * ModelByIndex(const uint64_t _index) const
Get an immediate (not recursively nested) child model based on an index.
uint64_t ActorCount() const
Get the number of actors.
const sdf::Gui * Gui() const
Get a pointer to the Gui associated with this world.
bool ActorNameExists(const std::string &_name) const
Get whether an actor name exists.
const Light * LightByIndex(const uint64_t _index) const
Get a light based on an index.
Errors Load(ElementPtr _sdf)
Load the world based on a element pointer.
bool AddActor(const Actor &_actor)
Add an actor to the world.
ignition::math::Vector3d WindLinearVelocity() const
Get the wind linear velocity in the global/world coordinate frame.
uint64_t LightCount() const
Get the number of lights.
uint64_t PhysicsCount() const
Get the number of physics profiles.
std::string Name() const
Get the name of the world.
std::string AudioDevice() const
Get the audio device name.
const ignition::math::SphericalCoordinates * SphericalCoordinates() const
Get the spherical coordinates for the world origin.
const Frame * FrameByName(const std::string &_name) const
Get an explicit frame based on a name.
void ClearActors()
Remove all models.
bool PhysicsNameExists(const std::string &_name) const
Get whether a physics profile name exists.
void SetAtmosphere(const sdf::Atmosphere &_atmosphere)
Set the atmosphere model associated with this world.
void ClearLights()
Remove all models.
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:34
#define SDFORMAT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system_util.hh:41