ComputationalBiomechanicsLab / opensim-creator

A UI for building OpenSim models
https://opensimcreator.com
Apache License 2.0
141 stars 17 forks source link

Refactor `OpenSim::Model::addComponent/Joint/Muscle etc.` to use `osc::` helper function instead #756

Closed adamkewley closed 1 year ago

adamkewley commented 1 year ago

The OpenSim pattern:

OpenSim::Joint* j = new WeldJoint{};
model.addJoint(j);
osc.setSelected(j);

Is error-prone because it relies on creating naked pointers, where the naked pointer's lifetime isn't RAII controlled.

So instead, it would be better to have functions like:

namespace osc {
    template<typename TJoint, typename... Args>
    TJoint& AddJointOpenSim::Model const&, Args...);
}

Where the caller can then write:

auto& j = AddJoint<OpenSim::WeldJoint>(model);