SDFormat Editor
Loading...
Searching...
No Matches
sdformat_parser.h
1/*
2* sdformat-editor
3* Copyright 2025 sdformat-editor
4*
5* Licensed under the Apache License, Version 2.0 (the "License");
6* you may not use this file except in compliance with the License.
7* You may obtain a copy of the License at
8*
9* http://www.apache.org/licenses/LICENSE-2.0
10*
11* Unless required by applicable law or agreed to in writing, software
12* distributed under the License is distributed on an "AS IS" BASIS,
13* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14* See the License for the specific language governing permissions and
15* limitations under the License.
16*
17* Developer: Zaid Duraid, Ean Wheeler, Evan Vokey
18*/
19
20#ifndef SDFORMAT_EDITOR_PARSER_HH_
21#define SDFORMAT_EDITOR_PARSER_HH_
22
23#include <cstdlib>
24#include <cstring>
25#include <limits.h>
26#include <memory>
27#include <filesystem>
28
29#include <interfaces/sdformat_parser_interface.h>
30
31#include <glm/glm.hpp>
32#include <glm/gtc/quaternion.hpp>
33// #include <glm/gtx/quaternion.hpp>
34
37{
38
40 private: sdf::SDFPtr sdfElement;
41
43 private: void Initialize(const std::string file_path, bool &success) override;
44
47 private: sdf::SDFPtr GetSDFElement() override;
48
52 private: std::vector<sdf::ElementPtr> LookupElementsByAttributeType(const std::string& attribute_type) override;
53
58 private: std::vector<sdf::ElementPtr> LookupElementsByAttributeTypeAndValue(const std::string& attribute_type, const std::string& attribute_value) override;
59
67 private: std::vector<sdf::ElementPtr> LookupElementsInternal(const std::string& attribute_type, const std::string& attribute_value,
68 sdf::ElementPtr scope, sdf::ElementPtr scope_to_exclude);
69
73 private: sdf::ElementPtr FindScope(sdf::ElementPtr element);
74
79 private: sdf::ElementPtr FindCanonical(sdf::ElementPtr element);
80
84 private: std::vector<sdf::ElementPtr> LookupElementsByType(const std::string& type) override;
85
89 private: Mentions FindMentions(std::string key) override;
90
95 private: Mentions FindMentions(std::string key, sdf::ElementPtr element_to_exclude) override;
96
101 private: Mentions FindMentions(std::string key, sdf::ParamPtr attribute_to_exclude) override;
102
108 private: Mentions FindMentions(std::string key, sdf::ElementPtr element_to_exclude, sdf::ParamPtr attribute_to_exclude) override;
109
113 private: std::string GetSDFTreePathToElement(sdf::ElementPtr element) override;
114
120 private: std::pair<glm::dvec3, glm::dquat> FindAbsolutePose(sdf::ElementPtr element, std::vector<sdf::ElementPtr> previously_visited_elements = {});
121
127 private: std::pair<glm::dvec3, glm::dquat> ParsePoseElement(sdf::ElementPtr element, std::string& relative_to);
128
133 private: bool HandleRelativeToSpecificationSpecialcases(sdf::ElementPtr element, std::string& relative_to);
134
139 private: std::vector<double> ParseStringDoubleVector(const std::string& string_of_doubles, bool& success);
140
145 private: std::pair<std::vector<ModelViewerI::ModelInfo>, std::vector<ModelViewerI::PresetModelInfo>> GetModelsFromSDFTree(bool render_collisions = false) override;
146
148 private: std::string sdf_file_path;
149};
150
151#endif
Interface for the SDFormat Editor's Parser.
Definition sdformat_parser_interface.h:32
Implementation of SDFormatParserI.
Definition sdformat_parser.h:37
std::vector< double > ParseStringDoubleVector(const std::string &string_of_doubles, bool &success)
Given a string containing doubles seperated by spaces, this method returns a vector a doubles.
Definition sdformat_parser.cpp:670
bool HandleRelativeToSpecificationSpecialcases(sdf::ElementPtr element, std::string &relative_to)
Considers if this is a special case of "relative_to" and approperiately handles it.
Definition sdformat_parser.cpp:376
sdf::SDFPtr GetSDFElement() override
Implementation of interface method.
Definition sdformat_parser.cpp:52
sdf::ElementPtr FindScope(sdf::ElementPtr element)
Finds the nearest world, model, or root element parent of the given element.
Definition sdformat_parser.cpp:319
std::string GetSDFTreePathToElement(sdf::ElementPtr element) override
Implementation of interface method.
Definition sdformat_parser.cpp:283
std::string sdf_file_path
Store the file path of the sdf file.
Definition sdformat_parser.h:148
std::vector< sdf::ElementPtr > LookupElementsByAttributeType(const std::string &attribute_type) override
Implementation of interface method.
Definition sdformat_parser.cpp:144
std::pair< std::vector< ModelViewerI::ModelInfo >, std::vector< ModelViewerI::PresetModelInfo > > GetModelsFromSDFTree(bool render_collisions=false) override
Implementation of interface method.
Definition sdformat_parser.cpp:785
sdf::SDFPtr sdfElement
The main sdfElement associated this this SDFormatParser instance.
Definition sdformat_parser.h:40
std::pair< glm::dvec3, glm::dquat > ParsePoseElement(sdf::ElementPtr element, std::string &relative_to)
Parses a given pose element to get the pose values, and also indicates if this pose is relative to an...
Definition sdformat_parser.cpp:707
sdf::ElementPtr FindCanonical(sdf::ElementPtr element)
Finds the canonical link of a model and, if that doesn't exist, the first child nested model.
Definition sdformat_parser.cpp:333
std::vector< sdf::ElementPtr > LookupElementsByType(const std::string &type) override
Implementation of interface method.
Definition sdformat_parser.cpp:233
std::vector< sdf::ElementPtr > LookupElementsInternal(const std::string &attribute_type, const std::string &attribute_value, sdf::ElementPtr scope, sdf::ElementPtr scope_to_exclude)
Attempts to find an element containing the given attribute type and attribute value within an inital ...
Definition sdformat_parser.cpp:155
std::vector< sdf::ElementPtr > LookupElementsByAttributeTypeAndValue(const std::string &attribute_type, const std::string &attribute_value) override
Implementation of interface method.
Definition sdformat_parser.cpp:149
void Initialize(const std::string file_path, bool &success) override
Implementation of interface method.
Definition sdformat_parser.cpp:26
std::pair< glm::dvec3, glm::dquat > FindAbsolutePose(sdf::ElementPtr element, std::vector< sdf::ElementPtr > previously_visited_elements={})
Finds the absolute pose (translation and rotation) of a given mesh/geometry-containing element.
Definition sdformat_parser.cpp:423
Mentions FindMentions(std::string key) override
Implementation of interface method.
Definition sdformat_parser.cpp:57
Struct to define a "mentions" object type.
Definition sdformat_parser_interface.h:46