-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathClsUndoRedo.vb
980 lines (804 loc) · 26.9 KB
/
ClsUndoRedo.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
Public MustInherit Class UndoRedoItem
Protected m_PCB As PCB
Protected m_ChangedPCB As Boolean 'is true if we changed the pcb project (if changed are already made by another action, this is false
Public MustOverride ReadOnly Property Description() As String
Public Sub New(ByVal PCB As PCB)
m_ChangedPCB = Not PCB.IsChanged
If m_ChangedPCB Then PCB.IsChanged = True
m_PCB = PCB
End Sub
Public Overridable Sub Undo()
If m_PCB.IsChanged = False Then 'project has been saved and we will change it if we undo
m_ChangedPCB = True
End If
If m_ChangedPCB Then
m_PCB.IsChanged = Not m_PCB.IsChanged
End If
End Sub
Public Overridable Sub Redo()
If m_PCB.IsChanged = False Then 'project has been saved and we will change it if we redo
m_ChangedPCB = True
End If
If m_ChangedPCB Then
m_PCB.IsChanged = Not m_PCB.IsChanged
End If
End Sub
End Class
''' <summary>
''' Undo / Redo any connection type of 2 or more pads
''' </summary>
''' <remarks></remarks>
Public Class UndoRedoConnect
Inherits UndoRedoItem
Dim m_UndoConnections As ConnectionMatrix
Dim m_RedoConnections As ConnectionMatrix
Dim m_ByAutoRouter As Boolean
Public Sub New(ByVal PCB As PCB)
MyBase.New(PCB)
m_UndoConnections = PCB.ConnectionMatrix.BackUp()
End Sub
''' <summary>
''' If the connection was made by auto router
''' </summary>
''' <param name="PCB"></param>
''' <param name="ByAutoRouter"></param>
''' <remarks></remarks>
Public Sub New(ByVal PCB As PCB, ByVal ByAutoRouter As Boolean)
Me.New(PCB)
m_ByAutoRouter = ByAutoRouter
End Sub
Public Overrides ReadOnly Property Description() As String
Get
Return "connect pads."
End Get
End Property
Public Overrides Sub Undo()
MyBase.Undo()
m_RedoConnections = m_PCB.ConnectionMatrix.BackUp() 'backup before undo
m_PCB.ConnectionMatrix.Restore(m_UndoConnections)
If m_ByAutoRouter Then
If IsFormOpen(GetType(FrmManualRoute)) Then
CType(GetForm(GetType(FrmManualRoute)), FrmManualRoute).NextCheck()
End If
End If
End Sub
Public Overrides Sub Redo()
MyBase.Undo()
m_PCB.ConnectionMatrix.Restore(m_RedoConnections)
If m_ByAutoRouter Then
If IsFormOpen(GetType(FrmManualRoute)) Then
CType(GetForm(GetType(FrmManualRoute)), FrmManualRoute).NextCheck()
End If
End If
End Sub
End Class
Public Class UndoRedoMovePCBImage
Inherits UndoRedoItem
Dim Loc As PointF
Dim RedoLoc As PointF
Dim Image As PCBImage
Public Sub New(ByVal PCB As PCB, ByVal Image As PCBImage, ByVal StartLocation As PointF)
MyBase.New(PCB)
Loc = StartLocation
Me.Image = Image
End Sub
Public Overrides ReadOnly Property Description() As String
Get
Return "move background"
End Get
End Property
Public Overrides Sub Redo()
MyBase.Redo()
Image.Location = New Point(RedoLoc.X, RedoLoc.Y)
End Sub
Public Overrides Sub Undo()
MyBase.Undo()
RedoLoc = Image.Location
Image.Location = New Point(Loc.X, Loc.Y)
End Sub
End Class
Public Class UndoRedoAddDevice
Inherits UndoRedoItem
Protected Device As Device
Public Sub New(ByVal PCB As PCB, ByVal Device As Device)
MyBase.New(PCB)
Me.Device = Device
End Sub
Public Overrides ReadOnly Property Description() As String
Get
Return "add device"
End Get
End Property
Public Overrides Sub Redo()
MyBase.Redo()
m_PCB.AddDevice(Device)
End Sub
Public Overrides Sub Undo()
MyBase.Undo()
m_PCB.RemoveDevice(Device)
End Sub
End Class
Public Class UndoRedoDeleteDevice
Inherits UndoRedoItem
Dim Connections As ConnectionMatrix
Dim RedoConnections As ConnectionMatrix
Dim Device As Device 'the device + device pins + connected pads remain in the memory by this pointer but are removed from the PCB project
'Dim m_UndoDeletePads As New Stack(Of UndoRedoDeletePad)
'Dim m_RedoDeletePads As New Stack(Of UndoRedoDeletePad)
Public Sub New(ByVal PCB As PCB, ByVal Device As Device)
MyBase.New(PCB)
Me.Device = Device
Connections = PCB.ConnectionMatrix.BackUp 'backup the connections
'For Each Pin As DevicePin In Device.Pins
' For Each Pad As Pad In Pin.Pads
' m_UndoDeletePads.Push(Pad.GetUndoDeleteItem(PCB))
' Next
'Next
End Sub
Public Overrides ReadOnly Property Description() As String
Get
Return "delete device"
End Get
End Property
Public Overrides Sub Redo()
MyBase.Redo()
'While m_RedoDeletePads.Count > 0
' Dim UndoItem As UndoRedoItem = m_RedoDeletePads.Pop()
' UndoItem.Redo()
' m_UndoDeletePads.Push(UndoItem)
'End While
m_PCB.ConnectionMatrix.Restore(RedoConnections)
m_PCB.RemoveDevice(Device)
End Sub
Public Overrides Sub Undo()
MyBase.Undo()
RedoConnections = m_PCB.ConnectionMatrix.BackUp
'While m_UndoDeletePads.Count > 0
' Dim RedoItem As UndoRedoItem = m_UndoDeletePads.Pop()
' RedoItem.Undo()
' m_UndoDeletePads.Push(RedoItem)
'End While
m_PCB.AddDevice(Device)
m_PCB.ConnectionMatrix.Restore(Connections)
End Sub
End Class
Public Class UndoRedoDeviceValueChange
Inherits UndoRedoItem
Dim m_Device As Device
Dim m_OldValue As String
Dim m_NewValue As String
Public Sub New(ByVal PCB As PCB, ByVal Device As Device, ByVal OldValue As String, ByVal NewValue As String)
MyBase.New(PCB)
m_Device = Device
m_OldValue = OldValue
m_NewValue = NewValue
End Sub
Public Overrides ReadOnly Property Description() As String
Get
Return "change value."
End Get
End Property
Public Overrides Sub Redo()
MyBase.Redo()
m_Device.Value = m_NewValue
End Sub
Public Overrides Sub Undo()
MyBase.Undo()
m_Device.Value = m_OldValue
End Sub
End Class
Public Class UndoRedoDeviceNameChange
Inherits UndoRedoItem
Dim m_Device As Device
Dim m_OldName As String
Dim m_NewName As String
Public Sub New(ByVal PCB As PCB, ByVal Device As Device, ByVal OldName As String, ByVal NewName As String)
MyBase.New(PCB)
m_Device = Device
m_OldName = OldName
m_NewName = NewName
End Sub
Public Overrides ReadOnly Property Description() As String
Get
Return "rename device."
End Get
End Property
Public Overrides Sub Redo()
MyBase.Redo()
m_Device.Name = m_NewName
End Sub
Public Overrides Sub Undo()
MyBase.Undo()
m_Device.Name = m_OldName
End Sub
End Class
Public Class UndoRedoNameChange
Inherits UndoRedoItem
Dim m_OldName As String
Dim m_NewName As String
Dim m_Object As LayerObject
Public Sub New(ByVal PCB As PCB, ByVal Obj As LayerObject, ByVal OldName As String, ByVal NewName As String)
MyBase.New(PCB)
m_Object = Obj
m_OldName = OldName
m_NewName = NewName
End Sub
Public Overrides ReadOnly Property Description() As String
Get
Return "change name " & m_OldName
End Get
End Property
Public Overrides Sub Redo()
MyBase.Redo()
m_Object.Name = m_NewName
End Sub
Public Overrides Sub Undo()
MyBase.Undo()
m_Object.Name = m_OldName
End Sub
End Class
Public Class UndoRedoMirrorBackgroundImage
Inherits UndoRedoItem
Dim m_HorizontalMirror As Boolean
Dim m_VerticalMirror As Boolean
Dim m_RedoHorizontalMirror As Boolean
Dim m_RedoVerticalMirror As Boolean
Dim m_WindowType As PCB.WindowTypes
Public Sub New(ByVal PCB As PCB, ByVal WindowType As PCB.WindowTypes)
MyBase.New(PCB)
m_HorizontalMirror = PCB.HorizontalMirror(WindowType)
m_VerticalMirror = PCB.VerticalMirror(WindowType)
m_PCB = PCB
m_WindowType = WindowType
End Sub
Public Overrides ReadOnly Property Description() As String
Get
Return "flip background"
End Get
End Property
Public Overrides Sub Redo()
MyBase.Redo()
m_PCB.HorizontalMirror(m_WindowType) = m_RedoHorizontalMirror
m_PCB.VerticalMirror(m_WindowType) = m_RedoVerticalMirror
End Sub
Public Overrides Sub Undo()
MyBase.Undo()
m_RedoHorizontalMirror = m_PCB.HorizontalMirror(m_WindowType)
m_RedoVerticalMirror = m_PCB.VerticalMirror(m_WindowType)
m_PCB.HorizontalMirror(m_WindowType) = m_HorizontalMirror
m_PCB.VerticalMirror(m_WindowType) = m_VerticalMirror
End Sub
End Class
Public Class UndoRedoResizeLayerObject
Inherits UndoRedoItem
Dim m_OriginalLocation As RectangleF
Dim m_NewLocation As RectangleF
Dim m_LayerObject As SelectableLayerObject
Public Sub New(ByVal PCB As PCB, ByVal LayerObject As SelectableLayerObject, ByVal OriginalLocation As RectangleF)
MyBase.New(PCB)
m_LayerObject = LayerObject
m_PCB = PCB
m_OriginalLocation = OriginalLocation
m_NewLocation = LayerObject.Rect
End Sub
Public Overrides ReadOnly Property Description() As String
Get
Return "resize"
End Get
End Property
Public Overrides Sub Redo()
MyBase.Redo()
m_LayerObject.Location = m_NewLocation.Location
m_LayerObject.Width = m_NewLocation.Width
m_LayerObject.Height = m_NewLocation.Height
End Sub
Public Overrides Sub Undo()
MyBase.Undo()
m_LayerObject.Location = m_OriginalLocation.Location
m_LayerObject.Width = m_OriginalLocation.Width
m_LayerObject.Height = m_OriginalLocation.Height
End Sub
End Class
Public Class UndoRedoMoveLayerObject
Inherits UndoRedoItem
Private Structure UndoMoveObjectItem
Public LayerObject As SelectableLayerObject
Public OriginalCenterLocation As PointF
Public NewCenterLocation As PointF
Public Sub New(ByVal LayerObject As SelectableLayerObject)
Me.LayerObject = LayerObject
Me.OriginalCenterLocation = LayerObject.StartCenter
Me.NewCenterLocation = LayerObject.Center
End Sub
End Structure
Dim m_MoveItems As New List(Of UndoMoveObjectItem)
Public Sub New(ByVal PCB As PCB, ByVal LayerObjects As ReadOnlyDictionary(Of Integer, SelectableLayerObject))
MyBase.New(PCB)
For Each LayerObject As KeyValuePair(Of Integer, SelectableLayerObject) In LayerObjects
m_MoveItems.Add(New UndoMoveObjectItem(LayerObject.Value)) 'back up the start position
Next
m_PCB = PCB
End Sub
Public Overrides ReadOnly Property Description() As String
Get
Return "Move objects"
End Get
End Property
Public Overrides Sub Redo()
MyBase.Redo()
For Each MoveItem As UndoMoveObjectItem In m_MoveItems
MoveItem.LayerObject.Center = MoveItem.NewCenterLocation
Next
End Sub
Public Overrides Sub Undo()
MyBase.Undo()
For Each MoveItem As UndoMoveObjectItem In m_MoveItems
MoveItem.LayerObject.Center = MoveItem.OriginalCenterLocation
Next
End Sub
End Class
Public Class UndoRedoDisconnectPin
Inherits UndoRedoItem
Protected DevicePin As DevicePin
Protected Pad As Pad
Protected EaglePadName As String
Protected PadName As String
Protected RedoPadName As String
Protected RedoDevicePin As DevicePin
Protected RedoEaglePadName As String
Public Sub New(ByVal PCB As PCB, ByVal DevicePin As DevicePin, ByVal Pad As Pad)
MyBase.New(PCB)
Me.DevicePin = DevicePin
Me.Pad = Pad
Me.PadName = Pad.Name
Me.EaglePadName = Pad.EaglePadName
End Sub
Public Overrides ReadOnly Property Description() As String
Get
Return "Disconnect pin and pad"
End Get
End Property
Public Overrides Sub Redo()
MyBase.Redo()
DevicePin.RemovePad(Pad)
Pad.DevicePin = RedoDevicePin
If RedoDevicePin IsNot Nothing Then RedoDevicePin.AddPad(Pad, RedoEaglePadName)
Pad.Name = RedoPadName
End Sub
Public Overrides Sub Undo()
MyBase.Undo()
RedoDevicePin = Pad.DevicePin
RedoEaglePadName = Pad.EaglePadName
If RedoDevicePin IsNot Nothing Then RedoDevicePin.RemovePad(Pad)
Pad.DevicePin = DevicePin
DevicePin.AddPad(Pad, EaglePadName)
RedoPadName = Pad.Name
Pad.Name = PadName
End Sub
End Class
Public Class UndoRedoConnectPin
Inherits UndoRedoItem
Protected DevicePin As DevicePin
Protected Pad As Pad
Protected EaglePadName As String
Protected PadName As String
Protected RedoPadName As String
Protected RedoEaglePadName As String
Public Sub New(ByVal PCB As PCB, ByVal DevicePin As DevicePin, ByVal Pad As Pad)
MyBase.New(PCB)
Me.DevicePin = DevicePin
Me.Pad = Pad
Me.PadName = Pad.Name
Me.EaglePadName = Pad.EaglePadName
End Sub
Public Overrides ReadOnly Property Description() As String
Get
Return "connect pin and pad"
End Get
End Property
Public Overrides Sub Redo()
MyBase.Redo()
Pad.Name = RedoPadName
DevicePin.AddPad(Pad, RedoEaglePadName)
Pad.DevicePin = DevicePin
End Sub
Public Overrides Sub Undo()
MyBase.Undo()
RedoEaglePadName = Pad.EaglePadName
DevicePin.RemovePad(Pad)
Pad.DevicePin = Nothing
RedoPadName = Pad.Name
Pad.Name = PadName
Pad.EaglePadName = EaglePadName
End Sub
End Class
Public Class UndoRedoAddPad
Inherits UndoRedoAddObject
Protected DevicePin As DevicePin
Protected RedoEaglePadName As String
Protected EaglePadName As String
Public Sub New(ByVal PCB As PCB, ByVal Obj As LayerObject)
MyBase.New(PCB, Obj)
EaglePadName = CType(Obj, Pad).EaglePadName
End Sub
Public Overrides ReadOnly Property Description() As String
Get
Return "add pad"
End Get
End Property
Public Overrides Sub Redo()
If DevicePin IsNot Nothing Then
CType(Obj, Pad).DevicePin = DevicePin
DevicePin.AddPad(Obj, RedoEaglePadName)
End If
MyBase.Redo()
End Sub
Public Overrides Sub Undo()
DevicePin = CType(Obj, Pad).DevicePin
RedoEaglePadName = CType(Obj, Pad).EaglePadName
CType(Obj, Pad).EaglePadName = EaglePadName
MyBase.Undo()
End Sub
End Class
Public Class UndoRedoAddObject
Inherits UndoRedoItem
Protected Obj As LayerObject
Protected OnLayers As New List(Of Layer)
Public Sub New(ByVal PCB As PCB, ByVal Obj As LayerObject)
MyBase.New(PCB)
Me.Obj = Obj
End Sub
Public Overrides ReadOnly Property Description() As String
Get
Return "add object"
End Get
End Property
Public Overrides Sub Redo()
MyBase.Redo()
m_PCB.AddObject(Obj)
For Each Layer As Layer In OnLayers
Layer.AddObject(Obj)
Next
End Sub
Public Overrides Sub Undo()
MyBase.Undo()
'remember the layers the object is placed on
OnLayers.Clear()
For Each Layer As KeyValuePair(Of PCB.LayerTypes, Layer) In m_PCB.Layers
If Layer.Value.LayerObjects.Contains(Obj) Then
OnLayers.Add(Layer.Value)
End If
Next
m_PCB.RemoveObject(Obj)
End Sub
End Class
Public Class UndoRedoDeletePad
Inherits UndoRedoDeleteObject
Dim Connections As ConnectionMatrix
Dim RedoConnections As ConnectionMatrix
Dim DevicePin As DevicePin
Dim m_UndoDeleteRoutes As New Stack(Of UndoRedoDeleteRoute)
Dim m_RedoDeleteRoutes As New Stack(Of UndoRedoDeleteRoute)
Public Sub New(ByVal PCB As PCB, ByVal Obj As LayerObject)
MyBase.New(PCB, Obj)
Connections = PCB.ConnectionMatrix.BackUp
DevicePin = CType(Obj, Pad).DevicePin
For Each Route As Route In CType(Obj, Pad).Routes
m_UndoDeleteRoutes.Push(Route.GetUndoDeleteItem(PCB, False))
Next
End Sub
Public Overrides ReadOnly Property Description() As String
Get
Return "delete pad"
End Get
End Property
Public Overrides Sub Undo()
RedoConnections = m_PCB.ConnectionMatrix.BackUp
MyBase.Undo()
If DevicePin IsNot Nothing Then
DevicePin.Pads.Remove(Obj)
End If
While m_UndoDeleteRoutes.Count > 0
Dim RedoItem As UndoRedoItem = m_UndoDeleteRoutes.Pop()
RedoItem.Undo()
m_RedoDeleteRoutes.Push(RedoItem)
End While
m_PCB.ConnectionMatrix.Restore(Connections) 'restore the connection matrix
End Sub
Public Overrides Sub Redo()
MyBase.Redo()
m_PCB.RemoveObject(Obj)
If DevicePin IsNot Nothing Then
DevicePin.Pads.Add(Obj)
End If
While m_RedoDeleteRoutes.Count > 0
Dim UndoItem As UndoRedoItem = m_RedoDeleteRoutes.Pop()
UndoItem.Redo()
m_UndoDeleteRoutes.Push(UndoItem)
End While
m_PCB.ConnectionMatrix.Restore(RedoConnections) 'restore the connections from before the undo
End Sub
End Class
Public Class UndoRedoDeleteObject
Inherits UndoRedoItem
Protected Obj As LayerObject
Protected OnLayers As New List(Of Layer)
Public Sub New(ByVal PCB As PCB, ByVal Obj As LayerObject)
MyBase.New(PCB)
Me.Obj = Obj
'save on which layer the object was displayed
For Each Layer As KeyValuePair(Of PCB.LayerTypes, Layer) In PCB.Layers
If Layer.Value.LayerObjects.Contains(Obj) Then
OnLayers.Add(Layer.Value)
End If
Next
End Sub
Public Overrides ReadOnly Property Description() As String
Get
Return "delete object"
End Get
End Property
Public Overrides Sub Redo()
MyBase.Redo()
m_PCB.RemoveObject(Obj)
For Each layer As Layer In OnLayers
layer.LayerObjects.Remove(Obj)
Next
End Sub
Public Overrides Sub Undo()
MyBase.Undo()
m_PCB.AddObject(Obj)
For Each Layer As Layer In OnLayers
Layer.AddObject(Obj)
Next
End Sub
End Class
Public Class UndoRedoRemoveLibrary
Inherits UndoRedoItem
Dim m_Library As Eagle.Project
Public Sub New(ByVal PCB As PCB, ByVal Library As Eagle.Project)
MyBase.New(PCB)
m_Library = Library
End Sub
Public Overrides ReadOnly Property Description() As String
Get
Return "Remove Eagle library"
End Get
End Property
Public Overrides Sub Redo()
MyBase.Redo()
m_PCB.RemoveEagleLibrary(m_Library.Drawing.Library.Name)
End Sub
Public Overrides Sub Undo()
MyBase.Undo()
If Not m_PCB.AddEagleLibrary(m_Library) Then
MsgBox("Cannot undo remove Eagle Library because another library with the same name is already added!")
End If
End Sub
End Class
Public Class UndoRedoTextChange
Inherits UndoRedoItem
Dim m_Font As Font
Dim m_Text As String
Dim m_Textbox As TextBox
Dim m_RedoFont As Font
Dim m_RedoText As String
Public Sub New(ByVal PCB As PCB, ByVal TextObject As TextBox)
MyBase.New(PCB)
m_Textbox = TextObject
m_Text = TextObject.Text
m_Font = TextObject.Font.Clone()
End Sub
Public Overrides ReadOnly Property Description() As String
Get
Return "Change text"
End Get
End Property
Public Overrides Sub Redo()
MyBase.Redo()
m_Textbox.Font = m_RedoFont
m_Textbox.Text = m_RedoText
End Sub
Public Overrides Sub Undo()
m_RedoFont = m_Textbox.Font
m_RedoText = m_Textbox.Text
MyBase.Undo()
m_Textbox.Text = m_Text
m_Textbox.Font = m_Font
End Sub
End Class
Public Class UndoRedoChangeColor
Inherits UndoRedoItem
Dim m_Color As Color
Dim m_RedoColor As Color
Dim m_Object As SelectableLayerObject
Public Sub New(ByVal PCB As PCB, ByVal LayerObject As SelectableLayerObject)
MyBase.New(PCB)
m_Color = LayerObject.color
End Sub
Public Overrides ReadOnly Property Description() As String
Get
Return "Change color"
End Get
End Property
Public Overrides Sub Redo()
MyBase.Redo()
m_Object.Color = m_RedoColor
End Sub
Public Overrides Sub Undo()
m_RedoColor = m_Object.Color
MyBase.Undo()
m_Object.Color = m_Color
End Sub
End Class
Public Class UndoRedoChangeRotation
Inherits UndoRedoItem
Dim m_Rotation As Single
Dim m_RedoRotation As Single
Dim m_Object As LayerObject
Public Sub New(ByVal PCB As PCB, ByVal LayerObject As LayerObject)
MyBase.New(PCB)
m_Rotation = LayerObject.Rotation
m_Object = LayerObject
End Sub
Public Overrides ReadOnly Property Description() As String
Get
Return "Change color"
End Get
End Property
Public Overrides Sub Redo()
MyBase.Redo()
m_Object.Rotation = m_RedoRotation
End Sub
Public Overrides Sub Undo()
m_RedoRotation = m_Object.Rotation
MyBase.Undo()
m_Object.Rotation = m_Rotation
End Sub
End Class
Public Class UndoRedoMoveSchematicInstance
Inherits UndoRedoItem
Dim m_Instance As SchematicInstance
Dim m_Location As PointF
Dim m_RedoLocation As PointF
Dim m_Rotation As Single
Dim m_RedoRotation As Single
Public Sub New(ByVal PCB As PCB, ByVal Instance As SchematicInstance)
MyBase.New(PCB)
m_Instance = Instance
m_Location = Instance.StartLocation
m_Rotation = Instance.StartRotation
End Sub
Public Overrides Sub Redo()
MyBase.Redo()
m_Instance.Location = m_RedoLocation
End Sub
Public Overrides Sub Undo()
m_RedoLocation = m_Instance.Location
m_RedoRotation = m_Instance.Rotation
MyBase.Undo()
m_Instance.Location = m_Location
m_Instance.Rotation = m_Rotation
End Sub
Public Overrides ReadOnly Property Description() As String
Get
Return "Move item on schematic."
End Get
End Property
End Class
Public Class UndoRedoDeleteRoutePoint
Inherits UndoRedoDeleteObject
Public Sub New(ByVal PCB As PCB, ByVal Obj As LayerObject)
MyBase.New(PCB, Obj)
End Sub
Public Overrides ReadOnly Property Description() As String
Get
Return "Delete Route Point"
End Get
End Property
End Class
Public Class UndoRedoDeleteRoute
Inherits UndoRedoDeleteObject
Dim Connections As ConnectionMatrix
Dim RedoConnections As ConnectionMatrix
Dim m_BackupConnections As Boolean
Protected m_UndoRoutePointsStack As New Stack(Of UndoRedoDeleteRoutePoint)
Protected m_RedoRoutePointsStack As New Stack(Of UndoRedoDeleteRoutePoint)
Public Sub New(ByVal PCB As PCB, ByVal Obj As Route)
Me.New(PCB, Obj, True)
End Sub
Public Sub New(ByVal PCB As PCB, ByVal Obj As Route, ByVal BackupConnections As Boolean)
MyBase.New(PCB, Obj)
If (BackupConnections) Then
Connections = PCB.ConnectionMatrix.BackUp
End If
m_BackupConnections = BackupConnections
Dim Route As Route = CType(Obj, Route)
For Each RoutePoint As RoutePoint In Route.RoutePoints
m_UndoRoutePointsStack.Push(RoutePoint.GetUndoDeleteItem(PCB))
Next
End Sub
Public Overrides Sub Redo()
MyBase.Redo()
If m_BackupConnections Then
m_PCB.ConnectionMatrix.Restore(RedoConnections)
End If
While m_RedoRoutePointsStack.Count > 0
Dim UndoItem As UndoRedoItem = m_RedoRoutePointsStack.Pop()
UndoItem.Redo()
m_UndoRoutePointsStack.Push(UndoItem)
End While
End Sub
Public Overrides Sub Undo()
MyBase.Undo()
If m_BackupConnections Then RedoConnections = m_PCB.ConnectionMatrix.BackUp()
While m_UndoRoutePointsStack.Count > 0
Dim RedoItem As UndoRedoItem = m_UndoRoutePointsStack.Pop()
RedoItem.Undo()
m_RedoRoutePointsStack.Push(RedoItem)
End While
If m_BackupConnections Then
m_PCB.ConnectionMatrix.Restore(Connections)
End If
End Sub
Public Overrides ReadOnly Property Description() As String
Get
Return "Delete Route"
End Get
End Property
End Class
Public Class UndoRedoAddRoutePoint
Inherits UndoRedoAddObject
Public Sub New(ByVal PCB As PCB, ByVal RoutePoint As RoutePoint)
MyBase.New(PCB, RoutePoint)
End Sub
Public Overrides ReadOnly Property Description() As String
Get
Return "Add Route point."
End Get
End Property
End Class
''' <summary>
''' Undo / Redo drawing route point
''' </summary>
''' <remarks></remarks>
Public Class UndoRedoAddRoute
Inherits UndoRedoAddObject
Dim m_UndoConnections As ConnectionMatrix
Dim m_RedoConnections As ConnectionMatrix
Protected m_UndoRoutePointsStack As New Stack(Of UndoRedoAddRoutePoint)
Protected m_RedoRoutePointsStack As New Stack(Of UndoRedoAddRoutePoint)
Public Sub New(ByVal PCB As PCB, ByVal Route As Route)
MyBase.New(PCB, Route)
m_UndoConnections = PCB.ConnectionMatrix.BackUp()
For i As Integer = Route.RoutePoints.Count - 1 To 0 Step -1
m_UndoRoutePointsStack.Push(Route.RoutePoints(i).GetUndoAddItem(PCB))
Next
'For Each RoutePoint As RoutePoint In Route.RoutePoints
'Next
End Sub
Public Overrides Sub Undo()
m_RedoConnections = m_PCB.ConnectionMatrix.BackUp()
While m_UndoRoutePointsStack.Count > 0
Dim RedoItem As UndoRedoItem = m_UndoRoutePointsStack.Pop()
RedoItem.Undo()
m_RedoRoutePointsStack.Push(RedoItem)
End While
MyBase.Undo()
m_PCB.ConnectionMatrix.Restore(m_UndoConnections)
End Sub
Public Overrides Sub Redo()
MyBase.Redo()
m_PCB.ConnectionMatrix.Restore(m_RedoConnections)
While m_RedoRoutePointsStack.Count > 0
Dim UndoItem As UndoRedoItem = m_RedoRoutePointsStack.Pop()
UndoItem.Redo()
m_UndoRoutePointsStack.Push(UndoItem)
End While
End Sub
Public Overrides ReadOnly Property Description() As String
Get
Return "Draw Route."
End Get
End Property
End Class