public ScenarioPropertiesViewModel(Scenario scenario)
 {
     Scenario = scenario;
     ScenarioName = Scenario.Name;
     DurationString = ((TimeSpan)Scenario.Duration).ToString(TimeSpanFormatString);
     Comments = Scenario.Comments;
     ComputeSizes();
     AddValidationRules(
         new ValidationRule<ScenarioPropertiesViewModel>
         {
             PropertyName = "ScenarioName",
             Description = "Must be unique within the selected location and cannot be null or empty",
             IsRuleValid = (target, rule) => !string.IsNullOrEmpty(target.ScenarioName),
         },
         new ValidationRule<ScenarioPropertiesViewModel>
         {
             PropertyName = "PulseIntervalString",
             Description = "Must be a valid, non-negative time span value in the format hh:mm where 00 <= hh <= 23; 00 <= mm <= 59",
             IsRuleValid = (target, rule) =>
             {
                 if (string.IsNullOrEmpty(target.DurationString)) return false;
                 TimeSpan timeSpan;
                 var isOK = TimeSpan.TryParseExact(target.DurationString, TimeSpanFormatString, null, out timeSpan);
                 return isOK && timeSpan.Ticks > 0;
             },
         });
 }
コード例 #2
0
 public EnvironmentNode(Scenario scenario)
 {
     EnvironmentLayers.Add(new BitmapNode("Wind Speed", scenario.Wind));
     EnvironmentLayers.Add(scenario.SoundSpeed);
     EnvironmentLayers.Add(new BitmapNode("Bathymetry", scenario.Bathymetry));
     EnvironmentLayers.Add(new BitmapNode("Sediment", scenario.Sediment));
     scenario.PropertyChanged += (s, e) =>
     {
         var sender = (Scenario)s;
         switch (e.PropertyName)
         {
             case "Wind":
                 EnvironmentLayers[0] = new BitmapNode("Wind", sender.Wind);
                 break;
             case "SoundSpeed":
                 EnvironmentLayers[1] = sender.SoundSpeed;
                 break;
             case "Bathymetry":
                 EnvironmentLayers[2] = new BitmapNode("Bathymetry", sender.Bathymetry);
                 break;
             case "Sediment":
                 EnvironmentLayers[3] = new BitmapNode("Sediment", scenario.Sediment);
                 break;
         }
     };
 }
コード例 #3
0
 public ScenarioNode(Scenario scenario) 
 {
     Scenario = scenario;
     Children.Add(scenario);
     Children.Add(new AnalysisPointsNode(scenario));
     Children.Add(new PerimetersNode(scenario));
     Children.Add(new SpeciesNode(scenario));
     Children.Add(new EnvironmentNode(scenario));
 }
コード例 #4
0
 public static Simulation Create(Scenario scenario, string simulationDirectory)
 {
     Directory.CreateDirectory(simulationDirectory);
     var result = new Simulation(scenario, simulationDirectory)
     {
         MovingAnimats = false,
         AnimateSimulation = true,
         TimeStepSize = (from p in scenario.Platforms
                         from s in p.Sources
                         from m in s.Modes
                         select (TimeSpan)m.PulseInterval).Max()
     };
     return result;
 }
コード例 #5
0
 Simulation(Scenario scenario, string simulationDirectory)
 {
     _simulationDirectory = simulationDirectory;
     //_database = SimulationContext.OpenOrCreate(Path.Combine(_simulationDirectory, "simulation.db"));
     //_scenario = _database.ImportScenario(scenario);
     Scenario = scenario;
     _transmissionLossCache = new TransmissionLossCache("RadialCache", new NameValueCollection
     {
         { "physicalMemoryLimitPercentage", "50" }, 
         { "pollingInterval", "00:05:00" }
     });
     foreach (var species in scenario.ScenarioSpecies)
         GuidToColorMap.Add(species.Guid, species.LayerSettings.LineOrSymbolColor);
 }
