File: action.tcl

package info (click to toggle)
tkgate 2.1%2Brepack-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 28,384 kB
  • sloc: ansic: 62,300; tcl: 20,345; xml: 2,731; yacc: 1,177; lex: 839; sh: 664; makefile: 180; perl: 39
file content (1243 lines) | stat: -rw-r--r-- 29,497 bytes parent folder | download | duplicates (5)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
#   Copyright (C) 1987-2015 by Jeffery P. Hansen
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License along
#   with this program; if not, write to the Free Software Foundation, Inc.,
#   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Last edit by hansen on Mon Feb 23 20:30:42 2009
#


#############################################################################
#
# Use this for a basic action.  "name" is the name of the action that will
# appear in the undo/redo listboxes, and "body" is the undoable code to
# execute.
#
proc action {name body} {
  set ok [gat_obBeginFrame $name]
  uplevel $body
  if {$ok} { gat_obEndFrame }
}

#############################################################################
#
# Use this for a action which will be appended to the most recent action.
#
proc continueAction {name body} {
  gat_obAppendFrame $name
#  namespace eval :: $body
  uplevel $body
  gat_obEndFrame
}

#############################################################################
#
# Use this for "transparent" actions.  Transparent actions are those
# for which a frame record is kept and placed in the stack, but which
# are not directly visible to the user.
#
proc transAction {name body} {
  gat_obBeginFrame $name 1
#  namespace eval :: $body
  uplevel $body
  gat_obEndFrame
}

#############################################################################
#
# Use this for "background" actions.  Background actions are actions taken
# internally by tkgate and not directly by the user.
#
proc bgAction {name body} {
  gat_obBeginFrame $name 5
#  namespace eval :: $body
  uplevel $body
  gat_obEndFrame
}

#############################################################################
#
# Use this action for operations for which undo processing will
# be suspended.
#
proc suspendAction {body} {
  set m [gat_obMode]
  gat_obMode 0
#  namespace eval :: $body
  uplevel $body
  gat_obMode $m
}

#############################################################################
#
# Use this action for operations for which undo processing will
# be suspended, and all undo data cleared.
#
proc clearAction {body} {
  set m [gat_obMode]
  gat_obMode 0
  gat_obFlush
#  namespace eval :: $body
  uplevel $body
  gat_obMode $m
}

#############################################################################
#############################################################################
##
## Tkgate actions are defined below here.  All calls from the interface
## go through an action function.
##
#############################################################################
#############################################################################
namespace eval Action  {
  proc null {} { }

  proc cancel {} {
    transAction Cancel { tkg_cancel; gat_unselectGates }
  }

  #############################################################################
  #
  # Show debugging info about wires.
  #
  proc dumpWires {} {
    gat_dumpWires
  }

  #############################################################################
  #
  # Run the internal datat structure verifier.
  #
  proc verify {} {
    gat_verify
  }

  #############################################################################
  #
  # Add an input to the selected gate.
  #
  proc addPort {} {
    action AddPort { gat_addPort }
  }

  #############################################################################
  #
  # Change the type of a port
  #
  proc editPort {} {
    action EditPort { gat_changePinDir }
  }


  #############################################################################
  #
  # Set debugging mode
  #
  proc debugMode {} {
    action Mode { ToolBar::selectTool 12 }
  }

  #############################################################################
  #
  # Put tkgate in standard edit mode
  #
  proc editMode {} {
    action Mode { ToolBar::selectTool 1 }
  }

  #############################################################################
  #
  # Put tkgate in delete gate mode (obsolete, code '3' now used for scrolling)
  #
  proc deleteMode {} {
    action Mode {ToolBar::selectTool 3 }
  }

  #############################################################################
  #
  # Put tkgate in delete gate mode
  #
  proc scrollMode {} {
    action Mode {ToolBar::selectTool 3 }
  }

  #############################################################################
  #
  # Put tkgate in cut wire mode
  #
  proc cutMode {} {
    action Mode {ToolBar::selectTool 0 }
  }

  #############################################################################
  #
  # Put tkgate in invert in/out mode
  #
  proc invertMode {} {
    action Mode {ToolBar::selectTool 2 }
  }

  #############################################################################
  #
  # Put tkgate in set wire size mode
  #
  proc sizeMode {} {
    action Mode {ToolBar::selectTool 9 }
  }

  #############################################################################
  #
  # Set gate rotation to 0 degrees
  #
  proc rot0 {} {
    action Rotation { gat_setrot 0 }
  }

