private void FormContainer_Load(object sender, EventArgs e)
        {
            try
            {
                formLog      = new FormLog(this);
                formLog.Left = -1000;
                IntPtr iptr = formLog.Handle; // Force window handle creation
                log = GetLog(formLog.GetTextBox());

                // Create directories and files
                if (!Directory.Exists(GAEnvironment.SettingsPath))
                {
                    Directory.CreateDirectory(GAEnvironment.SettingsPath);
                }

                installDir = Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]) + Path.DirectorySeparatorChar;

                if (!File.Exists(GAEnvironment.NuclideLibraryFile))
                {
                    File.Copy(installDir + "template_nuclides.lib", GAEnvironment.NuclideLibraryFile);
                }

                LoadSettings();

                formWaterfall      = new FormWaterfall(this, settings, log);
                formWaterfall.Left = -1000;
                formROI            = new FormROI(this, settings, log);
                formROI.Left       = -1000;
                formMap            = new FormMap(this, settings, log);
                formMap.Left       = -1000;
                formMain           = new FormMain(this, settings, log);
                formMain.Left      = -1000;

                menuItemLayoutSession_Click(sender, e);

                statusLabel.Text = "";
            }
            catch (Exception ex)
            {
                log.Fatal(ex.Message, ex);
                MessageBox.Show("Unable to load application. See log for details", "Error");

                if (formMain != null)
                {
                    formMain.Shutdown();
                    formMain.Close();
                }

                if (formMap != null)
                {
                    formMap.Close();
                }

                if (formROI != null)
                {
                    formROI.Close();
                }

                if (formWaterfall != null)
                {
                    formWaterfall.Shutdown();
                    formWaterfall.Close();
                }

                if (formLog != null)
                {
                    formLog.Close();
                }

                Environment.Exit(1);
            }
        }
Exemple #2
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            try
            {                
                // Hide tabs on tabcontrol
                tabs.ItemSize = new Size(0, 1);
                tabs.SizeMode = TabSizeMode.Fixed;
                tabs.SelectedTab = pageMenu;

                // Create directories and files
                if (!Directory.Exists(CrashEnvironment.SettingsPath))
                    Directory.CreateDirectory(CrashEnvironment.SettingsPath);

                if (!Directory.Exists(CrashEnvironment.GEScriptPath))
                    Directory.CreateDirectory(CrashEnvironment.GEScriptPath);                
                
                string InstallDir = Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]) + Path.DirectorySeparatorChar;                

                if (!File.Exists(CrashEnvironment.SettingsFile))
                    File.Copy(InstallDir + "template_settings.xml", CrashEnvironment.SettingsFile, false);

                if (!File.Exists(CrashEnvironment.NuclideLibraryFile))
                    File.Copy(InstallDir + "template_nuclides.lib", CrashEnvironment.NuclideLibraryFile, false);

                if (!File.Exists(CrashEnvironment.GEScriptPath + Path.DirectorySeparatorChar + "Nai-2tom.py"))
                    File.Copy(InstallDir + "template_Nai-2tom.py", CrashEnvironment.GEScriptPath + Path.DirectorySeparatorChar + "Nai-2tom.py", true);

                if (!File.Exists(CrashEnvironment.GEScriptPath + Path.DirectorySeparatorChar + "Nai-3tom.py"))
                    File.Copy(InstallDir + "template_Nai-3tom.py", CrashEnvironment.GEScriptPath + Path.DirectorySeparatorChar + "Nai-3tom.py", true);

                // Load settings
                LoadSettings();
                menuItemConvertToLocalTime.Checked = settings.DisplayLocalTime;

                LoadNuclideLibrary();

                // Create forms
                formWaterfallLive = new FormWaterfallLive(settings.ROIList);                
                formROILive = new FormROILive(settings.ROIList);                
                frmMap = new FormMap();                

                // Set up custom events
                formWaterfallLive.SetSessionIndexEvent += SetSessionIndexEvent;
                formROILive.SetSessionIndexEvent += SetSessionIndexEvent;
                frmMap.SetSessionIndexEvent += SetSessionIndexEvent;

                tbSetupLivetime.KeyPress += CustomEvents.Integer_KeyPress;
                tbSetupSpectrumCount.KeyPress += CustomEvents.Integer_KeyPress;
                tbSetupDelay.KeyPress += CustomEvents.Integer_KeyPress;

                // Populate UI
                tbSessionDir.Text = settings.SessionRootDirectory;
                PopulateDetectorTypeList();
                PopulateDetectorList();
                PopulateDetectors();                

                lblConnectionStatus.ForeColor = Color.Red;
                lblConnectionStatus.Text = "Not connected";
                lblSetupChannel.Text = "";
                lblSessionChannel.Text = "";
                lblSessionEnergy.Text = "";
                lblSetupEnergy.Text = "";
                lblDetector.Text = "";
                separatorDetector.Visible = false;

                lblSessionDetector.Text = "";
                lblBackground.Text = "";
                lblComment.Text = "";
                ClearSpectrumInfo();                                               

                // Start networking thread
                netThread.Start();
                while (!netThread.IsAlive) ;

                // Start timer listening for network messages
                timer.Interval = 10;
                timer.Tick += timer_Tick;
                timer.Start();
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message + Path.DirectorySeparatorChar + ex.StackTrace, "Error");
                Environment.Exit(1);
            }
        }