コード例 #6
0
 public AnalysisPointsNode(Scenario scenario)
 {
     _propertyObserver = new PropertyObserver<AnalysisPointsNode>(this)
         .RegisterHandler(p => p.Scenario,
                          () =>
                          {
                              if (_collectionObserver != null) _collectionObserver.UnregisterHandler(AnalysisPointCollectionChanged);
                              else _collectionObserver = new CollectionObserver(Scenario.AnalysisPoints);
                              _collectionObserver.RegisterHandler(AnalysisPointCollectionChanged);
                          }
         );
     Scenario = scenario;
     CheckForErrors();
 }
コード例 #7
0
 internal void Log(Scenario scenario, string message) { LogBase(new LogEntry(scenario), message); }
コード例 #8
0
 public SpeciesNode(Scenario scenario) { Scenario = scenario; }
コード例 #9
0
        void AddPerimeter(Scenario scenario)
        {
            try
            {
                var locationGeoRect = (GeoRect)Scenario.Location.GeoRect;
                var initialGeoRect = new GeoRect((locationGeoRect.North + locationGeoRect.Center.Latitude) / 2,
                                                 (locationGeoRect.South + locationGeoRect.Center.Latitude) / 2,
                                                 (locationGeoRect.East + locationGeoRect.Center.Longitude) / 2,
                                                 (locationGeoRect.West + locationGeoRect.Center.Longitude) / 2);
                MapViewModel.EditablePolygonOverlayViewModel.GeoArray = new GeoArray(initialGeoRect.NorthWest, initialGeoRect.NorthEast, initialGeoRect.SouthEast, initialGeoRect.SouthWest, initialGeoRect.NorthWest);
                MapViewModel.EditablePolygonOverlayViewModel.IsVisible = true;
                MapViewModel.EditablePolygonOverlayViewModel.LocationBounds = locationGeoRect;
                MapViewModel.EditablePolygonOverlayViewModel.AreCrossingSegmentsAllowed = false;

                Globals.VisualizerService.ShowWindow("CreateOrEditPerimeterView",
                                       new CreateOrEditPerimeterViewModel { EditablePolygonOverlayViewModel = MapViewModel.EditablePolygonOverlayViewModel, PerimeterName = "New perimeter", DialogTitle = "Create perimeter" },
                                       true,
                                       (sender, args) =>
                                       {
                                           MapViewModel.EditablePolygonOverlayViewModel.IsVisible = false;
                                           var vm = (CreateOrEditPerimeterViewModel)args.State;
                                           if (vm.IsCanceled) return;
                                           Perimeter perimeter = MapViewModel.EditablePolygonOverlayViewModel.GeoArray;
                                           perimeter.Name = vm.PerimeterName;
                                           perimeter.Scenario = Scenario;
                                           Scenario.Perimeters.Add(perimeter);
                                           perimeter.UpdateMapLayers();
                                           perimeter.LayerSettings.IsChecked = true;
                                       });
                OnPropertyChanged("IsSaveScenarioCommandEnabled");
            }
            catch (Exception e) { Globals.MessageBoxService.ShowError(e.Message); }
        }
コード例 #10
0
 async void RepopulateAllSpecies(Scenario scenario)
 {
     foreach (var species in scenario.ScenarioSpecies)
         await RepopulateSpeciesAsync(species);
 }
