void Body::updateFromXMLNode(SimTK::Xml::Element& aNode, int versionNumber) { if (versionNumber < XMLDocument::getLatestVersion()) { if (versionNumber < 30500) { SimTK::Vec6 newInertia(1.0, 1.0, 1.0, 0., 0., 0.); std::string inertiaComponents[] = { "inertia_xx", "inertia_yy", "inertia_zz", "inertia_xy", "inertia_xz", "inertia_yz" }; for (int i = 0; i < 6; ++i) { SimTK::Xml::element_iterator iIter = aNode.element_begin(inertiaComponents[i]); if (iIter != aNode.element_end()) { newInertia[i] = iIter->getValueAs<double>(); aNode.removeNode(iIter); } } std::ostringstream strs; for (int i = 0; i < 6; ++i) { strs << newInertia[i]; if (i < 5) strs << " "; } std::string strInertia = strs.str(); SimTK::Xml::Element inertiaNode("inertia", strInertia); aNode.insertNodeAfter(aNode.element_end(), inertiaNode); } } Super::updateFromXMLNode(aNode, versionNumber); }
//_____________________________________________________________________________ // Override default implementation by object to intercept and fix the XML node // underneath the model to match current version. void Muscle::updateFromXMLNode(SimTK::Xml::Element& aNode, int versionNumber) { if ( versionNumber < XMLDocument::getLatestVersion()) { if (Object::getDebugLevel()>=1) cout << "Updating Muscle object to latest format..." << endl; if (versionNumber <= 20301){ SimTK::Xml::element_iterator pathIter = aNode.element_begin("GeometryPath"); if (pathIter != aNode.element_end()) { XMLDocument::renameChildNode(*pathIter, "MusclePointSet", "PathPointSet"); XMLDocument::renameChildNode(*pathIter, "MuscleWrapSet", "PathWrapSet"); } else { // There was no GeometryPath, just MusclePointSet SimTK::Xml::element_iterator musclePointSetIter = aNode.element_begin("MusclePointSet"); bool pathPointSetFound=false; if (musclePointSetIter != aNode.element_end()){ XMLDocument::renameChildNode(aNode, "MusclePointSet", "PathPointSet"); pathPointSetFound=true; } bool pathWrapSetFound=false; SimTK::Xml::element_iterator muscleWrapSetIter = aNode.element_begin("MuscleWrapSet"); if (muscleWrapSetIter != aNode.element_end()){ XMLDocument::renameChildNode(aNode, "MuscleWrapSet", "PathWrapSet"); pathWrapSetFound=true; } // Now create a "GeometryPath" node and move MusclePointSet & MuscleWrapSet under it SimTK::Xml::Element myPathElement("GeometryPath"); SimTK::Xml::Node moveNode; if (pathPointSetFound) { SimTK::Xml::element_iterator pathPointSetIter = aNode.element_begin("PathPointSet"); moveNode = aNode.removeNode(pathPointSetIter); myPathElement.insertNodeAfter(myPathElement.element_end(),moveNode); } if (pathWrapSetFound) { SimTK::Xml::element_iterator pathWrapSetIter = aNode.element_begin("PathWrapSet"); moveNode = aNode.removeNode(pathWrapSetIter); myPathElement.insertNodeAfter(myPathElement.element_end(),moveNode); } aNode.insertNodeAfter(aNode.element_end(), myPathElement); } XMLDocument::renameChildNode(aNode, "pennation_angle", "pennation_angle_at_optimal"); } } // Call base class now assuming aNode has been corrected for current version Super::updateFromXMLNode(aNode, versionNumber); }