123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using Tofly.Core.Context.Support;
- using Tofly.Core.Context;
- using Tofly.Core.ServiceLocator;
- using Tofly.CoreUI.Plot;
- using Tofly.CoreUI.Control;
- using Tofly.Data.Metadata;
- using Tofly.GIS.Display;
- using Tofly.GISUI.Controls;
- using Tofly.GIS.Geometry;
- using Tofly.GIS.Carto;
- using Tofly.GIS.SpatialDatabase;
- using Tofly.DataEditUI.Properties;
- using Tofly.GISUI.Plugin;
- namespace Tofly.DataEditUI
- {
-
-
-
- [PluginComponentAttribute((long)Core.SysRegist.ModuleKey.Edit, PluginGISType.ArcGIS, GroupName = "编辑", Caption = "属性编辑", Describe = "属性编辑", IsCreate = true, States = Tofly.CoreUI.Control.Status.STATE_EDIT)]
- [Tofly.Core.Stereotype.Component(IsSingleton = "false", Name = "Tofly.DataEditUI.AttributeCommand")]
- public class AttributeCommand : GISPluginCheckBase
- {
- private IAttributeEdit xmlForm;
- private object mainForm;
- private IActiveView ActiveView;
- public AttributeCommand()
- {
- this.Enable = false;
- }
- public override void Click()
- {
- IMapControl pMapControl = content.ServiceLocator.
- GetInstance<IControl>(ServiceLocatorKeys.AxMapControl) as IMapControl;
- if (pMapControl == null)
- return;
- if (pMapControl.CurrentTool != this)
- {
- ActiveView = pMapControl.ActiveView;
- pMapControl.CurrentTool = this;
- }
- }
- public override void Create(IPluginContent content)
- {
- base.Create(content);
- mainForm = content.PluginMainForm;
- base.Cursor = new Cursor(Resources.EDitSelectFeature);
- content.ServiceLocator.ServiceValueChange += ServiceLocator_ServiceValueChange;
- }
- protected virtual void ServiceLocator_ServiceValueChange(string key, object value)
- {
- if (key.Equals(ServiceLocatorKeys.IsMapEdit))
- {
- this.Enable = content.ServiceLocator.GetInstance<bool>(ServiceLocatorKeys.IsMapEdit);
- }
- }
- public override void MouseUp(int iButton, int iShift, int ix, int iy)
- {
- if (iButton == 2)
- return;
- IMapControl pMapControl = content.ServiceLocator.
- GetInstance<IControl>(ServiceLocatorKeys.AxMapControl) as IMapControl;
- if (pMapControl != null)
- ActiveView = pMapControl.ActiveView;
- IPoint m_pPtMove = ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(ix, iy);
- double dBuffer = ConvertPixelsToAVUnits(ActiveView, 2);
- IFeatureLayer editLayer = content.ServiceLocator.
- GetInstance<IFeatureLayer>(ServiceLocatorKeys.NowEditFeatureLayer);
- if (editLayer == null || editLayer.FeatureClass == null)
- return;
- List<IFeature> pFeatures = editLayer.FeatureClass.SpatialSearch(m_pPtMove.Buffer(dBuffer, BufferStyle.Round),
- SpatialRelType.Intersects);
- if (pFeatures == null || pFeatures.Count < 1)
- return;
- IFeature pFeature = pFeatures[0];
- Cursor pCursor = base.Cursor;
- pMapControl.Map.ActiveView.PartialRefresh(ViewDrawPhase.ViewGeoSelection, null, null);
- base.Cursor = new Cursor(CurrsorType.WaitCursor);
- pMapControl.Map.ClearSelection();
- pMapControl.Map.SelectFeature(editLayer, pFeature);
- base.Cursor = pCursor;
- pMapControl.Map.ActiveView.PartialRefresh(ViewDrawPhase.ViewGeoSelection, null, null);
- if (xmlForm == null)
- {
- IApplicationContext pContext = ContextRegistry.GetContext();
- xmlForm = pContext.GetObject("Tofly.DataEditUI.Win.AttributeEdit") as IAttributeEdit;
- xmlForm.CurrentTable = editLayer.FeatureClass;
- xmlForm.DataSource = null;
- xmlForm.DataSource = pFeature;
- xmlForm.ClosingEvent += xmlForm_ClosingEvent;
- xmlForm.FormClosedEvent += xmlForm_FormClosedEvent;
- xmlForm.Show(mainForm);
- }
- else if (!xmlForm.Visible)
- {
- xmlForm.CurrentTable = editLayer.FeatureClass;
- xmlForm.DataSource = pFeature;
- xmlForm.Show(mainForm);
- }
- else
- {
- xmlForm.CurrentTable = editLayer.FeatureClass;
- xmlForm.DataSource = pFeature;
- }
- }
- void xmlForm_ClosingEvent(object sender, System.ComponentModel.CancelEventArgs e)
- {
- xmlForm.CloseEdit();
- }
- void xmlForm_FormClosedEvent(object sender)
- {
- if (xmlForm != null)
- xmlForm = null;
- IMapControl pMapControl = content.ServiceLocator.
- GetInstance<IControl>(ServiceLocatorKeys.AxMapControl) as IMapControl;
- if (pMapControl != null)
- pMapControl.Map.ActiveView.PartialRefresh(ViewDrawPhase.ViewGeoSelection, null, null);
- }
-
-
-
-
-
-
- private double ConvertPixelsToAVUnits(IActiveView pAv, long lTolerance)
- {
- if (pAv == null) return 5;
- IDisplayTransformation pTransformation;
- IScreenDisplay pScreenDisplay = pAv.ScreenDisplay;
- pTransformation = pScreenDisplay.DisplayTransformation;
- WKSPoint pOutPoint;
- TagPOINT pInPoint;
- pOutPoint.X = 0;
- pOutPoint.Y = 0;
- pInPoint.x = (int)lTolerance;
- pInPoint.y = (int)lTolerance;
- pTransformation.TransformCoords(ref pOutPoint, ref pInPoint, 1, 6);
- return pOutPoint.X;
- }
- }
- }
|