コード例 #11
0
 Scenario CreateScenario(Location location, string scenarioName, string comments, TimePeriod timePeriod, TimeSpan duration, EnvironmentalDataSet wind, EnvironmentalDataSet soundSpeed, EnvironmentalDataSet bathymetry, EnvironmentalDataSet sediment)
 {
     var scenario = new Scenario
     {
         Wind = Globals.MasterDatabaseService.LoadOrCreateEnvironmentalDataSet(location, wind.Resolution, timePeriod, wind.SourcePlugin),
         SoundSpeed = Globals.MasterDatabaseService.LoadOrCreateEnvironmentalDataSet(location, soundSpeed.Resolution, timePeriod, soundSpeed.SourcePlugin),
         Bathymetry = Globals.MasterDatabaseService.LoadOrCreateEnvironmentalDataSet(location, bathymetry.Resolution, TimePeriod.Invalid, bathymetry.SourcePlugin),
         Sediment = Globals.MasterDatabaseService.LoadOrCreateEnvironmentalDataSet(location, sediment.Resolution, TimePeriod.Invalid, sediment.SourcePlugin),
         Name = scenarioName,
         Location = location,
         Comments = comments,
         TimePeriod = timePeriod,
         Duration = duration,
         ShowAllPerimeters = true,
         ShowAllAnalysisPoints = true,
         ShowAllSpecies = false,
     };
     scenario.SoundSpeed.LayerSettings.LineOrSymbolSize = 5;
     var existing = (from s in location.Scenarios
                     where s.Name == scenario.Name && s.Location == scenario.Location
                     select s).FirstOrDefault();
     if (existing != null) throw new DuplicateNameException(String.Format("a Scenario named \"{0}\" already exists in the Location \"{1}\"; please select another name.", scenario.Name, scenario.Location.Name));
     location.Scenarios.Add(scenario);
     Globals.MasterDatabaseService.Context.Scenarios.Add(scenario);
     return scenario;
 }
