
# Per-object parameters.

proc grid_edit_perobject_params {} {
    global grid_type grid_perobject_val grid_perobject_tree
    global grid_perobject_frame grid_perobject_now_selected
    
    if 0 {
	switch $grid_type {
	    tetra { grid_edit_tetra_perobject }
	    auto { grid_edit_perobject }
	}
	return
    }
    
    set buts [list [list Done "grid_edit_perobject_to_shape; form_done .perobject_params"] [list "Disable all" grid_perobject_disable_all]]
    
    form_kill .perobject_one ;# just in case this is up
    set d [form_init .perobject_params "Per-object meshing parameters" "" \
	       $buts "" 1 1 1]
    if {$d != ""} {
	set sw [ScrolledWindow $d.params]
	set sfw [ScrollableFrame $sw.f]
	$sw setwidget $sfw
	set grid_perobject_frame [$sfw getframe]
	frame $d.tree -relief flat -borderwidth 0
	set treef [tree_standalone_model_selection $d.tree "" \
		       "grid_edit_perobject_params_select" 32 16 1 \
		       grid_perobject_object_type]
	set grid_perobject_tree $d.tree
	pack $d.tree $d.params -side left -fill both -expand 1
	pack $treef -side left -fill both -expand 1
	
	form_finish bot
    }
    tree_standalone_model_populate $grid_perobject_tree 0 0 0 \
	grid_perobject_color
    
    foreach c [pack slaves $grid_perobject_frame] {
	pack forget $c
    }
    catch {unset grid_perobject_now_selected}
}

proc grid_perobject_color {obj} {
    if [string match shape* $obj] {
	set shapes $obj ;# not so elegant
    } else {
	set shapes [db_shapes $obj]
    }
    foreach sh $shapes {
	if [$sh cget -grid_enabled] {
	    return red
	}
    }
    return black
}

proc grid_perobject_object_type {obj} {
    if [$obj getval fix_shapes 0] {
	return [$obj getval obtype]
    }
    if [string match shape* $obj] {
	set sh $obj
    } else {
	set sh [db_shapes $obj 0]
    }
    if {$sh == ""} { return "" }
    return [grid_perobject_shape_type $sh]
}

proc grid_perobject_disable_all {} {
    global grid_perobject_tree grid_perobject_enabled
    
    set grid_perobject_enabled 0
    
    grid_edit_perobject_to_shape
    foreach obj [db_list_objects_recursive] {
	set sh [$obj getval body_shape]
	if {$sh != ""} {
	    $sh configure -grid_enabled 0
	    tree_standalone_text_color $grid_perobject_tree $obj black
	}
    }
}

proc grid_edit_perobject_one {what obj} {
    global grid_perobject_frame grid_perobject_now_selected grid_perobject_tree
    
    catch {unset grid_perobject_now_selected}
    catch {unset grid_perobject_tree}
    form_kill .perobject_one
    form_kill .perobject_params
    set grid_perobject_frame [form_init .perobject_one "Per-object parameters" "" \
				  {accept reset cancel}]
    grid_edit_perobject_params_select $what $obj 1
    form_finish bot
    if [form_wait .perobject_one] {
	grid_edit_perobject_params_select $what $obj 0
    }
}

