GuidoScript scripts/geologyutilities.tcl
set flag 0
proc getDatabaseHandle {} {
set buffer [GuidoExecServer LegacyGetCurrentDatabaseHandle [subst {sessionType = "GeologyDatabase"}]]
return [GuidoGetParamBufferValue $buffer DatabaseHandle]
}
proc fieldExistsInTable {table_handle field_handle field_name} {
set numberOfRows [$table_handle getRowCount]
for {set row 0} {$row < $numberOfRows} {incr row} {
set fieldName [$field_handle getCurrentValue $row]
if {$fieldName == $field_name} {
return 0
}
}
return 1
}
proc updateAvailableFieldInfo {dbHandle tableName availableField availableFieldTable selectedField selectedFieldTable} {
set table_name [$tableName getCurrentValue]
set buffer [GuidoExecServer TableFieldBrowser [subst {TableName = $table_name DatabaseHandle = $dbHandle}]]
set FieldNames [GuidoGetParamBufferValue $buffer FieldName]
$availableFieldTable setInitialRows [llength $FieldNames] 0 [llength $FieldNames]
set jdx 0
for {set idx 0} {$idx < [llength $FieldNames]} {incr idx} {
set field_name [lindex $FieldNames $idx]
set buffer1 [GuidoExecServer GetFieldInformation [subst {DatabaseType = "GeologyDatabase" SurpacTableName = "$table_name" SurpacFieldName = $field_name}]]
set FieldType [GuidoGetParamBufferValue $buffer1 FieldType]
if {$FieldType == "real" || $FieldType == "integer"} {
if {[fieldExistsInTable $selectedFieldTable $selectedField $field_name] == 1} {
$availableField setCurrentValue $jdx $field_name
incr jdx
}
}
}
$availableFieldTable setInitialRows $jdx 0 $jdx
}
proc populateAvailableFieldPanel {dbHandle tableName availableField availableFieldTable selectedField selectedFieldTable nextButton} {
global flag
if {$flag > 2} {
for {set row [expr "[$selectedFieldTable getRowCount]" - 1] } {$row >= 0} {incr row -1} {
$selectedFieldTable removeRow $row
}
}
incr flag 1
set table_name [$tableName getCurrentValue]
set buffer [GuidoExecServer TableFieldBrowser [subst {TableName = $table_name DatabaseHandle = $dbHandle}]]
set FieldNames [GuidoGetParamBufferValue $buffer FieldName]
set availableFieldTableSize [llength $FieldNames]
$availableFieldTable setInitialRows $availableFieldTableSize 0 200
set jdx 0
for {set idx 0} {$idx < [llength $FieldNames]} {incr idx} {
set field_name [lindex $FieldNames $idx]
set buffer1 [GuidoExecServer GetFieldInformation [subst {DatabaseType = "GeologyDatabase" SurpacTableName = "$table_name" SurpacFieldName = $field_name}]]
set FieldType [GuidoGetParamBufferValue $buffer1 FieldType]
if {$FieldType == "real" || $FieldType == "integer"} {
if {[fieldExistsInTable $selectedFieldTable $selectedField $field_name] == 1} {
$availableField setCurrentValue $jdx $field_name
incr jdx
}
}
}
$availableFieldTable setInitialRows $jdx 0 200
if {[$selectedFieldTable getRowCount] > 0} {
$nextButton setInputAllowed true
} else {
$nextButton setInputAllowed false
}
}
proc populateSelectedFieldTable {table availableFieldTable availableField selectedFieldTable selectedField nextButton} {
set idx [$availableFieldTable getEditingRow]
if {$idx < [$availableFieldTable getRowCount]} {
set fieldToBeAdded [$availableField getCurrentValue]
if {$fieldToBeAdded != ""} {
set fieldExists "[validateTableFieldPair $table $availableField]"
if {$fieldExists == "true"} {
if {[fieldExistsInTable $selectedFieldTable $selectedField $fieldToBeAdded] == 1} {
$selectedFieldTable addRows 1
set rowCount [$selectedFieldTable getRowCount]
set rowToBeUpdated [expr $rowCount - 1]
$selectedField setCurrentValue $rowToBeUpdated [$availableField getCurrentValue]
$availableFieldTable removeRow $idx
$availableFieldTable setInitialRows [$availableFieldTable getRowCount] 0 [$availableFieldTable getRowCount]
}
}
}
}
if {[$selectedFieldTable getRowCount] > 0} {
$nextButton setInputAllowed true
} else {
$nextButton setInputAllowed false
}
}
proc removeFieldFromSelectedFieldTable {table availableFieldTable availableField selectedFieldTable selectedField nextButton} {
set idx [$selectedFieldTable getEditingRow]
$selectedFieldTable removeRow $idx
$availableFieldTable setInitialRows [$selectedFieldTable getRowCount] 0 [$selectedFieldTable getRowCount]
set databaseHandle [getDatabaseHandle]
updateAvailableFieldInfo $databaseHandle $table $availableField $availableFieldTable $selectedField $selectedFieldTable
if {[$selectedFieldTable getRowCount] > 0} {
$nextButton setInputAllowed true
} else {
$nextButton setInputAllowed false
}
}
GuidoForm frmRRMSelectSampleData {
-label "Select sample data"
-layout BoxLayout Y_AXIS
-help_id 1712
GuidoPanel MainPanel {
-layout BoxLayout Y_AXIS
GuidoFiller filler_22 {
-height 1
}
GuidoPanel Panel_1 {
-layout BoxLayout X_AXIS
GuidoFiller filler_222 {
-width 5
}
GuidoLabel label1 {
-font_style bold
-label "Select the table and fields from which to select the sample data"
}
}
GuidoFiller filler_1 {
-height 1
}
GuidoPanel Panel_2 {
-layout BoxLayout X_AXIS
set databaseHandle [getDatabaseHandle]
GuidoDatabaseTableBrowser table {
-null false
-format none
-database_handle $databaseHandle
-table_types "interval | point"
-translate lower
-tip "00060_TIP_0"
-label "Table name"
}
$table updateBrowserList
}
GuidoFiller filler_2 {
-height 1
}
GuidoPanel Panel_3 {
-layout BoxLayout X_AXIS
GuidoPanel Panel_4 {
-layout CentreLineLayout
GuidoScrollPane scroll_1 {
-height 22
-width 16.5
GuidoTable availableFieldTable {
-instances 1 1 100
-interactive false
GuidoField availableField {
-display_length 12
-format none
-menu_enabled false
-input false
-tip "DYNAMIC_SHELLS_TIP_002"
-label "Available fields"
-max_length 32
}
}
}
}
GuidoPanel Panel_5 {
-layout BoxLayout Y_AXIS
GuidoFiller filler_3 {
-height 8
}
GuidoPanel Panel_6 {
-layout CentreLineLayout
GuidoButton addButton {
-display_length 10
-icon "icons/RightArrow.gif"
-caption "Add"
}
}
GuidoPanel Panel_7 {
-layout CentreLineLayout
GuidoButton removeButton {
-display_length 10
-icon "icons/LeftArrow.gif"
-caption "Remove"
}
}
}
GuidoPanel Panel_8 {
-layout CentreLineLayout
GuidoScrollPane scroll_2 {
-height 22
-width 17
GuidoTable selectedFieldTable {
-instances 0 0 100
-interactive false
GuidoField selectedField {
-display_length 15
-format none
-input false
-menu_enabled false
-tip "DYNAMIC_SHELLS_TIP_003"
-label "Selected fields"
-max_length 32
}
}
}
}
}
GuidoFiller filler14 {
-height 1
}
GuidoPanel negativeSamplePanel {
-layout BoxLayout X_AXIS
GuidoCheckBox ignoreNegativeSamples {
-default false
-selected_value Y
-unselected_value N
-tip "DYNAMIC_SHELLS_TIP_004"
}
GuidoLabel ignore_negative_sample_label {
-label "Ignore negative samples"
}
}
GuidoPanel buttonPanel {
-layout FlowLayout Left
GuidoButton helpButton {
-action valueChanged { [$frmRRMSelectSampleData setStatus "help"] }
-icon "icons/16/help.png"
-caption " "
}
GuidoFiller filler12 {
-width 24
}
GuidoButton nextButton {
-action valueChanged { [$frmRRMSelectSampleData setStatus "next"] }
-display_length 8
-icon "icons/RightArrow.gif"
-caption "Next"
}
GuidoButton cancelButton {
-action valueChanged { [$frmRRMSelectSampleData setStatus "cancel"] }
-display_length 9
-icon "icons/cancel.png"
-caption "Cancel"
}
}
$frmRRMSelectSampleData setActionCallback initial {[populateAvailableFieldPanel $databaseHandle $table $availableField $availableFieldTable $selectedField $selectedFieldTable $nextButton]}
$table setActionCallback valueChanged {[populateAvailableFieldPanel $databaseHandle $table $availableField $availableFieldTable $selectedField $selectedFieldTable $nextButton]}
$addButton setActionCallback valueChanged {[populateSelectedFieldTable $table $availableFieldTable $availableField $selectedFieldTable $selectedField $nextButton]}
$removeButton setActionCallback valueChanged {[removeFieldFromSelectedFieldTable $table $availableFieldTable $availableField $selectedFieldTable $selectedField $nextButton]}
}
$frmRRMSelectSampleData setNextFocusableComponentName addButton
}
