using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
using DelftTools.Controls;
using DelftTools.Controls.Swf;
using DelftTools.Shell.Gui;
using DelftTools.Utils;
using DelftTools.Utils.Aop;
using DelftTools.Utils.Collections;
using DelftTools.Utils.Collections.Generic;
using DeltaShell.Plugins.SharpMapGis.Gui.Properties;
using DeltaShell.Plugins.SharpMapGis.Tools;
using GeoAPI.Extensions.Feature;
using GeoAPI.Geometries;
using GisSharpBlog.NetTopologySuite.Geometries;
using SharpMap;
using SharpMap.Api.Layers;
using SharpMap.CoordinateSystems.Transformations;
using SharpMap.Layers;
using SharpMap.UI.Forms;
using SharpMap.UI.Tools;
namespace DeltaShell.Plugins.SharpMapGis.Gui.Forms
{
public partial class MapView : UserControl, ICanvasEditor, ICompositeView, ISearchableView
{
private MapViewTabControl tabControl;
private bool canAddPoint = true;
private bool canDeleteItem = true;
private bool canMoveItem = true;
private bool canMoveItemLinear = true;
private bool canSelectItem = true;
private bool settingSelection = false;
private StackTrace constructorStackTrace;
public MapView()
{
InitializeComponent();
IsAllowSyncWithGuiSelection = true;
tabControl = new MapViewTabControl { Size = new Size(300, 250), Dock = DockStyle.Bottom };
Controls.Add(tabControl);
mapControl.SelectedFeaturesChanged += (s,e) => SyncMapViewEditorSelection();
collapsibleSplitter1.ControlToHide = tabControl;
tabControl.ViewCollectionChanged += OnTabControlOnViewCollectionChanged;
// hide for now
IsTabControlVisible = false;
// add some tools here, to avoid references to DeltaShell projects in SharpMap
mapControl.Tools.Add(new ExportMapToImageMapTool());
Map = new Map(mapControl.ClientSize) { Zoom = 100 };
if (Assembly.GetEntryAssembly() == null) // HACK: detecting nasty dispose exceptions when assembly empty - we run from non-exe (test)
{
constructorStackTrace = new StackTrace();
}
}
public bool IsTabControlVisible
{
get { return collapsibleSplitter1.Visible; }
set
{
if (IsTabControlVisible == value)
{
return;
}
collapsibleSplitter1.ToggleState();
collapsibleSplitter1.Visible = value;
tabControl.SendToBack();
}
}
///
/// If true, selection in the MapView is synched with Gui.Selection
///
public bool IsAllowSyncWithGuiSelection { get; set; }
public Map Map
{
get { return mapControl.Map; }
set
{
if(mapControl.Map == value)
{
return;
}
UnsubscribeEvents();
if (mapControl != null)
{
mapControl.Map = value;
}
SubscribeEvents();
}
}
public MapControl MapControl
{
get { return mapControl; }
}
public ViewInfo ViewInfo { get; set; }
public bool CanSelectItem
{
get { return canSelectItem; }
set { canSelectItem = value; }
}
public bool IsSelectItemActive
{
get
{
return (MapControl.SelectTool.IsActive &&
(MapControl.SelectTool.MultiSelectionMode == MultiSelectionMode.Rectangle));
}
set
{
if (value)
{
MapControl.SelectTool.MultiSelectionMode = MultiSelectionMode.Rectangle;
MapControl.ActivateTool(MapControl.SelectTool);
}
}
}
public bool CanMoveItem
{
get { return canMoveItem; }
set { canMoveItem = value; }
}
public bool IsMoveItemActive
{
get { return MapControl.MoveTool.IsActive; }
set
{
// only support setting to true
if (value)
{
MapControl.ActivateTool(MapControl.MoveTool);
}
}
}
public bool CanMoveItemLinear
{
get { return canMoveItemLinear; }
set { canMoveItemLinear = value; }
}
public bool IsMoveItemLinearActive
{
get { return MapControl.LinearMoveTool.IsActive; }
set
{
if (value)
{
MapControl.ActivateTool(MapControl.LinearMoveTool);
}
}
}
public bool CanDeleteItem
{
get { return canDeleteItem; }
set { canDeleteItem = value; }
}
public bool IsDeleteItemActive
{
get { return true; }
set { }
}
public bool CanAddPoint
{
get { return canAddPoint; }
set { canAddPoint = value; }
}
public bool IsAddPointActive
{
get
{
var tool = (CurvePointTool)MapControl.GetToolByName("CurvePoint");
return tool.IsActive && tool.Mode == CurvePointTool.EditMode.Add;
}
set
{
if (value)
{
var tool = (CurvePointTool)MapControl.GetToolByName("CurvePoint");
tool.Mode = CurvePointTool.EditMode.Add;
MapControl.ActivateTool(tool);
}
}
}
public bool IsRemovePointActive
{
get
{
var tool = (CurvePointTool)MapControl.GetToolByName("CurvePoint");
return tool.IsActive && tool.Mode == CurvePointTool.EditMode.Remove;
}
set
{
if (value)
{
var tool = (CurvePointTool)MapControl.GetToolByName("CurvePoint");
tool.Mode = CurvePointTool.EditMode.Remove;
MapControl.ActivateTool(tool);
}
}
}
public bool CanRemovePoint { get { return true; } }
///
/// Expects a Map
///
public object Data
{
get { return mapControl.Map; }
set { Map = (Map) value; }
}
public Image Image
{
get { return Resources.Map; }
set { }
}
public MapViewTabControl TabControl { get { return tabControl; } }
public CollapsibleSplitter Splitter
{
get { return collapsibleSplitter1; }
set { collapsibleSplitter1 = value; }
}
public IEventedList ChildViews
{
get { return tabControl.ChildViews; }
}
public bool HandlesChildViews
{
get { return true; }
}
public Func GetDataForLayer { get; set; }
public Func