proc grid_edit_perobject_params_select {what obj on} {
    global grid_type meshing_units grid_perobject_enabled
    global grid_perobject_for_shape_$grid_type grid_perobject_frame
    global grid_perobject_val grid_perobject_actual
    global grid_perobject_now_selected
    
    set frame $grid_perobject_frame
    
    set is_object 0
    
    switch $what {
	object {
	    if [$obj getval fix_shapes 0] {
		set tt [$obj getval obtype]
		set is_object 1
		set sh $obj
	    } else {
		set shapes [db_shapes $obj]
		if {[llength $shapes] != 1} return
		set sh [lindex $shapes 0]
	    }
	}
	shape {
	    set sh $obj
	    set obj [$sh get -object]
	}
    }
    
    #if {[$obj getval obtype] == "part"} return
    
    if !$on {
	grid_edit_perobject_to_shape $sh
	catch {unset grid_perobject_now_selected($sh)}
    } else {
	set grid_perobject_now_selected($sh) 1
    }
    
    set selected [array names grid_perobject_now_selected]
    if {$selected == ""} {
	foreach c [pack slaves $frame] {
	    pack forget $c
	}
	return
    }
    
    # here when the complex objects have different genuses OR subtypes, may need different grid params
    set ttlist  [grid_perobject_shape_type $sh]
    
    set tt [lindex $ttlist 0]
    if {[llength $selected] == 1} {
	grid_edit_perobject_from_shape $sh $tt
    }
    
    if {[lindex $ttlist 1] != ""} {
	set d $frame.$tt[lindex $ttlist 1]
    } else {
	set d $frame.$tt
    }
    

    if ![winfo exists $d] {
	frame $d -borderwidth 0 -relief flat
	
	set act grid_perobject_enabled
	
	form_checkbutton $d.enabled "Use per-object parameters" \
	    grid_perobject_enabled {0 0 -cols -}
	form_label_variable $d.unitslab grid_perobject_val(mesh_units_text) \
	    {1 0 -cols -}
	
	form_label $d.top1 Requested {2 1} $act
	if !$is_object {
	    form_label $d.top2 Actual {2 2} $act
	}
	
	set u $meshing_units
	
	set r 5
 	if [info exists grid_perobject_for_shape_${grid_type}($tt)] {
	    foreach p [set grid_perobject_for_shape_${grid_type}($tt)] {
		if {$p == ""} {
		    form_rowheight $d $r 10
		    incr r
		    continue
		}
		set ptype [lindex $p 1]; set n [lindex $p 2]
		set key $ptype,$n
		
		switch $ptype {
		    height { set dtype [list float_cmp ">0"] }
		    length { set dtype [list float_cmp ">0"] }
		    ratio  { set dtype [list float_cmp ">1"] }
		}
		
		form_checkbutton $d.l$r [lindex $p 0] grid_perobject_on($key) \
		    "$r 0" $act
		form_entry $d.e$r grid_perobject_val($key) $dtype "$r 1" \
		    [list $act grid_perobject_on($key)]
		if !$is_object {
		    form_entry $d.a$r grid_perobject_actual($key) float "$r 2"
		    $d.a$r configure -state disabled
		}
		incr r
	    }
	}
    }    
    foreach sl [pack slaves $frame] { pack forget $sl }
    pack $d -fill both -expand 1
}

proc grid_edit_perobject_from_shape {sh tt} {
    global grid_type meshing_units grid_perobject_enabled
    global grid_perobject_for_shape_$grid_type
    global grid_perobject_val grid_perobject_actual grid_perobject_on
    
    catch {unset grid_perobject_val}
    catch {unset grid_perobject_actual}
    set grid_perobject_val(mesh_units_text) "All units are $meshing_units"
    if [string match shape_* $sh] {
	set grid_perobject_enabled [$sh cget -grid_enabled]
    } else {
	set proc app_special_perobject_params_[$sh getval obtype]
	set grid_perobject_enabled [$proc get $sh enabled]
    }
    
    set u $meshing_units
    if [info exists grid_perobject_for_shape_${grid_type}($tt)] {
	foreach p [set grid_perobject_for_shape_${grid_type}($tt)] {
	    if {$p == ""} continue
	    set ptype [lindex $p 1]
	    set n [lindex $p 2]
	    if [string match shape_* $sh] {
		set rval [lindex [$sh get -grid_$ptype] $n]
		set aval [lindex [$sh get -grid_${ptype}_used] $n]
	    } else {
		set rval [app_special_perobject_params_$tt get $sh $ptype $n]
		set aval "" ;# for now
	    }
	    if {($rval == "") || ($rval == 0)} {
		set grid_perobject_on($ptype,$n) 0
		switch $ptype {
		    height { set grid_perobject_val($ptype,$n) 0 }
		    length { set grid_perobject_val($ptype,$n) 0 }
		    ratio  { set grid_perobject_val($ptype,$n) 2 }
		}
	    } else {
		set grid_perobject_on($ptype,$n) 1
		if {$ptype == "height"} {
		    set grid_perobject_val($ptype,$n) [unit_convert $rval $u 1]
		} else {
		    set grid_perobject_val($ptype,$n) $rval
		}
	    }
	    if {($ptype == "height") && ($aval != "")} {
		set aval [unit_convert $aval $u 1]
	    }
	    set grid_perobject_actual($ptype,$n) $aval
	}
    }
}

