Loading...
Searching...
No Matches
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 <optional>
22#include <string>
23#include <utility>
24#include <vector>
25
26#include <gz/math/Pose3.hh>
27#include <gz/utils/ImplPtr.hh>
28#include "sdf/Element.hh"
29#include "sdf/OutputConfig.hh"
30#include "sdf/ParserConfig.hh"
31#include "sdf/Plugin.hh"
32#include "sdf/SemanticPose.hh"
33#include "sdf/Types.hh"
34#include "sdf/config.hh"
35#include "sdf/system_util.hh"
36
37namespace sdf
38{
39 // Inline bracket to help doxygen filtering.
40 inline namespace SDF_VERSION_NAMESPACE {
41 //
42
43 // Forward declarations.
44 class Frame;
45 class InterfaceModel;
46 class Joint;
47 class Link;
48 class ParserConfig;
49 class NestedInclude;
50 struct PoseRelativeToGraph;
51 struct FrameAttachedToGraph;
52 template <typename T> class ScopedGraph;
53 using InterfaceModelConstPtr = std::shared_ptr<const InterfaceModel>;
54
56 {
58 public: Model();
59
66 public: Errors Load(ElementPtr _sdf);
67
75 public: Errors Load(sdf::ElementPtr _sdf, const ParserConfig &_config);
76
81 public: Errors ValidateGraphs() const;
82
86 public: std::string Name() const;
87
91 public: void SetName(const std::string &_name);
92
96 public: std::optional<std::string> Namespace() const;
97
101 public: std::optional<std::string> RawNamespace() const;
102
106 public: void SetRawNamespace(const std::string &_ns);
107
112 public: bool Static() const;
113
118 public: void SetStatic(bool _static);
119
125 public: bool SelfCollide() const;
126
131 public: void SetSelfCollide(bool _selfCollide);
132
137 public: bool AllowAutoDisable() const;
138
143 public: void SetAllowAutoDisable(bool _allowAutoDisable);
144
149 public: bool EnableWind() const;
150
154 public: void SetEnableWind(bool _enableWind);
155
161 public: uint64_t LinkCount() const;
162
168 public: const Link *LinkByIndex(const uint64_t _index) const;
169
176 public: Link *LinkByIndex(uint64_t _index);
177
183 public: const Link *LinkByName(const std::string &_name) const;
184
190 public: Link *LinkByName(const std::string &_name);
191
197 public: bool LinkNameExists(const std::string &_name) const;
198
204 public: uint64_t JointCount() const;
205
211 public: const Joint *JointByIndex(const uint64_t _index) const;
212
219 public: Joint *JointByIndex(uint64_t _index);
220
226 public: bool JointNameExists(const std::string &_name) const;
227
235 public: const Joint *JointByName(const std::string &_name) const;
236
244 public: Joint *JointByName(const std::string &_name);
245
251 public: uint64_t FrameCount() const;
252
260 public: const Frame *FrameByIndex(const uint64_t _index) const;
261
269 public: Frame *FrameByIndex(uint64_t _index);
270
277 public: const Frame *FrameByName(const std::string &_name) const;
278
285 public: Frame *FrameByName(const std::string &_name);
286
292 public: bool FrameNameExists(const std::string &_name) const;
293
299 public: uint64_t ModelCount() const;
300
307 public: const Model *ModelByIndex(const uint64_t _index) const;
308
310 // based on an index.
315 public: Model *ModelByIndex(uint64_t _index);
316
322 public: bool ModelNameExists(const std::string &_name) const;
323
331 public: const Model *ModelByName(const std::string &_name) const;
332
340 public: Model *ModelByName(const std::string &_name);
341
347 public: const gz::math::Pose3d &RawPose() const;
348
352 public: void SetRawPose(const gz::math::Pose3d &_pose);
353
356 public: const Link *CanonicalLink() const;
357
362 public: const std::string &CanonicalLinkName() const;
363
368 public: void SetCanonicalLinkName(const std::string &_canonicalLink);
369
374 public: const std::string &PoseRelativeTo() const;
375
380 public: void SetPoseRelativeTo(const std::string &_frame);
381
386 public: sdf::ElementPtr Element() const;
387
392
395 public: const std::string &PlacementFrameName() const;
396
400 public: void SetPlacementFrameName(const std::string &_name);
401
406 // TODO(addisu): If the canonical link is inside an interface model, this
407 // function returns {nullptr, name}. This can be problematic for downstream
408 // applications.
409 public: std::pair<const Link *, std::string> CanonicalLinkAndRelativeName()
410 const;
411
416 public: uint64_t InterfaceModelCount() const;
417
424 public: std::shared_ptr<const InterfaceModel> InterfaceModelByIndex(
425 const uint64_t _index) const;
426
435 const uint64_t _index) const;
436
452 const OutputConfig &_config = OutputConfig::GlobalConfig()) const;
453
464 const std::string &_name) const;
465
470 public: bool AddLink(const Link &_link);
471
476 public: bool AddJoint(const Joint &_joint);
477
482 public: bool AddModel(const Model &_model);
483
488 public: bool AddFrame(const Frame &_frame);
489
491 public: void ClearLinks();
492
494 public: void ClearJoints();
495
497 public: void ClearModels();
498
500 public: void ClearFrames();
501
504 public: std::string Uri() const;
505
508 public: void SetUri(const std::string &_uri);
509
513 public: const sdf::Plugins &Plugins() const;
514
519
521 public: void ClearPlugins();
522
525 public: void AddPlugin(const Plugin &_plugin);
526
532 public: void ResolveAutoInertials(sdf::Errors &_errors,
533 const ParserConfig &_config);
534
540 private: void SetPoseRelativeToGraph(
542
548 private: void SetFrameAttachedToGraph(
550
553 private: const std::vector<std::pair<std::optional<sdf::NestedInclude>,
554 sdf::InterfaceModelConstPtr>> &MergedInterfaceModels() const;
555
559 private: bool IsMerged() const;
560
571 private: sdf::Frame PrepareForMerge(sdf::Errors &_errors,
572 const std::string &_parentOfProxyFrame);
573
578 private: std::optional<std::string> ResolveNamespace (
579 const std::optional<std::string> &_rawNs,
580 const std::string &_modelName);
581
585 friend class Root;
586 friend class World;
587
588 // Allow ModelWrapper from FrameSemantics.cc to call MergedInterfaceModels
589 friend struct ModelWrapper;
590
592 GZ_UTILS_IMPL_PTR(dataPtr)
593 };
594 }
595}
596#endif
A Frame element describes the properties associated with an explicit frame defined in a Model or Worl...
Definition Frame.hh:43
Definition Joint.hh:85
Definition Model.hh:56
sdf::ElementPtr Element() const
Get a pointer to the SDF element that was used during load.
bool AddModel(const Model &_model)
Add a model to the model.
bool AddJoint(const Joint &_joint)
Add a joint to the model.
void SetStatic(bool _static)
Set this model to be static or not static.
sdf::Plugins & Plugins()
Get a mutable vector of plugins attached to this object.
void ClearLinks()
Remove all links.
Joint * JointByName(const std::string &_name)
Get a mutable joint based on a name.
const Link * LinkByIndex(const uint64_t _index) const
Get an immediate (not nested) child link based on an index.
uint64_t ModelCount() const
Get the number of nested models that are immediate (not recursively nested) children of this Model ob...
const std::string & CanonicalLinkName() const
Get the name of the model's canonical link.
uint64_t LinkCount() const
Get the number of links that are immediate (not nested) children of this Model object.
std::optional< std::string > RawNamespace() const
Get the raw namespace associated with the model.
void SetUri(const std::string &_uri)
Set the URI associated with this model.
const gz::math::Pose3d & RawPose() const
Get the pose of the model.
bool JointNameExists(const std::string &_name) const
Get whether a joint name exists.
bool AddLink(const Link &_link)
Add a link to the model.
void SetCanonicalLinkName(const std::string &_canonicalLink)
Set the name of the model's canonical link.
std::string Name() const
Get the name of the model.
void SetAllowAutoDisable(bool _allowAutoDisable)
Set this model to allow auto-disabling.
bool FrameNameExists(const std::string &_name) const
Get whether an explicit frame name exists.
Joint * JointByIndex(uint64_t _index)
Get an immediate (not nested) mutable child joint based on an index.
void AddPlugin(const Plugin &_plugin)
Add a plugin to this object.
std::string Uri() const
Get the URI associated with this model.
const Link * LinkByName(const std::string &_name) const
Get a link based on a name.
void ClearPlugins()
Remove all plugins.
const Frame * FrameByIndex(const uint64_t _index) const
Get an immediate (not nested) child explicit frame based on an index.
bool LinkNameExists(const std::string &_name) const
Get whether a link name exists.
Errors Load(sdf::ElementPtr _sdf, const ParserConfig &_config)
Load the model based on a element pointer.
void ResolveAutoInertials(sdf::Errors &_errors, const ParserConfig &_config)
Calculate and set the inertials for all the links belonging to the model object.
void ClearJoints()
Remove all joints.
Link * LinkByName(const std::string &_name)
Get a mutable link based on a name.
std::shared_ptr< const InterfaceModel > InterfaceModelByIndex(const uint64_t _index) const
Get an immediate (not recursively nested) child interface model based on an index.
bool Static() const
Check if this model should be static.
void SetPoseRelativeTo(const std::string &_frame)
Set the name of the coordinate frame relative to which this object's pose is expressed.
std::optional< std::string > Namespace() const
Get the resolved namespace associated with the model.
uint64_t InterfaceModelCount() const
Get the number of nested interface models that are immediate (not recursively nested) children of thi...
void SetSelfCollide(bool _selfCollide)
Set this model to self-collide or not self-collide.
const std::string & PlacementFrameName() const
Get the name of the placement frame of the model.
sdf::SemanticPose SemanticPose() const
Get SemanticPose object of this object to aid in resolving poses.
const sdf::Plugins & Plugins() const
Get the plugins attached to this object.
uint64_t FrameCount() const
Get the number of explicit frames that are immediate (not nested) children of this Model object.
Errors Load(ElementPtr _sdf)
Load the model based on a element pointer.
void ClearModels()
Remove all models.
bool SelfCollide() const
Check if this model should self-collide.
void ClearFrames()
Remove all frames.
void SetRawNamespace(const std::string &_ns)
Set the raw namespace associated with the model.
void SetEnableWind(bool _enableWind)
Set whether this model should be subject to wind.
const Link * CanonicalLink() const
Get the model's canonical link.
bool EnableWind() const
Check if this model should be subject to wind.
uint64_t JointCount() const
Get the number of joints that are immediate (not nested) children of this Model object.
Model * ModelByName(const std::string &_name)
Get a mutable nested model based on a name.
const Frame * FrameByName(const std::string &_name) const
Get an explicit frame based on a name.
const Joint * JointByName(const std::string &_name) const
Get a joint based on a name.
bool NameExistsInFrameAttachedToGraph(const std::string &_name) const
Check if a given name exists in the FrameAttachedTo graph at the scope of the model.
bool AllowAutoDisable() const
Check if this model should be allowed to auto-disable.
const Model * ModelByName(const std::string &_name) const
Get a nested model based on a name.
bool ModelNameExists(const std::string &_name) const
Get whether a nested model name exists.
Frame * FrameByIndex(uint64_t _index)
Get a mutable immediate (not nested) child explicit frame based on an index.
void SetRawPose(const gz::math::Pose3d &_pose)
Set the pose of the model.
Model()
Default constructor.
void SetPlacementFrameName(const std::string &_name)
Set the name of the placement frame of the model.
Frame * FrameByName(const std::string &_name)
Get a mutable explicit frame based on a name.
Link * LinkByIndex(uint64_t _index)
Get an immediate (not nested) mutable child link based on an index.
const Joint * JointByIndex(const uint64_t _index) const
Get an immediate (not nested) child joint based on an index.
const Model * ModelByIndex(const uint64_t _index) const
Get an immediate (not recursively nested) child model based on an index.
std::pair< const Link *, std::string > CanonicalLinkAndRelativeName() const
Get the model's canonical link and the nested name of the link relative to the current model,...
sdf::ElementPtr ToElement(const OutputConfig &_config=OutputConfig::GlobalConfig()) const
Create and return an SDF element filled with data from this model.
void SetName(const std::string &_name)
Set the name of the model.
Model * ModelByIndex(uint64_t _index)
Get an immediate (not recursively nested) mutable child model.
const NestedInclude * InterfaceModelNestedIncludeByIndex(const uint64_t _index) const
Get the nested include information of an immediate (not recursively nested) child interface model bas...
bool AddFrame(const Frame &_frame)
Add a frame to the model.
Errors ValidateGraphs() const
Check that the FrameAttachedToGraph and PoseRelativeToGraph are valid.
const std::string & PoseRelativeTo() const
Get the name of the coordinate frame relative to which this object's pose is expressed.
Contains the necessary information about an included model file for custom model parsers to be able t...
Definition InterfaceElements.hh:48
This class contains configuration options for SDF output.
Definition OutputConfig.hh:59
This class contains configuration options for the libsdformat parser.
Definition ParserConfig.hh:121
Definition Plugin.hh:46
Root class that acts as an entry point to the SDF document model.
Definition Root.hh:58
Definition Collision.hh:44
SemanticPose is a data structure that can be used by different DOM objects to resolve poses on a Pose...
Definition SemanticPose.hh:55
Definition World.hh:59
std::shared_ptr< const InterfaceModel > InterfaceModelConstPtr
Definition InterfaceModel.hh:51
std::vector< Plugin > Plugins
A vector of Plugin.
Definition Plugin.hh:245
std::vector< Error > Errors
A vector of Error.
Definition Types.hh:83
std::shared_ptr< Element > ElementPtr
Definition Element.hh:57
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