Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #333 from Esri/CTLocalGovTeam-dev
Browse files Browse the repository at this point in the history
Delivery of Visibility Addin DotNet 2.4.1 – Sprint 1 of 1
  • Loading branch information
dfoll authored Sep 27, 2019
2 parents 57e6de2 + 571f798 commit ba40810
Show file tree
Hide file tree
Showing 12 changed files with 541 additions and 164 deletions.
93 changes: 55 additions & 38 deletions source/addins/ArcMapAddinVisibility/ViewModels/LLOSViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ public LLOSViewModel()
DisplayProgressBarLLOS = Visibility.Hidden;
// commands
SubmitCommand = new RelayCommand(OnSubmitCommand);

ClearGraphicsVisible = true;

}

#region Properties
Expand Down Expand Up @@ -213,10 +211,64 @@ internal override void CreateMapElement()
IsRunning = true;
IPolyline longestLine = new PolylineClass();

ReadSelectedLayerPoints();


ILayer surfaceLayer = GetLayerFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);
if (surfaceLayer == null)
{
System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgSurfaceLayerNotFound, VisibilityLibrary.Properties.Resources.CaptionError);
return;
}

IsValidSurface = ValidateElevationSurface();
if (!IsValidSurface)
{
return;
}

// Issue warning if layer is ImageServerLayer
if (surfaceLayer is IImageServerLayer)
{
MessageBoxResult mbr = MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgLayerIsImageService,
VisibilityLibrary.Properties.Resources.CaptionLayerIsImageService, MessageBoxButton.YesNo);

if (mbr == MessageBoxResult.No)
{
System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
return;
}
}

// Determine if selected surface is projected or geographic
var geoDataset = surfaceLayer as IGeoDataset;
if (geoDataset == null)
{
System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.CaptionError);
return;
}

SelectedSurfaceSpatialRef = geoDataset.SpatialReference;

if (SelectedSurfaceSpatialRef is IGeographicCoordinateSystem)
{
MessageBox.Show(VisibilityLibrary.Properties.Resources.LLOSUserPrompt, VisibilityLibrary.Properties.Resources.LLOSUserPromptCaption);
return;
}

if (ArcMap.Document.FocusMap.SpatialReference.FactoryCode != geoDataset.SpatialReference.FactoryCode)
{
MessageBox.Show(VisibilityLibrary.Properties.Resources.LOSDataFrameMatch, VisibilityLibrary.Properties.Resources.LOSSpatialReferenceCaption);
SetErrorTemplate(false);
return;
}

if (!CanCreateElement || ArcMap.Document == null || ArcMap.Document.FocusMap == null || string.IsNullOrWhiteSpace(SelectedSurfaceName))
return;

SetErrorTemplate(true);
ReadSelectedLayerPoints();


if ((LLOS_ObserversInExtent.Any() || ObserverAddInPoints.Any())
&& LLOS_TargetsInExtent.Any() || TargetAddInPoints.Any())
{
Expand All @@ -228,42 +280,7 @@ internal override void CreateMapElement()
if (surface == null)
return;

ILayer surfaceLayer = GetLayerFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);

// Issue warning if layer is ImageServerLayer
if (surfaceLayer is IImageServerLayer)
{
MessageBoxResult mbr = MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgLayerIsImageService,
VisibilityLibrary.Properties.Resources.CaptionLayerIsImageService, MessageBoxButton.YesNo);

if (mbr == MessageBoxResult.No)
{
System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
return;
}
}

// Determine if selected surface is projected or geographic
var geoDataset = surfaceLayer as IGeoDataset;
if (geoDataset == null)
{
System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.CaptionError);
return;
}

SelectedSurfaceSpatialRef = geoDataset.SpatialReference;

if (SelectedSurfaceSpatialRef is IGeographicCoordinateSystem)
{
MessageBox.Show(VisibilityLibrary.Properties.Resources.LLOSUserPrompt, VisibilityLibrary.Properties.Resources.LLOSUserPromptCaption);
return;
}

if (ArcMap.Document.FocusMap.SpatialReference.FactoryCode != geoDataset.SpatialReference.FactoryCode)
{
MessageBox.Show(VisibilityLibrary.Properties.Resources.LOSDataFrameMatch, VisibilityLibrary.Properties.Resources.LOSSpatialReferenceCaption);
return;
}

SelectedSurfaceSpatialRef = geoDataset.SpatialReference;

