Model.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2018 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_MODEL_HH_
18 #define SDF_MODEL_HH_
19 
20 #include <memory>
21 #include <string>
22 #include <utility>
23 #include <vector>
24 #include <gz/math/Pose3.hh>
25 #include <gz/utils/ImplPtr.hh>
26 #include "sdf/Element.hh"
27 #include "sdf/OutputConfig.hh"
28 #include "sdf/ParserConfig.hh"
29 #include "sdf/Plugin.hh"
30 #include "sdf/SemanticPose.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 declarations.
42  class Frame;
43  class InterfaceModel;
44  class Joint;
45  class Link;
46  class ParserConfig;
47  class NestedInclude;
48  struct PoseRelativeToGraph;
49  struct FrameAttachedToGraph;
50  template <typename T> class ScopedGraph;
51  using InterfaceModelConstPtr = std::shared_ptr<const InterfaceModel>;
52 
53 
55  {
57  public: Model();
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 
85  public: std::string Name() const;
86 
90  public: void SetName(const std::string &_name);
91 
96  public: bool Static() const;
97 
102  public: void SetStatic(bool _static);
103 
109  public: bool SelfCollide() const;
110 
115  public: void SetSelfCollide(bool _selfCollide);
116 
121  public: bool AllowAutoDisable() const;
122 
127  public: void SetAllowAutoDisable(bool _allowAutoDisable);
128 
133  public: bool EnableWind() const;
134 
138  public: void SetEnableWind(bool _enableWind);
139 
145  public: uint64_t LinkCount() const;
146 
152  public: const Link *LinkByIndex(const uint64_t _index) const;
153 
160  public: Link *LinkByIndex(uint64_t _index);
161 
167  public: const Link *LinkByName(const std::string &_name) const;
168 
174  public: Link *LinkByName(const std::string &_name);
175 
181  public: bool LinkNameExists(const std::string &_name) const;
182 
188  public: uint64_t JointCount() const;
189 
195  public: const Joint *JointByIndex(const uint64_t _index) const;
196 
203  public: Joint *JointByIndex(uint64_t _index);
204 
210  public: bool JointNameExists(const std::string &_name) const;
211 
219  public: const Joint *JointByName(const std::string &_name) const;
220 
228  public: Joint *JointByName(const std::string &_name);
229 
235  public: uint64_t FrameCount() const;
236 
244  public: const Frame *FrameByIndex(const uint64_t _index) const;
245 
253  public: Frame *FrameByIndex(uint64_t _index);
254 
261  public: const Frame *FrameByName(const std::string &_name) const;
262 
269  public: Frame *FrameByName(const std::string &_name);
270 
276  public: bool FrameNameExists(const std::string &_name) const;
277 
283  public: uint64_t ModelCount() const;
284 
291  public: const Model *ModelByIndex(const uint64_t _index) const;
292 
294  // based on an index.
299  public: Model *ModelByIndex(uint64_t _index);
300 
306  public: bool ModelNameExists(const std::string &_name) const;
307 
315  public: const Model *ModelByName(const std::string &_name) const;
316 
324  public: Model *ModelByName(const std::string &_name);
325 
331  public: const gz::math::Pose3d &RawPose() const;
332 
336  public: void SetRawPose(const gz::math::Pose3d &_pose);
337 
340  public: const Link *CanonicalLink() const;
341 
346  public: const std::string &CanonicalLinkName() const;
347 
352  public: void SetCanonicalLinkName(const std::string &_canonicalLink);
353 
358  public: const std::string &PoseRelativeTo() const;
359 
364  public: void SetPoseRelativeTo(const std::string &_frame);
365 
370  public: sdf::ElementPtr Element() const;
371 
375  public: sdf::SemanticPose SemanticPose() const;
376 
379  public: const std::string &PlacementFrameName() const;
380 
384  public: void SetPlacementFrameName(const std::string &_name);
385 
390  // TODO(addisu): If the canonical link is inside an interface model, this
391  // function returns {nullptr, name}. This can be problematic for downstream
392  // applications.
393  public: std::pair<const Link *, std::string> CanonicalLinkAndRelativeName()
394  const;
395 
400  public: uint64_t InterfaceModelCount() const;
401 
408  public: std::shared_ptr<const InterfaceModel> InterfaceModelByIndex(
409  const uint64_t _index) const;
410 
418  public: const NestedInclude *InterfaceModelNestedIncludeByIndex(
419  const uint64_t _index) const;
420 
435  public: sdf::ElementPtr ToElement(
436  const OutputConfig &_config = OutputConfig::GlobalConfig()) const;
437 
447  public: bool NameExistsInFrameAttachedToGraph(
448  const std::string &_name) const;
449 
454  public: bool AddLink(const Link &_link);
455 
460  public: bool AddJoint(const Joint &_joint);
461 
466  public: bool AddModel(const Model &_model);
467 
472  public: bool AddFrame(const Frame &_frame);
473 
475  public: void ClearLinks();
476 
478  public: void ClearJoints();
479 
481  public: void ClearModels();
482 
484  public: void ClearFrames();
485 
488  public: std::string Uri() const;
489 
492  public: void SetUri(const std::string &_uri);
493 
497  public: const sdf::Plugins &Plugins() const;
498 
502  public: sdf::Plugins &Plugins();
503 
505  public: void ClearPlugins();
506 
509  public: void AddPlugin(const Plugin &_plugin);
510 
516  private: void SetPoseRelativeToGraph(
518 
524  private: void SetFrameAttachedToGraph(
526 
529  private: const std::vector<std::pair<std::optional<sdf::NestedInclude>,
530  sdf::InterfaceModelConstPtr>> &MergedInterfaceModels() const;
531 
535  friend class Root;
536  friend class World;
537 
538  // Allow ModelWrapper from FrameSemantics.cc to call MergedInterfaceModels
539  friend struct ModelWrapper;
540 
542  IGN_UTILS_IMPL_PTR(dataPtr)
543  };
544  }
545 }
546 #endif
sdf::SDF_VERSION_NAMESPACE::OutputConfig
This class contains configuration options for SDF output.
Definition: OutputConfig.hh:58
sdf::SDF_VERSION_NAMESPACE::Model
Definition: Model.hh:54
sdf
namespace for Simulation Description Format parser
Definition: Actor.hh:34
sdf::SDF_VERSION_NAMESPACE::Element
class IGNITION_SDFORMAT_VISIBLE Element
Definition: Element.hh:50
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::SDF_VERSION_NAMESPACE::InterfaceModelConstPtr
std::shared_ptr< const InterfaceModel > InterfaceModelConstPtr
Definition: InterfaceModel.hh:50
SemanticPose.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::Joint
Definition: Joint.hh:85
sdf::SDF_VERSION_NAMESPACE::Root
Root class that acts as an entry point to the SDF document model.
Definition: Root.hh:56
sdf::SDF_VERSION_NAMESPACE::SemanticPose
SemanticPose is a data structure that can be used by different DOM objects to resolve poses on a Pose...
Definition: SemanticPose.hh:54
sdf::SDF_VERSION_NAMESPACE::Errors
std::vector< Error > Errors
A vector of Error.
Definition: Types.hh:106
sdf::SDF_VERSION_NAMESPACE::ScopedGraph
Definition: Collision.hh:39
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:44
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:196
sdf::SDF_VERSION_NAMESPACE::World
Definition: World.hh:57
sdf::SDF_VERSION_NAMESPACE::ElementPtr
std::shared_ptr< Element > ElementPtr
Definition: Element.hh:54
Element.hh