  #############################################################################
  #
  # Set gate rotation to 90 degrees
  #
  proc rot90 {} {
    action Rotation { gat_setrot 1 }
  }

  #############################################################################
  #
  # Set gate rotation to 180 degrees
  #
  proc rot180 {} {
    action Rotation { gat_setrot 2 }
  }

  #############################################################################
  #
  # Set gate rotation to 270 degrees
  #
  proc rot270 {} {
    action Rotation { gat_setrot 3 }
  }

  #############################################################################
  #
  # Open a Tcl shell window
  #
  proc shellWindow {} {
    ::shellWindow
  }

  #############################################################################
  #
  # Open the selected module.
  #
  proc openMod {} {
    action Open { if { "%W" != ".scope"} { gat_openBox } else { .scope.main.frame.canvas zoom 1 } }
  }

  #############################################################################
  #
  # Close the current module.
  #
  proc closeMod {} {
    action Close { if { "%W" != ".scope"} { gat_closeBox } else { .scope.main.frame.canvas zoom -1 } }
  }

  ######################################################################
  #
  # Replicate a gate.
  #
  proc replicate {} {
    action Replicate { gat_replicate }
  }

  ######################################################################
  #
  # Delete the selected object.
  #
  proc delete {} {
    action Delete { gat_deleteSelected }
  }

  ######################################################################
  #
  # Edit the properties of the selected object.
  #
  proc editProps {} {
    action EditProps { gat_editProps }
  }

  ######################################################################
  #
  # Set/unset a probe on the selected wire.
  #
  proc toggleProbe {} {
    gat_toggleProbe
  }

  ######################################################################
  #
  # Set/unset a probe on the selected wire.
  #
  proc delScopeProbe {} {
    gat_delScopeProbe
  }

  ######################################################################
  #
  # Move to the previous error in the error box.
  #
  proc errBoxUp {} {
    action ErrUp { ErrBox::selectUp }
  }

  ######################################################################
  #
  # Move to the next error in the error box.
  #
  proc errBoxDown {} {
    action ErrDown { ErrBox::selectDown }
  }

  ######################################################################
  #
  # Align gates horizontally
  #
  proc hAlign {} {
    action HAlign { gat_align 1 }
  }

  ######################################################################
  #
  # Counter clockwise rotation.
  #
  # The type of rotation depends on the current edit mode.  If en regular
  # edit mode, selected gates are rotated.  If the symbol editor is active
  # and we are in port mode, then the selected port is edited.  If the symbol
  # editor is active and we are not in port mode, then the bits are rotated.
  #
  proc rotate {} {
    action Rotate {
      set mm [gat_getMajorMode]

      switch $mm {
	edit {
	  gat_rotate
	}
	interface {
	  if {[SymbolEdit::isactive]} {
	    if { $SymbolEdit::emode == "port" } {
	      SymbolEdit::rotatePort 1
	    } else {
	      SymbolEdit::rotateBits 1
	    }
	  }
	}
      }
    }
  }

  ######################################################################
  #
  # Back rotate gates
  #
  proc backRotate {} {
    action Rotate {
      set mm [gat_getMajorMode]

      switch $mm {
	edit {
	  gat_rotate -1
	}
	interface {
	  if {[SymbolEdit::isactive]} {
	    if { $SymbolEdit::emode == "port" } {
	      SymbolEdit::rotatePort -1
	    } else {
	      SymbolEdit::rotateBits -1
	    }
	  }
	}
      }
    }
  }

  ######################################################################
  #
  # Align gates vertically
  #
  proc vAlign {} {
    action VAlign { gat_align 0 }
  }

  ######################################################################
  #
  # Clear the current circuit and start editing a new file.
  #
  proc newFile {} {
    clearAction File::new
  }

  ######################################################################
  #
  # Load the specified file
  #
  proc loadFile {} {
    clearAction File::load
  }

  ######################################################################
  #
  # Load the specified file
  #
  proc loadNamedFile {name} {
    clearAction "gat_load $name"
  }

  ######################################################################
  #
  # Load modules from a library
  #
  proc loadLibrary {} {
    clearAction File::loadLibrary
  }

  ######################################################################
  #
  # Unload the library selected in the module tree view
  #
  proc unloadSelectedLibrary {} {
    set lib [BlockTree::getselection]
    if {[string first "||" $lib] != 0} return
    set lib [string range $lib 2 end]
    clearAction { gat_unloadLibrary $lib }
  }

