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 <gz/math/SphericalCoordinates.hh>
24 #include <gz/math/Vector3.hh>
25 #include <gz/utils/ImplPtr.hh>
26 
27 #include "sdf/Atmosphere.hh"
28 #include "sdf/Element.hh"
29 #include "sdf/Gui.hh"
30 #include "sdf/OutputConfig.hh"
31 #include "sdf/ParserConfig.hh"
32 #include "sdf/Plugin.hh"
33 #include "sdf/Scene.hh"
34 #include "sdf/Types.hh"
35 #include "sdf/sdf_config.h"
36 #include "sdf/system_util.hh"
37 
38 namespace sdf
39 {
40  // Inline bracket to help doxygen filtering.
41  inline namespace SDF_VERSION_NAMESPACE {
42  //
43 
44  // Forward declare private data class.
45  class Actor;
46  class Frame;
47  class InterfaceModel;
48  class Joint;
49  class Light;
50  class Model;
51  class ParserConfig;
52  class Physics;
53  class NestedInclude;
54  struct PoseRelativeToGraph;
55  struct FrameAttachedToGraph;
56  template <typename T> class ScopedGraph;
57 
59  {
61  public: World();
62 
69  public: Errors Load(ElementPtr _sdf);
70 
78  public: Errors Load(sdf::ElementPtr _sdf, const ParserConfig &_config);
79 
84  public: Errors ValidateGraphs() const;
85 
88  public: std::string Name() const;
89 
92  public: void SetName(const std::string &_name);
93 
98  public: std::string AudioDevice() const;
99 
104  public: void SetAudioDevice(const std::string &_device);
105 
110  public: gz::math::Vector3d WindLinearVelocity() const;
111 
116  public: void SetWindLinearVelocity(const gz::math::Vector3d &_wind);
117 
123  public: gz::math::Vector3d Gravity() const;
124 
128  public: void SetGravity(const gz::math::Vector3d &_gravity);
129 
136  public: gz::math::Vector3d MagneticField() const;
137 
144  public: void SetMagneticField(const gz::math::Vector3d &_mag);
145 
148  public: const gz::math::SphericalCoordinates *
149  SphericalCoordinates() const;
150 
153  public: void SetSphericalCoordinates(
154  const gz::math::SphericalCoordinates &_coord);
155 
161  public: uint64_t ModelCount() const;
162 
169  public: const Model *ModelByIndex(const uint64_t _index) const;
170 
177  public: Model *ModelByIndex(uint64_t _index);
178 
186  public: const Model *ModelByName(const std::string &_name) const;
187 
195  public: Model *ModelByName(const std::string &_name);
196 
202  public: bool ModelNameExists(const std::string &_name) const;
203 
208  public: bool AddModel(const Model &_model);
209 
214  public: bool AddActor(const Actor &_actor);
215 
220  public: bool AddJoint(const Joint &_joint);
221 
226  public: bool AddLight(const Light &_light);
227 
232  public: bool AddPhysics(const Physics &_physics);
233 
238  public: bool AddFrame(const Frame &_frame);
239 
241  public: void ClearModels();
242 
244  public: void ClearActors();
245 
247  public: void ClearJoints();
248 
250  public: void ClearLights();
251 
253  public: void ClearPhysics();
254 
256  public: void ClearFrames();
257 
260  public: uint64_t ActorCount() const;
261 
267  public: const Actor *ActorByIndex(const uint64_t _index) const;
268 
274  public: Actor *ActorByIndex(uint64_t _index);
275 
279  public: bool ActorNameExists(const std::string &_name) const;
280 
286  public: const Actor *ActorByName(const std::string &_name) const;
287 
293  public: Actor *ActorByName(const std::string &_name);
294 
300  public: uint64_t FrameCount() const;
301 
309  public: const Frame *FrameByIndex(const uint64_t _index) const;
310 
318  public: Frame *FrameByIndex(uint64_t _index);
319 
326  public: const Frame *FrameByName(const std::string &_name) const;
327 
334  public: Frame *FrameByName(const std::string &_name);
335 
341  public: bool FrameNameExists(const std::string &_name) const;
342 
345  public: uint64_t JointCount() const;
346 
352  public: const Joint *JointByIndex(uint64_t _index) const;
353 
359  public: Joint *JointByIndex(uint64_t _index);
360 
367  public: const Joint *JointByName(const std::string &_name) const;
368 
375  public: Joint *JointByName(const std::string &_name);
376 
380  public: bool JointNameExists(const std::string &_name) const;
381 
384  public: uint64_t LightCount() const;
385 
391  public: const Light *LightByIndex(const uint64_t _index) const;
392 
398  public: Light *LightByIndex(uint64_t _index);
399 
403  public: bool LightNameExists(const std::string &_name) const;
404 
409  public: const sdf::Atmosphere *Atmosphere() const;
410 
413  public: void SetAtmosphere(const sdf::Atmosphere &_atmosphere);
414 
419  public: const sdf::Gui *Gui() const;
420 
423  public: void SetGui(const sdf::Gui &_gui);
424 
429  public: const sdf::Scene *Scene() const;
430 
433  public: void SetScene(const sdf::Scene &_scene);
434 
439  public: sdf::ElementPtr Element() const;
440 
443  public: uint64_t PhysicsCount() const;
444 
451  public: const Physics *PhysicsByIndex(const uint64_t _index) const;
452 
459  public: Physics *PhysicsByIndex(uint64_t _index);
460 
463  public: const Physics *PhysicsDefault() const;
464 
468  public: bool PhysicsNameExists(const std::string &_name) const;
469 
474  public: uint64_t InterfaceModelCount() const;
475 
482  public: std::shared_ptr<const InterfaceModel> InterfaceModelByIndex(
483  const uint64_t _index) const;
484 
492  public: const NestedInclude* InterfaceModelNestedIncludeByIndex(
493  const uint64_t _index) const;
494 
501  public: sdf::ElementPtr ToElement(
502  const OutputConfig &_config = OutputConfig::GlobalConfig()) const;
503 
513  public: bool NameExistsInFrameAttachedToGraph(
514  const std::string &_name) const;
515 
519  public: const sdf::Plugins &Plugins() const;
520 
524  public: sdf::Plugins &Plugins();
525 
527  public: void ClearPlugins();
528 
531  public: void AddPlugin(const Plugin &_plugin);
532 
537  private: void SetPoseRelativeToGraph(
539 
544  private: void SetFrameAttachedToGraph(
546 
549  friend class Root;
550 
552  GZ_UTILS_IMPL_PTR(dataPtr)
553  };
554  }
555 }
556 #endif
sdf::SDF_VERSION_NAMESPACE::OutputConfig
This class contains configuration options for SDF output.
Definition: OutputConfig.hh:58
Gui.hh
sdf::SDF_VERSION_NAMESPACE::Model
Definition: Model.hh:54
Scene.hh
sdf
namespace for Simulation Description Format parser
Definition: Actor.hh:34
sdf::SDF_VERSION_NAMESPACE::Physics
The physics element specifies the type and properties of a dynamics engine.
Definition: Physics.hh:36
sdf::SDF_VERSION_NAMESPACE::Frame
A Frame element descibes the properties associated with an explicit frame defined in a Model or World...
Definition: Frame.hh:42
ParserConfig.hh
Types.hh
sdf_config.h
SDFORMAT_VISIBLE
#define SDFORMAT_VISIBLE
Definition: system_util.hh:25
sdf::SDF_VERSION_NAMESPACE::ParserConfig
This class contains configuration options for the libsdformat parser.
Definition: ParserConfig.hh:84
sdf::SDF_VERSION_NAMESPACE::Plugin
Definition: Plugin.hh:45
sdf::SDF_VERSION_NAMESPACE::Atmosphere
The Atmosphere class contains information about an atmospheric model and related parameters such as t...
Definition: Atmosphere.hh:45
sdf::SDF_VERSION_NAMESPACE::Light
Provides a description of a light source.
Definition: Light.hh:63
sdf::SDF_VERSION_NAMESPACE::Joint
Definition: Joint.hh:85
sdf::SDF_VERSION_NAMESPACE::Scene
Definition: Scene.hh:33
sdf::SDF_VERSION_NAMESPACE::Element
class GZ_SDFORMAT_VISIBLE Element
Definition: Element.hh:51
sdf::SDF_VERSION_NAMESPACE::Root
Root class that acts as an entry point to the SDF document model.
Definition: Root.hh:57
sdf::SDF_VERSION_NAMESPACE::Actor
Provides a description of an actor.
Definition: Actor.hh:191
sdf::SDF_VERSION_NAMESPACE::Errors
std::vector< Error > Errors
A vector of Error.
Definition: Types.hh:80
sdf::SDF_VERSION_NAMESPACE::ScopedGraph
Definition: Collision.hh:40
OutputConfig.hh
sdf::SDF_VERSION_NAMESPACE::NestedInclude
Contains the necessary information about an included model file for custom model parsers to be able t...
Definition: InterfaceElements.hh:45
sdf::SDF_VERSION_NAMESPACE::OutputConfig::GlobalConfig
static OutputConfig & GlobalConfig()
Mutable access to a singleton OutputConfig that serves as the global OutputConfig object for all pars...
system_util.hh
Plugin.hh
sdf::SDF_VERSION_NAMESPACE::Plugins
std::vector< Plugin > Plugins
A vector of Plugin.
Definition: Plugin.hh:245
sdf::SDF_VERSION_NAMESPACE::World
Definition: World.hh:58
Atmosphere.hh
sdf::SDF_VERSION_NAMESPACE::Gui
Definition: Gui.hh:31
sdf::SDF_VERSION_NAMESPACE::ElementPtr
std::shared_ptr< Element > ElementPtr
Definition: Element.hh:55
Element.hh