Did Aquinas say a baby has no soul until 40 days (for a boy) or 80 days (for a girl) after conception, so abortion is okay before those times?
This is only half true. Aquinas did say an unborn baby receives a soul 40 or 80 days after conception, depending on gender. But he also said abortion is a violation of natural law and is always wrong, no matter when a soul may be infused into the developing child's body.
The 40/80-day view is based on the writings of Aristotle, who said a child becomes human at "formation," the point at which it first "has a human form"--that is, when it looks human. He said this was 40 days for boys and 80 days for girls. Probably this distinction was based on the point at which genitals could be observed on miscarried children. Keep in mind that fetal embryology was then a restricted science; all observations could be made only by the naked eye, the microscope being in the distant future.
Aquinas accepted the idea of formation, which he said occurs when a child receives a soul. But since abortion violates natural law whether or not the child has a soul, Aquinas taught that abortion is always gravely wrong.
Today we have better scientific tools than did Aristotle or Aquinas. Modern science verifies that the unborn have a human genetic code from conception, and this is when their humanity begins.