  ######################################################################
  #
  # Save the current circuit to the current file
  #
  proc saveFile {} {
    transAction -Save File::saveCurrent
  }

  ######################################################################
  #
  # Save the current circuit to a new file.
  #
  proc saveAsFile {} {
    clearAction File::saveAs
  }

  ######################################################################
  #
  # Import image
  #
  proc importImage {} {
    SymbolEdit::importImage
  }

  ######################################################################
  #
  # Export image
  #
  proc exportImage {} {
    SymbolEdit::exportImage
  }

  ######################################################################
  #
  # Print the current circuit
  #
  proc print {} {
    suspendAction PrintDlg::post
  }

  ######################################################################
  #
  # Exit tkgate
  #
  proc exit {} {
    File::closeApplication
  }

  ######################################################################
  #
  # Edit tkgate options
  #
  proc editOptions {} {
    suspendAction OptionDlg::post
  }

  ######################################################################
  #
  # Select all gates in the current module
  #
  proc selectAll {} {
    if {$HdlEditor::isActive} {
      action SelectAll { HdlEditor::selectAll }
    } else {
      action SelectAll { gat_selectAll }
    }
  }

  ######################################################################
  #
  # Edit circuit properties
  #
  proc editCProps {} {
    action EditCProps { EditCircDB::post }
  }

  ######################################################################
  #
  # Set an anchor on the selected gate
  #
  proc anchor {} {
    action Anchor { gat_anchor 1 }
  }

  ######################################################################
  #
  # Remove an anchor from the current gate.
  #
  proc unAnchor {} {
    action UnAnchor { gat_anchor 0 }
  }

  ######################################################################
  #
  # Begin critical path analysis mode
  #
  proc cpathAnal {} {
    tkg_cpathAnal
  }

  ######################################################################
  #
  # Copy selected region to cut buffer
  #
  proc copyToBuf {} {
    if {$HdlEditor::isActive} {
      HdlEditor::doCopy
    } else {
      action Copy { gat_copyToBuf }
    }
  }

  ######################################################################
  #
  # Cut the selected objects and place them in the cut buffer
  #
  proc cutToBuf {} {
    if {$HdlEditor::isActive} {
      HdlEditor::doCut
    } else {
      action Cut gat_cutToBuf
    }
  }

  ######################################################################
  #
  # Cut the selected objects and append them to the cut buffer
  #
  proc cutToBufAppend {} {
    if {$HdlEditor::isActive} {
      HdlEditor::startCommand -
    }
    action CutAppend gat_cutToBufAppend
  }

  ######################################################################
  #
  # Yank a copy of the cut buffer to the current module
  #
  proc yankFromBuf {} {
    if {$HdlEditor::isActive} {
      HdlEditor::doYank
    } else {
      action Yank gat_yankFromBuf
    }
  }

  ######################################################################
  #
  # Duplicate
  #
  proc duplicate {} {
    action Duplicate {
      gat_copyToBuf
      gat_yankFromBuf 30 30
    }
  }


  ######################################################################
  #
  # Find an object
  #
  proc findObject {} {
    transAction Find { Find::post }
  }

  ######################################################################
  #
  # Start the simulator
  #
  proc startSimulator {} {
    gat_setMajorMode simulate
  }

  ######################################################################
  #
  # End the simulator
  #
  proc endSimulator {} {
    gat_setMajorMode edit
  }

  ######################################################################
  #
  # Put simulator in "run" mode
  #
  proc simRun {} {
    tkg_simRun
  }

  ######################################################################
  #
  # Put simulator in "stop" mode.
  #
  proc simStop {} {
    tkg_simStop
  }

  ######################################################################
  #
  # Edit simulator breakpoints
  #
  proc editBreakpoints {} {
    InfoPanel::notify Breakpoints -force 1
    update
    Breakpoint::add
  }

  ######################################################################
  #
  # Execute a simulation script
  #
  proc doSimScript {} {
    tkg_doSimScript
  }

  ######################################################################
  #
  # Load a memory file
  #
  proc simLoadMem {} {
    tkg_simLoadMem
  }

  ######################################################################
  #
  # Dump a memory file.
  #
  proc simDumpMem {} {
    tkg_simDumpMem
  }

  ######################################################################
  #
  # View a memory file.
  #
  proc simViewMem {} {
    set g [gat_simSelected ram rom]

    if {$g != "" } {
      MemView::new $g.m -title $g
    } else {
      errmsg [m err.nomemselect]
    }
  }

  ######################################################################
  #
  # Print a scope trace
  #
  proc scopePrint {} {
    ScopePrintDlg::post
  }

