Skip to content

Commit

Permalink
[multibody] Removal of deprecated Parser::AddModelFromString (#19413)
Browse files Browse the repository at this point in the history
  • Loading branch information
DamrongGuoy authored May 17, 2023
1 parent 0aa7c48 commit 02aec89
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 74 deletions.
11 changes: 0 additions & 11 deletions bindings/pydrake/multibody/parsing_py.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,6 @@ PYBIND11_MODULE(parsing, m) {
cls_doc.SetAutoRenaming.doc)
.def("GetAutoRenaming", &Class::GetAutoRenaming,
cls_doc.GetAutoRenaming.doc);

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
cls // BR
.def("AddModelFromString",
WrapDeprecated(cls_doc.AddModelFromString.doc_deprecated,
&Class::AddModelFromString),
py::arg("file_contents"), py::arg("file_type"),
py::arg("model_name") = "",
cls_doc.AddModelFromString.doc_deprecated);
#pragma GCC diagnostic pop
}

// Model Directives
Expand Down
7 changes: 0 additions & 7 deletions bindings/pydrake/multibody/test/parsing_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,6 @@ def test_parser_string(self):
"drake/multibody/benchmarks/acrobot/acrobot.sdf")
with open(sdf_file, "r") as f:
sdf_contents = f.read()
plant = MultibodyPlant(time_step=0.01)
parser = Parser(plant=plant)
self.assertEqual(parser.plant(), plant)
with catch_drake_warnings(expected_count=1):
result = parser.AddModelFromString(
file_contents=sdf_contents, file_type="sdf")
self.assertIsInstance(result, ModelInstanceIndex)

plant = MultibodyPlant(time_step=0.01)
parser = Parser(plant=plant)
Expand Down
18 changes: 0 additions & 18 deletions multibody/parsing/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,5 @@ ModelInstanceIndex Parser::AddModelFromFile(
return *maybe_model;
}

ModelInstanceIndex Parser::AddModelFromString(
const std::string& file_contents,
const std::string& file_type,
const std::string& model_name) {
DataSource data_source(DataSource::kContents, &file_contents);
const std::string pseudo_name(data_source.GetStem() + "." + file_type);
ParserInterface& parser = SelectParser(diagnostic_policy_, pseudo_name);
auto composite = internal::CompositeParse::MakeCompositeParse(this);
std::optional<ModelInstanceIndex> maybe_model;
maybe_model = parser.AddModel(data_source, model_name, model_name_prefix_,
composite->workspace());
if (!maybe_model.has_value()) {
throw std::runtime_error(
fmt::format("{}: parsing failed", pseudo_name));
}
return *maybe_model;
}

} // namespace multibody
} // namespace drake
17 changes: 0 additions & 17 deletions multibody/parsing/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,23 +248,6 @@ class Parser final {
const std::string& file_name,
const std::string& model_name = {});

/// Provides same functionality as AddModelFromFile, but instead parses the
/// model description text data via @p file_contents with format dictated by
/// @p file_type.
///
/// @param file_contents The model data to be parsed.
/// @param file_type The data format; must be one of the filename suffixes
/// listed above, *without* the leading dot (.) .
/// @param model_name The name given to the newly created instance of this
/// model. If empty, the model name provided by the input text will be used.
/// @returns The instance index for the newly added model.
/// @throws std::exception in case of errors.
DRAKE_DEPRECATED("2023-04-01", "Use AddModelsFromString() instead.")
ModelInstanceIndex AddModelFromString(
const std::string& file_contents,
const std::string& file_type,
const std::string& model_name = {});

private:
friend class internal::CompositeParse;

Expand Down
21 changes: 0 additions & 21 deletions multibody/parsing/test/parser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,27 +213,6 @@ GTEST_TEST(FileParserTest, BasicStringTest) {
}
}

GTEST_TEST(FileParserTest, LegacyStringMethodTest) {
// Just make sure the legacy method "AddModelFromString" still works. This
// test can go away when the method is removed.
//
// Note that extensive per-format testing is not required, since
// AddModelFromString is implemented as a thin wrapper around
// ParserInterface::AddModel. It shares the underlying implementation in
// common with AddModelFromFile.
const std::string sdf_name = FindResourceOrThrow(
"drake/multibody/benchmarks/acrobot/acrobot.sdf");
const std::string sdf_contents = ReadEntireFile(sdf_name);
MultibodyPlant<double> plant(0.0);
Parser dut(&plant);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
const ModelInstanceIndex id = dut.AddModelFromString(sdf_contents, "sdf",
"foo");
#pragma GCC diagnostic pop
EXPECT_EQ(plant.GetModelInstanceName(id), "foo");
}

// Try loading a file with two <model> elements, but without a <world>.
// This should always result in an error. For an example of a valid <world>
// with two <model> elements, refer to MultiModelViaWorldIncludesTest.
Expand Down

0 comments on commit 02aec89

Please sign in to comment.