1#   Copyright (C) 1987-2015 by Jeffery P. Hansen
2#
3#   This program is free software; you can redistribute it and/or modify
4#   it under the terms of the GNU General Public License as published by
5#   the Free Software Foundation; either version 2 of the License, or
6#   (at your option) any later version.
7#
8#   This program is distributed in the hope that it will be useful,
9#   but WITHOUT ANY WARRANTY; without even the implied warranty of
10#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11#   GNU General Public License for more details.
12#
13#   You should have received a copy of the GNU General Public License along
14#   with this program; if not, write to the Free Software Foundation, Inc.,
15#   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16#
17# Last edit by hansen on Sat Sep 26 15:32:41 2009
18#
19
20
21#
22# Wire Ops: Changes to the port list are passed back through the variable "edgat_wops".  The
23# variable contains a list of "wire ops".  Wire ops can be one of the following:
24#
25#      {add I}			Add a wire to port group I
26#      {delete I2}		Delete 2nd wire of port group I
27#      {edit Pold w Pnew io n}	Edit port.  Pold is old port name, w is signal name,
28#      				Pnew is new port name, io is the I/O type,
29#				and n is the number of bits.
30
31
32set edgat_wires {}
33set edgat_wops {}
34set edgat_portOpCount 0
35set edgat_dtype "huh?"
36set edgat_type "huh?"
37set edgat_name "huh?"
38set edgat_hideName 1
39set edgat_cpbreak 0
40set edgat_anchor 0
41set edgat_xpos 0
42set edgat_ypos 0
43set edgat_blockFunc "huh?"
44set edgat_newBlock 0
45set edgat_newPort 0
46set edgat_geom "+0+0"
47set ecpOmega 100
48set ecpPhi 50
49set ecpDuty 50
50set edgat_switch 0
51set edgat_extbar 0
52set edgat_dip 0
53set edgat_tap 0
54set edgat_memFile ""
55set edgat_ok 0
56set edgat_commentLen 0
57set edgat_dolink 0
58set edgat_link ""
59set edport_hidename 0
60
61set edport_ok 0
62set edport_idx 0
63set edport_sig "huh"
64set edport_port "huh"
65set edport_basePort "huh"
66set edport_type "huh"
67set edport_bits "huh"
68
69set clkFrame [list]
70
71array set editgate_caps {
72  AND {sig size add}
73  OR {sig size add}
74  XOR {sig size add}
75  MUX {sig size add}
76  DEMUX {sig size add}
77  CONCAT {sig size add}
78  Module {sig size type port add side}
79  TAP {}
80}
81
82proc trace_edgat_tech args {
83  global edgat_tech edgatdelay_w edgat_techdelay
84  gat_setGateTechDelays $edgat_tech
85}
86trace variable edgat_tech w trace_edgat_tech
87
88#############################################################################
89#
90# Dialog box for editing a single port on a module.
91#
92namespace eval PortEdit {
93  proc ok {} {
94    global edport_ok
95
96    set edport_ok 1
97    destroy .edport
98  }
99
100  ########################################
101  #
102  # Throw up a dialog box for changing port values (Now only used when creating ports)
103  #
104  proc post {pos args} {
105    global edport_idx edport_sig edport_basePort edport_port edport_type edport_bits edport_hidename
106    global edgat_type edgat_wops edport_ok
107    global edgatio_w
108
109    set showsig 1
110    set interface 0
111
112    parseargs $args {-ismodule -showsig}
113
114    set edport_ok 0
115    set oldPort $edport_port
116    set edport_hidename 1
117
118    set p [string first ":" $edport_port]
119    if { $p > 0 } {
120      set edport_basePort [string range $edport_port 0 $p]
121      set edport_port [string range $edport_port [expr $p + 1] end]
122      set isBlock 1
123    } {
124      set edport_basePort ""
125      set isBlock 0
126    }
127
128    toplevel .edport
129    wm transient .edport .
130    wm resizable .edport 0 0
131    wm title .edport [m port.title]
132    wm geometry .edport $pos
133
134    frame .edport.box -relief raised -bd 1
135
136    dialogImage .edport.box.image -image [gifI port.gif] -caption [m port.parms]
137    grid .edport.box.image -sticky nsew -column 0 -row 0 -rowspan 6
138    grid rowconfigure .edport.box 5 -weight 1
139
140    if { $showsig } {
141      label .edport.box.siglab  -text "[m db.gate.signam]:"
142      entry .edport.box.sig     -textvariable edport_sig -bg white
143    }
144    label .edport.box.portlab -text "[m db.gate.portnam]:"
145    entry .edport.box.port    -textvariable edport_port -bg white
146
147    label .edport.box.iolab   -text "[m db.gate.iotype]:"
148    label .edport.box.bitlab  -text "[m db.gate.bitw]:"
149
150    frame .edport.box.io
151    radiobutton .edport.box.io.in -text [m b.in] -variable edport_type -value in
152    radiobutton .edport.box.io.out -text [m b.out] -variable edport_type -value out
153    radiobutton .edport.box.io.bdir -text [m b.inout] -variable edport_type -value inout
154    pack .edport.box.io.in .edport.box.io.out .edport.box.io.bdir -side left
155
156#    entry .edport.box.bit     -textvariable edport_bits -bg white
157    bitsizeselector .edport.box.bit -variable edport_bits -width 3
158
159
160    if { $showsig } {
161      bind .edport.box.sig <KeyPress-Return> PortEdit::ok
162    }
163
164    bind .edport.box.port <KeyPress-Return> PortEdit::ok
165    bind .edport.box.bit <KeyPress-Return> PortEdit::ok
166
167    frame .edport.box.pad -height 10
168    grid .edport.box.pad -column 1 -row 0
169
170    grid .edport.box.portlab  -column 1 -row 1 -sticky e -padx 5 -pady 2
171    grid .edport.box.port     -column 2 -row 1 -sticky w -padx 5 -pady 2
172    grid .edport.box.iolab    -column 1 -row 2 -sticky e -padx 5 -pady 2
173    grid .edport.box.io       -column 2 -row 2 -sticky w -padx 5 -pady 2
174    grid .edport.box.bitlab   -column 1 -row 3 -sticky e -padx 5 -pady 2
175    grid .edport.box.bit      -column 2 -row 3 -sticky w -padx 5 -pady 2
176
177    if { $showsig } {
178      grid .edport.box.siglab   -column 1 -row 4 -sticky e -padx 5 -pady 2
179      grid .edport.box.sig      -column 2 -row 4 -sticky w -padx 5 -pady 2
180    }
181
182    frame  .edport.confirm -relief raised -bd 1
183    button .edport.confirm.ok     -text [m b.ok] -command PortEdit::ok
184    button .edport.confirm.cancel -text [m b.cancel] -command { destroy .edport }
185    pack .edport.confirm.ok -side left -padx 5 -pady 5
186    pack .edport.confirm.cancel -side right -padx 5 -pady 5
187
188    pack .edport.box -fill x
189    pack .edport.confirm -fill both
190
191    #
192    # Select port name
193    #
194    .edport.box.port selection range 0 end
195    .edport.box.port icursor end
196    focus .edport.box.port
197
198    if { $showsig } {
199      helpon .edport.box.siglab  [m ho.edgat.signam]
200    }
201    helpon .edport.box.portlab [m ho.edgat.port]
202    helpon .edport.box.iolab   [m ho.edgat.iolab]
203    helpon .edport.box.bitlab  [m ho.edgat.bitlab]
204
205    dialogWait .edport
206
207    return $edport_ok
208  }
209}
210
211#############################################################################
212#
213# Methods for editing module parameters.
214#
215namespace eval ModParmMgr {
216  variable pmlb_w
217
218  #############################################################################
219  #
220  # Entry manager for the module parameter manager
221  #
222  proc manager {cmd args} {
223    variable pmlb_w
224
225    if { [lindex $args 0] == "-args" } {
226      set args [lindex $args 1]
227    }
228
229    switch $cmd {
230      canenter {               	# check to see if we can enter data
231	set c [lindex $args 2]
232	if { $c == 1} {
233	  return 1
234	} else {
235	  return 0
236	}
237      }
238      entrywidget {
239	return 0
240      }
241      close {
242	set data [lindex $args 3]
243	return $data
244      }
245      delete {			# respond to the delete key
246      }
247      canappend {
248	return 0
249      }
250    }
251  }
252
253  proc seeDestroy args {
254    variable pmlb_w
255    global edgat_modParms
256
257    set N [SpreadSheet::size $pmlb_w]
258    for { set i 0 } { $i < $N } { incr i } {
259      set entry [SpreadSheet::get $pmlb_w $i]
260      set edgat_modParms([lindex $entry 0]) [lindex $entry 1]
261    }
262  }
263
264  proc create {w} {
265    variable pmlb_w
266    global edgat_modParms
267
268    frame $w.mparms
269    set pmlb_w $w.mparms.lb
270
271    #
272    # Parameter names
273    #
274    set names [lsort [array names edgat_modParms]]
275
276    if {[llength $names] > 0 } {
277      SpreadSheet::create $w.mparms.lb  -height 15 -bd 1 -relief sunken -yscrollcommand "$w.mparms.vb set" -expandcol 1 -entrycommand ModParmMgr::manager
278      scrollbar $w.mparms.vb -orient vertical -command "SpreadSheet::yview $w.mparms.lb"
279
280      SpreadSheet::addcolumn $w.mparms.lb -width 25 -header [m db.gate.mparm.parameter]
281      SpreadSheet::addcolumn $w.mparms.lb -width 20 -header [m db.gate.mparm.value]
282
283      pack $w.mparms.lb $w.mparms.vb -side left -fill both
284
285      foreach n $names {
286	SpreadSheet::insert $w.mparms.lb end [list $n $edgat_modParms($n)]
287      }
288
289      bind $w.mparms.lb <Destroy> ModParmMgr::seeDestroy
290    } else {
291      label $w.mparms.exampleA -text [m db.gate.mparm.exampleA] -justify left
292      pack $w.mparms.exampleA -padx 10 -pady 10
293      label $w.mparms.exampleB -text [m db.gate.mparm.exampleB] -justify left -font hdlFont
294      pack $w.mparms.exampleB -padx 10 -pady 10 -anchor w
295    }
296
297    pack $w.mparms -padx 10 -pady 10
298  }
299}
300
301#############################################################################
302#
303# Methods for editing the port list of an instance.
304#
305namespace eval PortMgr {
306  variable io_w ""
307  variable iolb_w ""
308  variable doIdleUpdate 0
309  variable edcap_sig
310  variable edcap_port
311  variable edcap_type
312  variable edcap_size
313  variable edcap_add
314  variable edcap_side
315
316  #############################################################################
317  #
318  # Add a new port (used on initial load of gate)
319  #
320  proc add {p n} {
321    variable iolb_w
322    SpreadSheet::insert $iolb_w $p $n
323  }
324
325  #############################################################################
326  #
327  # Respond to a press of the "New" button
328  #
329  proc addNew {w} {
330    set r [SpreadSheet::size $w]
331    set r [SpreadSheet::getPhysicalRow $w $r]
332    SpreadSheet::entrySelect $w $r 0
333  }
334
335  #############################################################################
336  #
337  # Respond to a press of the "Delete" button
338  #
339  proc deletePort {w} {
340    variable edcap_add
341    variable edport_type
342    global edgat_wops
343
344    #
345    # Deletions only allowed when adds are also valid.
346    #
347    if {!$edcap_add} { return }
348
349
350    #
351    # If nothing is selected, then do nothing
352    #
353    set items [SpreadSheet::getselection $w]
354    if {[llength $items] == 0} { return }
355
356    #
357    # Count number of variable ports
358    #
359    set N [SpreadSheet::size $w]
360    set Nvar 0
361    for { set i 0 } { $i < $N } { incr i } {
362      set E [SpreadSheet::get $w $i]
363      set P [lindex $E 1]
364      if {[regexp {^([A-Za-z]+)([0-9]+)$} $P X B pnum]} {
365	incr Nvar
366      }
367    }
368
369    #
370    # If all remaining variable ports are selected, then do nothing.
371    #
372    if {[llength $items] == $Nvar} { return }
373
374
375    #
376    # Make sure selected ports are all of the same variable type
377    #
378    set ok 1
379    set baseName ""
380    set plist {}
381    foreach i $items {
382      set P [lindex [SpreadSheet::get $w $i] 1]
383      if {![regexp {^([A-Za-z]+)([0-9]+)$} $P X B pnum]} {
384	set ok 0
385      }
386      if {$baseName == "" } { set baseName $B }
387      if { $baseName != $B } { set ok 0 }
388      lappend plist $pnum
389
390    }
391    if { !$ok } { return }
392
393
394    #
395    # Deletion is ok
396    #
397    SpreadSheet::delete $w $items
398
399    #
400    # Create wire ops for deletions in reverse order of port number
401    #
402    foreach pn [lsort -integer -decreasing $plist] {
403      lappend edgat_wops [list delete $baseName$pn]
404    }
405
406
407    #
408    # Go get the undeleted entries from the variable pad and sort them
409    #
410    set N [SpreadSheet::size $w]
411    set L {}
412    for { set i 0 } { $i < $N } { incr i } {
413      set E [SpreadSheet::get $w $i]
414      set P [lindex $E 1]
415      if {[regexp {^([A-Za-z]+)([0-9]+)$} $P X B pnum]} {
416	lappend L [list $pnum $i]
417      }
418    }
419    set L [lsort -index 0 $L]
420
421    #
422    # Now relable the variable pad ports
423    #
424    set n 0
425    foreach p $L {
426      set i [lindex $p 1]
427      set E [SpreadSheet::get $w $i]
428
429      if {[regexp {^([A-Za-z]+)([0-9]+)$} [lindex $E 1] X B pnum]} {
430	set E [lreplace $E 1 1 $B$n]
431	incr n
432      }
433
434      SpreadSheet::put $w $i $E
435    }
436  }
437
438
439  #############################################################################
440  #
441  # Respond to a press of the "Edit" button
442  #
443  proc editSelected {w} {
444    set items [SpreadSheet::getselection $w]
445
446    if { [llength $items] < 1 } { return }
447
448    set r [lindex $items 0]
449    set r [SpreadSheet::getPhysicalRow $w $r]
450    SpreadSheet::entrySelect $w $r 0
451  }
452
453
454
455  #############################################################################
456  #
457  # Generate a new port entry
458  #
459  proc newPortEntry {} {
460    variable iolb_w
461    variable edcap_side
462    global edgat_wops edgatio_w edport_basePort
463    global edport_sig edport_port edport_type edport_bits edport_ok
464
465    set Q -1
466    set E ""
467
468    set N [SpreadSheet::size $iolb_w]
469    for {set i 0} { $i < $N } {incr i} {
470      set item [SpreadSheet::get $iolb_w $i]
471
472      set P [lindex $item 1]
473
474      if {[regexp {^([A-Za-z]+)([0-9]+)$} $P X B Nbits]} {
475	if { $Nbits > $Q} {
476	  set edport_idx [expr $i + 1]
477	  set Q $Nbits
478	  set E $item
479	}
480      }
481    }
482
483    if { $Q < 0 } {
484      errmsg [m err.badportadd]
485      return
486    }
487    incr Q
488
489    set portName  [string trimright [lindex $E 1] 0123456789]$Q
490
491    set item [list "*autoname*" $portName [lindex $E 2] [lindex $E 3]]
492    if { $edcap_side } {
493      lappend item [lindex $E 4]
494    }
495
496    return $item
497  }
498
499  #############################################################################
500  #
501  # Entry manager for the port editor
502  #
503  proc manager {cmd args} {
504    variable edcap_sig
505    variable edcap_port
506    variable edcap_type
507    variable edcap_size
508    variable edcap_side
509    variable edcap_add
510    variable iolb_w
511    global edgat_wops
512    global edgat_oldentry
513    global edgat_portOpCount
514
515    if { [lindex $args 0] == "-args" } {
516      set args [lindex $args 1]
517    }
518    switch $cmd {
519      canenter {               	# check to see if we can enter data
520	set c [lindex $args 2]
521	switch $c {
522	  0 { return $edcap_sig }
523	  1 { return $edcap_port }
524	  2 { return $edcap_type }
525	  3 { return $edcap_size }
526	  4 { return $edcap_side }
527	}
528	return 0
529      }
530      entrywidget {		# use a special widget for some cells (return 0 for normal entry)
531	set w [lindex $args 0]
532	set r [lindex $args 1]
533	set c [lindex $args 2]
534	set W [lindex $args 3]
535	set width [lindex $args 4]
536	set variable [lindex $args 5]
537	set edgat_oldentry [SpreadSheet::get $iolb_w [SpreadSheet::getEffectiveRow $iolb_w $r]]
538
539	switch $c {
540	  0 {
541	    return 0
542	  }
543	  1 {
544	    return 0
545	  }
546	  2 {
547	    Dropbox::new $W -variable $variable -width [expr $width - 3] -bd 1 -highlightthickness 0
548	    SpreadSheet::tabBindings $W.e $w $r $c
549	    Dropbox::itemadd $W "in"
550	    Dropbox::itemadd $W "out"
551	    Dropbox::itemadd $W "inout"
552	    update
553	    focus $W.e
554	    return 1
555	  }
556	  3 {
557	    bitsizeselector $W -variable $variable -width [expr $width - 3]
558#	    Dropbox::new $W -variable $variable -width [expr $width - 3] -bd 1 -highlightthickness 0
559	    SpreadSheet::tabBindings $W.e $w $r $c
560#	    for { set i 1 } { $i <= 32 } { incr i } {
561#	      Dropbox::itemadd $W $i
562#	    }
563	    update
564	    focus $W.e
565	    return 1
566	  }
567	  4 {
568	    Dropbox::new $W -variable $variable -width [expr $width - 3] -bd 1 -highlightthickness 0
569	    SpreadSheet::tabBindings $W.e $w $r $c
570	    Dropbox::itemadd $W "left"
571	    Dropbox::itemadd $W "right"
572	    Dropbox::itemadd $W "top"
573	    Dropbox::itemadd $W "bottom"
574	    update
575	    focus $W.e
576	    return 1
577	  }
578
579	}
580
581	return 0
582      }
583      delete {			# respond to the delete key
584	deletePort $iolb_w
585      }
586      closenotify {
587	incr edgat_portOpCount
588      }
589      close {
590	set r [SpreadSheet::getEffectiveRow $iolb_w [lindex $args 1]]
591	set c [lindex $args 2]
592	set data [lindex $args 3]
593
594	if { [lindex $edgat_oldentry $c] != $data } {
595	  set wop [concat [list edit [lindex $edgat_oldentry 1]] [lreplace $edgat_oldentry $c $c $data]]
596	  lappend edgat_wops $wop
597	}
598
599	return $data
600      }
601      canappend {
602	return $edcap_add
603      }
604      initentry {
605	set w [lindex $args 0]
606	set r [lindex $args 1]
607
608	set new_ent [newPortEntry]
609
610	set base_name  [string trimright [lindex $new_ent 1] 0123456789]
611	lappend edgat_wops [list add $base_name]
612
613	return $new_ent
614      }
615    }
616  }
617
618  proc seeDestroy args {
619    variable iolb_w
620    global edgat_wires
621
622    set N [SpreadSheet::size $iolb_w]
623    set edgat_wires {}
624    for { set i 0 } { $i < $N } { incr i } {
625      lappend edgat_wires [SpreadSheet::get $iolb_w $i]
626    }
627  }
628
629  #############################################################################
630  #
631  # Create the port manager window.
632  #
633  proc create {w args} {
634    variable io_w
635    variable iolb_w
636    variable edcap_sig
637    variable edcap_port
638    variable edcap_type
639    variable edcap_size
640    variable edcap_add
641    variable edcap_side
642    global edgat_wires
643
644    set edcap_sig  0
645    set edcap_port 0
646    set edcap_type 0
647    set edcap_size 0
648    set edcap_add  0
649    set edcap_side  0
650
651    parseargs $args {-editcaps}
652    foreach cap $editcaps {
653      set edcap_$cap 1
654    }
655
656
657    set io_w $w.io
658    set iolb_w $w.io.ports.lb
659
660    frame $w.io
661
662    frame $w.io.but
663    button $w.io.but.edit -text [m db.gate.edit] -command "PortMgr::editSelected  $iolb_w"
664    button $w.io.but.add -text [m db.gate.add] -command "PortMgr::addNew $iolb_w"
665    button $w.io.but.delete -text [m db.gate.delete] -command "PortMgr::deletePort $iolb_w"
666    pack $w.io.but.edit $w.io.but.add $w.io.but.delete -padx 5 -pady 5 -side left
667    pack $w.io.but -side bottom -anchor e
668    if { !$edcap_add } {
669      $w.io.but.add configure -state disabled
670      $w.io.but.delete configure -state disabled
671    }
672    pack $w.io -expand 1 -fill both
673
674
675    frame $w.io.ports
676    SpreadSheet::create $w.io.ports.lb  -height 10 -bd 1 -relief sunken -yscrollcommand "$w.io.ports.vb set"  -entrycommand PortMgr::manager -expandcol 1
677
678    SpreadSheet::addcolumn $iolb_w -width 13 -header [m db.gate.signam]
679    SpreadSheet::addcolumn $iolb_w -width 8 -header [m db.gate.port]
680    SpreadSheet::addcolumn $iolb_w -width 6  -header [m db.gate.iotype]
681    SpreadSheet::addcolumn $iolb_w -width 6  -header [m db.gate.bitws]
682    if { $edcap_side } {
683      SpreadSheet::addcolumn $iolb_w -width 6  -header [m db.gate.side]
684    }
685
686    scrollbar $w.io.ports.vb -orient vertical -command "SpreadSheet::yview $iolb_w"
687    pack $w.io.ports.lb -fill both -side left -expand 1
688    pack $w.io.ports.vb -fill both -side left
689    pack $w.io.ports -padx 10 -pady 10 -fill x -expand 1
690
691    foreach n $edgat_wires {
692      PortMgr::add end $n
693    }
694#    updateWhenIdle
695
696    bind $w.io.ports.lb <Destroy> PortMgr::seeDestroy
697  }
698}
699
700namespace eval EditGate {
701  variable clock_line_len	320.0
702  variable tap_size
703  variable wire_size
704  variable tap_lsbMax
705
706  #################################################
707  #
708  # Select interval and total width from an omega value.
709  #
710  #     P	Power of ten >= to omega
711  #     Q	Normalized omega value
712  #     V	Size of interval
713  #
714  proc chooseW {omega} {
715
716    set omega [expr 1.2*$omega ]
717    if { $omega < 10 } {set omega 10 }
718
719    for {set P 1.0} {$P < $omega} {set P [expr $P * 10.0]} {}
720
721    set Q [expr ($P - $omega)/$P ]
722
723    if { $Q >= 0.8 } {
724      set V $P*0.02
725    } elseif { $Q >= 0.6 } {
726      set V $P*0.05
727    } else {
728      set V $P*0.1
729    }
730
731    set W 0
732    for {set I 0} { $W <= $omega } { incr I } {
733      set W [expr int($I * $V) ]
734    }
735    set W [expr int($I * $V) ]
736
737    return [list $I $W]
738  }
739
740  #############################################################################
741  #
742  # Create the frame for the clock diagram.
743  #
744  proc clockFrame {w} {
745    global ecpI ecpW
746    variable clock_line_len
747
748    $w.wave delete frame
749    set clkFrame [list]
750    for {set i 0} {$i <= $ecpI } {incr i} {
751      set x [expr 15 + ($i)*$clock_line_len/$ecpI ]
752      $w.wave create line ${x} 75 ${x} 85 -tag frame
753      $w.wave create text ${x} 100 -text [expr $i*$ecpW/$ecpI ] -anchor s -tag frame
754    }
755  }
756
757  ########################################
758  #
759  # Update clock display from value change
760  #
761  proc setClockTrace {w} {
762    global ecpl1 ecpl2 ecpl3 ecpl4 ecpl5
763    global ecpE0 ecpE1 ecpE2
764    $w.wave coords $ecpl1 $ecpE0  5 $ecpE0 75
765    $w.wave coords $ecpl2 15     65 $ecpE1 65
766    $w.wave coords $ecpl3 $ecpE1 65 $ecpE1 15
767    $w.wave coords $ecpl4 $ecpE1 15 $ecpE2 15
768    $w.wave coords $ecpl5 $ecpE2 15 $ecpE2 65
769  }
770
771  ########################################
772  #
773  # Translate movement of a clock graph component to actual new positons
774  # and new parameter values.
775  #
776  #
777  proc moveClock {w x} {
778    global ecpS ecpE0 ecpE1 ecpE2
779    global ecpl1 ecpl2 ecpl3 ecpl4 ecpl5
780    global ecpPhi ecpDuty ecpOmega ecpW
781    variable clock_line_len
782
783    trace vdelete ecpOmega w EditGate::clockPUpdate
784    trace vdelete ecpPhi w EditGate::clockPUpdate
785    trace vdelete ecpDuty w EditGate::clockPUpdate
786
787    if { $ecpS == $ecpl1 } {
788      set ecpE0 $x
789      if { $ecpE0 < 15 }      { set ecpE0 15 }
790      if { $ecpE0 >= $ecpE2 } { set ecpE0 $ecpE2 }
791      set ecpPhi [expr int(100*($ecpE0 - 15)/($ecpE2 - 15)) ]
792    } elseif { $ecpS == $ecpl3 } {
793      set ecpE1 $x
794      if { $ecpE1 <= 15 }     { set ecpE1 15 }
795      if { $ecpE1 >= $ecpE2 } { set ecpE1 [expr $ecpE2 - 1] }
796      set ecpDuty [expr int(100*($ecpE1 - 15)/($ecpE2 - 15)) ]
797    } elseif { $ecpS == $ecpl5 } {
798      set ecpE2 $x
799      if { $ecpE2 <= $ecpE1 } { set ecpE2 [expr $ecpE1 + 1] }
800      if { $ecpE2 <= $ecpE0 } { set ecpE2 [expr $ecpE0 + 1] }
801      if { $ecpE2 >= [expr $clock_line_len + 15] }    { set ecpE2 [expr $clock_line_len + 15] }
802      set ecpE0 [expr 15 + int($ecpPhi*($ecpE2-15.0)/100.0)]
803      set ecpE1 [expr 15 + int($ecpDuty*($ecpE2-15.0)/100.0)]
804      set ecpOmega [expr int($ecpW*($ecpE2 - 15)/$clock_line_len) ]
805    }
806
807    trace variable ecpOmega w EditGate::clockPUpdate
808    trace variable ecpPhi w EditGate::clockPUpdate
809    trace variable ecpDuty w EditGate::clockPUpdate
810
811    setClockTrace $w
812  }
813
814
815  ########################################
816  #
817  # Translate change in parameter values to change in graph
818  #
819  proc clockPUpdate args {
820    global ecpl1 ecpl2 ecpl3 ecpl4 ecpl5
821    global ecpE0 ecpE1 ecpE2
822    global ecpW ecpI ecpOmega ecpPhi ecpDuty
823    global edgatclk_w
824    variable clock_line_len
825
826    catch {
827
828      if { [scan $ecpPhi "%d" P] != 1 } { set P 0 }
829      if { [scan $ecpDuty "%d" D] != 1 } { set D 50 }
830      if { [scan $ecpOmega "%d" O] != 1 } { set O $ecpW }
831
832      set IW [chooseW $ecpOmega]
833      set ecpI [lindex $IW 0]
834      set ecpW [lindex $IW 1]
835
836      if { $P <= 0 } { set P 0 }
837      if { $P >= 99 } { set P 99 }
838      if { $D <= 0 } { set D 1 }
839      if { $D >= 99 } { set D 99 }
840      if { $O <= 0 } { set O 1 }
841
842      set X [expr $clock_line_len*$O/$ecpW ]
843
844      set ecpE2 [expr 15 + $X ]
845      set ecpE0 [expr 15 + $X*$P/100 ]
846      set ecpE1 [expr 15 + $X*$D/100 ]
847
848      clockFrame $edgatclk_w
849      setClockTrace $edgatclk_w
850    }
851  }
852
853  ########################################
854  #
855  # Clock parameter edit window
856  #
857  proc  tabClockParms {w omega phi duty} {
858    global ecpS ecpl1 ecpl2 ecpl3 ecpl4 ecpl5
859    global ecpE0 ecpE1 ecpE2
860    global ecpW ecpI ecpOmega ecpPhi ecpDuty
861    global edgatclk_w
862    variable clock_line_len
863
864    set edgatclk_w $w
865
866    set IW [chooseW $omega]
867    set ecpI [lindex $IW 0]
868    set ecpW [lindex $IW 1]
869
870    set ecpOmega $omega
871    set ecpPhi $phi
872    set ecpDuty $duty
873
874    frame $edgatclk_w.cycle
875    label $edgatclk_w.cycle.lab -text "[m db.gate.cyclew]: " -anchor e -width 18
876    incdecEntry $edgatclk_w.cycle.ent -width 6 -variable ecpOmega -format %d
877    pack $edgatclk_w.cycle.lab $edgatclk_w.cycle.ent -side left -pady 2
878
879    frame $edgatclk_w.phase
880    label $edgatclk_w.phase.lab -text "[m db.gate.phase](%): " -anchor e -width 18
881    incdecEntry $edgatclk_w.phase.ent -width 6 -variable ecpPhi -format %d
882    pack $edgatclk_w.phase.lab $edgatclk_w.phase.ent -side left -pady 2
883
884    frame $edgatclk_w.duty
885    label $edgatclk_w.duty.lab -text "[m db.gate.duty](%): " -anchor e -width 18
886    incdecEntry $edgatclk_w.duty.ent -width 6 -variable ecpDuty -format %d
887    pack $edgatclk_w.duty.lab $edgatclk_w.duty.ent -side left -pady 2
888
889    bind $edgatclk_w.cycle.ent <KeyPress-Return> "EditGate::ok"
890    bind $edgatclk_w.phase.ent <KeyPress-Return> "EditGate::ok"
891    bind $edgatclk_w.duty.ent <KeyPress-Return> "EditGate::ok"
892
893    canvas $edgatclk_w.wave -width [expr  $clock_line_len + 30] -height 110 -closeenough 5.0 -bg white -bd 2 -relief sunken
894    $edgatclk_w.wave create line 15 75 [expr $clock_line_len + 15] 75
895    clockFrame $w
896
897    set ecpl1 [$edgatclk_w.wave create line 0 0 0 0 -tags edge ]
898    set ecpl2 [$edgatclk_w.wave create line 0 0 0 0 ]
899    set ecpl3 [$edgatclk_w.wave create line 0 0 0 0 -tags edge ]
900    set ecpl4 [$edgatclk_w.wave create line 0 0 0 0 ]
901    set ecpl5 [$edgatclk_w.wave create line 0 0 0 0 -tags edge ]
902
903    clockPUpdate
904
905    $edgatclk_w.wave bind edge <Button-1> {
906      set ecpS [$edgatclk_w.wave find withtag current]
907    }
908    $edgatclk_w.wave bind edge <B1-Motion> "EditGate::moveClock $w %x"
909    $edgatclk_w.wave bind edge <ButtonRelease-1> "EditGate::clockPUpdate"
910
911    label $edgatclk_w.l -text [m db.gate.waveform]
912
913    pack $edgatclk_w.l -anchor w
914    pack $edgatclk_w.wave
915    pack $edgatclk_w.cycle $edgatclk_w.phase $edgatclk_w.duty -anchor w
916
917    pack $edgatclk_w -fill both -padx 5 -pady 20
918
919    helpon $edgatclk_w.cycle.lab [m ho.edgat.cycle]
920    helpon $edgatclk_w.phase.lab [m ho.edgat.phase]
921    helpon $edgatclk_w.duty.lab [m ho.edgat.duty]
922  }
923
924  #############################################################################
925  #
926  # Gate delay properties
927  #
928  proc tabDelay {w} {
929    global edgat_delays edgat_dtype edgat_techList edgat_tech edgat_techdelay
930
931    frame $w.delay
932    set wd $w.delay
933
934    frame $wd.pad
935    pack $wd.pad -pady 3
936
937    frame $wd.tech_label
938    radiobutton $wd.tech_label.b -text [m db.gate.stddelay] -variable edgat_dtype -value tech -command "EditGate::dvalSetState $wd"
939#    eval "tk_optionMenu $wd.tech_label.opt edgat_tech $edgat_techList"
940
941    Dropbox::new $wd.tech_label.opt -variable edgat_tech -width 10
942    foreach item $edgat_techList {
943      Dropbox::itemadd $wd.tech_label.opt $item
944    }
945
946    pack $wd.tech_label.b -side left
947    pack $wd.tech_label.opt -side left -padx 3
948
949#    radiobutton $wd.tech_label -text [m db.gate.stddelay] -variable edgat_dtype -value tech -command "EditGate::dvalSetState $wd"
950
951
952    windowframe $wd.tech $wd.tech_label -bd 2 -relief groove -dy -3
953
954#    radioframe $wd.tech [m db.gate.stddelay] -bd 2 -relief groove -variable edgat_dtype -value tech -command "EditGate::dvalSetState $wd"
955#    radiobutton $wd.tech.b -text [m db.gate.stddelay] -variable edgat_dtype -value tech -command "EditGate::dvalSetState $wd"
956#    eval "tk_optionMenu $wd.tech.opt edgat_tech $edgat_techList"
957
958    frame $wd.tech.pad
959    pack $wd.tech.pad -pady 5
960
961
962    set idx 0
963    set r 0
964    set c 0
965    frame $wd.tech.dtab
966    set dtw $wd.tech.dtab
967    foreach d $edgat_delays {
968      label $dtw.l${r}_$c -text "$d:"
969      label $dtw.e${r}_$c -textvariable edgat_techdelay($d) -width 4 -justify left
970
971      grid $dtw.l${r}_$c -row $r -column [expr 3*$c] -padx 2 -pady 3  -sticky  e
972      grid $dtw.e${r}_$c -row $r -column [expr 3*$c+1] -padx 2 -pady 3 -sticky w
973
974      incr idx
975      incr c
976      if { $c == 3 } {
977	set c 0
978	incr r
979      }
980    }
981    grid columnconfigure $wd.tech.dtab 2 -minsize 20
982    grid columnconfigure $wd.tech.dtab 5 -minsize 20
983    pack $wd.tech.dtab -padx 5 -pady 5 -side bottom
984#    pack $wd.tech.opt  -padx 5 -pady 5 -anchor w -side left
985
986    radioframe $wd.cust [m db.gate.custdelay] -bd 2 -relief groove -variable edgat_dtype -value cust -command  "EditGate::dvalSetState $wd"
987#    radiobutton $wd.cust.b -text [m db.gate.custdelay] -variable edgat_dtype -value cust -command  "EditGate::dvalSetState $wd"
988    frame $wd.cust.pad
989    pack $wd.cust.pad -pady 5
990
991
992    set r 0
993    set c 0
994    frame $wd.cust.dtab
995    set dtw $wd.cust.dtab
996    foreach d $edgat_delays {
997      label $dtw.l${r}_$c -text "$d:"
998      entry $dtw.e${r}_$c -width 4 -textvariable edgat_delayvalue($d) -bg white
999
1000      grid $dtw.l${r}_$c -row $r -column [expr 3*$c] -padx 2 -pady 3 -sticky e
1001      grid $dtw.e${r}_$c -row $r -column [expr 3*$c+1] -padx 2 -pady 3
1002
1003      incr c
1004      if { $c == 3 } {
1005	set c 0
1006	incr r
1007      }
1008    }
1009    grid columnconfigure $wd.cust.dtab 2 -minsize 20
1010    grid columnconfigure $wd.cust.dtab 5 -minsize 20
1011    pack $wd.cust.dtab -padx 5 -pady 5
1012
1013    frame $wd.pad2
1014    pack $wd.tech $wd.pad2 $wd.cust -padx 5 -pady 3 -fill both
1015    pack $wd -padx 5 -pady 20 -fill both
1016
1017    dvalSetState $wd
1018    gat_setGateTechDelays $edgat_tech
1019
1020    helpon $wd.tech_label [m ho.techbut]
1021    helpon $wd.cust_label [m ho.custbut]
1022  }
1023
1024  #############################################################################
1025  #
1026  # Gate properties for general properties shared by all gate types.
1027  #
1028  proc tabBasic {w args} {
1029    global edgat_type edgat_name edgat_hideName edgat_blockFunc
1030
1031    if { [lindex $args 0] == "-raised" } {
1032      frame $w.basic -bd 1 -relief raised
1033    } else {
1034      frame $w.basic
1035    }
1036    pack $w.basic
1037
1038    frame $w.basic.props
1039    set wb $w.basic.props
1040
1041    label $wb.type_l -text "[m db.gate.gtype]:" -anchor e
1042    label $wb.type_e -text "$edgat_type" -width 12 -anchor w
1043    grid $wb.type_l -row 0 -column 0 -sticky e -padx 5 -pady 3
1044    grid $wb.type_e -row 0 -column 1 -sticky w -padx 5 -pady 3
1045
1046    label $wb.name_l -text "[m db.gate.gname]:" -anchor e
1047    entry $wb.name_e -width 15 -textvariable edgat_name -bg white
1048    grid $wb.name_l -row 1 -column 0 -sticky e -padx 5 -pady 3
1049    grid $wb.name_e -row 1 -column 1 -sticky w -padx 5 -pady 3
1050
1051    if { $edgat_type != "COMMENT" &&  $edgat_type != "FRAME"  &&  $edgat_type != "SCRIPT" } {
1052      label $wb.hide_l -text "[m db.gate.hidenam]:" -anchor e
1053      checkbutton $wb.hide_e -variable edgat_hideName
1054      grid $wb.hide_l -row 2 -column 0 -sticky e -padx 5 -pady 3
1055      grid $wb.hide_e -row 2 -column 1 -sticky w -padx 5 -pady 3
1056
1057      helpon $wb.hide_l [m ho.edgat.hide]
1058    }
1059
1060    label $wb.anchor_l -text "[m db.gate.anchor]:" -anchor e
1061    frame $wb.anchor_f
1062    grid $wb.anchor_l -row 3 -column 0 -sticky e -padx 5 -pady 3
1063    grid $wb.anchor_f -row 3 -column 1 -sticky w -pady 3
1064
1065    checkbutton $wb.anchor_f.ent -variable edgat_anchor
1066    label $wb.anchor_f.xlab -text "X:"
1067    entry $wb.anchor_f.xent -width 4 -textvariable edgat_xpos -bg white
1068    label $wb.anchor_f.ylab -text "Y:"
1069    entry $wb.anchor_f.yent -width 4 -textvariable edgat_ypos -bg white
1070    pack  $wb.anchor_f.ent $wb.anchor_f.xlab $wb.anchor_f.xent $wb.anchor_f.ylab $wb.anchor_f.yent -padx 5 -pady 3 -side left
1071
1072    if { $edgat_type != "Module" } {
1073      label $wb.cpbreak_l -text "[m db.gate.cpbreak]:" -anchor e
1074      checkbutton $wb.cpbreak_e -variable edgat_cpbreak
1075      grid $wb.cpbreak_l -row 4 -column 0 -sticky e -padx 5 -pady 3
1076      grid $wb.cpbreak_e -row 4 -column 1 -sticky w -padx 5 -pady 3
1077    }
1078
1079    #  checkbutton $w.
1080
1081    bind $wb.name_e <KeyPress-Return> "EditGate::ok"
1082
1083
1084    if { [lindex $args 0] == "-raised" } {
1085      pack $wb -fill both
1086    } else {
1087      pack $wb -padx 5 -pady 20
1088    }
1089
1090    helpon $wb.type_l [m ho.edgat.gtype]
1091    helpon $wb.name_l [m ho.edgat.gname]
1092    helpon $wb.anchor_l [m ho.edgat.ganchor]
1093    helpon $wb.anchor_f.xlab [m ho.edgat.gx]
1094    helpon $wb.anchor_f.ylab [m ho.edgat.gy]
1095  }
1096
1097  proc dvalSetState {w} {
1098    global edgat_delays edgat_dtype
1099
1100    catch {
1101      if { $edgat_dtype == "tech" } {
1102	set state "disabled"
1103      } else {
1104	set state "normal"
1105      }
1106
1107      set r 0
1108      set c 0
1109      set tdtw $w.tech.dtab
1110      set dtw $w.cust.dtab
1111      foreach d $edgat_delays {
1112	$dtw.e${r}_$c configure -state $state
1113
1114	if { $state == "normal" } {
1115	  $dtw.e${r}_$c configure -foreground black
1116	  $dtw.l${r}_$c configure -foreground black
1117	  $tdtw.e${r}_$c configure -foreground dimgray
1118	  $tdtw.l${r}_$c configure -foreground dimgray
1119	} else {
1120	  $dtw.e${r}_$c configure -foreground dimgray
1121	  $dtw.l${r}_$c configure -foreground dimgray
1122	  $tdtw.e${r}_$c configure -foreground black
1123	  $tdtw.l${r}_$c configure -foreground black
1124	}
1125
1126	incr c
1127	if { $c == 3 } {
1128	  set c 0
1129	  incr r
1130	}
1131      }
1132    }
1133  }
1134
1135  #
1136  # Pin placement properties of mux and demux.
1137  #
1138  proc tabMux {w} {
1139    global edgat_type
1140
1141    switch $edgat_type {
1142      MUX {
1143	set prefix db.gate.mux
1144	set ord1 [gifI muxord1.gif]
1145	set ord2 [gifI muxord2.gif]
1146	set sel1 [gifI muxsel1.gif]
1147	set sel2 [gifI muxsel2.gif]
1148
1149	set uord1 [gifI Umuxord1.gif]
1150	set uord2 [gifI Umuxord2.gif]
1151	set usel1 [gifI Umuxsel1.gif]
1152	set usel2 [gifI Umuxsel2.gif]
1153      }
1154      DECODER {
1155	set prefix db.gate.decoder
1156	set ord1 [gifI demuxord1.gif]
1157	set ord2 [gifI demuxord2.gif]
1158	set sel1 [gifI demuxsel1.gif]
1159	set sel2 [gifI demuxsel2.gif]
1160
1161	set uord1 [gifI Udemuxord1.gif]
1162	set uord2 [gifI Udemuxord2.gif]
1163	set usel1 [gifI Udemuxsel1.gif]
1164	set usel2 [gifI Udemuxsel2.gif]
1165      }
1166      DEMUX {
1167	set prefix db.gate.demux
1168	set ord1 [gifI demuxord1.gif]
1169	set ord2 [gifI demuxord2.gif]
1170	set sel1 [gifI demuxsel1.gif]
1171	set sel2 [gifI demuxsel2.gif]
1172
1173	set uord1 [gifI Udemuxord1.gif]
1174	set uord2 [gifI Udemuxord2.gif]
1175	set usel1 [gifI Udemuxsel1.gif]
1176	set usel2 [gifI Udemuxsel2.gif]
1177      }
1178    }
1179
1180    set wraplength 130
1181
1182    #############################################################################
1183    labelframe $w.dataord [m $prefix.dataorder]
1184
1185    imageRadioButton $w.dataord.ascend -onimage $ord1 -offimage $uord1 -wraplength $wraplength \
1186	-variable edgat_dataOrder -value 0 -label [m $prefix.ord1.hdr] -description [m $prefix.ord1.exp]
1187
1188    imageRadioButton $w.dataord.descend -onimage $ord2 -offimage $uord2 -wraplength $wraplength \
1189	-variable edgat_dataOrder -value 1 -label [m $prefix.ord2.hdr] -description [m $prefix.ord2.exp]
1190
1191    frame $w.dataord.toppad -height 10
1192    frame $w.dataord.botpad -height 5
1193    pack $w.dataord.toppad
1194    pack $w.dataord.botpad -side bottom
1195    pack $w.dataord.ascend $w.dataord.descend -padx 4 -side left
1196
1197    #############################################################################
1198    labelframe $w.selsty [m $prefix.select]
1199
1200
1201    imageRadioButton $w.selsty.onleft -onimage $sel1 -offimage $usel1 -wraplength $wraplength \
1202	-variable edgat_selectSide -value 0 -label [m $prefix.sel1.hdr] -description [m $prefix.sel1.exp]
1203
1204    imageRadioButton $w.selsty.onright -onimage $sel2 -offimage $usel2 -wraplength $wraplength \
1205	-variable edgat_selectSide -value 1 -label [m $prefix.sel2.hdr] -description [m $prefix.sel2.exp]
1206
1207    frame $w.selsty.toppad -height 10
1208    frame $w.selsty.botpad -height 5
1209    pack $w.selsty.toppad
1210    pack $w.selsty.botpad -side bottom
1211    pack $w.selsty.onleft $w.selsty.onright -padx 4 -side left
1212
1213    #############################################################################
1214
1215    frame $w.pad -height 10
1216    frame $w.pad2 -height 10
1217
1218    pack $w.pad
1219    pack $w.dataord -anchor w -fill both -padx 5
1220    pack $w.pad2
1221    pack $w.selsty -anchor w -fill both -padx 5
1222  }
1223
1224  #############################################################################
1225  #
1226  # Gate property tab for flip-flop gates.
1227  #
1228  proc tabFF {w ff} {
1229    global edgat_ffmirror
1230
1231    labelframe $w.fftype [m db.gate.$ff.type]
1232
1233    set wraplength 130
1234
1235    imageRadioButton $w.fftype.normal -onimage [gifI $ff.gif] -offimage [gifI U$ff.gif] -wraplength $wraplength \
1236	-variable edgat_ffmirror -value 0 -label [m db.gate.$ff.normal.hdr] -description [m db.gate.$ff.normal.exp]
1237
1238    imageRadioButton $w.fftype.reverse -onimage [gifI r$ff.gif] -offimage [gifI Ur$ff.gif] -wraplength $wraplength \
1239	-variable edgat_ffmirror -value 1 -label [m db.gate.$ff.reverse.hdr] -description [m db.gate.$ff.reverse.exp]
1240
1241    frame $w.fftype.toppad -height 10
1242    frame $w.fftype.botpad -height 5
1243    pack $w.fftype.toppad
1244    pack $w.fftype.botpad -side bottom
1245    pack $w.fftype.normal $w.fftype.reverse -padx 4 -side left
1246
1247    pack $w.fftype -fill both -padx 5 -pady 20
1248  }
1249
1250  #############################################################################
1251  #
1252  # Gate property tab for concat gates.
1253  #
1254  proc tabConcatPlace {w} {
1255    labelframe $w.catdir [m db.gate.catdiruse]
1256
1257    set wraplength 130
1258
1259    #
1260    # The "ascending" button
1261    #
1262    imageRadioButton $w.catdir.ascend -onimage [gifI cat_asc.gif] -offimage [gifI Ucat_asc.gif] -wraplength $wraplength \
1263	-variable edgat_catdir -value 1 -label [m db.gate.cat.asc.hdr] -description [m db.gate.cat.asc.exp]
1264
1265    #
1266    # The "descending" button
1267    #
1268    imageRadioButton $w.catdir.descend -onimage [gifI cat_dec.gif] -offimage [gifI Ucat_dec.gif] -wraplength $wraplength \
1269	-variable edgat_catdir -value 0 -label [m db.gate.cat.dec.hdr] -description [m db.gate.cat.dec.exp]
1270
1271    #
1272    # Button layout
1273    #
1274    grid $w.catdir.ascend -row 0 -column 0 -padx 3 -pady 8 -sticky nw
1275    grid $w.catdir.descend -row 0 -column 1 -padx 3 -pady 8 -sticky nw
1276
1277    #############################################################################
1278    labelframe $w.sigdir [m db.gate.cat.sigdir]
1279
1280
1281    frame $w.sigdir.toppad -height 5
1282    frame $w.sigdir.botpad -height 5
1283
1284    #
1285    # The "auto" button
1286    #
1287    imageRadioButton $w.sigdir.auto -onimage [gifI cat_auto.gif] -offimage [gifI Ucat_auto.gif] -wraplength $wraplength \
1288	-variable edgat_sigdir -value 2 -label [m db.gate.cat.auto.hdr] -description [m db.gate.cat.auto.exp]
1289
1290    #
1291    # The "Multi-Input" button
1292    #
1293    imageRadioButton $w.sigdir.multin -onimage [gifI cat_multin.gif] -offimage [gifI Ucat_multin.gif] -wraplength $wraplength \
1294	-variable edgat_sigdir -value 1 -label [m db.gate.cat.multin.hdr] -description [m db.gate.cat.multin.exp]
1295
1296    #
1297    # The "Single-Input" button
1298    #
1299    imageRadioButton $w.sigdir.singin -onimage [gifI cat_singin.gif] -offimage [gifI Ucat_singin.gif] -wraplength $wraplength \
1300	-variable edgat_sigdir -value 0 -label [m db.gate.cat.singin.hdr] -description [m db.gate.cat.singin.exp]
1301
1302    #
1303    # The "tran" button
1304    #
1305    imageRadioButton $w.sigdir.tran -onimage [gifI cat_tran.gif] -offimage [gifI Ucat_tran.gif] -wraplength $wraplength \
1306	-variable edgat_sigdir -value 3 -label [m db.gate.cat.tran.hdr] -description [m db.gate.cat.tran.exp]
1307
1308    grid $w.sigdir.toppad -row 0
1309    grid $w.sigdir.auto   -row 1 -column 0 -padx 3 -pady 3 -sticky nw
1310    grid $w.sigdir.multin	-row 1 -column 1 -padx 3 -pady 3 -sticky nw
1311    grid $w.sigdir.tran   -row 2 -column 0 -padx 3 -pady 3 -sticky nw
1312    grid $w.sigdir.singin -row 2 -column 1 -padx 3 -pady 3 -sticky nw
1313    grid $w.sigdir.botpad -row 3
1314
1315    #############################################################################
1316
1317    frame $w.pad -height 10
1318    frame $w.pad2 -height 10
1319
1320    pack $w.pad
1321    pack $w.catdir -anchor w -fill both -padx 5
1322    pack $w.pad2
1323    pack $w.sigdir -anchor w -fill both -padx 5
1324  }
1325
1326  #############################################################################
1327  #
1328  # Gate property tab for gates that can have extender bars.
1329  #
1330  proc tabCrunchExtGate {w} {
1331    global edgat_extbar
1332
1333    frame $w.pad -height 10
1334    pack $w.pad
1335
1336    set wraplength 130
1337
1338    #############################################################################
1339    labelframe $w.extbar [m db.gate.aox.extbaruse]
1340
1341    imageRadioButton $w.extbar.use -onimage [gifI extbarand.gif] -offimage [gifI Uextbarand.gif] -wraplength $wraplength \
1342	-variable edgat_extbar -value 1 -label [m db.gate.aox.use.hdr] -description [m db.gate.aox.use.exp]
1343
1344    imageRadioButton $w.extbar.nouse -onimage [gifI crunchand.gif] -offimage [gifI Ucrunchand.gif] -wraplength $wraplength \
1345	-variable edgat_extbar -value 0 -label [m db.gate.aox.nouse.hdr] -description [m db.gate.aox.nouse.exp]
1346
1347    frame $w.extbar.toppad -height 10
1348    frame $w.extbar.botpad -height 10
1349    pack $w.extbar.toppad
1350    pack $w.extbar.botpad -side bottom
1351    pack $w.extbar.use $w.extbar.nouse -padx 4 -side left
1352
1353    #############################################################################
1354    pack $w.extbar -anchor w -fill both -padx 5
1355
1356    #  helpon $w.extbar.use.b [m ho.edgat.extbar]
1357    #  helpon $w.extbar.nouse.b [m ho.edgat.extbar]
1358    #  helpon $w.extbar.use.i [m ho.edgat.extbar]
1359    #  helpon $w.extbar.nouse.i [m ho.edgat.extbar]
1360  }
1361
1362  #############################################################################
1363  #
1364  # Gate property tab for setting Switch properties.
1365  #
1366  proc tabSwitch {w} {
1367    global edgat_switch
1368
1369    set wraplength 130
1370
1371    labelframe $w.state [m db.gate.switch.state]
1372    packPad $w.state
1373    imageRadioButton $w.state.on -onimage [gifI onswitch.gif] -offimage [gifI Uonswitch.gif] \
1374	-wraplength $wraplength -variable edgat_switch -value 1 \
1375	-label [m db.gate.switch.state.on.hdr] -description [m db.gate.switch.state.on.exp]
1376
1377    imageRadioButton $w.state.off -onimage [gifI offswitch.gif] -offimage [gifI Uoffswitch.gif] \
1378	-wraplength $wraplength -variable edgat_switch -value 0 \
1379	-label [m db.gate.switch.state.off.hdr] -description [m db.gate.switch.state.off.exp]
1380    pack $w.state.on $w.state.off -padx 4 -pady 5 -side left
1381
1382    labelframe $w.shownet [m db.gate.switch.shownet]
1383    packPad $w.shownet
1384    imageRadioButton $w.shownet.on -onimage [gifI wsswitch.gif] -offimage [gifI Uwsswitch.gif] \
1385	-wraplength $wraplength -variable edgat_shownet -value 1 \
1386	-label [m db.gate.switch.shownet.on.hdr] -description [m db.gate.switch.shownet.on.exp]
1387    imageRadioButton $w.shownet.off -onimage [gifI nwsswitch.gif] -offimage [gifI Unwsswitch.gif] \
1388	-wraplength $wraplength -variable edgat_shownet -value 0 \
1389	-label [m db.gate.switch.shownet.off.hdr] -description [m db.gate.switch.shownet.off.exp]
1390    pack $w.shownet.on $w.shownet.off -padx 4 -pady 5 -side left -anchor n
1391
1392    packPad $w
1393    pack $w.state -fill both -padx 5 -pady 5
1394    pack $w.shownet -fill both -padx 5 -pady 5
1395
1396#    helpon $w.switch.state [m ho.edgat.swstate]
1397  }
1398
1399  proc dipValChange {w args} {
1400    global edgat_dip
1401
1402    set n $edgat_dip
1403    if { $n == ""} { set n "0" }
1404
1405    $w.dip.c itemconfigure value -text $n
1406  }
1407
1408  #############################################################################
1409  #
1410  # Gate property tab for setting wire tab properties.
1411  #
1412  proc tabDip {w} {
1413    global edgat_dip
1414
1415    #
1416    # State Property
1417    #
1418    labelframe $w.state [m db.gate.dip.value]
1419    packPad $w.state
1420
1421    canvas $w.state.c -width 150 -height 70 -bg white -bd 1 -relief sunken
1422    $w.state.c create image 100 35 -image [gifI setdip.gif]
1423    $w.state.c create text 100 18 -text $edgat_dip -font dipFont -fill blue -tags value
1424
1425    set wrap [rescale [m @db.gate.dip.value.exp.width]]
1426    label $w.state.e -text [m db.gate.dip.value.exp] -justify left -wraplength $wrap -font dialogExpFont
1427    label $w.state.l -text [m db.gate.dip.value.hex]
1428    incdecEntry $w.state.ent -width 12 -variable edgat_dip -format %x -validatecommand hexValidate
1429
1430    pack $w.state.e -side left -fill both -padx 5
1431    pack $w.state.c -padx 5 -pady 5 -side bottom -fill x
1432
1433    pack $w.state.ent -padx 5 -pady 5 -side right -anchor w
1434    pack $w.state.l -side right -anchor w
1435
1436    trace variable ::edgat_dip w "EditGate::dipValChange $w"
1437    bind $w.state <Destroy> "trace vdelete ::edgat_dip w \"EditGate::dipValChange $w\""
1438
1439    #
1440    # Show Net Property
1441    #
1442    set wraplength 130
1443    labelframe $w.shownet [m db.gate.dip.shownet]
1444    packPad $w.shownet
1445    imageRadioButton $w.shownet.on -onimage [gifI wsdip.gif] -offimage [gifI Uwsdip.gif] \
1446	-wraplength $wraplength -variable edgat_shownet -value 1 \
1447	-label [m db.gate.dip.shownet.on.hdr] -description [m db.gate.dip.shownet.on.exp]
1448    imageRadioButton $w.shownet.off -onimage [gifI nwsdip.gif] -offimage [gifI Unwsdip.gif] \
1449	-wraplength $wraplength -variable edgat_shownet -value 0 \
1450	-label [m db.gate.dip.shownet.off.hdr] -description [m db.gate.dip.shownet.off.exp]
1451    pack $w.shownet.on $w.shownet.off -padx 4 -pady 5 -side left -anchor n
1452
1453    #
1454    # Final layout
1455    #
1456    packPad $w
1457    pack $w.state -fill both -padx 5 -pady 5
1458    pack $w.shownet -fill both -padx 5 -pady 5
1459
1460#    frame $w.dip
1461#    label $w.dip.label -text "[m db.gate.dipval]:"
1462#    entry $w.dip.state -textvariable edgat_dip -bg white
1463#    pack $w.dip.label $w.dip.state -padx 5 -pady 5 -side left -anchor w
1464#    bind $w.dip.state <KeyPress-Return> "EditGate::ok"
1465
1466#    helpon $w.dip.label [m ho.edgat.dipstate]
1467  }
1468
1469
1470  proc tabTapUpdateRange {w args} {
1471    global edgat_tap
1472    $w.tap.c itemconfig range -text $edgat_tap
1473  }
1474
1475  proc tabTapBuild {w args} {
1476    global edgat_tap edgatTap_lsb
1477    global tkg_wireColor tkg_busColor tkg_instColor
1478    variable tap_size
1479    variable wire_size
1480    variable tap_lsbMax
1481
1482    set n [SpreadSheet::size $PortMgr::iolb_w]
1483    for { set i 0} {$i < $n} {incr i} {
1484      set row [SpreadSheet::get $PortMgr::iolb_w $i]
1485      set name [lindex $row 1]
1486      set bits [lindex $row 3]
1487      if { $name == "Z" } { set tap_size $bits }
1488      if { $name == "D" } { set wire_size $bits }
1489    }
1490
1491    #
1492    # The wire sizing is currently illegal, so just treat
1493    # tap as the same size as the wire.
1494    #
1495    if { $tap_size > $wire_size} {
1496      set tap_size $wire_size
1497    }
1498
1499    #
1500    # Maximum value for LSB
1501    #
1502    set tap_lsbMax [expr $wire_size-$tap_size]
1503
1504    #
1505    # Fix LSB if it is out of range
1506    #
1507    if {$edgatTap_lsb > $tap_lsbMax} {
1508      set edgatTap_lsb $tap_lsbMax
1509    }
1510
1511    incdecEntry_configure $w.tap.lsb -max $tap_lsbMax
1512
1513    $w.tap.c delete all
1514
1515    #
1516    # wire tap position
1517    #
1518    set width [$w.tap.c cget -width]
1519    set height [$w.tap.c cget -height]
1520    set x 20
1521    set y [expr $height/2]
1522    set tap_len [expr $width - 25]
1523    set wire_len [expr $height/2 -5]
1524    set x1 [expr $x + $tap_len]
1525    set y1 [expr $y - $wire_len]
1526    set y2 [expr $y + $wire_len]
1527
1528    if { $tap_size > 1 } {
1529      $w.tap.c create line $x $y $x1 $y -width 2 -fill $tkg_busColor
1530
1531      set x3 [expr $x + $tap_len - 15]
1532
1533      $w.tap.c create line [expr $x3-4] [expr $y+4] [expr $x3+4] [expr $y-4] -fill red
1534      $w.tap.c create text $x3 [expr $y-8] -text $tap_size -fill red -anchor s
1535
1536      $w.tap.exp configure -text [m db.gate.tap.exp.bus]
1537      $w.tap.l configure -text [m db.gate.tap.lbl.bus]
1538    } else {
1539      $w.tap.c create line $x $y $x1 $y -width 1 -fill $tkg_wireColor
1540
1541      $w.tap.exp configure -text [m db.gate.tap.exp.bit]
1542      $w.tap.l configure -text [m db.gate.tap.lbl.bit]
1543    }
1544    if { $wire_size > 1 } {
1545      $w.tap.c create line $x $y1 $x $y2 -width 2 -fill $tkg_busColor
1546
1547      set y3 [expr ($y+$y2)/2]
1548
1549      $w.tap.c create line [expr $x-4] [expr $y3+4] [expr $x+4] [expr $y3-4] -fill red
1550      $w.tap.c create text [expr $x+8] $y3 -text $wire_size -fill red -anchor w
1551    } else {
1552      $w.tap.c create line $x $y1 $x $y2 -width 1 -fill $tkg_wireColor
1553    }
1554    $w.tap.c create polygon [expr $x+1] [expr $y -5]  [expr $x + 5] $y  [expr $x+1] [expr $y + 5] -fill $tkg_instColor
1555    $w.tap.c create text [expr $x+8] [expr $y-5] -text $edgat_tap -anchor sw -fill $tkg_instColor -tags range
1556  }
1557
1558  proc tabTapUpdateLSB {w args} {
1559    global edgat_tap edgatTap_lsb
1560    variable tap_size
1561    variable wire_size
1562    variable tap_lsbMax
1563
1564    #
1565    # Do range checking of lsb before we use it for bit-tap expression
1566    #
1567    set lsb $edgatTap_lsb
1568
1569    #
1570    # Fix LSB if it is out of range
1571    #
1572    if {$lsb > $tap_lsbMax} {
1573      set lsb $tap_lsbMax
1574    }
1575    if {$lsb < 0} {
1576      set lsb 0
1577    }
1578
1579
1580    if { $tap_size > 1 } {
1581      set edgat_tap [expr $lsb + $tap_size - 1]:$lsb
1582    } else {
1583      set edgat_tap $lsb
1584    }
1585  }
1586
1587  #############################################################################
1588  #
1589  # Gate property tab for setting wire tab properties.
1590  #
1591  proc tabTap {w} {
1592    global edgat_tap edgatTap_lsb
1593    variable tap_size
1594    variable wire_size
1595
1596    set tap_size 0
1597    set wire_size 0
1598
1599    labelframe $w.tap [m db.gate.tap.select]
1600    packPad $w.tap
1601
1602    if { [scan $edgat_tap %*d:%d edgatTap_lsb] == 1} {
1603    } else {
1604      set edgatTap_lsb $edgat_tap
1605    }
1606
1607    label $w.tap.exp -wraplength [mr @db.gate.tap.exp.width] -justify left
1608    label $w.tap.l
1609    incdecEntry $w.tap.lsb -width 5 -variable edgatTap_lsb -format %d -min 0
1610
1611    canvas $w.tap.c -width 100 -height 100 -bg white -bd 1 -relief sunken
1612    tabTapBuild $w
1613
1614    pack $w.tap.c -padx 5 -pady 5 -side right
1615    pack $w.tap.exp -padx 5 -pady 5 -side top -anchor w
1616    pack $w.tap.l -padx 5 -pady 5 -side left -anchor w
1617    pack $w.tap.lsb -padx 5 -pady 5 -side left -anchor w
1618
1619
1620    pack $w.tap -fill both -padx 5 -pady 20
1621
1622    trace variable ::edgat_portOpCount w "EditGate::tabTapBuild $w"
1623    trace variable ::edgat_tap w "EditGate::tabTapUpdateRange $w"
1624    trace variable ::edgatTap_lsb w "EditGate::tabTapUpdateLSB $w"
1625    bind $w <Destroy> "trace vdelete ::edgat_portOpCount w \"EditGate::tabTapBuild $w\""
1626    bind $w <Destroy> "+ trace vdelete ::edgat_tap w \"EditGate::tabTapUpdateRange $w\""
1627    bind $w <Destroy> "+ trace vdelete ::edgatTap_lsb w \"EditGate::tabTapUpdateLSB $w\""
1628  }
1629
1630  #############################################################################
1631  #
1632  # Gate property tab for setting Memory properties.
1633  #
1634  proc tabMem {w} {
1635    global edgat_memFile edgatmem_w
1636
1637    set edgatmem_w $w.mem
1638    frame $w.mem
1639    label $w.mem.label -text "[m db.gate.memfilenam]:"
1640    entry $w.mem.file -textvariable edgat_memFile -bg white
1641    button $w.mem.browse -text [m b.browse]  -command {
1642      global mem_filter mem_filetypes edgate_memFile edgatmem_w
1643      set file [tk_getOpenFile -defaultextension $mem_filter -filetypes $mem_filetypes -parent .edgat]
1644      if { $file != "" } {
1645	set edgat_memFile $file
1646	$edgatmem_w.file icursor end
1647	$edgatmem_w.file xview end
1648      }
1649    }
1650
1651    pack $w.mem.label $w.mem.file $w.mem.browse -padx 5 -pady 5 -side left -anchor w
1652    pack $w.mem -fill both -padx 5 -pady 20
1653    bind $w.mem.file <KeyPress-Return> "EditGate::ok"
1654
1655    helpon $w.mem.label [m ho.edgat.memfile]
1656  }
1657
1658  #############################################################################
1659  #
1660  # User requested a new module on the edgat box
1661  #
1662  proc newModule {w} {
1663    global edgat_blockFunc
1664    BlockOp::new -parent .edgat
1665
1666    if { $BlockOp::props(ok) == 1 } {
1667      Dropbox::flush $w.mod.funcF.name
1668      foreach m [BlockList::getallmodules -types {module part}] {
1669	Dropbox::itemadd $w.mod.funcF.name     $m
1670      }
1671      set edgat_blockFunc $BlockOp::props(name)
1672    }
1673  }
1674
1675  #############################################################################
1676  #
1677  # Gate property tab for setting Module properties.
1678  #
1679  proc tabModule {w} {
1680    global edgat_newBlock edgat_blockFunc
1681
1682    frame $w.mod
1683
1684
1685    label $w.mod.funcL -text "[m db.gate.modname]:" -width 12 -anchor e
1686    frame $w.mod.funcF
1687
1688    tkg_moduleSelector $w.mod.funcF.name -width 20 -variable edgat_blockFunc -value $edgat_blockFunc -entry 0 -nomain 1
1689    button $w.mod.funcF.new -text [m b.new]... -command "EditGate::newModule $w"
1690    pack $w.mod.funcF.name $w.mod.funcF.new -anchor w -side left -padx 5
1691
1692    pack $w.mod.funcL -padx 5 -pady 5 -side left
1693    pack $w.mod.funcF -pady 5 -side left
1694
1695    focus $w.mod.funcF.name.e
1696
1697    helpon $w.mod.funcL [m ho.edgat.func]
1698    pack $w.mod -fill both -padx 5 -pady 20
1699  }
1700
1701  #############################################################################
1702  #
1703  # Gate property tab for setting Frame properties.
1704  #
1705  proc tabFrame {w} {
1706    global edgat_newBlock
1707
1708    frame $w.frm
1709    label $w.frm.lab -text "[m b.label]:" -anchor e
1710    entry $w.frm.ent -width 30 -textvariable edgat_frameLabel -bg white
1711    bind $w.frm.ent <KeyPress-Return> "EditGate::ok"
1712    pack $w.frm.lab -padx 5 -pady 5 -side left
1713    pack $w.frm.ent -padx 5 -pady 5 -side left -fill both -expand 1
1714    pack $w.frm -anchor w
1715    if { $edgat_newBlock } {
1716      #    $w.frm.ent selection range 0 end
1717      focus $w.frm.ent
1718    }
1719    helpon $w.frm.lab [m ho.edgat.frame]
1720    pack $w.frm -fill both -padx 5 -pady 20
1721
1722    focus $w.frm.ent
1723    $w.frm.ent selection range 0 end
1724    $w.frm.ent icursor end
1725  }
1726
1727  #############################################################################
1728  #
1729  # Gate property tab for setting LED properties.
1730  #
1731  proc tabLED {w} {
1732    global edgat_newBlock
1733
1734    set wraplength 130
1735
1736    labelframe $w.led [m db.gate.led.type]
1737
1738    imageRadioButton $w.led.bit -onimage [gifI led_bit.gif] -offimage [gifI Uled_bit.gif] -wraplength $wraplength \
1739	-variable edgat_ledType -value 0 -label [m db.gate.led.bit.hdr] -description [m db.gate.led.bit.exp]
1740
1741    imageRadioButton $w.led.bar -onimage [gifI led_bar.gif] -offimage [gifI Uled_bar.gif] -wraplength $wraplength \
1742	-variable edgat_ledType -value 1 -label [m db.gate.led.bar.hdr] -description [m db.gate.led.bar.exp]
1743
1744    imageRadioButton $w.led.hex -onimage [gifI led_hex.gif] -offimage [gifI Uled_hex.gif] -wraplength $wraplength \
1745	-variable edgat_ledType -value 2 -label [m db.gate.led.hex.hdr] -description [m db.gate.led.hex.exp]
1746
1747    imageRadioButton $w.led.dec -onimage [gifI led_dec.gif] -offimage [gifI Uled_dec.gif] -wraplength $wraplength \
1748	-variable edgat_ledType -value 3 -label [m db.gate.led.dec.hdr] -description [m db.gate.led.dec.exp]
1749
1750    imageRadioButton $w.led.seg -onimage [gifI led_direct.gif] -offimage [gifI Uled_direct.gif] -wraplength $wraplength \
1751	-variable edgat_ledType -value 4 -label [m db.gate.led.seg.hdr] -description [m db.gate.led.seg.exp]
1752
1753
1754    frame $w.led.pad1 -height 10
1755    frame $w.led.pad2 -height 10
1756    frame $w.led.pad3 -height 10
1757    frame $w.led.pad4 -height 10
1758
1759    grid $w.led.pad1 -row 0 -column 0
1760    grid $w.led.bit  -row 1 -column 0 -sticky w
1761    grid $w.led.bar  -row 1 -column 1 -sticky w
1762
1763    grid $w.led.pad2 -row 2 -column 0
1764    grid $w.led.hex  -row 3 -column 0 -sticky w
1765    grid $w.led.dec  -row 3 -column 1 -sticky w
1766
1767    grid $w.led.pad3 -row 4 -column 0
1768    grid $w.led.seg  -row 5 -column 0 -sticky w
1769
1770    grid $w.led.pad4 -row 6 -column 0
1771
1772    pack $w.led -fill both -padx 5 -pady 20
1773  }
1774
1775  #############################################################################
1776  #
1777  # This procedure is called when the OK button is pressed
1778  #
1779  proc ok {} {
1780    global edgat_ok edgat_type edgat_blockFunc
1781
1782    set edgat_ok 1
1783
1784    switch $edgat_type {
1785      COMMENT {
1786	# The saveComment will fail if the Text tab is not active, but that is ok
1787	# since in this case the edgat_commentLines() array will be up to date.
1788	# JPH 1/19/09 - The above statement may no longer be true due to the new
1789	# tabbox implementation.  We may not need the "catch" anymore.
1790	catch { saveComment }
1791      }
1792      SCRIPT {
1793	# Reusing comment editing for script editing
1794	catch { saveComment }
1795      }
1796      MODULE {
1797	if { $edgat_blockFunc == "" } {
1798	  errmsg [m err.nofunc]
1799	  set edgat_ok 0
1800	}
1801      }
1802      SYMMODULE {
1803	if { $edgat_blockFunc == "" } {
1804	  errmsg [m err.nofunc]
1805	  set edgat_ok 0
1806	}
1807      }
1808    }
1809
1810    destroy .edgat
1811  }
1812
1813  #############################################################################
1814  #
1815  # This procedure is called when the Cancel button is pressed
1816  #
1817  proc cancel {} {
1818    global edgat_ok
1819
1820    set edgat_ok 0
1821    destroy .edgat
1822  }
1823
1824  proc saveScript {w} {
1825    global edgat_commentLen edgat_commentLines edgat_ok
1826
1827    for { set i 1 } { [$w compare $i.end < end] } { incr i } {
1828      set x [$w get $i.0 $i.end]
1829      set j [expr $i - 1]
1830      set edgat_commentLines($j) $x
1831    }
1832    set edgat_commentLen [expr $i - 1]
1833
1834    HdlEditor::dbHide
1835  }
1836
1837  proc tabScriptText {w} {
1838    global edgat_commentLines edgat_commentLen
1839    global edgat_comment_w
1840
1841    HdlEditor::new $w.script -width 1 -height 1 -keygroup hdledit
1842    pack $w.script -expand 1 -fill both
1843    HdlEditor::dbShow $w.script
1844
1845
1846    set tw $w.script.pane.main.t
1847
1848    for {set i 0 } { $i < $edgat_commentLen } { incr i } {
1849      if { $i > 0 } { $tw insert end "\n" }
1850      $tw insert end  $edgat_commentLines($i)
1851    }
1852    HdlEditor::recolorize 1.0 end
1853
1854    frame $tw.destroyDetect
1855    bind $tw.destroyDetect <Destroy> "EditGate::saveScript $tw"
1856  }
1857
1858  #############################################################################
1859  #
1860  # Save contents of the comment text
1861  #
1862  proc saveComment {} {
1863    global edgat_commentLen edgat_commentLines edgat_ok
1864    global edgat_comment_w
1865
1866    set w $edgat_comment_w
1867
1868    for { set i 1 } { [$w.f.t compare $i.end < end] } { incr i } {
1869      set x [$w.f.t get $i.0 $i.end]
1870      set j [expr $i - 1]
1871      set edgat_commentLines($j) $x
1872    }
1873    set edgat_commentLen [expr $i - 1]
1874  }
1875
1876  #############################################################################
1877  #
1878  # Gate property tab for editing comment text.
1879  #
1880  proc tabCommentText {w} {
1881    global edgat_commentLines edgat_commentLen
1882    global edgat_comment_w
1883
1884    frame $w.ctext
1885    set edgat_comment_w $w.ctext
1886
1887    frame $w.ctext.f
1888    text $w.ctext.f.t -yscrollcommand "$w.ctext.f.vb set" -xscrollcommand "$w.ctext.f.hb set" -width 1 -height 1 -bg white
1889# -width [m @db.gate.comment.width] -height [m @db.gate.comment.height]
1890    scrollbar $w.ctext.f.vb -command "$w.ctext.f.t yview"
1891    scrollbar $w.ctext.f.hb -command "$w.ctext.f.t xview" -orient horizontal
1892
1893    grid rowconfig $w.ctext.f 0  -weight 1 -minsize 0
1894    grid columnconfig $w.ctext.f 0 -weight 1 -minsize 0
1895
1896    grid $w.ctext.f.t -row 0 -column 0 -sticky news
1897    grid $w.ctext.f.vb -row 0 -column 1 -sticky news
1898    grid $w.ctext.f.hb -row 1 -column 0 -sticky news
1899    pack $w.ctext.f -ipadx 5 -ipady 5 -fill both -expand 1 -padx 5 -pady 5
1900
1901    for {set i 0 } { $i < $edgat_commentLen } { incr i } {
1902      if { $i > 0 } { $w.ctext.f.t insert end "\n" }
1903      $w.ctext.f.t insert end  $edgat_commentLines($i)
1904    }
1905
1906    #
1907    # This sub-window is created but not packed.  It is used to detect a destroy of the
1908    # text window and get control before the text window is actually destroyed.
1909    #
1910    frame $w.ctext.f.t.destroyDetect
1911    bind $w.ctext.f.t.destroyDetect <Destroy> EditGate::saveComment
1912
1913    pack $w.ctext -fill both -expand 1
1914
1915    focus $w.ctext.f.t
1916  }
1917
1918  #############################################################################
1919  #
1920  # Handle a tab selection in the edit gate dialog box
1921  #
1922  proc dotab {w tab} {
1923    global edgat_type edgat_name edgat_hideName edgat_geom
1924    global ecpOmega ecpPhi ecpDuty
1925    global editgate_caps
1926
1927    frame $w
1928    frame $w.props
1929    pack $w.props -side right -fill both -expand 1
1930
1931    set gif general.gif
1932    set explaination [m db.gate.tab.${tab}.exp]
1933    set caption [m db.gate.tab.${tab}.cap]
1934
1935    switch $tab {
1936      General {
1937	tabBasic $w.props
1938	set gif gateprops.gif
1939      }
1940      Ports {
1941	if { [catch { set caplist $editgate_caps($edgat_type)}]} {
1942	  set caplist { sig size }
1943	}
1944	PortMgr::create $w.props -editcaps $caplist
1945	#      edgatIO $w.props
1946	set gif port.gif
1947      }
1948      Delay {
1949	tabDelay $w.props
1950	set gif delay.gif
1951      }
1952      Parameters {
1953	ModParmMgr::create $w.props
1954      }
1955      CLOCK {
1956	tabClockParms $w.props $ecpOmega $ecpPhi $ecpDuty
1957	set gif details.gif
1958      }
1959      SWITCH {
1960	tabSwitch $w.props
1961	set gif details.gif
1962      }
1963      DIP {
1964	tabDip $w.props
1965	set gif details.gif
1966      }
1967      TAP {
1968	tabTap $w.props
1969	set gif details.gif
1970      }
1971      RAM {
1972	tabMem $w.props
1973	set gif details.gif
1974      }
1975      ROM {
1976	tabMem $w.props
1977	set gif details.gif
1978      }
1979      MODULE  {
1980	tabModule $w.props
1981	set gif details.gif
1982      }
1983      FRAME {
1984	tabFrame $w.props
1985	set gif details.gif
1986      }
1987      LED {
1988	tabLED $w.props
1989	set gif details.gif
1990      }
1991      AND {
1992	tabCrunchExtGate $w.props
1993	set gif details.gif
1994      }
1995      OR {
1996	tabCrunchExtGate $w.props
1997	set gif details.gif
1998      }
1999      XOR {
2000	tabCrunchExtGate $w.props
2001	set gif details.gif
2002      }
2003      MUX {
2004	tabMux $w.props
2005	set gif details.gif
2006      }
2007      DEMUX {
2008	tabMux $w.props
2009	set gif details.gif
2010      }
2011      DECODER {
2012	tabMux $w.props
2013	set gif details.gif
2014      }
2015      FF {
2016	tabFF $w.props ff
2017	set gif details.gif
2018      }
2019      JKFF {
2020	tabFF $w.props jkff
2021	set gif details.gif
2022      }
2023      CONCAT {
2024	tabConcatPlace $w.props
2025	set gif details.gif
2026      }
2027      COMMENT {
2028	tabCommentText $w.props
2029	set gif details.gif
2030      }
2031      SCRIPT {
2032	tabScriptText $w.props
2033	set gif details.gif
2034      }
2035    }
2036
2037    dialogImage $w.image -image [gifI $gif] -caption $caption -explaination $explaination
2038    pack $w.image -fill both -side left -pady 10
2039  }
2040
2041  #############################################################################
2042  #
2043  # Post the gate parameters dialog box
2044  #
2045  proc post args {
2046    global edgat_type edgat_name edgat_hideName edgat_geom edgat_wops edgat_dtype
2047    global ecpOmega ecpPhi ecpDuty
2048
2049#    puts "EditGate::post type=$edgat_type"
2050
2051    set edgat_wops {}
2052
2053    set start_page General
2054
2055    if { $args != "" } {
2056      set start_page $args
2057    }
2058
2059    set w .edgat
2060    if { [catch { toplevel $w }] } { return }
2061    wm withdraw $w
2062
2063    wm title $w [m db.gate.title]
2064    wm geometry $w $edgat_geom
2065    wm transient $w .
2066
2067    switch $edgat_type {
2068      COMMENT {
2069	set start_page COMMENT
2070	wm geometry $w [mr @db.gate.comment.width]x[mr @db.gate.comment.height]
2071      }
2072      SCRIPT {
2073	set start_page SCRIPT
2074	wm geometry $w [mr @db.gate.comment.width]x[mr @db.gate.comment.height]
2075      }
2076      FRAME {
2077	set start_page FRAME
2078	wm resizable $w 0 0
2079      }
2080      default {
2081	wm resizable $w 0 0
2082      }
2083    }
2084
2085
2086    set tabs { General }
2087    set labels [list [m db.gate.general]]
2088
2089    if { $edgat_type != "FRAME" && $edgat_type != "COMMENT"  && $edgat_type != "SCRIPT" } {
2090      lappend tabs Ports
2091      lappend labels [m db.gate.ports]
2092    }
2093
2094    #
2095    # If this is a gate type that has a details tab, add the tab
2096    #
2097    if {[lsearch {CLOCK SWITCH DIP TAP RAM ROM MODULE FRAME LED AND OR XOR MUX DECODER DEMUX JKFF FF CONCAT} $edgat_type] >= 0 } {
2098      lappend tabs $edgat_type; lappend labels [m db.gate.details]
2099    }
2100
2101    if { $edgat_type == "MODULE" || $edgat_type == "SYMMODULE" } {
2102      lappend tabs Parameters
2103      lappend labels [m db.gate.parameters]
2104    }
2105
2106    #
2107    # Add special tab for comments
2108    #
2109    if { $edgat_type == "COMMENT" } {
2110      lappend tabs COMMENT
2111      lappend labels [m db.gate.text]
2112    }
2113
2114    if { $edgat_type == "SCRIPT" } {
2115      lappend tabs SCRIPT
2116      lappend labels [m db.gate.text]
2117    }
2118
2119    if { $edgat_dtype != "none" } {
2120      lappend tabs Delay
2121      lappend labels [m db.gate.delay]
2122    }
2123
2124    TabBox::new $w.tbox -command EditGate::dotab -tabs $tabs -tablabels $labels -startpage $start_page -takefocus 1
2125    pack $w.tbox -fill both -expand 1
2126
2127    okcancel $w.ok -okcommand EditGate::ok -cancelcommand EditGate::cancel
2128    pack $w.ok -fill both
2129
2130    trace variable ecpOmega w EditGate::clockPUpdate
2131    trace variable ecpPhi w EditGate::clockPUpdate
2132    trace variable ecpDuty w EditGate::clockPUpdate
2133
2134    wm deiconify $w
2135    dialogWait $w
2136
2137    trace vdelete ecpOmega w EditGate::clockPUpdate
2138    trace vdelete ecpPhi w EditGate::clockPUpdate
2139    trace vdelete ecpDuty w EditGate::clockPUpdate
2140  }
2141}
2142