Expand Down
157 changes: 147 additions & 10 deletions source/addins/ArcMapAddinVisibility/ViewModels/LOSBaseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Media;
using System.Windows.Threading;
using VisibilityLibrary;
using VisibilityLibrary.Helpers;
Expand Down Expand Up @@ -69,12 +71,12 @@ public LOSBaseViewModel()
SelectedLLOS_ObserverLyrName = string.Empty;
SelectedLLOS_TargetLyrName = string.Empty;
SelectedRLOS_ObserverLyrName = string.Empty;
SetErrorTemplate(true);

Mediator.Register(Constants.MAP_TOC_UPDATED, OnMapTocUpdated);
Mediator.Register(Constants.DISPLAY_COORDINATE_TYPE_CHANGED, OnDisplayCoordinateTypeChanged);
Mediator.Register(Constants.MAP_SPATIAL_REFERENCED_CHANGED, OnMapSpatialReferenceChanged);


DeletePointCommand = new RelayCommand(OnDeletePointCommand);
DeleteAllPointsCommand = new RelayCommand(OnDeleteAllPointsCommand);
PasteCoordinatesCommand = new RelayCommand(OnPasteCommand);
Expand Down Expand Up @@ -217,10 +219,32 @@ public string SelectedRLOS_ObserverLyrName
}
}

private string selectedSurfaceTooltip;
public string SelectedSurfaceTooltip
{
get { return selectedSurfaceTooltip; }
set
{
selectedSurfaceTooltip = value;
RaisePropertyChanged(() => SelectedSurfaceTooltip);
}
}

private System.Windows.Media.Brush selectedBorderBrush;
public System.Windows.Media.Brush SelectedBorderBrush
{
get { return selectedBorderBrush; }
set
{
selectedBorderBrush = value;
RaisePropertyChanged(() => SelectedBorderBrush);
}
}

public ObservableCollection<string> LLOS_ObserverLyrNames { get; set; }
public ObservableCollection<string> LLOS_TargetLyrNames { get; set; }
public ObservableCollection<string> RLOS_ObserverLyrNames { get; set; }

private bool _isLLOSValidSelection { get; set; }
public bool IsLLOSValidSelection
{
Expand All @@ -234,7 +258,7 @@ public bool IsLLOSValidSelection
RaisePropertyChanged(() => IsLLOSValidSelection);
}
}

private bool _isRLOSValidSelection { get; set; }
public bool IsRLOSValidSelection
{
Expand All @@ -248,7 +272,21 @@ public bool IsRLOSValidSelection
RaisePropertyChanged(() => IsRLOSValidSelection);
}
}


private bool isInputValid;
public bool IsInputValid
{
get
{
return isInputValid;
}
set
{
isInputValid = value;
RaisePropertyChanged(() => IsInputValid);
}
}

public string EnterManullyOption { get; set; }
public ObservableCollection<AddInPointObject> LLOS_ObserversInExtent { get; set; }
public ObservableCollection<AddInPointObject> LLOS_ObserversOutOfExtent { get; set; }
Expand Down Expand Up @@ -487,6 +525,9 @@ private void OnMapTocUpdated(object obj)
var map = ArcMap.Document.FocusMap;

ResetSurfaceNames(map);


this.ValidateSelectedSurface();
}

/// <summary>
Expand All @@ -495,7 +536,8 @@ private void OnMapTocUpdated(object obj)
/// <param name="obj">not used</param>
private void OnMapSpatialReferenceChanged(object obj)
{
if ((ArcMap.Document == null) || (ArcMap.Document.FocusMap == null) ||
this.ValidateSelectedSurface();
if ((ArcMap.Document == null) || (ArcMap.Document.FocusMap == null) ||
(GraphicsList == null) || (GraphicsList.Count == 0))
return;

Expand Down Expand Up @@ -529,6 +571,29 @@ private void OnMapSpatialReferenceChanged(object obj)
av.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}


private void ValidateSelectedSurface()
{
if (!string.IsNullOrEmpty(SelectedSurfaceName))
{
ILayer surfaceLayer = GetLayerFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);

var geoDataset = surfaceLayer as IGeoDataset;
if (geoDataset != null)
{
SelectedSurfaceSpatialRef = geoDataset.SpatialReference;
if (ArcMap.Document.FocusMap.SpatialReference.FactoryCode != geoDataset.SpatialReference.FactoryCode)
{
SetErrorTemplate(false);
}
else
{
SetErrorTemplate(true);
}
}
}
}

/// <summary>
/// Override this method to implement a "Mode" to separate the input of
/// observer points and target points
Expand Down Expand Up @@ -564,6 +629,59 @@ protected override void OnMapPointToolDeactivated(object obj)
base.OnMapPointToolDeactivated(obj);
}

internal bool ValidateElevationSurface()
{
if (string.IsNullOrEmpty(SelectedSurfaceName))
{
MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgSurfaceLayerNotFound,
VisibilityLibrary.Properties.Resources.CaptionError, MessageBoxButton.OK);
return false;
}

