% This function is part of the NMSM Pipeline, see file for full license.
%
% This function converts the spring portion of a parsed .osimx file
% into a new .osimx struct to be printed with writeOsimxFile(). See
% buildOsimxFromOsimxStruct(), buildGcpOsimx(), and
% buildGcpContactSurface() for reference.
%
% (struct, struct) -> (struct)
% Adds groundContact to .osimx struct
function contactSurface = buildGcpSpring(contactSurface, spring)
split = strsplit(spring.name, "_");
markerNumberStr = split{end};
markerNumber = str2num(markerNumberStr);
contactSurface.GCPSpringSet.GCPSpring{markerNumber}.Attributes.name = ...
convertStringsToChars(spring.name);
contactSurface.GCPSpringSet.GCPSpring{markerNumber}.parent_body.Comment = ...
'The body that the spring is attached to';
contactSurface.GCPSpringSet.GCPSpring{markerNumber}.parent_body.Text = ...
spring.parentBody;
contactSurface.GCPSpringSet.GCPSpring{markerNumber}.location.Comment = ...
'The location of the spring in the body it is attached to';
contactSurface.GCPSpringSet.GCPSpring{markerNumber}.location.Text = ...
num2str([spring.location(1) spring.location(2) spring.location(3)], 15);
contactSurface.GCPSpringSet.GCPSpring{markerNumber}.spring_constant.Comment = ...
'The modeled spring constant for the spring';
contactSurface.GCPSpringSet.GCPSpring{markerNumber}.spring_constant.Text = ...
num2str(spring.springConstant, 15);
end