-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAddNetStopsTool.cs
More file actions
227 lines (199 loc) · 7.95 KB
/
AddNetStopsTool.cs
File metadata and controls
227 lines (199 loc) · 7.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.Controls;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
namespace ArcEngine
{
/// <summary>
/// Summary description for AddNetStopsTool.
/// </summary>
[Guid("e75632d7-6346-49c4-83bb-d0f55cb8a4f0")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("ArcEngine.AddNetStopsTool")]
public sealed class AddNetStopsTool : BaseTool
{
#region COM Registration Function(s)
[ComRegisterFunction()]
[ComVisible(false)]
static void RegisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryRegistration(registerType);
//
// TODO: Add any COM registration code here
//
}
[ComUnregisterFunction()]
[ComVisible(false)]
static void UnregisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryUnregistration(registerType);
//
// TODO: Add any COM unregistration code here
//
}
#region ArcGIS Component Category Registrar generated code
/// <summary>
/// Required method for ArcGIS Component Category registration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryRegistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
MxCommands.Register(regKey);
ControlsCommands.Register(regKey);
}
/// <summary>
/// Required method for ArcGIS Component Category unregistration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryUnregistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
MxCommands.Unregister(regKey);
ControlsCommands.Unregister(regKey);
}
#endregion
#endregion
private IHookHelper m_hookHelper = null;
private IFeatureWorkspace pFWorkspace;
private IFeatureClass inputFClass;
//private string path = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
public AddNetStopsTool(string name)
{
//
// TODO: Define values for the public properties
//
base.m_category = "AddNetStopsTool"; //localizable text
base.m_caption = "Add Stop"; //localizable text
base.m_message = "Mouse click on the Map"; //localizable text
base.m_toolTip = "AddStop"; //localizable text
base.m_name = "AddStop"; //unique id, non-localizable (e.g. "MyCategory_MyTool")
_name = name;
try
{
//
// TODO: change resource name if necessary
//
string bitmapResourceName = GetType().Name + ".bmp";
base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);
base.m_cursor = new System.Windows.Forms.Cursor(GetType(), GetType().Name + ".cur");
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
}
}
#region Overridden Class Methods
/// <summary>
/// Occurs when this tool is created
/// </summary>
/// <param name="hook">Instance of the application</param>
public override void OnCreate(object hook)
{
try
{
m_hookHelper = new HookHelperClass();
m_hookHelper.Hook = hook;
if (m_hookHelper.ActiveView == null)
{
m_hookHelper = null;
}
}
catch
{
m_hookHelper = null;
}
if (m_hookHelper == null)
base.m_enabled = false;
else
base.m_enabled = true;
// TODO: Add other initialization code
}
/// <summary>
/// Occurs when this tool is clicked
/// </summary>
private string _name;
public override void OnClick()
{
// TODO: Add AddNetStopsTool.OnClick implementation
//string name = NetWorkAnalysClass.getPath(path) + "\\data\\HuanbaoGeodatabase.gdb";
pFWorkspace = NetWorkAnalysClass.OpenWorkspace(_name) as IFeatureWorkspace;
inputFClass = pFWorkspace.OpenFeatureClass("Stops");
if (inputFClass.FeatureCount(null) > 0)
{
ITable pTable = inputFClass as ITable;
pTable.DeleteSearchedRows(null);
}
}
public override void OnMouseDown(int Button, int Shift, int X, int Y)
{
// TODO: Add AddNetStopsTool.OnMouseDown implementation
try
{
//IPoint pStopsPoint = new PointClass();
var pStopsPoint = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
IFeature newPointFeature = inputFClass.CreateFeature();
try
{
pStopsPoint.Z = 0;
newPointFeature.Shape = pStopsPoint;
IZAware pZAware = pStopsPoint as IZAware;
IMAware pMAware = pStopsPoint as IMAware;
pZAware.ZAware = true;
pMAware.MAware = true;
}
catch
{
IGeometry pGeo = pStopsPoint as IGeometry;
IZAware pZAware = pGeo as IZAware;
pZAware.ZAware = false;
newPointFeature.Shape = pGeo;
}
newPointFeature.Store();
IGraphicsContainer pGrap = m_hookHelper.ActiveView as IGraphicsContainer;
IColor pColor;
IRgbColor pRgbColor = new RgbColorClass();
pRgbColor.Red = 255;
pRgbColor.Green = 255;
pRgbColor.Blue = 255;
pColor = pRgbColor as IColor;
IPictureMarkerSymbol pms = new PictureMarkerSymbolClass();
pms.BitmapTransparencyColor = pColor;
string picturePath = "..\\..\\..\\Img\\stops.bmp";
//添加自定义站点图片
pms.CreateMarkerSymbolFromFile(esriIPictureType.esriIPictureBitmap, picturePath);
pms.Size = 18;
IMarkerElement pMarkerEle = new MarkerElementClass();
pMarkerEle.Symbol = pms as IMarkerSymbol;
pStopsPoint.SpatialReference = m_hookHelper.ActiveView.FocusMap.SpatialReference;
IElement pEle = pMarkerEle as IElement;
pEle.Geometry = pStopsPoint;
pGrap.AddElement(pEle, 1);
m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
catch
{
MessageBox.Show("添加站点失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
public override void OnMouseMove(int Button, int Shift, int X, int Y)
{
// TODO: Add AddNetStopsTool.OnMouseMove implementation
}
public override void OnMouseUp(int Button, int Shift, int X, int Y)
{
// TODO: Add AddNetStopsTool.OnMouseUp implementation
}
#endregion
}
}