-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathClsPad.vb
455 lines (380 loc) · 16.1 KB
/
ClsPad.vb
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
444
445
446
447
448
449
450
451
452
453
454
455
Imports System.Globalization
Imports System.Drawing
Imports System.ComponentModel
Public Class Pad
Inherits SelectableLayerObject
Implements System.ICloneable
Public Const PadDefaultColor As Int32 = &HFFA54B4B
Protected m_Pen As System.Drawing.Pen
Protected m_Brush As System.Drawing.SolidBrush
Protected m_DevicePin As DevicePin 'pin of device connected to
Protected m_EagleDevicePadName As String
Protected m_Routes As New List(Of Route) 'connected routes
Public Sub New()
MyBase.New()
m_Color = System.Drawing.Color.FromArgb(PadDefaultColor)
m_Pen = New System.Drawing.Pen(m_Color)
End Sub
Public Sub New(ByVal location As System.Drawing.PointF)
MyBase.New(location)
m_Color = System.Drawing.Color.FromArgb(PadDefaultColor)
m_Pen = New System.Drawing.Pen(m_Color)
End Sub
Public Sub New(ByVal location As System.Drawing.PointF, ByVal Width As Single, ByVal Height As Single)
MyBase.New(location, Width, Height)
m_Color = System.Drawing.Color.FromArgb(PadDefaultColor)
m_Pen = New System.Drawing.Pen(m_Color)
m_Name = "pad_" & m_id
End Sub
'construct from XML
Public Sub New(ByVal PCB As PCB, ByVal Root As Xml.XmlNode, ByVal BinData As Ionic.Zip.ZipFile)
fromXML(PCB, Root, BinData)
End Sub
'Not selected color
'<CategoryAttribute("Color"), _
' DefaultValueAttribute(PadDefaultColor)> _
Public Overrides Property Color() As System.Drawing.Color
Get
Return m_Pen.Color
End Get
Set(ByVal value As System.Drawing.Color)
m_Color = value
m_Pen.Color = value
End Set
End Property
'Draws the pad on the needed layers
Public Overrides Sub Draw(ByVal Graphics As System.Drawing.Graphics, ByVal Layer As Layer)
If m_Selected Then
m_Pen = New Pen(m_SelectedColor)
m_Brush = New SolidBrush(m_SelectedColor)
Else
If m_Highlighted Then
m_Pen = New Pen(m_HighlightColor)
m_Brush = New SolidBrush(m_HighlightColor)
Else
m_Pen = New Pen(m_Color)
m_Brush = New SolidBrush(m_Color)
End If
End If
End Sub
Public Property DevicePin() As DevicePin
Get
Return m_DevicePin
End Get
Set(ByVal value As DevicePin)
m_DevicePin = value
End Set
End Property
''' <summary>
''' Returns the name of the pad of the eagle device this pad is connected with
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Overridable Property EaglePadName() As String
Get
Return m_EagleDevicePadName
End Get
Set(ByVal value As String)
m_EagleDevicePadName = value
End Set
End Property
Public Overrides Sub AddToPCB(ByVal PCB As PCB)
MyBase.AddToPCB(PCB)
PCB.ConnectionMatrix.AddPad(Me)
End Sub
Public Overrides Sub PlaceObject(ByVal PCB As PCB, ByVal WindowType As PCB.WindowTypes)
PlaceObject(PCB, WindowType, m_Center)
End Sub
Public Overrides Sub PlaceObject(ByVal PCB As PCB, ByVal WindowType As PCB.WindowTypes, ByVal Location As System.Drawing.PointF)
MyBase.PlaceObject(PCB, WindowType, m_Rect.Location)
End Sub
''' <summary>
''' Called by PCB class when deleting the object by the user, class has to create undo information and adds to project
''' </summary>
''' <remarks></remarks>
Public Overrides Function GetUndoDeleteItem(ByVal PCB As PCB) As UndoRedoItem
Return New UndoRedoDeletePad(PCB, Me)
End Function
''' <summary>
''' Called by PCB class before placing the object to the PCB
''' </summary>
''' <param name="PCB"></param>
''' <returns>Returns a undo redo stack item to undo adding the object</returns>
''' <remarks></remarks>
Public Overrides Function GetUndoAddItem(ByVal PCB As PCB) As UndoRedoItem
Return New UndoRedoAddPad(PCB, Me)
End Function
Public Overrides Function GetProperties() As LayerObjectProperties
Return New PadProperties(m_PCB, Me)
End Function
''' <summary>
''' Called by the PCB class when removing the object from the project
''' </summary>
''' <remarks></remarks>
Public Overrides Sub Remove()
MyBase.Remove()
'delete all the routes
Dim TmpRoutes() As Route = m_Routes.ToArray()
For Each Route As Route In TmpRoutes
m_PCB.RemoveObject(Route)
Next
m_PCB.ConnectionMatrix.RemovePad(Me)
If DevicePin IsNot Nothing Then
'DevicePin.Pads.Remove(Me)
DevicePin.RemovePad(Me)
End If
m_Routes = New List(Of Route)
For Each Route As Route In TmpRoutes 'for making undo delete device work properly
m_Routes.Add(Route)
Next
End Sub
Public Overrides Sub toXML(ByVal XMLDoc As Xml.XmlDocument, ByVal Root As Xml.XmlNode, ByVal BinData As Ionic.Zip.ZipFile)
MyBase.toXML(XMLDoc, Root, BinData)
Root.Attributes.Append(XMLDoc.CreateAttribute("eagle_device_pad_name")).Value = m_EagleDevicePadName
End Sub
Public Overrides Sub fromXML(ByVal PCB As PCB, ByVal Root As System.Xml.XmlNode, ByVal BinData As Ionic.Zip.ZipFile)
MyBase.fromXML(PCB, Root, BinData)
m_EagleDevicePadName = Root.Attributes("eagle_device_pad_name").Value
End Sub
Public Overrides Function Clone() As Object
Dim Obj As Object = MyBase.Clone()
CType(Obj, Pad).m_Name = "pad_" & CType(Obj, Pad).m_id
CType(Obj, Pad).m_Routes = New List(Of Route)
CType(Obj, Pad).m_DevicePin = Nothing
Return Obj
End Function
Public ReadOnly Property Routes() As List(Of Route)
Get
Return m_Routes
End Get
End Property
''' <summary>
''' Returns all pads that are connected to this pad by the connected routes
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Public Function GetConnectedPadsByRoutes() As List(Of Pad)
Dim Pads As New List(Of Pad)
Pads.Add(Me)
AddConnectedPadsByRoutes(Pads)
Return Pads
End Function
Protected Sub AddConnectedPadsByRoutes(ByVal Lst As List(Of Pad))
For Each Route As Route In m_Routes
If Not Lst.Contains(Route.StartPad) Then
Lst.Add(Route.StartPad)
Route.StartPad.AddConnectedPadsByRoutes(Lst)
End If
If Not Lst.Contains(Route.EndPad) Then
Lst.Add(Route.EndPad)
Route.EndPad.AddConnectedPadsByRoutes(Lst)
End If
Next
End Sub
End Class
'http://msdn.microsoft.com/en-us/library/aa302326.aspx
'<DefaultPropertyAttribute("SaveOnClose")> _
Public Class SMDPad
Inherits Pad
Public Const SMDPadDefaultWidth As Integer = 10
Public Const SMDPadDefaultHeight As Integer = 8
Public Sub New()
MyBase.New(New PointF(0, 0), SMDPadDefaultWidth, SMDPadDefaultHeight)
End Sub
Public Sub New(ByVal Location As System.Drawing.PointF)
Me.New(Location, 0, 0)
End Sub
Public Sub New(ByVal Location As System.Drawing.PointF, ByVal Width As Single, ByVal Height As Single)
MyBase.New(Location, Width, Height)
End Sub
'construct from XML
Public Sub New(ByVal PCB As PCB, ByVal Root As Xml.XmlNode, ByVal BinData As Ionic.Zip.ZipFile)
fromXML(PCB, Root, BinData)
End Sub
Public Overrides Sub Draw(ByVal Graphics As System.Drawing.Graphics, ByVal Layer As Layer)
If Not m_Visible Then Return
MyBase.Draw(Graphics, Layer)
Graphics.FillRectangle(m_Brush, m_Rect)
End Sub
''' <summary>
''' Places the object on the current location
''' </summary>
''' <param name="PCB"></param>
''' <remarks></remarks>
Public Overrides Sub PlaceObject(ByVal PCB As PCB, ByVal WindowType As PCB.WindowTypes)
PlaceObject(PCB, WindowType, m_Rect.Location)
End Sub
Public Overrides Sub PlaceObject(ByVal PCB As PCB, ByVal WindowType As PCB.WindowTypes, ByVal Location As System.Drawing.PointF)
MyBase.PlaceObject(PCB, WindowType, Location)
If WindowType = PCB.WindowTypes.WindowTypeBottom Then
PCB.GetLayer(PCB.LayerTypes.LayerTypeBottomPads).LayerObjects.Add(Me)
Else
PCB.GetLayer(PCB.LayerTypes.LayerTypeTopPads).LayerObjects.Add(Me)
End If
End Sub
Public Overloads Sub PlaceObject(ByVal PCB As PCB, ByVal WindowType As PCB.WindowTypes, ByVal Layer As PCB.LayerTypes, ByVal Location As System.Drawing.PointF)
MyBase.PlaceObject(PCB, WindowType, Location)
PCB.GetLayer(Layer).LayerObjects.Add(Me)
End Sub
Public Overrides Sub toXML(ByVal XMLDoc As System.Xml.XmlDocument, ByVal Root As System.Xml.XmlNode, ByVal BinData As Ionic.Zip.ZipFile)
MyBase.toXML(XMLDoc, Root, BinData)
End Sub
Public Overrides Sub fromXML(ByVal PCB As PCB, ByVal Root As System.Xml.XmlNode, ByVal BinData As Ionic.Zip.ZipFile)
MyBase.fromXML(PCB, Root, BinData)
End Sub
End Class
Public Class ThroughHolePad
Inherits Pad
Public Const ThroughHolePadDefaultRadius As Single = 12
Public Sub New()
MyBase.New(New Point(0, 0), ThroughHolePadDefaultRadius, ThroughHolePadDefaultRadius)
End Sub
Public Sub New(ByVal Location As System.Drawing.PointF)
Me.New(Location, 0, 0)
End Sub
Public Sub New(ByVal Location As System.Drawing.PointF, ByVal Width As Single, ByVal Height As Single)
MyBase.New(Location, Width, Height)
End Sub
'construct from XML
Public Sub New(ByVal PCB As PCB, ByVal Root As Xml.XmlNode, ByVal BinData As Ionic.Zip.ZipFile)
fromXML(PCB, Root, BinData)
End Sub
Public Overrides Sub Draw(ByVal Graphics As System.Drawing.Graphics, ByVal Layer As Layer)
If Not m_Visible Then Return
MyBase.Draw(Graphics, Layer)
Graphics.FillEllipse(m_Brush, m_Rect)
End Sub
''' <summary>
''' Places the object on the current location
''' </summary>
''' <param name="PCB"></param>
''' <remarks></remarks>
Public Overrides Sub PlaceObject(ByVal PCB As PCB, ByVal WindowType As PCB.WindowTypes)
PlaceObject(PCB, WindowType, m_Rect.Location)
End Sub
''' <summary>
''' Places the object on a center location, keeping the current width and height
''' </summary>
''' <param name="PCB">PCB project</param>
''' <param name="Location">Center of where to place the object</param>
''' <remarks></remarks>
Public Overrides Sub PlaceObject(ByVal PCB As PCB, ByVal WindowType As PCB.WindowTypes, ByVal Location As System.Drawing.PointF)
PlaceObject(PCB, WindowType, Location, PCB.LayerTypes.LayerTypeTopPads, PCB.LayerTypes.LayerTypeBottomPads)
End Sub
Protected Overloads Sub PlaceObject(ByVal PCB As PCB, ByVal WindowType As PCB.WindowTypes, ByVal Location As System.Drawing.PointF, ByVal TopLayer As PCB.LayerTypes, ByVal BottomLayer As PCB.LayerTypes)
MyBase.PlaceObject(PCB, WindowType, Location)
PCB.GetLayer(TopLayer).LayerObjects.Add(Me)
PCB.GetLayer(BottomLayer).LayerObjects.Add(Me)
End Sub
''' <summary>
''' Automatic scaling of the object
''' </summary>
''' <param name="Window">The window the object scaled on</param>
''' <param name="StartPoint">Point clicked by left mouse button at start of drawing (x,y on screen)</param>
''' <param name="CurrentPoint">Current point the mouse is down at (x,y on screen)</param>
''' <remarks></remarks>
Public Overrides Sub AutoScale(ByVal Window As FrmLayer, ByVal StartPoint As PointF, ByVal CurrentPoint As PointF)
Dim Rad As Integer = Distance(CurrentPoint, StartPoint)
If Rad <= 0 Then Rad = 1
m_Rect.Width = Rad * 2
m_Rect.Height = Rad * 2
Me.Center = New Point(StartPoint.X, StartPoint.Y)
End Sub
Public Overrides Sub toXML(ByVal XMLDoc As System.Xml.XmlDocument, ByVal Root As System.Xml.XmlNode, ByVal BinData As Ionic.Zip.ZipFile)
MyBase.toXML(XMLDoc, Root, BinData)
End Sub
Public Overrides Sub fromXML(ByVal PCB As PCB, ByVal Root As System.Xml.XmlNode, ByVal BinData As Ionic.Zip.ZipFile)
MyBase.fromXML(PCB, Root, BinData)
End Sub
End Class
Public Class Via
Inherits ThroughHolePad
Public Sub New()
MyBase.New(New Point(0, 0), ThroughHolePadDefaultRadius, ThroughHolePadDefaultRadius)
m_Color = Drawing.Color.Purple
m_Name = "via_" & m_id
End Sub
Public Sub New(ByVal Location As System.Drawing.PointF)
Me.New(Location, 0, 0)
m_Color = Drawing.Color.Purple
m_Name = "via_" & m_id
End Sub
''' <summary>
''' Places the object on a center location, keeping the current width and height
''' </summary>
''' <param name="PCB">PCB project</param>
''' <param name="Location">Center of where to place the object</param>
''' <remarks></remarks>
Public Overrides Sub PlaceObject(ByVal PCB As PCB, ByVal WindowType As PCB.WindowTypes, ByVal Location As System.Drawing.PointF)
MyBase.PlaceObject(PCB, WindowType, Location, unPCB.PCB.LayerTypes.LayerTypeTopVias, unPCB.PCB.LayerTypes.LayerTypeBottomVias)
End Sub
Public Sub New(ByVal Location As System.Drawing.PointF, ByVal Width As Single, ByVal Height As Single)
MyBase.New(Location, Width, Height)
m_Color = Drawing.Color.Purple
End Sub
'construct from XML
Public Sub New(ByVal PCB As PCB, ByVal Root As Xml.XmlNode, ByVal BinData As Ionic.Zip.ZipFile)
fromXML(PCB, Root, BinData)
End Sub
Public Overrides Function Clone() As Object
Dim Obj As Via = CType(MyBase.Clone(), Via)
Obj.m_Name = "via_" & Obj.m_id
Return Obj
End Function
End Class
Public Class RouteJunction
Inherits SMDPad
Public Const RouteJunctionDefaultSize As Integer = 5
Public Sub New()
MyBase.New(New Point(0, 0), RouteJunctionDefaultSize, RouteJunctionDefaultSize)
m_Color = Drawing.Color.Purple
m_Name = "junction_" & m_id
End Sub
Public Sub New(ByVal Location As System.Drawing.PointF)
Me.New(Location, RouteJunctionDefaultSize, RouteJunctionDefaultSize)
m_Color = Drawing.Color.Purple
m_Name = "junction_" & m_id
End Sub
''' <summary>
''' Places the object on a pcb, keeping the current width and height
''' </summary>
''' <param name="PCB">PCB project</param>
''' <remarks></remarks>
Public Overrides Sub PlaceObject(ByVal PCB As PCB, ByVal WindowType As PCB.WindowTypes)
PlaceObject(PCB, WindowType, WindowType, m_Rect.Location)
End Sub
''' <summary>
''' Places the object on a center location, keeping the current width and height
''' </summary>
''' <param name="PCB">PCB project</param>
''' <param name="Location">Center of where to place the object</param>
''' <remarks></remarks>
Public Overrides Sub PlaceObject(ByVal PCB As PCB, ByVal WindowType As PCB.WindowTypes, ByVal Location As System.Drawing.PointF)
MyBase.PlaceObject(PCB, WindowType, IIf(WindowType = unPCB.PCB.WindowTypes.WindowTypeTop, PCB.LayerTypes.LayerTypeTopRoute, PCB.LayerTypes.LayerTypeBottomRoute), Location)
End Sub
Public Sub New(ByVal Location As System.Drawing.PointF, ByVal Width As Single, ByVal Height As Single)
MyBase.New(Location, Width, Height)
m_Color = Drawing.Color.Purple
End Sub
'construct from XML
Public Sub New(ByVal PCB As PCB, ByVal Root As Xml.XmlNode, ByVal BinData As Ionic.Zip.ZipFile)
fromXML(PCB, Root, BinData)
End Sub
Public Overrides Function Clone() As Object
Dim Obj As RouteJunction = CType(MyBase.Clone(), RouteJunction)
Obj.m_Name = "junction_" & Obj.m_id
Return Obj
End Function
End Class
Public Class PadProperties
Inherits LayerObjectProperties
Public Sub New(ByVal PCB As PCB, ByVal Obj As LayerObject)
MyBase.New(PCB, Obj)
End Sub
Public Overridable ReadOnly Property EaglePadName() As String
Get
Return CType(m_Object, Pad).EaglePadName
End Get
End Property
End Class