-
Notifications
You must be signed in to change notification settings - Fork 331
Use relative paths in updateFromXMLNode() for socket connectees #1751
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This commit attempts to correct the connectee name paths created in updateFromXMLNode() to avoid subsequent warnings when trying to connect a model that is loaded from an old XML file. [skip ci]
FWIW, I don't think it's safe to be modifying |
I might consider fixing the bouncing block issue as part of this work (opensim-org/opensim-gui#68). |
Thanks @aseth1 and @tkuchida for chatting about this issue earlier today. The plan will be to focus on fixing the updateFromXMLNode portion of the issue. I will try to locally test my changes using old models to protect against introducing new bugs: I will ensure that the master branch and my branch produce the same updated 4.0 model (except for the correction to connectee names). As for addressing the fact that the warning also gets generated when building a model programmatically, I will update sockets to use the connectee pointer rather than the connectee name to establish the connection during finalizeConnections(), and deprecate the parts of the interface where users pass string names to specify connectees. I will also need to update print() to throw an exception if finalizeConnections()/finalizeProperties() is not yet called, or alternatively, we could make |
Sounds good @chrisdembia.
Precedent for this approach has been established in |
Also, fix a bug in TwoFrameLinker::updateFromXMLNode() wherein the connectee name was not set correctly when offset frames were required.
…ateFromXMLNode_socket_paths
This should already by the case. |
I think addComponent() calls finailzeFromProperties(), but not finalizeConnections(). |
This PR is now ready for review (no longer WIP). This PR helps avoid generating a "could not find connectee" message (in the Here's an example before-and-after comparison: Before: <PathPoint name="muscle2-point1">
<!--Path to a Component that satisfies the Socket 'parent_frame' of type PhysicalFrame (description: The frame in which this path point is defined.).-->
<socket_parent_frame_connectee_name>ground</socket_parent_frame_connectee_name>
...
</PathPoint> After: <PathPoint name="muscle2-point1">
<!--Path to a Component that satisfies the Socket 'parent_frame' of type PhysicalFrame (description: The frame in which this path point is defined.).-->
<socket_parent_frame_connectee_name>../../../ground</socket_parent_frame_connectee_name>
...
</PathPoint> I ensured that the following classes will no longer cause the "could not find
I tested this by uncommenting the message in Socket::findAndConnect(), and
These models were selected because they contain the components listed above. By default, the "could not find connectee" message is still not emitted I also fixed the following unrelated bugs:
Here are some issues with this PR:
|
{ | ||
SimTK::Xml::Element frameNode("PhysicalOffsetFrame"); | ||
frameNode.setAttributeValue("name", frameName); | ||
stringstream ss; | ||
ss << localXform[3] << " " << localXform[4] << " " << localXform[5]; | ||
SimTK::Xml::Element translationNode("translation", ss.str()); | ||
ss.clear(); | ||
ss = stringstream(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this, ss
would still contain localXform[3]
, localXform[4]
, and localXform[5]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we have to wipeout the existing stream, just reset it to empty string, e.g. ss.str("");
and then ss.clear();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM I only have one comment that is optional to address (if you agree).
I am still concerned about our coverage of updateFromXML code which is some of the more complicated code with thin coverage. Beyond this PR, but lets continue to think of systematic tests to improve our coverage.
// It's necessary to correct the connectee names in the BushingForce, which | ||
// we can do with finalizeConnections() (they are incorrect otherwise | ||
// because `spring` is initially orphaned). | ||
osimModel.finalizeConnections(osimModel); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I interpret this operation differently. If you "print()" a Component you get the existing values for its properties and connections. You call finalizeConnections
before printing because you want the serialization to reflect the existing connections and want to flag any errors. You could print without calling finalizeConnections
if you didn't care about the connections, for example, you are going to add more components when you reload.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with your interpretation. This change was necessary to get the equality comparison to pass. I can investigate if alternate changes to the code can make the test pass. If not, then I will at least update the comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update the comment to something like: "To print (serialize) the latest connections of the model, it is necessary to finalizeConnections() first." Or something to that effect? I think the code is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chrisdembia wish to update the comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I will; thanks for your response. I've been meaning to update this PR but haven't gotten around to it yet.
- std::function needs <functional> header - std::stringstream copy constructor is deleted.
@aseth1 will look at again. |
@tkuchida added you as second reviewer since you've been part of the discussion here. Hope you don't mind. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine to merge, but going forward I suggest we consider one or more of the following:
- add a repository of representative models in various formats to improve model conversion testing (Add test case for model conversion #206)
- release an XML schema for OSIM files (Need Schema for osim files #775)
- update OSIM files one version at a time (updateFromXMLNode(): Connector/Socket updates can occur out of order #1588)
Thanks for reviewing, @tkuchida . |
Thanks @aseth1. I'll try to submit a small followup PR soon to fix the comment in testForces. |
@chrisdembia sure. Sounds good. |
This PR is a first pass at addressing part of #1609.
The "hackathon" warning is caused by two workflows:
updateFromXMLNode()
uses only names, not the correct relative paths; andThis PR shows how we can avoid warnings caused by (a). I am about halfway through editing the updateFromXMLNode() to avoid these warnings; I have to still tackle the
Constraint
classes that were modified to use sockets.The most controversial aspect of this PR is probably that I have edited the
updateFromXMLNode()
code for previous XMLDocument versions, rather than creating a new XMLDocument version. Creating a new version would make the fix much more complex, and might actually be the wrong thing to do. If the perspective is that this is a bug fix, then it might be fine that we are editing the update code for a pre-existing XMLDocument version.