proc grid_edit_perobject_to_shape {{sh ""} {verbose 0}} {
    global grid_type meshing_units grid_perobject_enabled
    global grid_perobject_for_shape_$grid_type
    global grid_perobject_val grid_perobject_actual grid_perobject_on
    global grid_perobject_tree grid_perobject_now_selected
    
    if {$sh == ""} {
	busy 1
	set mess ""
	foreach sh [array names grid_perobject_now_selected] {
	    append mess [grid_edit_perobject_to_shape $sh 0]
	}
	busy 0
	mess $mess
	return
    }
    
    set u $meshing_units
    
    if [string match shape_* $sh] {
	if {[info command $sh] != ""} {
	    set enabled [$sh cget -grid_enabled]
	    $sh configure -grid_enabled $grid_perobject_enabled
	    set obj [$sh get -object]
	    
	    foreach ptype {length height ratio} {
		set req [$sh get -grid_$ptype]
		for {set i 0} {$i < [llength $req]} {incr i} {
		    set got_${ptype}($i) [lindex $req $i]
		}
	    }
	} else {
	    return ""   
	}
    } else {
	set obj $sh
	set obtype [$obj getval obtype]
	set proc app_special_perobject_params_$obtype
	set enabled [$proc get $sh enabled]
	$proc set $sh enabled $grid_perobject_enabled
	
	foreach ptype {length height ratio} {
	    for {set i 0} 1 {incr i} {
		set v [$proc get $obj $ptype $i]
		if {$v == ""} break
		set got_${ptype}($i) $v
	    }
	}
    }
    
    set changed 0
    if {$grid_perobject_enabled != $enabled} { set changed 1 }
    
    if [info exists grid_perobject_tree] {
	tree_standalone_text_color $grid_perobject_tree $obj \
	    [grid_perobject_color $obj]
	if {$obj != $sh} {
	    tree_standalone_text_color $grid_perobject_tree $sh \
		[grid_perobject_color $sh]
	}
    }
    
    foreach key [array names grid_perobject_val] {
	set xx [split $key ,]; set ptype [lindex $xx 0]; set n [lindex $xx 1]
	if {$n == ""} continue
	
	if {[info exists grid_perobject_on($key)] && \
		$grid_perobject_on($key)} {
	    if {$ptype == "height"} {
		set v [unit_convert $grid_perobject_val($key) $u 0]
	    } else {
		set v $grid_perobject_val($key)
	    }
	} else {
	    set v 0
	}
	set got_${ptype}($n) $v
    }
    
    if [string match shape_* $sh] {
	foreach ptype {length height ratio} {
	    set req ""
	    foreach n [lsort -integer [array names got_${ptype}]] {
		lappend req [set got_${ptype}($n)]
	    }
	    
	    if {$req != [$sh cget -grid_$ptype]} { set changed 1 }
	    $sh configure -grid_$ptype $req
	}
    } else {
	foreach ptype {length height ratio} {
	    foreach n [lsort -integer [array names got_${ptype}]] {
		if [$proc set $obj $ptype $n [set got_${ptype}($n)]] {
		    set changed 1
		}
	    }
	}
	app_clean_up_$obtype $obj
    }
    
    if $changed {
	set sub ""
	if {$sh != $obj} {
	    if {[$sh get -name] != "body"} { set sub " [$sh get -name]" }
	}
	set mm "Params modified for [$obj getval name]$sub\n"
	if $verbose { mess $mm }
	return $mm
    } else {
	return ""
    }
}

