internal void OpenSpectraFile(string fileName) { if (File.Exists(fileName)) { SpectraFile spectraFile = SpectraFile.Load(fileName); if (spectraFile != null) { DisplaySpectra(spectraFile.Data, null, m_DisplaySettings, fileName); string videoFile = m_VideoController.GetVideoFileMatchingLcFile(spectraFile.Header.PathToVideoFile, fileName); if (!string.IsNullOrEmpty(videoFile) && File.Exists(videoFile)) { if (m_VideoController.OpenVideoFile(videoFile)) { TangraContext.Current.CanPlayVideo = false; } } else { // NOTE: No video file found, just show the saved averaged frame TangraContext.Current.Reset(); if (spectraFile.Data.MeasurementInfo.FrameBitmapPixels != null && spectraFile.Data.MeasurementInfo.FrameBitmapPixels.Length > 0) { if (m_VideoController.SingleBitmapFile(spectraFile.Data.MeasurementInfo.FrameBitmapPixels, spectraFile.Header.Width, spectraFile.Header.Height)) { TangraContext.Current.CanPlayVideo = false; m_VideoController.UpdateViews(); PSFFit.SetDataRange(spectraFile.Header.BitPix, spectraFile.Header.DataAav16NormVal); } } TangraContext.Current.CanPlayVideo = false; TangraContext.Current.CanScrollFrames = false; } TangraContext.Current.FileName = Path.GetFileName(fileName); TangraContext.Current.FileFormat = spectraFile.Header.SourceInfo; m_VideoController.UpdateViews(); } RegisterRecentSpectraFile(fileName); } }
public void OpenLcFile(string fileName) { var fi = new FileInfo(fileName); double expectedMemoryMbNeeded = 500 /* For Tangra to operate*/ + 20 * fi.Length / (1024 * 1024) /* For the .lc file to be unpacked and loaded in memory */; double availableMemoryMb = CrossPlaform.GetAvailableMemoryInMegabytes(); if (expectedMemoryMbNeeded > availableMemoryMb) { if (MessageBox.Show( m_MainFormView, string.Format("It appears that you may be running in a low memory conditions and opening this file will require at least {0}Gb of free memory. Do you wish to continue?", (Math.Ceiling(expectedMemoryMbNeeded / 512.0) / 2).ToString("0.0")), "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { return; } } m_MainFormView.Cursor = Cursors.WaitCursor; LCFile lcFile = null; try { m_MainFormView.Update(); lcFile = LCFile.Load(fileName, m_VideoController); if (lcFile != null) { ReduceLightCurveOperation operation = (ReduceLightCurveOperation)m_VideoController.SetOperation <ReduceLightCurveOperation>(this, false); operation.SetLCFile(lcFile); bool flipVertically; bool flipHorizontally; FramePlayer.TranslateFlipRotate(lcFile.Footer.RotateFlipType, out flipVertically, out flipHorizontally); object videoFile = GetVideoFileMatchingLcFile(lcFile, fileName); if (videoFile is string && !string.IsNullOrEmpty((string)videoFile) && File.Exists((string)videoFile)) { if (m_VideoController.OpenVideoFile((string)videoFile, new TangraOpenFileArgs { FrameRate = lcFile.Header.FramesPerSecond, BitPix = lcFile.Footer.DataBitPix, SerTiming = lcFile.Header.SerTimingType })) { TangraContext.Current.CanPlayVideo = false; m_VideoController.UpdateViews(); } } else if (videoFile is string[] && ((string[])videoFile).Length > 0) { var fitsFiles = (string[])videoFile; if (m_VideoController.OpenFitsFileSequence(Path.GetDirectoryName(fitsFiles[0]), fitsFiles, new LCFITSTimeStampReader(lcFile), null, 0, flipVertically, flipHorizontally, (int)lcFile.Data[0][0].CurrFrameNo)) { TangraContext.Current.CanPlayVideo = false; if (lcFile.Footer.FitsDynamicFromValue != -1 && lcFile.Footer.FitsDynamicToValue != -1) { m_VideoController.SetDisplayIntensifyMode(DisplayIntensifyMode.Dynamic, lcFile.Footer.FitsDynamicFromValue, lcFile.Footer.FitsDynamicToValue); } m_VideoController.UpdateViews(); } } else { // NOTE: No video file found, just show the saved averaged frame bool oldCanProcessLightCurvePixels = TangraContext.Current.CanProcessLightCurvePixels; TangraContext.Current.Reset(); TangraContext.Current.CanProcessLightCurvePixels = oldCanProcessLightCurvePixels; if (lcFile.Footer.AveragedFrameBytes != null) { if (m_VideoController.SingleBitmapFile(lcFile)) { TangraContext.Current.CanPlayVideo = false; m_VideoController.UpdateViews(); PSFFit.SetDataRange(lcFile.Footer.DataBitPix, lcFile.Footer.DataAav16NormVal); } } TangraContext.Current.CanPlayVideo = false; TangraContext.Current.CanScrollFrames = false; m_VideoController.UpdateViews(); } m_Context = new LightCurveContext(lcFile); m_LightCurveForm = new frmLightCurve(this, m_AddinsController, lcFile, fileName); m_LightCurveForm.SetGeoLocation(m_VideoController.GeoLocation); m_LightCurveForm.Show(m_MainFormView); m_LightCurveForm.Update(); // TODO: Review the VideoController-LightCurveController-ReduceLightCurveOperation relation and how they are initialized // TODO: Provide a clean way of initializing the controller/operation state when opening an .lc file! operation.EnterViewLightCurveMode(lcFile, m_VideoController, m_VideoController.ControlerPanel); RegisterRecentFile(RecentFileType.LightCurve, fileName); if (!string.IsNullOrEmpty(m_VideoController.CurrentVideoFileType)) { // Move to the first frame in the light curve m_VideoController.MoveToFrame((int)lcFile.Header.MinFrame); } TangraContext.Current.FileName = Path.GetFileName(fileName); TangraContext.Current.FileFormat = m_lcFile.Header.SourceInfo; m_VideoController.UpdateViews(); } } catch (IOException ioex) { MessageBox.Show(ioex.Message, "Tangra", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { m_MainFormView.Cursor = Cursors.Default; } }