Thermodynamical theory of pion condensation