年度变更建库软件5.0版本
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

358 lines
13 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using KGIS.Framework.Views;
using UIShell.OSGi;
using KGIS.Framework.Maps;
using KGIS.Framework.AE.Interface;
using DevExpress.XtraBars;
using KGIS.Framework.Utils.Helper;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using Kingo.Plugin.MapView.Views;
using KGIS.Framework.Menus.Entities;
using KGIS.Framework.Utils.ExtensionMethod;
using KGIS.Framework.Utils;
using KGIS.Framework.Commands;
using KGIS.Framework.Menus.ServicesInvokes;
using ESRI.ArcGIS.SystemUI;
namespace Kingo.Plugin.MapView
{
public partial class UCDataCatalog : UserControl, IDockPanel, IDataCatalogService
{
private ICommandManager _CmdManager;
private IMapService _MapService;
public object TocHook = null;
public UCDataCatalog()
{
try
{
InitializeComponent();
TocHook = axTOCControl1.Object;
DockAreas = KGIS.Framework.Views.DockStyle.DockLeft;
DockWidth = 300;
DefaultArea = KGIS.Framework.Views.DockStyle.DockLeft;
ShowCloseButton = false;
ShowAutoHideButton = true;
Title = "数据目录";
}
catch (Exception ex)
{
if (ex.Message.Contains("ActiveX"))
{
MessageHelper.Show("ArcGIS授权服务未启动或已到期,请检查ArcGIS授权!");
}
else
{
MessageHelper.Show(ex.Message);
}
}
}
public UCDataCatalog(IBundleContext pContext) : this()
{
InitService(pContext);
axTOCControl1.OnDoubleClick += AxTOCControl1_OnDoubleClick;
axTOCControl1.OnMouseUp += _axTocCtrl_OnMouseUp;
}
UCLayerStyleSet view = null;
private void AxTOCControl1_OnDoubleClick(object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnDoubleClickEvent e)
{
if (e.button != 1) return;
esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone;
IBasicMap map = null;
ILayer layer = null;
object other = null;
object index = null;
this.axTOCControl1.Refresh();
this.axTOCControl1.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);
if (item != esriTOCControlItem.esriTOCControlItemLegendClass) return;
if (view == null)
{
view = new UCLayerStyleSet(layer);
view.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
view.ShowInTaskbar = false;
view.Closed += (s, o) =>
{
view = null;
};
}
view.ShowInMainWindow(true);
}
private void InitService(IBundleContext context)
{
context.AddService<IDataCatalogService>(this);
}
public void InitCatalogContextMenus(IEnumerable<ContentMenuItemEntity> itemDatas)
{
InitContextMenus(itemDatas);
}
public Guid ID { get; set; }
public KGIS.Framework.Views.DockStyle DockAreas { get; set; }
public Size FloatSize { get; set; }
public int DockWidth { get; set; }
public int DockHeight { get; set; }
public KGIS.Framework.Views.DockStyle DefaultArea { get; set; }
public bool ShowCloseButton { get; set; }
public bool ShowAutoHideButton { get; set; }
public string Title { get; set; }
#region IDataCatalog接口
public object TocCtrl => axTOCControl1;
public object BarManager => barManager1;
public object MapContextMenu => popMapMenu;
public object GroupContextMenu => popGroupMenu;
public object LayerContextMenu => popLayerMenu;
#endregion
private void _axTocCtrl_OnMouseUp(object sender, ITOCControlEvents_OnMouseUpEvent e)
{
if (e.button != 2)
return;
esriTOCControlItem item = esriTOCControlItem.esriTOCControlItemNone;
IBasicMap map = null;
ILayer layer = null;
object other = null;
object index = null;
axTOCControl1.Refresh();
axTOCControl1.HitTest(e.x, e.y, ref item, ref map, ref layer, ref other, ref index);
if (item == esriTOCControlItem.esriTOCControlItemNone)
{
return;
}
if (item == esriTOCControlItem.esriTOCControlItemMap)
{
axTOCControl1.SelectItem(map, null);
}
else
{
axTOCControl1.SelectItem(layer, null);
}
if (layer == null)
{
MapsManager.Instance.MapService.SetCustomProperty(map);
}
else
{
MapsManager.Instance.MapService.SetCustomProperty(layer);
}
if (item == esriTOCControlItem.esriTOCControlItemMap)
{
SetMenuEnabled(popMapMenu);
popMapMenu.ShowPopup(Control.MousePosition);//弹出右键菜单
}
if (item == esriTOCControlItem.esriTOCControlItemLayer)
{
if (layer is IGroupLayer)
{
////图层组
SetMenuEnabled(popGroupMenu);
popGroupMenu.ShowPopup(Control.MousePosition);//弹出右键菜单
}
else
{
SetMenuEnabled(popLayerMenu);
popLayerMenu.ShowPopup(Control.MousePosition);//弹出右键菜单
}
}
}
/// <summary>
/// 设置弹出菜单最新状态
/// </summary>
/// <param name="menu"></param>
public void SetMenuEnabled(PopupMenu menu)
{
foreach (LinkPersistInfo menuitem in menu.LinksPersistInfo)//循环设置右键菜单启用/禁用状态
{
if ((menuitem.Item as BarButtonItem) != null)
{
var tmpmenu = menuitem.Item as BarButtonItem;
var tmpcmd = tmpmenu.Tag;
if (tmpcmd == null) return;
Type type = tmpcmd.GetType(); //获取类型
try
{
var propertyInfo = type.GetProperty("Enabled");//获取最新启用状态
//设置菜单启用禁用
tmpmenu.Enabled = (bool)propertyInfo.GetValue(tmpcmd, null);
propertyInfo = type.GetProperty("Caption");
if (propertyInfo == null) return;
object title = propertyInfo.GetValue(tmpcmd, null);
if (title == null) continue;
if (string.IsNullOrWhiteSpace(title.ToTrim())) continue; ;
tmpmenu.Caption = title.ToTrim();
}
catch (Exception exc)
{
LogAPI.Debug(exc);
}
}
}
}
public void InitContextMenus(IEnumerable<ContentMenuItemEntity> itemDatas)
{
if (itemDatas == null)
return;
if (_CmdManager == null)
_CmdManager = BundleRuntime.Instance.GetFirstOrDefaultService<ICommandManager>();
if (_MapService == null)
{
_MapService = BundleRuntime.Instance.GetFirstOrDefaultService<IMapService>();
}
foreach (var item in itemDatas)
{
BarItem barItem = DealWithCatalogContextMenus(item);
switch (item.ContentItemType)
{
case "Map":
popMapMenu.AddItem(barItem);
break;
case "Group":
popGroupMenu.AddItem(barItem);
break;
case "Layer":
popLayerMenu.AddItem(barItem);
break;
default:
break;
}
}
}
/// <summary>
/// 将配置列表数据加载成右击菜单项
/// </summary>
/// <param name="pMenuItem"></param>
/// <returns></returns>
private BarItem DealWithCatalogContextMenus(ContentMenuItemEntity pMenuItem)
{
try
{
BarItem bar = null;
if (pMenuItem.Childs != null && pMenuItem.Childs.Count > 0)
{
bar = new BarSubItem();
bar.Caption = pMenuItem.Name;
bar.Glyph = pMenuItem.GetImage();
//创建子项
foreach (var item in pMenuItem.Childs)
{
BarItem subItem = DealWithCatalogContextMenus(item);
(bar as BarSubItem).AddItem(subItem);
barManager1.Items.Add(bar);
if (ExtendMethd.JudgeIsCouldConversionStringOrHasValue(item.ParentId) == false)
{
switch (item.ContentItemType)
{
case "Map":
popMapMenu.AddItem(subItem);
break;
case "Group":
popGroupMenu.AddItem(subItem);
break;
case "Layer":
popLayerMenu.AddItem(subItem);
break;
default:
break;
}
}
}
}
else
{
bar = new BarButtonItem();
bar.Caption = pMenuItem.Name;
bar.ItemClick += Bar_ItemClick;
bar.Glyph = pMenuItem.GetImage();
if (_CmdManager != null)
bar.Tag = _CmdManager.AddCmd(pMenuItem.CommandId, pMenuItem.Bundle, null);
if (bar.Tag is BaseMapMenuCommand && _MapService != null)
{
(bar.Tag as BaseMapMenuCommand).OnCreate(_MapService.getAxMapControl().Object);
}
else
if (bar.Tag is ICommand && _MapService != null)
{
(bar.Tag as ICommand).OnCreate(_MapService.getAxMapControl().Object);
}
barManager1.Items.Add(bar);
}
return bar;
}
catch (Exception ex)
{
LogAPI.Debug("执行 将配置列表数据加载成右击菜单项 方法时异常:" + ex + " ; ");
return null;
}
finally
{
}
}
private void Bar_ItemClick(object sender, ItemClickEventArgs e)
{
BarItem item = e.Item as BarItem;
if (item == null || item.Tag == null)
{
return;
}
try
{
if (item.Tag is ITool && _MapService != null)
{
_MapService.SetCurrentTool(item.Tag);
}
else
if (item.Tag is BaseMapMenuCommand)
{
CommandManagerInvoke.ExeCommand(item.Tag, null);
if (item is BarCheckItem)
{
(item as BarCheckItem).Checked = (item.Tag as BaseMapMenuCommand).Checked;
}
}
else
if (item.Tag is ICommand)
{
(item.Tag as ICommand).OnClick();
if (item is BarCheckItem)
{
(item as BarCheckItem).Checked = (item.Tag as ICommand).Checked;
}
}
}
catch (Exception ex)
{
LogAPI.Debug(string.Format("执行【{0}】命令异常,异常信息如下:", item.Caption));
LogAPI.Debug(ex);
LogAPI.Debug("异常信息结束");
}
}
public void InitLayerTree(IMap pMap)
{
throw new NotImplementedException();
}
}
}