Changeset 169 for trunk/MultiChannelUSB


Ignore:
Timestamp:
Oct 18, 2012, 1:13:15 AM (12 years ago)
Author:
demin
Message:

add region of interest to histogram view

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MultiChannelUSB/UserInterface.tcl

    r168 r169  
    88
    99wm minsize . 990 680
     10
     11image create bitmap leftarrow -data "
     12#define leftarrow_width 5\n
     13#define leftarrow_height 5\n
     14static unsigned char leftarrow_bits\[\] = {\n
     150x10, 0x1C, 0x1F, 0x1C, 0x10};"
     16image create bitmap rightarrow -data "
     17#define rightarrow_width 5\n
     18#define rightarrow_height 5\n
     19static unsigned char rightarrow_bits\[\] = {\n
     200x01, 0x07, 0x1F, 0x07, 0x01};"
    1021
    1122namespace eval ::mca {
     
    114125            unset handle
    115126        }
    116 if {1} {
     127if {0} {
    117128        while {[catch {usb::connect 0x09FB 0x6001 1 1 0} result]} {
    118129            set answer [tk_messageBox -icon error -type retrycancel \
     
    429440        ${config}.thrs_field set 25
    430441
     442        my set xmin_val 0
     443        my set xmax_val 4095
     444
     445        trace add variable [myvar xmin_val] write [myproc xmin_val_update]
     446        trace add variable [myvar xmax_val] write [myproc xmax_val_update]
     447       
     448        my stat_update
     449
    431450        set cntr_tmp 1200000000
    432451        my set cntr_val $cntr_tmp
     
    444463        ${config}.chan_frame.axisx_value configure -text 0.0
    445464
     465        ${config}.stat_frame.tot_value configure -text 0.0
     466        ${config}.stat_frame.bkg_value configure -text 0.0
     467
    446468#        my cntr_reset
    447469    }
     
    461483        $graph legend configure -hide yes
    462484
     485        $graph marker create line -name xmin -coords "0 -Inf 0 Inf"  -linewidth 2 -outline red
     486        $graph marker create line -name xmax -coords "4095 -Inf 4095 Inf"  -linewidth 2 -outline red
     487        $graph marker bind xmin <Enter> [list [self] marker_enter xmin]
     488        $graph marker bind xmin <Leave> [list [self] marker_leave xmin]
     489        $graph marker bind xmax <Enter> [list [self] marker_enter xmax]
     490        $graph marker bind xmax <Leave> [list [self] marker_leave xmax]
     491
    463492        set config [frame ${master}.config -width 170]
    464493
    465494        checkbutton ${config}.axis_check -text {log scale} -variable [myvar axis]
    466495
    467         frame ${config}.spc1 -width 170 -height 30
     496        frame ${config}.spc1 -width 170 -height 20
    468497
    469498        frame ${config}.rate_frame -borderwidth 0 -width 170
     
    471500        legendLabel ${config}.rate_frame 1 mean {Avg. rate, 1/s}
    472501
    473         frame ${config}.spc2 -width 170 -height 30
     502        frame ${config}.spc2 -width 170 -height 10
    474503
    475504        frame ${config}.chan_frame -borderwidth 0 -width 170
    476505        legendLabel ${config}.chan_frame 0 entr  {Total entries}
    477         legendLabel ${config}.chan_frame 1 empty {}
     506        frame ${config}.chan_frame.spc1 -height 10
     507        grid ${config}.chan_frame.spc1 -row 1
    478508        legendLabel ${config}.chan_frame 2 axisy {Bin entries}
    479509        legendLabel ${config}.chan_frame 3 axisx {Bin number}
    480 
    481         frame ${config}.spc3 -width 170 -height 30
     510               
     511        frame ${config}.spc3 -width 170 -height 10
     512
     513        label ${config}.roi -text {Region of interest}
     514        frame ${config}.roi_frame -borderwidth 0 -width 170
     515        label ${config}.roi_frame.min_title -anchor w -text {start:}
     516        label ${config}.roi_frame.min_value -width 4 -anchor e -text {}
     517        label ${config}.roi_frame.spc1 -width 5 -anchor w -text {}
     518        label ${config}.roi_frame.max_title -anchor w -text {end:}
     519        label ${config}.roi_frame.max_value -width 4 -anchor e -text {}
     520
     521        grid ${config}.roi_frame.min_title ${config}.roi_frame.min_value \
     522            ${config}.roi_frame.spc1 ${config}.roi_frame.max_title \
     523            ${config}.roi_frame.max_value
     524
     525        frame ${config}.stat_frame -borderwidth 0 -width 17
     526
     527        legendLabel ${config}.stat_frame 0 tot {total entries}
     528        legendLabel ${config}.stat_frame 1 bkg {bkg entries}
     529
     530        frame ${config}.spc4 -width 170 -height 20
    482531
    483532        checkbutton ${config}.thrs_check -text {amplitude threshold} -variable [myvar thrs]
     
    486535            -validate all -vcmd {::mca::validate 4095 4 %P}
    487536
    488         frame ${config}.spc4 -width 170 -height 30
     537        frame ${config}.spc5 -width 170 -height 20
    489538
    490539        label ${config}.cntr -text {time of exposure}
     
    504553            ${config}.cntr_frame.m_field ${config}.cntr_frame.m ${config}.cntr_frame.s_field ${config}.cntr_frame.s
    505554
    506         frame ${config}.spc5 -width 170 -height 10
     555        frame ${config}.spc6 -width 170 -height 20
    507556
    508557        button ${config}.start -text Start \
     
    511560            -bg red -activebackground red -command [myproc cntr_reset]
    512561
    513         frame ${config}.spc6 -width 170 -height 30
     562        frame ${config}.spc7 -width 170 -height 20
    514563
    515564        button ${config}.register -text Register \
    516565            -bg lightblue -activebackground lightblue -command [myproc register]
    517566
    518         frame ${config}.spc7 -width 170 -height 30
     567        frame ${config}.spc8 -width 170 -height 20
    519568
    520569        button ${config}.recover -text {Read file} \
     
    527576        grid ${config}.chan_frame -sticky ew -padx 5
    528577        grid ${config}.spc3
     578        grid ${config}.roi -sticky w -pady 1 -padx 5
     579        grid ${config}.roi_frame -sticky ew -padx 5
     580        grid ${config}.stat_frame -sticky ew -padx 5
     581        grid ${config}.spc4
    529582        grid ${config}.thrs_check -sticky w
    530583        grid ${config}.thrs_field -sticky ew -pady 1 -padx 5
    531         grid ${config}.spc4
     584        grid ${config}.spc5
    532585        grid ${config}.cntr -sticky w -pady 1 -padx 3
    533586        grid ${config}.cntr_frame -sticky ew -padx 5
    534         grid ${config}.spc5
     587        grid ${config}.spc6
    535588        grid ${config}.start -sticky ew -pady 3 -padx 5
    536589        grid ${config}.reset -sticky ew -pady 3 -padx 5
    537         grid ${config}.spc6
     590        grid ${config}.spc7
    538591        grid ${config}.register -sticky ew -pady 3 -padx 5
    539         grid ${config}.spc7
     592        grid ${config}.spc8
    540593        grid ${config}.recover -sticky ew -pady 3 -padx 5
    541594
     
    549602        grid columnconfigure ${config}.rate_frame 1 -weight 1
    550603        grid columnconfigure ${config}.chan_frame 1 -weight 1
     604        grid columnconfigure ${config}.stat_frame 1 -weight 1
    551605
    552606        my crosshairs $graph
     
    556610        # create one element with data for the x and y axis, no dots
    557611        $graph element create Spectrum1 -color blue -linewidth 2 -symbol none -smooth step -xdata [myvar xvec] -ydata [myvar yvec]
     612    }
     613
     614# -------------------------------------------------------------------------
     615
     616    HstDisplay instproc marker_enter {marker} {
     617        my instvar config graph
     618        $graph configure -cursor hand2
     619        $graph crosshairs off
     620        blt::RemoveBindTag $graph zoom-$graph
     621        $graph marker bind $marker <ButtonPress-1> [list [self] marker_press $marker]
     622        $graph marker bind $marker <ButtonRelease-1> [list [self] marker_release $marker]
     623    }
     624
     625# -------------------------------------------------------------------------
     626
     627    HstDisplay instproc marker_leave {marker} {
     628        my instvar config graph
     629        $graph configure -cursor crosshair
     630        $graph crosshairs on
     631        blt::AddBindTag $graph zoom-$graph
     632        $graph marker bind $marker <ButtonPress-1> {}
     633        $graph marker bind $marker <ButtonRelease-1> {}
     634    }
     635
     636# -------------------------------------------------------------------------
     637
     638    HstDisplay instproc marker_press {marker} {
     639        my instvar config graph
     640        $graph marker bind $marker <Motion> [list [self] ${marker}_motion %W %x %y]
     641    }
     642
     643# -------------------------------------------------------------------------
     644
     645    HstDisplay instproc marker_release {marker} {
     646        my instvar config graph
     647        $graph marker bind $marker <Motion> {}
     648    }
     649
     650# -------------------------------------------------------------------------
     651
     652    HstDisplay instproc xmin_motion {W x y} {
     653        my instvar config graph xmin_val
     654        set index [$graph axis invtransform x $x]
     655        set index [::tcl::mathfunc::round $index]
     656        if {$index < 0} {
     657            set index 0
     658        }
     659        set xmin_val $index
     660    }
     661
     662# -------------------------------------------------------------------------
     663
     664    HstDisplay instproc xmax_motion {W x y} {
     665        my instvar config graph xmax_val
     666        set index [$graph axis invtransform x $x]
     667        set index [::tcl::mathfunc::round $index]
     668        if {$index > 4095} {
     669            set index 4095
     670        }
     671        set xmax_val $index
    558672    }
    559673
     
    572686        }
    573687    }
     688
    574689# -------------------------------------------------------------------------
    575690
     
    622737# -------------------------------------------------------------------------
    623738
     739    HstDisplay instproc stat_update {} {
     740        my instvar config graph xmin_val xmax_val
     741        set ymin_val [[myvar yvec] index $xmin_val]
     742        set ymax_val [[myvar yvec] index $xmax_val]
     743
     744        ${config}.roi_frame.min_value configure -text $xmin_val
     745        ${config}.roi_frame.max_value configure -text $xmax_val
     746       
     747        ${config}.stat_frame.tot_value configure \
     748            -text [usb::integrateBlt [myvar yvec] $xmin_val $xmax_val 0]
     749
     750        ${config}.stat_frame.bkg_value configure \
     751            -text [expr {($xmax_val - $xmin_val + 1) * ($ymin_val + $ymax_val) / 2.0}]
     752   }
     753# -------------------------------------------------------------------------
     754
     755    HstDisplay instproc xmin_val_update args {
     756        my instvar config graph xmin_val xmax_val
     757        if {$xmin_val > 4075} {
     758            set xmin_val 4075
     759        }
     760        if {$xmin_val > $xmax_val - 20} {
     761            set xmax_val [expr {$xmin_val + 20}]
     762        }
     763        $graph marker configure xmin -coords "$xmin_val -Inf $xmin_val Inf"
     764        my stat_update
     765    }
     766
     767# -------------------------------------------------------------------------
     768
     769    HstDisplay instproc xmax_val_update args {
     770        my instvar config graph xmin_val xmax_val
     771        if {$xmax_val < 20} {
     772            set xmax_val 20
     773        }
     774        if {$xmax_val < $xmin_val + 20} {
     775            set xmin_val [expr {$xmax_val - 20}]
     776        }
     777        $graph marker configure xmax -coords "$xmax_val -Inf $xmax_val Inf"
     778        my stat_update
     779    }
     780
     781# -------------------------------------------------------------------------
     782
    624783    HstDisplay instproc rate_val_update {name key op} {
    625784        my instvar config rate_val
     
    737896            set cntr_bak $cntr_tmp
    738897            set cntr_old $cntr_tmp
    739             set yvec_bak [usb::integrateBlt [myvar yvec] 0]
     898            set yvec_bak [usb::integrateBlt [myvar yvec] 0 4095 0]
    740899            set yvec_old $yvec_bak
    741900
     
    824983
    825984        $controller usbCmdReadRaw $command [expr {$size * 4}] [myvar data]
    826         set yvec_new [usb::integrateBlt [myvar yvec] 0]
     985        set yvec_new [usb::integrateBlt [myvar yvec] 0 4095 0]
    827986
    828987        set prefix [format {%x} [expr {5 + ${number}}]]
     
    836995            set rate_val(mean) [expr {($yvec_new - $yvec_bak)*20000000/($cntr_bak - $cntr_new)}]
    837996            ${config}.chan_frame.entr_value configure -text $yvec_new
     997            my stat_update
    838998
    839999            set yvec_old $yvec_new
     
    9131073
    9141074    HstDisplay instproc recover {} {
     1075        my instvar config
    9151076        my open_data
     1077        ${config}.chan_frame.entr_value configure -text [usb::integrateBlt [myvar yvec] 0 4095 0]
     1078        my stat_update
    9161079    }
    9171080
     
    12991462
    13001463        ${config}.chan_frame.mean_value configure \
    1301             -text [format {%.2e} [usb::integrateBlt [myvar yvec] 1]]
     1464            -text [format {%.2e} [usb::integrateBlt [myvar yvec] 0 9999 1]]
    13021465        ${config}.chan_frame.entr_value configure \
    1303             -text [usb::integrateBlt [myvar yvec] 0]
     1466            -text [usb::integrateBlt [myvar yvec] 0 9999 0]
    13041467
    13051468    }
Note: See TracChangeset for help on using the changeset viewer.