IFReplaceCommand.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. //======================================================================
  2. //
  3. //
  4. //
  5. // CLR 版本: 4.0.30319.1
  6. // 命名空间: Tofly.DataEditUI
  7. // 类 名: IFReplaceCommand
  8. // 创 建 人: 汤云伟
  9. // 创建时间: 2018/06/28
  10. // 修 改 人:
  11. // 修改时间:
  12. //
  13. //======================================================================
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using Tofly.Core.Context.Support;
  17. using Tofly.Core.ServiceLocator;
  18. using Tofly.CoreUI.Plot;
  19. using Tofly.CoreUI.Control;
  20. using Tofly.CoreUI.Message;
  21. using Tofly.DataEdit.Util;
  22. using Tofly.GISUI.Controls;
  23. using Tofly.GIS.Carto;
  24. using Tofly.GIS.SpatialDatabase;
  25. using Tofly.GIS.Util;
  26. using Tofly.GISUI.Content;
  27. using Tofly.GISUI.Plugin;
  28. using Tofly.GISUI.Utils;
  29. namespace Tofly.DataEditUI
  30. {
  31. /// <summary>
  32. /// 设备更换编辑命令
  33. /// </summary>
  34. [PluginComponentAttribute((long)Core.SysRegist.ModuleKey.Edit, PluginGISType.ArcGIS, GroupName = "编辑", Caption = "设备更换", Describe = "设备更换", IsCreate = true, States = Tofly.CoreUI.Control.Status.STATE_EDIT)]
  35. [Tofly.Core.Stereotype.Component(IsSingleton = "false", Name = "Tofly.DataEditUI.IFReplaceCommand")]
  36. public class IFReplaceCommand : GISPluginButtonBase
  37. {
  38. /// <summary>
  39. ///
  40. /// </summary>
  41. private IMap _cmap;
  42. /// <summary>
  43. /// 接口设备更换窗口
  44. /// </summary>
  45. private IForm _frmIFReplace;
  46. /// <summary>
  47. /// 当前选择可编辑要素字典
  48. /// </summary>
  49. private Dictionary<IFeatureLayer, List<IFeature>> _dicEditableFeatures;
  50. /// <summary>
  51. /// 可编辑图层集合
  52. /// </summary>
  53. private List<IFeatureLayer> _lstEditableLayer = new List<IFeatureLayer>();
  54. /// <summary>
  55. ///
  56. /// </summary>
  57. private IGeoDataSourceHelper _geoDSHelper;
  58. public IFReplaceCommand()
  59. {
  60. this.Enable = false;
  61. }
  62. public override void Create(IPluginContent content)
  63. {
  64. base.Create(content);
  65. this.content.ServiceLocator.ServiceValueChange += ServiceLocator_ServiceValueChange;
  66. }
  67. public override void Click()
  68. {
  69. try
  70. {
  71. if (this._frmIFReplace != null && this._frmIFReplace.Visible)
  72. {
  73. return;
  74. }
  75. if (this._cmap.SelectionCount == 0)
  76. {
  77. return;
  78. }
  79. if (this._dicEditableFeatures == null || this._dicEditableFeatures.Count == 0)
  80. {
  81. throw new System.Exception("请选择需要进行更换的设备要素。");
  82. }
  83. var __kvSelLayerFeature = this._dicEditableFeatures.ElementAt(0);
  84. this._frmIFReplace = ContextRegistry.GetContext().GetObject("Tofly.DataEditUI.Win.FormInterfaceFeatureReplace", new object[] { this.content, __kvSelLayerFeature.Value[0] }) as IForm;
  85. this._frmIFReplace.FormStartPosition = FormStartPositionType.CenterScreen;
  86. this._frmIFReplace.FormClosedEvent += (s) =>
  87. {
  88. System.Windows.Forms.Form __frmBase = this._frmIFReplace as System.Windows.Forms.Form;
  89. if (__frmBase != null && __frmBase.IsDisposed == false)
  90. {
  91. __frmBase.Dispose();
  92. }
  93. this._frmIFReplace = null;
  94. };
  95. this._frmIFReplace.ShowDialog(this.content.PluginMainForm);
  96. }
  97. catch (System.Exception ex)
  98. {
  99. MessageManager.Show("打开失败: " + ex.Message, "设备更换");
  100. }
  101. }
  102. protected virtual void ServiceLocator_ServiceValueChange(string key, object value)
  103. {
  104. if (key.Equals(ServiceLocatorKeys.IsMapEdit))
  105. {
  106. //this.Enable = content.ServiceLocator.GetInstance<bool>(ServiceLocatorKeys.IsMapEdit);
  107. this.ActiveViewContent_ActiveViewSelectionChanged(null);
  108. }
  109. else if (key.Equals(ServiceLocatorKeys.DocumentContent))
  110. {
  111. this._cmap = (this.content.ServiceLocator.GetInstance<IControl>(ServiceLocatorKeys.MapControl) as IMapControl).Map;
  112. var documentcontent = this.content.ServiceLocator.GetInstance<IDocumentContent>(ServiceLocatorKeys.DocumentContent);
  113. documentcontent.ActiveViewContent.ActiveViewSelectionChanged -= ActiveViewContent_ActiveViewSelectionChanged;
  114. documentcontent.ActiveViewContent.ActiveViewSelectionChanged += ActiveViewContent_ActiveViewSelectionChanged;
  115. }
  116. }
  117. /// <summary>
  118. ///
  119. /// </summary>
  120. /// <param name="e"></param>
  121. protected void ActiveViewContent_ActiveViewSelectionChanged(ActiveViewSelectionChangedEventArgs e)
  122. {
  123. this.Enable = false;
  124. this._dicEditableFeatures = null;
  125. if (content.ServiceLocator.GetInstance<bool>(ServiceLocatorKeys.IsMapEdit))
  126. {
  127. if (this._cmap.SelectionCount > 0)
  128. {
  129. if (this._lstEditableLayer.Count == 0)
  130. {
  131. this._lstEditableLayer.AddRange(this._cmap.GetFeatureLayersByMap());
  132. this._lstEditableLayer.RemoveAll(clayer => clayer.FeatureClass == null || clayer.FeatureClass.Workspace.IsBeingEdited() == false); //移除不可编辑图层
  133. this._lstEditableLayer.RemoveAll(clayer => this._geoDSHelper.IsInterfaceFeatureLayer(clayer.FeatureClass.ClassName) == false); //移除非接口设备图层
  134. }
  135. List<IFeatureLayer> __lstEditableLayer = this._lstEditableLayer.Where(flayer => flayer.Visible).ToList(); //筛选出可见要素图层类
  136. this._dicEditableFeatures = MapSelectionHelper.GetSelectedFeaturesByLayer(this._cmap, __lstEditableLayer, true);
  137. int __iFeatureCount = this._dicEditableFeatures.Sum(kvLayerFeature => kvLayerFeature.Value.Count);
  138. string __strArchivalState = (__iFeatureCount == 0 ? "" : this._dicEditableFeatures.ElementAt(0).Value[0].GetValue<string>(AppConfig.g_FieldIFArchivalState));
  139. this.Enable = (__iFeatureCount == 1 && __strArchivalState == "已存档"); //分离出可编辑要素集合
  140. __lstEditableLayer.Clear();
  141. }
  142. }
  143. }
  144. }
  145. }