If I understand correctly, this is supposed to make the +X axis of each of the hinges part aligned, where a hinge is defined as a local rotation from its target body/ship
So basically to create such constraint, you need to make a quat that transforms the axis of the hinge/normal of the surface you clicked back to the +X axis (1,0,0) in local ship space.
One way to do that is to get the direction/normal of where you clicked in local ship space, then compute a quaternion that gives this value when we multiply it with (1,0,0) then invert it