
# This code creates the user interface for the mesh editor.
#
# Copyright (c) 1993 - 1995 Pacific Marketing and Consulting, Inc,
#       and ICEM Systems, GmbH.  All rights reserved.
# Author:  Wayne A. Christopher, wayne@icemcfd.com

proc make_struct_window {w} {
    global str_type_visible display_menu_info str_option
    global str_number_visible
    
    checkbutton $w.domain -text Domains -variable str_type_visible(domain)
    checkbutton $w.subface -text Subfaces -variable str_type_visible(subface)
    checkbutton $w.edge -text Edges -variable str_type_visible(edge)
    checkbutton $w.vertex -text Vertices -variable str_type_visible(vertex)
    #checkbutton $w.region -text Regions -variable str_type_visible(region)
    foreach t {domain subface edge vertex} {  ;# region
	$w.$t configure -command "disp_change_overall_visible $t"
    }
    
    menubutton $w.domain_opt -text Opts -menu $w.domain_opt.m \
	-relief raised -borderwidth 2
    menubutton $w.subface_opt -text Opts -menu $w.subface_opt.m \
	-relief raised -borderwidth 2
    menubutton $w.edge_opt -text Opts -menu $w.edge_opt.m \
	-relief raised -borderwidth 2
    menubutton $w.vertex_opt -text Opts -menu $w.vertex_opt.m \
	-relief raised -borderwidth 2
    #menubutton $w.region_opt -text Opts -menu $w.region_opt.m -relief raised -borderwidth 2
    
    menu $w.domain_opt.m -tearoffcommand "disp_set_tearoff_name Domain"
    menu $w.subface_opt.m -tearoffcommand "disp_set_tearoff_name Subface"
    menu $w.edge_opt.m -tearoffcommand "disp_set_tearoff_name Edge"
    menu $w.vertex_opt.m -tearoffcommand "disp_set_tearoff_name Vertex"
    #menu $w.region_opt.m -tearoffcommand "disp_set_tearoff_name Region"
    
    foreach type {domain subface edge vertex} { ;# region
	set m $w.${type}_opt.m
	foreach opt $display_menu_info($type) {
	    switch [llength $opt] {
		0 {
		    $m add separator
		}
		2 {
		    $m add command -label [lindex $opt 0] \
			-command [lindex $opt 1]
		}
		3 {
		    $m add checkbutton -label [lindex $opt 0] \
			-variable str_option([lindex $opt 1]) \
			-command [lindex $opt 2]
		}
		4 {
		    $m add radiobutton -label [lindex $opt 0] \
			-variable str_option([lindex $opt 1]) \
			-value [lindex $opt 2] -command [lindex $opt 3]
		}
	    }
	}
	
	set str_option($type,shade) wire
	set str_option($type,ijk_shrink) 0
    }
    set str_option(domain,shade) none
    
    frame $w.domain_list
    frame $w.subface_list
    frame $w.edge_list
    frame $w.vertex_list
    #frame $w.region_list
    
    frame $w.scanp -relief ridge -borderwidth 2
    make_scanp_control $w.scanp
        
    grid $w.domain       -row 1 -column 1  -columnspan 2 -sticky w
    grid $w.domain_opt   -row 1 -column 3  -columnspan 1 -sticky we
    grid $w.domain_list  -row 2 -column 1  -columnspan 3 -sticky nswe
    grid $w.subface      -row 3 -column 1  -columnspan 2 -sticky w
    grid $w.subface_opt  -row 3 -column 3  -columnspan 1 -sticky we
    grid $w.subface_list -row 4 -column 1  -columnspan 3 -sticky nswe
    grid $w.edge         -row 5 -column 1  -columnspan 2 -sticky w
    grid $w.edge_opt     -row 5 -column 3  -columnspan 1 -sticky we
    grid $w.edge_list    -row 6 -column 1  -columnspan 3 -sticky nswe
    grid $w.vertex       -row 7 -column 1  -columnspan 2 -sticky w
    grid $w.vertex_opt   -row 7 -column 3  -columnspan 1 -sticky we
    grid $w.vertex_list  -row 8 -column 1  -columnspan 3 -sticky nswe
    #grid $w.region       -row 9 -column 1  -columnspan 2 -sticky w
    #grid $w.region_opt   -row 9 -column 3  -columnspan 1 -sticky we
    #grid $w.region_list  -row 10 -column 1 -columnspan 3 -sticky we
    grid $w.scanp        -row 11 -column 1 -columnspan 3 -sticky we
    
    trace variable str_number_visible w "disp_list_update_trace"
    
    set str_type_visible(domain) 1
}