proc grid_perobject_shape_type {sh} {
    global grid_type domain
    global grid_perobject_for_shape_$grid_type
    global use_grid_grading app_has_special_perobject_shape_dependence
    
    set vn grid_perobject_for_shape_$grid_type

    if ![string match shape_* $sh] {
	set obj $sh
	set obtype [$obj getval obtype]
	set ${vn}($obtype) [app_special_perobject_params_$obtype list $obj]
	
	# this has been added since sometimes the grid params for complex 
	# objects depend not just on genus, but possibly on genus AND one 
	# or more shape subtypes (e.g. fans meshing params depend on genus 
	# and shtype_3d)
	
	if [info exists app_has_special_perobject_shape_dependence($obtype)] {
	    return [app_special_perobject_shape_dependence_$obtype $obj]
	} else {
	    return [list $obtype [$obj getval current_genus]]
	}
    }
    
    set obj [$sh get -object]
    
    set tt [lindex [split [$sh get -type] _] 1]
    set tp $tt
    switch $tt {
	quad {
	    append tt _[$sh getval plane]
	    if {[$obj getval obtype] == "wall"} {
		append tt _oneside
	    }
	}
	circ {
	    if {[$obj getval obtype] != "fan"} {
		append tt _nohub
	    }
	}
	incline {
	    append tt _[$sh getval axis]
	    if {[$sh si_value thickness] != 0} {
		append tt _thick
	    }
	}
	container {
	    if {[$obj getval obtype] == "domain"} { set tt hexa }
	}
	polygon {
	    set hgt [$sh si_value height]
	    if !$hgt { append tt _thin }
	    set n [$sh getval nverts]
	    append tt _$n
	    if ![info exists ${vn}($tt)] {
		set ll ""; set hh ""; set rr ""
		for {set i 0} {$i < $n} {incr i}  {
		    set i2 [expr {$i + 2}]
		    lappend ll [list "Side [expr $i + 1] count" length $i]
		    if $hgt {
			lappend hh [list "Side [expr $i + 1] height" height $i2]
			lappend rr [list "Side [expr $i + 1] ratio" ratio $i2]
		    }
		}
		if $hgt {
		    set ${vn}($tt) \
			[concat $ll [list [list "Height count" length $n]] {{}} \
			     [list [list "Bottom height" height 0] \
				  [list "Top height" height 1]] $hh {{}} \
			     [list [list "Bottom ratio" ratio 0] \
				  [list "Top ratio" ratio 1]] $rr]
		} else {
		    set ${vn}($tt) \
			[concat $ll {{}} \
			     [list [list "Bottom height" height 0] \
				  [list "Top height" height 1]] $hh {{}} \
			     [list [list "Bottom ratio" ratio 0] \
				  [list "Top ratio" ratio 1]] $rr]
		}
		if $use_grid_grading {
		    lappend ${vn}($tt) {} \
			[list "Grading height" height [expr $n + 2]] \
			[list "Grading ratio"  ratio  [expr $n + 2]]
		}
	    }
	}
    }
    if {$obj == $domain} { append tt _domain }
    return $tt
}

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

# Compound objects that don't have their own special parameters can use these.

proc app_special_perobject_params_generic_compound {what args} {
    global current_object model_data grid_type
    
    set lnames {x y z}
    set hnames {height}
    set rnames {ratio}
    
    switch $what {
	list {
	    switch $grid_type {
		auto {
		    return {
			{ "X element size"       length 0 }
			{ "Y element size"       length 1 }
			{ "Z element size"       length 2 }
			{ "Element height"       height 0 }
			{ "Element ratio"        ratio  0 }
		    }
		}
		tetra {
		    return {
			{ "Element size"         height 0 }
		    }
		}
		default { return "" }
	    }
	}
	get {
	    # Returns "" if there are not that many
	    set obj [lindex $args 0]
	    set ptype [lindex $args 1]
	    switch $ptype {
		enabled {
		    set pp enabled
		}
		length {
		    set n [lindex $args 2]
		    set pp [lindex $lnames $n]
		    if {$pp == ""} { return "" }
		}
		ratio {
		    set n [lindex $args 2]
		    set pp [lindex $rnames $n]
		    if {$pp == ""} { return "" }
		}
		height {
		    set n [lindex $args 2]
		    set pp [lindex $hnames $n]
		    if {$pp == ""} { return "" }
		}
	    }
	    
	    return [$obj getval grid_$pp]
	}
	set {
	    # Returns 1 if it was changed
	    set obj [lindex $args 0]
	    set ptype [lindex $args 1]
	    switch $ptype {
		enabled {
		    set val [lindex $args 2]
		    set pp enabled
		}
		length {
		    set n [lindex $args 2]
		    set val [lindex $args 3]
		    set pp [lindex $lnames $n]
		}
		ratio {
		    set n [lindex $args 2]
		    set val [lindex $args 3]
		    set pp [lindex $rnames $n]
		}
		height {
		    set n [lindex $args 2]
		    set val [lindex $args 3]
		    set pp [lindex $hnames $n]
		}
	    }
	    set oval [$obj getval grid_$pp]
	    if {$ptype != "enabled"} {
		if {[scan $val %g val] != 1} {
		    mess "Warning: bad value \"$val\"\n" red
		    return 0
		}
	    }
	    $obj setval grid_$pp $val
	    if {$obj == $current_object} {
		set model_data(grid_$pp) $val
	    }
	    return [string compare $val $oval]
	}
    }
}

