package require java
set buffer [GuidoExecServer LegacyGetCurrentDatabaseHandle [subst {sessionType = "GeologyDatabase" getBlastCompatibility = "true"}]]
set status [ GuidoGetParamBufferValue $buffer status ]
if {$status >= 0} {
set dbHandle [ GuidoGetParamBufferValue $buffer DatabaseHandle ]
} else {
set dbHandle "0"
}
set printing 0
set finalized 0
set formLabel "View / Edit Drillhole"
set databaseBlastSupport "false"
if { [ GuidoSSIOption get "invoked from blast function" ] == "true" } {
set databaseBlastSupport [ GuidoGetParamBufferValue $buffer BlastCompatible ]
if { $databaseBlastSupport == "true" } {
set formLabel "View Blasthole"
}
} else {
set rmc_field "undefined"
}
proc updateTableName {field_name table_name} {
if {[ $table_name getCurrentValue] == ""} {
$field_name removeAllItems
$field_name setCurrentValue ""
return 0
}
set val [$field_name getCurrentValue]
$field_name setTableHandle [$table_name getCurrentValue]
$field_name updateBrowserList
if {[string length $val] == 0} {
$field_name setCurrentValue [$field_name getItemAt 1]
} else {
$field_name setCurrentValue $val
}
return 1
}
set created_tabs ""
set created_tables ""
set created_fields ""
set created_field_handles ""
proc removeRow { table_name table_display_table} {
$table_display_table updateColumn $table_name
}
proc addTab {pending_edit_pane table_name table_display_table} {
global created_tabs
global created_tables
global created_fields
global created_field_handles
global dbHandle
set alreadyCreated [lsearch -exact $created_tabs $table_name]
if {$alreadyCreated < 0} {
lappend created_tabs $table_name
global "pending_table_$table_name"
GuidoPanel "$table_name" {
-layout BoxLayout Y_AXIS
GuidoScrollPane "pending_edits_$table_name" {
-height 24
-width 66
GuidoTable "pending_table_$table_name" {
-instances 0 0 200
-interactive false
-action stateChanged { [removeRow $table_name $table_display_table]}
}
}
}
$pending_edit_pane add [eval "\$$table_name getObject"]
upvar 0 "pending_table_$table_name" table
lappend created_tables $table
set buffer [GuidoExecServer TableFieldBrowser [subst {TableName = $table_name DatabaseHandle = $dbHandle}]]
set FieldNames [GuidoGetParamBufferValue $buffer FieldName]
for {set idx 0} {$idx < [llength $FieldNames]} {incr idx} {
set base_field_name [lindex $FieldNames $idx]
if {$base_field_name == "depth_from"} {
set field_name "$table_name[lindex $FieldNames $idx]"
global "$field_name"
GuidoLabel "$field_name" {
-height 1
-display_length 10
-label depth_from
-no_mlt
}
$table add [eval "\"\$$field_name\" getObject"]
lappend created_fields $field_name
lappend created_field_handles [eval "\"\$$field_name\" getObject"]
break
}
}
for {set idx 0} {$idx < [llength $FieldNames]} {incr idx} {
set base_field_name [lindex $FieldNames $idx]
if {$base_field_name == "depth_to"} {
set field_name "$table_name[lindex $FieldNames $idx]"
global "$field_name"
GuidoLabel "$field_name" {
-height 1
-display_length 10
-label depth_to
}
$table add [eval "\"\$$field_name\" getObject"]
lappend created_fields $field_name
lappend created_field_handles [eval "\"\$$field_name\" getObject"]
break
}
}
for {set idx 0} {$idx < [llength $FieldNames]} {incr idx} {
set base_field_name [lindex $FieldNames $idx]
if {$base_field_name == "depth_from" || $base_field_name == "depth_to"} {
continue
}
set buffer [GuidoExecServer IsFieldCalculated [subst {TableName = $table_name FieldName = $base_field_name}]]
set isCalculated [GuidoGetParamBufferValue $buffer isCalculated]
set field_name "$table_name[lindex $FieldNames $idx]"
if {$isCalculated == "false" && $base_field_name != "hole_id"} {
global "$field_name"
GuidoLabel "$field_name" {
-height 1
-display_length 10
-label $base_field_name
}
$table add [eval "\"\$$field_name\" getObject"]
lappend created_fields $field_name
lappend created_field_handles [eval "\"\$$field_name\" getObject"]
}
}
}
}
proc addColumn {table_display_table table_name field_name pending_edit_pane} {
if {$table_name != "" && $field_name != ""}  {
set buffer [ GuidoExecServer GetTableType [subst {table = $table_name}]]
set type [ GuidoGetParamBufferValue $buffer type ]
$table_display_table addColumn $table_name $field_name $type
addTab $pending_edit_pane $table_name $table_display_table
}
}
proc changeColumn {table_display_table table_name field_name pending_edit_pane} {
if {$table_name != "" && $field_name != ""} {
$table_display_table changeSelectedColumn $table_name $field_name
addTab $pending_edit_pane $table_name $table_display_table
}
}
proc initialize { form table_display_table blasthole_display field_name geology_table field_column value_column pending_edit_pane } {
global created_tabs
set created_tabs ""
global created_tables
set created_tables ""
global created_fields
set created_fields ""
global created_field_handles
set created_field_handles ""
global databaseBlastSupport
global formLabel
global finalized
set finalized 0
set val [$form readInputField "hole_id"]
$form setLabel "[GuidoMessage translate $formLabel]: $val"
$table_display_table setCurrentValue $val
set num_rows 5
if {$databaseBlastSupport == "true"} {
$blasthole_display setCurrentValue $val
incr num_rows
incr num_rows
}
$geology_table setInputAllowed false
$geology_table setInitialRows $num_rows
$field_column setCurrentValue 0 "hole_id"
$field_column setCurrentValue 1 "z"
$field_column setCurrentValue 2 "samp_id"
$field_column setCurrentValue 3 "depth_from"
$field_column setCurrentValue 4 "depth_to"
if {$databaseBlastSupport == "true"} {
$field_column setCurrentValue 5 "rock_class"
$field_column setCurrentValue 6 "subdrill"
}
$value_column setCurrentValue 0 $val
$value_column setCurrentValue 1 ""
$value_column setCurrentValue 2 ""
$value_column setCurrentValue 3 ""
$value_column setCurrentValue 4 ""
if {$val != ""} {
set buffer [ GuidoExecServer GetCollar [subst {hole_id = $val}] ]
set collar [ GuidoGetParamBufferValue $buffer COLLAR ]
$value_column setCurrentValue 1 [format "%.3f" $collar]
}
if {$databaseBlastSupport == "true" && $val != ""} {
set buffer [ GuidoExecServer GetBlastRMC [subst {hole_id = $val}] ]
set rmc [ GuidoGetParamBufferValue $buffer RMC ]
$value_column setCurrentValue 5 $rmc
set buffer [ GuidoExecServer GetBlastSubdrill [subst {hole_id = $val}] ]
set subdrill [ GuidoGetParamBufferValue $buffer subdrill ]
$value_column setCurrentValue 6 [format "%.3f" $subdrill]
}
set buffer [ GuidoExecServer GetFormValue [subst {function = "EDIT_HOLE" form = "View_edit_drillhole" field = "num_columns"}]]
set numColumns [ GuidoGetParamBufferValue $buffer value ]
if {$databaseBlastSupport == "true"} {
$blasthole_display addColumn "charge" "" 80 true "blasthole"
addTab $pending_edit_pane "charge" $table_display_table
}
if {$numColumns == ""} {
return
}
set numColumnsMinusOne $numColumns
incr numColumnsMinusOne  -1
for {set idx 0} {$idx < $numColumns} {incr idx} {
set buffer [GuidoExecServer GetFormValue [subst {function = "EDIT_HOLE" form = "View_edit_drillhole" field = "table$idx"}]]
set table [ GuidoGetParamBufferValue $buffer value ]
set buffer [GuidoExecServer GetFormValue [subst {function = "EDIT_HOLE" form = "View_edit_drillhole" field = "field$idx"}]]
set field [ GuidoGetParamBufferValue $buffer value ]
set buffer [GuidoExecServer GetFormValue [subst {function = "EDIT_HOLE" form = "View_edit_drillhole" field = "width$idx"}]]
set width [ GuidoGetParamBufferValue $buffer value ]
set buffer [GuidoExecServer GetFormValue [subst {function = "EDIT_HOLE" form = "View_edit_drillhole" field = "type$idx"}]]
set type [ GuidoGetParamBufferValue $buffer value ]
if {$idx == $numColumnsMinusOne} {
set updateLegend true
} else {
set updateLegend false
}
set buffer [GuidoExecServer ValidTableFieldPair [subst {TableName = $table FieldName = $field}]]
set status [ GuidoGetParamBufferValue $buffer status ]
if {$status >= 0} {
$table_display_table addColumn $table $field $width $updateLegend $type
addTab $pending_edit_pane $table $table_display_table
}
}
set buffer [GuidoExecServer GetHoleEdits {}]
set num_tables [ GuidoGetParamBufferValue $buffer num_tables ]
for {set idx 0} {$idx < $num_tables} {incr idx} {
set num_rows [ GuidoGetParamBufferValue $buffer num_rows_$idx ]
set num_columns [ GuidoGetParamBufferValue $buffer num_cols_$idx ]
set table "[ GuidoGetParamBufferValue $buffer "table_$idx" ]"
global "pending_table_$table"
upvar 0 "pending_table_$table" table_handle
$table_handle setInitialRows $num_rows 0 200
set depth_col 1
for {set col 0} {$col < $num_columns} {incr col} {
set field_name "[ GuidoGetParamBufferValue $buffer $table\_$col\_name ]"
if {$field_name == "depth_from"} {
set depth_col $col
break
}
}
for {set row 0} {$row < $num_rows} {incr row} {
for {set col 0} {$col < $num_columns} {incr col} {
set value "[ GuidoGetParamBufferValue $buffer $table\_$row\_$col ]"
set field_name "[ GuidoGetParamBufferValue $buffer $table\_$col\_name ]"
set modified_value "[ GuidoGetParamBufferValue $buffer $table\_$row\_$col\_modified ]"
set depth "[ GuidoGetParamBufferValue $buffer $table\_$row\_$depth_col ]"
if {$modified_value == "true"} {
java::call com.surpac.guido.GeologyTableHelper setModified $table $num_columns $depth $col
set field [string range $field_name [string length $table] end]
$table_display_table updatePattern $table $field $depth $value
if {$databaseBlastSupport == "true"} {
$blasthole_display updatePattern $table $field $depth $value
}
}
if [catch {
global "$field_name"
upvar 0 "$field_name" field_handle
$field_handle setCurrentValue $row $value
}] {}
}
}
}
}
proc finish { form table_display_table geology_panel} {
global printing
global finalized
if {!$finalized} {
if {[$geology_panel validateObject] } {
global created_tabs
global created_tables
global created_fields
global created_field_handles
set arg_list {}
set field_idx 0
set start_idx 0
set num_tables 0
for {set idx 0} {$idx < [llength $created_tables]} {incr idx} {
set table [lindex $created_tables $idx]
set table_name [lindex $created_tabs $idx]
if {[$table getRowCount] > 0} {
lappend arg_list "table($num_tables) = \"$table_name\""
lappend arg_list "table_nrows($num_tables) = \"[$table getRowCount]\""
lappend arg_list "table_ncols($num_tables) = \"[$table getColumnCount]\""
for {set row 0} {$row < [$table getRowCount]} {incr row} {
set field_idx $start_idx
for {set col 0} {$col < [$table getColumnCount]} {incr col} {
set field_name [string range [lindex $created_fields $field_idx] [string length $table_name] end]
set field_handle [lindex $created_field_handles $field_idx]
incr field_idx
if {$row == 0} {
lappend arg_list "$table_name\_field\($col\) = \"$field_name\""
}
set value [$field_handle getCurrentValue $row]
set modified "false"
if { [java::call com.surpac.guido.GeologyTableHelper isModified $table_name $row $col] } {
set modified "true"
}
lappend arg_list "$table_name\_$field_name\_modified\($row\) = \"$modified\""
lappend arg_list "$table_name\_$field_name\($row\) = \"$value\""
}
}
incr num_tables
}
incr start_idx [$table getColumnCount]
}
lappend arg_list "num_tables = \"$num_tables\""
set arg_list_string [join $arg_list]
GuidoExecServer SaveHoleEdits [subst { $arg_list_string } ]
if {$printing} {
$form writeOutputField "printing" 1
} else {
$form writeOutputField "printing" 0
}
GuidoExecServer SaveFormValue [subst {function_name = "EDIT_HOLE" form_name = "View_edit_drillhole" table = "" field_name = "num_columns" value = "[$table_display_table getColumnCount]"}]
for {set idx 0} {$idx < [$table_display_table getColumnCount]} {incr idx} {
GuidoExecServer SaveFormValue [subst {function_name = "EDIT_HOLE" form_name = "View_edit_drillhole" field_name = "table$idx" table = "" value = [$table_display_table getColumnTable $idx]}]
GuidoExecServer SaveFormValue [subst {function_name = "EDIT_HOLE" form_name = "View_edit_drillhole" field_name = "field$idx" table = "" value = [$table_display_table getColumnField $idx]}]
GuidoExecServer SaveFormValue [subst {function_name = "EDIT_HOLE" form_name = "View_edit_drillhole" field_name = "width$idx" table = "" value = [$table_display_table getColumnWidth $idx]}]
GuidoExecServer SaveFormValue [subst {function_name = "EDIT_HOLE" form_name = "View_edit_drillhole" field_name = "type$idx" table = "" value = [$table_display_table getColumnType $idx]}]
GuidoExecServer SaveFormValue [subst {function_name = "EDIT_HOLE" form_name = "View_edit_drillhole" field_name = "minimum$idx" table = "" value = [$table_display_table getColumnMinimum $idx]}]
GuidoExecServer SaveFormValue [subst {function_name = "EDIT_HOLE" form_name = "View_edit_drillhole" field_name = "maximum$idx" table = "" value = [$table_display_table getColumnMaximum $idx]}]
}
$form writeOutputField "num_columns" [$table_display_table getColumnCount]
for {set idx 0} {$idx < [$table_display_table getColumnCount]} {incr idx} {
$form writeOutputField "scroll_region($idx).table" [$table_display_table getColumnTable $idx]
$form writeOutputField "scroll_region($idx).field" [$table_display_table getColumnField $idx]
$form writeOutputField "scroll_region($idx).type" [$table_display_table getColumnType $idx]
$form writeOutputField "scroll_region($idx).minimum" [$table_display_table getColumnMinimum $idx]
$form writeOutputField "scroll_region($idx).maximum" [$table_display_table getColumnMaximum $idx]
}
$form finishedWritingFields
set finalized 1
}
}
}
proc saveFormData { form table_display_table geology_panel } {
global databaseBlastSupport
finish $form $table_display_table $geology_panel
if {$databaseBlastSupport == "true"} {
finish $form $form.blasthole_display $geology_panel
}
}
GuidoForm frm77001 {
-default_buttons
-label "$formLabel"
-layout BoxLayout Y_AXIS
-tip DB_EDIT_HOLE_FORM_TIP
-defaults_management true
GuidoTabbedPane tabbed_pane {
GuidoPanel Graphical_Editor {
-layout FlowLayout Left
-label "Graphical Editor"
GuidoPanel group_panel {
-layout BoxLayout Y_AXIS
GuidoPanel group_panel2 {
-layout FlowLayout Left
-height 28
GuidoPanel left_panel {
-layout BoxLayout Y_AXIS
-height 27
-label "Geology table"
-border etched true
if {$databaseBlastSupport == "true"} {
GuidoTabbedPane tabbed_pane2 {
-height 22
GuidoScrollPane blasthole_display_scrollpane {
-label Blasthole
-scroll_size 57 18
-height 22
-width 35
GeologyTable blasthole_display {
-label blasthole_display
-geology_legend legend_area
-table_editor table_name
-field_editor field_name
-instances 1 1 200
}
}
GuidoScrollPane leftblock1 {
-label Geology
-scroll_size 57 18
-height 22
-width 35
GeologyTable table_display_table {
-geology_legend legend_area
-table_editor table_name
-field_editor field_name
-instances 1 1 200
}
}
}
} else {
GuidoScrollPane leftblock1 {
-label Geology
-scroll_size 57 18
-height 22
-width 35
GeologyTable table_display_table {
-geology_legend legend_area
-table_editor table_name
-field_editor field_name
-instances 1 1 200
}
}
GeologyTable blasthole_display {
-height 0.0
}
}
GuidoFiller fill {
-height 0.2
}
GuidoPanel tbl_fld_panel {
-layout BoxLayout Y_AXIS
GuidoPanel tbl_fld_panel2 {
-layout CentreLineLayout
GuidoPanel tbl_fld_panel3 {
-layout CentreLineLayout
GuidoDatabaseTableBrowser table_name {
-label "Table"
-database dbHandle
-width 6
-table_types "interval | point"
-tip DB_EDIT_HOLE_TBLFLD_TIP
}
GuidoTableFieldBrowser field_name {
-label "Field"
-format string
-database dbHandle
-dependency {"[updateTableName $field_name $table_name]"}
-field_types optional
-width 6
-tip DB_EDIT_HOLE_TBLFLD_TIP
}
}
GuidoPanel tbl_fld_panel4 {
-layout BoxLayout Y_AXIS
GuidoButton Add {
-height 1
-width 7
-caption "Add"
-action valueChanged { [addColumn $table_display_table [$table_name getCurrentValue] [$field_name getCurrentValue] $pending_edit_pane]}
-selected_value "add"
-tip DB_EDIT_HOLE_TBLFLD_TIP
}
GuidoButton Change {
-height 1
-width 7
-caption "Modify"
-action valueChanged { [changeColumn $table_display_table [$table_name getCurrentValue] [$field_name getCurrentValue] $pending_edit_pane]}
-selected_value "change"
-input false
-tip DB_EDIT_HOLE_TBLFLD_TIP
}
}
}
}
}
GuidoPanel center_panel {
-layout BoxLayout Y_AXIS
-height 27
-width 23
GuidoPanel geology_table_panel {
-label "Mandatory fields"
-border etched true
GuidoTable geology_table {
-interactive false
-row_headings Field Value
GuidoField field_column {
-dependency 1
-display_length 6
-label "Field"
-format string
}
GuidoField value_column {
-dependency 1
-label "Value"
-display_length 10
-format string
}
}
}
GuidoPanel geology_fields_panel {
-label "Optional fields"
-border etched true
GuidoScrollPane geology_fields_pane {
-height 10
-width 21
GuidoPanel geology_panel {
-layout CentreLineLayout VERTICAL LEFT
}
}
}
GuidoPanel print_panel2 {
GuidoButton print {
-height 1
-caption "Print graphical log"
-selected_value "print"
-legacy_button
-action valueChanged {[
global printing
set printing 1
]}
}
}
}
GuidoPanel right_panel {
-layout BoxLayout Y_AXIS
-height 27
-label "Legend"
-border etched true
GuidoScrollPane legend_panel {
-height 25
-width 11
GeologyLegend legend_area { }
}
}
}
GuidoLabel rightClickInfoText {
-label "HOLE_EDIT_GRAPHICAL_TAB_TIP"
}
}
}
GuidoPanel Pending_Edits {
-label "Pending Edits"
-layout FlowLayout Left
GuidoTabbedPane pending_edit_pane {
}
}
}
$table_name updateBrowserList
$table_name setCurrentValue ""
$frm77001 legacyProcessValues false
-action initial {[initialize $frm77001 $table_display_table $blasthole_display $field_name $geology_table $field_column $value_column $pending_edit_pane]}
-action stateChanged {[ saveFormData $frm77001 $table_display_table $geology_panel]}
}
