Skip to content

Commit

Permalink
Fix ExternalLoads not copying the underlying connection to its associ…
Browse files Browse the repository at this point in the history
…ated document (#3926)
  • Loading branch information
adamkewley committed Oct 4, 2024
1 parent cb88eac commit 57dd758
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ v4.6
- Made improvements to `MocoUtilities::createExternalLoadsTableForGait()`: center of pressure values are now set to zero, rather
than NaN, when vertical force is zero, and the vertical torque is returned in the torque columns (rather than the sum of the
sphere torques) to be consistent with the center of pressure GRF representation.
- Fixed an issue where a copy of an `OpenSim::Model` containing a `OpenSim::ExternalLoads` could not be
finalized (#3926)

v4.5.1
======
Expand Down
6 changes: 6 additions & 0 deletions OpenSim/Simulation/Model/ExternalLoads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ ExternalLoads::ExternalLoads(const ExternalLoads &otherExternalLoads) :
ModelComponentSet<ExternalForce>(otherExternalLoads),
_dataFileName(_dataFileNameProp.getValueStr())
{
// copy the document over, because it's used during `extendFinalizeConnections`
// to figure out where the associated motion file (#3926)
if (auto* document = otherExternalLoads.getDocument()) {
setDocument(std::make_unique<XMLDocument>(*document).release());
}

setNull();

// Class Members
Expand Down
2 changes: 1 addition & 1 deletion OpenSim/Tools/Test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ OpenSimAddTests(


# edge-case: one test ensures that `ExternalLoads` still works - even when it isn't in
# the working directory of the test runner
# the working directory of the test runner (#3926)
file(COPY "ExternalLoadsInSubdir" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
4 changes: 4 additions & 0 deletions OpenSim/Tools/Test/testExternalLoads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ TEST_CASE("ExternalLoads Default Properties")
model.initSystem();
}

// related: #3926
//
// adding a valid `OpenSim::ExternalLoads` to a model shouldn't result in a model
// that cannot be copied.
TEST_CASE("ExternalLoads Can Be Copied")
{
OpenSim::Model model{"ExternalLoadsInSubdir/model-in-subdir.osim"};
Expand Down

0 comments on commit 57dd758

Please sign in to comment.