File: twoD.tk

package info (click to toggle)
dstooltk 2.0-3
  • links: PTS
  • area: main
  • in suites: potato, slink
  • size: 2,500 kB
  • ctags: 3,169
  • sloc: ansic: 27,185; tcl: 4,770; makefile: 587; sh: 70; csh: 7
file content (730 lines) | stat: -rw-r--r-- 19,278 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
#
# twoD.tk
#

proc twoD(build) {n wname} {
    global Model Defaults Snap rbox highlight Browser COLOR

    build_Title $wname "2-D View \#$n"
    wm minsize $wname 100 160
    upvar #0 twoD$n nm
  
    if {![info exists nm(hor)]} {
	set nm(hor) {Varb 0}
	set nm(ver) {Varb 1}
    }

    # force default settings when window rebuilds
    set nm(hor) {Varb 0}
    set nm(ver) {Varb 1}

    set nm(horindex) [eval [concat type_to_index $nm(hor) Varb Param Funct] ]
    set nm(verindex) [eval [concat type_to_index $nm(ver) Varb Param Funct] ]

    set ht [lindex $nm(hor) 0]
    set hn [lindex $nm(hor) 1]
    set vt [lindex $nm(ver) 0]
    set vn [lindex $nm(ver) 1]
    set nm(hormin) $Defaults($ht\_Min,$hn)
    set nm(hormax) $Defaults($ht\_Max,$hn)
    set nm(vermin) $Defaults($vt\_Min,$vn)
    set nm(vermax) $Defaults($vt\_Max,$vn)
    set nm(pick) 0

    set nm(hormouse) ""
    set nm(vermouse) ""

    set cmd [build_CmdFrame $wname cmd]
    set cmdl [build_StdFrame $cmd l]
    set cmdr [build_StdFrame $cmd r]

    #build_DismissButtonbar $wname dbbar "window(dismiss) twoD$n" \
	[list "Refresh" "twoD(refresh) $n"] \
	[list "Clear" "twoD(clear) $n"] \
        [list "Reset to default range" "twoD(default) $n"] \
        [list "Snapshot..." "twoD(snap) $n"] \
        [list "Print..." "twoD(print) $n"] \
        [list "Color..." "window(open) dscolor"]

    set db [build_StdFrame $wname db]
    set dbl [build_StdFrame $db dbl]
    set dbr [build_StdFrame $db dbr]

#    build_Menubar $dbl options \
#	{} \
#	{"Options" \
#		{"Color..." "window(open) dscolor" } \
#		{"Print..." "twoD(print)" } \
#		{"Snapshot..." "twoD(snap)" } }

    build_Menubar $dbl options \
	{} \
	[list "Options" \
		[list "Color..." "window(open) dscolor"] \
		[list "Continuation colors..." "window(open) contcolors"] \
		[list "Print..." "twoD(print) $n"] \
		[list "Snapshot..." "twoD(snap) $n"]
	]
  
    build_Menubar $dbl sizeoptions \
	{} \
	[list "Window sizes" \
		[list "Scale to fit" "twoD(scale_and_refresh) $n"] \
		[list "Set current to default" "twoD(default) $n"] \
		[list "Set default to current" "twoD(def_to_curr) $n"]
	]

    build_Optionscol $dbl pick [list "twoD(pickcolor)" "$n"] \
        [list "Pick color" twoD$n\(pick\)]

    build_DismissButtonbar $dbr dbbar "window(dismiss) twoD$n" \
	[list "Refresh" "twoD(refresh) $n"] \
	[list "Clear" "twoD(clear) $n"]

#        [list "Reset to default range" "twoD(default) $n"] 

    pack $db -fill x -expand true -side bottom
    pack $dbl -side left -fill x
    pack $dbl.options -side left -fill x
    pack $dbl.sizeoptions -side left -fill x 
    pack $dbl.pick -side left -fill x
    pack $dbr -side right -fill x
    pack $dbr.dbbar -side right -fill x -expand true

    build_PopupMenu $cmdl hor {} "twoD$n\(horindex)" \
	"twoD(hor) $n" \
	[concat [array_to_listvalues Model Varb_Names] \
	     [array_to_listvalues Model Param_Names] \
	     [array_to_listvalues Model Funct_Names] ]

    build_PopupMenu $cmdl ver "" "twoD$n\(verindex)" \
	"twoD(ver) $n" \
	[concat [array_to_listvalues Model Varb_Names] \
	     [array_to_listvalues Model Param_Names] \
	     [array_to_listvalues Model Funct_Names] ]

    build_LabelEntryColumns $cmdr le0 \
	     [list dentry {} [list twoD$n\(hormin\) twoD$n\(vermin\)]] \
	     [list dlabel {} [list twoD$n\(hormouse\) twoD$n\(vermouse\)]] \
	     [list dentry {} [list twoD$n\(hormax\) twoD$n\(vermax\)]]

    bind $cmdr.le0.c0.0 <Return> "twoD(update) $n"
    bind $cmdr.le0.c0.1 <Return> "twoD(update) $n"
    bind $cmdr.le0.c2.0 <Return> "twoD(update) $n"
    bind $cmdr.le0.c2.1 <Return> "twoD(update) $n"

    pack $cmdl $cmdr -side left -anchor w
    pack $cmd -fill x

    if { [winfo exists $wname.c] == 0 } {
	plot $wname.c -bg $COLOR(views) -width 600 -height 600
	pack $wname.c -expand 1 -fill both
	bind $wname.c <Motion> [list twoD(c_motion) $n %x %y]
	bind $wname.c <Leave>  [list twoD(c_leave) $n]
	bind $wname.c <Enter>  [list twoD(leave) $n]
	bind $wname <Configure> [list twoD(resize) $n]
	bind $wname.c <Button-1> [list twoD(button1) $n %x %y]
	bind $wname.c <Button-2> [list twoD(button2) $n %x %y]
	bind $wname.c <Button-3> [list twoD(button3) $n %x %y]
	bind $wname.c <Shift-Button-1> [list twoD(shift_button1) $n %x %y]
	bind $wname.c <Shift-B1-Motion> \
	    [list twoD(shift_button1_motion) $n %x %y]
	bind $wname.c <Control-Button-1> [list twoD(control_button1) $n %x %y]
	bind $wname.c <Control-B1-Motion> \
	    [list twoD(control_button1_motion) $n %x %y]
        bind $wname.c <ButtonRelease-1> \
            [list twoD(button1_release) $n %x %y]


	
	window_register TWOD $n ACTIVATE
    }
    
    twoD(register) $n
    set rbox(drawn) 0
    set rbox(key) ""
    set Snap(Wid) $n

# draw highlight right away if it's called for 
    set highlight(two_drawn$n) 0
    if {$Browser(Highlight) == 1} {
        twoD(set_highlight) $n
        twoD(draw_highlight) $n
        }
    set highlight(two_drawn$n) $Browser(Highlight)

    twoD(refresh) $n

}

