Exemple #1
0
        private void ChooseLocation_Click(object sender, EventArgs e)
        {
            LocationSetup dialog = new LocationSetup();

            dialog.Sky = false;

            dialog.Latitude     = Coordinates.Parse(this.latText.Text);
            dialog.Longitude    = Coordinates.Parse(this.lngText.Text);
            dialog.LocationName = this.locationName.Text;
            dialog.Altitude     = Convert.ToDouble(this.Altitude.Text.Replace("m", "").Replace("'", ""));

            if (dialog.ShowDialog(this) == DialogResult.OK)
            {
                this.latText.Text            = Coordinates.FormatDMS(Properties.Settings.Default.LocationLat = dialog.Latitude);
                this.lngText.Text            = Coordinates.FormatDMS(Properties.Settings.Default.LocationLng = dialog.Longitude);
                this.locationName.Text       = Properties.Settings.Default.LocationName = dialog.LocationName;
                this.Altitude.Text           = (Properties.Settings.Default.LocationAltitude = dialog.Altitude).ToString() + "m";
                SpaceTimeController.Altitude = Properties.Settings.Default.LocationAltitude;
                SpaceTimeController.Location = Coordinates.FromLatLng(Properties.Settings.Default.LocationLat, Properties.Settings.Default.LocationLng);
            }
        }
        bool IUiController.MouseMove(object sender, MouseEventArgs e)
        {
            if (drag)
            {
                Coordinates cursor = Earth3d.MainWindow.GetCoordinatesForScreenPoint(e.X, e.Y);

                switch (dragCorner)
                {
                case DragCorners.NW:
                    Overlay.north = cursor.Lat;
                    Overlay.west  = cursor.Lng;
                    break;

                case DragCorners.N:
                    Overlay.north = cursor.Lat;
                    break;

                case DragCorners.NE:
                    Overlay.north = cursor.Lat;
                    Overlay.east  = cursor.Lng;
                    break;

                case DragCorners.W:
                    Overlay.west = cursor.Lng;
                    break;

                case DragCorners.C:
                    Overlay.north -= (mouseDown.Lat - cursor.Lat);
                    Overlay.west  -= (mouseDown.Lng - cursor.Lng);
                    Overlay.south -= (mouseDown.Lat - cursor.Lat);
                    Overlay.east  -= (mouseDown.Lng - cursor.Lng);

                    break;

                case DragCorners.E:
                    Overlay.east = cursor.Lng;
                    break;

                case DragCorners.SW:
                    Overlay.south = cursor.Lat;
                    Overlay.west  = cursor.Lng;
                    break;

                case DragCorners.S:
                    Overlay.south = cursor.Lat;
                    break;

                case DragCorners.SE:
                    Overlay.south = cursor.Lat;
                    Overlay.east  = cursor.Lng;
                    break;

                default:
                    break;
                }
                mouseDown = cursor;
                UpdateTextBoxes();
                UpdateLines();
                return(true);
            }
            else
            {
                Control wnd    = (Control)sender;
                double  width  = Overlay.east - Overlay.west;
                double  height = Overlay.north - Overlay.south;

                double      range      = Math.Max(width / 40, height / 40);
                Coordinates cursor     = Earth3d.MainWindow.GetCoordinatesForScreenPoint(e.X, e.Y);
                DragCorners dragCorner = DragCorners.None;
                if (cursor.Distance(Coordinates.FromLatLng(Overlay.north, Overlay.west)) < range)
                {
                    dragCorner = DragCorners.NW;
                }
                if (cursor.Distance(Coordinates.FromLatLng(Overlay.north, (Overlay.west + Overlay.east) / 2)) < range)
                {
                    dragCorner = DragCorners.N;
                }
                if (cursor.Distance(Coordinates.FromLatLng(Overlay.north, Overlay.east)) < range)
                {
                    dragCorner = DragCorners.NE;
                }

                if (cursor.Distance(Coordinates.FromLatLng((Overlay.north + Overlay.south) / 2, Overlay.west)) < range)
                {
                    dragCorner = DragCorners.W;
                }

                if (cursor.Distance(Coordinates.FromLatLng((Overlay.north + Overlay.south) / 2, (Overlay.west + Overlay.east) / 2)) < range)
                {
                    dragCorner = DragCorners.C;
                }

                if (cursor.Distance(Coordinates.FromLatLng((Overlay.north + Overlay.south) / 2, Overlay.east)) < range)
                {
                    dragCorner = DragCorners.E;
                }

                if (cursor.Distance(Coordinates.FromLatLng(Overlay.south, Overlay.west)) < range)
                {
                    dragCorner = DragCorners.SW;
                }

                if (cursor.Distance(Coordinates.FromLatLng(Overlay.south, (Overlay.west + Overlay.east) / 2)) < range)
                {
                    dragCorner = DragCorners.S;
                }

                if (cursor.Distance(Coordinates.FromLatLng(Overlay.south, Overlay.east)) < range)
                {
                    dragCorner = DragCorners.SE;
                }

                switch (dragCorner)
                {
                case DragCorners.SE:
                case DragCorners.NW:
                    wnd.Cursor = Cursors.SizeNWSE;
                    break;

                case DragCorners.N:
                case DragCorners.S:
                    wnd.Cursor = Cursors.SizeNS;
                    break;

                case DragCorners.W:
                case DragCorners.E:
                    wnd.Cursor = Cursors.SizeWE;
                    break;

                case DragCorners.C:
                    wnd.Cursor = Cursors.Hand;
                    break;

                case DragCorners.SW:
                case DragCorners.NE:
                    wnd.Cursor = Cursors.SizeNESW;
                    break;

                default:
                    wnd.Cursor = Cursors.Default;
                    break;
                }
            }
            return(false);
        }
        bool IUiController.MouseDown(object sender, MouseEventArgs e)
        {
            double width  = Overlay.east - Overlay.west;
            double height = Overlay.north - Overlay.south;

            double      range  = Math.Max(width / 40, height / 40);
            Coordinates cursor = Earth3d.MainWindow.GetCoordinatesForScreenPoint(e.X, e.Y);

            if (cursor.Distance(Coordinates.FromLatLng(Overlay.north, Overlay.west)) < range)
            {
                dragCorner = DragCorners.NW;
                drag       = true;
            }
            if (cursor.Distance(Coordinates.FromLatLng(Overlay.north, (Overlay.west + Overlay.east) / 2)) < range)
            {
                dragCorner = DragCorners.N;
                drag       = true;
            }
            if (cursor.Distance(Coordinates.FromLatLng(Overlay.north, Overlay.east)) < range)
            {
                dragCorner = DragCorners.NE;
                drag       = true;
            }

            if (cursor.Distance(Coordinates.FromLatLng((Overlay.north + Overlay.south) / 2, Overlay.west)) < range)
            {
                dragCorner = DragCorners.W;
                drag       = true;
            }

            if (cursor.Distance(Coordinates.FromLatLng((Overlay.north + Overlay.south) / 2, (Overlay.west + Overlay.east) / 2)) < range)
            {
                dragCorner = DragCorners.C;
                drag       = true;
            }

            if (cursor.Distance(Coordinates.FromLatLng((Overlay.north + Overlay.south) / 2, Overlay.east)) < range)
            {
                dragCorner = DragCorners.E;
                drag       = true;
            }

            if (cursor.Distance(Coordinates.FromLatLng(Overlay.south, Overlay.west)) < range)
            {
                dragCorner = DragCorners.SW;
                drag       = true;
            }

            if (cursor.Distance(Coordinates.FromLatLng(Overlay.south, (Overlay.west + Overlay.east) / 2)) < range)
            {
                dragCorner = DragCorners.S;
                drag       = true;
            }

            if (cursor.Distance(Coordinates.FromLatLng(Overlay.south, Overlay.east)) < range)
            {
                dragCorner = DragCorners.SE;
                drag       = true;
            }

            if (drag)
            {
                mouseDown = cursor;
            }
            return(drag);
        }