# The clean up function must call this.

proc app_special_perobject_params_copy_to_shapes {obj} {
    # Now copy the meshing parameters to the shapes.
    if [$obj getval fix_shapes] {
	foreach sh [db_shapes $obj] {
	    $sh configure -grid_enabled [$obj getval grid_enabled]
	    set lens ""
	    foreach p {x y z} {
		set v [$obj getval grid_$p]
		if {$v > 0} {
		    lappend lens [expr [$sh getval dim_$p] / ($v + 0)]
		} else {
		    lappend lens 0
		}
	    }
	    set h [$obj getval grid_height]
	    set r [$obj getval grid_ratio]
	    $sh configure -grid_length $lens -grid_height "$h $h $h $h $h $h" \
		-grid_ratio "$r $r $r $r $r $r"
	}
    }
}

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

set grid_perobject_for_shape_auto(hexa_domain) {
    { "Low X height"  height 0 }
    { "High X height" height 1 }
    { "Low Y height"  height 2 }
    { "High Y height" height 3 }
    { "Low Z height"  height 4 }
    { "High Z height" height 5 }
    {}
    { "Low X ratio"   ratio  0 }
    { "High X ratio"  ratio  1 }
    { "Low Y ratio"   ratio  2 }
    { "High Y ratio"  ratio  3 }
    { "Low Z ratio"   ratio  4 }
    { "High Z ratio"  ratio  5 }
}

set grid_perobject_for_shape_tetra(hexa_domain) {
    { "Low X height"  height 0 }
    { "High X height" height 1 }
    { "Low Y height"  height 2 }
    { "High Y height" height 3 }
    { "Low Z height"  height 4 }
    { "High Z height" height 5 }
}

# This has to have both inward and outward parameters

set grid_perobject_for_shape_auto(container) {
    { "Outside X count"       length 0 }
    { "Outside Y count"       length 1 }
    { "Outside Z count"       length 2 }
    {}
    { "Outside low X height"  height 0 }
    { "Outside high X height" height 1 }
    { "Outside low Y height"  height 2 }
    { "Outside high Y height" height 3 }
    { "Outside low Z height"  height 4 }
    { "Outside high Z height" height 5 }
    {}
    { "Outside low X ratio"   ratio  0 }
    { "Outside high X ratio"  ratio  1 }
    { "Outside low Y ratio"   ratio  2 }
    { "Outside high Y ratio"  ratio  3 }
    { "Outside low Z ratio"   ratio  4 }
    { "Outside high Z ratio"  ratio  5 }
    {}
    { "Inside X max size"     length 3 }
    { "Inside Y max size"     length 4 }
    { "Inside Z max size"     length 5 }
    {}
    { "Inside low X height"   height 6 }
    { "Inside high X height"  height 7 }
    { "Inside low Y height"   height 8 }
    { "Inside high Y height"  height 9 }
    { "Inside low Z height"   height 10 }
    { "Inside high Z height"  height 11 }
    {}
    { "Inside low X ratio"    ratio  6 }
    { "Inside high X ratio"   ratio  7 }
    { "Inside low Y ratio"    ratio  8 }
    { "Inside high Y ratio"   ratio  9 }
    { "Inside low Z ratio"    ratio  10 }
    { "Inside high Z ratio"   ratio  11 }
}

set grid_perobject_for_shape_auto(hexa) {
    { "X count"       length 0 }
    { "Y count"       length 1 }
    { "Z count"       length 2 }
    {}
    { "Low X height"  height 0 }
    { "High X height" height 1 }
    { "Low Y height"  height 2 }
    { "High Y height" height 3 }
    { "Low Z height"  height 4 }
    { "High Z height" height 5 }
    {}
    { "Low X ratio"   ratio  0 }
    { "High X ratio"  ratio  1 }
    { "Low Y ratio"   ratio  2 }
    { "High Y ratio"  ratio  3 }
    { "Low Z ratio"   ratio  4 }
    { "High Z ratio"  ratio  5 }
    {}
    { "Inward height" height 6 1 }
    { "Inward ratio"  ratio  6 }
}