proc initialize_struct_visibility {} {
    update_struct_visibility
    disp_new_stuff
}


proc update_struct_visibility {} {
    global fam_visible str_type_visible str_number_visible
    global str_domain_visible
    
    foreach f [ic_str_list_families] {
	if ![info exists fam_visible($f)] {
	    set fam_visible($f) 1
	}
    }
    foreach type {domain subface edge vertex region} {
	if ![info exists str_type_visible($type)] {
	    set str_type_visible($type) [expr {$type == "domain"}]
	}
	foreach s [ic_str_list_entities $type] {
	    if ![info exists str_number_visible($type,$s)] {
		set str_number_visible($type,$s) 1
	    }
	}
    }
    foreach s [ic_str_list_entities domain] {
	foreach type {subface edge vertex} {
	    set str_domain_visible($type,$s) 0
	}
    }
}

proc uninitialize_struct_visibility {} {
}

# ----------------------------------------------------------

proc str_set_visibility_surfs {what on famvar numvar} {
}

proc update_str_visible {} {
    global fam_visible str_type_visible
    
    ic_str_set_type_family_visible [array get str_type_visible] [array get fam_visible]
}

proc disp_change_overall_visible {what} {
    global str_type_visible fam_visible
    
    ic_str_topo_make_surfs $what 0
    disp_set_option $what
#    disp_pack_list $what
    ic_str_set_type_family_visible "$what $str_type_visible($what)" [array get fam_visible]
    global aie_sharedStrDisplay
    if $aie_sharedStrDisplay(shared) {
        aie_changeStrSharedDisplay shared
	} elseif $aie_sharedStrDisplay(unshared) {
	    aie_changeStrSharedDisplay unshared
	}
}

proc disp_set_visible {what how} {
    global str_update_trace_disable
    global str_number_visible fam_visible

    set vals ""
    switch $how {
	0 - 1 {
	    # This is a roundabout way to get the update to happen quickly.
	    set str_update_trace_disable 1
	    foreach s [ic_str_list_entities $what] {
		if {$str_number_visible($what,$s) != $how} {
		    set str_number_visible($what,$s) $how
		}
	    }
	    unset str_update_trace_disable
	    set nl .e.struct.${what}_list.number.list
	    if [winfo exists $nl] {
		if $how { set sc set } else { set sc clear }
		$nl selection $sc 0 end
	    }
	    set dl .e.struct.${what}_list.domain.list
	    if [winfo exists $dl] {
		if $how { set sc set } else { set sc clear }
		$dl selection $sc 0 end
	    }
	    ic_str_set_type_family_visible "$what $how" ""
	    return
	}
	b {
	    set surfs [select_struct_surf $what 0 item]
	    foreach s $surfs {
		lappend vals $s 0
	    }
	}
	r {
	    set surfs [select_struct_surf $what 0 item]
	    foreach s $surfs { set found($s) 1 }
	    foreach s [ic_str_list_entities $what] {
		if ![info exists found($s)] {
		    lappend vals $s 0
		}
	    }
	}
	i {
	    foreach s [ic_str_list_entities $what] {
		set n $str_number_visible($what,$s)
		lappend vals $s [expr !$n]
	    }
	}
	u  - s {
	    foreach s [ic_str_list_entities $what] {
		set n [llength [ic_str_get_topo_info $what $s 1]]
		if {$how == "u"} {
		    lappend vals $s [expr $n == 1]
		} else {
		    lappend vals $s [expr $n == 2]
		}
	    }
	}
	a {
	    foreach s [ic_str_list_entities $what] {
		if $str_number_visible($what,$s) {
		    foreach a [ic_str_adjacent_surfs $what $s] {
			set got($a) 1
		    }
		}
	    }
	    foreach a [array names got] {
		lappend vals $a 1
	    }
	}
    }
    foreach {s v} $vals {
	set str_number_visible($what,$s) $v
    }
    ic_str_set_nums_visible $what $vals
}