proc twoD(pickcolor) {n} {
  global Defaults
  upvar #0 twoD$n nm
  #puts "pick color mode for window #$n : $nm(pick)"
  window_register TWOD $n COLORMODE $nm(pick)
  if {$Defaults(Auto_Refresh) == 1} {
	twoD(refresh) $n
  }
}

proc twoD(snap) n {
    global Snap
    global Print

#    set n $Snap(Wid)
    set Snap(Wid) $n
    set Snap(Xwidth) [lindex [.twoD$n.c configure -width] 4] 
    set Snap(Ywidth) [lindex [.twoD$n.c configure -height] 4]
    set Snap(Xoff) 0
    set Snap(Yoff) 0
    set Snap(Directory) $Print(Directory) 
    set Snap(Filename) "twod.snap"
    set Snap(Findex) 0

    window(open) snap
}

proc twoD(print) n {
    global Print
    global Snap

#    set n $Snap(Wid)
    set Snap(Wid) n

    upvar #0 twoD$n nm

    set vals [concat [array_to_listvalues Model Varb_Names] \
             [array_to_listvalues Model Param_Names] \
             [array_to_listvalues Model Funct_Names] ]

    set Print(HorIndex) $nm(horindex)
    set Print(VerIndex) $nm(verindex)

    set Print(Hor_Label) [lindex $vals $Print(HorIndex)]
    set Print(Ver_Label) [lindex $vals $Print(VerIndex)]

    set Print(HorMin) $nm(hormin)
    set Print(HorMax) $nm(hormax)

    set Print(VerMin) $nm(vermin)
    set Print(VerMax) $nm(vermax)

    window(open) print
}


proc twoD(enter) {n} {
}

