public AnalysisPointViewModel(AnalysisPoint analysisPoint) { AnalysisPoint = analysisPoint; Observable.FromEventPattern<PropertyChangedEventArgs>(AnalysisPoint, "PropertyChanged") .Where(e => e.EventArgs.PropertyName == "IsDeleted") .Select(e => AnalysisPoint.IsDeleted) .DistinctUntilChanged() .ObserveOnDispatcher() .Subscribe(isDeleted => { if (isDeleted) CloseDialog(null); }); 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; if (transmissionLoss == null) return; TransmissionLossViewModel.TransmissionLoss = transmissionLoss; _oldIndex = AnalysisPoint.TransmissionLosses.IndexOf(transmissionLoss); _transmissionLossObserver = Observable.FromEventPattern<PropertyChangedEventArgs>(transmissionLoss, "PropertyChanged") .ObserveOnDispatcher() .Subscribe(e => { if (e.EventArgs.PropertyName == "IsDeleted" && AnalysisPoint.TransmissionLosses.Count > 1) TransmissionLossViewModel.TransmissionLoss = AnalysisPoint.TransmissionLosses[_oldIndex % (AnalysisPoint.TransmissionLosses.Count - 1)]; }); Debug.WriteLine(string.Format("{0:HH:mm:ss.fff} AnalysisPointViewModel: TransmissionLossViewModel.SelectedRadialIndex set to 0", DateTime.Now)); }); TransmissionLoss = analysisPoint.TransmissionLosses.FirstOrDefault(); }
void Copy(AnalysisPoint analysisPoint) { Geo = new Geo(analysisPoint.Geo); LayerSettings = new LayerSettings(analysisPoint.LayerSettings); }
public AnalysisPoint(AnalysisPoint analysisPoint): this() { Copy(analysisPoint); }
void Copy(Scenario scenario) { Name = scenario.Name; Comments = scenario.Comments; ShowAllAnalysisPoints = scenario.ShowAllAnalysisPoints; ShowAllPerimeters = scenario.ShowAllPerimeters; ShowAllSpecies = scenario.ShowAllSpecies; StartTime = new TimeSpan(scenario.StartTime.Ticks); Duration = new TimeSpan(scenario.Duration.Ticks); TimePeriod = (TimePeriod)scenario.TimePeriod; Location = scenario.Location; Wind = scenario.Wind; SoundSpeed = scenario.SoundSpeed; Sediment = scenario.Sediment; Bathymetry = scenario.Bathymetry; // Here we map the old perimeter to the new perimeter so that the copied platform gets the proper perimeter var perimeterMap = new Dictionary<Guid, Guid>(); foreach (var perimeter in scenario.Perimeters) { var newPerimeter = new Perimeter(perimeter) { Scenario = this }; perimeterMap.Add(perimeter.Guid, newPerimeter.Guid); Perimeters.Add(newPerimeter); } var modeMap = new Dictionary<Guid, Guid>(); var allModes = new List<Mode>(); foreach (var platform in scenario.Platforms) { var newPlatform = new Platform(platform) { Scenario = this }; // Make sure the new perimeter gets the proper copied perimeter from the original scenario if (platform.Perimeter != null) newPlatform.Perimeter = Perimeters.Find(p => p.Guid == perimeterMap[platform.Perimeter.Guid]); Platforms.Add(newPlatform); foreach (var source in platform.Sources) { var newSource = new Source(source) { Platform = newPlatform }; newPlatform.Sources.Add(newSource); foreach (var mode in source.Modes) { var newMode = new Mode(mode) { Source = newSource }; modeMap.Add(mode.Guid, newMode.Guid); newSource.Modes.Add(newMode); allModes.Add(newMode); } } } foreach (var analysisPoint in scenario.AnalysisPoints) { var newAnalysisPoint = new AnalysisPoint(analysisPoint) { Scenario = this }; AnalysisPoints.Add(newAnalysisPoint); foreach (var transmissionLoss in analysisPoint.TransmissionLosses) { var newTransmissionLoss = new TransmissionLoss { AnalysisPoint = newAnalysisPoint, LayerSettings = new LayerSettings(transmissionLoss.LayerSettings) }; foreach (var mode in transmissionLoss.Modes) newTransmissionLoss.Modes.Add(allModes.Find(m => m.Guid == modeMap[mode.Guid])); newAnalysisPoint.TransmissionLosses.Add(newTransmissionLoss); foreach (var radial in transmissionLoss.Radials) { var newRadial = new Radial(radial) { TransmissionLoss = newTransmissionLoss }; newTransmissionLoss.Radials.Add(newRadial); newRadial.CopyFiles(radial); } } } foreach (var species in scenario.ScenarioSpecies) { var newSpecies = new ScenarioSpecies(species) { Scenario = this }; ScenarioSpecies.Add(newSpecies); newSpecies.CopyFiles(species); } }
void ViewAnalysisPoint(AnalysisPoint analysisPoint) { try { var analysisPointViewModel = new AnalysisPointViewModel(analysisPoint); var window = Globals.VisualizerService.ShowWindow("AnalysisPointWindowView", analysisPointViewModel); _openPopups.Add(window); analysisPointViewModel.TransmissionLossViewModel.Window = window; analysisPointViewModel.TransmissionLossViewModel.SaveFileService = Globals.SaveFileService; } catch (InvalidOperationException ex) { Globals.MessageBoxService.ShowError(string.Format("Error displaying analysis point: {0}", ex.Message)); } }
void MapClick(Geo geo) { if (IsInAnalysisPointMode) { if (Scenario != null && geo != null && Scenario.GeoRect.Contains(geo)) { Task.Run(() => { var analysisPoint = new AnalysisPoint { Geo = new Geo(geo), Scenario = Scenario }; Scenario.AnalysisPoints.Add(analysisPoint); Scenario.UpdateAnalysisPoints(); analysisPoint.CheckForErrors(); var analysisPointsNode = (AnalysisPointsNode)LayerTreeViewModel.RootNodes.FirstOrDefault(n => n.GetType() == typeof(AnalysisPointsNode)); if (analysisPointsNode != null) analysisPointsNode.CheckForErrors(); }); } IsInAnalysisPointMode = false; Cursor = Cursors.Arrow; } if (_fakeAnalysisPoint != null) { _fakeAnalysisPoint.RemoveMapLayers(); _fakeAnalysisPoint = null; } }
void ViewAnalysisPointProperties(AnalysisPoint analysisPoint) { Globals.VisualizerService.ShowDialog("TreeViewItemPropertiesView", new AnalysisPointPropertiesViewModel { PropertyObject = analysisPoint }); }
void RecalculateAnalysisPoint(AnalysisPoint analysisPoint) { if (Globals.MessageBoxService.ShowYesNo(string.Format("Are you sure you want to recalculate this analysis point \"{0}\"?", analysisPoint.Geo), MessageBoxImage.Warning) != MessageBoxResult.Yes) return; analysisPoint.Recalculate(); }
void DeleteAnalysisPoint(AnalysisPoint analysisPoint) { if (Globals.MessageBoxService.ShowYesNo(string.Format("Are you sure you want to delete this analysis point \"{0}\"?", analysisPoint.Geo), MessageBoxImage.Warning) != MessageBoxResult.Yes) return; //analysisPoint.LayerSettings.IsChecked = false; //analysisPoint.RemoveMapLayers(); //await Task.Delay(50); analysisPoint.Delete(); OnPropertyChanged("IsRunSimulationCommandEnabled"); OnPropertyChanged("IsSaveScenarioCommandEnabled"); }