proc disp_pack_list {what} {
    global str_type_visible str_option disp_struct_row_number
    
    set wn .e.struct.${what}_list.number
    set wd .e.struct.${what}_list.domain
    
    if {$str_option($what,selnumber) && $str_type_visible($what)} {
	if ![winfo exists $wn] {
	    disp_make_list $wn $what number
	}
	if [catch {pack info $wn}] {
	    pack $wn -side top -fill both -expand 1
	}
    } else {
	catch {pack unpack $wn}
    }
    if {$what != "domain"} {
	if {$str_option($what,seldomain) && $str_type_visible($what)} {
	    if ![winfo exists $wd] {
		disp_make_list $wd $what domain
	    }
	    if [catch {pack info $wd}] {
		pack $wd -side top -fill both -expand 1
	    }
	} else {
	    catch {pack unpack $wd}
	}
    }
    
    # Should we allow the struct subwindow to grow or not?
    set grow 0
    set curr 2
    foreach t {domain subface edge vertex} {
	set wn .e.struct.${t}_list.number
	set wd .e.struct.${t}_list.domain
	if {![catch {pack info $wn}] || ![catch {pack info $wd}]} {
	    grid rowconfigure .e.struct $curr -weight 1
	    set grow 1
	} else {
	    grid rowconfigure .e.struct $curr -weight 0
	}
	incr curr 2
    }
    grid rowconfigure .e $disp_struct_row_number -weight $grow
}

proc disp_update_number_list {what} {
    set wn .e.struct.${what}_list.number
    if [info exists $wn] {
	disp_make_list $wn $what number
    }
}

proc disp_make_list {w what which} {
    global str_${which}_visible
    global disp_list_location
    
    set choices ""
    switch $which {
	number {
	    set choices [ic_str_list_entities $what]
	}
	family {
	    foreach s [ic_str_list_entities $what] {
		set fam [ic_str_get_family $what $s]
		set families($fam) 1
	    }
	    catch {unset families()}
	    set choices [lsort -command "family_name_compare -1" \
			     [array names families]]
	}
	domain {
	    set choices ""
	    set nd [ic_str_num_entities domain]
	    for {set d 1} {$d <= $nd} {incr d} { lappend choices $d }
	}
    }
    if ![winfo exists $w] {
	frame $w
	listbox $w.list -background white -height 4 -width 4 \
	    -selectmode multiple -selectbackground cyan -selectborderwidth 0 \
	    -exportselection 0 -yscroll "$w.scroll set"
	
	bind $w.list <1> "tkListboxBeginSelect %W \[%W index @%x,%y\]; \
		disp_toggle_${which}_visible $what \
		\[%W get \[%W nearest %y\]\]; break"
	foreach ev {<B1-Motion> <ButtonRelease-1> <B1-Leave> <B1-Enter>} {
	    bind $w.list $ev break
	}
	
	scrollbar $w.scroll -command "$w.list yview"  -relief sunken \
	    -borderwidth 2 -orient v
	pack $w.list -side left -fill both -expand 1
	puts "pack $w.list -side left -fill both -expand 1"
	pack $w.scroll -side right -fill y
    } else {
	$w.list delete 0 end
    }
    foreach ch $choices {
	set loc [$w.list size]
	set disp_list_location($which,$what,$ch) $loc
	$w.list insert end $ch
	if [set str_${which}_visible($what,$ch)] {
	    $w.list selection set $loc
	}
    }
    
    # To help unpacking of list window - quick fix
    set wf .e.struct.${what}_list.dummy
    if ![winfo exists $wf] {
	frame $wf 
	pack $wf -side top -fill both -expand 0
    }
}

proc disp_toggle_number_visible {what name {on ""}} {
    global str_number_visible
    
    if {$name == ""} return
    
    if {$on == ""} {
	set on [expr ![set str_number_visible($what,$name)]]
    }
    
    set str_number_visible($what,$name) $on
    ic_str_set_nums_visible $what [list $name $on]
}

# This one is a bit strange because every time anything changes here we
# recompute all the subface, etc visibility.  That is because entities
# can be shared.

proc disp_toggle_domain_visible {what name {on ""}} {
    global str_domain_visible str_number_visible
    global disp_list_location

    if {$name == ""} return
    
    if {$on == ""} {
	set on [expr ![set str_domain_visible($what,$name)]]
    }
    set vv disp_list_location(domain,$name)
    if [info exists $vv] {
        set n [set $vv]
	set w .e.struct.${what}_list.domain
	if $on {
	    $w.list selection set $n
	} else {
	    $w.list selection clear $n
	}
    }
    set str_domain_visible($what,$name) $on
    
    foreach s [ic_str_list_entities $what] {
	set is_on($s) 0
    }
    foreach d [ic_str_list_entities domain] {
	if $str_domain_visible($what,$d) {
	    foreach s [ic_str_boundaries_of_entity domain $d] {
		set is_on($s) 1
	    }
	}
    }
    set changes ""
    foreach s [array names is_on] {
	if {$is_on($s) != $str_number_visible($what,$s)} {
	    set str_number_visible($what,$s) $is_on($s)
	    lappend changes $s $is_on($s)
	}
    }
    if {$changes != ""} {
	ic_str_set_nums_visible $what $changes
    }
}