ILayer surfaceLayer = GetLayerFromMapByName(ArcMap.Document.FocusMap, SelectedSurfaceName);

// Issue warning if layer is ImageServerLayer
if (surfaceLayer is IImageServerLayer)
{
MessageBoxResult mbr = MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgLayerIsImageService,
VisibilityLibrary.Properties.Resources.CaptionLayerIsImageService, MessageBoxButton.YesNo);

if (mbr == MessageBoxResult.No)
{
System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.MsgCalcCancelled);
return false;
}
}

// Determine if selected surface is projected or geographic
var geoDataset = surfaceLayer as IGeoDataset;
if (geoDataset == null)
{
System.Windows.MessageBox.Show(VisibilityLibrary.Properties.Resources.MsgTryAgain, VisibilityLibrary.Properties.Resources.CaptionError);
return false;
}

SelectedSurfaceSpatialRef = geoDataset.SpatialReference;

if (SelectedSurfaceSpatialRef is IGeographicCoordinateSystem)
{
MessageBox.Show(VisibilityLibrary.Properties.Resources.LLOSUserPrompt, VisibilityLibrary.Properties.Resources.LLOSUserPromptCaption);
return false;
}

if (ArcMap.Document.FocusMap.SpatialReference.FactoryCode != geoDataset.SpatialReference.FactoryCode)
{
MessageBox.Show(VisibilityLibrary.Properties.Resources.LOSDataFrameMatch, VisibilityLibrary.Properties.Resources.LOSSpatialReferenceCaption);
SetErrorTemplate(false);
return false;
}
else
{
SetErrorTemplate(true);
}
return true;
}

/// <summary>
/// Override this event to collect observer points based on tool mode
/// </summary>
Expand All @@ -573,7 +691,7 @@ internal override void OnNewMapPointEvent(object obj)
if (!IsActiveTab)
return;

var point = obj as IPoint;
var point = obj as IPoint;

// ok, we have a point
if (ToolMode == MapPointToolMode.Observer)
Expand Down Expand Up @@ -1027,7 +1145,7 @@ internal virtual void OnDisplayCoordinateTypeChanged(object obj)
var list = ObserverAddInPoints.ToList();
var inExtentList = ObserverInExtentPoints.ToList();
var outExtentList = ObserverOutExtentPoints.ToList();

ObserverAddInPoints.Clear();
ObserverInExtentPoints.Clear();
ObserverOutExtentPoints.Clear();
Expand Down Expand Up @@ -1152,7 +1270,7 @@ internal void ReadSelectedLyrPoints(ObservableCollection<AddInPointObject> inExt
var id = Convert.ToInt32(feature.get_Value(idIndex));
var z1 = surface.GetElevation(point) + finalObserverOffset;

if ((point.SpatialReference != null) && (ArcMap.Document.FocusMap != null)
if ((point.SpatialReference != null) && (ArcMap.Document.FocusMap != null)
&& (ArcMap.Document.FocusMap.SpatialReference != null))
{
if (point.SpatialReference != ArcMap.Document.FocusMap.SpatialReference)
Expand All @@ -1172,13 +1290,13 @@ internal void ReadSelectedLyrPoints(ObservableCollection<AddInPointObject> inExt
}
layer = layers.Next();
}
}
}

private static List<int> GetSelectedFeaturesCollections(ILayer layer)
{
var selectedFeatureCollections = new List<int>();
var selectedFeature = ((IFeatureSelection)layer).SelectionSet;
var enumFeature = ((IEnumIDs)(((ISelectionSet)(selectedFeature)).IDs));
var enumFeature = selectedFeature.IDs;
enumFeature.Reset();
int selfeature = enumFeature.Next();
while (selfeature != -1)
Expand All @@ -1202,5 +1320,24 @@ internal void ClearRLOSCollections()
RLOS_ObserversInExtent.Clear();
RLOS_ObserversOutOfExtent.Clear();
}

internal void SetErrorTemplate(bool isDefaultColor)
{
Dispatcher.CurrentDispatcher.Invoke(() =>
{
if (isDefaultColor)
{
SelectedBorderBrush = new SolidColorBrush(Colors.Transparent);
SelectedSurfaceTooltip = "Select Surface";
IsInputValid = true;
}
else
{
SelectedBorderBrush = new SolidColorBrush(Colors.Red);
SelectedSurfaceTooltip = VisibilityLibrary.Properties.Resources.LOSDataFrameMatchError;
IsInputValid = false;
}
});
}
}
}
Loading

0 comments on commit ba40810

Please sign in to comment.