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 Mon Feb 23 19:27:02 2009 18# 19 20# Toolbar y padding 21set tbypad 0 22 23set logo_w "" 24set tbfile_w "" 25set tech_w "" 26set undo_w "" 27set gateop_w "" 28set simtools_w "" 29 30namespace eval ToolBar { 31 variable currentMode 32 variable newMode 33 variable enabledTools 34 variable grabX 3 35 variable grabY 12 36 variable tbMiddle 30 37 variable modeTools 38 variable mbar_w 39 40 # 41 # These variable show the natural position of the tools. One or more 42 # may be hidden and thus not be actually be displayed, but when the tool 43 # is unhidden it will be displayed according to the order shown here. 44 # 45 variable topTools {File Undo Edit SymEdit GateOp Zoom SymZoom BlockOp} 46 variable bottomTools {Modes SimModes SymModes SymPort SymShift SymOpr LimModes SimControl SimAux GateProp Tech} 47 variable windowTools {} 48 49 array set modeTools { 50 None {} 51 All {File Undo Edit GateOp Zoom SymZoom Modes SymModes SimModes SymEdit SymPort SymShift SymOpr \ 52 LimModes BlockOp GateProp Tech SimControl SimAux} 53 Edit {File Undo Edit GateOp Zoom Modes BlockOp GateProp Tech} 54 HdlEdit {File Undo Edit BlockOp} 55 EditInterfaces {File Undo Edit Zoom LimModes BlockOp} 56 Simulate {File Zoom SimModes SimControl SimAux} 57 EditInterfaces.sym {File Undo SymEdit SymZoom SymModes SymPort SymShift SymOpr BlockOp} 58 } 59 60 61 # 62 # This shows the actual state of a tool. It is either the window the tool is in, 63 # or "hidden" if the tool is not visible. 64 # 65 variable toolState 66 variable toolWindow 67 variable toolPos 68 69 proc tbGrabber {w tool argv} { 70 frame $w 71 72 set dobind 1 73 parseargs $argv {-dobind} 74 75 frame $w.p1 -width 3 76 frame $w.v1 -bd 1 -relief raised -width 2 -height 13 77 frame $w.v2 -bd 1 -relief raised -width 2 -height 13 78 frame $w.p2 -width 5 79 80 pack $w.p1 -side left 81 pack $w.v1 -side left -padx 0 82 pack $w.v2 -side left -padx 0 83 pack $w.p2 -side left 84 85 if { $dobind } { 86 foreach W [list $w $w.p1 $w.v1 $w.v2 $w.p2] { 87 bind $W <B1-Motion> "ToolBar::setGrab $tool" 88 } 89 } 90 } 91 92 proc resetTechList {} { 93 global gatesetech_w tech_w 94 95 set L [gat_getTechList] 96 97 Dropbox::flush $tech_w 98 Dropbox::itemadd $tech_w $L 99 100 # 101 # Build menus for plain entry technology lists 102 # 103 set menu_list [list $gatesetech_w] 104 foreach m $menu_list { 105 catch { 106 destroy $m 107 menu $m -tearoff 0 108 foreach mi $L { 109 $m add command -label $mi -command "gat_setTech $mi" 110 } 111 } 112 } 113 114 # 115 # Build menus for radio button technology lists 116 # 117 set menu_list [list .pop_MIgate.settech .pop_gate.settech .pop_multi.settech] 118 foreach m $menu_list { 119 catch { 120 destroy $m 121 menu $m -tearoff 0 122 foreach mi $L { 123 $m add radiobutton -variable pop_tech -value $mi -label $mi -command "gat_setTech $mi" 124 } 125 } 126 } 127 } 128 129 proc tbSymModes {w args} { 130 global bd tbr tbypad 131 132 frame $w 133 tbGrabber $w.grab SymModes $args 134 pack $w.grab -side left -fill both 135 136 foreach e {point line rect fillrect port select} { 137 flatradiobutton $w.$e -image [gifI "symed_${e}.gif"] -variable SymbolEdit::emode -value $e 138 pack $w.$e -side left -pady $tbypad 139 helpon $w.$e [m ho.symed.$e] 140 } 141 142 143 frame $w.vbar -bd 1 -relief sunken -width 2 144 pack $w.vbar -side left -padx 1 -pady 2 -fill y 145 } 146 147 proc tbSymEdit {w args} { 148 global bd tbr tbypad 149 150 frame $w 151 tbGrabber $w.grab SymEdit $args 152 pack $w.grab -side left -fill both 153 154 toolbutton $w.cut "edit_cut.gif" SymbolEdit::cutRegion "" 155 toolbutton $w.copy "edit_copy.gif" SymbolEdit::copyRegion "" 156 toolbutton $w.paste "edit_paste.gif" SymbolEdit::pasteRegion "" 157 toolbutton $w.overlay "edit_overlay.gif" SymbolEdit::overlayRegion "" 158 159 pack $w.cut $w.copy $w.paste $w.overlay -side left -pady $tbypad 160 161 frame $w.vbar -bd 1 -relief sunken -width 2 162 pack $w.vbar -side left -padx 1 -pady 2 -fill y 163 } 164 165 proc tbSymPort {w args} { 166 global bd tbr tbypad 167 168 frame $w 169 tbGrabber $w.grab SymPort $args 170 pack $w.grab -side left -fill both 171 172 toolbutton $w.clk "symed_pcrot.gif" Action::seCWRotPort "" 173 toolbutton $w.cntr "symed_pccrot.gif" Action::seCCWRotPort "" 174 pack $w.clk $w.cntr -side left -pady $tbypad 175 176 frame $w.vbar -bd 1 -relief sunken -width 2 177 pack $w.vbar -side left -padx 1 -pady 2 -fill y 178 } 179 180 proc tbSymShift {w args} { 181 global bd tbr tbypad 182 183 frame $w 184 tbGrabber $w.grab SymShift $args 185 pack $w.grab -side left -fill both 186 187 toolbutton $w.rshift "arrow0.gif" { SymbolEdit::shiftBits 1 0 } ho.symed.rshift 188 toolbutton $w.lshift "arrow180.gif" { SymbolEdit::shiftBits -1 0 } ho.symed.lshift 189 toolbutton $w.ushift "arrow90.gif" { SymbolEdit::shiftBits 0 -1 } ho.symed.ushift 190 toolbutton $w.dshift "arrow270.gif" { SymbolEdit::shiftBits 0 1 } ho.symed.dshift 191 toolbutton $w.cwrotate "symed_cwrotate.gif" { SymbolEdit::rotateBits 1 } ho.symed.cwrotate 192 toolbutton $w.ccwrotate "symed_ccwrotate.gif" { SymbolEdit::rotateBits -1 } ho.symed.ccwrotate 193 194 pack $w.rshift $w.lshift $w.ushift $w.dshift $w.cwrotate $w.ccwrotate -side left -pady $tbypad 195 196 frame $w.vbar -bd 1 -relief sunken -width 2 197 pack $w.vbar -side left -padx 1 -pady 2 -fill y 198 } 199 200 proc tbSymOpr {w args} { 201 global bd tbr tbypad 202 203 frame $w 204 tbGrabber $w.grab SymOpr $args 205 pack $w.grab -side left -fill both 206 207 toolbutton $w.import "symed_import.gif" { Action::importImage } ho.symed.import 208 toolbutton $w.export "symed_export.gif" { Action::exportImage } ho.symed.export 209 toolbutton $w.autobold "symed_autobold.gif" { SymbolEdit::boldBits } ho.symed.autobold 210# toolbutton $w.resize "symed_resize.gif" {} ho.symed.resize 211 212 pack $w.import $w.export $w.autobold -side left -pady $tbypad 213 214 frame $w.vbar -bd 1 -relief sunken -width 2 215 pack $w.vbar -side left -padx 1 -pady 2 -fill y 216 } 217 218 proc tbSymZoom {w args} { 219 global bd tbr tbypad 220 221 frame $w 222 tbGrabber $w.grab SymEdit $args 223 pack $w.grab -side left -fill both 224 225 toolbutton $w.in "zoom_in.gif" { SymbolEdit::zoom 1 } "" 226 toolbutton $w.out "zoom_out.gif" { SymbolEdit::zoom -1 } "" 227 pack $w.in $w.out -side left -pady $tbypad 228 229 frame $w.vbar -bd 1 -relief sunken -width 2 230 pack $w.vbar -side left -padx 1 -pady 2 -fill y 231 } 232 233 proc tbFile {w args} { 234 global bd tbr tbypad tbfile_w 235 236 set tbfile_w $w 237 frame $w 238 tbGrabber $w.grab File $args 239 pack $w.grab -side left -fill both 240 241 toolbutton $w.new "file_new.gif" {clearAction File::new} ho.new 242 toolbutton $w.open "file_open.gif" {clearAction File::load} ho.open 243 toolbutton $w.lib "file_lib.gif" Action::loadLibrary ho.library 244 toolbutton $w.save "file_save.gif" Action::saveFile ho.save 245 toolbutton $w.saveas "file_saveas.gif" Action::saveAsFile ho.saveas 246 toolbutton $w.print "file_print.gif" {suspendAction PrintDlg::post} ho.print 247 frame $w.vbar -bd 1 -relief sunken -width 2 248 249 pack $w.new $w.open $w.lib $w.save $w.saveas $w.print -side left -pady $tbypad 250 pack $w.vbar -side left -padx 1 -pady 2 -fill y 251 } 252 253 proc tbEdit {w args} { 254 global bd tbr tbypad 255 256 frame $w 257 tbGrabber $w.grab Edit $args 258 pack $w.grab -side left -fill y 259 260 toolbutton $w.cut "edit_cut.gif" Action::cutToBuf ho.tool.cut 261 toolbutton $w.copy "edit_copy.gif" Action::copyToBuf ho.tool.copy 262 toolbutton $w.paste "edit_paste.gif" Action::yankFromBuf ho.tool.paste 263 toolbutton $w.find "edit_find.gif" Action::findObject ho.tool.find 264 265 frame $w.vbar -bd 1 -relief sunken -width 2 266 267 pack $w.cut $w.copy $w.paste $w.find -side left -pady $tbypad 268 pack $w.vbar -side left -padx 1 -pady 2 -fill y 269 } 270 271 proc tbGateOp {w args} { 272 global bd tbr tbypad gateop_w 273 274 275 set gateop_w $w 276 frame $w 277 tbGrabber $w.grab GateOp $args 278 pack $w.grab -side left -fill y 279 280 toolbutton $w.curRot "rotation0.gif" ToolBar::advanceRotation ho.tool.currot 281 updateRotation 282 283 toolbutton $w.valgn "edit_valgn.gif" Action::vAlign ho.tool.valgn 284 toolbutton $w.halgn "edit_halgn.gif" Action::hAlign ho.tool.halgn 285 toolbutton $w.rotate "edit_rotate.gif" Action::rotate ho.tool.rotate 286 toolbutton $w.brotate "edit_brotate.gif" Action::backRotate ho.tool.brotate 287 288 frame $w.vbar -bd 1 -relief sunken -width 2 289 290 pack $w.curRot $w.rotate $w.brotate $w.valgn $w.halgn -side left -pady $tbypad 291 pack $w.vbar -side left -padx 1 -pady 2 -fill y 292 } 293 294 proc tbGateProp {w args} { 295 global bd tbr tbypad gateprop_w 296 297 set gateprop_w $w 298 frame $w 299 tbGrabber $w.grab GateProp $args 300 pack $w.grab -side left -fill y 301 302 toolbutton $w.addport "addport.gif" Action::addPort ho.tool.addport 303 toolbutton $w.anchor "anchor.gif" Action::anchor ho.tool.anchor 304 toolbutton $w.unanchor "unanchor.gif" Action::unAnchor ho.tool.unanchor 305 flatradiobutton $w.replicate -image [gifI "replicate.gif"] -variable tkg_replicateOn -value 1 -command Action::replicate 306 toolbutton $w.delete "delgate.gif" Action::delete ho.tool.delete 307 308 pack $w.addport $w.anchor $w.unanchor $w.replicate $w.delete -anchor w -side left 309 310 frame $w.vbar -bd 1 -relief sunken -width 2 311 pack $w.vbar -side left -padx 1 -pady 2 -fill y 312 313 helpon $w.replicate [m ho.tool.replicate] 314 } 315 316 317 proc updateRotation args { 318 global gateop_w rot 319 320 catch { 321 switch $rot { 322 0 { $gateop_w.curRot configure -image [gifI rotation0.gif] } 323 1 { $gateop_w.curRot configure -image [gifI rotation90.gif] } 324 2 { $gateop_w.curRot configure -image [gifI rotation180.gif] } 325 3 { $gateop_w.curRot configure -image [gifI rotation270.gif] } 326 } 327 } 328 } 329 330 proc advanceRotation args { 331 global gateop_w rot 332 switch $rot { 333 0 { Action::rot90 } 334 1 { Action::rot180 } 335 2 { Action::rot270 } 336 3 { Action::rot0 } 337 } 338 } 339 340 proc tbSimModes {w args} { 341 global bd tbr tbypad 342 global tkg_defaultWType tkg_wtypeList 343 344 frame $w 345 tbGrabber $w.grab Modes $args 346 pack $w.grab -side left -fill y 347 348 # 349 # Flat relief icon radio button are not supported until tck/tk 8.4, so use our own 350 # 351 flatradiobutton $w.mov -image [gifI "mov_curs.gif"] -variable mode -value 1 -command Action::editMode 352 flatradiobutton $w.scroll -image [gifI "scroll_curs.gif"] -variable mode -value 3 -command Action::scrollMode 353 354 pack $w.mov $w.scroll -side left -pady $tbypad 355 356 frame $w.vbar -bd 1 -relief sunken -width 2 357 pack $w.vbar -side left -padx 1 -pady 2 -fill y 358 359 helpon $w.mov [m ho.simmove] 360 helpon $w.scroll [m ho.scroll] 361 } 362 363 proc tbModes {w args} { 364 global bd tbr tbypad 365 global tkg_defaultWType tkg_wtypeList 366 367 frame $w 368 tbGrabber $w.grab Modes $args 369 pack $w.grab -side left -fill y 370 371 # 372 # Flat relief icon radio button are not supported until tck/tk 8.4, so use our own 373 # 374 flatradiobutton $w.mov -image [gifI "mov_curs.gif"] -variable mode -value 1 -command Action::editMode 375 flatradiobutton $w.cut -image [gifI "cut_curs.gif"] -variable mode -value 0 -command Action::cutMode 376 flatradiobutton $w.inv -image [gifI "inv_curs.gif"] -variable mode -value 2 -command Action::invertMode 377 flatradiobutton $w.scroll -image [gifI "scroll_curs.gif"] -variable mode -value 3 -command Action::scrollMode 378 flatradiobutton $w.siz -image [gifI "size_curs.gif"] -variable mode -value 9 -command Action::sizeMode 379 380# pack $w.mov $w.del $w.cut $w.inv $w.siz -side left -pady $tbypad -ipadx 2 -ipady 2 381 pack $w.mov $w.cut $w.inv $w.scroll $w.siz -side left -pady $tbypad 382 383 label $w.nbitsl -text "[m ibits] " 384 bitsizeselector $w.nbitsv -variable tkg_bitWidth -width 3 -takefocus 0 385 pack $w.nbitsl $w.nbitsv -side left -pady $tbypad 386 387 label $w.typel -text "[m itype] " 388 Dropbox::new $w.typev -variable tkg_defaultWType -value $tkg_defaultWType -width 7 -takefocus 0 389 pack $w.typel $w.typev -side left -pady $tbypad 390 Dropbox::itemadd $w.typev $tkg_wtypeList 391 392 393 frame $w.pad 394 pack $w.pad -side left -padx 2 -pady 2 395 396 frame $w.vbar -bd 1 -relief sunken -width 2 397 pack $w.vbar -side left -padx 1 -pady 2 -fill y 398 399 helpon $w.mov [m ho.move] 400# helpon $w.del [m ho.delgat] 401 helpon $w.cut [m ho.cutw] 402 helpon $w.inv [m ho.inv] 403 helpon $w.siz [m ho.bitw] 404 helpon $w.scroll [m ho.scroll] 405 406 helpon $w.nbitsl [m ho.cmd.bitw] 407 helpon $w.nbitsv [m ho.cmd.bitw] 408 } 409 410 proc tbLimModes {w args} { 411 global bd tbr tbypad 412 413 frame $w 414 tbGrabber $w.grab Modes $args 415 pack $w.grab -side left -fill y 416 417 # 418 # Flat relief icon radio button are not supported until tck/tk 8.4, so use our own 419 # 420 flatradiobutton $w.mov -image [gifI "mov_curs.gif"] -variable mode -value 1 -command Action::editMode 421 flatradiobutton $w.cut -image [gifI "cut_curs.gif"] -variable mode -value 0 -command Action::cutMode 422 flatradiobutton $w.siz -image [gifI "size_curs.gif"] -variable mode -value 9 -command Action::sizeMode 423 424 pack $w.mov $w.cut $w.siz -side left -pady $tbypad 425 426 label $w.nbitsl -text "[m ibits] " 427 bitsizeselector $w.nbitsv -variable tkg_bitWidth -width 3 -takefocus 0 428 pack $w.nbitsl $w.nbitsv -side left -pady $tbypad 429 430 frame $w.pad 431 pack $w.pad -side left -padx 2 -pady 2 432 433 frame $w.vbar -bd 1 -relief sunken -width 2 434 pack $w.vbar -side left -padx 1 -pady 2 -fill y 435 436 helpon $w.mov [m ho.move] 437 helpon $w.cut [m ho.cutw] 438 helpon $w.siz [m ho.bitw] 439 440 helpon $w.nbitsl [m ho.cmd.bitw] 441 helpon $w.nbitsv [m ho.cmd.bitw] 442 } 443 444 proc tbUndo {w args} { 445 global bd tbr tbypad tbfile_w undo_w 446 447 set undo_w $w 448 frame $w 449 tbGrabber $w.grab Undo $args 450 pack $w.grab -side left -fill y 451 452 label $w.back -image [gifI "back.gif"] -bd 1 -relief flat -takefocus 0 453 label $w.forward -image [gifI "forward.gif"] -bd 1 -relief flat -takefocus 0 454# button $w.back -image [gifI "back.gif"] -bd 1 -relief flat -takefocus 0 455# button $w.forward -image [gifI "forward.gif"] -bd 1 -relief flat -takefocus 0 456 457 pack $w.back $w.forward -side left -pady $tbypad -ipadx 1 -ipady 1 458 459 frame $w.vbar -bd 1 -relief sunken -width 2 460 pack $w.vbar -side left -padx 1 -pady 2 -fill y 461 462 bind $w.back <Button-1> { %W configure -relief sunken ;Undo::undoSelect; %W configure -relief flat } 463 bind $w.forward <Button-1> { %W configure -relief sunken ;Undo::redoSelect; %W configure -relief flat } 464 465 bind $w.back <Enter> "%W configure -relief raised" 466 bind $w.back <Leave> "%W configure -relief flat" 467 bind $w.forward <Enter> "%W configure -relief raised" 468 bind $w.forward <Leave> "%W configure -relief flat" 469 470 helpon $w.back [m ho.undo] 471 helpon $w.forward [m ho.redo] 472 473 set activebackground [option get . activeBackground UndoRedo] 474 set normalbackground [$w.back cget -bg] 475 476 bind $w.back <Enter> "+ %W configure -bg $activebackground" 477 bind $w.back <Leave> "+ %W configure -bg $normalbackground" 478 bind $w.forward <Enter> "+ %W configure -bg $activebackground" 479 bind $w.forward <Leave> "+ %W configure -bg $normalbackground" 480 } 481 482 proc tbBlockOp {w args} { 483 global bd tbr tbypad 484 485 frame $w 486 tbGrabber $w.grab BlockOp $args 487 pack $w.grab -side left -fill y 488 489 toolbutton $w.new "blk_new.gif" Action::blockNew ho.mod.new 490 toolbutton $w.del "blk_delete.gif" Action::blockDelete ho.mod.del 491 toolbutton $w.copy "blk_copy.gif" Action::blockCopy ho.mod.copy 492 toolbutton $w.rename "blk_rename.gif" Action::blockRename ho.mod.rename 493 toolbutton $w.claim "blk_claim.gif" Action::blockClaim ho.mod.claim 494# toolbutton $w.root "blk_root.gif" Action::blockSetRoot ho.mod.setroot 495 toolbutton $w.open "blk_open.gif" Action::openMod ho.mod.open 496 toolbutton $w.close "blk_close.gif" Action::closeMod ho.mod.close 497 498 pack $w.new $w.del $w.copy $w.rename $w.claim $w.open $w.close -side left -pady $tbypad 499 500 frame $w.vbar -bd 1 -relief sunken -width 2 501 pack $w.vbar -side left -padx 1 -pady 2 -fill y 502 } 503 504 proc tbZoom {w args} { 505 global bd tbr tbypad 506 507 frame $w 508 tbGrabber $w.grab Zoom $args 509 pack $w.grab -side left -fill y 510 511 toolbutton $w.zoomin "zoom_in.gif" { action ZoomIn { gat_zoom 1 } } ho.tool.zoomin 512 toolbutton $w.zoomout "zoom_out.gif" { action ZoomOut { gat_zoom -1 } } ho.tool.zoomout -state disabled 513 pack $w.zoomin $w.zoomout -side left -pady $tbypad 514 515 516 frame $w.vbar -bd 1 -relief sunken -width 2 517 pack $w.vbar -side left -padx 1 -pady 2 -fill y 518 } 519 520 proc tbSimControl {w args} { 521 global bd tbr tbypad simtools_w 522 523 set simtools_w $w 524 525 frame $w 526 tbGrabber $w.grab SimControl $args 527 pack $w.grab -side left -fill y 528 529 toolbutton $w.simgo "sim_go.gif" tkg_simRun ho.simgo 530 toolbutton $w.simpause "sim_pause.gif" tkg_simStop ho.simpause 531 toolbutton $w.simstep "sim_step.gif" Simulator::stepEpoch ho.simstep 532 toolbutton $w.simclock "sim_clock.gif" tkg_simCycle ho.simclock 533 toolbutton $w.simstop "sim_stop.gif" { gat_setMajorMode edit } ho.simstop 534 535 pack $w.simgo $w.simpause $w.simstep $w.simclock $w.simstop -side left -pady $tbypad 536 537 frame $w.vbar -bd 1 -relief sunken -width 2 538 pack $w.vbar -side left -padx 1 -pady 2 -fill y 539 } 540 541 proc tbSimAux {w args} { 542 global bd tbr tbypad 543 544 frame $w 545 tbGrabber $w.grab SimAux $args 546 pack $w.grab -side left -fill y 547 548 toolbutton $w.simbreak "sim_break.gif" Action::editBreakpoints ho.simbreak 549 toolbutton $w.simscript "sim_script.gif" Action::doSimScript ho.simexec 550 toolbutton $w.simload "sim_load.gif" Action::simLoadMem ho.simload 551 toolbutton $w.simdump "sim_dump.gif" Action::simDumpMem ho.simdump 552 toolbutton $w.simview "sim_view.gif" Action::simViewMem ho.simview 553 554 pack $w.simbreak $w.simscript $w.simload $w.simdump $w.simview -side left -pady $tbypad 555# pack $w.simload $w.simdump -side left -pady $tbypad 556 557 frame $w.vbar -bd 1 -relief sunken -width 2 558 pack $w.vbar -side left -padx 1 -pady 2 -fill y 559 } 560 561 proc tbLogo {w} { 562 global bd tbr tbypad logo_w 563 564 set logo_w $w 565 label $logo_w -image [gifI "gatelogo.gif"] 566 helpon $logo_w [m ho.status.logo] 567 568 } 569 570 proc tbTech {w args} { 571 global tkg_defaultTech tech_w tbr bd 572 573 set tech_w $w.v 574 frame $w 575 tbGrabber $w.grab Tech $args 576 pack $w.grab -side left -fill y 577 578 label $w.l -text "[m b.tech]:" 579 Dropbox::new $w.v -variable tkg_defaultTech -value $tkg_defaultTech -width 14 -takefocus 0 580 Dropbox::itemadd $w.v [gat_getTechList] 581 582 pack $w.l $w.v -anchor w -side left 583 584 frame $w.vbar -bd 1 -relief sunken -width 2 585 pack $w.vbar -side left -padx 1 -pady 2 -fill y 586 587 helpon $w.l [m ho.deftech] 588 } 589 590 ############################################################################# 591 # 592 # Methods from here are used for controlling toobars 593 # 594 ############################################################################# 595 596 proc clearLocation {t} { 597 variable windowTools 598 variable topTools 599 variable bottomTools 600 601 set i [lsearch $topTools $t] 602 if {$i >= 0 } { set topTools [lreplace $topTools $i $i] } 603 set i [lsearch $bottomTools $t] 604 if {$i >= 0 } { set bottomTools [lreplace $bottomTools $i $i] } 605 set i [lsearch $windowTools $t] 606 if {$i >= 0 } { set windowTools [lreplace $windowTools $i $i] } 607 } 608 609 proc seeToolDrop {t w x y} { 610 variable toolWindow 611 variable windowTools 612 variable topTools 613 variable bottomTools 614 variable toolPos 615 variable grabX 616 variable grabY 617 variable tbMiddle 618 variable toolState 619 620 # 621 # If we drop the tool on the toolbar, then go figure out where to insert it, 622 # otherwise make a new window for it. 623 # 624 if { [string range $w 0 4] == ".tbar" } { 625 # 626 # If the drop is on .tbar itself, use the y position to decide top or bottom 627 # and add it to the end. Otherwise figure out which window we dropped on 628 # and where to insert it. 629 # 630 scan $w ".tbar.%\[^.\]" where 631 set tbroot_x [winfo rootx .tbar.top] 632 set tbroot_y [winfo rooty .tbar.top] 633 634 if { [expr $y - $tbroot_y] > $tbMiddle } { 635 set i 0 636 foreach q $bottomTools { 637 if {!$toolState($q) } { 638 incr i 639 continue 640 } 641 set mw .tbar.bottom.w$q 642 set mx [winfo rootx $mw] 643 set mwidth [winfo width $mw] 644 if { $x < [expr $mx + $mwidth/2] } { 645 break 646 } 647 incr i 648 } 649 set bottomTools [linsert $bottomTools $i $t] 650 } else { 651 set i 0 652 foreach q $topTools { 653 if {!$toolState($q) } { 654 incr i 655 continue 656 } 657 set mw .tbar.top.w$q 658 set mx [winfo rootx $mw] 659 set mwidth [winfo width $mw] 660 if { $x < [expr $mx + $mwidth/2] } { 661 break 662 } 663 incr i 664 } 665 set topTools [linsert $topTools $i $t] 666 } 667 show $t 668 } else { 669 clearLocation $t 670 lappend windowTools $t 671 set toolPos($t) +[expr $x - $grabX]+[expr $y - $grabY] 672 show $t 673 } 674 } 675 676 proc setGrab {t} { 677 variable toolWindow 678 variable toolState 679 variable topTools 680 variable bottomTools 681 variable windowTools 682 variable grabX 683 variable grabY 684 685 clearLocation $t 686 687 set dw [Dragger::make -command "ToolBar::seeToolDrop $t" -absolute 1 -grabpoint [list $grabX $grabY] ] 688 if { $dw != "" } { 689 makeW $t $dw.w$t -dobind 0 690 pack $dw.w$t 691 set toolWindow($t) "" 692 set toolState($t) 0 693 } 694 } 695 696 proc hideEdit {} { 697 pack forget .tbar.bottom.modes 698 pack forget .tbar.bottom.tech 699 pack forget .tbar.top.edit 700 pack forget .tbar.top.undo 701 } 702 703 proc showEdit {} { 704 pack .tbar.bottom.modes -side left -before .tbar.bottom.blockop 705 pack .tbar.bottom.tech -side left -after .tbar.bottom.blockop 706 pack .tbar.top.undo -side left -after .tbar.top.file 707 pack .tbar.top.edit -side left -after .tbar.top.file 708 } 709 710 proc showSim {} { 711 pack .tbar.bottom.simctl -side left 712 pack .tbar.bottom.simaux -side left 713 } 714 715 proc hideSim {} { 716 pack forget .tbar.bottom.simctl .tbar.bottom.simaux 717 } 718 719 720 # 721 # make tool t be in window w 722 # 723 proc makeW {t w args} { 724 variable toolWindow 725 726 if { $t != $toolWindow($t) } { 727 if { $toolWindow($t) != "" } { 728 if { [string range $toolWindow($t) 0 4] == ".tbar" } { 729 destroy $toolWindow($t) 730 } else { 731 destroy .tb$t 732 } 733 } 734 if { $w != "" } { 735 eval "tb$t $w $args" 736 } 737 set toolWindow($t) $w 738 } 739 } 740 741 # 742 # swallow toolbar t 743 # 744 proc show {t} { 745 variable topTools 746 variable bottomTools 747 variable windowTools 748 variable toolWindow 749 variable toolState 750 variable toolPos 751 752 # 753 # If tool is already visible, don't do anything 754 # 755 if { $toolState($t) == 1 } { 756 return 757 } 758 759 set after_w .tbar.top.pad 760 foreach q $topTools { 761 if {$t == $q } { 762 set w .tbar.top.w$t 763 makeW $t $w 764 pack $w -after $after_w -side left 765 set toolState($t) 1 766 return 767 } 768 if { $toolState($q) == 1 } { 769 set after_w .tbar.top.w$q 770 } 771 } 772 773 set after_w .tbar.bottom.pad 774 foreach q $bottomTools { 775 if {$t == $q } { 776 set w .tbar.bottom.w$t 777 makeW $t $w 778 pack $w -after $after_w -side left 779 set toolState($t) 1 780 return 781 } 782 if { $toolState($q) == 1 } { 783 set after_w .tbar.bottom.w$q 784 } 785 } 786 787 foreach q $windowTools { 788 if {$t == $q } { 789 set tw .tb$t 790 toplevel $tw -cursor arrow -bd 2 -relief solid 791 wm resizable $tw 0 0 792 wm transient $tw . 793 wm overrideredirect $tw 1 794 wm geometry $tw $toolPos($t) 795 796 797 set w $tw.w$t 798 makeW $t $w 799 800 pack $w -padx 1 -pady 1 801 set toolState($t) 1 802 return 803 } 804 } 805 } 806 807 # 808 # remove a toolbar 809 # 810 proc hide {t} { 811 variable toolWindow 812 variable toolState 813 # 814 # If tool is already hidden, don't do anything 815 # 816 if { $toolState($t) == 0 } { 817 return 818 } 819 820 set w $toolWindow($t) 821 if { [string range $w 0 4] == ".tbar" } { 822 pack forget $w 823 } else { 824 set rootw [winfo parent $w] 825 destroy $rootw 826 set toolWindow($t) "" 827 } 828 set toolState($t) 0 829 } 830 831 proc toolConfigure {t subw args} { 832 variable toolWindow 833 834 if { $toolWindow($t) == "" } { 835 return 836 } 837 catch { 838 eval "$toolWindow($t).$subw configure $args" 839 } 840 } 841 842 ############################################################################# 843 # 844 # Set the current toolbar mode. Tools relevent to the mode will be displayed 845 # and irrelevent tools will be hidden. 846 # 847 proc setMode {m} { 848 variable modeTools 849 variable newMode 850 variable currentMode 851 variable enabledTools 852 853 if { $m == "EditInterfaces" && [info exists IPanel::data(itype)] && $IPanel::data(itype) == "symbol" } { 854 set m EditInterfaces.sym 855 } 856 857 # 858 # Hide tool groups that are in the current set but not in the new set 859 # 860 foreach item $modeTools($currentMode) { 861 if {[lsearch $modeTools($m) $item] < 0 } { 862 hide $item 863 } 864 } 865 866 # 867 # Show tool groups that are in the new set but not in the current set 868 # 869 set newMode $m 870 foreach item $ToolBar::modeTools($ToolBar::newMode) { 871 if {[lsearch $ToolBar::modeTools($ToolBar::currentMode) $item] < 0 \ 872 && [lsearch $ToolBar::enabledTools $item] >= 0 } { 873 ToolBar::show $item 874 } 875 } 876 877 set currentMode $m 878 } 879 880 ############################################################################# 881 # 882 # Update the list of enabled tools 883 # 884 proc updateEnabled {} { 885 variable modeTools 886 variable currentMode 887 variable enabledTools 888 global tkg_filetb tkg_edittb tkg_gateoptb tkg_undotb tkg_zoomtb tkg_modetb 889 global tkg_moduletb tkg_techtb tkg_simctltb tkg_simauxtb tkg_gateprop 890 global tkg_symmodestb tkg_simmodestb tkg_symedittb tkg_zoomtb tkg_symporttb tkg_symshifttb tkg_symoprtb 891 892 893 set newSet {} 894 if {$tkg_filetb} { lappend newSet File } 895 if {$tkg_edittb} { lappend newSet Edit } 896 if {$tkg_gateoptb} { lappend newSet GateOp } 897 if {$tkg_gateprop} { lappend newSet GateProp } 898 if {$tkg_undotb} { lappend newSet Undo } 899 if {$tkg_zoomtb} { lappend newSet Zoom } 900 if {$tkg_modetb} { lappend newSet Modes LimModes } 901 if {$tkg_moduletb} { lappend newSet BlockOp } 902 if {$tkg_techtb} { lappend newSet Tech } 903 if {$tkg_simctltb} { lappend newSet SimControl } 904 if {$tkg_simauxtb} { lappend newSet SimAux } 905 906 if {$tkg_symmodestb} { lappend newSet SymModes } 907 if {$tkg_simmodestb} { lappend newSet SimModes } 908 if {$tkg_symedittb} { lappend newSet SymEdit } 909 if {$tkg_zoomtb} { lappend newSet SymZoom } 910 if {$tkg_symporttb} { lappend newSet SymPort } 911 if {$tkg_symshifttb} { lappend newSet SymShift } 912 if {$tkg_symoprtb} { lappend newSet SymOpr } 913 914 if { $enabledTools != $newSet } { 915 foreach item $modeTools($currentMode) { 916 if {[lsearch $newSet $item] < 0 && [lsearch $enabledTools $item] >= 0} { 917 hide $item 918 } 919 if {[lsearch $newSet $item] >= 0 && [lsearch $enabledTools $item] < 0} { 920 show $item 921 } 922 } 923 924 set enabledTools $newSet 925 } 926 } 927 928 proc init {} { 929 variable topTools 930 variable bottomTools 931 variable toolWindow 932 variable toolState 933 variable modeTools 934 variable currentMode 935 variable enabledTools 936 variable mbar_w 937 global logo_w rot 938 global gatesetech_w 939 940 set currentMode None 941 942 set enabledTools $modeTools(All) 943 updateEnabled 944 945 foreach t $modeTools(All) { 946 set toolWindow($t) "" 947 set toolState($t) 0 948 } 949 950 951 tbLogo .tbar.logo 952 pack $logo_w -side right -ipadx 2 -ipady 2 -padx 5 -pady 5 -anchor n 953 954 955 # 956 # Menu setup 957 # 958 Menu::makeBar .tbar.m editor 959 set mbar_w .tbar.m 960 set gatesetech_w $mbar_w.format.menu.settech 961 KeyBinding::listener .tbar.m main -unmatchedcommand dobell 962 focus $mbar_w 963 964 frame .tbar.bar1 -bd 1 -relief sunken -height 2 965 frame .tbar.top 966 frame .tbar.bar2 -bd 1 -relief sunken -height 2 967 frame .tbar.bottom 968 969 pack .tbar.m -fill x 970 pack .tbar.bar1 -fill x -padx 3 -pady 1 971 pack .tbar.top -fill y -anchor w 972 pack .tbar.bar2 -fill x -padx 3 -pady 1 973 pack .tbar.bottom -fill y -anchor w 974 frame .tbar.top.pad -height 25 975 frame .tbar.bottom.pad -height 25 976 pack .tbar.top.pad -padx 3 -side left 977 pack .tbar.bottom.pad -padx 3 -side left 978 979 trace variable rot w ToolBar::updateRotation 980 } 981 982 ############################################################################# 983 # 984 # 985 # 986 proc takeFocus {} { 987 variable mbar_w 988 989 focus $mbar_w 990 } 991 992 ############################################################################# 993 # 994 # Set the editing tool (mode) to use. 995 # 996 proc selectTool {tool} { 997 global mode simOn 998 999 if { ! $simOn || $tool == 1 || $tool == 3} { 1000 set mode $tool 1001 gat_mode $tool 1002 } 1003 } 1004 1005 ############################################################################# 1006 # 1007 # Respond to a change in the mode. 1008 # 1009 proc modeChanged args { 1010 global mode tkg_batMode tkg_batRate tkg_bitWidth old_mode 1011 1012 if { $mode == 1 && $tkg_batMode } { 1013 after $tkg_batRate gat_batInc 1014 } 1015 1016 set old_mode $mode 1017 } 1018 1019 proc simStateChange args { 1020 global simulatorState simtools_w 1021 1022 set baseBg [$simtools_w cget -bg] 1023 1024 if { $simulatorState == "stop" } { 1025 $simtools_w.simgo configure -relief flat -bg $baseBg 1026 $simtools_w.simpause configure -relief sunken -bg "\#aaaacc" 1027 } else { 1028 $simtools_w.simgo configure -relief sunken -bg "\#aaaacc" 1029 $simtools_w.simpause configure -relief flat -bg $baseBg 1030 } 1031 } 1032} 1033 1034trace variable mode w ToolBar::modeChanged 1035trace variable ::simulatorState w ToolBar::simStateChange 1036 1037 1038 1039