private void CallbackOnFlightReady()
 {
     Log.Info("PDPNSelectionWindow.CallbackOnFlightReady");
     //	doVesselRename ();
     flightStatus = FlightStatusType.onPad;
     flightReady  = true;
     physicsCnt   = 0;
 }
        public static string formatManualEntryName(PartModule pm2, string templateName, bool fillSelections = false, bool inFlight = false, string storedTemplateName = "")
        {
            Log.Info("enter formatManualEntryName:  " + templateName);
            //if (templateName == "")
            //	return "";
            if (pm2 == null)
            {
                return("Unknown vessel debris");
            }

            if (!inFlight && (!fillSelections && (templateName.Length < 3 || templateName [0] != '*' || templateName [templateName.Length - 1] != '*')))
            {
                Log.Info("returning: " + templateName);
                return(templateName);
            }


            KeyValuePair <string, PDPN.Tuple <string, NameValueCollection, bool> > t;

            if (inFlight)
            {
                t = GetFormat(storedTemplateName);
            }
            else
            {
                t = GetFormat(templateName);
            }

            if (!fillSelections)
            {
                InitSelectionWindow();
                flightStatus = FlightStatusType.onPad;
                templateName = Utils.formatName(pm2, templateName);
                Log.Info("After call to Utils.formatName, templateName: " + templateName);
            }


            string newVesselName = "";

            if (fillSelections || inFlight || t.Key != "")
            {
                string template;

                template = templateName;

                Log.Info("formatManualEntryName:  template: " + template);
                Log.Info("flightStatus: " + flightStatus.ToString());
                newVesselName = template;
                string pattern = "";
                char   prefix  = ' ';
                char   suffix  = ' ';

                for (int pcnt = 0; pcnt < 2; pcnt++)
                {
                    switch (pcnt)
                    {
                    case 0:
                        pattern = "\\(.*?\\)";
                        prefix  = '(';
                        suffix  = ')';
                        break;

                    case 1:
                        pattern = "\\#.*?\\#";
                        prefix  = '#';
                        suffix  = '#';
                        break;
                    }
                    Log.Info("formatManualEntryName pattern: " + pattern + "   template: " + template);
                    Regex r = new Regex(pattern);

                    Match m = r.Match(template);
                    while (m.Success)
                    {
                        string id          = m.Value.Substring(1, m.Value.Length - 2);
                        string search      = prefix + id + suffix;
                        string replacement = "";
                        //string engineType = "";
                        Log.Info("formatName  id: " + id + "   search: " + search);
                        //replacement = (++cnt).ToString();
                        replacement = "";
                        if (fillSelections)
                        {
                            Log.Info("fillSelections  id: " + id);
                            for (int i = 0; i < selTitleList.Count; i++)
                            {
                                if (selTitleList [i] == id)
                                {
                                    replacement = selArList [i] [selList [i]];
                                    Log.Info("Final replacement: " + selTitleList [i] + "  replacement: " + replacement);
                                    break;
                                }
                            }
                        }
                        else
                        {
                            // Format the replacement, then do the replace
                            if (prefix == '#')
                            {
                                replacement = PDPN_Persistent.getShipIdCount(id).ToString();
                            }
                            else
                            {
                                int stageCnt = StageManager.GetStageCount(Utils.getPartList(pm2));
                                switch (id)
                                {
                                case "destination":
                                case "moons":
                                case "planets":
                                    replacement = getDestination(id, pm2, stageCnt - Utils.getCurrentVessel(pm2).currentStage, t);
                                    break;

                                default:
                                    replacement = getCustom(id, pm2, stageCnt - Utils.getCurrentVessel(pm2).currentStage, t);
                                    break;
                                }
                            }
                        }

                        if (replacement != "")
                        {
                            newVesselName = newVesselName.Replace(search, replacement);
                        }

                        m = m.NextMatch();
                    }
                }
                //}

                //				foreach (string s in t.Value.Second.AllKeys) {
                //					Log.Info ("Key: " + s + "     Value: " + t.Value.Second [s]);
                //				}
            }
            Log.Info("formatname vesselName: " + newVesselName);
            return(newVesselName);
        }