reference/ocr-new/multi_zone.test.tcl
changeset 0 6b8091ca909a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/reference/ocr-new/multi_zone.test.tcl	Thu May 18 23:12:51 2006 +0200
@@ -0,0 +1,234 @@
+proc multiZone_open { filename } {
+# 1 means success
+    global IMAGE_DISPLAY_WIN ZONING_SCALE_FACTOR DISPLAY_IMAGE XV xvprocess \
+	    multiZone_display_open
+    
+    set open 1
+    
+    if { $multiZone_display_open == $open } {
+	focus .zoning_window
+    } else {
+	
+	toplevel .zoning_window
+	init_zoning_display .zoning_window
+    }
+	
+        
+#   puts stdout "Opening $filename"
+    page_open $filename
+# Scale image to display    
+    set ZONING_SCALE_FACTOR .50
+#[ max [expr 800.0/[get_page_height]] \
+#		[expr 800/[get_page_width]] ]
+
+#   puts stdout "Done putting into page structure"
+    if { 1 }  {
+	set display_height [expr $ZONING_SCALE_FACTOR * [get_page_height]]
+	set display_width [expr $ZONING_SCALE_FACTOR * [get_page_width]]
+	append geometry [expr int($display_width)] x [expr int($display_height)]
+#	puts stdout "Displaying Image"
+	if { $DISPLAY_IMAGE == $XV } {
+	    set xvprocess [exec xv $filename &]
+	    puts stdout "xvprocess $xvprocess"
+	} else {
+# use the canvas...
+	DISPLAY_INTERVALS .zoning_window.work_space $ZONING_SCALE_FACTOR
+	FIND_LINES
+	}
+    } else {
+	popup_image_failure_win
+    }
+    puts stdout "Determining Line boundaries"
+
+}
+
+
+proc init_zoning_display { window } {
+    global ZONING_SCALE_FACTOR BACKGROUND FOREGROUND scroll_inc
+	wm geometry $window 800x800
+	wm title $window "Zoning Window"
+	wm minsize $window 400 300
+        $window configure -background $BACKGROUND
+
+ 
+    set canvas_width 1000
+    set canvas_height 1000
+
+   canvas $window.work_space -bg white -xscrollcommand \
+	  "$window.xscroller set" -yscrollcommand \
+	  "$window.yscroller set" -xscrollincrement \
+	   $scroll_inc -cursor {crosshair black gray}  \
+	   -width $canvas_width -height $canvas_height 
+# two scrollbars
+    scrollbar $window.xscroller -command "$window.work_space xview" -orient horizontal -background $BACKGROUND
+    scrollbar $window.yscroller -command "$window.work_space yview" -background $BACKGROUND
+
+    pack $window.xscroller -side bottom -fill x
+}
+
+proc max { a b } {
+    if { [expr $a] > [expr $b] } {
+	return $a
+    } else {
+	return $b
+    }
+}
+
+
+
+
+
+set x_init 0
+set y_init 0
+set x_final 0
+set y_final 0
+
+set started_region 0
+set region_count 0
+
+
+proc initialize_region_grab { window } {
+#
+#
+# facilitates the grabbing of a rectangle of the window
+# using mouse button 1
+# canvas subwindow must be called $window.work_space
+
+    global x_init y_init x_final y_final started_region region_data region_list region_id arrow_in_progress current_arrow
+    
+    bind $window.work_space <ButtonPress-1> {
+	if [expr ! $started_region] {
+	    grab set $window 
+	    set x_init [$window.work_space canvasx %x]
+	    set y_init [$window.work_space canvasy %y]
+
+	    set region_id [$window.work_space create rectangle $x_init $y_init $x_init $y_init -outline black -width 3 ]
+	    $window.work_space itemconfigure $region_id -tags region$region_id
+
+	    set started_region 1
+
+	}
+    }
+    bind $window.work_space <ButtonRelease-1> {
+	set x_final [$window.work_space canvasx %x]
+	set y_final [$window.work_space canvasy %y]
+	
+	$window.work_space coords region$region_id $x_init $y_init $x_final $y_final
+
+
+	# if finishing a rectangle, initialize its stuff in the array
+	if {$x_init <= $x_final} {
+	    set region_data($region_id,x_init) $x_init
+	    set region_data($region_id,x_final) $x_final
+	} else {
+	    set region_data($region_id,x_final) $x_init
+	    set region_data($region_id,x_init) $x_final
+	}
+	if {$y_init <= $y_final} {
+	    set region_data($region_id,y_init) $y_init
+	    set region_data($region_id,y_final) $y_final
+	} else {
+	    set region_data($region_id,y_init) $y_final
+	    set region_data($region_id,y_final) $y_init
+	}
+	
+	set region_data($region_id,next_region_id) 0
+	lappend region_list $region_id
+	
+	make_region_buttons $region_id	    
+
+	set started_region 0
+	grab release $window
+    }
+    
+    bind $window.work_space <B2-Motion> {
+	if $arrow_in_progress {
+	    set curx [$window.work_space canvasx %x] 
+	    set cury [$window.work_space canvasy %y]
+	    $window.work_space coords $current_arrow 0 0 $curx $cury
+	}
+    }
+    bind $window.work_space <B1-Motion> {
+	if $started_region {
+
+	    set curx [$window.work_space canvasx %x] 
+	    set cury [$window.work_space canvasy %y]
+
+	    $window.work_space coords region$region_id $x_init $y_init $curx $cury
+
+
+	} 
+    }
+    bind $window <Leave> {
+	# on leaving the display, release control of the mouse etc.
+	# maybe make it scroll instead?
+	if $started_region {
+	    grab release $window
+	    set started_region 0
+	    $window.work_space coords region$region_id 0 0 0 0  
+	}
+    }
+}
+
+
+
+set arrow_in_progress 0
+
+proc make_region_buttons {reg_id } {
+    global region_data kill_button_data next_button_data arrow_in_progress current_arrow
+
+    set x_init $region_data($reg_id,x_init)
+    set y_init $region_data($reg_id,y_init)
+
+    set next_num [$window.work_space create rectangle $x_init $y_init [expr $x_init + 40] [expr $y_init + 20]  -tags "region$reg_id next_button$reg_id"]
+#statement above had -fill blue between 20 and -tags
+    set next_button_data($next_num,reg_id) $reg_id
+    $window.work_space bind next_button$reg_id <Double-2> {
+	set reg_id $next_button_data([$window.work_space find withtag current],reg_id)
+	if { $arrow_in_progress } {
+	    finish_arrow $reg_id
+	} else {
+	    set canvas_x [$window.work_space canvasx %x] 
+	    set canvas_y [$window.work_space canvasy %y]
+	    start_arrow $reg_id $canvas_x $canvas_y
+	    puts stdout "Starting an arrow at $canvas_x $canvas_y"
+	}
+    }
+    set kill_num [$window.work_space create rectangle [expr $x_init] $y_init [expr $x_init + 20] [expr $y_init + 20] -fill red  -tags "region$reg_id kill_button$reg_id"]
+    set kill_button_data($kill_num,reg_id) $reg_id
+
+    $window.work_space bind kill_button$reg_id <Double-2> {
+	set reg_id $kill_button_data([$window.work_space find withtag current],reg_id)
+	destroy_region $reg_id $window.work_space
+    }
+}
+
+
+
+
+proc start_arrow { reg_id x_start y_start } {
+    global arrow_in_progress next_button_data region_data current_arrow
+    set path_name $window.work_space
+# start an arrow in the middle of the little red button
+    
+    
+
+    set arrow [$window.work_space create line $x_start $y_start $x_start $y_start -width 3 -arrow last -arrowshape {6.0m 8.0m 1.5m} -fill blue -tags arrow$reg_id]
+
+    set region_data($reg_id,arrow) $arrow
+    set arrow_in_progress 1
+    set current_arrow $arrow
+}
+
+
+proc destroy_region { reg_id path_name } {
+    $path_name delete region$reg_id
+    puts stdout "Destroying $reg_id"
+}
+
+
+
+
+
+
+