  ######################################################################
  #
  # Step the simulator one epoch
  #
  proc simStep {} {
    Simulator::stepEpoch
  }

  ######################################################################
  #
  # Step the simulator one "clock cycle".
  #
  proc simCycle {} {
    tkg_simCycle
  }

  ######################################################################
  #
  # If in simulator mode, step the simulator one "clock cycle".  If in
  # edit mode, rotate the selected gates.
  #
  proc simCycleOrRotate {} {
    set mm [gat_getMajorMode]

    if { $mm == "simulate" } {
      tkg_simCycle
    } else {
      rotate
    }
  }

  ######################################################################
  #
  # Refresh the screen.
  #
  proc refreshScreen {} {
    gat_refreshScreen
  }

  ######################################################################
  #
  # Create a new module
  #
  proc blockNew {} {
    action NewMod BlockOp::new
  }

  ######################################################################
  #
  # Delete a module
  #
  proc blockDelete {} {
    action DeleteMod BlockOp::delete
  }

  ######################################################################
  #
  # Copy a module
  #
  proc blockCopy {} {
    action CopyMod BlockOp::copy
  }

  ######################################################################
  #
  # Set root module
  #
  proc blockSetRoot {} {
    action SetRoot BlockOp::setroot
  }

  ######################################################################
  #
  # Rename a module
  #
  proc blockRename {} {
    action RenameMod BlockOp::rename
  }

  ######################################################################
  #
  # Set the interface of the selected module
  #
  proc setBlockDesc {} {
    action SetInterf { gat_setBlockDesc }
  }

  ######################################################################
  #
  # Edit the module interfaces
  #
  proc editBlockDesc {} {
    action EditInterf gat_editBlockDesc
  }

  ######################################################################
  #
  # Autogenerate a module interface
  #
  proc autoGenerate {} {
    IGen::post -which ipanel
  }

  ######################################################################
  #
  # Autogenerate a module interface from module list
  #
  proc autoGenerateSelected {} {
    IGen::post -which selected
  }

  ######################################################################
  #
  # Autogenerate a module interface from direct canvas selection
  #
  proc autoGenerateCanvas {} {
    IGen::post -which canvas
  }

  ######################################################################
  #
  # "Claim" a block (make it a non-library block)
  #
  proc blockClaim {} {
    action Claim BlockOp::claim
  }

  ######################################################################
  #
  # Shows/edits properties of a module
  #
  proc blockProp {} {
    action Props ModuleProps::postSelected
  }

  ######################################################################
  #
  # Shows/edits properties of a module
  #
  proc blockPropCanvas {} {
    action Props { ModuleProps::postSelected -which canvas }
  }

  ######################################################################
  #
  # Zoom in
  #
  proc zoomIn {} {
    action ZoomIn { gat_zoom 1 }
  }

  ######################################################################
  #
  # Zoom out
  #
  proc zoomOut {} {
    action ZoomOut { gat_zoom -1 }
  }

  ######################################################################
  #
  # SymboleEdit Zoom in
  #
  proc seZoomIn {} {
    SymbolEdit::zoom 1
  }

  ######################################################################
  #
  # SymboleEdit Zoom out
  #
  proc seZoomOut {} {
    SymbolEdit::zoom -1
  }

  ######################################################################
  #
  # Nudge the selected objects left
  #
  proc nudgeLeft {} {
    action NudgeL { gat_moveGate -1 0 }
  }

  ######################################################################
  #
  # Nudge the selected objects right
  #
  proc nudgeRight {} {
    action NudgeR { gat_moveGate 1 0 }
  }

  ######################################################################
  #
  # Nudge the selected objects up
  #
  proc nudgeUp {} {
    action NudgeU { gat_moveGate 0 -1 }
  }

  ######################################################################
  #
  # Nudge the selected objects down
  #
  proc nudgeDown {} {
    action NudgeD { gat_moveGate 0 1 }
  }

  ######################################################################
  #
  # Show the about message
  #
  proc showAbout {} {
    ::showAbout
  }

  ######################################################################
  #
  # Show the license message
  #
  proc showLicense {} {
    ::showLicense
  }

  ######################################################################
  #
  # Show the documentation message
  #
  proc showDocumentation {} {
    ::showDocumentation
  }

  ######################################################################
  #
  # Load example circuit 1
  #
  proc loadExample {} { global tkgate_exampledir; gat_load $tkgate_exampledir/index.v }


