# # Copyright 2004 (c) Pointwise, Inc. # All rights reserved. # # This sample Gridgen script is not supported by Pointwise, Inc. # It is provided freely for demonstration purposes only. # SEE THE WARRANTY DISCLAIMER AT THE BOTTOM OF THIS FILE. # # This script requires Glyph version 1.6.4 or higher # Ensure that the script is being executed such an environment package require PWI_Glyph 1.6.4 # Script wide error utility ###################################################################### ## PROC: ErrorMsg ## Error popup message ###################################################################### proc ErrorMsg {msg {title "Error"}} { global dialog_win tk_messageBox -message "$msg" -type ok -icon error -title $title if { [info exists dialog_win] } { after 20 {raise $dialog_win} } } # Globals # Element list, a container to store the state of all DB elements set elementList "" set initialColorList "" set enableColorPalette normal gg::tkLoad catch { set scriptDir [file dirname [info script]] source [file join $scriptDir pwiLogo.glf] } if { [catch { set calledFromExternalSouce TRUE source [file join $scriptDir ColorPalette.glf] } msg] } { ErrorMsg $msg "Could not find ColorPalette.glf." set enableColorPalette disabled } ###################################################################### ## PROC: layerColorClick ## Passes selected layers and picked color to setLayerGroupColor ###################################################################### proc layerColorClick { index } { setLayerGroupColor [gg::lmGetSelectedLayers] $index } ###################################################################### ## PROC: spawnGlobalColorPalette ## Spwans an instance of the global color pallette script ###################################################################### proc spawnGlobalColorPalette { } { if { [catch { initColorPaletteDefaults } msg] } { ErrorMsg "Failed to initialize color palette:\n$msg" } if { [catch { makeColorPaletteWindow [toplevel .globalColorPalette] } msg] } { if { $msg != \ "window name \"globalColorPalette\" already exists in parent" } { ErrorMsg "Failed to spawn color palette.\n$msg" } else { # if window exists, bring it to the front wm deiconify .globalColorPalette raise .globalColorPalette } # window exists } # catch } ###################################################################### ## PROC: saveAllColorState ## Saves all color state for DB elements ###################################################################### proc saveAllColorState {} { global elementList global initialColorList # Walk through list and save ALL color state # N.B. DB groups do not have a color state to preserve foreach element [gg::dbGetAll] { if { [ gg::dbQuery $element TYPE ] != "GROUP" } { # add the element to the list if it is applicable lappend elementList [ list $element [gg::dbDisp $element -linecolor] \ [gg::dbDisp $element -surfacecolor] ] } } # Preserve the initial color palette set initialColorList "" for {set i 0} { $i < 7 } { incr i } { lappend initialColorList [gg::dispColor $i] } } ###################################################################### ## PROC: restoreAllColorState ## Restores all color state for all DB elements to the saved value ###################################################################### proc restoreAllColorState {} { global elementList global initialColorList # First try to restore the colors to the originals catch { restoreDefaults allDefaults } # Walk through the stored list and reset all color state to the # stored value foreach element $elementList { gg::dbDisp [lindex $element 0] -linecolor [lindex $element 1] \ -surfacecolor [lindex $element 2] } # Restore original color settings for {set i 0} {$i < [llength $initialColorList]} {incr i} { gg::dispColor $i [lindex $initialColorList $i] } } ###################################################################### ## PROC: setLayerGroupColor ## Set all elements within a list of layer(s) to a given color index ###################################################################### proc setLayerGroupColor { layerList pendingColor } { # Quick escape if no layers are selected if { [llength $layerList] == 0 } { ErrorMsg "No layers selected" return } # Preserve current layer, so that it is possible to change the color # of layers without always setting the current set savedCurrentLayer [gg::dbLayerCurrent] # First save the current layer state. gg::dbLayerSetCreate setLayerColorPState # Set the current layer to one of the layers within the set # of layers that we want to change gg::dbLayerCurrent [lindex $layerList 0 ] # Now, disable the entire scene gg::dbLayerStatus ALL OFF # Next, enable only the layers needed foreach layer $layerList { gg::dbLayerStatus $layer ON } # Change the color for each db entity foreach element [gg::dbGetAll -active ON] { if { [ gg::dbQuery $element TYPE ] != "GROUP" } { gg::dbDisp $element -linecolor $pendingColor \ -surfacecolor $pendingColor } } # Restore current DB layer gg::dbLayerCurrent $savedCurrentLayer # Finally, restore the original layer state, # and delete the layer set that was created gg::dbLayerSetRestore setLayerColorPState gg::dbLayerSetDelete setLayerColorPState } ###################################################################### ## PROC: makeWindow ## Generate GUI ###################################################################### proc makeWindow {} { global enableColorPalette # Setup title and description set winName "" label $winName.title -text "Layer Color Manager" set font [$winName.title cget -font] $winName.title configure -font [font create -family [font actual $font -family] -weight bold] pack $winName.title -expand 1 -side top pack [ label $winName.description -text \ "Select layers within the layer manager and select a color to assign below" \ -anchor w ] -side top -fill x pack [frame $winName.hr1 -bd 1 -height 2 -relief sunken] -fill x -pady 2 # Create a main frame, and two child frames to hold the color swatches set parent $winName pack [frame $winName.content] -side top -fill x pack [frame $winName.left] -in $winName.content -side left -fill both \ -expand 1 pack [frame $winName.right] -in $winName.content -side right -fill both \ -expand 1 # Create the color swatch sub-sub frames foreach i {0 1 2 3 4 5 6} { frame $winName.colorChoice$i -borderwidth 1 -relief solid pack [label $winName.colorNumber$i -text "[expr $i+1]:"] -in \ $winName.colorChoice$i -side left pack [button $winName.colorSample$i -width 20 -command "layerColorClick $i"]\ -in $winName.colorChoice$i -padx 2 -pady 2 -fill both -side right -expand 1 # Setup color swatches $winName.colorSample$i configure -background [gg::dispColor $i] # Pack them into the left or right frame as appropriate if { $i > 3 } { pack $winName.colorChoice$i -in $winName.right -side top -ipadx 3 \ -padx 5 -pady 2 -fill x } else { pack $winName.colorChoice$i -in $winName.left -side top -ipadx 3 -padx 5 \ -pady 2 -fill x } } # Horizontal rulebar pack [frame $winName.hr2 -bd 1 -height 2 -relief sunken] -fill x -pady 2 # Setup and pack the buttons frame $winName.buttons pack [button $winName.buttons.exit -text "OK" -command { exit }] \ -side right -padx 3 pack [button $winName.buttons.reset -text "Reset All" \ -command {restoreAllColorState}] -side right -padx 3 pack [button $winName.buttons.dispInteract -text "Manipulate Model" \ -command { wm iconify .; gg::dispInteract; wm deiconify . } ] \ -side right -padx 3 pack [button $winName.buttons.colorpal -text "Display Global Color Palette" \ -command { spawnGlobalColorPalette } -state $enableColorPalette] \ -side right -padx 3 pack [button $winName.buttons.lm -text "Display Layer Manager" \ -command { gg::lmDisplayWindow }] -side right -padx 3 if {![catch {pwiLogoCreate $winName.buttons.logo 1} b]} { $b configure -bd 0 -relief flat pack $b -side left -padx 5 -fill y } pack $winName.buttons -fill x -side bottom -padx 2 -pady 1 } # Main execution # Preserve the initial state on entry saveAllColorState # Render our GUI window makeWindow # Bring up the Layer Manager gg::lmDisplayWindow # Put the GUI window up on the display ::tk::PlaceWindow . widget gg::tkLoop # # DISCLAIMER: # TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, POINTWISE DISCLAIMS # ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED # TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE, WITH REGARD TO THIS SCRIPT. TO THE MAXIMUM EXTENT PERMITTED # BY APPLICABLE LAW, IN NO EVENT SHALL POINTWISE BE LIABLE TO ANY PARTY # FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES # WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF # BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE # USE OF OR INABILITY TO USE THIS SCRIPT EVEN IF POINTWISE HAS BEEN # ADVISED OF THE POSSIBILITY OF SUCH DAMAGES AND REGARDLESS OF THE # FAULT OR NEGLIGENCE OF POINTWISE. #