Multiwavelength campaign on Mrk 509. XV. A global modeling of the broad emission lines in the optical, UV, and X-ray bands