At Which Stage Should I Apply for a Patent?

Over the years I have noticed that inventors seek patent filing related advice at various stages of the inventing process. At one extreme, I have seen inventors exploring the option of filing a patent application at an ideation stage. On the other hand, I have also come across inventors who explore the patent filing option after bringing the invention to public domain. Given the wide gap between the two extremes, I intend to provide some information through this article to help inventors decide an ideal time to apply for a patent.