proc disp_list_update_trace {varname key op} {
    global disp_list_location str_type_visible
    global str_number_visible
    global str_update_trace_disable
    
    if [info exists str_update_trace_disable] return
    
    set what [lindex [split $key ,] 0]
    set num [lindex [split $key ,] 1]
    set on [expr {[set ${varname}($key)] && $str_type_visible($what)}]
    
    set vv disp_list_location(number,$key)
    if [info exists $vv] {
        set n [set $vv]	
	set w .e.struct.${what}_list.number
	if $on {
	    $w.list selection set $n
	    
	} else {
	    $w.list selection clear $n
	}
    }
}

proc disp_set_option {what} {
    if {$what == "all"} {
        foreach type {domain subface edge vertex region} {
            disp_set_option_one $type ""
        }
    } else {
        disp_set_option_one $what ""
    }
}

proc disp_set_option_one {what num} {
    global str_option
    if [ic_str_is_loaded] {
	    ic_str_configure $what $num \
            $str_option($what,shade) \
            $str_option($what,type_color) \
            $str_option($what,nodes) \
            $str_option($what,ijk) \
            $str_option($what,names) \
	        $str_option($what,numbers) \
	        $str_option($what,outlines) \
	        $str_option($what,node_size) \
	        $str_option($what,famcols) \
	        $str_option($what,simplify) \
	        $str_option($what,ijk_shrink) \
	        $str_option($what,width) \
	        $str_option($what,extended) \
	        $str_option($what,changes) \
	        $str_option($what,draw_twin)
    }
}

proc disp_shrink_ijk {what reset} {
    global str_option
    if $reset {
	set str_option($what,ijk_shrink) 0
    } else {
	incr str_option($what,ijk_shrink)
    }
    disp_set_option $what
}

proc disp_adjacent {} {
}

# ----------------------------------------------------------

proc make_scanp_control {w} {
    global guibase_dir scanp scanp_form ai_environment
   
    if {![info exists ai_environment] || ($ai_environment == 0)} {
        set scanp_form $w
        checkbutton $w.on -text "Scan planes" -variable scanp(visible) \
	    -command scanp_change_visible -anchor w
    }
    frame $w.c1
    frame $w.c2
    frame $w.c3
    button $w.c1.new -text New -command scanp_new
    button $w.c1.delete -text Delete -command scanp_delete
    button $w.c1.clear -text Clear -command scanp_clear
    if {[info exists ai_environment] && $ai_environment} {
        button $w.c1.done -text Done -command aie_domain_scanplanes_form_done
    }
    menubutton $w.c2.how -textvariable scanp(how) -menu $w.c2.how.m \
	-relief raised -borderwidth 2
    entry $w.c2.index -textvariable scanp(ind) -width 3
    button $w.c2.up -bitmap @$guibase_dir/goup.xbm -command "scanp_move 1 -1"
    button $w.c2.down -bitmap @$guibase_dir/godown.xbm -command "scanp_move -1 -1"
    menubutton $w.c2.opts -text Opts -relief raised -borderwidth 2 \
	-menu $w.c2.opts.m
    if {[info exists ai_environment] && $ai_environment} {
        pack $w.c1.new $w.c1.delete $w.c1.clear $w.c1.done \
            -side left -fill both -expand 1
    } else {
        pack $w.on -side top -fill x -anchor w
        pack $w.c1.new $w.c1.delete $w.c1.clear \
            -side left -fill both -expand 1
    }
    pack $w.c2.how $w.c2.index $w.c2.up $w.c2.down $w.c2.opts \
	-side left -fill both -expand 1
    
    bind $w.c2.index <Return>
    
    set m $w.c2.how.m
    menu $m
    $m add command -label "Set I" -command "scanp_set_dir I $m"
    $m add command -label "Set J" -command "scanp_set_dir J $m"
    $m add command -label "Set K" -command "scanp_set_dir K $m"
    
    set m $w.c2.opts.m
    menu $m -tearoffcommand "disp_set_tearoff_name {Scan planes}"
    
    $m add radiobutton -label Wireframe \
	-variable scanp(shade) -value wire -command scanp_set_options
    $m add radiobutton -label Solid \
	-variable scanp(shade) -value solid -command scanp_set_options
    $m add radiobutton -label Solid/wire \
	-variable scanp(shade) -value flat_wire -command scanp_set_options
    $m add radiobutton -label "Hidden line" \
	-variable scanp(shade) -value hidden -command scanp_set_options
    $m add separator
    $m add checkbutton -label Extended -variable scanp(extended) \
	-command scanp_set_options
    $m add checkbutton -label "Show nodes" -variable scanp(draw_nodes) \
	-command scanp_set_options
    $m add checkbutton -label "Show IJK" -variable scanp(draw_ijk) \
	-command scanp_set_options
    $m add checkbutton -label "Show changes" -variable scanp(draw_changes) \
	-command scanp_set_options
    $m add command -label "Change color" -command scanp_set_color
    if {[info exists ai_environment] && $ai_environment} {
        pack $w.c1 $w.c2 $w.c3 -side top -fill both -expand 1
        if {$scanp_form != ".scanp"} {
            frame $w.c4; pack $w $w.c4 -side bottom -fill both -expand 1
        }
	ic_str_scanp_configure "" -visible 1
    }
}