set grid_perobject_for_shape_tetra(hexa) {
    { "Low X height"  height 0 }
    { "High X height" height 1 }
    { "Low Y height"  height 2 }
    { "High Y height" height 3 }
    { "Low Z height"  height 4 }
    { "High Z height" height 5 }
}

if $use_grid_grading {
    lappend grid_perobject_for_shape_auto(hexa) {} \
	{ "Grading height" height 7 1 } \
	{ "Grading ratio"  ratio  7 }
}

set grid_perobject_for_shape_auto(sphere) {
    { "Curved surface size" height 0 }
    { "Flat (internal) surface size"  height 1 }
}

set grid_perobject_for_shape_tetra(sphere) {
    { "Curved surface size" height 0 }
    { "Flat (internal) surface size"  height 1 }
}

set grid_perobject_for_shape_auto(cyl) {
    {"Diameter count"  length 0}
    {"Side count"      length 1}
    {}
    {"Low end height"  height 0}
    {"High end height" height 1}
    {"Side height"     height 2}
    {"Inward height"   height 3 1 }
    {}
    {"Low end ratio"   ratio 0}
    {"High end ratio"  ratio 1}
    {"Side ratio"      ratio 2}
    {"Inward ratio"    ratio 3}
}

set grid_perobject_for_shape_tetra(cyl) {
    {"Low end height"  height 0}
    {"High end height" height 1}
    {"Side height"     height 2}
}

if $use_grid_grading {
    lappend grid_perobject_for_shape_auto(cyl) {} \
	{ "Grading height" height 4 1 } \
	{ "Grading ratio"  ratio  4 }
}

set grid_perobject_for_shape_auto(oval) {
    {"Low end height"  height 0}
    {"High end height" height 1}
    {"Side height"     height 2}
    {}
    {"Low end ratio"   ratio 0}
    {"High end ratio"  ratio 1}
    {"Side ratio"      ratio 2}
}

set grid_perobject_for_shape_tetra(oval) {
    {"Low end height"  height 0}
    {"High end height" height 1}
    {"Side height"     height 2}
}

set grid_perobject_for_shape_auto(circ) {
    {"Diameter count"  length 0}
    {}
    {"Low end height"  height 0}
    {"High end height" height 1 1 }
    {"Inward height"   height 2 1 }
    {"Outward height"  height 3 1 }
    {}
    {"Low end ratio"   ratio 0}
    {"High end ratio"  ratio 1}
    {"Inward ratio"    ratio 2}
    {"Outward ratio"   ratio 3}
}

set grid_perobject_for_shape_tetra(circ) {
    {"Element height"  height 0}
}

set grid_perobject_for_shape_auto(circ_nohub) {
    {"Diameter count"  length 0}
    {}
    {"Low end height"  height 0}
    {"High end height" height 1 1 }
    {"Inward height"   height 2 1 }
    {}
    {"Low end ratio"   ratio 0}
    {"High end ratio"  ratio 1}
    {"Inward ratio"    ratio 2}
}

set grid_perobject_for_shape_tetra(circ_nohub) {
    {"Element height"  height 0}
}

set grid_perobject_for_shape_auto(polygon_thin) {
    {"Element height"  height 0}
}

set grid_perobject_for_shape_tetra(polygon_thin) {
    {"Element height"  height 0}
}

set grid_perobject_for_shape_auto(quad_0) {
    {"Y count"         length 0}
    {"Z count"         length 1}
    {}
    {"Low end height"  height 0}
    {"High end height" height 1 1 }
    {"Inward height"   height 2 1 }
    {}
    {"Low end ratio"   ratio 0}
    {"High end ratio"  ratio 1}
    {"Inward ratio"    ratio 2}
}

set grid_perobject_for_shape_auto(quad_1) {
    {"X count"         length 1}
    {"Z count"         length 0}
    {}
    {"Low end height"  height 0}
    {"High end height" height 1 1 }
    {"Inward height"   height 2 1 }
    {}
    {"Low end ratio"   ratio 0}
    {"High end ratio"  ratio 1}
    {"Inward ratio"    ratio 2}
}

