void IUiController.Render(Earth3d window)
        {
            lines.DrawLines(window.RenderContext11, 1);

            return;
        }
 public void PreRender(Earth3d window)
 {
 }
        public void PreRender(Earth3d window)
        {
            if (tour == null || tour.CurrentTourStop == null)
            {
                return;
            }

            UpdateSlideStates();
        }
        public void Render(Earth3d window)
        {
            window.SetupMatricesOverlays();
            window.RenderContext11.DepthStencilMode = DepthStencilMode.Off;

            if (tour == null || tour.CurrentTourStop == null)
            {
                return;
            }

            if (ProjectorServer)
            {
                overlayBlend.State = true;
            }

            if (!onTarget && !ProjectorServer)
            {
                slideStartTime = SpaceTimeController.MetaNow;
                if (Earth3d.MainWindow.OnTarget(Tour.CurrentTourStop.Target))
                {
                    onTarget = true;
                    overlayBlend.State = !Tour.CurrentTourStop.FadeInOverlays;
                    overlayBlend.TargetState = true;

                    if (!PreRoll)
                    {
                        if (tour.CurrentTourStop.MusicTrack != null)
                        {
                            tour.CurrentTourStop.MusicTrack.Play();
                        }

                        if (tour.CurrentTourStop.VoiceTrack != null)
                        {
                            tour.CurrentTourStop.VoiceTrack.Play();
                        }

                        foreach (Overlay overlay in tour.CurrentTourStop.Overlays)
                        {
                            overlay.Play();
                        }
                    }

                    LayerManager.SetVisibleLayerList(tour.CurrentTourStop.Layers);

                    if (tour.CurrentTourStop.KeyFramed)
                    {
                        tour.CurrentTourStop.KeyFrameMover.CurrentDateTime = tour.CurrentTourStop.StartTime;
                        tour.CurrentTourStop.KeyFrameMover.CurrentPosition = tour.CurrentTourStop.Target.CamParams;
                        tour.CurrentTourStop.KeyFrameMover.MoveTime = (double)(tour.CurrentTourStop.Duration.TotalMilliseconds / 1000.0);
                        Earth3d.MainWindow.Mover = tour.CurrentTourStop.KeyFrameMover;
                    }
                    else if (tour.CurrentTourStop.EndTarget != null && tour.CurrentTourStop.EndTarget.ZoomLevel != -1)
                    {
                        if (tour.CurrentTourStop.Target.Type == ImageSetType.SolarSystem)
                        {
                            tour.CurrentTourStop.Target.UpdatePlanetLocation(SpaceTimeController.UtcToJulian(tour.CurrentTourStop.StartTime));
                            tour.CurrentTourStop.EndTarget.UpdatePlanetLocation(SpaceTimeController.UtcToJulian(tour.CurrentTourStop.EndTime));
                        }

                        Earth3d.MainWindow.Mover = new ViewMoverKenBurnsStyle(tour.CurrentTourStop.Target.CamParams, tour.CurrentTourStop.EndTarget.CamParams, tour.CurrentTourStop.Duration.TotalMilliseconds / 1000.0, tour.CurrentTourStop.StartTime, tour.CurrentTourStop.EndTime, tour.CurrentTourStop.InterpolationType);

                    }

                    Settings.TourSettings = tour.CurrentTourStop;
                    SpaceTimeController.Now = tour.CurrentTourStop.StartTime;
                    SpaceTimeController.SyncToClock = false;
                }
            }

            if (currentMasterSlide != null)
            {
                foreach (Overlay overlay in currentMasterSlide.Overlays)
                {
                    overlay.TweenFactor = 1f;

                    overlay.Draw3D(window.RenderContext11, 1.0f, false);
                }
            }

            if (onTarget || ProjectorServer)
            {
                foreach (Overlay overlay in tour.CurrentTourStop.Overlays)
                {
                    if (!Tour.CurrentTourStop.KeyFramed || (overlay.Animate && overlay.AnimationTarget == null))
                    {
                        overlay.TweenFactor = (float)CameraParameters.EaseCurve(tour.CurrentTourStop.TweenPosition, overlay.InterpolationType == InterpolationType.Default ? tour.CurrentTourStop.InterpolationType : overlay.InterpolationType);
                    }
                    overlay.Draw3D(window.RenderContext11, overlayBlend.Opacity, false);
                }
            }
        }
 void IUiController.Render(Earth3d window)
 {
     return;
 }
        private void Earth3d_Load(object sender, System.EventArgs e)
        {
            CheckOSVersion();
            string path = Properties.Settings.Default.ImageSetUrl;

            if (Properties.Settings.Default.ImageSetUrl.ToLower().Contains("imagesetsnew"))
            {
                Properties.Settings.Default.ImageSetUrl = "http://www.worldwidetelescope.org/wwtweb/catalog.aspx?X=ImageSets5";
            }
             
            Earth3d.MainWindow = this;
            this.dsm = new DataSetManager();
            Constellations.Containment = this.constellationCheck;

            ContextSearch.InitializeDatabase(true);

            LoadExploreRoot();
            if (explorerRoot != null)
            {
                ContextSearch.AddFolderToSearch(explorerRoot, true);
            }
            ContextSearch.AddCatalogs(true);

            BackInitDelegate initBackground = SearchInit;

            initBackground.BeginInvoke(null, null);

            this.WindowState = FormWindowState.Maximized;



            this.FormBorderStyle = TouchKiosk ? FormBorderStyle.None : FormBorderStyle.Sizable;
            TileCache.StartQueue();
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.UserPaint, true);
            Earth3d.MainWindow.Config.DomeTilt = (float)Properties.Settings.Default.DomeTilt;
            if (ProjectorServer)
            {
                ShowFullScreen(true);
                this.timer.Interval = 1000;
                this.InputTimer.Enabled = false;
                Cursor.Hide();
                Properties.Settings.Default.ShowCrosshairs = false;
                Properties.Settings.Default.SolarSystemMultiRes = true;
                NetControl.Start();

            }
            else
            {
                if (Properties.Settings.Default.ListenMode || Settings.DomeView)
                {
                    NetControl.Start();
                }
            }
            if (Settings.MasterController)
            {
                NetControl.StartStatusListner();
            }

            if (Settings.MasterController)
            {
                NetControl.LoadNodeList();
            }

            if (Earth3d.TouchKiosk)
            {
                this.menuTabs.IsVisible = false;
                this.kioskTitleBar.Visible = true;
                Properties.Settings.Default.ShowTouchControls = true;
                ShowFullScreen(true);
            }

            if (NoUi)
            {
                this.menuTabs.IsVisible = false;
                Properties.Settings.Default.ShowTouchControls = true;
                ShowFullScreen(true);
            }

            Tile.GrayscaleStyle = Properties.Settings.Default.MonochromeImageStyle;



            // This forces a init at startup does not do anything but force the static contstuctor to fire now
            LayerManager.LoadTree();

            listenUpBoysToolStripMenuItem.Checked = Properties.Settings.Default.ListenMode;
            int id = Properties.Settings.Default.StartUpLookAt;
            if (Properties.Settings.Default.StartUpLookAt == 5)
            {
                id = Properties.Settings.Default.LastLookAtMode;
            }

            if (Properties.Settings.Default.StartUpLookAt == 6)
            {
                Random rnd = new Random();
                id = rnd.Next(-1, 5);
                Properties.Settings.Default.LastLookAtMode = id;
            }

            CurrentImageSet = GetDefaultImageset((ImageSetType)id, BandPass.Visible);

            Properties.Settings.Default.SettingChanging += new System.Configuration.SettingChangingEventHandler(Default_SettingChanging);
            Properties.Settings.Default.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(Default_PropertyChanged);

            if (Properties.Settings.Default.LocalHorizonMode)
            {
                viewType = ViewTypes.AltAz;
            }
            else
            {
                viewType = ViewTypes.Equatorial;
            }
            InitSpaceNavigator();
            ReadyToRender = true;
            Refresh();

            try
            {
                fov = new FieldOfView(Properties.Settings.Default.FovTelescope, Properties.Settings.Default.FovCamera, Properties.Settings.Default.FovEyepiece);
            }
            catch
            {
            }

            SpaceTimeController.Altitude = Properties.Settings.Default.LocationAltitude;
            SpaceTimeController.Location = Coordinates.FromLatLng(Properties.Settings.Default.LocationLat, Properties.Settings.Default.LocationLng);

            TourPlayer.TourEnded += new EventHandler(TourPlayer_TourEnded);
            if (KmlMarkers == null)
            {
                KmlMarkers = new KmlLabels();
            }
            ReadyToRender = true;
            Initialized = true;
            this.Activate();
            fadeImageSet.State = false;
            fadeImageSet.State = true;
            fadeImageSet.TargetState = false;

            // Force settings 
            Properties.Settings.Default.ActualPlanetScale = true;
            Properties.Settings.Default.HighPercitionPlanets = true;
            Properties.Settings.Default.ShowMoonsAsPointSource = false;
            Properties.Settings.Default.ShowSolarSystem.TargetState = true;

            toolStripMenuItem2.Checked = Settings.MasterController;

            viewCamera.Target = SolarSystemObjects.Sun;

            if (!ProjectorServer)
            {
                webServer.Startup();

                sampConnection = new Samp();

                // Register goto
                SampMessageHandler.RegiseterMessage(new SampCoordPointAtSky(new CoordPointAtSkyDelegate(SampGoto)));
                SampMessageHandler.RegiseterMessage(new SampTableLoadVoTable(new TableLoadVoTableDelegate(SampLoadTable)));
                SampMessageHandler.RegiseterMessage(new SampImageLoadFits(new ImageLoadFitsDelegate(SampLoadFitsImage)));
                SampMessageHandler.RegiseterMessage(new SampTableHighlightRow(new TableHighlightRowDelegate(SampHighlightRow)));

                NetworkChange.NetworkAddressChanged += new NetworkAddressChangedEventHandler(NetworkChange_NetworkAddressChanged);

                MidiMapManager.Startup();

            }

            Fader.TargetState = false;

            hold = new Text3dBatch(80);
            hold.Add(new Text3d(new Vector3d(0, 0, 1), new Vector3d(0, 1, 0), " 0hr123456789-+", 80, .0001f));
            hold.Add(new Text3d(new Vector3d(0, 0, 1), new Vector3d(0, 1, 0), "JanuyFebMcApilg", 80, .0001f));
            hold.Add(new Text3d(new Vector3d(0, 0, 1), new Vector3d(0, 1, 0), "stSmOoNvDBCEdqV", 80, .0001f));
            hold.Add(new Text3d(new Vector3d(0, 0, 1), new Vector3d(0, 1, 0), "jxGHILPRTU", 80, .0001f));
            hold.PrepareBatch();

            Constellations.InitializeConstellationNames();

            if (Properties.Settings.Default.ShowClientNodeList && !ProjectorServer)
            {

                ClientNodeList.ShowNodeList();
            }

            if (DetachScreenId > -1)
            {
                FreeFloatRenderWindow(DetachScreenId);
            }

            if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.RefreshToken))
            {
                WindowsLiveSignIn();
            }
        }
        static void Main(string[] args)
        {
 


            CultureInfo culture = new CultureInfo("en-US", false);
            System.Threading.Thread.CurrentThread.CurrentCulture = culture;
            Application.CurrentCulture = culture;
            System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.AboveNormal;
            Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;
 
            DateTime now = DateTime.Now;
            bool singleInstance = true;


            foreach (string arg in args)
            {
             
                if (arg == "-logging")
                {
                    Logging = true;
                }


                if (arg == "-kiosk")
                {
                    TouchKiosk = true;
                }

                if (arg == "-domeviewer")
                {
                    DomeViewer = true;
                    singleInstance = false;
                    HideSplash = true;
                    TileCache.NodeID++;
                }

                if (arg == "-noui")
                {
                    NoUi = true;
                }

                if (arg == "-dumpshaders")
                {
                    DumpShaders = true;
                }

                if (arg.StartsWith("-screen:"))
                {
                    try
                    {
                        TargetScreenId = int.Parse(arg.Substring(arg.LastIndexOf(":") + 1));
                    }
                    catch
                    {
                    }
                }

                if (arg.StartsWith("-detach:"))
                {
                    try
                    {
                        DetachScreenId = int.Parse(arg.Substring(arg.LastIndexOf(":") + 1));
                    }
                    catch
                    {
                    }
                }
            }

            AlertMessage = RegisterWindowMessage("WWT Launch Tour");
            ChangeWindowMessageFilter(AlertMessage, 1);

            if (args.Length > 0)
            {
                if (args[0] == "launch")
                {
                    Process.Start("wwtexplorer.exe");
                    return;
                }
                if (args[0] == "restart")
                {
                    singleInstance = false;
                    HideSplash = true;
                    RestartedWithoutTour = true;
                }

                if (args[0].ToLower().EndsWith(".kml") || args[0].ToLower().EndsWith(".kmz") || args[0].ToLower().EndsWith(".wtt") || args[0].ToLower().EndsWith(".wtml") || args[0].ToLower().EndsWith(".wwtfig") || args[0].ToLower().EndsWith(".wwtl"))
                {
                    if (File.Exists(args[0]))
                    {
                        launchTourFile = args[0];
                    }
                }
            }

            if (singleInstance)
            {
                Process[] RunningProcesses = Process.GetProcessesByName("WWTExplorer");


                if (RunningProcesses.Length > 1)
                {
                    foreach (Process p in RunningProcesses)
                    {
                        if (p.Id != Process.GetCurrentProcess().Id)
                        {
                            SendWMData(p.MainWindowHandle, launchTourFile);
                        }
                    }
                    return;
                }
            }

            PulseMe.PulseForUpdate = Earth3d.PulseForUpdate;

            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            CheckDefaultProperties(true);
            defaultWebProxy = WebRequest.DefaultWebProxy;
            UpdateProxySettings();


            Language.CurrentLanguage =
                new Language(Properties.Settings.Default.LanguageName,
                             Properties.Settings.Default.LanguageUrl,
                             Properties.Settings.Default.LanguageCode,
                             Properties.Settings.Default.ExploreRootUrl,
                             Properties.Settings.Default.ImageSetUrl,
                             Properties.Settings.Default.SharedCacheServer);

            CacheProxy.BaseUrl = Properties.Settings.Default.SharedCacheServer;

            try
            {
                if (!Earth3d.CheckForUpdates(false))
                {
                    return;
                }
            }
            catch
            {
            }

            try
            {
                RegisterKnownFileTypes();
            }
            catch
            {
            }


            // Check for failed Startup
            if (CheckStartFlag())
            {
                if (UiTools.ShowMessageBox(Language.GetLocalizedText(688, "WorldWide Telescope failed to complete the last startup attempt. Would you like WorldWide Telescope to attempt an auto reset of the data directory?"), Language.GetLocalizedText(3, "Microsoft WorldWide Telescope"), MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    ResetDataDirectory();
                }
            }
            SetStartFlag();



            using (Earth3d frm = new Earth3d())
            {
                //Stopwatch sw = new Stopwatch();
                try
                {
                    frm.Show();
                    frm.Refresh();
                    if (!frm.Created)
                    {
                        return;
                    }
                }
                catch
                {
                    return;
                }


                MainLoop(frm);

            }
            if (LanguageReboot)
            {
                string path = System.Reflection.Assembly.GetExecutingAssembly().Location;

                Process.Start(path, "restart");
            }
        }
        public void Render(Earth3d window)
        {
            window.SetupMatricesOverlays();
            window.RenderContext11.DepthStencilMode = DepthStencilMode.Off;

            if (tour == null || tour.CurrentTourStop == null)
            {
                if (Properties.Settings.Default.ShowSafeArea && tour != null && tour.EditMode && !Capturing)
                {
                    DrawSafeZone(window);
                }
                return;
            }

            foreach (Overlay overlay in tour.CurrentTourStop.Overlays)
            {
                if (overlay.Animate && Tour.CurrentTourStop.KeyFramed)
                {
                    overlay.TweenFactor = tour.CurrentTourStop.TweenPosition;
                }
                else if (!Tour.CurrentTourStop.KeyFramed)
                {
                    overlay.TweenFactor = tour.CurrentTourStop.TweenPosition < .5f ? 0f : 1f;
                }
                overlay.Draw3D(window.RenderContext11, 1.0f, true);
            }

            if (Properties.Settings.Default.ShowSafeArea && tour != null && tour.EditMode && !Capturing)
            {
                DrawSafeZone(window);
            }
            selection.Draw3D(window.RenderContext11, 1.0f);

            if (!Scrubbing)
            {
                if (CurrentEditor != null)
                {
                    CurrentEditor.Render(window);
                }

                Settings.TourSettings = null;
            }
        }
        private Bitmap GetChartImageBitmap(Earth3d window)
        {
            Bitmap bmp = null;
            if (chartType == ChartTypes.Histogram)
            {
                if (!Stats.Computed)
                {
                    Stats = layer.GetSingleColumnHistogram(TargetColumn);
                }
                bmp = GetBarChartBitmap(Stats);

                texture = Texture11.FromBitmap( bmp, 0);

            }

            else if (chartType == ChartTypes.BarChart)
            {
                if (!Stats.Computed)
                {
                    Stats = layer.GetDomainValueBarChart(domainColumn, targetColumn, denominatorColumn, statType);
                }
                bmp = GetBarChartBitmap(Stats);

                texture = Texture11.FromBitmap(bmp, 0);

            }
            else if (chartType == ChartTypes.TimeChart)
            {
                if (!Stats.Computed)
                {
                    Stats = layer.GetDateHistogram(TargetColumn, DateFilter);
                }
                bmp = GetBarChartBitmap(Stats);

                texture = Texture11.FromBitmap(bmp, 0);

            }

            Width = bmp.Width;
            Height = bmp.Height;
            Top = (int)window.RenderContext11.ViewPort.Height - (Height + 120);
            Left = (int)window.RenderContext11.ViewPort.Width / 2 - (Width / 2);

            return bmp;
        }
 public void Render(Earth3d window)
 {
     showEditUi = true;
     return ;
 }
        public void Render(Earth3d window)
        {
            //todo11 reanble this
            if (texture == null)
            {
                Bitmap bmp = null;
                bmp = GetChartImageBitmap(window);
                bmp.Dispose();
            }

            Sprite2d.Draw2D(window.RenderContext11, texture, new SizeF(texture.Width, texture.Height), new PointF(0, 0), 0, new PointF(Left + texture.Width / 2, Top + texture.Height / 2), Color.White);

            if (!String.IsNullOrEmpty(HoverText))
            {
                Rectangle recttext = new Rectangle((int)(hoverPoint.X + 15), (int)(hoverPoint.Y - 8), 0, 0);
             }

            return;
        }
        public void Render(Earth3d window)
        {
            //todo11 reanble this
            if (texture == null)
            {
                Bitmap bmp = GetChartImageBitmap(window);
                bmp.Dispose();
            }

            Sprite2d.Draw2D(window.RenderContext11, texture, new SizeF(texture.Width, texture.Height), new PointF(0, 0), 0, new PointF(Left + texture.Width / 2, Top + texture.Height / 2), Color.White);
        }
 public void PreRender(Earth3d window)
 {
     if (OverlayLayer != null)
     {
         OverlayLayer.ShowEditUi = true;
         OverlayLayer.UiLines = lines;
     }
 }
        public void Render(Earth3d window)
        {
            if (popup == null)
            {
                popup = new ImageAlignPopup();
                popup.Owner = Earth3d.MainWindow;
                popup.Show();

            }
            // todo Draw Achor and tanget points..
            return;
        }
        public static void MainLoop(Earth3d frm)
        {
            // Hook the application's idle event     
            System.Windows.Forms.Application.AddMessageFilter(new DataMessageFilter());
            System.Windows.Forms.Application.Idle += new EventHandler(OnApplicationIdle);
            System.Windows.Forms.Application.Run(frm);

        }
        public void PreRender(Earth3d window)
        {
            if (tour.CurrentTourStop != null)
            {
                if (Scrubbing)
                {
                    Settings.TourSettings = tour.CurrentTourStop;
                    TimeSpan slideElapsedTime = SpaceTimeController.MetaNow - ScrubStartTime;

                    if (ScrubbingBackwards)
                    {
                        if (slideElapsedTime > tour.CurrentTourStop.Duration)
                        {
                            Scrubbing = false;
                            tour.CurrentTourStop.TweenPosition = 0.0f;
                        }
                        else
                        {
                            tour.CurrentTourStop.TweenPosition = Math.Min(1, 1 - (float)(slideElapsedTime.TotalMilliseconds / tour.CurrentTourStop.Duration.TotalMilliseconds));
                            TimeLine.RefreshUi();
                        }
                    }
                    else
                    {
                        if (slideElapsedTime > tour.CurrentTourStop.Duration)
                        {
                            Scrubbing = false;
                            tour.CurrentTourStop.TweenPosition = 1.0f;
                        }
                        else
                        {
                            tour.CurrentTourStop.TweenPosition = (float)(slideElapsedTime.TotalMilliseconds / tour.CurrentTourStop.Duration.TotalMilliseconds);
                            TimeLine.RefreshUi();
                        }
                    }
                }
                else
                {
                    if (CurrentEditor != null)
                    {
                        CurrentEditor.PreRender(window);
                    }
                }
            }
        }
        private void Earth3d_FormClosed(object sender, FormClosedEventArgs e)
        {
            try
            {

                if (sampConnection.Connected)
                {
                    sampConnection.Unregister();
                }
            }
            catch
            {
            }

            try
            {
                webServer.Shutdown();
            }
            catch
            {
            }

            if (Settings.MasterController)
            {
                NetControl.SaveNodeList();
            }

            MidiMapManager.Shutdown();

            if (config.Master == false)
            {
                NetControl.ReportStatus(ClientNodeStatus.Offline, "Shutting Down", "");
            }


            try
            {
                pause = true;
                config.SaveToXml();
            }
            catch
            {
            }
            try
            {

                ShutdownServices();

                MainWindow = null;
            }
            catch
            {
            }

            try
            {
                TourDocument.ClearTempDirectory();
            }
            catch
            {
            }

            if (settingsDirty)
            {
                Properties.Settings.Default.Save();
            }
        }
        private void DrawSafeZone(Earth3d window)
        {
            Rectangle rect = window.RenderWindow.ClientRectangle;

            int x = rect.Width / 2;
            int y = rect.Height / 2;

            int ratioWidth = rect.Height* 4 /3;
            int halfWidth = (rect.Width - ratioWidth)/2;

            DrawTranparentBox(window.RenderContext11, new Rectangle(-x, -y, halfWidth, rect.Height));
            DrawTranparentBox(window.RenderContext11, new Rectangle((rect.Width - halfWidth)-x, -y, halfWidth, rect.Height));
        }
        public static void MainLoop(Earth3d frm)
        {
            // Hook the application's idle event     
            Application.AddMessageFilter(new DataMessageFilter());
            Application.Idle += OnApplicationIdle;
            Application.Run(frm);

        }