proc twoD(leave) {n} {
    upvar #0 twoD$n nm

    eval [concat window_register TWOD $n RANGE \
	      $nm(hor) $nm(hormin) $nm(hormax) \
	      $nm(ver) $nm(vermin) $nm(vermax)] 
}

proc twoD(c_motion) {n x y} {
    upvar #0 twoD$n nm
    
    set xy [twoD(convert) $n $x $y]
    set nm(hormouse) [lindex $xy 0]
    set nm(vermouse) [lindex $xy 1]
}

proc twoD(c_leave) n {
    upvar #0 twoD$n nm
    set nm(hormouse) ""
    set nm(vermouse) ""
}

proc twoD(convert) {n x y} {
    upvar #0 twoD$n nm
    set h [lindex [.twoD$n.c configure -height] 4]
    set w [lindex [.twoD$n.c configure -width] 4]
#    set dx [expr double($x)/$w*($nm(hormax)-$nm(hormin))+$nm(hormin)]
#    set dy [expr double($y)/$h*($nm(vermin)-$nm(vermax))+$nm(vermax)]

# BAM 8/18/97  -- error checking in case a min/max field is not a number
    set xokay [catch {set dx [expr double($x)/$w*($nm(hormax)-$nm(hormin))+$nm(hormin)]}]
    set yokay [catch {set dy [expr double($y)/$h*($nm(vermin)-$nm(vermax))+$nm(vermax)]}]
    if {$xokay != 0} { set dx "check bounds" }
    if {$yokay != 0} { set dy "check bounds" }

    list $dx $dy
}

proc twoD(hor) {n} {
    global Defaults Model
    upvar #0 twoD$n nm

    set nm(hor) [index_to_type $nm(horindex) Varb Param Funct]
    set ht [lindex $nm(hor) 0]
    set hn [lindex $nm(hor) 1]
    set nm(hormin) $Defaults($ht\_Min,$hn)
    set nm(hormax) $Defaults($ht\_Max,$hn)
    twoD(register) $n
    if {$Defaults(Auto_Refresh) == 1} {
	twoD(refresh) $n
    }	
# 8/13/97 BAM for save/load purposes
    update_PopupMenu .twoD$n.cmd.l.hor.mb $Model($ht\_Names,$hn) {} {}
}

proc twoD(ver) {n} {
    global Defaults Model
    upvar #0 twoD$n nm
    
    set nm(ver) [index_to_type $nm(verindex) Varb Param Funct]
    set vt [lindex $nm(ver) 0]
    set vn [lindex $nm(ver) 1]
    set nm(vermin) $Defaults($vt\_Min,$vn)
    set nm(vermax) $Defaults($vt\_Max,$vn)
    twoD(register) $n
    if {$Defaults(Auto_Refresh) == 1} {
	twoD(refresh) $n
    }	
# 8/13/97 BAM for save/load purposes
    update_PopupMenu .twoD$n.cmd.l.ver.mb $Model($vt\_Names,$vn) {} {}
}

proc twoD(button1) {n x y} {
    global Flow

    twoD(to_selected) $n $x $y
    set Flow(Direction) 1
    tcl_to_pm Flow
    message_show "Press middle mouse button to go forwards."
}

proc twoD(button2) {n x y} {
    begin_wait
    pm EXEC Flow.Continue
    pm_to_tcl Memory Selected
    end_wait "Press middle mouse button to continue."
}

proc twoD(button3) {n x y} {
    global Flow

    twoD(to_selected) $n $x $y
    set Flow(Direction) 2
    tcl_to_pm Flow
    message_show "Press middle mouse button to go backwards."
}

proc twoD(to_selected) {n x y} {
    global Selected
    upvar #0 twoD$n nm
    
    set xy [twoD(convert) $n $x $y]
    set ht [lindex $nm(hor) 0]
    set vt [lindex $nm(ver) 0]
    set hi [lindex $nm(hor) 1]
    set vi [lindex $nm(ver) 1]
    
    if {$ht != "Funct"} {
	set Selected($ht\_Ic,$hi) [lindex $xy 0]
    }
    if {$vt != "Funct"} {
	set Selected($vt\_Ic,$vi) [lindex $xy 1]
    }
    tcl_to_pm Selected
    selected(enter)
}

proc twoD(refresh) n {
  global View Defaults Browser

  begin_wait "Refreshing 2-D View \#$n"
  twoD(plot_clear) $n
  browser(highlight)
  set View(Refresh_Num) $n
  set View(Refresh_Type) TWOD
  tcl_to_pm View
  pm EXEC View.Refresh
  end_wait
}

