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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
| Option Explicit
Implements ICommand
Implements ITool
Private m_pApp As IApplication
Private m_pActiveView As IActiveView
Private m_pDispTrans As IDisplayTransformation
Private m_pDispFeedback As IDisplayFeedback
Private m_pNewLineFeedback As INewLineFeedback
Private m_pTinFeatureEdit As ITinFeatureEdit
Private m_pLinePC As IPointCollection
Private m_bFeedback_Start As Boolean
Private m_lCursor As Long
Private Sub FreeVariables()
Set m_pActiveView = Nothing
Set m_pDispTrans = Nothing
Set m_pDispFeedback = Nothing
Set m_pNewLineFeedback = Nothing
Set m_pTinFeatureEdit = Nothing
Set m_pLinePC = Nothing
End Sub
Private Sub Class_Terminate()
FreeVariables
Set m_pApp = Nothing
End Sub
Private Property Get ICommand_Bitmap() As esrisystem.OLE_HANDLE
ICommand_Bitmap = frmDigitizeTinLine.Command1.Picture
End Property
Private Property Get ICommand_Caption() As String
ICommand_Caption = "Digitize TIN Line Tool"
End Property
Private Property Get ICommand_Category() As String
ICommand_Category = "3D TIN Editing Samples"
End Property
Private Property Get ICommand_Checked() As Boolean
End Property
Private Property Get ICommand_Enabled() As Boolean
On Error GoTo EH
Dim pSurf As ISurface
Set pSurf = miscUtil.GetCurrentSurface(m_pApp)
If (Not pSurf Is Nothing) Then
If (TypeOf pSurf Is ITinEdit) Then
Dim pTE As ITinEdit
Set pTE = pSurf
If (pTE.IsInEditMode) Then
ICommand_Enabled = True
Exit Property
End If
End If
End If
' In case user clicks command to stop editing while this tool is active
If (frmDigitizeTinLine.Visible = True) Then
frmDigitizeTinLine.Hide
End If
ICommand_Enabled = False
Exit Property
EH:
ICommand_Enabled = False
End Property
Private Property Get ICommand_HelpContextID() As Long
End Property
Private Property Get ICommand_HelpFile() As String
End Property
Private Property Get ICommand_Message() As String
ICommand_Message = "Adds a line to a TIN"
End Property
Private Property Get ICommand_Name() As String
ICommand_Name = "SurfaceAnalysisDigitizeTinLine"
End Property
Private Sub ICommand_OnClick()
Dim pMxDoc As IMxDocument
Set pMxDoc = m_pApp.Document
Set m_pActiveView = pMxDoc.ActiveView
Set m_pDispTrans = m_pActiveView.ScreenDisplay.DisplayTransformation
m_bFeedback_Start = False
Set m_pTinFeatureEdit = miscUtil.GetCurrentSurface(m_pApp)
Set m_pLinePC = New Polyline
m_lCursor = frmDigitizeTinLine.cmdCross.MouseIcon
frmDigitizeTinLine.Init miscUtil.GetCurrentSurface(m_pApp)
Dim lRes As Long
lRes = ShowWindow(frmDigitizeTinLine.hwnd, SW_SHOWNORMAL)
End Sub
Private Sub ICommand_OnCreate(ByVal hook As Object)
Set m_pApp = hook
End Sub
Private Property Get ICommand_Tooltip() As String
ICommand_Tooltip = "Add TIN Line"
End Property
Private Property Get ITool_Cursor() As esrisystem.OLE_HANDLE
ITool_Cursor = m_lCursor
End Property
Private Function ITool_Deactivate() As Boolean
frmDigitizeTinLine.Hide
FreeVariables
ITool_Deactivate = True
End Function
Private Function ITool_OnContextMenu(ByVal X As Long, ByVal Y As Long) As Boolean
End Function
Private Sub ITool_OnDblClick()
On Error GoTo EH:
Dim pPolyline As IPolyline
Set pPolyline = m_pNewLineFeedback.Stop
Set pPolyline.SpatialReference = m_pActiveView.FocusMap.SpatialReference
m_bFeedback_Start = False
If (Not pPolyline Is Nothing) Then
Dim pLayer As ILayer
Set pLayer = miscUtil.GetCurrentSurfaceLayer(m_pApp)
Dim bTOCModified As Boolean
bTOCModified = False
Dim pSurf As ISurface
Set pSurf = m_pTinFeatureEdit
Dim pTinEdit As ITinEdit
Set pTinEdit = pSurf
Dim lSFType As esriTinSurfaceType
lSFType = frmDigitizeTinLine.GetSFType
Dim lZSource As Long
lZSource = frmDigitizeTinLine.GetHeightSource
Select Case lZSource
Case 1
pTinEdit.AddShape pPolyline, lSFType, 0
Case 2
Dim pPolyZ As IPolyline
pSurf.InterpolateShape pPolyline, pPolyZ
Dim pEnv As IEnvelope
Set pEnv = pPolyZ.Envelope
pTinEdit.AddShape pPolyline, lSFType, 0, pEnv.zmax
Case 3
pSurf.InterpolateShape pPolyline, pPolyZ
Set pEnv = pPolyZ.Envelope
pTinEdit.AddShape pPolyline, lSFType, 0, pEnv.zmin
Case 4
Dim dZ As Double
dZ = frmDigitizeTinLine.GetHeight
pTinEdit.AddShape pPolyline, lSFType, 0, dZ
If (tinUtil.FindTinRenderer(pLayer, "Elevation") <> -1) Then
bTOCModified = tinUtil.CheckTinLegendZRange(pLayer, dZ)
End If
End Select
If (tinUtil.FindTinRenderer(pLayer, "Edge types") = -1) Then
tinUtil.AddTinRenderer pLayer, "TinBreaklineRenderer", "Edge types"
bTOCModified = True
End If
If (bTOCModified) Then
If (TypeOf m_pApp Is IMxApplication) Then
Dim pMxDoc As IMxDocument
Set pMxDoc = m_pApp.Document
pMxDoc.CurrentContentsView.Refresh 0 ' 0 seems to work for any position of layer in toc
End If
End If
If (TypeOf m_pApp Is IMxApplication) Then
Dim pDoc As IMxDocument
Set pDoc = m_pApp.Document
pDoc.ActiveView.Refresh
'pActiveView.PartialRefresh esriDPGeography, pLayer, pActiveView.Extent
End If
End If
Exit Sub
EH:
MsgBox "Error on DblClick: " & Err.Description
End Sub
Private Sub ITool_OnKeyDown(ByVal keyCode As Long, ByVal Shift As Long)
End Sub
Private Sub ITool_OnKeyUp(ByVal keyCode As Long, ByVal Shift As Long)
End Sub
Private Sub ITool_OnMouseDown(ByVal Button As Long, ByVal Shift As Long, ByVal X As Long, ByVal Y As Long)
Dim pPnt As IPoint
Set pPnt = m_pDispTrans.ToMapPoint(X, Y)
If (frmDigitizeTinLine.chkSnap.Value = vbChecked) Then
Dim pTin As ITinAdvanced
Set pTin = m_pTinFeatureEdit
Dim pNode As ITinNode
Set pNode = New TinNode
Dim dDist As Double
pTin.QueryNearestNode pPnt, pNode, dDist
If (dDist < CDbl(frmDigitizeTinLine.txtSnap)) Then
pNode.QueryAsPoint pPnt
End If
End If
If (Button = 1) Then ' add another point
If (Not m_bFeedback_Start) Then
Set m_pNewLineFeedback = New NewLineFeedback
Set m_pDispFeedback = m_pNewLineFeedback
Set m_pDispFeedback.Display = m_pActiveView.ScreenDisplay
m_pNewLineFeedback.Start pPnt
m_pLinePC.AddPoint pPnt
m_bFeedback_Start = True
Else
m_pNewLineFeedback.AddPoint pPnt
m_pLinePC.AddPoint pPnt
End If
End If
End Sub
Private Sub ITool_OnMouseMove(ByVal Button As Long, ByVal Shift As Long, ByVal X As Long, ByVal Y As Long)
If (m_bFeedback_Start) Then
Dim pPnt As IPoint
Set pPnt = m_pDispTrans.ToMapPoint(X, Y)
m_pDispFeedback.MoveTo pPnt
If (frmDigitizeTinLine.DetectConflicts) Then
If (Not m_pTinFeatureEdit.CanAddVertex(m_pLinePC, pPnt, False, 0)) Then
m_lCursor = frmDigitizeTinLine.cmdNo.MouseIcon
Else
m_lCursor = frmDigitizeTinLine.cmdCross.MouseIcon
End If
Else
m_lCursor = frmDigitizeTinLine.cmdCross.MouseIcon
End If
End If
End Sub
Private Sub ITool_OnMouseUp(ByVal Button As Long, ByVal Shift As Long, ByVal X As Long, ByVal Y As Long)
End Sub
Private Sub ITool_Refresh(ByVal hDC As esrisystem.OLE_HANDLE)
End Sub |