
proc after_create_uns_stuff {} {
    global uns_cur ai_environment 

    set nf [$uns_cur check_new_families]
    foreach f $nf { add_new_family $f 1 }
}

proc display_quad_results {} {
    global batch_mode uns_type_visible uns_cur
    if {$batch_mode || ![ic_uns_is_loaded]} { return }
    after_create_uns_stuff
    # set new_fams to 1, since although the family will
    # exist via the geometry, we want the uns colors updated.
    set new_fams 1; #[expr {([llength $nf] > 0) ? 1 : 0}]
    set types "BAR_2 LINE_2 TRI_3 QUAD_4"
    display_update unstruct $new_fams $types
    update_uns_available
}

proc quad_uniquify_pairs {pairs} {
    set segs ""
    foreach ss $pairs {
        eval lappend segs $ss
    }
    foreach {i j} $segs {
        if {$i == $j} continue
        if {$i > $j} {
            set k $i
            set i $j
            set j $k
        }
        set "found($i $j)" 1
    }
    set ret ""
    foreach ff [array names found] {
        eval lappend ret $ff
    }
    return $ret
}

proc ic_quad_undo {what {big 0}} {
    if {$big == -1} return
    if {$what == "start"} {
        if {$big} {
            ic_start_bigunsop
        } else {
            ic_newop
            start_new_elems
        }
    } elseif {$what == "finish"} {
        if {$big} {
            ic_finish_bigunsop
        } else {
            finish_new_elems
        }
    } else {
        mess "Wrong argument in ic_quad_undo: what = \"$what\"\n" red
    }
}

proc ic_quad_type {{shape 0}} {
    if {$shape == 1} {
        set type QUAD_8
    } else {
        set type QUAD_4
    }
    return $type
}

proc ic_tri_type {{shape 0}} {
    if {$shape == 1} {
        set type TRI_6
    } else {
        set type TRI_3
    }
    return $type
}

proc ic_bar_type {{shape 0}} {
    if {$shape == 1} {
        set type BAR_3
    } else {
        set type BAR_2
    }
    return $type
}
