proc validateDepths {depth_from depth_to} {
set dt [$depth_to getCurrentValue]
set df [$depth_from getCurrentValue]
if [catch {
if {[expr $dt - $df] < 0.001} {
GuidoMessage warning DB_DTO_LT_DFROM
return false
}
} result] {
return false
}
return true
}
GuidoApp check_db "CHECK DATABASE CONNECTED"
$check_db setParam "databasesession" "GeologyDatabase"
set result [$check_db invoke]
$check_db destroy
if {$result == "0"} {
GuidoApp select "SELECT HOLE"
set databuf [ GuidoExecServer GetComposites {} ]
set status [GuidoGetParamBufferValue $databuf status]
if {$status >= 0} {
set num_composite_rows [GuidoGetParamBufferValue $databuf "num_composite_rows"]
} else {
set num_composite_rows 0
}
proc recalculate_composites {depth_from depth_to composite num_composite_rows hole_id} {
set dt [$depth_to getCurrentValue]
set df [$depth_from getCurrentValue]
if [catch {
if {[expr $dt - $df] < 0.001} {
for {set i 0} {$i < $num_composite_rows} {incr i} {
$composite setCurrentValue $i "-"
}
return
}
} result] {
for {set i 0} {$i < $num_composite_rows} {incr i} {
$composite setCurrentValue $i "-"
}
return
}
set compositedatabuf [ GuidoExecServer CalculateComposite [subst {hole_id = $hole_id depth_from = $df depth_to = $dt}]]
set status [GuidoGetParamBufferValue $compositedatabuf status]
if {$status >= 0} {
for {set i 0} {$i < $num_composite_rows} {incr i} {
$composite setCurrentValue $i [GuidoGetParamBufferValue $compositedatabuf "value($i)"]
}
} else {
for {set i 0} {$i < $num_composite_rows} {incr i} {
$composite setCurrentValue $i "-"
}
}
}
GuidoForm form {
-default_buttons
-defaults_management false
-label "Edit Composite"
-tip DB_COMPOSITE_EDIT_TIP
-layout CentreLineLayout
GuidoPanel main {
-layout CentreLineLayout
GuidoPanel left {
-layout CentreLineLayout
GuidoFiller filler1 {
-height 1
}
GuidoFiller filler2 {
-height 1
}
GuidoField depth_from_field {
-label "Depth from"
-display_length 12
-format double
-max_length 20
-null false
-decimals 3
-tip DB_COMPOSITE_EDIT_MIN_TIP
-validation {[validateDepths $depth_from_field $depth_to_field]}
-action keyReleased {[
set df [$depth_from_field getCurrentValue]
set dt [$depth_to_field getCurrentValue]
if [catch {
$width_field setCurrentValue "[format %.3f [expr $dt - $df]]"
} result] {
$width_field setCurrentValue "0.000"
}
if {$num_composite_rows > 0} {
recalculate_composites $depth_from_field $depth_to_field $composite $num_composite_rows $hole_id
}
]}
}
GuidoField depth_to_field {
-label "Depth to"
-display_length 12
-format double
-max_length 20
-null false
-decimals 3
-tip DB_COMPOSITE_EDIT_MAX_TIP
-validation {[validateDepths $depth_from_field $depth_to_field]}
-action keyReleased {[
set df [$depth_from_field getCurrentValue]
set dt [$depth_to_field getCurrentValue]
if [catch {
$width_field setCurrentValue "[format %.3f [expr $dt - $df]]"
} result] {
$width_field setCurrentValue "0.000"
}
if {$num_composite_rows > 0} {
recalculate_composites $depth_from_field $depth_to_field $composite $num_composite_rows $hole_id
}
]}
}
GuidoLabel width_label {
-label "Width"
}
GuidoLabel width_field {
-label "Width"
-display_length 12
}
GuidoField code_field {
-label "Code"
-display_length 12
-format string
-max_length 20
-null true
-tip DB_COMPOSITE_EDIT_CODE_TIP
}
GuidoFiller filler3 {
-height 1
}
GuidoFiller filler4 {
-height 1
}
}
if {$num_composite_rows > 0} {
GuidoScrollPane composite_values {
-label "Composite values"
-height 7
-border etched true
GuidoTable composite_values_table {
-instances 0 0 200
-interactive false
GuidoLabel composite_name {
-label "Name"
-width 10
}
GuidoLabel composite {
-label "Value"
-width 10
}
}
}
}
}
}
if {$status >= 0} {
if {$num_composite_rows > 0} {
$composite_values_table setInitialRows $num_composite_rows 0 200
for {set i 0} {$i < $num_composite_rows} {incr i} {
set tbl [GuidoGetParamBufferValue $databuf "tbl($i)"]
set fld [GuidoGetParamBufferValue $databuf "fld($i)"]
$composite_name setCurrentValue $i "$tbl / $fld"
}
}
}
set hole_id "-"
while {$hole_id > ""} {
$select setParam prompt "DB_SELECT_COMPOSITE"
$select setParam report "off"
$select setParam marker "off"
$select setParam single_click "true"
set result [$select invoke]
set buffer [ GuidoExecServer GetSelectedHoleId {} ]
set hole_id [ GuidoGetParamBufferValue $buffer hole_id ]
set depth [ GuidoGetParamBufferValue $buffer depth ]
if {$hole_id > ""} {
set databuf [ GuidoExecServer GetComposite [subst {hole_id = $hole_id depth = $depth } ] ]
set status [GuidoGetParamBufferValue $databuf status]
if {$status >= 0} {
set depth_from [GuidoGetParamBufferValue $databuf depth_from]
set depth_to [GuidoGetParamBufferValue $databuf depth_to]
set code [GuidoGetParamBufferValue $databuf code]
$depth_from_field setCurrentValue $depth_from
$depth_to_field setCurrentValue $depth_to
$width_field setCurrentValue "[format %.3f [expr $depth_to - $depth_from]]"
$code_field setCurrentValue $code
set depth [expr ($depth_to + $depth_from) / 2.0]
if {$num_composite_rows > 0} {
recalculate_composites $depth_from_field $depth_to_field $composite $num_composite_rows $hole_id
}
set return_code [$form interact]
if {$return_code == "apply"} {
GuidoApp deletecomposite "DELETE COMPOSITE"
$deletecomposite setParam hole_id $hole_id
$deletecomposite setParam depth $depth
$deletecomposite invoke
$deletecomposite destroy
GuidoApp createcomposite "CREATE COMPOSITE"
$createcomposite setParam hole_id $hole_id
$createcomposite setParam depth_from [$depth_from_field getCurrentValue]
$createcomposite setParam depth_to [$depth_to_field getCurrentValue]
$createcomposite setParam code [$code_field getCurrentValue]
$createcomposite invoke
$createcomposite destroy
}
}
set hole_id "-"
}
}
$select destroy
$form destroy
}