proc twoD(refresh_all) {} {
    global View window

    begin_wait {}
    foreach ttt $window(names) {
	if {[regexp {^twoD([0-9]+)$} $ttt tn n] == 1 } {
	    twoD(refresh) $n
	}
    }
    end_wait
}

proc twoD(dismiss) n {
    upvar #0 twoD$n nm
    window_register TWOD $n DISMISS

    unset nm
}

proc twoD(clear) n {
    Flow(Clear_All)
    pm_to_tcl Memory
    twoD(refresh) $n
}

proc twoD(resize) n {
    #puts "Caught Configure event!"
    eval [concat window_register TWOD $n CONFIG \
	      [lindex [.twoD$n.c configure -width] 4] \
	      [lindex [.twoD$n.c configure -height] 4] ]
    #twoD(refresh) $n
}

proc twoD(default) n {
    global Defaults
    upvar #0 twoD$n nm
    
    set ht [lindex $nm(hor) 0]
    set vt [lindex $nm(ver) 0]
    set hi [lindex $nm(hor) 1]
    set vi [lindex $nm(ver) 1]
    
    set nm(hormin) $Defaults($ht\_Min,$hi)
    set nm(hormax) $Defaults($ht\_Max,$hi)
    set nm(vermin) $Defaults($vt\_Min,$vi)
    set nm(vermax) $Defaults($vt\_Max,$vi)
    
    twoD(leave) $n
    if {$Defaults(Auto_Refresh) == 1} {
	twoD(refresh) $n
    }
}

proc twoD(register) n {
    upvar #0 twoD$n nm
    eval [concat window_register TWOD $n CONFIG \
	      [lindex [.twoD$n.c configure -width] 4] \
	      [lindex [.twoD$n.c configure -height] 4] ]
    eval [concat window_register TWOD $n RANGE \
	      $nm(hor) $nm(hormin) $nm(hormax) \
	      $nm(ver) $nm(vermin) $nm(vermax)] 
}


proc twoD(plot_clear) n {
    .twoD$n.c clear
    #update
}

proc index_to_type {n args} {
    global Model
    
    foreach arg $args {
	set m $Model($arg\_Dim)
	if {$n < $m} {
	    return [list $arg $n]
	}
	incr n -$m
    }
}

proc type_to_index {type n args} {
    global Model

    set m 0
    foreach arg $args {
	set d $Model($arg\_Dim)
	if {$type == $arg} {
	    if {$n < $d} {
		return [expr $m + $n]
	    } elseif { $d > 0 } {
		return [expr $m + $d - 1]
	    } else {
		return 0
	    }
	} else {
	    incr m $d
	}
    }
    return 0
}


proc twoD(shift_button1) {n x y} {
    global rbox

    set rbox(x) $x
    set rbox(y) $y
    set rbox(drawn) 0
    set rbox(key) "shift"
}

