Did you ever get this to work? I have exact same task and I run out of ideas how to do it.
Need to prevent bones from further rotation after it takes certain shape but I need to keep simulating whole body. Before I started to dig into cpp I have tried a lot of different approaches but none of them were good enough.