You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
234 lines
7.2 KiB
234 lines
7.2 KiB
using System; |
|
using System.Diagnostics; |
|
using System.Drawing; |
|
using System.Runtime.InteropServices; |
|
using System.Windows.Forms; |
|
using ESRI.ArcGIS.ADF.CATIDs; |
|
using ESRI.ArcGIS.Carto; |
|
using ESRI.ArcGIS.Controls; |
|
using ESRI.ArcGIS.Display; |
|
using ESRI.ArcGIS.Geometry; |
|
using KGIS.Framework.Utils.Enum; |
|
|
|
namespace Kingo.Plugin.ResultsOfProof |
|
{ |
|
public class CustomDrawTool : BaseToolCommand |
|
{ |
|
public override enumProductType AttachProductType |
|
{ |
|
get { return enumProductType.KDB | enumProductType.KAP; } |
|
} |
|
private IHookHelper m_hookHelper; |
|
private DrawParams m_pDrawParams; |
|
private ISimpleFillSymbol m_pFillSymbol; |
|
private IGeometry m_pGeom; |
|
|
|
public event DoContinueEventHandler DoContinue; |
|
|
|
public CustomDrawTool(DrawParams pDrawParams) |
|
{ |
|
this.m_pGeom = null; |
|
base.m_category = ""; |
|
base.m_caption = ""; |
|
base.m_message = ""; |
|
base.m_toolTip = ""; |
|
base.m_name = "画多边形"; |
|
try |
|
{ |
|
string resource = base.GetType().Name + ".bmp"; |
|
//base.m_cursor = new Cursor(base.GetType(), base.GetType().Name + ".cur"); |
|
//base.m_bitmap = new Bitmap(base.GetType(), resource); |
|
} |
|
catch (Exception exception) |
|
{ |
|
Trace.WriteLine(exception.Message, "Invalid Bitmap"); |
|
} |
|
this.m_pDrawParams = pDrawParams; |
|
} |
|
|
|
private void AddElement(IActiveView pActiveView, ISimpleFillSymbol pSimpleFillSymbol) |
|
{ |
|
m_pGeom = null; |
|
IRubberBand band = new RubberRectangularPolygonClass(); |
|
if (m_pDrawParams.enumDrawMode == EnumDrawMode.DrawPolygon) |
|
{ |
|
band = new RubberPolygonClass(); // 多边型 |
|
} |
|
|
|
IPolygon polygon = (IPolygon)band.TrackNew(pActiveView.ScreenDisplay, null); |
|
if (this.m_pDrawParams.bCreateTrail) |
|
{ |
|
IFillShapeElement element = new PolygonElementClass(); |
|
IElement pElement = (IElement)element; |
|
if (pSimpleFillSymbol == null) |
|
{ |
|
pSimpleFillSymbol = (ISimpleFillSymbol)Symbol.CreateDefaultSymbol(EnumSymbolType.SimpleFillSymbol); |
|
} |
|
element.Symbol = pSimpleFillSymbol; |
|
pElement.Geometry = polygon; |
|
Element.DrawElement(pElement, pActiveView); |
|
} |
|
this.m_pGeom = polygon; |
|
} |
|
|
|
private static void ArcGISCategoryRegistration(System.Type registerType) |
|
{ |
|
ControlsCommands.Register(string.Format(@"HKEY_CLASSES_ROOT\CLSID\{{{0}}}", registerType.GUID)); |
|
} |
|
|
|
private static void ArcGISCategoryUnregistration(System.Type registerType) |
|
{ |
|
ControlsCommands.Unregister(string.Format(@"HKEY_CLASSES_ROOT\CLSID\{{{0}}}", registerType.GUID)); |
|
} |
|
|
|
public override void OnClick() |
|
{ |
|
} |
|
|
|
public override void OnCreate(object hook) |
|
{ |
|
if (this.m_hookHelper == null) |
|
{ |
|
this.m_hookHelper = new HookHelperClass(); |
|
} |
|
this.m_hookHelper.Hook = hook; |
|
} |
|
|
|
public override void OnMouseDown(int Button, int Shift, int X, int Y) |
|
{ |
|
IMapControl2 hook = (IMapControl2)this.m_hookHelper.Hook; |
|
if (this.m_pDrawParams.bClearOtherElement) |
|
{ |
|
hook.ActiveView.GraphicsContainer.DeleteAllElements(); |
|
} |
|
if (Button <= 2) |
|
{ |
|
this.AddElement(hook.ActiveView, this.m_pDrawParams.pSymbol as ISimpleFillSymbol); |
|
this.DoContinue(this.m_pGeom); |
|
} |
|
else |
|
{ |
|
//Bug-15932 霍岩 2019-05-27 但点击鼠标滚轮时启动漫游工具 |
|
this.CurrentTool = new ControlsMapPanToolClass(); |
|
} |
|
} |
|
|
|
public override void OnMouseMove(int Button, int Shift, int X, int Y) |
|
{ |
|
} |
|
|
|
public override void OnMouseUp(int Button, int Shift, int X, int Y) |
|
{ |
|
} |
|
|
|
|
|
[ComRegisterFunction, ComVisible(false)] |
|
private static void RegisterFunction(System.Type registerType) |
|
{ |
|
ArcGISCategoryRegistration(registerType); |
|
} |
|
|
|
[ComUnregisterFunction, ComVisible(false)] |
|
private static void UnregisterFunction(System.Type registerType) |
|
{ |
|
ArcGISCategoryUnregistration(registerType); |
|
} |
|
|
|
public IGeometry ReturnGeom |
|
{ |
|
get |
|
{ |
|
return this.m_pGeom; |
|
} |
|
} |
|
|
|
public delegate void DoContinueEventHandler(IGeometry pGeo); |
|
} |
|
|
|
public struct DrawParams |
|
{ |
|
public EnumDrawMode enumDrawMode; |
|
public bool bCreateTrail; |
|
public bool bClearOtherElement; |
|
public ISymbol pSymbol; |
|
} |
|
public enum EnumDrawMode |
|
{ |
|
DrawPoint, |
|
DrawLine, |
|
DrawRect, |
|
DrawPolygon, |
|
DrawCircle, |
|
DrawEllipse |
|
} |
|
|
|
public class Symbol |
|
{ |
|
public static ISymbol CreateDefaultSymbol(EnumSymbolType pSymbolType) |
|
{ |
|
ISymbol symbol = null; |
|
IRgbColor color = new RgbColorClass(); |
|
color = GetRGBColor(0xff, 0, 0); |
|
switch (pSymbolType) |
|
{ |
|
case EnumSymbolType.SimpleMarkerSymbol: |
|
return symbol; |
|
|
|
case EnumSymbolType.SimpleLineSymbol: |
|
{ |
|
ISimpleLineSymbol symbol2 = new SimpleLineSymbolClass(); |
|
symbol2.Color = color; |
|
symbol2.Width = 1.5; |
|
return (ISymbol)symbol2; |
|
} |
|
case EnumSymbolType.SimpleFillSymbol: |
|
{ |
|
ISimpleFillSymbol symbol3 = new SimpleFillSymbolClass(); |
|
symbol3.Outline.Color = color; |
|
symbol3.Color = color; |
|
symbol3.Style = esriSimpleFillStyle.esriSFSDiagonalCross; |
|
return (ISymbol)symbol3; |
|
} |
|
} |
|
return symbol; |
|
} |
|
|
|
|
|
public static IRgbColor GetRGBColor(int pRed, int pGreen, int pBlue) |
|
{ |
|
try |
|
{ |
|
IRgbColor color = new RgbColorClass(); |
|
color.Red = pRed; |
|
color.Green = pGreen; |
|
color.Blue = pBlue; |
|
return color; |
|
} |
|
catch |
|
{ |
|
return null; |
|
} |
|
} |
|
} |
|
public enum EnumSymbolType |
|
{ |
|
SimpleMarkerSymbol, |
|
SimpleLineSymbol, |
|
SimpleFillSymbol, |
|
FormattedTextSymbol |
|
} |
|
public class Element |
|
{ |
|
public static void DrawElement(IElement pElement, IActiveView pActiveView) |
|
{ |
|
try |
|
{ |
|
((IGraphicsContainer)pActiveView).AddElement(pElement, 0); |
|
pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); |
|
} |
|
catch |
|
{ |
|
} |
|
} |
|
} |
|
}
|
|
|