コード例 #12
0
        public void CreateScenario(string locationName, string scenarioName, double north, double south, double east, double west)
        {
            Console.WriteLine("Creating database service...");
            var database = new MasterDatabaseService { MasterDatabaseDirectory = _databaseDirectory };
            Console.WriteLine("Loading plugins...");
            var plugins = new PluginManagerService { PluginDirectory = PluginDirectory };
            var cache = new EnvironmentalCacheService(plugins, database);
            Console.WriteLine(string.Format("Looking for test location '{0}'...", locationName));
            var location = database.FindLocation(locationName);
            if (location != null)
            {
                Console.WriteLine(string.Format("Test location '{0}' already exists.  Deleting the existing location.", locationName));
                database.DeleteLocation(location);
            }
            Console.WriteLine(string.Format("Creating test location '{0}'...", locationName));
            var geoRect = new GeoRect(north, south, east, west);
            location = new Location
            {
                Name = locationName,
                Comments = null,
                GeoRect = geoRect
            };
            location.LayerSettings.IsChecked = true;
            database.Add(location);

            foreach (var month in NAVOConfiguration.AllMonths)
            {
                // SoundSpeed dataset for each month
                Console.WriteLine(string.Format("Importing soundspeed for {0}", month));
                cache.ImportDatasetTest(database.LoadOrCreateEnvironmentalDataSet(location, 15, month, plugins[PluginType.EnvironmentalDataSource, PluginSubtype.SoundSpeed].PluginIdentifier));

                // Wind dataset for each month
                Console.WriteLine(string.Format("Importing wind for {0}", month));
                cache.ImportDatasetTest(database.LoadOrCreateEnvironmentalDataSet(location, 60, month, plugins[PluginType.EnvironmentalDataSource, PluginSubtype.Wind].PluginIdentifier));
            }
            
            // Sediment dataset
            Console.WriteLine("Importing 5min sediment");
            cache.ImportDatasetTest(database.LoadOrCreateEnvironmentalDataSet(location, 5f, TimePeriod.Invalid, plugins[PluginType.EnvironmentalDataSource, PluginSubtype.Sediment].PluginIdentifier));
            Console.WriteLine("Importing 0.1min sediment");
            cache.ImportDatasetTest(database.LoadOrCreateEnvironmentalDataSet(location, 0.1f, TimePeriod.Invalid, plugins[PluginType.EnvironmentalDataSource, PluginSubtype.Sediment].PluginIdentifier));

            // Bathymetry dataset at 2min resolution
            Console.WriteLine("Importing 2min bathymetry");
            cache.ImportDatasetTest(database.LoadOrCreateEnvironmentalDataSet(location, 2f, TimePeriod.Invalid, plugins[PluginType.EnvironmentalDataSource, PluginSubtype.Bathymetry].PluginIdentifier));
            // Bathymetry dataset at 1min resolution
            Console.WriteLine("Importing 1min bathymetry");
            cache.ImportDatasetTest(database.LoadOrCreateEnvironmentalDataSet(location, 1f, TimePeriod.Invalid, plugins[PluginType.EnvironmentalDataSource, PluginSubtype.Bathymetry].PluginIdentifier));
            // Bathymetry dataset at 0.5min resolution
            Console.WriteLine("Importing 0.5min bathymetry");
            cache.ImportDatasetTest(database.LoadOrCreateEnvironmentalDataSet(location, 0.5f, TimePeriod.Invalid, plugins[PluginType.EnvironmentalDataSource, PluginSubtype.Bathymetry].PluginIdentifier));
            Scenario scenario;
            database.Add(scenario = new Scenario
            {
                Location = location,
                Name = scenarioName,
                Comments = string.Format("Some comments for {0}", scenarioName),
                StartTime = new DbTimeSpan(new TimeSpan(0, 12, 0, 0)),
                Duration = new DbTimeSpan(new TimeSpan(0, 1, 0, 0)),
                TimePeriod = TimePeriod.April,
            });
            location.Scenarios.Add(scenario);
            Platform platform;
            database.Add(platform = new Platform
            {
                Description = "Platform description",
                PlatformName = "PlatformName",
                PlatformType = "PlatformType",
                RepeatCount = 0,
                Scenario = scenario,
                Course = 45,
                Depth = 0,
                Geo = geoRect.Center,
                Speed = 0,
                IsRandom = false,
                TrackType = TrackType.Stationary,
                Perimeter = null,
            });
            Source source;
            database.Add(source = new Source
            {
                Platform = platform,
                SourceName = "SourceName",
                SourceType = "SourceType",
            });
            database.Add(new Mode
            {
                ActiveTime = 500,
                DepressionElevationAngle = 0,
                Depth = 5,
                HighFrequency = 3000,
                HorizontalBeamWidth = 360,
                LowFrequency = 3000,
                MaxPropagationRadius = 25000,
                ModeName = "ModeName",
                ModeType = "ModeType",
                //PSMModeGuid = 
                PulseInterval = new TimeSpan(0, 0, 0, 30),
                PulseLength = new TimeSpan(0, 0, 0, 0, 500),
                RelativeBeamAngle = 0,
                Source = source,
                SourceLevel = 200,
                VerticalBeamWidth = 180,
            });
            database.SetEnvironmentalData(scenario,
                                          (from data in location.EnvironmentalDataSets
                                           where data.SourcePlugin.PluginSubtype == PluginSubtype.Wind && ((TimePeriod)scenario.TimePeriod == (TimePeriod)data.TimePeriod)
                                           select data).FirstOrDefault());

            database.SetEnvironmentalData(scenario,
                                          (from data in location.EnvironmentalDataSets
                                           where data.SourcePlugin.PluginSubtype == PluginSubtype.SoundSpeed && ((TimePeriod)scenario.TimePeriod == (TimePeriod)data.TimePeriod)
                                           select data).FirstOrDefault());

            database.SetEnvironmentalData(scenario,
                                          (from data in location.EnvironmentalDataSets
                                           where data.SourcePlugin.PluginSubtype == PluginSubtype.Sediment
                                           orderby data.Resolution
                                           select data).FirstOrDefault());

            database.SetEnvironmentalData(scenario,
                                          (from data in location.EnvironmentalDataSets
                                           where data.SourcePlugin.PluginSubtype == PluginSubtype.Bathymetry
                                           orderby data.Resolution
                                           select data).FirstOrDefault());
            database.SaveChanges();
        }
コード例 #13
0
 public Scenario(Scenario scenario) : this()
 {
     Copy(scenario);
 }
コード例 #14
0
 void AddPlatform(Scenario scenario)
 {
     if (scenario.LayerControl != null) ((LayerControl)scenario.LayerControl).Expand();
     var platform = new Platform
     {
         Scenario = scenario,
         Course = 0,
         Depth = 0,
         Description = null,
         Geo = ((GeoRect)scenario.Location.GeoRect).Center,
         PlatformName = "New Platform",
         IsRandom = false,
         Launches = false,
         TrackType = TrackType.Stationary,
         IsNew = true,
     };
     scenario.Platforms.Add(platform);
     platform.UpdateMapLayers();
     OnPropertyChanged("CanPlaceAnalysisPoint");
     OnPropertyChanged("IsSaveScenarioCommandEnabled");
 }
