FeatureBackSaveCommand.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //======================================================================
  2. //
  3. //
  4. //
  5. // CLR 版本: 4.0.30319.1
  6. // 命名空间: Tofly.DataEditUI
  7. // 类 名: FeatureBackSaveCommand
  8. // 创 建 人: 汤云伟
  9. // 创建时间: 2016/10/05 15:20: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.CoreUI.Win.Form.Forms;
  25. using Tofly.CoreUI.Utils;
  26. using Tofly.Data.Metadata;
  27. using Tofly.GIS.Display;
  28. using Tofly.GISUI.Content;
  29. using Tofly.GISUI.Controls;
  30. using Tofly.GIS.Geometry;
  31. using Tofly.GIS.Carto;
  32. using Tofly.GIS.SpatialDatabase;
  33. using Tofly.GIS.Util;
  34. using Tofly.DataEditUI.Properties;
  35. using Tofly.GISUI.Plugin;
  36. using Tofly.Data.General;
  37. using Tofly.GISUI.Utils;
  38. namespace Tofly.DataEditUI
  39. {
  40. /// <summary>
  41. /// 属性自动化命令
  42. /// </summary>
  43. [PluginComponentAttribute((long)Core.SysRegist.ModuleKey.Edit, PluginGISType.ArcGIS, GroupName = "编辑", Caption = "属性自动化", Describe = "根据当前工程信息,对选择设备要素进行属性数据自动化处理", IsCreate = true, States = Tofly.CoreUI.Control.Status.STATE_EDIT)]
  44. [Tofly.Core.Stereotype.Component(IsSingleton = "false", Name = "Tofly.DataEditUI.FeatureBackSaveCommand")]
  45. public class FeatureBackSaveCommand : GISPluginButtonBase
  46. {
  47. /// <summary>
  48. ///
  49. /// </summary>
  50. private IMap _cmap;
  51. /// <summary>
  52. ///
  53. /// </summary>
  54. private Dictionary<IFeatureLayer, List<IFeature>> _dicEditableFeatures;
  55. /// <summary>
  56. /// 管网图层集合
  57. /// </summary>
  58. private List<IFeatureLayer> _lstEditableGWLayer = new List<IFeatureLayer>();
  59. /// <summary>
  60. ///
  61. /// </summary>
  62. private IFormBackSaveEquipment _frmBackSave;
  63. public override void Create(IPluginContent content)
  64. {
  65. base.Create(content);
  66. this.Enable = false;
  67. this.content.ServiceLocator.ServiceValueChange += ServiceLocator_ServiceValueChange;
  68. }
  69. public override void Click()
  70. {
  71. try
  72. {
  73. if (this._cmap.SelectionCount == 0 || this._frmBackSave != null)
  74. {
  75. return;
  76. }
  77. if (this._dicEditableFeatures == null || this._dicEditableFeatures.Count == 0)
  78. {
  79. throw new System.Exception("无有效可编辑要素.");
  80. }
  81. List<IFeatureLayer> __lstLayerSelected = this._dicEditableFeatures.Keys.ToList();
  82. if (__lstLayerSelected.Count > 1) //多图层选择时
  83. {
  84. __lstLayerSelected.Clear(); //清除
  85. IFormSelectMultiEditLayer __frmSelMutiLayer = ContextRegistry.GetContext().GetObject("Tofly.DataEditUI.Win.FormSelectMultiEditLayer") as IFormSelectMultiEditLayer;
  86. __frmSelMutiLayer.EditingLayerFeatures = this._dicEditableFeatures;
  87. __frmSelMutiLayer.LoadSelectableLayers(this._dicEditableFeatures.Keys.ToList());
  88. if (__frmSelMutiLayer.ShowDialog(this.content.PluginMainForm) == DialogResult.OK)
  89. {
  90. __lstLayerSelected = __frmSelMutiLayer.SelectedLayers; //更新选择的用于属性自动化的图层集合
  91. }
  92. __frmSelMutiLayer.Dispose();
  93. __frmSelMutiLayer = null;
  94. }
  95. if (__lstLayerSelected.Count > 0)
  96. {
  97. var __dicSelFeaturesByLayer = (from __kvLayerFeature in this._dicEditableFeatures
  98. where __lstLayerSelected.Contains(__kvLayerFeature.Key)
  99. select __kvLayerFeature).ToDictionary(kvItem => kvItem.Key, kvItem => kvItem.Value);
  100. this._frmBackSave = ContextRegistry.GetContext().GetObject("Tofly.DataEditUI.Win.FormBackSaveEquipment", new object[1] { __dicSelFeaturesByLayer }) as IFormBackSaveEquipment;
  101. this._frmBackSave.CMap = this._cmap; //设置变量
  102. this._frmBackSave.Content = this.content;
  103. this._frmBackSave.FormClosedEvent += this.FromBackSave_FormClosed;
  104. this._frmBackSave.ShowDialog(this.content.PluginMainForm);
  105. //this._hhHookHelper.Map.ClearSelection();
  106. this._cmap.ActiveView.PartialRefresh(ViewDrawPhase.ViewGeography | ViewDrawPhase.ViewGeoSelection, null, this._cmap.Extent);
  107. var __docContent = content.ServiceLocator.GetInstance<IDocumentContent>(ServiceLocatorKeys.DocumentContent);
  108. IActiveView __viewSelction = __docContent.ActiveViewContent.ActiveView; //广播地图选择集变化的视图对象
  109. __viewSelction.PartialRefresh(ViewDrawPhase.ViewGeoSelection, null, __viewSelction.Extent);
  110. }
  111. }
  112. catch (System.Exception ex)
  113. {
  114. MessageManager.Show("属性处理错误: " + ex.Message, "属性自动化");
  115. }
  116. }
  117. /// <summary>
  118. ///
  119. /// </summary>
  120. /// <param name="key"></param>
  121. /// <param name="value"></param>
  122. protected void ServiceLocator_ServiceValueChange(string key, object value)
  123. {
  124. if (key.Equals(ServiceLocatorKeys.IsMapEdit))
  125. {
  126. this._lstEditableGWLayer.Clear(); //重置管网要素图层集合
  127. this.ActiveViewContent_ActiveViewSelectionChanged(null);
  128. }
  129. else if (key.Equals(ServiceLocatorKeys.DocumentContent))
  130. {
  131. this._cmap = (this.content.ServiceLocator.GetInstance<IControl>(ServiceLocatorKeys.MapControl) as IMapControl).Map;
  132. var documentcontent = content.ServiceLocator.GetInstance<IDocumentContent>(ServiceLocatorKeys.DocumentContent);
  133. documentcontent.ActiveViewContent.ActiveViewSelectionChanged -= ActiveViewContent_ActiveViewSelectionChanged;
  134. documentcontent.ActiveViewContent.ActiveViewSelectionChanged += ActiveViewContent_ActiveViewSelectionChanged;
  135. }
  136. }
  137. protected void ActiveViewContent_ActiveViewSelectionChanged(ActiveViewSelectionChangedEventArgs e)
  138. {
  139. this.Enable = false;
  140. this._dicEditableFeatures = null;
  141. if (content.ServiceLocator.GetInstance<bool>(ServiceLocatorKeys.IsMapEdit))
  142. {
  143. if (this._cmap.SelectionCount > 0)
  144. {
  145. if (this._lstEditableGWLayer.Count == 0)
  146. {
  147. this._lstEditableGWLayer.AddRange(FeatureLayerHelper.GetFeatureLayersByDataset(this._cmap, AppConfig.GWDatasetName));
  148. this._lstEditableGWLayer.RemoveAll(flayer => flayer.FeatureClass.Workspace.IsBeingEdited() == false); //移除非编辑图层
  149. }
  150. this._dicEditableFeatures = MapSelectionHelper.GetSelectedFeaturesByLayer(this._cmap, this._lstEditableGWLayer, true);
  151. this.Enable = (this._dicEditableFeatures.Count > 0); //分离出可编辑要素集合
  152. }
  153. }
  154. }
  155. private void FromBackSave_FormClosed(object sender)
  156. {
  157. if (this._frmBackSave != null)
  158. {
  159. this._frmBackSave.Dispose();
  160. }
  161. this._frmBackSave = null;
  162. }
  163. }
  164. }