First, they take the measurements of the existing mouldings (not sure how they did this - I imagine some fancy laser beam scanning device).
Then, the specialist company produces a length of mouldings which has the same profile. Actually, it's fibre-glass covered with plaster.
Then the damaged part is cut away, and the ceiling coated in something presumably very sticky...
And the new piece added. Ta da! As good as new.