Skip to content

Commit

Permalink
Esri#407 - Importing an open .csv file causes application to crash
Browse files Browse the repository at this point in the history
Esri#457 - Inputting coordinates manually do not populate the list function
  • Loading branch information
saip committed Mar 27, 2018
1 parent a153d63 commit 3344fec
Show file tree
Hide file tree
Showing 8 changed files with 1,073 additions and 922 deletions.
Expand Up @@ -318,7 +318,7 @@ private void BroadcastCoordinateValues(ESRI.ArcGIS.Geometry.IPoint point)
Mediator.NotifyColleagues(CoordinateConversionLibrary.Constants.BroadcastCoordinateValues, dict);
}

private IPolygon GetMGRSPolygon(IPoint point)
internal IPolygon GetMGRSPolygon(IPoint point)
{
CoordinateMGRS mgrs;

Expand Down
Expand Up @@ -83,7 +83,7 @@ public bool HasAnySelectedItems

public AddInPoint ListBoxItemAddInPoint { get; set; }

public ObservableCollection<AddInPoint> CoordinateAddInPoints { get; set; }
public static ObservableCollection<AddInPoint> CoordinateAddInPoints { get; set; }

private object _ListBoxSelectedItem = null;
public object ListBoxSelectedItem
Expand Down Expand Up @@ -124,7 +124,7 @@ public int ListBoxSelectedIndex
public RelayCommand CopyAllCoordinatesCommand { get; set; }

// lists to store GUIDs of graphics, temp feedback and map graphics
private static List<AMGraphic> GraphicsList = new List<AMGraphic>();
internal static List<AMGraphic> GraphicsList = new List<AMGraphic>();

private void OnDeletePointCommand(object obj)
{
Expand Down
@@ -1,120 +1,215 @@
// 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.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Collections.ObjectModel;
using CoordinateConversionLibrary.Helpers;
using CoordinateConversionLibrary.Models;
using CoordinateConversionLibrary.Views;
using CoordinateConversionLibrary.ViewModels;
using System.Windows.Forms;

namespace ArcMapAddinCoordinateConversion.ViewModels
{
public class ConvertTabViewModel : ArcMapTabBaseViewModel
{
public ConvertTabViewModel()
{
InputCCView = new InputCoordinateConversionView();
InputCCView.DataContext = this;

OutputCCView = new OutputCoordinateView();
OutputCCView.DataContext = new OutputCoordinateViewModel();

CollectTabView = new CCCollectTabView();
CollectTabView.DataContext = new CollectTabViewModel();

InputCoordinateHistoryList = new ObservableCollection<string>();
}

public InputCoordinateConversionView InputCCView { get; set; }
public OutputCoordinateView OutputCCView { get; set; }
public CCCollectTabView CollectTabView { get; set; }

public ObservableCollection<string> InputCoordinateHistoryList { get; set; }

public bool IsToolActive
{
get
{
if ((ArcMap.Application != null) && (ArcMap.Application.CurrentTool != null))
return ArcMap.Application.CurrentTool.Name.ToLower() == MapPointToolName.ToLower();

return false;
}

set
{
if (value)
{
if (ArcMap.Application != null)
CurrentTool = ArcMap.Application.CurrentTool;

OnActivateTool(null);
}
else
{
ArcMap.Application.CurrentTool = CurrentTool;
}

RaisePropertyChanged(() => IsToolActive);
Mediator.NotifyColleagues("IsMapPointToolActive", value);
}
}

/// <summary>
/// Activates the map tool to get map points from mouse clicks/movement
/// </summary>
/// <param name="obj"></param>
internal void OnActivateTool(object obj)
{
if (ArcMap.LayerCount > 0)
{
SetToolActiveInToolBar(ArcMap.Application, MapPointToolName);
}
else
{
System.Windows.Forms.MessageBox.Show(CoordinateConversionLibrary.Properties.Resources.AddLayerMsg,
CoordinateConversionLibrary.Properties.Resources.AddLayerCap);
}
}

#region overrides

/// <summary>
/// Override to include the update of input coordinate history
/// </summary>
/// <param name="obj"></param>
public override bool OnNewMapPoint(object obj)
{
if (!base.OnNewMapPoint(obj))
return false;

var formattedInputCoordinate = amCoordGetter.GetInputDisplayString();

UIHelpers.UpdateHistory(formattedInputCoordinate, InputCoordinateHistoryList);

// deactivate map point tool
// KG - Commented out so user can continously capture coordinates
//IsToolActive = false;

// KG - Added so output component will updated when user clicks on the map
// not when mouse move event is fired.
Mediator.NotifyColleagues(CoordinateConversionLibrary.Constants.RequestOutputUpdate, null);

return true;
}

#endregion overrides
}
// 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.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Collections.ObjectModel;
using CoordinateConversionLibrary.Helpers;
using CoordinateConversionLibrary.Models;
using CoordinateConversionLibrary.Views;
using CoordinateConversionLibrary.ViewModels;
using System.Windows.Forms;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using System;
using ArcMapAddinCoordinateConversion.Helpers;
using ArcMapAddinCoordinateConversion.Models;

namespace ArcMapAddinCoordinateConversion.ViewModels
{
public class ConvertTabViewModel : ArcMapTabBaseViewModel
{
public ConvertTabViewModel()
{
InputCCView = new InputCoordinateConversionView();
InputCCView.DataContext = this;

OutputCCView = new OutputCoordinateView();
OutputCCView.DataContext = new OutputCoordinateViewModel();

CollectTabView = new CCCollectTabView();
CollectTabView.DataContext = new CollectTabViewModel();

InputCoordinateHistoryList = new ObservableCollection<string>();
}

public InputCoordinateConversionView InputCCView { get; set; }
public OutputCoordinateView OutputCCView { get; set; }
public CCCollectTabView CollectTabView { get; set; }

public ObservableCollection<string> InputCoordinateHistoryList { get; set; }

public bool IsToolActive
{
get
{
if ((ArcMap.Application != null) && (ArcMap.Application.CurrentTool != null))
return ArcMap.Application.CurrentTool.Name.ToLower() == MapPointToolName.ToLower();

return false;
}

set
{
if (value)
{
if (ArcMap.Application != null)
CurrentTool = ArcMap.Application.CurrentTool;

OnActivateTool(null);
}
else
{
ArcMap.Application.CurrentTool = CurrentTool;
}

RaisePropertyChanged(() => IsToolActive);
Mediator.NotifyColleagues("IsMapPointToolActive", value);
}
}

/// <summary>
/// Activates the map tool to get map points from mouse clicks/movement
/// </summary>
/// <param name="obj"></param>
internal void OnActivateTool(object obj)
{
if (ArcMap.LayerCount > 0)
{
SetToolActiveInToolBar(ArcMap.Application, MapPointToolName);
}
else
{
System.Windows.Forms.MessageBox.Show(CoordinateConversionLibrary.Properties.Resources.AddLayerMsg,
CoordinateConversionLibrary.Properties.Resources.AddLayerCap);
}
}

#region overrides

/// <summary>
/// Override to include the update of input coordinate history
/// </summary>
/// <param name="obj"></param>
public override bool OnNewMapPoint(object obj)
{
if (!base.OnNewMapPoint(obj))
return false;

var formattedInputCoordinate = amCoordGetter.GetInputDisplayString();

UIHelpers.UpdateHistory(formattedInputCoordinate, InputCoordinateHistoryList);

// deactivate map point tool
// KG - Commented out so user can continously capture coordinates
//IsToolActive = false;

// KG - Added so output component will updated when user clicks on the map
// not when mouse move event is fired.
Mediator.NotifyColleagues(CoordinateConversionLibrary.Constants.RequestOutputUpdate, null);

return true;
}

internal override void OnFlashPointCommand(object obj)
{
ProcessInput(InputCoordinate);
Mediator.NotifyColleagues(CoordinateConversionLibrary.Constants.RequestOutputUpdate, null);


IGeometry address = obj as IGeometry;

if (address == null && amCoordGetter != null && amCoordGetter.Point != null)
{
address = amCoordGetter.Point;
AddCollectionPoint(amCoordGetter.Point);
}

if (address != null)
{
// Map und View
IMxDocument mxdoc = ArcMap.Application.Document as IMxDocument;
IActiveView activeView = mxdoc.ActivatedView;
IMap map = mxdoc.FocusMap;
IEnvelope envelope = activeView.Extent;

//ClearGraphicsContainer(map);

IScreenDisplay screenDisplay = activeView.ScreenDisplay;
short screenCache = Convert.ToInt16(esriScreenCache.esriNoScreenCache);

ISpatialReference outgoingCoordSystem = map.SpatialReference;
address.Project(outgoingCoordSystem);

// is point within current extent
// if so, pan to point
var relationOp = envelope as IRelationalOperator;
if (relationOp != null && activeView is IMap)
{
if (!relationOp.Contains(address))
{
// pan to
envelope.CenterAt(address as IPoint);
activeView.Extent = envelope;
activeView.Refresh();
}
}

IRgbColor color = new RgbColorClass();
color.Green = 80;
color.Red = 22;
color.Blue = 68;

ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbol();
simpleMarkerSymbol.Color = color;
simpleMarkerSymbol.Size = 15;
simpleMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSDiamond;

IMarkerElement markerElement = new MarkerElementClass();

markerElement.Symbol = simpleMarkerSymbol;

IPolygon poly = null;
if (InputCoordinateType == CoordinateType.MGRS || InputCoordinateType == CoordinateType.USNG)
{
poly = GetMGRSPolygon(address as IPoint);
}

if (poly != null)
{
address = poly;
}
var av = mxdoc.FocusMap as IActiveView;
ArcMapHelpers.FlashGeometry(address, color, av.ScreenDisplay, 500, av.Extent);
}
}

#endregion overrides

private void AddCollectionPoint(IPoint point)
{
if (point != null && !point.IsEmpty)
{
var color = new RgbColorClass() { Red = 255 } as IColor;
var guid = ArcMapHelpers.AddGraphicToMap(point, color, true, esriSimpleMarkerStyle.esriSMSCircle, 7);
var addInPoint = new AddInPoint() { Point = point, GUID = guid };

//Add point to the top of the list
CollectTabViewModel.CoordinateAddInPoints.Insert(0, addInPoint);

CollectTabViewModel.GraphicsList.Add(new AMGraphic(guid, point, true));
}
}
}
}

0 comments on commit 3344fec

Please sign in to comment.