internal void EnsureLightCurveForm() { m_LightCurveForm = new frmLightCurve(this, m_AddinsController); m_LightCurveForm.Show(m_MainFormView); m_LightCurveForm.Update(); }
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); string videoFile = GetVideoFileMatchingLcFile(lcFile, fileName); if (!string.IsNullOrEmpty(videoFile) && File.Exists(videoFile)) { if (m_VideoController.OpenVideoFile(videoFile, new TangraOpenFileArgs { FrameRate = lcFile.Header.FramesPerSecond, BitPix = lcFile.Footer.DataBitPix, SerTiming = lcFile.Header.SerTimingType })) { TangraContext.Current.CanPlayVideo = false; 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; } }