  ######################################################################
  #
  # Load home page
  #
  proc loadWelcome {} { global tkgate_tutorialdir; gat_load $tkgate_tutorialdir/welcome.v }

  ######################################################################
  #
  # Load tutorial index
  #
  proc loadTutorial {} { global tkgate_tutorialdir; gat_load $tkgate_tutorialdir/index.v }

  #############################################################################
  #
  # Undo last action
  #
  proc undo {} {
    HdlEditor::startCommand -
    gat_undo
  }

  #############################################################################
  #
  # Redo last undone action
  #
  proc redo {} {
    HdlEditor::startCommand -
    gat_redo
  }

  ######################################################################
  #
  # Update the interface of a module instance  with the current interface
  #
  proc updateInterface {} {
    action UpdIntf { gat_updateInterface }
  }

  ######################################################################
  #
  # Update the interface of all module instances with the current interface
  #
  proc updateAllInterfaces {} {
    action UpdAllIntf { gat_updateInterface -all }
  }

  ######################################################################
  #
  # Update the interface of all module instances with the current interface
  #
  proc updateOpenInterface {} {
    action UpdAllIntf { gat_updateInterface -open }
  }

  ######################################################################
  #
  # Edit wire properties through popup menu
  #
  proc popupWireProps {} { continueAction WireProp gat_popupWireProps }

  ######################################################################
  #
  # Add a stub to a wire
  #
  proc popupWireAddStub {} { action AddStub gat_popupWireAddStub }

  ######################################################################
  #
  # Hide/Show the bit size mark on a multi-bit wire
  #
  proc popupWireHideSize {} { action SizeDisp { gat_popupWireSize -hide }}
  proc popupWireShowSize {} { action SizeDisp { gat_popupWireSize -show }}

  ######################################################################
  #
  # Hide/Show the label on a wire
  #
  proc popupWireHideLabel {} { action SizeDisp { gat_popupWireLabel -hide } }
  proc popupWireHideAllLabel {} { action SizeDisp { gat_popupWireLabel -hideall } }
  proc popupWireClearAllLabel {} { action SizeDisp { gat_popupWireLabel -clearall } }
  proc popupWireShowLabel {} { action SizeDisp { gat_popupWireLabel -show } }

  ######################################################################
  #
  # Change the anchor status of an object
  #
  proc popupAnchor {} { action Anchor { global pop_anchor; gat_anchor $pop_anchor } }

  ######################################################################
  #
  # Change the port type of a module port
  #
  proc popupPortMakeIn {} { action ChgPort { gat_popupPortCmd change-in } }
  proc popupPortMakeOut {} { action ChgPort { gat_popupPortCmd change-out } }
  proc popupPortMakeInOut {} { action ChgPort { gat_popupPortCmd change-inout } }


  ######################################################################
  #
  # Delete a port on a module through right-click
  #
  proc popupDeletePort {} { action DelPort { gat_popupPortCmd delete } }

  ######################################################################
  #
  # Delete a port on a module through right-click
  #
  proc popupPortSize {n} { action SizePort { gat_popupPortCmd size $n } }

  ######################################################################
  #
  # Add an input port to a module
  #
  proc popupBlockAddIn {} { action AddInPort { gat_popupPortCmd add-in } }

  ######################################################################
  #
  # Add an output port to a module
  #
  proc popupBlockAddOut {} { action AddOutPort { gat_popupPortCmd add-out } }

  ######################################################################
  #
  # Add an in/out port to a module
  #
  proc popupBlockAddInOut {} { action AddTriPort { gat_popupPortCmd add-inout } }

  #############################################################################
  #
  # Edit the interface of the selected block.
  #
  #############################################################################
  proc openInterface {args} {
    action EditInterf {
      set name [gat_getSelected module]
      if { $name == "" } {
	set name [tkg_getSelectedBlock]
      }
      if { $name != "" } {
	gat_editBlockDesc $name
      }
    }
  }