proc scanp_change_visible {} {
    global scanp scanp_form
    
    if $scanp(visible) {
	pack $scanp_form.c1 $scanp_form.c2 $scanp_form.c3 -side top \
	    -fill both -expand 1
	ic_str_scanp_configure "" -visible 1
    } else {
	foreach i {c1 c2 c3} {
	    catch {pack forget $scanp_form.$i}
	}
	ic_str_scanp_configure "" -visible 0
    }
    update
    top_geometry .e -0+0
}

proc scanp_set_dir {d w} {
    global scanp
    
    array set dirs {I 0 J 1 K 2}
    set ijk $dirs($d)
    
    if {$scanp(cur) != ""} {
	set stuff [ic_str_scanp_move $scanp(cur) 0 -1]
	set dom [lindex $stuff 0]
	set ext [lindex $stuff 3]
	
	ic_str_scanp_set $scanp(cur) $dom $ijk 1 $ext ""
	scanp_update_window
	scanp_update_cur
    }
}

proc scanp_set_color {} {
    global scanp
    
    if {$scanp(cur) != ""} {
	set col [edit_one_color "Select the color for the scan plane." \
		     $scanp(color_type)]
	if {$col != ""} {
	    set scanp(color_type) $col
	    scanp_set_options
	    scanp_update_window
	}
    }
}

proc scanp_set_options {} {
    global scanp
    
    if {$scanp(cur) != ""} {
	ic_str_scanp_configure $scanp(cur) \
	    -shade $scanp(shade) \
	    -draw_nodes $scanp(draw_nodes) \
	    -draw_previous $scanp(draw_changes) \
	    -draw_ijk $scanp(draw_ijk) -color_type $scanp(color_type)
	ic_str_scanp_move $scanp(cur) 0 $scanp(extended)
    }
}

proc scanp_new {} {
    global scanp ai_environment
    
    for {set i 1} {[ic_str_scanp_exists scanp.$i]} {incr i} {}
    set scanp(new_name) scanp.$i
    set scanp(new_dom) 1
    set scanp(new_ijk) 0
    set scanp(new_ind) 1
    set scanp(new_ext) 0
    set scanp(new_color_type) white
    
    set d [form_init .scanp_new "New scan plane"]
    if {$d != ""} {
	form_label $d.namel Name {0 0}
	form_label $d.doml Domain {1 0}
	form_label $d.ijkl Plane {2 0}
	form_label $d.indl Index {3 0}
	form_entry $d.name scanp(new_name) string {0 1 -cols 2}
	form_entry $d.dom scanp(new_dom) int {1 1 -cols 2}
	form_button $d.doms Select scanp_select_domain {1 2 -cols 2}
	form_frame $d.ijk_f flat 0 {2 1 -cols 2 -sticky w}
	form_radiobutton $d.ijk_f.i I scanp(new_ijk) 0 {0 0}
	form_radiobutton $d.ijk_f.j J scanp(new_ijk) 1 {0 1}
	form_radiobutton $d.ijk_f.k K scanp(new_ijk) 2 {0 2}
	form_entry $d.ind scanp(new_ind) int {3 1 -cols 3}
	form_checkbutton $d.ext Extend scanp(new_ext) {4 0}
	if {![info exists ai_environment] || ($ai_environment == 0)} {
	    form_frame $d.colf flat 0 {4 1 -cols 2}
	    form_label $d.colf.l Color {0 0}
	    futil_colorentry $d.colf.e scanp(new_color_type) {0 1}
	}
	form_finish bot
    }
    if ![form_wait .scanp_new] return
    
    if {[ic_str_domain_dimension $scanp(new_dom)] != 3} {
	error "You can't create a scan plane in a 2-D domain."
    }
    ic_str_scanp_delete $scanp(new_name)
    
    ic_str_scanp_create $scanp(new_name) $scanp(new_color_type)
    ic_str_scanp_set $scanp(new_name) $scanp(new_dom) $scanp(new_ijk) \
	$scanp(new_ind) $scanp(new_ext) $scanp(new_color_type)
    set scanp(cur) $scanp(new_name)
    set scanp(color_type) $scanp(new_color_type)
    scanp_update_window
    scanp_update_cur
}

