/// <summary> /// Initializes a new instance of the <see cref= "T:WorldWind.MainApplication"/> class. /// </summary> public MainApplication() { if(Settings.ConfigurationWizardAtStartup) { // If the settings file doesn't exist, then we are using the // default settings, and the default is to show the Configuration // Wizard at startup. We only want that to happen the first time // World Wind is started, so change the setting to false(the user // can change it to true if they want). if(!File.Exists(Settings.FileName)) { Settings.ConfigurationWizardAtStartup = false; } ConfigurationWizard.Wizard wizard = new ConfigurationWizard.Wizard( Settings ); wizard.TopMost = true; wizard.ShowInTaskbar = true; wizard.ShowDialog(); // TODO: should settings be saved now, in case of program crashes, // and so that XML file on disk matches in-memory settings? } using( this.splashScreen = new Splash() ) { this.splashScreen.Owner = this; this.splashScreen.Show(); this.splashScreen.SetText("Initializing..."); Application.DoEvents(); InitializeComponent(); // ParseArgs may have set the "startFullScreen" flag if(startFullScreen && !FullScreen) { FullScreen = true; } // set Upper and Lower limits for Cache size control, in bytes long CacheUpperLimit = (long)Settings.CacheSizeMegaBytes * 1024L * 1024L; long CacheLowerLimit = (long)Settings.CacheSizeMegaBytes * 768L * 1024L; //75% of upper limit //Set up the cache worldWindow.Cache = new Cache( Settings.CachePath, CacheLowerLimit, CacheUpperLimit, Settings.CacheCleanupInterval, Settings.TotalRunTime ); WorldWind.Net.WebDownload.Log404Errors = World.Settings.Log404Errors; DirectoryInfo worldsXmlDir = new DirectoryInfo( Settings.ConfigPath ); if (!worldsXmlDir.Exists) throw new ApplicationException( string.Format(CultureInfo.CurrentCulture, "World Wind configuration directory '{0}' could not be found.", worldsXmlDir.FullName)); FileInfo[] worldXmlDescriptorFiles = worldsXmlDir.GetFiles("*.xml"); int worldIndex = 0; menuItemFile.MenuItems.Add( 0, new System.Windows.Forms.MenuItem("-")); foreach (FileInfo worldXmlDescriptorFile in worldXmlDescriptorFiles) { try { Log.Write(Log.Levels.Debug+1, "CONF", "checking world " + worldXmlDescriptorFile.FullName + " ..."); World w = WorldWind.ConfigurationLoader.Load(worldXmlDescriptorFile.FullName, worldWindow.Cache); if(!availableWorldList.Contains(w.Name)) this.availableWorldList.Add(w.Name, worldXmlDescriptorFile.FullName); w.Dispose(); System.Windows.Forms.MenuItem mi = new System.Windows.Forms.MenuItem(w.Name, new System.EventHandler(OnWorldChange)); menuItemFile.MenuItems.Add(worldIndex, mi); worldIndex++; } catch( Exception caught ) { splashScreen.SetError( worldXmlDescriptorFile + ": " + caught.Message ); Log.Write(caught); } } Log.Write(Log.Levels.Debug, "CONF", "loading startup world..."); OpenStartupWorld(); // Set up vertical exaggeration sub-menu float[] verticalExaggerationMultipliers = { 0.0f, 1.0f, 1.5f, 2.0f, 3.0f, 5.0f, 7.0f, 10.0f }; foreach (float multiplier in verticalExaggerationMultipliers) { MenuItem curItem = new MenuItem(multiplier.ToString("f1",CultureInfo.CurrentCulture) + "x", new EventHandler(this.menuItemVerticalExaggerationChange)); curItem.RadioCheck = true; this.menuItemVerticalExaggeration.MenuItems.Add(curItem); if (Math.Abs(multiplier - World.Settings.VerticalExaggeration)<0.1f) curItem.Checked = true; } // Load defaults from settings this.menuItemPointGoTo.Checked = World.Settings.CameraIsPointGoto; this.menuItemInertia.Checked = World.Settings.CameraHasInertia; this.menuItemConstantMotion.Checked = World.Settings.CameraHasMomentum; this.menuItemCameraBanks.Checked = World.Settings.CameraBankLock; this.menuItemSunShading.Checked = World.Settings.EnableSunShading; this.menuItemAtmosphericScattering.Checked = World.Settings.EnableAtmosphericScattering; this.menuItemPlanetAxis.Checked = World.Settings.ShowPlanetAxis; this.menuItemShowLatLonLines.Checked = World.Settings.ShowLatLonLines; this.menuItemShowToolbar.Checked = World.Settings.ShowToolbar; this.menuItemLayerManager.Checked = World.Settings.ShowLayerManager; this.worldWindow.ShowLayerManager = World.Settings.ShowLayerManager; this.menuItemLockPlanetAxis.Checked = World.Settings.CameraTwistLock; this.menuItemShowCrosshairs.Checked = World.Settings.ShowCrosshairs; this.menuItemShowPosition.Checked = World.Settings.ShowPosition; this.menuItemBrowserVisible.Checked = World.Settings.BrowserVisible; this.menuItemUseInternalBrowser.Checked = World.Settings.UseInternalBrowser; while (!this.splashScreen.IsDone) System.Threading.Thread.Sleep(50); // Force initial render to avoid showing random contents of frame buffer to user. worldWindow.Render(); WorldWindow.Focus(); } /*webBrowserPanel.Visible = false; webBrowser.Visible = false; menuItemBrowserHoriz.Checked = false; browserSplitterHorz.Visible = false; browserSplitterVert.Visible = false; worldWindow.Dock = DockStyle.Fill;*/ // Center the main window Rectangle screenBounds = Screen.GetBounds(this); this.Location = new Point(screenBounds.Width / 2 - this.Size.Width / 2, screenBounds.Height / 2 - this.Size.Height / 2); }
public MainApplication() { try { //配置 if (Global.Settings.ConfigurationWizardAtStartup) { if (!File.Exists(Global.Settings.FileName)) { Global.Settings.ConfigurationWizardAtStartup = false; } ConfigurationWizard.Wizard wizard = new ConfigurationWizard.Wizard(Global.Settings); wizard.TopMost = true; wizard.ShowInTaskbar = true; wizard.ShowDialog(); } using (this.splashScreen = new Splash()) { this.splashScreen.Owner = this; this.splashScreen.Show(); this.splashScreen.SetText("Initializing..."); Application.DoEvents(); InitializeComponent(); //设置global Global.worldWindow = worldWindow; long CacheUpperLimit = (long)Global.Settings.CacheSizeMegaBytes * 1024L * 1024L; long CacheLowerLimit = (long)Global.Settings.CacheSizeMegaBytes * 768L * 1024L; //75% of upper limit //Set up the cache worldWindow.Cache = new Cache( Global.Settings.CachePath, CacheLowerLimit, CacheUpperLimit, Global.Settings.CacheCleanupInterval, Global.Settings.TotalRunTime); WorldWind.Net.WebDownload.Log404Errors = World.Settings.Log404Errors; DirectoryInfo worldsXmlDir = new DirectoryInfo(Global.Settings.ConfigPath); if (!worldsXmlDir.Exists) { throw new ApplicationException( string.Format(CultureInfo.CurrentCulture, "World Wind configuration directory '{0}' could not be found.", worldsXmlDir.FullName)); } FileInfo[] worldXmlDescriptorFiles = worldsXmlDir.GetFiles("*.xml"); int worldIndex = 0; foreach (FileInfo worldXmlDescriptorFile in worldXmlDescriptorFiles) { try { Log.Write(Log.Levels.Debug + 1, "CONF", "checking world " + worldXmlDescriptorFile.FullName + " ..."); string worldXmlSchema = null; string layerSetSchema = null; if (Global.Settings.ValidateXML) { worldXmlSchema = Global.Settings.ConfigPath + "\\WorldXmlDescriptor.xsd"; layerSetSchema = Global.Settings.ConfigPath + "\\Earth\\LayerSet.xsd"; } World w = WorldWind.ConfigurationLoader.Load( worldXmlDescriptorFile.FullName, worldWindow.Cache, worldXmlSchema, layerSetSchema); if (!availableWorldList.Contains(w.Name)) { this.availableWorldList.Add(w.Name, worldXmlDescriptorFile.FullName); } w.Dispose(); System.Windows.Forms.MenuItem mi = new System.Windows.Forms.MenuItem(w.Name, new System.EventHandler(OnWorldChange)); worldIndex++; } catch (Exception caught) { splashScreen.SetError(worldXmlDescriptorFile + ": " + caught.Message); Log.Write(caught); } } Log.Write(Log.Levels.Debug, "CONF", "loading startup world..."); OpenStartupWorld(); while (!this.splashScreen.IsDone) { System.Threading.Thread.Sleep(50); } // Force initial render to avoid showing random contents of frame buffer to user. worldWindow.Render(); WorldWindow.Focus(); } // Center the main window Rectangle screenBounds = Screen.GetBounds(this); this.Location = new Point(screenBounds.Width / 2 - this.Size.Width / 2, screenBounds.Height / 2 - this.Size.Height / 2); } catch { } }
/// <summary> /// Display Configuration Wizard /// </summary> private void menuItemConfigWizard_Click(object sender, System.EventArgs e) { ConfigurationWizard.Wizard wizard = new ConfigurationWizard.Wizard( Settings ); wizard.ShowDialog(); }