set grid_perobject_for_shape_auto(quad_2) {
    {"X count"         length 0}
    {"Y count"         length 1}
    {}
    {"Low end height"  height 0}
    {"High end height" height 1 1 }
    {"Inward height"   height 2 1 }
    {}
    {"Low end ratio"   ratio 0}
    {"High end ratio"  ratio 1}
    {"Inward ratio"    ratio 2}
}

set grid_perobject_for_shape_auto(quad_0_oneside) {
    {"Y count"         length 0}
    {"Z count"         length 1}
    {}
    {"Element height"  height 1}
    {"Inward height"   height 2 1 }
    {}
    {"Element ratio"   ratio 1}
    {"Inward ratio"    ratio 2}
}

set grid_perobject_for_shape_auto(quad_1_oneside) {
    {"X count"         length 1}
    {"Z count"         length 0}
    {}
    {"Element height"  height 1}
    {"Inward height"   height 2 1}
    {}
    {"Element ratio"   ratio 1}
    {"Inward ratio"    ratio 2}
}

set grid_perobject_for_shape_auto(quad_2_oneside) {
    {"X count"         length 0}
    {"Y count"         length 1}
    {}
    {"Element height"  height 1}
    {"Inward height"   height 2 1 }
    {}
    {"Element ratio"   ratio 1}
    {"Inward ratio"    ratio 2}
}

set grid_perobject_for_shape_auto(incline_0) {
    {"X count"         length 0}
    {"Y-Z count"       length 1}
    {}
    {"Low end height"  height 0}
    {"High end height" height 1 1 }
    {}
    {"Low end ratio"   ratio 0}
    {"High end ratio"  ratio 1}
}

set grid_perobject_for_shape_auto(incline_1) {
    {"Y count"         length 0}
    {"X-Z count"       length 1}
    {}
    {"Low end height"  height 0}
    {"High end height" height 1 1 }
    {}
    {"Low end ratio"   ratio 0}
    {"High end ratio"  ratio 1}
}

set grid_perobject_for_shape_auto(incline_2) {
    {"Z count"         length 0}
    {"X-Y count"       length 1}
    {}
    {"Low end height"  height 0}
    {"High end height" height 1 1 }
    {}
    {"Low end ratio"   ratio 0}
    {"High end ratio"  ratio 1}
}

foreach s {
    quad_0 quad_1 quad_2
    quad_0_oneside quad_1_oneside quad_2_oneside
    incline_0 incline_1 incline_2
    polygon_thin
} {
    set grid_perobject_for_shape_tetra($s) { {"Tetra size"  height 0} }
}

set grid_perobject_for_shape_auto(incline_0_thick) {
    {"X count"         length 0}
    {"Y-Z count"       length 1}
    {"Thickness count" length 2}
    {}
    {"Low end height"  height 0}
    {"High end height" height 1 1 }
    {}
    {"Low end ratio"   ratio 0}
    {"High end ratio"  ratio 1}
}

set grid_perobject_for_shape_auto(incline_1_thick) {
    {"Y count"         length 0}
    {"X-Z count"       length 1}
    {"Thickness count" length 2}
    {}
    {"Low end height"  height 0}
    {"High end height" height 1 1 }
    {}
    {"Low end ratio"   ratio 0}
    {"High end ratio"  ratio 1}
}

set grid_perobject_for_shape_auto(incline_2_thick) {
    {"Z count"         length 0}
    {"X-Y count"       length 1}
    {"Thickness count" length 2}
    {}
    {"Low end height"  height 0}
    {"High end height" height 1 1 }
    {}
    {"Low end ratio"   ratio 0}
    {"High end ratio"  ratio 1}
}

foreach s {
    incline_0_thick incline_1_thick incline_2_thick
} {
    set grid_perobject_for_shape_tetra($s) {
	{"Low end height"  height 0}
	{"High end height" height 1 1 }
    }
}

set grid_perobject_for_shape_tetra(cad) {
    {"Tetra size"      height 0}
}

set grid_perobject_for_shape_tetra(cyl_domain) {
    {"Tetra size"      height 0}
}

set grid_perobject_for_shape_tetra(pipe) {
    {"Tetra size"      height 0}
}

set grid_perobject_for_shape_auto(pipe) {
}

set grid_perobject_for_shape_auto(cad) {
}