  proc hdlDeleteForward {} {
    HdlEditor::startCommand DelFwrd
    HdlEditor::doDelete 0
  }
  proc hdlDeleteBackward {} {
    HdlEditor::startCommand DelBack
    HdlEditor::doDelete -1
  }
  proc hdlCut {} {
    HdlEditor::startCommand -Cut
    HdlEditor::doCut
  }
  proc hdlYank {} {
    HdlEditor::startCommand Yank
    HdlEditor::doYank
  }
  proc hdlKillLine {} {
    HdlEditor::startCommand -KillLine
    HdlEditor::doKillLine
  }
  proc hdlTransposeChar {} {
    HdlEditor::startCommand CharSwap
    HdlEditor::doTransposeChar
  }
  proc hdlSearch {} {
    HdlEditor::doSearch
  }
  proc hdlReverseSearch {} {
    HdlEditor::doRSearch
  }
  proc hdlPageDown {} {
    HdlEditor::startCommand -
    HdlEditor::doPageMove 1
  }
  proc hdlPageUp {} {
    HdlEditor::startCommand -
    HdlEditor::doPageMove -1
  }
  proc hdlDeleteWord {} {
    HdlEditor::startCommand DelWord
    HdlEditor::doDeleteWord 1
  }
  proc hdlOpenLine {} {
    HdlEditor::startCommand OpenLine
    HdlEditor::doOpenLine
  }
  proc hdlGotoLineEnd {} {
    HdlEditor::startCommand -
    HdlEditor::doMoveTo "insert lineend"
  }
  proc hdlGotoLineStart {} {
    HdlEditor::startCommand -
    HdlEditor::doMoveTo "insert linestart"
  }
  proc hdlGotoTop {} {
    HdlEditor::startCommand -
    HdlEditor::doMoveTo "1.0" -setpoint 1
  }
  proc hdlGotoEnd {} {
    HdlEditor::startCommand -
    HdlEditor::doMoveTo "end" -setpoint 1
  }
  proc hdlForwardWord {} {
    HdlEditor::startCommand -
    HdlEditor::doWordMove 1
  }
  proc hdlBackwardWord {} {
    HdlEditor::startCommand -
    HdlEditor::doWordMove -1
  }
  proc hdlBackwardChar {} {
    HdlEditor::startCommand -
    HdlEditor::doHMove -1
  }
  proc hdlForwardChar {} {
    HdlEditor::startCommand -
    HdlEditor::doHMove 1
  }
  proc hdlUpLine {} {
    HdlEditor::startCommand -
    HdlEditor::doVMove 1
  }
  proc hdlDownLine {} {
    HdlEditor::startCommand -
    HdlEditor::doVMove -1
  }
  proc hdlSetMark {} {
    HdlEditor::startCommand -
    HdlEditor::doSetPoint
  }
  proc hdlExchangePointAndMark {} {
    HdlEditor::startCommand -
    HdlEditor::doPointSwap
  }
  proc hdlCancel {} {
    HdlEditor::startCommand -
    HdlEditor::doCancel
  }
  proc hdlIndent {} {
    HdlEditor::startCommand Indent
    HdlEditor::doIndent
  }
  proc hdlLowercaseWord {} {
    HdlEditor::startCommand ToLower
    HdlEditor::doLowercaseWord
  }
  proc hdlUppercaseWord {} {
    HdlEditor::startCommand ToUpper
    HdlEditor::doUppercaseWord
  }
  proc hdlCasefyWord {} {
    HdlEditor::startCommand Casefy
    HdlEditor::doCasefyWord
  }
  proc hdlSetArgument {} {
    HdlEditor::doSetArgument
  }

  proc printTrace {} {
    ScopePrintDlg::post
  }
  proc scopeZoomIn {} {
    catch { .scope.main.frame.canvas zoom -1 }
  }
  proc scopeZoomOut {} {
    catch { .scope.main.frame.canvas zoom 1 }
  }

  proc seRShiftBits {} {
    SymbolEdit::shiftBits 1 0
  }

  proc seLShiftBits {} {
    SymbolEdit::shiftBits -1 0
  }

  proc seUShiftBits {} {
    SymbolEdit::shiftBits 0 -1
  }

  proc seDShiftBits {} {
    SymbolEdit::shiftBits 0 1
  }

  proc seCWRotate {} {
    SymbolEdit::rotateBits 1
  }

  proc seCCWRotate {} {
    SymbolEdit::rotateBits -1
  }

  proc seCWRotPort {} {
    SymbolEdit::rotatePort -1
  }

  proc seCCWRotPort {} {
    SymbolEdit::rotatePort 1
  }

  proc seBoldBits {} {
    SymbolEdit::boldBits
  }

  proc seResize	{} {
    SymbolEdit::resize
  }

  proc seCutToBuf {} {
    SymbolEdit::cutRegion
  }
  proc seCopyToBuf {} {
    SymbolEdit::copyRegion
  }
  proc sePasteFromBuf {} {
    SymbolEdit::pasteRegion
  }
  proc seOverlayFromBuf {} {
    SymbolEdit::overlayRegion
  }
}