proc twoD(button1_release) {n x y} {
    global rbox window
    upvar #0 twoD$n nm

    # erase box if drawn
    if {$rbox(drawn) > 0} {
	.twoD$n.c rbox $rbox(x) $rbox(y) $rbox(width) $rbox(height)
	# take appropriate action!
	if {($rbox(width) < 5) || ($rbox(height) < 5)} {
	    set ans 2
	} elseif {$rbox(key) == "shift"} {
	    set ans [build_Dialog dialog "Zoom" "Zoom options:" \
			 0 "Zoom in" "Zoom out" "Cancel"]
	} elseif {$rbox(key) == "control"} {
            set ans [build_Dialog dialog "Multiple ICs" "IC options:" \
			 0 "Load IC's" "Cancel"]
	    set ans [expr $ans + 3]
            }
	if {$ans == 0} {
	    # Zooming in
	    set mins [twoD(convert) $n $rbox(x) $rbox(y)]
	    set maxs [twoD(convert) $n [expr $rbox(x)+$rbox(width)] \
			  [expr $rbox(y)+$rbox(height)] ]
	    set nm(hormin) [lindex $mins 0]
	    set nm(vermin) [lindex $maxs 1]
	    set nm(hormax) [lindex $maxs 0]
	    set nm(vermax) [lindex $mins 1]
	    twoD(register) $n
	    twoD(refresh) $n
	} elseif {$ans == 1} {
	    # Zooming out
	    set h [lindex [.twoD$n.c configure -height] 4]
	    set w [lindex [.twoD$n.c configure -width] 4]
	    set hmin [expr $nm(hormin) - $rbox(x) * \
				($nm(hormax)-$nm(hormin)) / $rbox(width) ]
	    set nm(hormax) [expr $nm(hormin) + ($w-$rbox(x)) * \
				($nm(hormax)-$nm(hormin)) / $rbox(width) ]
	    set nm(hormin) $hmin
	    set vmax [expr $nm(vermax) + $rbox(y) * \
				($nm(vermax)-$nm(vermin)) / $rbox(height) ]
	    set nm(vermin) [expr $nm(vermax) - ($h-$rbox(y)) * \
				($nm(vermax)-$nm(vermin)) / $rbox(height) ]
	    set nm(vermax) $vmax 
	    twoD(register) $n
	    twoD(refresh) $n
	} elseif {$ans == 3} {
            # Check for Multiple orbits panel first
	    if {[lsearch $window(names) "multiple"] == -1} {
		window(open) multiple
		}
	    # set values of radius for hor and ver variables.
    	    set ht [lindex $nm(hor) 0]
            set hn [lindex $nm(hor) 1]
            set vt [lindex $nm(ver) 0]
            set vn [lindex $nm(ver) 1]
    	    set h [lindex [.twoD$n.c configure -height] 4]
            set w [lindex [.twoD$n.c configure -width] 4]
	    if {($ht != "Funct")&&($vt != "Funct")} {
	        # Calculate radii, then put them in postmaster
		set hrad [expr double($rbox(width))/(2.0*$w)*($nm(hormax)-$nm(hormin))]
	        pm PUT "Mult.Radius" $nm(horindex) $hrad
	        set vrad [expr double($rbox(height))/(2.0*$h)*($nm(vermax)-$nm(vermin))]
	        pm PUT "Mult.Radius" $nm(verindex) $vrad
		
		# Now, set the selected point to the center of the rectangle
		set ll [twoD(convert) $n $rbox(x) $rbox(y)]
		set ur [twoD(convert) $n [expr $rbox(x) + $rbox(width)] [expr $rbox(y) + $rbox(height)]]
		set c1 [expr ([lindex $ll 0] + [lindex $ur 0])/2.0] 
                set c2 [expr ([lindex $ll 1] + [lindex $ur 1])/2.0]

		pm PUT Selected.$ht\_Ic $hn $c1 
		pm PUT Selected.$vt\_Ic $vn $c2
	        }
	
	    pm_to_tcl Selected
	    pm_to_tcl Mult
	    multiple(load)
	    }
        }
    set rbox(drawn) 0
    set rbox(key) ""
}

proc twoD(shift_button1_motion) {n x y} {
    global rbox

    # erase box if drawn 
    if {$rbox(drawn) > 0} {
	.twoD$n.c rbox $rbox(x) $rbox(y) $rbox(width) $rbox(height)
    } else {
	set rbox(x) $x
	set rbox(y) $y
    }

    # compute new width height
    set rbox(width) [expr $x - $rbox(x)]
    set rbox(height) [expr $y - $rbox(y)]
    if {$rbox(width) < 0} {
	set rbox(x) $x
	set rbox(width) [expr -$rbox(width)]
    }
    if {$rbox(height) < 0} {
	set rbox(y) $y
	set rbox(height) [expr -$rbox(height)]
    }

    # draw new box
    .twoD$n.c rbox $rbox(x) $rbox(y) $rbox(width) $rbox(height)
    set rbox(drawn) 1
}

proc twoD(control_button1) {n x y} {
    global rbox

    set rbox(x) $x
    set rbox(y) $y
    set rbox(drawn) 0
    set rbox(key) "control"
}

proc twoD(control_button1_motion) {n x y} {
    
    twoD(shift_button1_motion) $n $x $y
}


proc twoD(update) n {
	twoD(leave) $n
	twoD(refresh) $n
}



proc twoD(scale_and_refresh) n {
     global Defaults 

     twoD(auto_scale) $n
     if {$Defaults(Auto_Refresh) == 1} {
          twoD(refresh) $n
     }
}

