コード例 #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
        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);
            }
        }