/// <summary> /// Get the selected object in TheSkyX /// </summary> /// <returns></returns> public async Task <DeepSkyObject> GetTarget() { try { string response = await Query("GET_TARGET"); response = response.TrimEnd('\r', '\n'); /* * Split the coordinates and object name from the returned message. * GET_TARGET returns 4 fields, space-separated: * RA Dec Name Position_angle * * RA and Dec are in radians. Epoch is J2000. */ string[] info = response.Split(' '); if (!(info[0].Equals("?") || string.IsNullOrEmpty(info[2]))) { Coordinates newCoordinates = new Coordinates(Astrometry.RadianToHour(double.Parse(info[0].Replace(',', '.'), System.Globalization.CultureInfo.InvariantCulture)), Astrometry.ToDegree(double.Parse(info[1].Replace(',', '.'), System.Globalization.CultureInfo.InvariantCulture)), Epoch.J2000, Coordinates.RAType.Hours); DeepSkyObject dso = new DeepSkyObject(info[2], newCoordinates, string.Empty); return(dso); } else { throw new PlanetariumObjectNotSelectedException(); } } catch (Exception ex) { Logger.Error(ex); throw ex; } }
public async Task <DeepSkyObject> GetTarget() { string route = "/api/objects/info?format=json"; var request = new HttpGetRequest(this.baseUrl + route); try { var response = await request.Request(new CancellationToken()); if (string.IsNullOrEmpty(response)) { return(await GetView()); } var jobj = JObject.Parse(response); var status = jobj.ToObject <StellariumObject>(); var ra = Astrometry.EuclidianModulus(status.RightAscension, 360); var dec = status.Declination; var coordinates = new Coordinates(Angle.ByDegree(ra), Angle.ByDegree(dec), Epoch.J2000); var dso = new DeepSkyObject(status.Name, coordinates, string.Empty); return(dso); } catch (Exception ex) { Logger.Error(ex); throw ex; } }
private void DeepSkyObjectSearchVM_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == nameof(DeepSkyObjectSearchVM.Coordinates) && DeepSkyObjectSearchVM.Coordinates != null) { DSO = new DeepSkyObject(DeepSkyObjectSearchVM.SelectedTargetSearchResult.Column1, DeepSkyObjectSearchVM.Coordinates, profileService.ActiveProfile.ApplicationSettings.SkyAtlasImageRepository); RaiseCoordinatesChanged(); } else if (e.PropertyName == nameof(DeepSkyObjectSearchVM.TargetName) && DSO != null) { DSO.Name = DeepSkyObjectSearchVM.TargetName; } }
/// <summary> /// Constructor for a Framing DSO. /// It takes a ViewportFoV and a DeepSkyObject and calculates XY values in pixels from the top left edge of the image subtracting half of its size. /// Those coordinates can be used to place the DSO including its name and size in any given image. /// </summary> /// <param name="dso">The DSO including its coordinates</param> /// <param name="viewport">The viewport of the offending DSO</param> public FramingDSO(DeepSkyObject dso, ViewportFoV viewport) { dsoType = dso.DSOType; arcSecWidth = viewport.ArcSecWidth; arcSecHeight = viewport.ArcSecHeight; if (dso.Size != null && dso.Size >= arcSecWidth) { sizeWidth = dso.Size.Value; } else { sizeWidth = DSO_DEFAULT_SIZE; } if (dso.Size != null && dso.Size >= arcSecHeight) { sizeHeight = dso.Size.Value; } else { sizeHeight = DSO_DEFAULT_SIZE; } Id = dso.Id; Name1 = dso.Name; Name2 = dso.AlsoKnownAs.FirstOrDefault(m => m.StartsWith("M ")); Name3 = dso.AlsoKnownAs.FirstOrDefault(m => m.StartsWith("NGC ")); if (Name3 != null && Name1 == Name3.Replace(" ", "")) { Name1 = null; } if (Name1 == null && Name2 == null) { Name1 = Name3; Name3 = null; } if (Name1 == null && Name2 != null) { Name1 = Name2; Name2 = Name3; Name3 = null; } coordinates = dso.Coordinates; RecalculateTopLeft(viewport); }
/// <summary> /// Get the selected object in CdC /// </summary> /// <returns></returns> public async Task <DeepSkyObject> GetTarget() { try { var response = await Query("GETSELECTEDOBJECT"); if (!response.StartsWith("OK!")) { throw new PlanetariumObjectNotSelectedException(); } var columns = response.Split('\t'); // An "OK!" response with fewer than 2 columns means that CdC is listening ok but the user has not selected an object. if (columns.Count() < 2) { throw new PlanetariumObjectNotSelectedException(); } if (!Match(columns[0].Replace("OK!", ""), @"(([0-9]{1,2})([h|:]|[?]{2})([0-9]{1,2})([m|:]|[?]{2})?([0-9]{1,2}(?:\.[0-9]+){0,1})?([s|:]|[?]{2}))", out var raString)) { throw new PlanetariumObjectNotSelectedException(); } var ra = Astrometry.HMSToDegrees(raString); if (!Match(columns[1], @"([\+|-]([0-9]{1,2})([d|°|:]|[?]{2})([0-9]{1,2})([m|'|:]|[?]{2})?([0-9]{1,2}(?:\.[0-9]+){0,1})?([s|""|:]|[?]{2}))", out var decString)) { throw new PlanetariumObjectNotSelectedException(); } var dec = Astrometry.DMSToDegrees(decString); if (!Match(columns.Last(), @"(?<=Equinox:).*", out var equinox)) { throw new PlanetariumObjectNotSelectedException(); } equinox = equinox.Replace("\r", "").Replace("\n", ""); var coordinates = new Coordinates(Angle.ByDegree(ra), Angle.ByDegree(dec), equinox.ToLower() == "now" ? Epoch.JNOW : Epoch.J2000); var dso = new DeepSkyObject(columns[3].Trim(), coordinates.Transform(Epoch.J2000), string.Empty); return(dso); } catch (Exception ex) { Logger.Error(ex); throw ex; } }
private async Task <DeepSkyObject> GetView() { string route = "/api/main/view"; var request = new HttpGetRequest(this.baseUrl + route); try { var response = await request.Request(new CancellationToken()); if (string.IsNullOrEmpty(response)) { throw new PlanetariumFailedToConnect(); } /* The api returns arrays in an invalid json array format so we need to remove the quotes first */ response = response.Replace("\"[", "[").Replace("]\"", "]"); var jobj = JObject.Parse(response); var status = jobj.ToObject <StellariumView>(); var x = Angle.ByRadians(status.J2000[0]); var y = Angle.ByRadians(status.J2000[1]); var z = Angle.ByRadians(status.J2000[2]); var dec = z.Asin(); var ra = Angle.Atan2(y, x); // A bug in Stellarium >= 0.20 will cause it to report negative y values which translates to a negative RA value. This is not desired. if (ra.Radians < 0d) { ra = (2 * Math.PI) + ra; } var coordinates = new Coordinates(ra, dec, Epoch.J2000); var dso = new DeepSkyObject(string.Empty, coordinates, string.Empty); return(dso); } catch (Exception ex) { Logger.Error(ex); throw ex; } }
public FramingAssistantVM(IProfileService profileService, ICameraMediator cameraMediator, ITelescopeMediator telescopeMediator, IApplicationStatusMediator applicationStatusMediator) : base(profileService) { this.cameraMediator = cameraMediator; this.cameraMediator.RegisterConsumer(this); this.telescopeMediator = telescopeMediator; this.applicationStatusMediator = applicationStatusMediator; Opacity = 0.2; SkyMapAnnotator = new SkyMapAnnotator(telescopeMediator); var defaultCoordinates = new Coordinates(0, 0, Epoch.J2000, Coordinates.RAType.Degrees); DSO = new DeepSkyObject(string.Empty, defaultCoordinates, profileService.ActiveProfile.ApplicationSettings.SkyAtlasImageRepository); FramingAssistantSource = profileService.ActiveProfile.FramingAssistantSettings.LastSelectedImageSource; CameraPixelSize = profileService.ActiveProfile.CameraSettings.PixelSize; FocalLength = profileService.ActiveProfile.TelescopeSettings.FocalLength; _statusUpdate = new Progress <ApplicationStatus>(p => Status = p); LoadImageCommand = new AsyncCommand <bool>(async() => { return(await LoadImage()); }); CancelLoadImageFromFileCommand = new RelayCommand((object o) => { CancelLoadImage(); }); _progress = new Progress <int>((p) => DownloadProgressValue = p); CancelLoadImageCommand = new RelayCommand((object o) => { CancelLoadImage(); }); DragStartCommand = new RelayCommand(DragStart); DragStopCommand = new RelayCommand(DragStop); DragMoveCommand = new RelayCommand(DragMove); ClearCacheCommand = new RelayCommand(ClearCache, (object o) => Cache != null); RefreshSkyMapAnnotationCommand = new RelayCommand((object o) => SkyMapAnnotator.UpdateSkyMap(), (object o) => SkyMapAnnotator.Initialized); MouseWheelCommand = new RelayCommand(MouseWheel); CoordsFromPlanetariumCommand = new AsyncCommand <bool>(() => Task.Run(CoordsFromPlanetarium)); DeepSkyObjectSearchVM = new DeepSkyObjectSearchVM(); DeepSkyObjectSearchVM.PropertyChanged += DeepSkyObjectSearchVM_PropertyChanged; SetSequenceCoordinatesCommand = new AsyncCommand <bool>(async(object parameter) => { var vm = (ApplicationVM)Application.Current.Resources["AppVM"]; vm.ChangeTab(ApplicationTab.SEQUENCE); var deepSkyObjects = new List <DeepSkyObject>(); foreach (var rect in CameraRectangles) { var name = rect.Id > 0 ? DSO?.Name + string.Format(" {0} ", Locale.Loc.Instance["LblPanel"]) + rect.Id : DSO?.Name; var dso = new DeepSkyObject(name, rect.Coordinates, profileService.ActiveProfile.ApplicationSettings.SkyAtlasImageRepository); dso.Rotation = Rectangle.DisplayedRotation; deepSkyObjects.Add(dso); } bool msgResult = false; if (parameter.ToString() == "Replace") { msgResult = await vm.SeqVM.SetSequenceCoordiantes(deepSkyObjects); } else if (parameter.ToString() == "Add") { msgResult = await vm.SeqVM.SetSequenceCoordiantes(deepSkyObjects, false); } ImageParameter = null; GC.Collect(); GC.WaitForPendingFinalizers(); return(msgResult); }, (object o) => Rectangle?.Coordinates != null); RecenterCommand = new AsyncCommand <bool>(async() => { DSO.Coordinates = Rectangle.Coordinates; await LoadImageCommand.ExecuteAsync(null); return(true); }, (object o) => Rectangle?.Coordinates != null); SlewToCoordinatesCommand = new AsyncCommand <bool>(async() => { return(await telescopeMediator.SlewToCoordinatesAsync(Rectangle.Coordinates)); }, (object o) => Rectangle?.Coordinates != null); var appSettings = profileService.ActiveProfile.ApplicationSettings; appSettings.PropertyChanged += ApplicationSettings_PropertyChanged; profileService.ProfileChanged += (object sender, EventArgs e) => { appSettings.PropertyChanged -= ApplicationSettings_PropertyChanged; this.FocalLength = profileService.ActiveProfile.TelescopeSettings.FocalLength; this.CameraPixelSize = profileService.ActiveProfile.CameraSettings.PixelSize; RaisePropertyChanged(nameof(CameraPixelSize)); RaisePropertyChanged(nameof(FocalLength)); RaisePropertyChanged(nameof(FieldOfView)); RaisePropertyChanged(nameof(CameraWidth)); RaisePropertyChanged(nameof(CameraHeight)); appSettings = profileService.ActiveProfile.ApplicationSettings; appSettings.PropertyChanged += ApplicationSettings_PropertyChanged; ApplicationSettings_PropertyChanged(null, null); }; resizeTimer = new DispatcherTimer(DispatcherPriority.ApplicationIdle, _dispatcher); resizeTimer.Interval = TimeSpan.FromMilliseconds(500); resizeTimer.Tick += ResizeTimer_Tick; ScrollViewerSizeChangedCommand = new RelayCommand((parameter) => { resizeTimer.Stop(); if (ImageParameter != null && FramingAssistantSource == SkySurveySource.SKYATLAS) { resizeTimer.Start(); } }); profileService.LocationChanged += (object sender, EventArgs e) => { DSO = new DeepSkyObject(DSO.Name, DSO.Coordinates, profileService.ActiveProfile.ApplicationSettings.SkyAtlasImageRepository); }; InitializeCache(); }
public async Task <List <DeepSkyObject> > GetDeepSkyObjects( string imageRepository, DeepSkyObjectSearchParams searchParams, CancellationToken token) { using (MyStopWatch.Measure()) { if (searchParams == null) { throw new ArgumentNullException(nameof(searchParams)); } var dsos = new List <DeepSkyObject>(); try { using (var context = new NINADbContext(connectionString)) { var query = from dso in context.DsoDetailSet select new { dso.id, dso.ra, dso.dec, dso.dsotype, dso.magnitude, dso.sizemin, dso.sizemax, dso.constellation, dso.surfacebrightness }; if (!string.IsNullOrEmpty(searchParams.Constellation)) { query = query.Where(x => x.constellation == searchParams.Constellation); } if (searchParams.RightAscension.From != null) { query = query.Where(x => x.ra >= searchParams.RightAscension.From); } if (searchParams.RightAscension.Thru != null) { query = query.Where(x => x.ra <= searchParams.RightAscension.Thru); } if (searchParams.Declination.From != null) { query = query.Where(x => x.dec >= searchParams.Declination.From); } if (searchParams.Declination.Thru != null) { query = query.Where(x => x.dec <= searchParams.Declination.Thru); } if (searchParams.Size.From.HasValue) { query = query.Where(x => x.sizemin >= searchParams.Size.From); } if (searchParams.Size.Thru.HasValue) { query = query.Where(x => x.sizemax <= searchParams.Size.Thru); } if (searchParams.Brightness.From.HasValue) { query = query.Where(x => x.surfacebrightness >= searchParams.Brightness.From); } if (searchParams.Brightness.Thru.HasValue) { query = query.Where(x => x.surfacebrightness <= searchParams.Brightness.Thru); } if (searchParams.Magnitude.From.HasValue) { query = query.Where(x => x.magnitude >= searchParams.Magnitude.From); } if (searchParams.Magnitude.Thru.HasValue) { query = query.Where(x => x.magnitude <= searchParams.Magnitude.Thru); } if (searchParams.DsoTypes?.Count > 0) { query = query.Where(x => searchParams.DsoTypes.Contains(x.dsotype)); } if (!string.IsNullOrEmpty(searchParams.ObjectName)) { var name = searchParams.ObjectName.ToLower(); var idQuery = context.CatalogueNrSet.Where(x => x.dsodetailid.ToLower().Contains(name) || (x.catalogue + x.designation).ToLower().Contains(name) || (x.catalogue + " " + x.designation).ToLower().Contains(name)).Select(x => x.dsodetailid).Distinct(); query = query.Join(idQuery, dsoDetail => dsoDetail.id, e => e, (dsoDetail, id) => dsoDetail); } if (searchParams.SearchOrder.Direction == "ASC") { query = query.OrderBy(searchParams.SearchOrder.Field); } else { query = query.OrderByDescending(searchParams.SearchOrder.Field); } if (searchParams.Limit != null) { query = query.Take(searchParams.Limit.Value); } var dsosTask = query.ToListAsync(token); var catalogueTask = (from q in query join cat in context.CatalogueNrSet on q.id equals cat.dsodetailid select new { cat.dsodetailid, designation = cat.catalogue == "NAME" ? cat.designation : cat.catalogue + " " + cat.designation }) .GroupBy(x => x.dsodetailid) .ToDictionaryAsync(x => x.Key, x => x.ToList(), token); await Task.WhenAll(dsosTask, catalogueTask); var dsoResult = dsosTask.Result; var catalogueResult = catalogueTask.Result; foreach (var row in dsoResult) { var id = row.id; var coords = new Coordinates(row.ra, row.dec, Epoch.J2000, Coordinates.RAType.Degrees); var dso = new DeepSkyObject(row.id, coords, imageRepository); dso.DSOType = row.dsotype; if (row.magnitude.HasValue) { dso.Magnitude = (double?)row.magnitude; } if (row.sizemax.HasValue) { dso.Size = (double?)row.sizemax; } dso.AlsoKnownAs = catalogueResult[row.id].Select(x => x.designation).ToList(); var longestName = dso.AlsoKnownAs.Aggregate("", (max, cur) => max.Length > cur.Length ? max : cur); dso.Name = longestName; if (!string.IsNullOrEmpty(row.constellation)) { dso.Constellation = row.constellation; } if (row.surfacebrightness.HasValue) { dso.SurfaceBrightness = (double?)row.surfacebrightness; } dsos.Add(dso); } } } catch (OperationCanceledException) { } catch (Exception ex) { if (!ex.Message.Contains("Execution was aborted by the user")) { Logger.Error(ex); Notification.ShowError(ex.Message); } } return(dsos); } }