private void BUT_sitl_Click(object sender, EventArgs e) { var form = new SITL(); form.Show(); }
public MainV2() { log.Info("Mainv2 ctor"); SetStyle(ControlStyles.OptimizedDoubleBuffer, true); // set this before we reset it Settings.Instance["NUM_tracklength"] = "200"; // create one here - but override on load Settings.Instance["guid"] = Guid.NewGuid().ToString(); // load config LoadConfig(); // force language to be loaded L10N.GetConfigLang(); ShowAirports = true; // setup adsb Utilities.adsb.UpdatePlanePosition += adsb_UpdatePlanePosition; Form splash = Program.Splash; splash.Refresh(); Application.DoEvents(); instance = this; //disable dpi scaling if (Font.Name != "宋体") { //Chinese displayed normally when scaling. But would be too small or large using this line of code. using (var g = CreateGraphics()) { Font = new Font(Font.Name, 8.25f*96f/g.DpiX, Font.Style, Font.Unit, Font.GdiCharSet, Font.GdiVerticalFont); } } InitializeComponent(); MyView = new MainSwitcher(this); View = MyView; AdvancedChanged += updateAdvanced; //startup console TCPConsole.Write((byte) 'S'); _connectionControl = toolStripConnectionControl.ConnectionControl; _connectionControl.CMB_baudrate.TextChanged += this.CMB_baudrate_TextChanged; _connectionControl.CMB_serialport.SelectedIndexChanged += this.CMB_serialport_SelectedIndexChanged; _connectionControl.CMB_serialport.Click += this.CMB_serialport_Click; _connectionControl.cmb_sysid.Click += cmb_sysid_Click; _connectionControl.ShowLinkStats += (sender, e) => ShowConnectionStatsForm(); srtm.datadirectory = Settings.GetDataDirectory() + "srtm"; var t = Type.GetType("Mono.Runtime"); MONO = (t != null); speechEngine = new Speech(); Warnings.CustomWarning.defaultsrc = comPort.MAV.cs; Warnings.WarningEngine.Start(); // proxy loader - dll load now instead of on config form load new Transition(new TransitionType_EaseInEaseOut(2000)); foreach (object obj in Enum.GetValues(typeof (Firmwares))) { _connectionControl.TOOL_APMFirmware.Items.Add(obj); } if (_connectionControl.TOOL_APMFirmware.Items.Count > 0) _connectionControl.TOOL_APMFirmware.SelectedIndex = 0; comPort.BaseStream.BaudRate = 115200; PopulateSerialportList(); if (_connectionControl.CMB_serialport.Items.Count > 0) { _connectionControl.CMB_baudrate.SelectedIndex = 8; _connectionControl.CMB_serialport.SelectedIndex = 0; } // ** Done splash.Refresh(); Application.DoEvents(); string temp = Settings.Instance.ComPort; if (!string.IsNullOrEmpty(temp)) { _connectionControl.CMB_serialport.SelectedIndex = _connectionControl.CMB_serialport.FindString(temp); if (_connectionControl.CMB_serialport.SelectedIndex == -1) { _connectionControl.CMB_serialport.Text = temp; // allows ports that dont exist - yet } comPort.BaseStream.PortName = temp; comPortName = temp; } string temp2 = Settings.Instance.BaudRate; if (!string.IsNullOrEmpty(temp2)) { _connectionControl.CMB_baudrate.SelectedIndex = _connectionControl.CMB_baudrate.FindString(temp2); if (_connectionControl.CMB_baudrate.SelectedIndex == -1) { _connectionControl.CMB_baudrate.Text = temp2; } } string temp3 = Settings.Instance.APMFirmware; if (!string.IsNullOrEmpty(temp3)) { _connectionControl.TOOL_APMFirmware.SelectedIndex = _connectionControl.TOOL_APMFirmware.FindStringExact(temp3); if (_connectionControl.TOOL_APMFirmware.SelectedIndex == -1) _connectionControl.TOOL_APMFirmware.SelectedIndex = 0; MainV2.comPort.MAV.cs.firmware = (MainV2.Firmwares) Enum.Parse(typeof (MainV2.Firmwares), _connectionControl.TOOL_APMFirmware.Text); } MissionPlanner.Utilities.Tracking.cid = new Guid(Settings.Instance["guid"].ToString()); // setup guids for droneshare if (!Settings.Instance.ContainsKey("plane_guid")) Settings.Instance["plane_guid"] = Guid.NewGuid().ToString(); if (!Settings.Instance.ContainsKey("copter_guid")) Settings.Instance["copter_guid"] = Guid.NewGuid().ToString(); if (!Settings.Instance.ContainsKey("rover_guid")) Settings.Instance["rover_guid"] = Guid.NewGuid().ToString(); if (Settings.Instance.ContainsKey("language") && !string.IsNullOrEmpty(Settings.Instance["language"])) { changelanguage(CultureInfoEx.GetCultureInfo(Settings.Instance["language"])); } this.Text = splash.Text; titlebar = splash.Text; if (!MONO) // windows only { if (Settings.Instance["showconsole"] != null && Settings.Instance["showconsole"].ToString() == "True") { } else { int win = NativeMethods.FindWindow("ConsoleWindowClass", null); NativeMethods.ShowWindow(win, NativeMethods.SW_HIDE); // hide window } // prevent system from sleeping while mp open var previousExecutionState = NativeMethods.SetThreadExecutionState(NativeMethods.ES_CONTINUOUS | NativeMethods.ES_SYSTEM_REQUIRED); } ChangeUnits(); if (Settings.Instance["theme"] != null) { try { ThemeManager.SetTheme( (ThemeManager.Themes) Enum.Parse(typeof (ThemeManager.Themes), Settings.Instance["theme"].ToString())); } catch (Exception exception) { log.Error(exception); } if (ThemeManager.CurrentTheme == ThemeManager.Themes.Custom) { try { ThemeManager.BGColor = Color.FromArgb(int.Parse(Settings.Instance["theme_bg"].ToString())); ThemeManager.ControlBGColor = Color.FromArgb(int.Parse(Settings.Instance["theme_ctlbg"].ToString())); ThemeManager.TextColor = Color.FromArgb(int.Parse(Settings.Instance["theme_text"].ToString())); ThemeManager.ButBG = Color.FromArgb(int.Parse(Settings.Instance["theme_butbg"].ToString())); ThemeManager.ButBorder = Color.FromArgb(int.Parse(Settings.Instance["theme_butbord"].ToString())); } catch { log.Error("Bad Custom theme - reset to standard"); ThemeManager.SetTheme(ThemeManager.Themes.BurntKermit); } } if (ThemeManager.CurrentTheme == ThemeManager.Themes.HighContrast) { switchlight(new menuicons2()); } } if (Settings.Instance["showairports"] != null) { MainV2.ShowAirports = bool.Parse(Settings.Instance["showairports"]); } // set default ShowTFR = true; // load saved if (Settings.Instance["showtfr"] != null) { MainV2.ShowTFR = Settings.Instance.GetBoolean("showtfr"); } if (Settings.Instance["enableadsb"] != null) { MainV2.instance.EnableADSB = Settings.Instance.GetBoolean("enableadsb"); } // load this before the other screens get loaded if (Settings.Instance["advancedview"] != null) { MainV2.Advanced = Settings.Instance.GetBoolean("advancedview"); } else { // existing user - enable advanced view if (Settings.Instance.Count > 3) { Settings.Instance["advancedview"] = true.ToString(); MainV2.Advanced = true; } else { Settings.Instance["advancedview"] = false.ToString(); } } try { log.Info("Create FD"); FlightData = new GCSViews.FlightData(); log.Info("Create FP"); FlightPlanner = new GCSViews.FlightPlanner(); //Configuration = new GCSViews.ConfigurationView.Setup(); log.Info("Create SIM"); Simulation = new SITL(); //Firmware = new GCSViews.Firmware(); //Terminal = new GCSViews.Terminal(); FlightData.Width = MyView.Width; FlightPlanner.Width = MyView.Width; Simulation.Width = MyView.Width; } catch (ArgumentException e) { //http://www.microsoft.com/en-us/download/details.aspx?id=16083 //System.ArgumentException: Font 'Arial' does not support style 'Regular'. log.Fatal(e); CustomMessageBox.Show(e.ToString() + "\n\n Font Issues? Please install this http://www.microsoft.com/en-us/download/details.aspx?id=16083"); //splash.Close(); //this.Close(); Application.Exit(); } catch (Exception e) { log.Fatal(e); CustomMessageBox.Show("A Major error has occured : " + e.ToString()); Application.Exit(); } if (Settings.Instance["CHK_GDIPlus"] != null) GCSViews.FlightData.myhud.UseOpenGL = !bool.Parse(Settings.Instance["CHK_GDIPlus"].ToString()); if (Settings.Instance["CHK_hudshow"] != null) GCSViews.FlightData.myhud.hudon = bool.Parse(Settings.Instance["CHK_hudshow"].ToString()); try { if (Settings.Instance["MainLocX"] != null && Settings.Instance["MainLocY"] != null) { this.StartPosition = FormStartPosition.Manual; Point startpos = new Point(Settings.Instance.GetInt32("MainLocX"), Settings.Instance.GetInt32("MainLocY")); // fix common bug which happens when user removes a monitor, the app shows up // offscreen and it is very hard to move it onscreen. Also happens with // remote desktop a lot. So this only restores position if the position // is visible. foreach (Screen s in Screen.AllScreens) { if (s.WorkingArea.Contains(startpos)) { this.Location = startpos; break; } } } if (Settings.Instance["MainMaximised"] != null) { this.WindowState = (FormWindowState) Enum.Parse(typeof (FormWindowState), Settings.Instance["MainMaximised"]); // dont allow minimised start state if (this.WindowState == FormWindowState.Minimized) { this.WindowState = FormWindowState.Normal; this.Location = new Point(100, 100); } } if (Settings.Instance["MainHeight"] != null) this.Height = Settings.Instance.GetInt32("MainHeight"); if (Settings.Instance["MainWidth"] != null) this.Width = Settings.Instance.GetInt32("MainWidth"); if (Settings.Instance["CMB_rateattitude"] != null) CurrentState.rateattitudebackup = Settings.Instance.GetByte("CMB_rateattitude"); if (Settings.Instance["CMB_rateposition"] != null) CurrentState.ratepositionbackup = Settings.Instance.GetByte("CMB_rateposition"); if (Settings.Instance["CMB_ratestatus"] != null) CurrentState.ratestatusbackup = Settings.Instance.GetByte("CMB_ratestatus"); if (Settings.Instance["CMB_raterc"] != null) CurrentState.ratercbackup = Settings.Instance.GetByte("CMB_raterc"); if (Settings.Instance["CMB_ratesensors"] != null) CurrentState.ratesensorsbackup = Settings.Instance.GetByte("CMB_ratesensors"); // make sure rates propogate MainV2.comPort.MAV.cs.ResetInternals(); if (Settings.Instance["speechenable"] != null) MainV2.speechEnable = Settings.Instance.GetBoolean("speechenable"); if (Settings.Instance["analyticsoptout"] != null) MissionPlanner.Utilities.Tracking.OptOut = Settings.Instance.GetBoolean("analyticsoptout"); try { if (Settings.Instance["TXT_homelat"] != null) MainV2.comPort.MAV.cs.HomeLocation.Lat = Settings.Instance.GetDouble("TXT_homelat"); if (Settings.Instance["TXT_homelng"] != null) MainV2.comPort.MAV.cs.HomeLocation.Lng = Settings.Instance.GetDouble("TXT_homelng"); if (Settings.Instance["TXT_homealt"] != null) MainV2.comPort.MAV.cs.HomeLocation.Alt = Settings.Instance.GetDouble("TXT_homealt"); // remove invalid entrys if (Math.Abs(MainV2.comPort.MAV.cs.HomeLocation.Lat) > 90 || Math.Abs(MainV2.comPort.MAV.cs.HomeLocation.Lng) > 180) MainV2.comPort.MAV.cs.HomeLocation = new PointLatLngAlt(); } catch { } } catch { } if (CurrentState.rateattitudebackup == 0) // initilised to 10, configured above from save { CustomMessageBox.Show( "NOTE: your attitude rate is 0, the hud will not work\nChange in Configuration > Planner > Telemetry Rates"); } // create log dir if it doesnt exist try { if (!Directory.Exists(Settings.Instance.LogDir)) Directory.CreateDirectory(Settings.Instance.LogDir); } catch (Exception ex) { log.Error(ex); } Microsoft.Win32.SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; // make sure new enough .net framework is installed if (!MONO) { Microsoft.Win32.RegistryKey installed_versions = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP"); string[] version_names = installed_versions.GetSubKeyNames(); //version names start with 'v', eg, 'v3.5' which needs to be trimmed off before conversion double Framework = Convert.ToDouble(version_names[version_names.Length - 1].Remove(0, 1), CultureInfo.InvariantCulture); int SP = Convert.ToInt32(installed_versions.OpenSubKey(version_names[version_names.Length - 1]) .GetValue("SP", 0)); if (Framework < 4.0) { CustomMessageBox.Show("This program requires .NET Framework 4.0. You currently have " + Framework); } } if (Program.IconFile != null) { this.Icon = Icon.FromHandle(((Bitmap)Program.IconFile).GetHicon()); } if (Program.Logo != null && Program.name == "VVVVZ") { MenuDonate.Click -= this.toolStripMenuItem1_Click; MenuDonate.Text = ""; MenuDonate.Image = Program.Logo; MenuDonate.Click += MenuCustom_Click; MenuFlightData.Visible = false; MenuFlightPlanner.Visible = true; MenuConfigTune.Visible = false; MenuHelp.Visible = false; MenuInitConfig.Visible = false; MenuSimulation.Visible = false; MenuTerminal.Visible = false; } else if (Program.Logo != null && Program.names.Contains(Program.name)) { MenuDonate.Click -= this.toolStripMenuItem1_Click; MenuDonate.Text = ""; MenuDonate.Image = Program.Logo; } Application.DoEvents(); Comports.Add(comPort); MainV2.comPort.MavChanged += comPort_MavChanged; // save config to test we have write access SaveConfig(); }