private void raText_Validating(object sender, CancelEventArgs e) { bool valid = false; switch (coordinateType.SelectedIndex) { case 0: valid = Coordinates.ValidateRA(raText.Text); break; case 1: valid = Coordinates.Validate(raText.Text); break; case 4: case 3: case 2: valid = Coordinates.Validate(raText.Text); break; } if (valid) { raText.BackColor = searchText.BackColor; } else { raText.BackColor = Color.Red; } }
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); } } }