ConnectionManageCommand.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. //======================================================================
  2. //
  3. //
  4. //
  5. // CLR 版本: 4.0.30319.1
  6. // 命名空间: Tofly.DataEditUI
  7. // 类 名: ConnectionManageCommand
  8. // 创 建 人: 汤云伟
  9. // 创建时间: 2017/04/05 14:30:00
  10. // 修 改 人:
  11. // 修改时间:
  12. //
  13. //======================================================================
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Text;
  17. using System.Linq;
  18. using Tofly.Core.Context.Support;
  19. using Tofly.Core.Context;
  20. using Tofly.Core.ServiceLocator;
  21. using Tofly.CoreUI.Plot;
  22. using Tofly.CoreUI.Control;
  23. using Tofly.CoreUI.Message;
  24. using Tofly.Data.Metadata;
  25. using Tofly.GIS.Display;
  26. using Tofly.GISUI.Controls;
  27. using Tofly.GIS.Geometry;
  28. using Tofly.GIS.Carto;
  29. using Tofly.GIS.SpatialDatabase;
  30. using Tofly.GIS.Util;
  31. using Tofly.DataEditUI.Properties;
  32. using Tofly.GISUI.Content;
  33. using Tofly.GISUI.Plugin;
  34. using Tofly.GISUI.Utils;
  35. using Tofly.DataEdit;
  36. namespace Tofly.DataEditUI
  37. {
  38. /// <summary>
  39. /// 扩展属性编辑命令
  40. /// </summary>
  41. [PluginComponentAttribute((long)Core.SysRegist.ModuleKey.Edit, PluginGISType.ArcGIS, GroupName = "编辑", Caption = "连通性编辑", Describe = "点要素连通性编辑管理", IsCreate = true, States = Tofly.CoreUI.Control.Status.STATE_EDIT)]
  42. [Tofly.Core.Stereotype.Component(IsSingleton = "false", Name = "Tofly.DataEditUI.ConnectionManageCommand")]
  43. public class ConnectionManageCommand : GISPluginButtonBase
  44. {
  45. /// <summary>
  46. ///
  47. /// </summary>
  48. private IMap _cmap;
  49. /// <summary>
  50. /// 连通性编辑窗口
  51. /// </summary>
  52. private IFormSetEditFeatureCollection _frmConnectionManage;
  53. /// <summary>
  54. /// 可编辑图层集合
  55. /// </summary>
  56. private List<IFeatureLayer> _lstEditableLayer = new List<IFeatureLayer>();
  57. /// <summary>
  58. /// 当前选择可编辑要素字典
  59. /// </summary>
  60. private Dictionary<IFeatureLayer, List<IFeature>> _dicEditableFeatures;
  61. /// <summary>
  62. ///
  63. /// </summary>
  64. public ConnectionManageCommand()
  65. {
  66. this.Enable = false;
  67. }
  68. public override void Create(IPluginContent content)
  69. {
  70. base.Create(content);
  71. this.content.ServiceLocator.ServiceValueChange += ServiceLocator_ServiceValueChange;
  72. }
  73. public override void Click()
  74. {
  75. try
  76. {
  77. if (this._frmConnectionManage != null && this._frmConnectionManage.Visible)
  78. {
  79. this._frmConnectionManage.FormWindowState = FormWindowState.Normal; //恢复窗口状态
  80. return;
  81. }
  82. if (this._cmap.SelectionCount == 0)
  83. {
  84. return;
  85. }
  86. if (this._dicEditableFeatures == null || this._dicEditableFeatures.Count == 0)
  87. {
  88. throw new System.Exception("无有效可编辑要素.");
  89. }
  90. if (this._dicEditableFeatures.Count > 0)
  91. {
  92. this._frmConnectionManage = ContextRegistry.GetContext().GetObject("Tofly.DataEditUI.Win.FormConnectionManage") as IFormSetEditFeatureCollection;
  93. this._frmConnectionManage.FormClosedEvent += (s) =>
  94. {
  95. System.Windows.Forms.Form __frmBase = this._frmConnectionManage as System.Windows.Forms.Form;
  96. if (__frmBase != null && __frmBase.IsDisposed == false)
  97. {
  98. __frmBase.Dispose();
  99. }
  100. this._frmConnectionManage = null;
  101. };
  102. this._frmConnectionManage.FormStartPosition = FormStartPositionType.CenterScreen;
  103. this._frmConnectionManage.Content = this.content;
  104. this._frmConnectionManage.CMap = this._cmap;
  105. this._frmConnectionManage.SetEditFeatures(this._dicEditableFeatures);
  106. this._frmConnectionManage.Show(this.content.PluginMainForm);
  107. }
  108. else
  109. {
  110. MessageManager.Show("请选择需要进行连通性编辑的点要素!", "连通性编辑");
  111. }
  112. }
  113. catch(System.Exception ex)
  114. {
  115. MessageManager.Show("打开编辑失败: " + ex.Message, "连通性编辑");
  116. }
  117. }
  118. protected virtual void ServiceLocator_ServiceValueChange(string key, object value)
  119. {
  120. if (key.Equals(ServiceLocatorKeys.IsMapEdit))
  121. {
  122. this.ActiveViewContent_ActiveViewSelectionChanged(null);
  123. bool __bIsWorkspaceEditing = this.content.ServiceLocator.GetInstance<bool>(ServiceLocatorKeys.IsMapEdit);
  124. if (__bIsWorkspaceEditing == false && this._frmConnectionManage != null) //做窗口控制
  125. {
  126. this._frmConnectionManage.Dispose();
  127. this._frmConnectionManage = null;
  128. }
  129. }
  130. else if (key.Equals(ServiceLocatorKeys.DocumentContent))
  131. {
  132. this._cmap = (this.content.ServiceLocator.GetInstance<IControl>(ServiceLocatorKeys.MapControl) as IMapControl).Map;
  133. var documentcontent = this.content.ServiceLocator.GetInstance<IDocumentContent>(ServiceLocatorKeys.DocumentContent);
  134. documentcontent.ActiveViewContent.ActiveViewSelectionChanged += ActiveViewContent_ActiveViewSelectionChanged;
  135. }
  136. }
  137. /// <summary>
  138. ///
  139. /// </summary>
  140. /// <param name="e"></param>
  141. protected void ActiveViewContent_ActiveViewSelectionChanged(ActiveViewSelectionChangedEventArgs e)
  142. {
  143. this.Enable = false;
  144. this._dicEditableFeatures = null;
  145. if (content.ServiceLocator.GetInstance<bool>(ServiceLocatorKeys.IsMapEdit))
  146. {
  147. if (this._cmap.SelectionCount > 0)
  148. {
  149. if (this._lstEditableLayer.Count == 0)
  150. {
  151. this._lstEditableLayer.AddRange(this._cmap.GetFeatureLayersByMap());
  152. this._lstEditableLayer.RemoveAll(clayer => clayer.FeatureClass == null || clayer.FeatureClass.Workspace.IsBeingEdited() == false); //移除不可编辑图层
  153. this._lstEditableLayer.RemoveAll(clayer => clayer.FeatureClass.ShapeType != GeometryType.GeometryPoint); //移除非点图层
  154. }
  155. List<IFeatureLayer> __lstEditableLayer = this._lstEditableLayer.Where(flayer => flayer.Visible).ToList(); //筛选出可见要素图层类
  156. this._dicEditableFeatures = MapSelectionHelper.GetSelectedFeaturesByLayer(this._cmap, __lstEditableLayer, true);
  157. this.Enable = (this._dicEditableFeatures.Count > 0); //分离出有效可编辑要素集合 && this._dicEditableFeatures.Sum(kvFeature => kvFeature.Value.Count) > 1
  158. }
  159. }
  160. }
  161. }
  162. }