Ejemplo n.º 1
0
 public Source(Source source)
 {
     
     SourceName = source.SourceName;
     SourceType = source.SourceType;
     if (source.Modes != null)
         foreach (var newmode in source.Modes.Select(mode => new Mode(mode)))
         {
             Modes.Add(newmode);
         }
 }
Ejemplo n.º 2
0
        public bool Equals(Source other)
        {
            if (Guid != other.Guid) return false;
            if (SourceName != other.SourceName) return false;
            if (SourceType != other.SourceType) return false;
            var modes = (from m in Modes orderby m.ModeName select m).ToList();
            var othermodes = (from m in other.Modes orderby m.ModeName select m).ToList();
            if (modes.Count != othermodes.Count) return false;
            if (modes.Where((t, i) => !t.Equals(othermodes[i])).Any()) return false;

            return true;
        }
 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);
     }
 }
        public void PlatformBehaviorToKML()
        {
            var jaxOpsArea = new GeoArray(new Geo(29.3590, -79.2195),
                                          new Geo(31.1627, -79.2195),
                                          new Geo(31.1627, -81.2789),
                                          new Geo(30.1627, -81.2789),
                                          new Geo(29.3590, -80.8789),
                                          new Geo(29.3590, -79.2195));

            var platform = new Platform
            {
                PlatformName = "Test Platform",
                Perimeter = jaxOpsArea,
                Depth = 0,
                IsRandom = true,
                TrackType = TrackType.PerimeterBounce,
                Sources = new ObservableList<Source>(),
                Speed = 20,
            };
            var source = new Source
            {
                SourceName = "Test Source",
                Modes = new ObservableList<Mode>(),
                Platform = platform,
            };
            platform.Sources.Add(source);
            var mode = new Mode
            {
                ModeName = "Test Mode",
                PulseInterval = new TimeSpan(0, 0, 0, 10),
                PulseLength = new TimeSpan(0, 0, 0, 0, 500),
                Depth = 5,
                HighFrequency = 1000,
                LowFrequency = 1000,
                DepressionElevationAngle = 10,
                VerticalBeamWidth = 90,
                SourceLevel = 200,
                Source = source,
            };
            source.Modes.Add(mode);

            var behavior = new PlatformBehavior(platform, new TimeSpan(0, 0, 0, 1), 86400);
#if true
            var kml = new KMLRoot();
            var folder = new Folder("Jacksonville");
            jaxOpsArea.Placemark.name = "Jacksonville OpArea";
            jaxOpsArea.Placemark.Snippet = "The operational area";
            jaxOpsArea.Placemark.Snippet.maxLines = 1;
            folder.Add(jaxOpsArea.Placemark);

#if true
            var timeStep = 0;
            foreach (var state in behavior.PlatformStates)
            {
                if (timeStep % 100 == 0)
                {
                    state.PlatformLocation.Location.Placemark.name = string.Format("TimeStep {0}", timeStep);
                    folder.Add(state.PlatformLocation.Location.Placemark);
                }
                timeStep++;
            }
#else
            result.Placemark.name = "Platform track";
            result.Placemark.Snippet = "The track of the platform";
            result.Placemark.Snippet.maxLines = 1;
            result.Placemark.Geometry.AltitudeMode = AltitudeMode.clampedToGround;
            folder.Add(result.Placemark);
#endif

            kml.Document.Add(folder);

            var savePath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "Platform Behavior Tests", "PlatformBehavior.kml");
            Debug.WriteLine("Saving KML...");
            kml.Save(savePath);
#endif
        }
 internal void Log(Source source, string message) { LogBase(new LogEntry(source), message); }
 void AddMode(Source source)
 {
     //var vm = new CreateModeViewModel();
     //var result = ESME.Globals.VisualizerService.ShowDialog("CreateModeView", vm);
     //if (!result.HasValue || !result.Value) return;
     ((LayerControl)source.LayerControl).Expand();
     AddMode(source, "New Mode", true);
     OnPropertyChanged("CanPlaceAnalysisPoint");
     OnPropertyChanged("IsSaveScenarioCommandEnabled");
 }
 void AddMode(Source source, string name, bool isNew, float frequency = 1000f, float depth = 0f, float maxPropagationRadius = 25000f)
 {
     var mode = new Mode
     {
         ActiveTime = 1f,
         Depth = depth,
         DepressionElevationAngle = 0f,
         HighFrequency = frequency,
         LowFrequency = frequency,
         MaxPropagationRadius = maxPropagationRadius,
         ModeName = name,
         ModeType = null,
         PulseInterval = new TimeSpan(0, 0, 0, 30),
         PulseLength = new TimeSpan(0, 0, 0, 0, 500),
         RelativeBeamAngle = 0,
         Source = source,
         SourceLevel = 200,
         VerticalBeamWidth = 180f,
         HorizontalBeamWidth = 90,
         IsNew = isNew,
         TransmissionLossPluginType = Globals.PluginManagerService[PluginType.TransmissionLossCalculator][PluginSubtype.Bellhop].DefaultPlugin.PluginIdentifier.Type,
     };
     source.Modes.Add(mode);
     //source.Platform.Scenario.Add(mode);
     source.Platform.Scenario.UpdateAnalysisPoints();
 }
 void SourceProperties(Source source)
 {
     //ESME.Globals.VisualizerService.ShowDialog("TreeViewItemPropertiesView", new SourcePropertiesViewModel { Source = source });
     var vm = new PropertiesViewModel { PropertyObject = source, WindowTitle = "Source Properties: " + source.SourceName };
     Globals.VisualizerService.ShowDialog("SourcePropertiesView", vm);
 }
 void DeleteSource(Source source)
 {
     if (Globals.MessageBoxService.ShowYesNo(string.Format("Are you sure you want to delete the source \"{0}\"?", source.SourceName), MessageBoxImage.Warning) != MessageBoxResult.Yes) return;
     source.Delete();
     OnPropertyChanged("CanPlaceAnalysisPoint");
     OnPropertyChanged("IsSaveScenarioCommandEnabled");
 }
Ejemplo n.º 10
0
 async void SourceBoundToLayer(Source source)
 {
     if (!source.IsNew) return;
     source.IsNew = false;
     ((LayerControl)source.LayerControl).Select();
     await Task.Delay(50);
     ((LayerControl)source.LayerControl).Edit();
 }
Ejemplo n.º 11
0
 static Source AddSource(Platform platform, string name, bool isNew)
 {
     var source = new Source
     {
         Platform = platform,
         SourceName = name,
         SourceType = null,
         IsNew = isNew,
     };
     platform.Sources.Add(source);
     return source;
 }
        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();
        }