# # 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. # package require PWI_Glyph 1.6.4 package require PWIUTIL 1.0 gg::tkLoad global file_name proc getTempDir { } { global tcl_platform global env # Build up a list of possible directories to write to set dirs [pwd] if {[info exists env(TEMP)]} { lappend dirs $env(TEMP) } if {[info exists env(TMP)]} { lappend dirs $env(TMP) } if {[info exists env(TMPDIR)]} { lappend dirs $env(TMPDIR) } if {[string equal $tcl_platform(platform) "windows"]} { if {[info exists env(USERPROFILE)]} { lappend dirs $env(USERPROFILE) } } else { lappend dirs "/tmp" lappend dirs "/usr/tmp" } if {[info exists env(HOME)]} { lappend dirs $env(HOME) } foreach dir $dirs { if {[file writable $dir]} { return $dir } } error "No writable temporary directory could be found." } set EntityTypes { Surfaces "Trimmed Surfaces" Curves Points Notes Planes } set EntityDisplay { Shaded "Shaded/Wire" Solid "Solid/Wire" "Hidden Line"} set file_name [PWIUTIL::getTempName \ [file join [getTempDir] "DBViewData"] ".dbv"] set file [open $file_name w] foreach dbe [gg::dbGetAll] { puts -nonewline $file "gg::dbDisp $dbe -linecolor [gg::dbDisp $dbe -linecolor] -surfacecolor [gg::dbDisp $dbe -surfacecolor] -density [gg::dbDisp $dbe -density]" # puts -nonewline "gg::dbDisp $dbe -linecolor [gg::dbDisp $dbe -linecolor] -surfacecolor [gg::dbDisp $dbe -surfacecolor] -density [gg::dbDisp $dbe -density]" catch { gg::dbDisp $dbe -linecolor puts -nonewline $file " -style [gg::dbDisp $dbe -style]" # puts -nonewline " -style [gg::dbDisp $dbe -style]" } if {[gg::dbDisp $dbe -outline] == 1} { puts $file " -outline TRUE" # puts " -outline TRUE" } elseif {[gg::dbDisp $dbe -intervals] == 1} { puts $file " -intervals TRUE" # puts " -intervals TRUE" } elseif {[gg::dbDisp $dbe -triangles] != 0} { puts $file " -triangles [gg::dbDisp $dbe -triangles]" # puts " -triangles [gg::dbDisp $dbe -triangles]" } elseif {[lindex [lindex [gg::dbDisp $dbe -isolines] 0] 0] >= 2 && \ [lindex [lindex [gg::dbDisp $dbe -isolines] 0] 1] >= 2} { puts $file " -isolines [gg::dbDisp $dbe -isolines]" # puts " -isolines [gg::dbDisp $dbe -isolines]" } else { puts $file "" # puts "" } } close $file catch { source [file join [file dirname [info script]] pwiLogo.glf] } set dbTypes {CIRCLE CONIC COPIUS PLANE LINE PCURVE PSURFACE POINT RULEDSURF SURFREVO TABCYL BCURVE BSURFACE OFFSURF OFFCURV BOUNDSURF TRIMSURF NOTE GROUP NAME SUBFIG_INST SHELL BSURFACE_COONS BSURFACE_AUTOCOONS} foreach t $dbTypes { set type$t 0 } set typeCurve 0 set typeSurface 0 set layerStatus ASIS set layerName 0 set layerNameValue {} set displayDisplay ASIS set displaySolid 0 set displayLine 0 set displaySolidColor 1 set displayLineColor 1 set renderRender ASIS proc cleanup { } { global file_name catch {file delete $file_name} exit } proc revertView { } { global file_name catch { source $file_name } } proc process { } { global renderRender renderIsolineValue renderTriangleValue if {[string compare $renderRender ISOLINES] == 0} { if {[validateIso "focus" $renderIsolineValue] == 0} { tk_dialog .diag "Invalid Isoline Value" "The isoline render value ($renderIsolineValue) is not a valid value for this field. It should be a set of two numbers separated by a space with no leading or trailing space." "" 0 OK return; } } elseif {[string compare $renderRender TRIANGLES] == 0} { if {[validateTri "focus" $renderTriangleValue] == 0} { tk_dialog .diag "Invalid Triangle Value" "The isoline render value ($renderTriangleValue) is not a valid value for this field. It should be a single number with no leading or trailing space." "" 0 OK return; } } set l [getList] if {$l != {} && $l != ""} { applyDisplay $l applyLayer $l applyRender $l } else { tk_dialog .diag "No Entities Selected" "No entities of the selected type(s) exist in visible layers." "" 0 OK } } proc getList { } { set on {} foreach t {CIRCLE CONIC COPIUS PLANE LINE PCURVE PSURFACE POINT RULEDSURF \ SURFREVO TABCYL BCURVE BSURFACE OFFSURF OFFCURV BOUNDSURF TRIMSURF NOTE \ GROUP SHELL} { global type$t 0 if { [set type$t] } { lappend on $t } } set l {} foreach db [gg::dbGetAll] { if { [lsearch $on [gg::dbQuery $db TYPE]] != -1 } { lappend l $db } } return $l } ###################################################################### # PROC: CreateLabelFrame # Creates a fancy label frame widget # Returns the new frame # proc CreateLabelFrame {w args} { #-- strip extraneous '.'s in window name set w [string trim $w "."] set w ".$w" frame $w -bd 0 label $w.l frame $w.f -bd 2 -relief groove frame $w.f.spc -height 5 pack $w.f.spc frame $w.f.f pack $w.f.f set text {} set font {} set padx 3 set pady 7 set ipadx 2 set ipady 9 set ipady 5 foreach {tag value} $args { switch -- $tag { -font {set font $value} -text {set text $value} -padx {set padx $value} -pady {set pady $value} -ipadx {set ipadx $value} -ipady {set ipady $value} -bd {$w.f config -bd $value} -relief {$w.f config -relief $value} } } if {"$font"!=""} { $w.l config -font $font } $w.l config -text $text pack $w.f -padx $padx -pady $pady -fill both -expand 1 place $w.l -x [expr $padx+10] -y $pady -anchor w pack $w.f.f -padx $ipadx -pady $ipady -fill both -expand 1 raise $w.l return $w.f.f } proc applyDisplay { l } { global displayDisplay displaySolid displayLine displaySolidColor global displayLineColor if {$displayDisplay != "ASIS" && $displayLine && $displaySolid} { gg::dbDisp $l -style $displayDisplay \ -linecolor [expr {$displayLineColor - 1}] \ -surfacecolor [expr {$displaySolidColor - 1}] } if {$displayDisplay == "ASIS" && $displayLine && $displaySolid} { gg::dbDisp $l -linecolor [expr {$displayLineColor - 1}] \ -surfacecolor [expr {$displaySolidColor - 1}] } if {$displayDisplay == "ASIS" && $displayLine == 0 && $displaySolid} { gg::dbDisp $l -surfacecolor [expr {$displaySolidColor - 1}] } if {$displayDisplay != "ASIS" && $displayLine == 0 && $displaySolid} { gg::dbDisp $l -style $displayDisplay \ -surfacecolor [expr {$displaySolidColor - 1}] } if {$displayDisplay != "ASIS" && $displayLine && $displaySolid == 0} { gg::dbDisp $l -style $displayDisplay \ -linecolor [expr {$displayLineColor - 1}] } if {$displayDisplay == "ASIS" && $displayLine && $displaySolid == 0} { gg::dbDisp $l -linecolor [expr {$displayLineColor - 1}] } if {$displayDisplay != "ASIS" && $displayLine==0 && $displaySolid == 0} { gg::dbDisp $l -style $displayDisplay } } proc applyLayer { l } { global layerStatus layerName layerNameValue if { $layerName == 1 && $layerNameValue != "" } { gg::dbLayerAssignEntity $layerNameValue $l } if { $layerStatus == "ENABLE" } { gg::dbEnable $l 1 } if { $layerStatus == "DISABLE" } { gg::dbEnable $l 0 } } proc applyRender { l } { global renderRender renderTriangleValue renderIsolineValue if { $renderRender == "ISOLINES" } { gg::dbDisp $l -isolines $renderIsolineValue } else { if { $renderRender == "OUTLINE" } { gg::dbDisp $l -outline 1 } else { if { $renderRender == "INTERVALS" } { gg::dbDisp $l -intervals 1 } else { if { $renderRender == "TRIANGLES" } { gg::dbDisp $l -triangles $renderTriangleValue } } } } } proc setCurve { } { global typeCurve foreach t {PCURVE CONIC CIRCLE BCURVE LINE OFFCURV} { global type$t set type$t $typeCurve } } proc setSurface { } { global typeSurface foreach t {PSURFACE BSURFACE RULEDSURF SURFREVO TRIMSURF SHELL TABCYL BOUNDSURF OFFSURF} { global type$t set type$t $typeSurface } } proc clear { } { foreach t {Curve Surface CIRCLE CONIC COPIUS PLANE LINE PCURVE PSURFACE POINT RULEDSURF SURFREVO TABCYL BCURVE BSURFACE OFFSURF OFFCURV BOUNDSURF TRIMSURF NOTE GROUP SHELL} { global type$t set type$t 0 } global layerStatus layerName layerNameValue displayDisplay displayLine displaySolid displaySolidColor displayLineColor renderRender set layerStatus ASIS; set layerName 0; set layerNameValue {} set displayDisplay ASIS; set displaySolid 0; set displayLine 0; set displaySolidColor 1; set displayLineColor 1 set renderRender ASIS } proc validateIso { type val } { global renderRender renderIsolineValue frmRender if { $renderRender == "ISOLINES" } { set d1 -1 set d2 -1 if { [scan $val {%d %d} d1 d2] == 2 && $d1 >= 2 && $d2 >= 2 } { $frmRender.isoin configure -background #FFFFFF return 1 } else { $frmRender.isoin configure -background #FFCCCC if { $type == "key" } { return 1 } return 0 } } return 1 } proc validateTri { type val } { global renderRender renderTriangleValue frmRender if { $renderRender == "TRIANGLES" } { set d1 -1 if { [scan $val {%d} d1] == 1 && $d1 != -1 } { $frmRender.triin configure -background #FFFFFF return 1 } else { $frmRender.triin configure -background #FFCCCC if { $type == "key" } { return 1 } return 0 } } return 1 } proc hideWindow { } { wm withdraw . gg::dispInteract if {[winfo exists .]} { wm deiconify . } } proc makeWindow { } { global EntityTypes EntityDisplay global renderRender renderTriangleValue renderIsolineValue label .title -text "Database Entity Display" set font [.title cget -font] .title configure -font [font create -family [font actual $font -family] \ -weight bold] pack .title -expand 1 -side top pack [frame .hr1 -bd 1 -height 2 -relief sunken] -fill x -pady 2 pack [frame .content] -fill both -side top set frmTypes [CreateLabelFrame .entityTypes -text "Entity Types"] pack [frame .content.left] -side left -anchor n pack [checkbutton $frmTypes.point -text "Points" -variable typePOINT -bd 0] \ -anchor w -pady 0 -ipady 0 -side top pack [checkbutton $frmTypes.curve -text "Curves" -variable typeCurve -bd 0 \ -command {setCurve}] -anchor w -pady 0 -ipady 0 pack [checkbutton $frmTypes.curve0 -text "B-spline curves" \ -variable typeBCURVE -bd 0] -anchor w -padx 20 -pady 0 pack [checkbutton $frmTypes.curve2 -text "Circular arcs" \ -variable typeCIRCLE -bd 0] -anchor w -padx 20 -pady 0 pack [checkbutton $frmTypes.curve3 -text "Conic arcs" -variable typeCONIC \ -bd 0] -anchor w -padx 20 -pady 0 pack [checkbutton $frmTypes.curve4 -text "Lines" -variable typeLINE -bd 0] \ -anchor w -padx 20 -pady 0 pack [checkbutton $frmTypes.curve5 -text "Offset curves" \ -variable typeOFFCURV -bd 0] -anchor w -padx 20 -pady 0 pack [checkbutton $frmTypes.curve1 -text "Parametric curves" \ -variable typePCURVE -bd 0] -anchor w -padx 20 -pady 0 pack [checkbutton $frmTypes.surf -text "Surfaces" -variable typeSurface \ -bd 0 -command {setSurface}] -anchor w -pady 0 -ipady 0 -side top -pady 0 pack [checkbutton $frmTypes.surf4 -text "B-spline surfaces" \ -variable typeBSURFACE -bd 0] -anchor w -padx 20 -pady 0 pack [checkbutton $frmTypes.surf6 -text "Bounded surfaces" \ -variable typeBOUNDSURF -bd 0] -anchor w -padx 20 -pady 0 pack [checkbutton $frmTypes.surf5 -text "Offset surfaces" \ -variable typeOFFSURF -bd 0] -anchor w -padx 20 -pady 0 pack [checkbutton $frmTypes.surf1 -text "Parametric Surfaces" \ -variable typePSURFACE -bd 0] -anchor w -padx 20 -pady 0 pack [checkbutton $frmTypes.surf2 -text "Ruled Surfaces" \ -variable typeRULEDSURF -bd 0] -anchor w -padx 20 -pady 0 pack [checkbutton $frmTypes.surf7 -text "Shells" -variable typeSHELL -bd 0] \ -anchor w -padx 20 -pady 0 pack [checkbutton $frmTypes.surf3 -text "Surfaces of Revolution" \ -variable typeSURFREVO -bd 0] -anchor w -padx 20 -pady 0 pack [checkbutton $frmTypes.surf0 -text "Trimmed Surfaces" \ -variable typeTRIMSURF -bd 0] -anchor w -padx 20 -pady 0 pack [checkbutton $frmTypes.plane -text "Planes" -variable typePLANE -bd 0] \ -anchor w -pady 0 -ipady 0 -side top pack [checkbutton $frmTypes.note -text "Notes" -variable typeNOTE -bd 0] \ -anchor w -pady 0 -ipady 0 -side top pack [button .interact -text "Change View" -command hideWindow] \ -side bottom -padx 3 -pady 3 -in .content.left pack [button .clear -text "Clear" -command {clear}] -side bottom \ -padx 3 -pady 3 -in .content.left set frmLayer [CreateLabelFrame .layerOptions -text "Layer Options"] pack [radiobutton $frmLayer.nothing -text "As Is" -variable layerStatus \ -value ASIS -bd 0] -anchor w -pady 0 -ipady 0 -side top pack [radiobutton $frmLayer.enable -text "Enable" -variable layerStatus \ -value ENABLE -bd 0] -anchor w -pady 0 -ipady 0 -side top pack [radiobutton $frmLayer.disable -text "Disable" -variable layerStatus \ -value DISABLE -bd 0] -anchor w -pady 0 -ipady 0 -side top pack [frame $frmLayer.container] -anchor w -pady 0 -ipady 0 -side top pack [checkbutton $frmLayer.name -text "Move to Layer:" -variable layerName \ -bd 0] -anchor w -pady 0 -ipady 0 -side left -in $frmLayer.container pack [entry $frmLayer.entName -textvariable layerNameValue -width 5] \ -side right -in $frmLayer.container pack [button $frmLayer.showlayout -text "Show Layer Manager" \ -command gg::lmDisplayWindow] -side bottom -padx 3 -pady 3 set frmDisplay [CreateLabelFrame .displayOptions -text "Display Options"] pack [radiobutton $frmDisplay.nothing -text "As Is" -variable displayDisplay \ -value ASIS -bd 0] -anchor w -pady 0 -ipady 0 -side top pack [radiobutton $frmDisplay.wire -text "Wireframe" \ -variable displayDisplay -value WIREFRAME -bd 0] -anchor w -pady 0 \ -ipady 0 -side top pack [radiobutton $frmDisplay.hidden -text "Hidden Line" \ -variable displayDisplay -value HIDDENLINE -bd 0] -anchor w -pady 0 \ -ipady 0 -side top pack [radiobutton $frmDisplay.shaded -text "Shaded" \ -variable displayDisplay -value SHADED -bd 0] -anchor w -pady 0 \ -ipady 0 -side top pack [radiobutton $frmDisplay.shadedwire -text "Shaded/Wire" \ -variable displayDisplay -value SHADED_LINE -bd 0] -anchor w \ -pady 0 -ipady 0 -side top pack [radiobutton $frmDisplay.solid -text "Solid" -variable displayDisplay \ -value SOLID -bd 0] -anchor w -pady 0 -ipady 0 -side top pack [radiobutton $frmDisplay.solidwire -text "Solid/Wire" \ -variable displayDisplay -value SOLID_LINE -bd 0] -anchor w -pady 0 \ -ipady 0 -side top pack [frame $frmDisplay.c1] -fill x pack [checkbutton $frmDisplay.line -text "Line Color" \ -variable displayLine -bd 0] -anchor w -pady 0 -ipady 0 -side top \ -in $frmDisplay.c1 -side left set m [tk_optionMenu $frmDisplay.linecolor displayLineColor 1 2 3 4 5 6 7] $m entryconfigure 0 -background [gg::dispColor 0] $m entryconfigure 1 -background [gg::dispColor 1] $m entryconfigure 2 -background [gg::dispColor 2] $m entryconfigure 3 -background [gg::dispColor 3] $m entryconfigure 4 -background [gg::dispColor 4] $m entryconfigure 5 -background [gg::dispColor 5] $m entryconfigure 6 -background [gg::dispColor 6] pack $frmDisplay.linecolor -side right -in $frmDisplay.c1 pack [frame $frmDisplay.c2] -fill x pack [checkbutton $frmDisplay.solidc -text "Solid Color" \ -variable displaySolid -bd 0] -anchor w -pady 0 -ipady 0 -side top \ -in $frmDisplay.c2 -side left set m [tk_optionMenu $frmDisplay.solidcolor displaySolidColor 1 2 3 4 5 6 7] $m entryconfigure 0 -background [gg::dispColor 0] $m entryconfigure 1 -background [gg::dispColor 1] $m entryconfigure 2 -background [gg::dispColor 2] $m entryconfigure 3 -background [gg::dispColor 3] $m entryconfigure 4 -background [gg::dispColor 4] $m entryconfigure 5 -background [gg::dispColor 5] $m entryconfigure 6 -background [gg::dispColor 6] pack $frmDisplay.solidcolor -in $frmDisplay.c2 -side right global frmRender set frmRender [CreateLabelFrame .renderOptions -text "Render Options"] pack [radiobutton $frmRender.nothing -text "As Is" -variable renderRender \ -value ASIS -bd 0] -anchor w -pady 0 -ipady 0 -side top pack [radiobutton $frmRender.outline -text "Outline" -variable renderRender \ -value OUTLINE -bd 0] -anchor w -pady 0 -ipady 0 -side top pack [radiobutton $frmRender.interval -text "Intervals" \ -variable renderRender -value INTERVALS -bd 0] -anchor w -pady 0 \ -ipady 0 -side top pack [frame $frmRender.iso -bd 0] -side top -anchor w -pady 0 -ipady 0 \ -fill x pack [radiobutton $frmRender.isolines -text "Isolines" \ -variable renderRender -value ISOLINES -bd 0 \ -command {global frmRender; focus $frmRender.isoin}] -anchor w -pady 0 \ -ipady 0 -side left -in $frmRender.iso pack [entry $frmRender.isoin -textvariable renderIsolineValue -width 5 \ -validate all] -side right -in $frmRender.iso -anchor e pack [frame $frmRender.tri -bd 0] -side top -anchor w -pady 0 -ipady 0 -fill x pack [radiobutton $frmRender.triangles -text "Triangles" \ -variable renderRender -value TRIANGLES -bd 0 \ -command {global frmRender; focus $frmRender.triin}] -anchor w \ -pady 0 -ipady 0 -side left -in $frmRender.tri pack [entry $frmRender.triin -textvariable renderTriangleValue -width 5 \ -validate all] -side right -in $frmRender.tri -anchor e $frmRender.isoin configure -validatecommand { validateIso %V %P } $frmRender.triin configure -validatecommand { validateTri %V %P } pack .entityTypes -in .content.left -side left -fill y -anchor n pack .renderOptions -in .content -side top -fill x pack .layerOptions -in .content -side top -fill x pack .displayOptions -in .content -side top -fill x pack [frame .hr2 -bd 1 -height 2 -relief sunken] -fill x -pady 2 -expand 1 frame .buttons pack [button .buttons.apply -text "Apply" \ -command { process; gg::dispLight [gg::dispLight] }] -side right -padx 3 pack [button .buttons.cancel -text "Cancel" \ -command { revertView; cleanup }] -side right -padx 3 pack [button .buttons.ok -text "OK" -command { process; cleanup }] \ -side right -padx 3 if {![catch {pwiLogoCreate .buttons.logo 1} b]} { $b configure -bd 0 -relief flat pack $b -side left -padx 5 } pack .buttons -fill x -side bottom -padx 2 -pady 1 -expand 1 } makeWindow ::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. #