Exemple #4
0
        private void GoToRADec_Click(object sender, EventArgs e)
        {
            int index = coordinateType.SelectedIndex;


            double ra       = 0;
            double dec      = 0;
            bool   raValid  = false;
            bool   decValid = false;

            switch (index)
            {
            case 0:     // Equitorial
            {
                ra       = Coordinates.ParseRA(raText.Text, false);
                dec      = Coordinates.ParseDec(decText.Text);
                raValid  = Coordinates.ValidateRA(raText.Text);
                decValid = Coordinates.ValidateDec(decText.Text);
            }
            break;

            case 2:     // Galactic
            {
                double l = Coordinates.Parse(raText.Text);
                double b = Coordinates.ParseDec(decText.Text);
                raValid  = Coordinates.Validate(raText.Text);
                decValid = Coordinates.ValidateDec(decText.Text);
                if (raValid && decValid)
                {
                    double[] result = Earth3d.GalactictoJ2000(l, b);
                    ra  = result[0] / 15;
                    dec = result[1];
                }
            }
            break;

            case 3:     // Ecliptic
            {
                double l = Coordinates.Parse(raText.Text);
                double b = Coordinates.ParseDec(decText.Text);
                raValid  = Coordinates.Validate(raText.Text);
                decValid = Coordinates.ValidateDec(decText.Text);
                if (raValid && decValid)
                {
                    AstroCalc.AstroRaDec radec = AstroCalc.AstroCalc.EclipticToJ2000(l, b, SpaceTimeController.JNow);
                    ra  = radec.RA;
                    dec = radec.Dec;
                }
            }
            break;

            case 4:     // Geo
            {
                ra       = -Coordinates.Parse(raText.Text) / 15;
                dec      = Coordinates.ParseDec(decText.Text);
                raValid  = Coordinates.Validate(raText.Text);
                decValid = Coordinates.ValidateDec(decText.Text);
            }
            break;

            case 1:     // alt/az
            {
                double az  = Coordinates.Parse(raText.Text);
                double alt = Coordinates.ParseDec(decText.Text);
                raValid  = Coordinates.Validate(raText.Text);
                decValid = Coordinates.ValidateDec(decText.Text);
                Coordinates radec = Coordinates.HorizonToEquitorial(Coordinates.FromLatLng(alt, az), SpaceTimeController.Location, SpaceTimeController.Now);
                ra  = radec.RA;
                dec = radec.Dec;
            }
            break;
            }
            if (raValid && decValid)
            {
                if (Earth3d.MainWindow.SolarSystemMode)
                {
                    Vector3d pnt = Coordinates.GeoTo3dDouble(dec, Coordinates.Parse(raText.Text));


                    pnt = Vector3d.TransformCoordinate(pnt, Planets.EarthMatrix);
                    pnt.Normalize();
                    Vector2d radec = Coordinates.CartesianToLatLng(pnt);

                    Earth3d.MainWindow.TargetLat  = radec.Y;
                    Earth3d.MainWindow.TargetLong = radec.X - 90;
                }
                else
                {
                    Earth3d.MainWindow.GotoTargetRADec(ra, dec, true, false);
                }
            }
        }