-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInventorButton.vb
More file actions
215 lines (174 loc) · 7.14 KB
/
InventorButton.vb
File metadata and controls
215 lines (174 loc) · 7.14 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
Imports System.Drawing
Imports System.Windows.Forms
Imports Inventor
'Namespace InventorNetAddinVB1
''' <summary>
''' The class wrapps up Inventor Button creation stuffs and is easy to use.
''' No need to derive. Create an instance using either constructor and assign the Action.
''' </summary>
Public Class InventorButton
#Region "Fields & Properties"
Private mButtonDef As ButtonDefinition
Public Property ButtonDef() As ButtonDefinition
Get
Return mButtonDef
End Get
Set(ByVal value As ButtonDefinition)
mButtonDef = value
End Set
End Property
#End Region
#Region "Constructors"
''' <summary>
''' The most comprehensive signature.
''' </summary>
Public Sub New(ByVal displayName As String, ByVal internalName As String, ByVal description As String, ByVal tooltip As String, ByVal standardIcon As Icon, ByVal largeIcon As Icon, _
ByVal commandType As CommandTypesEnum, ByVal buttonDisplayType As ButtonDisplayEnum)
Create(displayName, internalName, description, tooltip, AddinGlobal.ClassId, standardIcon, _
largeIcon, commandType, buttonDisplayType)
End Sub
''' <summary>
''' The signature does not care about Command Type (always editing) and Button Display (always with text).
''' </summary>
Public Sub New(ByVal displayName As String, ByVal internalName As String, ByVal description As String, ByVal tooltip As String, ByVal standardIcon As Icon, ByVal largeIcon As Icon)
Create(displayName, internalName, description, tooltip, AddinGlobal.ClassId, Nothing, _
Nothing, CommandTypesEnum.kEditMaskCmdType, ButtonDisplayEnum.kAlwaysDisplayText)
End Sub
''' <summary>
''' The signature does not care about icons.
''' </summary>
Public Sub New(ByVal displayName As String, ByVal internalName As String, ByVal description As String, ByVal tooltip As String, ByVal commandType As CommandTypesEnum, ByVal buttonDisplayType As ButtonDisplayEnum)
Create(displayName, internalName, description, tooltip, AddinGlobal.ClassId, Nothing, _
Nothing, commandType, buttonDisplayType)
End Sub
''' <summary>
''' This signature only cares about display name and icons.
''' </summary>
''' <param name="displayName"></param>
''' <param name="standardIcon"></param>
''' <param name="largeIcon"></param>
Public Sub New(ByVal displayName As String, ByVal standardIcon As Icon, ByVal largeIcon As Icon)
Create(displayName, displayName, displayName, displayName, AddinGlobal.ClassId, standardIcon, _
largeIcon, CommandTypesEnum.kEditMaskCmdType, ButtonDisplayEnum.kAlwaysDisplayText)
End Sub
''' <summary>
''' The simplest signature, which can be good for prototyping.
''' </summary>
Public Sub New(ByVal displayName As String)
Create(displayName, displayName, displayName, displayName, AddinGlobal.ClassId, Nothing, _
Nothing, CommandTypesEnum.kEditMaskCmdType, ButtonDisplayEnum.kAlwaysDisplayText)
End Sub
''' <summary>
''' The helper method for constructors to call to avoid duplicate code.
''' </summary>
Public Sub Create(ByVal displayName As String, ByVal internalName As String, ByVal description As String, ByVal tooltip As String, ByVal clientId As String, ByVal standardIcon As Icon, _
ByVal largeIcon As Icon, ByVal commandType As CommandTypesEnum, ByVal buttonDisplayType As ButtonDisplayEnum)
If String.IsNullOrEmpty(clientId) Then
clientId = AddinGlobal.ClassId
End If
Dim standardIconIPictureDisp As stdole.IPictureDisp = Nothing
Dim largeIconIPictureDisp As stdole.IPictureDisp = Nothing
If standardIcon IsNot Nothing Then
standardIconIPictureDisp = IconToPicture(standardIcon)
largeIconIPictureDisp = IconToPicture(largeIcon)
End If
mButtonDef = AddinGlobal.IVApp.CommandManager.ControlDefinitions.AddButtonDefinition(displayName, internalName, commandType, clientId, description, tooltip, _
standardIconIPictureDisp, largeIconIPictureDisp, buttonDisplayType)
mButtonDef.Enabled = True
AddHandler mButtonDef.OnExecute, AddressOf ButtonDefinition_OnExecute
DisplayText = True
AddinGlobal.ButtonList.Add(Me)
End Sub
#End Region
#Region "Behavior"
Public Property DisplayBigIcon() As Boolean
Get
Return m_DisplayBigIcon
End Get
Set(ByVal value As Boolean)
m_DisplayBigIcon = value
End Set
End Property
Private m_DisplayBigIcon As Boolean
Public Property DisplayText() As Boolean
Get
Return m_DisplayText
End Get
Set(ByVal value As Boolean)
m_DisplayText = value
End Set
End Property
Private m_DisplayText As Boolean
Public Property InsertBeforeTarget() As Boolean
Get
Return m_InsertBeforeTarget
End Get
Set(ByVal value As Boolean)
m_InsertBeforeTarget = value
End Set
End Property
Private m_InsertBeforeTarget As Boolean
Public Sub SetBehavior(ByVal displayBigIcon__1 As Boolean, ByVal displayText__2 As Boolean, ByVal insertBeforeTarget__3 As Boolean)
DisplayBigIcon = displayBigIcon__1
DisplayText = displayText__2
InsertBeforeTarget = insertBeforeTarget__3
End Sub
Public Sub CopyBehaviorFrom(ByVal button As InventorButton)
Me.DisplayBigIcon = button.DisplayBigIcon
Me.DisplayText = button.DisplayText
Me.InsertBeforeTarget = Me.InsertBeforeTarget
End Sub
#End Region
#Region "Actions"
''' <summary>
''' The button callback method.
''' </summary>
''' <param name="context"></param>
Private Sub ButtonDefinition_OnExecute(ByVal context As NameValueMap)
If Execute IsNot Nothing Then
Execute()
Else
MessageBox.Show("Nothing to execute.")
End If
End Sub
''' <summary>
''' The button action to be assigned from anywhere outside.
''' </summary>
Public Execute As Action
#End Region
#Region "Image Converters"
Public Shared Function ImageToPicture(ByVal image As Image) As stdole.IPictureDisp
Return ImageConverter.ImageToPicture(image)
End Function
Public Shared Function IconToPicture(ByVal icon As Icon) As stdole.IPictureDisp
Return ImageConverter.ImageToPicture(icon.ToBitmap())
End Function
Public Shared Function PictureToImage(ByVal picture As stdole.IPictureDisp) As Image
Return ImageConverter.PictureToImage(picture)
End Function
Public Shared Function PictureToIcon(ByVal picture As stdole.IPictureDisp) As Icon
Return ImageConverter.PictureToIcon(picture)
End Function
Private Class ImageConverter
Inherits AxHost
Public Sub New()
MyBase.New(String.Empty)
End Sub
Public Shared Function ImageToPicture(ByVal image As Image) As stdole.IPictureDisp
Return DirectCast(GetIPictureDispFromPicture(image), stdole.IPictureDisp)
End Function
Public Shared Function IconToPicture(ByVal icon As Icon) As stdole.IPictureDisp
Return ImageToPicture(icon.ToBitmap())
End Function
Public Shared Function PictureToImage(ByVal picture As stdole.IPictureDisp) As Image
Return GetPictureFromIPicture(picture)
End Function
Public Shared Function PictureToIcon(ByVal picture As stdole.IPictureDisp) As Icon
Dim bitmap As New Bitmap(PictureToImage(picture))
Return System.Drawing.Icon.FromHandle(bitmap.GetHicon())
End Function
End Class
#End Region
End Class
'End Namespace