From e84340170f6519b217c92a1b74ef47e53e3ace85 Mon Sep 17 00:00:00 2001 From: SaiP Date: Mon, 25 Jun 2018 15:02:25 +0530 Subject: [PATCH 01/22] #121: LLOS: add progress bar similar to RLOS (ArcMap) #120: LLOS: add progress bar similar to RLOS (ArcGIS Pro) --- .../ViewModels/LLOSViewModel.cs | 20 ++++++++++++++--- .../ViewModels/ProLLOSViewModel.cs | 22 +++++++++++++++++-- .../VisibilityLibrary/Views/LLOSView.xaml | 8 +++++++ 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/source/addins/ArcMapAddinVisibility/ViewModels/LLOSViewModel.cs b/source/addins/ArcMapAddinVisibility/ViewModels/LLOSViewModel.cs index ceb57e5..be60669 100644 --- a/source/addins/ArcMapAddinVisibility/ViewModels/LLOSViewModel.cs +++ b/source/addins/ArcMapAddinVisibility/ViewModels/LLOSViewModel.cs @@ -37,14 +37,28 @@ public class LLOSViewModel : LOSBaseViewModel public LLOSViewModel() { TargetAddInPoints = new ObservableCollection(); - + DisplayProgressBarLLOS = Visibility.Hidden; // commands SubmitCommand = new RelayCommand(OnSubmitCommand); ClearGraphicsVisible = true; + } #region Properties + private Visibility _displayProgressBarLLOS; + public Visibility DisplayProgressBarLLOS + { + get + { + return _displayProgressBarLLOS; + } + set + { + _displayProgressBarLLOS = value; + RaisePropertyChanged(() => DisplayProgressBarLLOS); + } + } public ObservableCollection TargetAddInPoints { get; set; } @@ -63,9 +77,9 @@ private void OnSubmitCommand(object obj) var savedCursor = System.Windows.Forms.Cursor.Current; System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor; System.Windows.Forms.Application.DoEvents(); - + DisplayProgressBarLLOS = Visibility.Visible; CreateMapElement(); - + DisplayProgressBarLLOS = Visibility.Hidden; System.Windows.Forms.Cursor.Current = savedCursor; } diff --git a/source/addins/ProAppVisibilityModule/ViewModels/ProLLOSViewModel.cs b/source/addins/ProAppVisibilityModule/ViewModels/ProLLOSViewModel.cs index bdacc8e..39e3c78 100644 --- a/source/addins/ProAppVisibilityModule/ViewModels/ProLLOSViewModel.cs +++ b/source/addins/ProAppVisibilityModule/ViewModels/ProLLOSViewModel.cs @@ -41,7 +41,7 @@ public ProLLOSViewModel() { TargetAddInPoints = new ObservableCollection(); IsActiveTab = true; - + DisplayProgressBarLLOS = Visibility.Hidden; // commands SubmitCommand = new RelayCommand(async (obj) => { @@ -119,6 +119,20 @@ public string SightLinesLayerName set { } } + private Visibility _displayProgressBar = Visibility.Collapsed; + public Visibility DisplayProgressBarLLOS + { + get + { + return _displayProgressBar; + } + set + { + _displayProgressBar = value; + RaisePropertyChanged(() => DisplayProgressBarLLOS); + } + } + #endregion #region Commands @@ -139,14 +153,18 @@ await Task.Run(async () => // TODO udpate wait cursor/progressor try { + DisplayProgressBarLLOS = Visibility.Visible; await CreateMapElement(); - //await Reset(true); } catch(Exception ex) { Debug.Print(ex.Message); } + finally + { + DisplayProgressBarLLOS = Visibility.Hidden; + } }); } diff --git a/source/addins/VisibilityLibrary/Views/LLOSView.xaml b/source/addins/VisibilityLibrary/Views/LLOSView.xaml index f904af6..1de4328 100644 --- a/source/addins/VisibilityLibrary/Views/LLOSView.xaml +++ b/source/addins/VisibilityLibrary/Views/LLOSView.xaml @@ -44,6 +44,14 @@ + Date: Mon, 25 Jun 2018 15:15:37 +0530 Subject: [PATCH 02/22] #122: RLOS: Distance parameter does not have a dedicated units control (ArcMap) #123: RLOS: Distance parameter does not have a dedicated units control (ArcGIS Pro) #279: Use a spreadsheet of values as inputs --- .../ViewModels/LOSBaseViewModel.cs | 155 +++++++++++++++-- .../ViewModels/RLOSViewModel.cs | 10 +- .../ProAppVisibilityModule.csproj | 13 +- .../ViewModels/ProLOSBaseViewModel.cs | 160 +++++++++++++++--- .../ViewModels/ProRLOSViewModel.cs | 2 +- .../Views/ProSelectCoordinateFieldsView.xaml | 79 +++++++++ .../ProSelectCoordinateFieldsView.xaml.cs | 15 ++ .../Properties/Resources.Designer.cs | 18 ++ .../Properties/Resources.resx | 6 + .../VisibilityLibrary/Views/LLOSView.xaml | 28 ++- .../VisibilityLibrary/Views/RLOSView.xaml | 54 ++++-- 11 files changed, 465 insertions(+), 75 deletions(-) create mode 100644 source/addins/ProAppVisibilityModule/Views/ProSelectCoordinateFieldsView.xaml create mode 100644 source/addins/ProAppVisibilityModule/Views/ProSelectCoordinateFieldsView.xaml.cs diff --git a/source/addins/ArcMapAddinVisibility/ViewModels/LOSBaseViewModel.cs b/source/addins/ArcMapAddinVisibility/ViewModels/LOSBaseViewModel.cs index bd9ab39..6783181 100644 --- a/source/addins/ArcMapAddinVisibility/ViewModels/LOSBaseViewModel.cs +++ b/source/addins/ArcMapAddinVisibility/ViewModels/LOSBaseViewModel.cs @@ -1,4 +1,4 @@ -// Copyright 2016 Esri +// Copyright 2016 Esri // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,21 +12,25 @@ // See the License for the specific language governing permissions and // limitations under the License. -using System; -using System.Collections.Generic; -using System.Linq; -using System.Collections.ObjectModel; -using System.Collections; +using ArcMapAddinVisibility.Models; +using CoordinateConversionLibrary.Models; +using ESRI.ArcGIS.Analyst3D; using ESRI.ArcGIS.Carto; +using ESRI.ArcGIS.Display; using ESRI.ArcGIS.Geodatabase; -using ESRI.ArcGIS.Analyst3D; using ESRI.ArcGIS.Geometry; -using ESRI.ArcGIS.Display; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; +using System.Linq; +using System.Text; +using System.Windows; using VisibilityLibrary; using VisibilityLibrary.Helpers; -using VisibilityLibrary.Views; using VisibilityLibrary.ViewModels; -using ArcMapAddinVisibility.Models; +using VisibilityLibrary.Views; namespace ArcMapAddinVisibility.ViewModels { @@ -37,6 +41,7 @@ public LOSBaseViewModel() ObserverOffset = 2.0; TargetOffset = 0.0; OffsetUnitType = DistanceTypes.Meters; + DistanceUnitType = DistanceTypes.Meters; AngularUnitType = AngularTypes.DEGREES; ObserverAddInPoints = new ObservableCollection(); @@ -50,12 +55,15 @@ public LOSBaseViewModel() DeletePointCommand = new RelayCommand(OnDeletePointCommand); DeleteAllPointsCommand = new RelayCommand(OnDeleteAllPointsCommand); + PasteCoordinatesCommand = new RelayCommand(OnPasteCommand); + ImportCSVFileCommand = new RelayCommand(OnImportCSVFileCommand); EditPropertiesDialogCommand = new RelayCommand(OnEditPropertiesDialogCommand); } #region Properties private bool observerToolActive = false; + public bool ObserverToolActive { get { return observerToolActive; } @@ -67,6 +75,7 @@ public bool ObserverToolActive } private bool targetToolActive = false; + public bool TargetToolActive { get { return targetToolActive; } @@ -78,6 +87,7 @@ public bool TargetToolActive } private bool isRunning = false; + public bool IsRunning { get { return isRunning; } @@ -89,6 +99,7 @@ public bool IsRunning } private double? observerOffset; + public double? ObserverOffset { get { return observerOffset; } @@ -101,7 +112,9 @@ public double? ObserverOffset throw new ArgumentException(VisibilityLibrary.Properties.Resources.AEInvalidInput); } } + private double? targetOffset; + public double? TargetOffset { get { return targetOffset; } @@ -116,6 +129,7 @@ public double? TargetOffset } private MapPointToolMode toolMode; + public MapPointToolMode ToolMode { get { return toolMode; } @@ -146,8 +160,9 @@ public MapPointToolMode ToolMode public ObservableCollection SurfaceLayerNames { get; set; } public string SelectedSurfaceName { get; set; } public DistanceTypes OffsetUnitType { get; set; } + public DistanceTypes DistanceUnitType { get; set; } public AngularTypes AngularUnitType { get; set; } - + #endregion #region Commands @@ -155,6 +170,8 @@ public MapPointToolMode ToolMode public RelayCommand DeletePointCommand { get; set; } public RelayCommand DeleteAllPointsCommand { get; set; } public RelayCommand EditPropertiesDialogCommand { get; set; } + public RelayCommand PasteCoordinatesCommand { get; set; } + public RelayCommand ImportCSVFileCommand { get; set; } /// /// Command method to delete points @@ -189,6 +206,7 @@ private void OnEditPropertiesDialogCommand(object obj) dlg.ShowDialog(); } + private void DeletePoints(List observers) { if (observers == null || !observers.Any()) @@ -204,6 +222,104 @@ private void DeletePoints(List observers) } } + /// + /// Command method to import points from csv file. + /// + /// + public virtual void OnImportCSVFileCommand(object obj) + { + var mode = obj.ToString(); + CoordinateConversionLibraryConfig.AddInConfig.DisplayAmbiguousCoordsDlg = false; + + var fileDialog = new Microsoft.Win32.OpenFileDialog(); + fileDialog.CheckFileExists = true; + fileDialog.CheckPathExists = true; + fileDialog.Filter = "csv files|*.csv"; + + // attemp to import + var fieldVM = new CoordinateConversionLibrary.ViewModels.SelectCoordinateFieldsViewModel(); + var result = fileDialog.ShowDialog(); + if (result.HasValue && result.Value == true) + { + var dlg = new CoordinateConversionLibrary.Views.SelectCoordinateFieldsView(); + using (Stream s = new FileStream(fileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + { + var headers = CoordinateConversionLibrary.Helpers.ImportCSV.GetHeaders(s); + foreach (var header in headers) + { + fieldVM.AvailableFields.Add(header); + System.Diagnostics.Debug.WriteLine("header : {0}", header); + } + dlg.DataContext = fieldVM; + } + if (dlg.ShowDialog() == true) + { + using (Stream s = new FileStream(fileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + { + var lists = CoordinateConversionLibrary.Helpers.ImportCSV.Import(s, fieldVM.SelectedFields.ToArray()); + + foreach (var item in lists) + { + string outFormattedString = string.Empty; + var sb = new StringBuilder(); + sb.Append(item.lat.Trim()); + if (fieldVM.UseTwoFields) + sb.Append(string.Format(" {0}", item.lon.Trim())); + + string coordinate = sb.ToString(); + CoordinateConversionLibrary.Models.CoordinateType ccType = CoordinateConversionLibrary.Helpers.ConversionUtils.GetCoordinateString(coordinate, out outFormattedString); + IPoint point = (ccType != CoordinateConversionLibrary.Models.CoordinateType.Unknown) ? GetPointFromString(outFormattedString) : null; + if (mode == VisibilityLibrary.Properties.Resources.ToolModeObserver) + { + ToolMode = MapPointToolMode.Observer; + Point1 = point; + OnNewMapPointEvent(Point1); + } + else if (mode == VisibilityLibrary.Properties.Resources.ToolModeTarget) + { + ToolMode = MapPointToolMode.Target; + Point2 = point; + OnNewMapPointEvent(Point2); + } + } + } + } + } + } + + /// + /// Command method to paste points from clipboard. + /// + /// + internal virtual void OnPasteCommand(object obj) + { + var mode = obj.ToString(); + + if (string.IsNullOrWhiteSpace(mode)) + return; + + var input = Clipboard.GetText().Trim(); + string[] lines = input.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); + var coordinates = new List(); + foreach (var item in lines) + { + string outFormattedString = string.Empty; + string coordinate = item.Trim().ToString(); + CoordinateConversionLibrary.Models.CoordinateType ccType = CoordinateConversionLibrary.Helpers.ConversionUtils.GetCoordinateString(coordinate, out outFormattedString); + IPoint point = (ccType != CoordinateConversionLibrary.Models.CoordinateType.Unknown) ? GetPointFromString(outFormattedString) : null; + if (mode == VisibilityLibrary.Properties.Resources.ToolModeObserver) + { + ToolMode = MapPointToolMode.Observer; + Point1 = point; OnNewMapPointEvent(Point1); + } + else if (mode == VisibilityLibrary.Properties.Resources.ToolModeTarget) + { + ToolMode = MapPointToolMode.Target; + Point2 = point; OnNewMapPointEvent(Point2); + } + } + } + #endregion #region Event handlers @@ -277,13 +393,14 @@ internal override void OnNewMapPointEvent(object obj) { // in tool mode "Observer" we add observer points // otherwise ignore - + var color = new RgbColorClass() { Blue = 255 } as IColor; var guid = AddGraphicToMap(point, color, true); var addInPoint = new AddInPoint() { Point = point, GUID = guid }; ObserverAddInPoints.Insert(0, addInPoint); } } + internal override void OnMouseMoveEvent(object obj) { if (!IsActiveTab) @@ -294,17 +411,18 @@ internal override void OnMouseMoveEvent(object obj) if (point == null) return; - if(ToolMode == MapPointToolMode.Observer) + if (ToolMode == MapPointToolMode.Observer) { Point1Formatted = string.Empty; Point1 = point; } - else if(ToolMode == MapPointToolMode.Target) + else if (ToolMode == MapPointToolMode.Target) { Point2Formatted = string.Empty; Point2 = point; } } + /// /// Handler for "Enter" key press /// If pressed when input textbox for observer or target is focused @@ -316,7 +434,7 @@ internal override void OnEnterKeyCommand(object obj) { var keyCommandMode = obj as string; - if(keyCommandMode == VisibilityLibrary.Properties.Resources.ToolModeObserver) + if (keyCommandMode == VisibilityLibrary.Properties.Resources.ToolModeObserver) { ToolMode = MapPointToolMode.Observer; OnNewMapPointEvent(Point1); @@ -332,6 +450,7 @@ internal override void OnEnterKeyCommand(object obj) base.OnEnterKeyCommand(obj); } } + /// /// Method to check to see point is withing the currently selected surface /// returns true if there is no surface selected or point is contained by layer AOI @@ -452,7 +571,7 @@ public ISurface GetSurfaceFromMapByName(IMap map, string name) var mosaicLayer = layer as IMosaicLayer; var rasterLayer = layer as IRasterLayer; - if ((mosaicLayer != null) && (mosaicLayer.PreviewLayer != null) && + if ((mosaicLayer != null) && (mosaicLayer.PreviewLayer != null) && (mosaicLayer.PreviewLayer.Raster != null)) { rasterSurface.PutRaster(mosaicLayer.PreviewLayer.Raster, 0); @@ -520,7 +639,7 @@ public List GetSurfaceNamesFromMap(IMap map, bool IncludeTinLayers = fal var layer = layers.Next(); - while(layer != null) + while (layer != null) { try { @@ -600,7 +719,7 @@ internal override void Reset(bool toolReset) } /// - /// Method used to reset the currently selected surfacename + /// Method used to reset the currently selected surfacename /// Use when toc items or map changes, on tab selection changed, etc /// /// IMap diff --git a/source/addins/ArcMapAddinVisibility/ViewModels/RLOSViewModel.cs b/source/addins/ArcMapAddinVisibility/ViewModels/RLOSViewModel.cs index d277fa9..af603f0 100644 --- a/source/addins/ArcMapAddinVisibility/ViewModels/RLOSViewModel.cs +++ b/source/addins/ArcMapAddinVisibility/ViewModels/RLOSViewModel.cs @@ -427,18 +427,18 @@ internal override void CreateMapElement() //unit of raster DistanceTypes srUnit = GetMTUnitFromEsriUnit(unitString); //get distance in map units - double muMaxDist = GetDistanceFromTo(OffsetUnitType, srUnit, MaxDistance); - double muMinDist = GetDistanceFromTo(OffsetUnitType, srUnit, MinDistance); + double muMaxDist = GetDistanceFromTo(DistanceUnitType, srUnit, MaxDistance); + double muMinDist = GetDistanceFromTo(DistanceUnitType, srUnit, MinDistance); //Distance in meters double convertedMinDistance = MinDistance * conversionFactor; double convertedMaxDistance = MaxDistance * conversionFactor; double finalMinDistance; double finalMaxDistance; - if (srUnit.ToString() != OffsetUnitType.ToString()) + if (srUnit.ToString() != DistanceUnitType.ToString()) { - finalMinDistance = GetLinearDistance(ArcMap.Document.FocusMap, convertedMinDistance, OffsetUnitType); - finalMaxDistance = GetLinearDistance(ArcMap.Document.FocusMap, convertedMaxDistance, OffsetUnitType); + finalMinDistance = GetLinearDistance(ArcMap.Document.FocusMap, convertedMinDistance, DistanceUnitType); + finalMaxDistance = GetLinearDistance(ArcMap.Document.FocusMap, convertedMaxDistance, DistanceUnitType); } else { diff --git a/source/addins/ProAppVisibilityModule/ProAppVisibilityModule.csproj b/source/addins/ProAppVisibilityModule/ProAppVisibilityModule.csproj index 929e5f9..57044be 100644 --- a/source/addins/ProAppVisibilityModule/ProAppVisibilityModule.csproj +++ b/source/addins/ProAppVisibilityModule/ProAppVisibilityModule.csproj @@ -114,6 +114,10 @@ ProEditPropertiesView.xaml + + ProSelectCoordinateFieldsView.xaml + Code + @@ -128,6 +132,10 @@ MSBuild:Compile Designer + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -180,9 +188,10 @@ - + + - + \ No newline at end of file diff --git a/source/addins/ProAppVisibilityModule/ViewModels/ProLOSBaseViewModel.cs b/source/addins/ProAppVisibilityModule/ViewModels/ProLOSBaseViewModel.cs index 0e0adf1..10908c6 100644 --- a/source/addins/ProAppVisibilityModule/ViewModels/ProLOSBaseViewModel.cs +++ b/source/addins/ProAppVisibilityModule/ViewModels/ProLOSBaseViewModel.cs @@ -1,4 +1,4 @@ -// Copyright 2016 Esri +// Copyright 2016 Esri // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,24 +12,26 @@ // See the License for the specific language governing permissions and // limitations under the License. +using ArcGIS.Core.CIM; +using ArcGIS.Core.Geometry; +using ArcGIS.Desktop.Framework.Threading.Tasks; +using ArcGIS.Desktop.Mapping; +using ArcGIS.Desktop.Mapping.Events; +using ProAppVisibilityModule.Models; using System; +using System.Collections; using System.Collections.Generic; -using System.Linq; using System.Collections.ObjectModel; -using System.Collections; -using System.Windows; -using System.Threading.Tasks; using System.Diagnostics; -using ArcGIS.Core.Geometry; -using ArcGIS.Desktop.Mapping; -using ArcGIS.Desktop.Framework.Threading.Tasks; -using ArcGIS.Desktop.Mapping.Events; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; using VisibilityLibrary; using VisibilityLibrary.Helpers; -using VisibilityLibrary.Views; using VisibilityLibrary.ViewModels; -using ProAppVisibilityModule.Models; -using ArcGIS.Core.CIM; +using VisibilityLibrary.Views; namespace ProAppVisibilityModule.ViewModels { @@ -40,10 +42,11 @@ public ProLOSBaseViewModel() ObserverOffset = 2.0; TargetOffset = 0.0; OffsetUnitType = DistanceTypes.Meters; + DistanceUnitType = DistanceTypes.Meters; AngularUnitType = AngularTypes.DEGREES; ObserverAddInPoints = new ObservableCollection(); - + ToolMode = MapPointToolMode.Unknown; SurfaceLayerNames = new ObservableCollection(); SelectedSurfaceName = string.Empty; @@ -53,6 +56,8 @@ public ProLOSBaseViewModel() DeletePointCommand = new RelayCommand(OnDeletePointCommand); DeleteAllPointsCommand = new RelayCommand(OnDeleteAllPointsCommand); EditPropertiesDialogCommand = new RelayCommand(OnEditPropertiesDialogCommand); + ImportCSVFileCommand = new RelayCommand(OnImportCSVFileCommand); + PasteCoordinatesCommand = new RelayCommand(OnPasteCommand); // subscribe to some mapping events ActiveMapViewChangedEvent.Subscribe(OnActiveMapViewChanged); @@ -80,6 +85,7 @@ protected override void OnMapPointToolDeactivated(object obj) } private bool observerToolActive = false; + public bool ObserverToolActive { get { return observerToolActive; } @@ -91,6 +97,7 @@ public bool ObserverToolActive } private bool targetToolActive = false; + public bool TargetToolActive { get { return targetToolActive; } @@ -102,6 +109,7 @@ public bool TargetToolActive } private bool isRunning = false; + public bool IsRunning { get { return isRunning; } @@ -113,6 +121,7 @@ public bool IsRunning } private double? observerOffset; + public double? ObserverOffset { get { return observerOffset; } @@ -125,7 +134,9 @@ public double? ObserverOffset throw new ArgumentException(VisibilityLibrary.Properties.Resources.AEInvalidInput); } } + private double? targetOffset; + public double? TargetOffset { get { return targetOffset; } @@ -140,6 +151,7 @@ public double? TargetOffset } private MapPointToolMode toolMode; + public MapPointToolMode ToolMode { get { return toolMode; } @@ -170,6 +182,7 @@ public MapPointToolMode ToolMode public ObservableCollection SurfaceLayerNames { get; set; } public string SelectedSurfaceName { get; set; } public DistanceTypes OffsetUnitType { get; set; } + public DistanceTypes DistanceUnitType { get; set; } public AngularTypes AngularUnitType { get; set; } #endregion @@ -179,6 +192,8 @@ public MapPointToolMode ToolMode public RelayCommand DeletePointCommand { get; set; } public RelayCommand DeleteAllPointsCommand { get; set; } public RelayCommand EditPropertiesDialogCommand { get; set; } + public RelayCommand ImportCSVFileCommand { get; set; } + public RelayCommand PasteCoordinatesCommand { get; set; } /// /// Command method to delete points @@ -212,8 +227,100 @@ private void OnEditPropertiesDialogCommand(object obj) dlg.DataContext = new EditPropertiesViewModel(); dlg.ShowDialog(); + } + + public virtual void OnImportCSVFileCommand(object obj) + { + var mode = obj as string; + CoordinateConversionLibrary.Models.CoordinateConversionLibraryConfig.AddInConfig.DisplayAmbiguousCoordsDlg = false; + var fileDialog = new Microsoft.Win32.OpenFileDialog(); + fileDialog.CheckFileExists = true; + fileDialog.CheckPathExists = true; + fileDialog.Filter = "csv files|*.csv"; + + // attemp to import + var fieldVM = new CoordinateConversionLibrary.ViewModels.SelectCoordinateFieldsViewModel(); + var result = fileDialog.ShowDialog(); + if (result.HasValue && result.Value == true) + { + var dlg = new CoordinateConversionLibrary.Views.ProSelectCoordinateFieldsView(); + using (Stream s = new FileStream(fileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + { + var headers = CoordinateConversionLibrary.Helpers.ImportCSV.GetHeaders(s); + foreach (var header in headers) + { + fieldVM.AvailableFields.Add(header); + System.Diagnostics.Debug.WriteLine("header : {0}", header); + } + dlg.DataContext = fieldVM; + } + if (dlg.ShowDialog() == true) + { + using (Stream s = new FileStream(fileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + { + var lists = CoordinateConversionLibrary.Helpers.ImportCSV.Import(s, fieldVM.SelectedFields.ToArray()); + + foreach (var item in lists) + { + string outFormattedString = string.Empty; + + var sb = new StringBuilder(); + sb.Append(item.lat.Trim()); + if (fieldVM.UseTwoFields) + sb.Append(string.Format(" {0}", item.lon.Trim())); + + string coordinate = sb.ToString(); + CoordinateConversionLibrary.Models.CoordinateType ccType = CoordinateConversionLibrary.Helpers.ConversionUtils.GetCoordinateString(coordinate, out outFormattedString); + MapPoint point = (ccType != CoordinateConversionLibrary.Models.CoordinateType.Unknown) ? GetMapPointFromString(outFormattedString) : null; + + if (mode == VisibilityLibrary.Properties.Resources.ToolModeObserver) + { + ToolMode = MapPointToolMode.Observer; + Point1 = point; + OnNewMapPointEvent(Point1); + } + else if (mode == VisibilityLibrary.Properties.Resources.ToolModeTarget) + { + ToolMode = MapPointToolMode.Target; + Point2 = point; + OnNewMapPointEvent(Point2); + } + } + } + } + } + } + + internal virtual void OnPasteCommand(object obj) + { + var mode = obj.ToString(); + + if (string.IsNullOrWhiteSpace(mode)) + return; + + var input = Clipboard.GetText().Trim(); + string[] lines = input.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); + var coordinates = new List(); + foreach (var item in lines) + { + string outFormattedString = string.Empty; + string coordinate = item.Trim().ToString(); + CoordinateConversionLibrary.Models.CoordinateType ccType = CoordinateConversionLibrary.Helpers.ConversionUtils.GetCoordinateString(coordinate, out outFormattedString); + MapPoint point = (ccType != CoordinateConversionLibrary.Models.CoordinateType.Unknown) ? GetMapPointFromString(outFormattedString) : null; + if (mode == VisibilityLibrary.Properties.Resources.ToolModeObserver) + { + ToolMode = MapPointToolMode.Observer; + Point1 = point; OnNewMapPointEvent(Point1); + } + else if (mode == VisibilityLibrary.Properties.Resources.ToolModeTarget) + { + ToolMode = MapPointToolMode.Target; + Point2 = point; OnNewMapPointEvent(Point2); + } + } } + /// /// Method used to delete points frome the view's observer listbox /// @@ -246,7 +353,7 @@ internal override void OnEnterKeyCommand(object obj) { var keyCommandMode = obj as string; - if(keyCommandMode == VisibilityLibrary.Properties.Resources.ToolModeObserver) + if (keyCommandMode == VisibilityLibrary.Properties.Resources.ToolModeObserver) { ToolMode = MapPointToolMode.Observer; OnNewMapPointEvent(Point1); @@ -363,7 +470,7 @@ internal async Task IsValidPoint(MapPoint point, bool showPopup = false) // WORKAROUND/BUG: // QueryExtent() is taking several minutes to return from this call with ImageServiceLayer - // during which MCT can't do anything, so for now just return true, + // during which MCT can't do anything, so for now just return true, // fix this in the future when QueryExtent() or alternate works with ImageServiceLayer if (layer is ImageServiceLayer) { @@ -420,7 +527,7 @@ internal async Task IsPointWithinExtent(MapPoint point, Envelope env) /// /// string name of layer /// Layer - /// + /// internal Layer GetLayerFromMapByName(string name) { var layer = MapView.Active.Map.GetLayersAsFlattenedList().FirstOrDefault(l => l.Name == name); @@ -438,10 +545,10 @@ internal async Task> GetSurfaceNamesFromMap() var elevationSurfaceList = await QueuedTask.Run(() => { var list = new List(); - foreach(var layer in layerList) + foreach (var layer in layerList) { var def = layer.GetDefinition(); - if(def != null && def.LayerType == ArcGIS.Core.CIM.MapLayerType.Operational && + if (def != null && def.LayerType == ArcGIS.Core.CIM.MapLayerType.Operational && (def is CIMRasterLayer || def is CIMTinLayer || def is CIMLASDatasetLayer || def is CIMMosaicLayer)) { list.Add(layer); @@ -499,18 +606,18 @@ internal override async Task Reset(bool toolReset) { // reset observer points ObserverAddInPoints.Clear(); - + ClearTempGraphics(); }); } - catch(Exception ex) + catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } } /// - /// Method used to reset the currently selected surfacename + /// Method used to reset the currently selected surfacename /// Use when toc items or map changes, on tab selection changed, etc /// internal async Task ResetSurfaceNames() @@ -544,7 +651,7 @@ internal async Task ResetSurfaceNames() RaisePropertyChanged(() => SelectedSurfaceName); } - catch(Exception ex) + catch (Exception ex) { Debug.Print(ex.Message); } @@ -609,7 +716,7 @@ internal double GetAsMapUnits(SpatialReference sr, double value) if (mapUnit == null) return result; - var offsetLinearUnit = GetLinearUnit(OffsetUnitType); + var offsetLinearUnit = GetLinearUnit(DistanceUnitType); result = offsetLinearUnit.ConvertTo(value, mapUnit); @@ -634,7 +741,6 @@ private async void OnLayersAdded(LayerEventsArgs obj) await ResetSurfaceNames(); } - private async void OnMapPropertyChanged(MapPropertyChangedEventArgs obj) { await ResetSurfaceNames(); @@ -655,18 +761,23 @@ internal LinearUnit GetLinearUnit(DistanceTypes dtype) case DistanceTypes.Feet: result = LinearUnit.Feet; break; + case DistanceTypes.Kilometers: result = LinearUnit.Kilometers; break; + case DistanceTypes.Miles: result = LinearUnit.Miles; break; + case DistanceTypes.NauticalMile: result = LinearUnit.NauticalMiles; break; + case DistanceTypes.Yards: result = LinearUnit.Yards; break; + case DistanceTypes.Meters: default: result = LinearUnit.Meters; @@ -674,6 +785,5 @@ internal LinearUnit GetLinearUnit(DistanceTypes dtype) } return result; } - } } diff --git a/source/addins/ProAppVisibilityModule/ViewModels/ProRLOSViewModel.cs b/source/addins/ProAppVisibilityModule/ViewModels/ProRLOSViewModel.cs index fd5c0fb..c8bd316 100644 --- a/source/addins/ProAppVisibilityModule/ViewModels/ProRLOSViewModel.cs +++ b/source/addins/ProAppVisibilityModule/ViewModels/ProRLOSViewModel.cs @@ -258,7 +258,7 @@ internal override void OnDeleteAllPointsCommand(object obj) { base.OnDeleteAllPointsCommand(obj); } - + public override bool CanCreateElement { get diff --git a/source/addins/ProAppVisibilityModule/Views/ProSelectCoordinateFieldsView.xaml b/source/addins/ProAppVisibilityModule/Views/ProSelectCoordinateFieldsView.xaml new file mode 100644 index 0000000..552fa5a --- /dev/null +++ b/source/addins/ProAppVisibilityModule/Views/ProSelectCoordinateFieldsView.xaml @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +