Skip to content

Commit

Permalink
Model DOM: add accessor API's for nested models
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Peters <[email protected]>
  • Loading branch information
scpeters committed Jul 17, 2020
1 parent 33d24e6 commit 047ec96
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ but with improved human-readability..
+ const Frame \*FrameByIndex(const uint64\_t) const
+ const Frame \*FrameByName(const std::string &) const
+ bool FrameNameExists(const std::string &) const
+ uint64\_t ModelCount() const
+ const Model \*ModelByIndex(const uint64\_t) const
+ const Model \*ModelByName(const std::string &) const
+ bool ModelNameExists(const std::string &) const
+ sdf::SemanticPose SemanticPose() const

1. **sdf/SDFImpl.hh**
Expand Down
23 changes: 23 additions & 0 deletions include/sdf/Model.hh
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,29 @@ namespace sdf
/// \return True if there exists an explicit frame with the given name.
public: bool FrameNameExists(const std::string &_name) const;

/// \brief Get the number of nested models.
/// \return Number of nested models contained in this Model object.
public: uint64_t ModelCount() const;

/// \brief Get a nested model based on an index.
/// \param[in] _index Index of the nested model. The index should be in the
/// range [0..ModelCount()).
/// \return Pointer to the model. Nullptr if the index does not exist.
/// \sa uint64_t ModelCount() const
public: const Model *ModelByIndex(const uint64_t _index) const;

/// \brief Get whether a nested model name exists.
/// \param[in] _name Name of the nested model to check.
/// \return True if there exists a nested model with the given name.
public: bool ModelNameExists(const std::string &_name) const;

/// \brief Get a nested model based on a name.
/// \param[in] _name Name of the nested model.
/// \return Pointer to the model. Nullptr if a model with the given name
/// does not exist.
/// \sa bool ModelNameExists(const std::string &_name) const
public: const Model *ModelByName(const std::string &_name) const;

/// \brief Get the pose of the model. This is the pose of the model
/// as specified in SDF (<model> <pose> ... </pose></model>), and is
/// typically used to express the position and rotation of a model in a
Expand Down
43 changes: 43 additions & 0 deletions src/Model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ class sdf::ModelPrivate
/// \brief The frames specified in this model.
public: std::vector<Frame> frames;

/// \brief The nested models specified in this model.
public: std::vector<Model> models;

/// \brief The SDF element pointer used during load.
public: sdf::ElementPtr sdf;

Expand Down Expand Up @@ -527,6 +530,46 @@ const Frame *Model::FrameByName(const std::string &_name) const
return nullptr;
}

/////////////////////////////////////////////////
uint64_t Model::ModelCount() const
{
return this->dataPtr->models.size();
}

/////////////////////////////////////////////////
const Model *Model::ModelByIndex(const uint64_t _index) const
{
if (_index < this->dataPtr->models.size())
return &this->dataPtr->models[_index];
return nullptr;
}

/////////////////////////////////////////////////
bool Model::ModelNameExists(const std::string &_name) const
{
for (auto const &m : this->dataPtr->models)
{
if (m.Name() == _name)
{
return true;
}
}
return false;
}

/////////////////////////////////////////////////
const Model *Model::ModelByName(const std::string &_name) const
{
for (auto const &m : this->dataPtr->models)
{
if (m.Name() == _name)
{
return &m;
}
}
return nullptr;
}

/////////////////////////////////////////////////
const Link *Model::CanonicalLink() const
{
Expand Down

0 comments on commit 047ec96

Please sign in to comment.