示例#1
0
        private void StabDerivCalcButtonAction(CalcAndExportEnum exportflag)
        {
            CelestialBody body = _bodySettingDropdown.ActiveSelection;

            FARAeroUtil.UpdateCurrentActiveBody(body);
            altitude = Regex.Replace(altitude, @"[^-?[0-9]*(\.[0-9]*)?]", "");
            double altitudeDouble = Convert.ToDouble(altitude) * 1000;

            machNumber = Regex.Replace(machNumber, @"[^-?[0-9]*(\.[0-9]*)?]", "");
            double machDouble           = FARMathUtil.Clamp(Convert.ToSingle(machNumber), 0.001, float.PositiveInfinity);
            int    flapsettingInt       = _flapSettingDropdown.ActiveSelection;
            bool   spoilersDeployedBool = spoilersDeployed;

            if (exportflag == CalcAndExportEnum.LoopExport)
            {
                int n = 0;
                ExportTextFileCache filecache = new ExportTextFileCache();
                foreach (Vector2 altmach in StabilityDerivativeExportFile.LoadConfigList())
                {
                    StabilityDerivExportOutput output = simManager.StabDerivCalculator.CalculateStabilityDerivs(body, (double)altmach.x, (double)altmach.y, flapsettingInt, spoilersDeployedBool);
                    if (AoAOk(output, exportflag) && StabilityDerivativeExportFile.Export(output, filecache))
                    {
                        n++;
                    }
                }
                if (n > 0)
                {
                    filecache.FlushTextFileLines();
                    PopupDialog.SpawnPopupDialog(new Vector2(0, 0), new Vector2(0, 0), "FARStabDerivLoopCount", Localizer.Format("FAREditorStabDerivLoopDone"), Localizer.Format("FAREditorStabDerivLoopDoneExp", n), Localizer.Format("FARGUIOKButton"), true, HighLogic.UISkin);
                }
                else
                {
                    PopupDialog.SpawnPopupDialog(new Vector2(0, 0), new Vector2(0, 0), "FARStabDerivSaveError", Localizer.Format("FAREditorStabDerivSaveError"), Localizer.Format("FAREditorStabDerivSaveErrorExp"), Localizer.Format("FARGUIOKButton"), true, HighLogic.UISkin);
                }
                return; // in the LoopExport case skip the usual calculation
            }

            StabilityDerivExportOutput stabDerivResult = simManager.StabDerivCalculator.CalculateStabilityDerivs(body, altitudeDouble, machDouble, flapsettingInt, spoilersDeployedBool);

            if (!AoAOk(stabDerivResult, exportflag))
            {
                PopupDialog.SpawnPopupDialog(new Vector2(0, 0), new Vector2(0, 0), "FARStabDerivError", Localizer.Format("FAREditorStabDerivError"), Localizer.Format("FAREditorStabDerivErrorExp"), Localizer.Format("FARGUIOKButton"), true, HighLogic.UISkin);
            }
            else
            {
                stabDerivOutput        = stabDerivResult.outputvals;
                simManager.vehicleData = stabDerivResult.outputvals;
                SetAngleVectors(stabDerivResult.outputvals.stableCondition.stableAoA);

                if (exportflag == CalcAndExportEnum.CalculateAndExport && !StabilityDerivativeExportFile.Export(stabDerivResult))
                {
                    PopupDialog.SpawnPopupDialog(new Vector2(0, 0), new Vector2(0, 0), "FARStabDerivSaveError", Localizer.Format("FAREditorStabDerivSaveError"), Localizer.Format("FAREditorStabDerivSaveErrorExp"), Localizer.Format("FARGUIOKButton"), true, HighLogic.UISkin);
                }
            }
        }
示例#2
0
 public void UpdateAllText(ExportTextFileCache cache)
 {
     if (BodyTextLoaded())
     {
         cache.UpdateTextFileLines(GetAllLines());
     }
     else
     {
         throw new InvalidOperationException("Cannot save result file to cache because the file was not loaded properly from cache in the first place.");
     }
 }
示例#3
0
 public void LoadBodyText(ExportTextFileCache cache)
 {
     bodytext = new List <string>();
     string[] lines = cache.TextFileLines;
     if (lines.Length == 0)
     {
         bodytextcount = 0;
     }
     else if (lines.Length < 5)
     {
         bodytextcount = -1;
     }
     else
     {
         bool b1 = lines[0].StartsWith("# Created by");
         bool b2 = lines[1] == "# name: data";
         bool b3 = lines[2] == "# type: cell";
         bool b4 = lines[3] == "# ndims: 3";
         bool b5 = lines[4].StartsWith(" 1 1 ");
         if (b1 && b2 && b3 && b4 && b5)
         {
             bodytextcount = int.Parse(lines[4].Remove(0, 5));
             int firstidx = 5;
             int lastidx  = lines.Length - 1;
             for (int i = firstidx; i == firstidx && i < lastidx; i++)
             {
                 if (lines[i] == "")
                 {
                     firstidx = i + 1;
                 }
             }
             for (int i = lastidx; i == lastidx && i > firstidx; i--)
             {
                 if (lines[i] == "")
                 {
                     lastidx = i - 1;
                 }
             }
             for (int i = firstidx; i <= lastidx; i++)
             {
                 bodytext.Add(lines[i]);
             }
         }
         else
         {
             bodytextcount = -1;
         }
     }
 }
示例#4
0
        static public bool Export(Simulation.StabilityDerivExportOutput output, ExportTextFileCache filecache = null)
        {
            StabilityDerivativeExportFile body  = new StabilityDerivativeExportFile();
            ExportTextFileCache           cache = (filecache != null) ? filecache : new ExportTextFileCache();

            body.LoadBodyText(cache);
            if (body.BodyTextLoaded())
            {
                body.AddResultElements(output);
                body.UpdateAllText(cache);
                if (filecache == null)
                {
                    cache.FlushTextFileLines();
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }