Repository navigation
Expand file tree
/
Copy pathForm_VarHandler.vb
More file actions
443 lines (315 loc) · 14.1 KB
/
Copy pathForm_VarHandler.vb
File metadata and controls
443 lines (315 loc) · 14.1 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
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
Imports System.ComponentModel
'Imports System.Net.WebRequestMethods
Imports SolidEdgeFramework
Public Class Form_VarHandler
Dim objApp As SolidEdgeFramework.Application
Public Shared ObjDoc As SolidEdgeFramework.SolidEdgeDocument
Public LengthUnits As SolidEdgeConstants.UnitOfMeasureLengthReadoutConstants
Public Tracker_3D As SolidEdgePart.CoordinateSystem
Public Tracker_2D As SolidEdgeDraft.BlockOccurrence
Public Tracking As Boolean = False
Public Trace As Boolean = False
Private _UpdateDoc As Boolean
Public Property UpdateDoc As Boolean
Get
Return _UpdateDoc
End Get
Set(value As Boolean)
_UpdateDoc = value
If Me.IsHandleCreated Then
BT_UpdateDoc.Checked = value
End If
End Set
End Property
Private _SaveImages As Boolean
Public Property SaveImages As Boolean
Get
Return _SaveImages
End Get
Set(value As Boolean)
_SaveImages = value
If Me.IsHandleCreated Then
BT_SaveImages.Checked = value
End If
End Set
End Property
Private _CheckInterference As Boolean
Public Property CheckInterference As Boolean
Get
Return _CheckInterference
End Get
Set(value As Boolean)
_CheckInterference = value
If Me.IsHandleCreated Then
BT_CheckInterference.Checked = value
End If
End Set
End Property
Private Sub BT_Aggiungi_Click(sender As Object, e As EventArgs) Handles BT_Aggiungi.Click
Dim tmpForm As New Form_SelectVariable With {
.ObjDoc = ObjDoc,
.LengthUnits = LengthUnits
}
tmpForm.ShowDialog(Me)
If tmpForm.Valid Then
For Each item In tmpForm.ListBox_Variables.SelectedItems
'Dim tmpSlider2 As New UC_Slider(item.objVariable, LengthUnits)
'Dim tmpSlider2 As New UC_Slider(item, LengthUnits, ObjDoc) With {
' .UpdateDoc = BT_Update.Checked,
' .SaveImages = BT_SaveImages.Checked,
' .CheckInterference = BT_CheckInterference.Checked
'}
Dim tmpSlider2 As New UC_Slider(item.objVariable, LengthUnits, ObjDoc) With {
.UpdateDoc = Me.UpdateDoc,
.SaveImages = Me.SaveImages,
.CheckInterference = Me.CheckInterference
}
If tmpSlider2.Valid Then
'tmpSlider2.objDoc = objDoc
''tmpSlider2.LengthUnits = LengthUnits
'tmpSlider2.UpdateDoc = BT_Update.Checked
'tmpSlider2.SaveImages = BT_SaveImages.Checked
'tmpSlider2.CheckInterference = BT_CheckInterference.Checked
AddHandler tmpSlider2.LB_value.TextChanged, AddressOf Slider_Click
FLP_Vars.Controls.Add(tmpSlider2)
SetupAnchors()
End If
Next
End If
End Sub
Private Sub Slider_Click(sender As Object, e As EventArgs)
' Fires on every slider's LB_value.TextChanged, so this runs repeatedly
' while dragging any single slider - reuse one UtilsUnits across all of
' them instead of letting each UpdateLabel() call build its own.
Dim UU As New UtilsUnits(ObjDoc)
For Each tmpSlider As Object In FLP_Vars.Controls
tmpSlider.UpdateLabel(UU)
Next
If ObjDoc.Type = DocumentTypeConstants.igAssemblyDocument And Me.UpdateDoc Then ObjDoc.UpdateDocument 'objDoc.Parent.StartCommand(11292)
End Sub
Private Sub SetupAnchors()
FLP_Vars.SuspendLayout()
If FLP_Vars.Controls.Count > 0 Then
For i = 0 To FLP_Vars.Controls.Count - 1
Dim c As Control = FLP_Vars.Controls(i)
If i = 0 Then
' Its the first control, all subsequent controls follow
' the anchor behavior of this control.
c.Width = FLP_Vars.Width - 6
c.Anchor = AnchorStyles.Left + AnchorStyles.Top
If FLP_Vars.VerticalScroll.Visible Then c.Width += -SystemInformation.VerticalScrollBarWidth + 0
Else
' It is not the first control. Set its anchor to
' copy the width of the first control in the list.
c.Anchor = AnchorStyles.Left + AnchorStyles.Right
End If
Next
End If
FLP_Vars.ResumeLayout()
End Sub
Private Sub Form_VarHandler_Resize(sender As Object, e As EventArgs) Handles Me.Resize
SetupAnchors()
End Sub
Private Sub Form_VarHandler_Load(sender As Object, e As EventArgs) Handles Me.Load
'################# Questo risolver il problema del bordo sgrazinato della ToolStrip
ToolStrip1.Renderer = New MySR()
'################# rif: https://stackoverflow.com/questions/1918247/how-to-disable-the-line-under-tool-strip-in-winform-c
Try
objApp = GetObject(, "SolidEdge.Application")
Catch ex As Exception
MsgBox("Solid Edge must be open", MsgBoxStyle.Critical)
End
End Try
Try
ObjDoc = objApp.ActiveDocument
LengthUnits = GetLengthUnits(ObjDoc)
Catch ex As Exception
MsgBox("A Solid Edge Document must be open", MsgBoxStyle.Critical)
End
End Try
Autotune()
Dim UP As New UtilsPreferences
UP.CreatePreferencesDirectory()
UP.GetProgramSettings(Me)
End Sub
Private Sub Autotune()
Dim tmpVars As SolidEdgeFramework.Variables = ObjDoc.Variables
Dim tmpVar = tmpVars.Query("*",, 2)
Dim variables As SolidEdgeFramework.Variables = CType(ObjDoc.Variables, SolidEdgeFramework.Variables)
Dim pFindCriterium As String = "*"
Dim NamedBy As Object = SolidEdgeConstants.VariableNameBy.seVariableNameByBoth
Dim CaseInsensitive As Object = False
Dim VarType As Object = SolidEdgeConstants.VariableVarType.SeVariableVarTypeBoth
Dim variableList As SolidEdgeFramework.VariableList = CType(variables.Query(pFindCriterium, NamedBy, VarType, CaseInsensitive), SolidEdgeFramework.VariableList)
If variableList.Count > 0 Then
Dim tmpList As New List(Of Object) 'variable)
For Each item In variableList
Try
Console.WriteLine(item.Name & " - " & item.GetComment)
If item.GetComment = "Autotune" Then
tmpList.Add(item)
End If
Catch ex As Exception
Console.WriteLine(item.Name)
End Try
Next
For Each item In tmpList
'tmpSlider.LengthUnits = LengthUnits
'Dim tmpSlider As New UC_Slider(item, LengthUnits) With {
' .objDoc = objDoc,
' .UpdateDoc = BT_Update.Checked,
' .SaveImages = BT_SaveImages.Checked,
' .CheckInterference = BT_CheckInterference.Checked
'}
Dim tmpSlider As New UC_Slider(item, LengthUnits, ObjDoc) With {
.UpdateDoc = Me.UpdateDoc,
.SaveImages = Me.SaveImages,
.CheckInterference = Me.CheckInterference
}
AddHandler tmpSlider.LB_value.TextChanged, AddressOf Slider_Click
FLP_Vars.Controls.Add(tmpSlider)
Next
SetupAnchors()
End If
BT_Tracker_Click(Me, Nothing)
End Sub
Private Sub FLP_Vars_ControlRemoved(sender As Object, e As ControlEventArgs) Handles FLP_Vars.ControlRemoved
SetupAnchors()
End Sub
Private Sub BT_Reload_Click(sender As Object, e As EventArgs) Handles BT_Reload.Click
FLP_Vars.Controls.Clear()
Autotune()
End Sub
Private Sub BT_Tracker_Click(sender As Object, e As EventArgs) Handles BT_Tracker.Click
'MsgBox("Not implemented yet! :)", MsgBoxStyle.Information)
If BT_Tracker.Checked Then
Select Case ObjDoc.Type
Case = DocumentTypeConstants.igDraftDocument
For Each item In ObjDoc.ActiveSheet.BlockOccurrences
If item.Block.Name = "Tracker" Then
Tracker_2D = item
End If
Next
If IsNothing(Tracker_2D) Then
MsgBox("2D Tracker not found!", MsgBoxStyle.Information)
BT_Tracker.Checked = False
Exit Sub
End If
Case Else
For Each item In ObjDoc.CoordinateSystems
If item.name = "Tracker" Then
Tracker_3D = item
End If
Next
If IsNothing(Tracker_3D) Then
MsgBox("3D Tracker not found!", MsgBoxStyle.Information)
BT_Tracker.Checked = False
Exit Sub
End If
End Select
SetupTracker()
Else
Trace = False
For Each item In FLP_Vars.Controls
If TypeOf item Is UC_Tracker Then FLP_Vars.Controls.Remove(item)
Next
End If
Tracking = BT_Tracker.Checked
End Sub
Private Sub SetupTracker()
Dim tmpTracker As New UC_Tracker("Tracker", LengthUnits, ObjDoc)
If ObjDoc.Type = DocumentTypeConstants.igDraftDocument Then tmpTracker.Tracker_3D = False
FLP_Vars.Controls.Add(tmpTracker)
tmpTracker.UpdateLabel()
SetupAnchors()
End Sub
Private Sub BT_Workflow_Click(sender As Object, e As EventArgs) Handles BT_Workflow.Click
'MsgBox("Not implemented yet! :)", MsgBoxStyle.Information)
Dim tmpVariables = New List(Of Object)
For Each item As UC_Slider In FLP_Vars.Controls.OfType(Of UC_Slider)
If Not IsNothing(item) Then tmpVariables.Add(item.objVar)
Next
Dim tmpWorkFlow As New Form_WorkFlow With {
.Variables = tmpVariables,
.UpdateDoc = Me.UpdateDoc,
.SaveImages = Me.SaveImages,
.CheckInterference = Me.CheckInterference,
.LengthUnits = LengthUnits,
.Export = BT_Export.Checked
}
tmpWorkFlow.ShowDialog(Me)
' TODO: When this dialog returns, the variable values may have changed.
' I think this is screwing up subsequent manual cycling of any UC_Slider.
' A single UtilsUnits is reused across every slider here rather than
' letting each SetTrackBar() call build its own - the document's units
' haven't changed, so re-enumerating them per slider was pure overhead.
Me.Cursor = Cursors.WaitCursor
Dim RefreshUU As New UtilsUnits(ObjDoc)
For Each item As UC_Slider In FLP_Vars.Controls.OfType(Of UC_Slider)
If Not IsNothing(item) Then item.SetTrackBar(RefreshUU)
Next
Me.Cursor = Cursors.Default
End Sub
Private Sub BT_UpdateDoc_CheckedChanged(sender As Object, e As EventArgs) Handles BT_UpdateDoc.CheckedChanged
Me.UpdateDoc = BT_UpdateDoc.Checked
For Each tmpSlider In FLP_Vars.Controls
If TypeOf tmpSlider Is UC_Slider Then tmpSlider.UpdateDoc = Me.UpdateDoc
Next
End Sub
'Private Sub BT_SaveImages_Click(sender As Object, e As EventArgs) Handles BT_SaveImages.Click
' For Each C As Control In FLP_Vars.Controls
' If TypeOf C Is UC_Slider Then
' Dim tmpSlider As UC_Slider = CType(C, UC_Slider)
' tmpSlider.SaveImages = BT_SaveImages.Checked
' End If
' Next
'End Sub
Private Sub BT_SaveImages_CheckChanged(sender As Object, e As EventArgs) Handles BT_SaveImages.CheckedChanged
Me.SaveImages = BT_SaveImages.Checked
For Each C As Control In FLP_Vars.Controls
If TypeOf C Is UC_Slider Then
Dim tmpSlider As UC_Slider = CType(C, UC_Slider)
tmpSlider.SaveImages = Me.SaveImages
End If
Next
End Sub
'Private Sub BT_CheckInterference_Click(sender As Object, e As EventArgs) Handles BT_CheckInterference.Click
' For Each C As Control In FLP_Vars.Controls
' If TypeOf C Is UC_Slider Then
' Dim tmpSlider As UC_Slider = CType(C, UC_Slider)
' tmpSlider.CheckInterference = Me.CheckInterference
' End If
' Next
'End Sub
Private Sub BT_CheckInterference_CheckChanged(sender As Object, e As EventArgs) Handles BT_CheckInterference.CheckedChanged
Me.CheckInterference = BT_CheckInterference.Checked
For Each C As Control In FLP_Vars.Controls
If TypeOf C Is UC_Slider Then
Dim tmpSlider As UC_Slider = CType(C, UC_Slider)
tmpSlider.CheckInterference = Me.CheckInterference
End If
Next
End Sub
Private Function GetLengthUnits(objDoc As SolidEdgeFramework.SolidEdgeDocument) As SolidEdgeConstants.UnitOfMeasureLengthReadoutConstants
Dim tmpLengthUnits As SolidEdgeConstants.UnitOfMeasureLengthReadoutConstants
Dim UnitsOfMeasure = objDoc.UnitsOfMeasure
For Each UnitOfMeasure As SolidEdgeFramework.UnitOfMeasure In UnitsOfMeasure
If UnitOfMeasure.Type = SolidEdgeConstants.UnitTypeConstants.igUnitDistance Then
tmpLengthUnits = UnitOfMeasure.Units
Exit For
End If
Next
Return tmpLengthUnits
End Function
Private Sub Form_Closing(sender As Object, e As EventArgs) Handles Me.FormClosing
Dim UP As New UtilsPreferences
UP.SaveProgramSettings(Me)
End Sub
End Class
Public Class MySR
Inherits ToolStripSystemRenderer
Public Sub New()
End Sub
Protected Overrides Sub OnRenderToolStripBorder(ByVal e As ToolStripRenderEventArgs)
End Sub
End Class