-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFrmLayer.vb
1593 lines (1438 loc) · 76.5 KB
/
FrmLayer.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
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Public Class FrmLayer
Private Enum DrawTools
DrawSMD = 1
DrawThrougHole = 2
DrawVia = 3
DrawRoute = 4
DrawJunction = 5
DrawSplit = 6
End Enum
Public Enum DrawStates
None = 0
DrawObject
DrawDevicePins
Connect
SelectObjects
MovePCBImage
StartMoveObjects
MoveObjects
AutoRouter
ResizeObjectSelect
ResizeObjectSelected
ResizeObjectResize
DrawRouteBegin 'first point of a route
DrawRouteEnd 'next point/end of a route
SplitRoute 'split route between 2 route points
End Enum
Private Structure ClickPoint
Dim Location As PointF
End Structure
Private Enum ResizePointType
ResizeNone
ResizeNW
ResizeN
ResizeNE
ResizeE
ResizeSE
ResizeS
ResizeSW
ResizeW
End Enum
Private Structure ResizeInfoStruct
Public ResizePoints() As ResizePoint
Public ResizeObject As LayerObject
Public WindowType As PCB.WindowTypes 'the window type the selected object is located on
Public ResizingRefPoint As PointF 'reference where resizing began
Public IsResizing As Boolean 'is now resizing
Public ResizingType As ResizePointType 'if resizing, this is the direction
Public ResizeStartLocation As RectangleF 'start location / size before resizing began
End Structure
Private Structure ResizePoint
Public Location As PointF
Public ResizeType As ResizePointType
Public CursorType As ResizePointType
Public Sub New(ByVal Location As PointF, ByVal ResizeType As ResizePointType, ByVal CursorType As ResizePointType)
Me.Location = Location
Me.ResizeType = ResizeType
Me.CursorType = CursorType
End Sub
Public Function GetCursor() As Cursor
Select Case CursorType
Case ResizePointType.ResizeE
Return Cursors.SizeWE
Case ResizePointType.ResizeN
Return Cursors.SizeNS
Case ResizePointType.ResizeNE
Return Cursors.SizeNESW
Case ResizePointType.ResizeNW
Return Cursors.SizeNWSE
Case ResizePointType.ResizeS
Return Cursors.SizeNS
Case ResizePointType.ResizeSE
Return Cursors.SizeNWSE
Case ResizePointType.ResizeSW
Return Cursors.SizeNESW
Case ResizePointType.ResizeW
Return Cursors.SizeWE
End Select
Return Nothing
End Function
End Structure
Private Shared sPCB As PCB 'shared PCB object for shared subs
Private Shared DrawObject As LayerObject 'temp object used to show what you are currently drawing
Private Shared DrawRouteWindow As PCB.WindowTypes 'if we are drawing a route, this is the window we started drawing the route, clicking the other window has no effect
Private Shared DrawState As DrawStates
Private Shared ConnectDevice As Device
Private Shared ConnectDevicePin As UnconnectedDevicePin
Private Shared LayerWindows As New List(Of FrmLayer)
Private Shared WithEvents AutoRouteWindow As FrmManualRoute
Private Shared WithEvents PropertiesWindow As FrmProperties
Private Shared ResizeInfo As ResizeInfoStruct 'holds information about the selected object that can be resized now
Private Shared InfoText As String
Dim MovePoint As ClickPoint 'last mouse move position
Dim LeftClickPoint As ClickPoint 'the last point left clicked = mouse down event
Dim RightClickPoint As ClickPoint 'the last point right clicked
Dim MiddleClickPoint As ClickPoint 'the last point middle clicked
Dim TranslateStartX As Single, TranslateStartY As Single 'used for moving the pcb on the screen with middle mouse button
Dim m_StartLocation As PointF
Dim m_Scale As Double
Dim m_Width As Single
Dim m_Height As Single
Dim m_TranslateX As Single
Dim m_TranslateY As Single
Dim m_LastRoutePointLocation As PointF 'last rightclicked routepoint location is saved here, in case of a double click we must move back to that location because the last point was removed by right click
Private Shared m_SplitRouteLines(0 To 1) As Line 'if we split a route, draw lines of new location
Public WithEvents PCB As PCB 'the pcb
Public WindowType As PCB.WindowTypes
''' <summary>
''' Creates a new layer window, the window type and the PCB project are required
''' </summary>
''' <param name="WindowType"></param>
''' <param name="PCB"></param>
''' <remarks></remarks>
Public Sub New(ByVal WindowType As PCB.WindowTypes, ByVal PCB As PCB)
' This call is required by the Windows Form Designer.
InitializeComponent()
Me.PCB = PCB
sPCB = PCB
m_Scale = 1
m_Height = PCB.Height
m_Width = PCB.Width
Me.WindowType = WindowType
LayerWindows.Add(Me)
UpdateWindowTitle()
End Sub
Private Sub UpdateWindowTitle()
Select Case WindowType
Case unPCB.PCB.WindowTypes.WindowTypeBottom
Me.Text = "unPCB [" & PCB.Name & "] - Bottom layer " & IIf(PCB.IsChanged, "*", "")
Case unPCB.PCB.WindowTypes.WindowTypeTop
Me.Text = "unPCB [" & PCB.Name & "] - Top layer " & IIf(PCB.IsChanged, "*", "")
End Select
End Sub
Private Sub FrmLayer_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
LayerWindows.Remove(Me)
End Sub
Private Sub FrmLayer_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ToolStripButtonUndo.Enabled = PCB.UndoStack.Count > 0
ToolStripButtonRedo.Enabled = PCB.RedoStack.Count > 0
FlipHorizontallyToolStripMenuItem.Checked = PCB.HorizontalMirror(WindowType)
FlipVerticallyToolStripMenuItem.Checked = PCB.VerticalMirror(WindowType)
RefreshLayerMenuItems()
End Sub
''' <summary>
''' Mouse wheel event, forward to the double buffer
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub FrmLayer_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel
DoubleBuffer_MouseWheel(sender, e)
End Sub
''' <summary>
''' Paint of the form, update the graphics
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub FrmLayer_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
UpdateGraphics()
End Sub
Private Sub DoubleBuffer_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DoubleBuffer.KeyDown
If e.KeyCode = Keys.Escape Then
ResetDrawState()
e.Handled = True
End If
End Sub
Private Sub DoubleBuffer_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DoubleBuffer.MouseDoubleClick
Select Case DrawState
Case DrawStates.DrawRouteBegin
PCB.UnHighlightAllObjects(True)
Dim ObjTypes As New List(Of Type)
Dim Route As Route = CType(DrawObject, Route)
ObjTypes.Add(GetType(SMDPad))
ObjTypes.Add(GetType(ThroughHolePad))
ObjTypes.Add(GetType(RouteJunction))
ObjTypes.Add(GetType(Via))
Dim Closest As LayerObject = PCB.GetClosestObject(WindowType, ConvertLocation(e.Location), ObjTypes, 20 / m_Scale, DrawObject)
If Closest Is Nothing Then
Dim Pad As Pad = Nothing
If e.Button = Windows.Forms.MouseButtons.Left Then
Pad = New RouteJunction()
ElseIf e.Button = Windows.Forms.MouseButtons.Right Then
Pad = New Via()
End If
If Pad IsNot Nothing Then
Pad.Center = ConvertLocation(e.Location)
PCB.PlaceObject(Pad, WindowType)
Route.StartPad = Pad
DrawRouteWindow = WindowType
If DrawRouteWindow = PCB.WindowTypes.WindowTypeTop Then 'add to drawlayer
PCB.GetLayer(PCB.LayerTypes.LayerTypeTopDrawing).LayerObjects.Add(DrawObject)
End If
If DrawRouteWindow = PCB.WindowTypes.WindowTypeBottom Then
PCB.GetLayer(PCB.LayerTypes.LayerTypeBottomDrawing).LayerObjects.Add(DrawObject)
End If
Route.AddRoutePoint(ConvertLocation(e.Location))
End If
End If
Case DrawStates.DrawRouteEnd
If DrawRouteWindow = WindowType Then
PCB.UnHighlightAllObjects(True)
Dim Route As Route = CType(DrawObject, Route)
Dim ObjTypes As New List(Of Type)
ObjTypes.Add(GetType(SMDPad))
ObjTypes.Add(GetType(ThroughHolePad))
ObjTypes.Add(GetType(RouteJunction))
ObjTypes.Add(GetType(Via))
Dim Closest As LayerObject = PCB.GetClosestObject(WindowType, ConvertLocation(e.Location), ObjTypes, 20 / m_Scale, DrawObject)
If Closest Is Nothing Then
Dim Pad As Pad = Nothing
If e.Button = Windows.Forms.MouseButtons.Left Then
Pad = New RouteJunction()
ElseIf e.Button = Windows.Forms.MouseButtons.Right Then
If Route.RoutePoints.Count > 0 Then
Route.LastRoutePoint.Location = m_LastRoutePointLocation
End If
Pad = New Via()
End If
If Pad IsNot Nothing Then
Pad.Center = ConvertLocation(e.Location)
PCB.GetLayer(unPCB.PCB.LayerTypes.LayerTypeBottomDrawing).LayerObjects.Remove(Route)
PCB.GetLayer(unPCB.PCB.LayerTypes.LayerTypeTopDrawing).LayerObjects.Remove(Route)
PCB.PlaceObject(Pad, WindowType)
If Route.RoutePoints.Count > 0 AndAlso e.Button = Windows.Forms.MouseButtons.Left Then
Route.RemoveRoutePoint(Route.LastRoutePoint)
End If
Route.EndPad = Pad
End If
End If
End If
End Select
End Sub
''' <summary>
'''
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub DoubleBuffer_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DoubleBuffer.MouseDown
Select Case e.Button
Case MouseButtons.Left
LeftClickPoint.Location = e.Location
Case MouseButtons.Middle
MiddleClickPoint.Location = e.Location
TranslateStartX = TranslateX
TranslateStartY = TranslateY
Case MouseButtons.Right
RightClickPoint.Location = e.Location
End Select
Select Case DrawState
Case DrawStates.DrawObject, DrawStates.DrawDevicePins
If e.Button = MouseButtons.Left Then 'set the center
DrawObject.Center = ConvertLocation(e.Location) ' New Point(Window.ConvertX(e.X), Window.ConvertY(e.Y))
End If
Case DrawStates.SelectObjects
Case DrawStates.MovePCBImage
If e.Button = Windows.Forms.MouseButtons.Left Then
m_StartLocation = DrawObject.Location
End If
Case DrawStates.MoveObjects
Case DrawStates.ResizeObjectSelect
Case DrawStates.ResizeObjectSelected 'now we start resizing, if we have a resize type set
If ResizeInfo.ResizingType <> ResizePointType.ResizeNone Then
ResizeInfo.IsResizing = True
ResizeInfo.ResizingRefPoint = ConvertLocation(e.Location)
DrawState = DrawStates.ResizeObjectResize
End If
Case DrawStates.ResizeObjectResize
End Select
UpdateGraphics()
End Sub
''' <summary>
''' forward to pcb
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub DoubleBuffer_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DoubleBuffer.MouseMove
If e.Button = MouseButtons.Middle Then
TranslateX = TranslateStartX + ConvertX(e.X) - ConvertX(MiddleClickPoint.Location.X)
TranslateY = TranslateStartY + ConvertY(e.Y) - ConvertY(MiddleClickPoint.Location.Y)
End If
MovePoint.Location = e.Location
Select Case DrawState
Case DrawStates.DrawObject, DrawStates.DrawDevicePins
If e.Button = MouseButtons.Left Then
If Distance(LeftClickPoint.Location, e.Location) > 5 Then DrawObject.AutoScale(Me, ConvertLocation(LeftClickPoint.Location), ConvertLocation(e.Location))
Else
DrawObject.Center = ConvertLocation(e.Location)
End If
PCB.GetLayer(PCB.LayerTypes.LayerTypeBottomDrawing).LayerObjects.Remove(DrawObject)
PCB.GetLayer(PCB.LayerTypes.LayerTypeTopDrawing).LayerObjects.Remove(DrawObject)
If WindowType = PCB.WindowTypes.WindowTypeTop Then
PCB.GetLayer(PCB.LayerTypes.LayerTypeTopDrawing).LayerObjects.Add(DrawObject)
End If
If WindowType = PCB.WindowTypes.WindowTypeBottom Then
PCB.GetLayer(PCB.LayerTypes.LayerTypeBottomDrawing).LayerObjects.Add(DrawObject)
End If
If DrawState = DrawStates.DrawDevicePins Then
InfoText = ConnectDevicePin.DevicePin.GetUniquePadName(ConnectDevicePin.EagleDevicePadName) 'display info about the pin
End If
Case DrawStates.MovePCBImage
If e.Button = Windows.Forms.MouseButtons.Left Then
DrawObject.Location = New Point(m_StartLocation.X + ConvertX(LeftClickPoint.Location.X) - ConvertX(e.X), m_StartLocation.Y + ConvertY(LeftClickPoint.Location.Y) - ConvertY(e.Y))
End If
Case DrawStates.MoveObjects
Dim SelectedObjects As ReadOnlyDictionary(Of Integer, SelectableLayerObject) = PCB.GetSelectedLayerObjects()
Dim Move As PointF = New PointF(ConvertX(e.X) - m_StartLocation.X, ConvertY(e.Y) - m_StartLocation.Y)
For Each SelectedObject As KeyValuePair(Of Integer, SelectableLayerObject) In SelectedObjects
SelectedObject.Value.Center = New PointF(SelectedObject.Value.StartCenter.X + Move.X, SelectedObject.Value.StartCenter.Y + Move.Y)
Next
Case DrawStates.ResizeObjectSelect 'wait for resize object to be selected, do nothing here
Case DrawStates.ResizeObjectSelected 'the resize object is selected
Dim SmallestDistance As Single = Single.MaxValue
Dim SmallestDistancePoint As ResizePoint
For Each Point As ResizePoint In ResizeInfo.ResizePoints
Dim Dist As Single = Distance(Point.Location, ConvertLocation(e.Location))
If Dist < SmallestDistance Then
SmallestDistance = Dist
SmallestDistancePoint = Point
End If
Next
If SmallestDistance <= 2 Then
Cursor = SmallestDistancePoint.GetCursor()
ResizeInfo.ResizingType = SmallestDistancePoint.ResizeType
Else
ResizeInfo.ResizingType = ResizePointType.ResizeNone
Cursor = Cursors.Default
End If
Case DrawStates.ResizeObjectResize 'actual resizing
ResizeObject(ResizeInfo.ResizeObject, ResizeInfo.ResizeStartLocation, ResizeInfo.ResizingRefPoint, ConvertLocation(e.Location), ResizeInfo.ResizingType)
Case DrawStates.DrawRouteBegin
PCB.UnHighlightAllObjects(True)
Dim ObjTypes As New List(Of Type)
ObjTypes.Add(GetType(SMDPad))
ObjTypes.Add(GetType(ThroughHolePad))
ObjTypes.Add(GetType(RouteJunction))
ObjTypes.Add(GetType(Via))
Dim Closest As LayerObject = PCB.GetClosestObject(WindowType, ConvertLocation(e.Location), ObjTypes, 20 / m_Scale, DrawObject)
If Closest IsNot Nothing Then PCB.HighlightObject(Closest)
Case DrawStates.DrawRouteEnd
If DrawRouteWindow = WindowType Then
PCB.UnHighlightAllObjects(True)
Dim ObjTypes As New List(Of Type)
Dim Route As Route = CType(DrawObject, Route)
ObjTypes.Add(GetType(SMDPad))
ObjTypes.Add(GetType(ThroughHolePad))
ObjTypes.Add(GetType(RouteJunction))
ObjTypes.Add(GetType(Via))
Dim Closest As LayerObject = PCB.GetClosestObject(WindowType, ConvertLocation(e.Location), ObjTypes, 20 / m_Scale, DrawObject)
If Closest IsNot Nothing Then PCB.HighlightObject(Closest)
If Route.RoutePoints.Count > 0 Then Route.LastRoutePoint.Location = ConvertLocation(e.Location)
End If
Case DrawStates.SplitRoute
For i As Integer = 0 To m_SplitRouteLines.Length - 1
PCB.GetLayer(PCB.LayerTypes.LayerTypeBottomDrawing).LayerObjects.Remove(m_SplitRouteLines(i))
PCB.GetLayer(PCB.LayerTypes.LayerTypeTopDrawing).LayerObjects.Remove(m_SplitRouteLines(i))
Next
m_SplitRouteLines(0).Highlighted = True
m_SplitRouteLines(1).Highlighted = True
Dim DrawLayer As PCB.LayerTypes = unPCB.PCB.LayerTypes.LayerTypeBottomDrawing
Dim RouteLayer As PCB.LayerTypes = unPCB.PCB.LayerTypes.LayerTypeBottomRoute
If WindowType = PCB.WindowTypes.WindowTypeTop Then
DrawLayer = unPCB.PCB.LayerTypes.LayerTypeTopDrawing
RouteLayer = unPCB.PCB.LayerTypes.LayerTypeTopRoute
End If
Dim MaxDistance As Single = 50 / m_Scale
Dim ClosestRoute As Route = Nothing
Dim ClosestRoutePointIndex As Integer = -1
For Each LayerObject As LayerObject In PCB.GetLayer(RouteLayer).LayerObjects
If TypeOf LayerObject Is Route Then
Dim TmpIndex As Integer = CType(LayerObject, Route).GetClosestRoutePointIndex(ConvertLocation(e.Location), MaxDistance, MaxDistance)
If TmpIndex >= 0 Then
ClosestRoute = CType(LayerObject, Route)
ClosestRoutePointIndex = TmpIndex
End If
End If
Next
If ClosestRoute IsNot Nothing Then
m_SplitRouteLines(0).Points(0) = ClosestRoute.GetFirstRouteSegmentLocation(ClosestRoutePointIndex)
m_SplitRouteLines(0).Points(1) = ConvertLocation(e.Location)
m_SplitRouteLines(1).Points(0) = ConvertLocation(e.Location)
m_SplitRouteLines(1).Points(1) = ClosestRoute.GetSecondRouteSegementLocation(ClosestRoutePointIndex)
PCB.GetLayer(DrawLayer).LayerObjects.Add(m_SplitRouteLines(0))
PCB.GetLayer(DrawLayer).LayerObjects.Add(m_SplitRouteLines(1))
End If
End Select
UpdateGraphics()
End Sub
''' <summary>
''' forwardto pcb
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub DoubleBuffer_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DoubleBuffer.MouseUp
If e.Button = MouseButtons.Middle Then
TranslateX = TranslateStartX + ConvertX(e.X) - ConvertX(MiddleClickPoint.Location.X)
TranslateY = TranslateStartY + ConvertY(e.Y) - ConvertY(MiddleClickPoint.Location.Y)
End If
Select Case DrawState
Case DrawStates.DrawObject
If e.Button = MouseButtons.Left Then
If DrawObject.Width > 0.001 AndAlso DrawObject.Height > 0.001 Then
PCB.PlaceObject(DrawObject, WindowType)
ResetDrawState()
End If
End If
Case DrawStates.DrawDevicePins
Select Case e.Button
Case Windows.Forms.MouseButtons.Left 'left button to place pad
If DrawObject.Width > 0.001 AndAlso DrawObject.Height > 0.001 Then
PCB.PlaceObject(DrawObject, WindowType)
sPCB.GetLayer(PCB.LayerTypes.LayerTypeBottomDrawing).LayerObjects.Remove(DrawObject)
sPCB.GetLayer(PCB.LayerTypes.LayerTypeTopDrawing).LayerObjects.Remove(DrawObject)
ConnectDevicePin.DevicePin.AddPad(DrawObject, ConnectDevicePin.EagleDevicePadName) 'add pad to connectdevicepin
CType(DrawObject, Pad).Name = ConnectDevicePin.DevicePin.GetUniquePadName(ConnectDevicePin.EagleDevicePadName)
InfoText = ""
ConnectDevicePin = ConnectDevice.GetUnconnectedPin() 'get next unconnected or not fully connected device pin
If ConnectDevicePin.DevicePin IsNot Nothing Then 'we are at the end
If ConnectDevicePin.DevicePin.DefaultPadType(ConnectDevicePin.EagleDevicePadName).Name = DrawObject.GetType.Name Then 'same pin type, clone object
DrawObject = CType(DrawObject.Clone(), LayerObject)
Else
DrawObject = Activator.CreateInstance(System.Type.GetType("unPCB." & ConnectDevicePin.DevicePin.DefaultPadType(ConnectDevicePin.EagleDevicePadName).Name, True, True))
End If
sPCB.Cursor = Cursors.Cross
Else
ResetDrawState()
End If
End If
Case Windows.Forms.MouseButtons.Right 'with right mouse we can toggle between SMD and throughole pads
PCB.GetLayer(PCB.LayerTypes.LayerTypeBottomDrawing).LayerObjects.Remove(DrawObject)
PCB.GetLayer(PCB.LayerTypes.LayerTypeTopDrawing).LayerObjects.Remove(DrawObject)
If DrawObject.GetType().Name = GetType(SMDPad).Name Then
DrawObject = New ThroughHolePad()
Else
DrawObject = New SMDPad()
End If
End Select
Case DrawStates.SelectObjects
PCB.UnHighlightAllObjects()
If e.Button = MouseButtons.Left Then
PCB.SelectObjects(WindowType, ConvertLocation(e.Location), My.Computer.Keyboard.CtrlKeyDown)
ElseIf e.Button = Windows.Forms.MouseButtons.Right Then
Menu_SelectConnectedPads.Enabled = PCB.GetSelectedLayerObjects(GetType(Pad)).Count > 0
HighlightConnectedPadsToolStripMenuItem.Enabled = Menu_SelectConnectedPads.Enabled
MenuRightClickObject.Show(DoubleBuffer, e.Location)
End If
Case DrawStates.Connect
Case DrawStates.MovePCBImage
If e.Button = Windows.Forms.MouseButtons.Left Then
PCB.AddUndoItem(New UndoRedoMovePCBImage(PCB, DrawObject, m_StartLocation))
End If
Case DrawStates.StartMoveObjects
If e.Button = Windows.Forms.MouseButtons.Left Then 'select objects
If PCB.GetSelectedLayerObjects().Count = 0 Or My.Computer.Keyboard.CtrlKeyDown Then
PCB.SelectObjects(WindowType, ConvertLocation(e.Location), My.Computer.Keyboard.CtrlKeyDown)
End If
If Not My.Computer.Keyboard.CtrlKeyDown Then
Dim SelectedObjects As ReadOnlyDictionary(Of Integer, SelectableLayerObject) = PCB.GetSelectedLayerObjects()
For Each SelectedObject As KeyValuePair(Of Integer, SelectableLayerObject) In SelectedObjects
SelectedObject.Value.StartCenter = SelectedObject.Value.Center
Next
m_StartLocation = ConvertLocation(e.Location)
DrawState = DrawStates.MoveObjects 'no ctrl key, go to move!
PCB.Cursor = Cursors.Cross
End If
End If
Case DrawStates.MoveObjects
If e.Button = Windows.Forms.MouseButtons.Left Then 'end moving objects
PCB.AddUndoItem(New UndoRedoMoveLayerObject(PCB, PCB.GetSelectedLayerObjects))
PCB.DeselectAllObjects()
DrawState = DrawStates.StartMoveObjects 'go back
PCB.Cursor = Cursors.Default
Else
ResetDrawState()
End If
Case DrawStates.ResizeObjectSelect
If e.Button = Windows.Forms.MouseButtons.Left Then
Dim ResizeObject As LayerObject = PCB.SelectObjects(WindowType, ConvertLocation(e.Location), False)
SelectResizeObject(ResizeObject)
End If
Case DrawStates.ResizeObjectSelected
Case DrawStates.ResizeObjectResize
' add undo item, end resizeing
If e.Button = Windows.Forms.MouseButtons.Left Then
PCB.AddUndoItem(New UndoRedoResizeLayerObject(PCB, ResizeInfo.ResizeObject, ResizeInfo.ResizeStartLocation))
DrawState = DrawStates.ResizeObjectSelect
SelectResizeObject(ResizeInfo.ResizeObject)
End If
Case DrawStates.DrawRouteBegin
If e.Button = Windows.Forms.MouseButtons.Left Then 'start first point of a route
'find the closest object and connect to that
Dim Route As Route = CType(DrawObject, Route)
If Route.StartPad Is Nothing Then
Dim ObjTypes As New List(Of Type)
ObjTypes.Add(GetType(SMDPad))
ObjTypes.Add(GetType(ThroughHolePad))
ObjTypes.Add(GetType(RouteJunction))
ObjTypes.Add(GetType(Via))
Dim Closest As LayerObject = PCB.GetClosestObject(WindowType, ConvertLocation(e.Location), ObjTypes, 20 / m_Scale, Route)
If Closest IsNot Nothing Then 'check if we are near a pad
DrawRouteWindow = WindowType
If DrawRouteWindow = PCB.WindowTypes.WindowTypeTop Then 'add to drawlayer
PCB.GetLayer(PCB.LayerTypes.LayerTypeTopDrawing).LayerObjects.Add(DrawObject)
End If
If DrawRouteWindow = PCB.WindowTypes.WindowTypeBottom Then
PCB.GetLayer(PCB.LayerTypes.LayerTypeBottomDrawing).LayerObjects.Add(DrawObject)
End If
Route.StartPad = Closest 'start
Route.AddRoutePoint(ConvertLocation(e.Location)) 'add the first route point
DrawState = DrawStates.DrawRouteEnd
End If
Else
DrawState = DrawStates.DrawRouteEnd
End If
End If
Case DrawStates.DrawRouteEnd
If DrawRouteWindow = WindowType Then
Dim Route As Route = CType(DrawObject, Route)
If Route.EndPad Is Nothing Then
If e.Button = Windows.Forms.MouseButtons.Left Then 'finish the second point of a route, then start a new one unless we connect to a pad
'find the closest object and connect to that
Dim ObjTypes As New List(Of Type)
ObjTypes.Add(GetType(SMDPad))
ObjTypes.Add(GetType(ThroughHolePad))
ObjTypes.Add(GetType(RouteJunction))
ObjTypes.Add(GetType(Via))
Dim Closest As LayerObject = PCB.GetClosestObject(WindowType, ConvertLocation(e.Location), ObjTypes, 20 / m_Scale, Route)
If Closest IsNot Nothing Then
Route.RemoveRoutePoint(Route.LastRoutePoint)
PCB.GetLayer(unPCB.PCB.LayerTypes.LayerTypeBottomDrawing).LayerObjects.Remove(DrawObject)
PCB.GetLayer(unPCB.PCB.LayerTypes.LayerTypeTopDrawing).LayerObjects.Remove(DrawObject)
Route.EndPad = Closest
PCB.PlaceObject(DrawObject, WindowType) 'add the next point
PCB.ConnectionMatrix.ConnectPads(Route.StartPad, Route.EndPad)
DrawObject = New Route()
DrawState = DrawStates.DrawRouteBegin
Else
Route.AddRoutePoint(ConvertLocation(e.Location))
End If
ElseIf e.Button = Windows.Forms.MouseButtons.Right Then
If Route.RoutePoints.Count > 0 Then
Route.RemoveRoutePoint(Route.LastRoutePoint)
If Route.RoutePoints.Count > 0 Then
m_LastRoutePointLocation = Route.LastRoutePoint.Location
Else
ResetDrawState(False)
End If
End If
End If
Else
If e.Button = Windows.Forms.MouseButtons.Left OrElse e.Button = Windows.Forms.MouseButtons.Right Then
PCB.GetLayer(unPCB.PCB.LayerTypes.LayerTypeBottomDrawing).LayerObjects.Remove(DrawObject)
PCB.GetLayer(unPCB.PCB.LayerTypes.LayerTypeTopDrawing).LayerObjects.Remove(DrawObject)
If e.Button = Windows.Forms.MouseButtons.Left Then Route.RemoveRoutePoint(Route.LastRoutePoint) 'double left click wil first insert a routepoint which must be deleted first
PCB.PlaceObject(DrawObject, WindowType) 'add the next point
PCB.ConnectionMatrix.ConnectPads(Route.StartPad, Route.EndPad)
DrawObject = New Route()
DrawState = DrawStates.DrawRouteBegin
End If
End If
Else
Beep()
End If
Case DrawStates.SplitRoute
If e.Button = Windows.Forms.MouseButtons.Left Then
For i As Integer = 0 To m_SplitRouteLines.Length - 1
PCB.GetLayer(PCB.LayerTypes.LayerTypeBottomDrawing).LayerObjects.Remove(m_SplitRouteLines(i))
PCB.GetLayer(PCB.LayerTypes.LayerTypeTopDrawing).LayerObjects.Remove(m_SplitRouteLines(i))
Next
Dim RouteLayer As PCB.LayerTypes = unPCB.PCB.LayerTypes.LayerTypeBottomRoute
If WindowType = PCB.WindowTypes.WindowTypeTop Then
RouteLayer = unPCB.PCB.LayerTypes.LayerTypeTopRoute
End If
Dim MaxDistance As Single = 50 / m_Scale
Dim ClosestRoute As Route = Nothing
Dim ClosestRoutePointIndex As Integer = -1
For Each LayerObject As LayerObject In PCB.GetLayer(RouteLayer).LayerObjects 'find the route to add the new route point to
If TypeOf LayerObject Is Route Then
Dim TmpIndex As Integer = CType(LayerObject, Route).GetClosestRoutePointIndex(ConvertLocation(e.Location), MaxDistance, MaxDistance)
If TmpIndex >= 0 Then
ClosestRoute = CType(LayerObject, Route)
ClosestRoutePointIndex = TmpIndex
End If
End If
Next
If ClosestRoute IsNot Nothing Then 'add new route point
Dim Point As RoutePoint = New RoutePoint(ConvertLocation(e.Location), ClosestRoute, ClosestRoutePointIndex)
ClosestRoute.AddRoutePoint(ClosestRoutePointIndex, Point)
Point.PlaceObject(PCB, WindowType)
PCB.AddObject(Point)
End If
End If
End Select
UpdateGraphics()
End Sub
''' <summary>
''' Selects an object for resizing, also adjust drawstate if not correct
''' </summary>
''' <param name="LayerObject"></param>
''' <remarks></remarks>
Private Sub SelectResizeObject(ByVal LayerObject As SelectableLayerObject)
If Not DrawState = DrawStates.ResizeObjectSelect Then
ResetDrawState(False)
SetDrawState(DrawStates.ResizeObjectSelect)
PCB.SelectObject(LayerObject)
End If
ResizeInfo.ResizeObject = LayerObject
ReDim ResizeInfo.ResizePoints(0 To 7)
CalcResizePoints(LayerObject)
ResizeInfo.ResizeStartLocation = ResizeInfo.ResizeObject.Rect
ResizeInfo.IsResizing = False
ResizeInfo.ResizingType = ResizePointType.ResizeNone
ResizeInfo.WindowType = WindowType
SetDrawState(DrawStates.ResizeObjectSelected) 'the object is now selected, we can start resizing it
End Sub
Private Sub CalcResizePoints(ByVal LayerObject As LayerObject)
ResizeInfo.ResizePoints(0) = New ResizePoint(New PointF(ResizeInfo.ResizeObject.Rect.Left, ResizeInfo.ResizeObject.Rect.Top), ResizePointType.ResizeNW, IIf(PCB.HorizontalMirror(WindowType) Xor PCB.VerticalMirror(WindowType), ResizePointType.ResizeSW, ResizePointType.ResizeNW))
ResizeInfo.ResizePoints(1) = New ResizePoint(New PointF(ResizeInfo.ResizeObject.Rect.Right, ResizeInfo.ResizeObject.Rect.Top), ResizePointType.ResizeNE, IIf(PCB.HorizontalMirror(WindowType) Xor PCB.VerticalMirror(WindowType), ResizePointType.ResizeSE, ResizePointType.ResizeNE))
ResizeInfo.ResizePoints(2) = New ResizePoint(New PointF(ResizeInfo.ResizeObject.Rect.Right, ResizeInfo.ResizeObject.Rect.Bottom), ResizePointType.ResizeSE, IIf(PCB.HorizontalMirror(WindowType) Xor PCB.VerticalMirror(WindowType), ResizePointType.ResizeNE, ResizePointType.ResizeSE))
ResizeInfo.ResizePoints(3) = New ResizePoint(New PointF(ResizeInfo.ResizeObject.Rect.Left, ResizeInfo.ResizeObject.Rect.Bottom), ResizePointType.ResizeSW, IIf(PCB.HorizontalMirror(WindowType) Xor PCB.VerticalMirror(WindowType), ResizePointType.ResizeNW, ResizePointType.ResizeSW))
ResizeInfo.ResizePoints(4) = New ResizePoint(MidPoint(ResizeInfo.ResizePoints(0).Location, ResizeInfo.ResizePoints(1).Location), ResizePointType.ResizeN, ResizePointType.ResizeN)
ResizeInfo.ResizePoints(5) = New ResizePoint(MidPoint(ResizeInfo.ResizePoints(1).Location, ResizeInfo.ResizePoints(2).Location), ResizePointType.ResizeE, ResizePointType.ResizeE)
ResizeInfo.ResizePoints(6) = New ResizePoint(MidPoint(ResizeInfo.ResizePoints(2).Location, ResizeInfo.ResizePoints(3).Location), ResizePointType.ResizeS, ResizePointType.ResizeS)
ResizeInfo.ResizePoints(7) = New ResizePoint(MidPoint(ResizeInfo.ResizePoints(3).Location, ResizeInfo.ResizePoints(0).Location), ResizePointType.ResizeW, ResizePointType.ResizeW)
End Sub
Private Sub ResizeObject(ByVal LayerObject As LayerObject, ByVal StartSize As RectangleF, ByVal RefPoint As PointF, ByVal ClickPoint As PointF, ByVal Direction As ResizePointType)
Select Case Direction
Case ResizePointType.ResizeE
LayerObject.Width = StartSize.Width + ClickPoint.X - RefPoint.X
Case ResizePointType.ResizeN
LayerObject.Location = New PointF(LayerObject.Location.X, StartSize.Location.Y + ClickPoint.Y - RefPoint.Y)
LayerObject.Height = StartSize.Height + RefPoint.Y - ClickPoint.Y
Case ResizePointType.ResizeNE
LayerObject.Location = New PointF(LayerObject.Location.X, StartSize.Location.Y + ClickPoint.Y - RefPoint.Y)
LayerObject.Width = StartSize.Width + ClickPoint.X - RefPoint.X
LayerObject.Height = StartSize.Height + RefPoint.Y - ClickPoint.Y
Case ResizePointType.ResizeNW
LayerObject.Location = New PointF(StartSize.X + ClickPoint.X - RefPoint.X, StartSize.Location.Y + ClickPoint.Y - RefPoint.Y)
LayerObject.Width = StartSize.Width + RefPoint.X - ClickPoint.X
LayerObject.Height = StartSize.Height + RefPoint.Y - ClickPoint.Y
Case ResizePointType.ResizeS
LayerObject.Height = StartSize.Height + ClickPoint.Y - RefPoint.Y
Case ResizePointType.ResizeSE
LayerObject.Height = StartSize.Height + ClickPoint.Y - RefPoint.Y
LayerObject.Width = StartSize.Width + ClickPoint.X - RefPoint.X
Case ResizePointType.ResizeSW
LayerObject.Location = New PointF(StartSize.X + ClickPoint.X - RefPoint.X, StartSize.Location.Y)
LayerObject.Height = StartSize.Height + ClickPoint.Y - RefPoint.Y
LayerObject.Width = StartSize.Width + RefPoint.X - ClickPoint.X
Case ResizePointType.ResizeW
LayerObject.Location = New PointF(StartSize.X + ClickPoint.X - RefPoint.X, StartSize.Location.Y)
LayerObject.Width = StartSize.Width + RefPoint.X - ClickPoint.X
End Select
CalcResizePoints(LayerObject)
End Sub
''' <summary>
''' Update graphics
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub DoubleBuffer_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles DoubleBuffer.MouseEnter
UpdateGraphics()
End Sub
''' <summary>
''' adjust window scale
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub DoubleBuffer_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DoubleBuffer.MouseWheel
Dim xBefore As Integer = ConvertX(e.X)
Dim yBefore As Integer = ConvertY(e.Y)
Dim xAfter As Integer
Dim yAfter As Integer
If e.Delta > 0 Then
m_Scale = m_Scale / 0.9
ElseIf e.Delta < 0 Then
m_Scale = m_Scale * 0.9
End If
xAfter = ConvertX(e.X)
yAfter = ConvertY(e.Y)
m_TranslateX += -(xBefore - xAfter)
m_TranslateY += -(yBefore - yAfter)
UpdateGraphics()
End Sub
''' <summary>
''' tells the doublebuffered image box to update the graphics (fire paint event)
''' </summary>
''' <remarks></remarks>
Public Sub UpdateGraphics()
DoubleBuffer.Refresh()
End Sub
''' <summary>
''' Paints everything
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub DoubleBuffer_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles DoubleBuffer.Paint
Dim HorizontalFlip As Double = 1
Dim VerticalFlip As Double = 1
Dim Graphics As System.Drawing.Graphics
Dim TmpTranslateX As Single, TmpTranslateY As Single
Graphics = e.Graphics
'Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low ' // or NearestNeighbour
'Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None
'Graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.None
'Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed
'Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel
If PCB.HorizontalMirror(WindowType) Then HorizontalFlip = -1.0
If PCB.VerticalMirror(WindowType) Then VerticalFlip = -1.0
Graphics.Clear(Color.Transparent)
Graphics.ResetTransform()
'http://www.vb-helper.com/howto_net_draw_flipped_text.html
Graphics.ScaleTransform(m_Scale * HorizontalFlip, m_Scale * VerticalFlip) 'flip horizontally
TmpTranslateX = m_TranslateX
If PCB.VerticalMirror(WindowType) Then
TmpTranslateY -= m_Height
End If
TmpTranslateY = m_TranslateY
If PCB.HorizontalMirror(WindowType) Then
TmpTranslateX -= m_Width
End If
Graphics.TranslateTransform(TmpTranslateX, TmpTranslateY)
For Each Layer As KeyValuePair(Of PCB.LayerTypes, Layer) In PCB.Layers
If PCB.GetWindowTypeOfLayerType(Layer.Key) = WindowType Then
Layer.Value.Draw(Graphics)
End If
Next
'If DrawState = DrawStates.ResizeObjectSelected Or DrawState = DrawStates.ResizeObjectResize Then
If ResizeInfo.WindowType = WindowType Then
If ResizeInfo.ResizeObject IsNot Nothing Then
Dim Pen As New Pen(Color.FromArgb(225, 255, 128, 0), 2)
Dim Brush As New SolidBrush(Color.FromArgb(225, 255, 128, 0))
Pen.DashStyle = Drawing2D.DashStyle.Dash
Pen.EndCap = Drawing2D.LineCap.SquareAnchor
Pen.StartCap = Drawing2D.LineCap.SquareAnchor
Graphics.DrawLine(Pen, ResizeInfo.ResizePoints(0).Location.X, ResizeInfo.ResizePoints(0).Location.Y, ResizeInfo.ResizePoints(1).Location.X, ResizeInfo.ResizePoints(1).Location.Y)
Graphics.DrawLine(Pen, ResizeInfo.ResizePoints(1).Location.X, ResizeInfo.ResizePoints(1).Location.Y, ResizeInfo.ResizePoints(2).Location.X, ResizeInfo.ResizePoints(2).Location.Y)
Graphics.DrawLine(Pen, ResizeInfo.ResizePoints(2).Location.X, ResizeInfo.ResizePoints(2).Location.Y, ResizeInfo.ResizePoints(3).Location.X, ResizeInfo.ResizePoints(3).Location.Y)
Graphics.DrawLine(Pen, ResizeInfo.ResizePoints(3).Location.X, ResizeInfo.ResizePoints(3).Location.Y, ResizeInfo.ResizePoints(0).Location.X, ResizeInfo.ResizePoints(0).Location.Y)
Graphics.FillRectangle(Brush, New RectangleF(ResizeInfo.ResizePoints(4).Location.X - 2, ResizeInfo.ResizePoints(4).Location.Y - 2, 2, 4))
Graphics.FillRectangle(Brush, New RectangleF(ResizeInfo.ResizePoints(5).Location.X - 2, ResizeInfo.ResizePoints(5).Location.Y - 2, 4, 2))
Graphics.FillRectangle(Brush, New RectangleF(ResizeInfo.ResizePoints(6).Location.X - 2, ResizeInfo.ResizePoints(6).Location.Y - 2, 2, 4))
Graphics.FillRectangle(Brush, New RectangleF(ResizeInfo.ResizePoints(7).Location.X - 2, ResizeInfo.ResizePoints(7).Location.Y - 2, 4, 2))
'Graphics.DrawLine(Pen, ResizeInfo.ResizePoints(4).Location.X, ResizeInfo.ResizePoints(4).Location.Y, ResizeInfo.ResizePoints(4).Location.X, ResizeInfo.ResizePoints(4).Location.Y)
'Graphics.DrawLine(Pen, ResizeInfo.ResizePoints(5).Location.X, ResizeInfo.ResizePoints(5).Location.Y, ResizeInfo.ResizePoints(5).Location.X, ResizeInfo.ResizePoints(5).Location.Y)
'Graphics.DrawLine(Pen, ResizeInfo.ResizePoints(6).Location.X, ResizeInfo.ResizePoints(6).Location.Y, ResizeInfo.ResizePoints(6).Location.X, ResizeInfo.ResizePoints(6).Location.Y)
'Graphics.DrawLine(Pen, ResizeInfo.ResizePoints(7).Location.X, ResizeInfo.ResizePoints(7).Location.Y, ResizeInfo.ResizePoints(7).Location.X, ResizeInfo.ResizePoints(7).Location.Y)
'Graphics.DrawRectangle(Pen, DrawObject.Rect.X, DrawObject.Rect.Y, DrawObject.Rect.Width, DrawObject.Rect.Height)
End If
End If
If InfoText <> "" Then
Dim Cont1 As Drawing2D.GraphicsContainer = Graphics.BeginContainer()
Graphics.TranslateTransform(ConvertX(MovePoint.Location.X + 5), ConvertY(MovePoint.Location.Y + 5))
Dim Cont2 As Drawing2D.GraphicsContainer = Graphics.BeginContainer()
If PCB.HorizontalMirror(WindowType) Then
Graphics.ScaleTransform(-1, 1)
End If
If PCB.VerticalMirror(WindowType) Then
Graphics.ScaleTransform(1, -1)
End If
Graphics.DrawString(InfoText, Me.Font, New SolidBrush(Color.Red), 0, 0)
Graphics.EndContainer(Cont2)
Graphics.EndContainer(Cont1)
End If
Select Case DrawState
Case DrawStates.AutoRouter
StatusBar.Text = "Auto router"
Case DrawStates.Connect
StatusBar.Text = "Connect pins"
Case DrawStates.DrawDevicePins
StatusBar.Text = "Place pin " & InfoText
Case DrawStates.DrawObject
StatusBar.Text = "Draw object"
Case DrawStates.MoveObjects
StatusBar.Text = "Move object"
Case DrawStates.MovePCBImage
StatusBar.Text = "Move background image"
Case DrawStates.None
StatusBar.Text = "Ready"
Case DrawStates.ResizeObjectResize
StatusBar.Text = "Resize object"
Case DrawStates.ResizeObjectSelect
StatusBar.Text = "Select object to resize"
Case DrawStates.ResizeObjectSelected
Case DrawStates.SelectObjects
StatusBar.Text = "Select objects"
Case DrawStates.StartMoveObjects
StatusBar.Text = "Move object"
End Select
End Sub
''' <summary>
''' Start drawing a pad
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub SMDPadToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SMDPadToolStripMenuItem.Click
For Each LayerWindow As FrmLayer In LayerWindows
LayerWindow.ToolStripSplitButtonDrawPad.Image = SMDPadToolStripMenuItem.Image
LayerWindow.ToolStripSplitButtonDrawPad.Tag = DrawTools.DrawSMD
Next
StartDrawObject(New SMDPad())
End Sub
''' <summary>
''' Start drawing throughole pad
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub ThroughHolePadToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThroughHolePadToolStripMenuItem.Click
For Each LayerWindow As FrmLayer In LayerWindows
LayerWindow.ToolStripSplitButtonDrawPad.Image = ThroughHolePadToolStripMenuItem.Image
LayerWindow.ToolStripSplitButtonDrawPad.Tag = DrawTools.DrawThrougHole
Next
StartDrawObject(New ThroughHolePad())
End Sub
''' <summary>
''' gets or sets the scale for the graphics displayed
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property DrawScale() As Double
Get
Return m_Scale
End Get
Set(ByVal value As Double)
m_Scale = value
End Set
End Property
''' <summary>
''' gets or sets the width of the PCB (also set through constructor from pcb)
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property PCBWidth() As Single
Get
Return m_Width
End Get
Set(ByVal value As Single)
m_Width = value
End Set
End Property
''' <summary>
''' Gets or sets the height of the PCB (also set through constructor from pcb)
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property PCBHeight() As Single
Get
Return m_Height
End Get
Set(ByVal value As Single)
m_Height = value
End Set
End Property
''' <summary>
''' gets or sets the translate X
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property TranslateX() As Single
Get
Return m_TranslateX
End Get
Set(ByVal value As Single)
m_TranslateX = value
End Set
End Property
''' <summary>
''' gets or sets the translate Y
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property TranslateY() As Single
Get
Return m_TranslateY
End Get
Set(ByVal value As Single)
m_TranslateY = value
End Set
End Property
''' <summary>
''' Scales width, size pixels on the screen to a width on the pcb
''' </summary>
''' <param name="Width"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Function ScaleWidth(ByVal Width As Integer) As Integer
Return Width / m_Scale
End Function
''' <summary>
''' Scales height, size pixels on the screen to a height on the pcb
''' </summary>
''' <param name="Height"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Function ScaleHeight(ByVal Height As Integer) As Integer
Return Height / m_Scale
End Function
''' <summary>
''' Converts location X on the screen (window pixels) to X location on the PCB
''' </summary>
''' <param name="x"></param>
''' <returns></returns>
''' <remarks></remarks>
Public Function ConvertX(ByVal x As Single) As Single
If PCB.HorizontalMirror(WindowType) Then
Return x / -m_Scale + m_Width - m_TranslateX
Else
Return x / m_Scale - m_TranslateX