
# The return values are:
# 0 skip
# 1 fill
# 2 blend
# 3 reintersect/trim
# 4 match
# 5 automatic
# 6 cancel
# 7 toggle partial option

proc tsf_pre_callback {edge_id1 edge_id2 edge_name1 edge_name2 dist partial} {
    global prev_tsf_stuff last_toler_max

    set debug 0
    set busy_last [busy reset]
    busy 0
    if {[info exists last_toler_max] && ([string is integer -strict $last_toler_max] || \
        [string is double -strict $last_toler_max]) && $last_toler_max > $dist} {
        set quiet 1
    } else {
        set quiet 0
    }
    if !$quiet {
        mess "Detected gap of distance $dist between curve $edge_name1 and curve $edge_name2.\n"
    }
    set prev_tsf_stuff "curve $edge_id1 curve $edge_id2"
    if {$partial} {
        set opt {n "no change" f fill b blend t trim m match a auto x cancel p "unset partial"}
    } else {
        set opt {n "no change" f fill b blend t trim m match a auto x cancel p "set partial"}
    }
    set status [present_geometry $prev_tsf_stuff "Option: " $opt]
    if {$debug} {
        mess "tsf_pre_callback: ic_show_geo_selected curve \"$edge_id1 $edge_id2\" 0\n" red
    }
    ic_show_geo_selected curve "$edge_id1 $edge_id2" 0
    busy $busy_last
    return $status
}

# The return values are:
# 0 accept
# 1 reject
# 2 retry

proc tsf_post_callback {mod_curves mod_surfs} {
    global prev_tsf_stuff

    set debug 0
    set busy_last [busy reset]
    busy 0
    set mod_obj $prev_tsf_stuff
    if {($mod_curves == "") && ($mod_surfs == "")} {
        update_bsp_consistency
    } else {
        # Be a bit smarter here
        update_bsp_consistency
        set mod_obj "$mod_curves $mod_surfs"
    }
    set status [present_geometry $mod_obj "Option: " {y yes n no r retry}]
    foreach {type num} $mod_obj {
        if {$debug} {
            mess "tsf_post_callback: ic_show_geo_selected \"$type $num\" 0\n" red
        }
        ic_show_geo_selected $type $num 0
    }
    busy $busy_last
    return $status
}

# The return values are:
# 0 accept
# 1 reject

proc tsf_mod_obj_callback {mod_obj} {
    set busy_last [busy reset]
    busy 0
    update_bsp_consistency
    set status [present_geometry $mod_obj "Option: " {y yes n no}]
    busy $busy_last
    return $status
}

# The return values are:
# 0 accept
# 1 skip
# 2 all
# 3 cancel

proc tsf_fill_hole_callback {mod_obj} {
    set busy_last [busy reset]
    busy 0
    clear_geom_objects
    define_geom_objects
    set status [present_geometry $mod_obj "Option: " {y yes n no a all x cancel}]
    busy $busy_last
    return $status
}

# The return values are:
# 0 compress
# 1 skip
# 2 toggle partial option
# (3 delete)
# (4 cancel)

proc tsf_midsurface_callback {{mod_obj} all partial alternate} {
    set busy_last [busy reset]
    busy 0

    set opt {y compress n no p}

    set p {partial}
    switch $partial {
	   3 {set p {non-partial}}
	   1 {set p {double partial}}
    }
    lappend opt $p

    if {$alternate == "0"} {
	set a {surface 1}
    } else {
	set a {surface 2}
    }
    lappend opt a $a

    if {$all} {
	lappend opt d delete x cancel
    } 

    set n [lindex $mod_obj end]
    set midsurface "surface"
    lappend midsurface $n
    set status [present_geometry $mod_obj "Option: " $opt $midsurface]

    busy $busy_last
    return $status
}

# The return values are:
# 0 compress
# 1 skip
# 2 delete
# 3 cancel

proc tsf_midsurface_old_callback {mod_obj} {
    set busy_last [busy reset]
    busy 0
    set status [present_geometry $mod_obj "Option: " {y compress n no d delete x cancel}]
    busy $busy_last
    return $status
}
