AttributeCommand.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Tofly.Core.Context.Support;
  5. using Tofly.Core.Context;
  6. using Tofly.Core.ServiceLocator;
  7. using Tofly.CoreUI.Plot;
  8. using Tofly.CoreUI.Control;
  9. using Tofly.Data.Metadata;
  10. using Tofly.GIS.Display;
  11. using Tofly.GISUI.Controls;
  12. using Tofly.GIS.Geometry;
  13. using Tofly.GIS.Carto;
  14. using Tofly.GIS.SpatialDatabase;
  15. using Tofly.DataEditUI.Properties;
  16. using Tofly.GISUI.Plugin;
  17. namespace Tofly.DataEditUI
  18. {
  19. /// <summary>
  20. /// 属性编辑
  21. /// </summary>
  22. [PluginComponentAttribute((long)Core.SysRegist.ModuleKey.Edit, PluginGISType.ArcGIS, GroupName = "编辑", Caption = "属性编辑", Describe = "属性编辑", IsCreate = true, States = Tofly.CoreUI.Control.Status.STATE_EDIT)]
  23. [Tofly.Core.Stereotype.Component(IsSingleton = "false", Name = "Tofly.DataEditUI.AttributeCommand")]
  24. public class AttributeCommand : GISPluginCheckBase
  25. {
  26. private IAttributeEdit xmlForm;
  27. private object mainForm;
  28. private IActiveView ActiveView;
  29. public AttributeCommand()
  30. {
  31. this.Enable = false;
  32. }
  33. public override void Click()
  34. {
  35. IMapControl pMapControl = content.ServiceLocator.
  36. GetInstance<IControl>(ServiceLocatorKeys.AxMapControl) as IMapControl;
  37. if (pMapControl == null)
  38. return;
  39. if (pMapControl.CurrentTool != this)
  40. {
  41. ActiveView = pMapControl.ActiveView;
  42. pMapControl.CurrentTool = this;
  43. }
  44. }
  45. public override void Create(IPluginContent content)
  46. {
  47. base.Create(content);
  48. mainForm = content.PluginMainForm;
  49. base.Cursor = new Cursor(Resources.EDitSelectFeature);
  50. content.ServiceLocator.ServiceValueChange += ServiceLocator_ServiceValueChange;
  51. }
  52. protected virtual void ServiceLocator_ServiceValueChange(string key, object value)
  53. {
  54. if (key.Equals(ServiceLocatorKeys.IsMapEdit))
  55. {
  56. this.Enable = content.ServiceLocator.GetInstance<bool>(ServiceLocatorKeys.IsMapEdit);
  57. }
  58. }
  59. public override void MouseUp(int iButton, int iShift, int ix, int iy)
  60. {
  61. if (iButton == 2)
  62. return;
  63. IMapControl pMapControl = content.ServiceLocator.
  64. GetInstance<IControl>(ServiceLocatorKeys.AxMapControl) as IMapControl;
  65. if (pMapControl != null)
  66. ActiveView = pMapControl.ActiveView;
  67. IPoint m_pPtMove = ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(ix, iy);
  68. double dBuffer = ConvertPixelsToAVUnits(ActiveView, 2);
  69. IFeatureLayer editLayer = content.ServiceLocator.
  70. GetInstance<IFeatureLayer>(ServiceLocatorKeys.NowEditFeatureLayer);
  71. if (editLayer == null || editLayer.FeatureClass == null)
  72. return;
  73. List<IFeature> pFeatures = editLayer.FeatureClass.SpatialSearch(m_pPtMove.Buffer(dBuffer, BufferStyle.Round),
  74. SpatialRelType.Intersects);
  75. if (pFeatures == null || pFeatures.Count < 1)
  76. return;
  77. IFeature pFeature = pFeatures[0];
  78. Cursor pCursor = base.Cursor;
  79. pMapControl.Map.ActiveView.PartialRefresh(ViewDrawPhase.ViewGeoSelection, null, null);
  80. base.Cursor = new Cursor(CurrsorType.WaitCursor);
  81. pMapControl.Map.ClearSelection();
  82. pMapControl.Map.SelectFeature(editLayer, pFeature);
  83. base.Cursor = pCursor;
  84. pMapControl.Map.ActiveView.PartialRefresh(ViewDrawPhase.ViewGeoSelection, null, null);
  85. if (xmlForm == null)
  86. {
  87. IApplicationContext pContext = ContextRegistry.GetContext();
  88. xmlForm = pContext.GetObject("Tofly.DataEditUI.Win.AttributeEdit") as IAttributeEdit;
  89. xmlForm.CurrentTable = editLayer.FeatureClass;
  90. xmlForm.DataSource = null;
  91. xmlForm.DataSource = pFeature;
  92. xmlForm.ClosingEvent += xmlForm_ClosingEvent;
  93. xmlForm.FormClosedEvent += xmlForm_FormClosedEvent;
  94. xmlForm.Show(mainForm);
  95. }
  96. else if (!xmlForm.Visible)
  97. {
  98. xmlForm.CurrentTable = editLayer.FeatureClass;
  99. xmlForm.DataSource = pFeature;
  100. xmlForm.Show(mainForm);
  101. }
  102. else
  103. {
  104. xmlForm.CurrentTable = editLayer.FeatureClass;
  105. xmlForm.DataSource = pFeature;
  106. }
  107. }
  108. void xmlForm_ClosingEvent(object sender, System.ComponentModel.CancelEventArgs e)
  109. {
  110. xmlForm.CloseEdit();
  111. }
  112. void xmlForm_FormClosedEvent(object sender)
  113. {
  114. if (xmlForm != null)
  115. xmlForm = null;
  116. IMapControl pMapControl = content.ServiceLocator.
  117. GetInstance<IControl>(ServiceLocatorKeys.AxMapControl) as IMapControl;
  118. if (pMapControl != null)
  119. pMapControl.Map.ActiveView.PartialRefresh(ViewDrawPhase.ViewGeoSelection, null, null);
  120. }
  121. /// <summary>
  122. /// 将像素容差转换成实际坐标容差
  123. /// </summary>
  124. /// <param name="pAv"></param>
  125. /// <param name="lTolerance"></param>
  126. /// <returns></returns>
  127. private double ConvertPixelsToAVUnits(IActiveView pAv, long lTolerance)
  128. {
  129. if (pAv == null) return 5;
  130. IDisplayTransformation pTransformation;
  131. IScreenDisplay pScreenDisplay = pAv.ScreenDisplay;
  132. pTransformation = pScreenDisplay.DisplayTransformation;
  133. WKSPoint pOutPoint;
  134. TagPOINT pInPoint;
  135. pOutPoint.X = 0;
  136. pOutPoint.Y = 0;
  137. pInPoint.x = (int)lTolerance;
  138. pInPoint.y = (int)lTolerance;
  139. pTransformation.TransformCoords(ref pOutPoint, ref pInPoint, 1, 6);
  140. return pOutPoint.X;
  141. }
  142. }
  143. }