コード例 #15
0
 void SaveScenarioCopy(Scenario scenario)
 {
     var copy = new Scenario(scenario) { Name = "Copy of " + scenario.Name };
     var copyNumber = 2;
     while ((from s in scenario.Location.Scenarios
             where s.Name == copy.Name
             select s).FirstOrDefault() != null) copy.Name = "Copy " + copyNumber++ + " of " + scenario.Name;
     scenario.Location.Scenarios.Add(copy);
     Globals.MasterDatabaseService.Context.Scenarios.Add(copy);
 }
コード例 #16
0
 void ViewScenarioProperties(Scenario scenario)
 {
     Globals.VisualizerService.ShowDialog("ScenarioPropertiesView", new ScenarioPropertiesViewModel(scenario));
 }
コード例 #17
0
 void DeleteScenario(Scenario scenario)
 {
     if (IsSimulationRunning || IsTransmissionLossBusy)
     {
         Globals.MessageBoxService.ShowInformation("A scenario cannot be deleted while a simulation is running or transmission losses are being calculated.  Please wait until these tasks finish.");
     }
     else
     {
         if (Globals.MessageBoxService.ShowYesNo(string.Format("Are you sure you want to delete the scenario \"{0}\"?", scenario.Name), MessageBoxImage.Warning) != MessageBoxResult.Yes) return;
         scenario.Delete();
     }
 }
コード例 #18
0
 void LoadScenario(Scenario scenario) { Scenario = scenario; }
コード例 #19
0
 public PerimetersNode(Scenario scenario) { Scenario = scenario; }
コード例 #20
0
 static void AddPlatform(Scenario scenario, Platform platform)
 {
     scenario.Platforms.Add(platform);
     platform.UpdateMapLayers();
 }
コード例 #21
0
 void DeleteAllSpecies(Scenario scenario)
 {
     if (Globals.MessageBoxService.ShowYesNo("Are you sure you want to delete ALL the species from this scenario?", MessageBoxImage.Warning) != MessageBoxResult.Yes) return;
     foreach (var species in scenario.ScenarioSpecies.ToList())
     {
         species.Delete();
         OnPropertyChanged("IsRunSimulationCommandEnabled");
     }
     OnPropertyChanged("IsSaveScenarioCommandEnabled");
 }
コード例 #22
0
 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);
     }
 }
コード例 #23
0
        async void AddSpecies(Scenario scenario)
        {
            var vm = new SpeciesPropertiesViewModel(new ScenarioSpecies
            {
                LatinName = "Generic odontocete", 
                PopulationDensity = 0.01f, 
                SpeciesDefinitionFilename = "Generic odontocete.spe"
            })
            {
                WindowTitle = "Add new species"
            };
            var result = Globals.VisualizerService.ShowDialog("SpeciesPropertiesView", vm);
            if ((!result.HasValue) || (!result.Value)) return;
            var species = new ScenarioSpecies
            {
                Scenario = scenario,
                LatinName = vm.LatinName,
                PopulationDensity = vm.PopulationDensity,
                SpeciesDefinitionFilename = vm.SpeciesDefinitionFilename,
            };

            try
            {
                scenario.ScenarioSpecies.Add(species);
                species.LayerSettings.LineOrSymbolSize = 3;
                var animats = await Animat.SeedAsync(species, scenario.Location.GeoRect, scenario.BathymetryData);
                animats.Save(species.PopulationFilePath);
                species.UpdateMapLayers();
            }
            catch (Exception e)
            {
                scenario.ScenarioSpecies.Remove(species);
                Globals.MessageBoxService.ShowError(e.Message);
            }
            OnPropertyChanged("IsRunSimulationCommandEnabled");
            OnPropertyChanged("IsSaveScenarioCommandEnabled");
        }