static RadialViewModel() { var axisRanges = new RangeCollection(); axisRanges.Add(new Range(0.1, 10)); DesignTimeData = new RadialViewModel { AxisSeriesViewModel = new FourAxisSeriesViewModel { BottomAxis = { Visibility = Visibility.Visible, Label = "Range (m)", }, LeftAxis = { Visibility = Visibility.Visible, Label = "Depth (m)", IsInverted = true, }, TopAxis = { Visibility = Visibility.Collapsed }, RightAxis = { Visibility = Visibility.Collapsed }, XAxisTicks = null, YAxisTicks = null, }, ColorMapViewModel = ColorMapViewModel.DesignTimeData, FullRange = new Range(0, 200), StatisticalRange = new Range(75, 125), AnimationTargetRange = new Range(50, 100), AnimationTime = TimeSpan.FromMilliseconds(200), }; DesignTimeData.AxisSeriesViewModel.BottomAxis.DataRange = axisRanges; DesignTimeData.AxisSeriesViewModel.LeftAxis.DataRange = axisRanges; }
public TransmissionLossViewModel() { TitleString = "<no radial selected>"; Observable.FromEventPattern<PropertyChangedEventArgs>(this, "PropertyChanged") .Where(e => e.EventArgs.PropertyName == "SelectedRadialIndex") .Select(e => SelectedRadialIndex) .DistinctUntilChanged() .Where(selectedRadialIndex => selectedRadialIndex >= 0) .Throttle(TimeSpan.FromMilliseconds(200)) .ObserveOnDispatcher() .Subscribe(selectedRadialIndex => { Debug.WriteLine(string.Format("{0:HH:mm:ss.fff} TransmissionLossViewModel: SelectedRadialIndex is now {1}", DateTime.Now, selectedRadialIndex)); //CurrentRadialView = RadialViews[value]; // var foo = SelectedMode.TransmissionLossPluginType. some regex here. var tlstring = ""; if (SelectedMode.TransmissionLossPluginType.ToLowerInvariant().Contains("bellhop")) tlstring = "Bellhop"; if (SelectedMode.TransmissionLossPluginType.ToLowerInvariant().Contains("ramgeo")) tlstring = "RAMGeo"; var nameString = Radials == null ? "<no radial selected>" : string.Format("Radial bearing: {0:000.0} degrees. Calculator: {1}", Radials[selectedRadialIndex].Bearing, tlstring); TitleString = nameString; if (RadialViewModel != null) { RadialViewModel.FullRange.Update(MinTransmissionLoss, MaxTransmissionLoss); RadialViewModel.Radial = Radials == null ? null : Radials[selectedRadialIndex]; RadialViewModel.AxisSeriesViewModel.PlotTitle = nameString; } }); Observable.FromEventPattern<PropertyChangedEventArgs>(this, "PropertyChanged") .Where(e => e.EventArgs.PropertyName == "SelectedRadialIndex") .Select(e => SelectedRadialIndex) .DistinctUntilChanged() .Where(selectedRadialIndex => selectedRadialIndex >= 0) .ObserveOnDispatcher() .Subscribe(selectedRadialIndex => { if (Radials == null || Radials.Count < selectedRadialIndex) SelectedBearingGeometry = null; else { var geometryString = new StringBuilder(); SelectedRadialBearing = Radials[selectedRadialIndex].Bearing; const double radius = 8; double x, y; for (double angle = 0; angle <= 2 * Math.PI; angle += Math.PI / 32.0) { geometryString.Append(geometryString.Length == 0 ? "M" : "L"); x = (Math.Sin(angle) * radius) + radius; y = (Math.Cos(angle) * radius) + radius; geometryString.Append(string.Format(CultureInfo.InvariantCulture, " {0:0.###},{1:0.###} ", x, y)); } geometryString.Append(string.Format("M {0:0.###}, {0:0.###} ", radius)); x = (Math.Sin(SelectedRadialBearing * (Math.PI / 180)) * radius) + radius; y = (-Math.Cos(SelectedRadialBearing * (Math.PI / 180)) * radius) + radius; geometryString.Append(string.Format(CultureInfo.InvariantCulture, "L {0:0.###},{1:0.###} ", x, y)); SelectedBearingGeometry = geometryString.ToString(); } }); Observable.FromEventPattern<PropertyChangedEventArgs>(this, "PropertyChanged") .ObserveOnDispatcher() .Where(e => e.EventArgs.PropertyName == "Window") .Subscribe(e => { if (RadialViewModel == null) RadialViewModel = new RadialViewModel { RadialView = Window.FindChildren<RadialView>().First() }; }); Observable.FromEventPattern<PropertyChangedEventArgs>(this, "PropertyChanged") .ObserveOnDispatcher() .Where(e => e.EventArgs.PropertyName == "SelectedMode") .Subscribe(e => { if (RadialViewModel != null) RadialViewModel.SelectedMode = SelectedMode; }); Observable.FromEventPattern<PropertyChangedEventArgs>(this, "PropertyChanged") .ObserveOnDispatcher() .Where(e => e.EventArgs.PropertyName == "RadialViewModel") .Subscribe(e1 => { RadialViewModel.SelectedMode = SelectedMode; RadialViewModel.PropertyChanged += (s, e) => { if (e.PropertyName == "WriteableBitmap" && Window != null) Window.Dispatcher.InvokeIfRequired(() => Window.Activate()); }; }); Observable.FromEventPattern<PropertyChangedEventArgs>(this, "PropertyChanged") .Where(e => e.EventArgs.PropertyName == "TransmissionLoss") .Select(e => TransmissionLoss) .DistinctUntilChanged() .ObserveOnDispatcher() .Subscribe(transmissionLoss => { if (_transmissionLossObserver != null) _transmissionLossObserver.Dispose(); _transmissionLossObserver = null; Radials = TransmissionLoss == null ? null : TransmissionLoss.Radials.OrderBy(r => r.Bearing).ToList(); if (Radials == null) RadialCount = 0; if (transmissionLoss == null || Radials == null || Radials.Count == 0) return; Debug.WriteLine(string.Format("{0:HH:mm:ss.fff} TransmissionLossViewModel: TransmissionLoss changed to {1}", DateTime.Now, transmissionLoss.ToString())); RadialCount = Radials.Count - 1; SelectedRadialIndex = -1; try { MinTransmissionLoss = (from radial in Radials from minimumValue in radial.MinimumTransmissionLossValues where !double.IsNaN(minimumValue) && !double.IsInfinity(minimumValue) select minimumValue).Min(); MaxTransmissionLoss = (from radial in Radials from maximumValue in radial.MaximumTransmissionLossValues where !double.IsNaN(maximumValue) && !double.IsInfinity(maximumValue) select maximumValue).Max(); } catch (FileNotFoundException ex) { Debug.WriteLine(string.Format("File not found exception loading radial: {0}", ex.FileName)); } catch (IOException ex) { Debug.WriteLine(string.Format("I/O exception loading radial: {0}", ex.Message)); } catch (InvalidOperationException ex) { Debug.WriteLine(string.Format("Invalid operation exception loading radial: {0}", ex.Message)); } SelectedMode = transmissionLoss.Modes.OrderBy(m => m.MaxPropagationRadius).Last(); MinRadialBearing = Radials.Min(r => r.Bearing); MaxRadialBearing = Radials.Max(r => r.Bearing); RadialBearingChange = (MaxRadialBearing - MinRadialBearing) / RadialCount; SelectedRadialBearing = MinRadialBearing; Debug.WriteLine("{0:HH:mm:ss.fff} TransmissionLossViewModel: SelectedRadialIndex set to -1", DateTime.Now); _transmissionLossObserver = Observable.FromEventPattern<PropertyChangedEventArgs>(transmissionLoss, "PropertyChanged") .ObserveOnDispatcher() .Select(e => TransmissionLoss) .DistinctUntilChanged() .Subscribe(tl => { if (tl.IsDeleted && Window != null) CloseDialog(null); }); SelectedRadialIndex = 0; }); }