proc twoD(auto_scale) n {
     global Defaults View

     upvar #0 twoD$n nm

     set padfactor [expr $Defaults(Plot_Scale_Factor) - 1]

     set View(Refresh_Num) $n
     tcl_to_pm View
     pm EXEC View.Calc_Nec_Size
     pm_to_tcl View
     set necsize [array_to_listvalues View Nec_Size ]

     set horwidth [expr $View(Nec_Size,1) - $View(Nec_Size,0)]
     set verwidth [expr $View(Nec_Size,3) - $View(Nec_Size,2)]
     set horpad [expr $horwidth*$padfactor/2.0]
     set verpad [expr $verwidth*$padfactor/2.0]

# Handle cases when horpad and/or verpad is zero (i.e. only have one value)
     if {$horpad == 0} { set horpad [expr (abs($View(Nec_Size,1))+1.0)*$padfactor/2.0] }
     if {$verpad == 0} { set verpad [expr (abs($View(Nec_Size,3))+1.0)*$padfactor/2.0] }

     set nm(hormin) [expr [lindex $necsize 0]-$horpad]
     set nm(hormax) [expr [lindex $necsize 1]+$horpad]
     set nm(vermin) [expr [lindex $necsize 2]-$verpad]
     set nm(vermax) [expr [lindex $necsize 3]+$verpad]

#     set nm(hormin) [expr [lindex $necsize 0]*$padfactor]
#     set nm(hormax) [expr [lindex $necsize 1]*$padfactor]
#     set nm(vermin) [expr [lindex $necsize 2]*$padfactor]
#     set nm(vermax) [expr [lindex $necsize 3]*$padfactor]
  
     twoD(leave) $n
}
 

proc twoD(def_to_curr) n {
     global Defaults

     upvar #0 twoD$n nm

     set ht [lindex $nm(hor) 0]
     set vt [lindex $nm(ver) 0]
     set hi [lindex $nm(hor) 1]
     set vi [lindex $nm(ver) 1]

     set Defaults($ht\_Min,$hi) $nm(hormin)
     set Defaults($ht\_Max,$hi) $nm(hormax)
     set Defaults($vt\_Min,$vi) $nm(vermin)
     set Defaults($vt\_Max,$vi) $nm(vermax)
  
     tcl_to_pm Defaults
     twoD(leave) $n
     if {$Defaults(Auto_Refresh) == 1} {
         twoD(refresh) $n
         }

}


proc twoD(set_highlight) n {
     global highlight Browser

     upvar #0 twoD$n nm
     set ht [lindex $nm(hor) 0]
     set vt [lindex $nm(ver) 0]
     set hi [lindex $nm(hor) 1]
     set vi [lindex $nm(ver) 1]
    
     if {$ht == "Varb"} {
         set real_x $Browser(Vars,$hi)
     } elseif {$ht == "Param"} {
         set real_x $Browser(Params,$hi)
     } else {
         set real_x $Browser(Funcs,$hi)
         }
         
     if {$vt == "Varb"} {
         set real_y $Browser(Vars,$vi)
     } elseif {$vt == "Param"} {
         set real_y $Browser(Params,$vi)
     } else {
         set real_y $Browser(Funcs,$vi)
         }
    
     set wdth [lindex [.twoD$n.c configure -width] 4]
     set hght [lindex [.twoD$n.c configure -height] 4]

     if {$real_x == ""} {
         set highlight(x$n) -1
     } else {
         catch {set highlight(x$n) [expr floor($wdth*($real_x - $nm(hormin))/($nm(hormax) - $nm(hormin)))] }
         }
     if {$real_y == ""} {
         set highlight(y$n) -1
     } else { 
         catch {set highlight(y$n) [expr floor($hght*($nm(vermax) - $real_y)/($nm(vermax) - $nm(vermin)))] }
         }

}


proc twoD(draw_highlight) n {
    global highlight Browser

    # erase highlight if drawn
    if {$highlight(two_drawn$n) > 0} {
        .twoD$n.c highlight $highlight(x$n) $highlight(y$n)
        }

    twoD(set_highlight) $n 
    .twoD$n.c highlight $highlight(x$n) $highlight(y$n)
    set highlight(two_drawn$n) $Browser(Highlight)
}
 

proc twoD(erase_highlight) n {
     global highlight Browser

     twoD(set_highlight) $n

     if {$highlight(two_drawn$n) > 0} {
         .twoD$n.c highlight $highlight(x$n) $highlight(y$n)
         }
     set highlight(two_drawn$n) $Browser(Highlight)
}