proc scanp_select_domain {} {
    global scanp
    
    set dom [select_struct_surf domain 1 item default]
    if {$dom == ""} return
    set scanp(new_dom) $dom
}

proc scanp_delete {} {
    global scanp
    
    if {$scanp(cur) == ""} return
    
    ic_str_scanp_delete $scanp(cur) 
    catch {unset scanp(prev)}
    set scanp(cur) [lindex [lsort [ic_str_scanp_list]] 0]
    scanp_update_cur
    scanp_update_window
}

proc scanp_clear {} {
    global scanp
    
    foreach sc [ic_str_scanp_list] {
	ic_str_scanp_delete $sc
    }
    catch {unset scanp(prev)}
    set scanp(cur) ""
    scanp_update_window
}

proc struct_disp_list_clear {} {
    global str_option

    set w .e.struct
    foreach ent {domain subface edge vertex} {
	set wn $w.${ent}_list.number
	if [winfo exists $wn] {
	    set str_option($ent,selnumber) 0
	    destroy $wn 
	}
	
	set wn $w.${ent}_list.domain
	if [winfo exists $wn] {
	    set str_option($ent,seldomain) 0
	    destroy $wn 
	}
    }
}

proc scanp_move {dir ext} {
    global scanp
    
    if [info exists scanp(cur)] {
        set xx [ic_str_scanp_move $scanp(cur) $dir $ext]
        foreach i {0 1 2 3} {
       	    set scanp([lindex {dom ijk ind ext} $i]) [lindex $xx $i]
        }
    }
}

proc scanp_update_window {} {
    global ai_environment scanp_form
    if {![info exists ai_environment] || ($ai_environment == 0)} {
        set w .e.struct.scanp.c3
    } else {
        if {$scanp_form == ".scanp"} {
            set w $scanp_form.main.c3
        } else {
            set w $scanp_form.c3
        }
    }
    set opts ""
    foreach s [lsort [ic_str_scanp_list]] {
	set col [lindex [ic_str_scanp_configure $s -color_type] end]
	if {($col == "white") || [string match \#f?f?f? $col]} { set col gray }
	lappend opts [list $s -command scanp_update_cur \
			  -foreground $col -selectbackground $col]
    }
    check_box $w $opts 4 scanp(cur) 0 scanp_update_cur
}

proc scanp_update_cur {} {
    global scanp
    
    if [info exists scanp(prev)] {
	unset scanp(prev)
    }
    if {$scanp(cur) == ""} {
	set scanp(ind) ""
	set scanp(how) ""
    } else {
	set scanp(prev) $scanp(cur)
	set stuff [ic_str_scanp_move $scanp(cur) 0 -1]
	set scanp(dom) [lindex $stuff 0]
	set scanp(ijk) [lindex $stuff 1]
	set scanp(ind) [lindex $stuff 2]
	set scanp(extended) [lindex $stuff 3]
	set scanp(how) [lindex {I J K} $scanp(ijk)]
	foreach x [ic_str_scanp_configure $scanp(cur)] {
	    set val([lindex $x 0]) [lindex $x 4]
	}
	foreach i {shade color_type draw_nodes draw_previous draw_ijk} {
	    set scanp($i) $val(-$i)
	}
    }
}
