# # Copyright 2006 (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 PWIUTIL 1.0 gg::tkLoad catch { set scriptDir [file dirname [info script]] source [file join $scriptDir pwiLogo.glf] } set ds1 0.10 set maxds 1.0 set ds2 0.10 set con_list "" proc dimension_cons { } { global ds1 maxds ds2 global con_list global cur_maxds set maxit 20 if { [llength $con_list] < 1} { tk_messageBox -icon warning \ -message "Please pick connectors first!" -parent . \ -title "No Connectors Picked!" -type ok return } get_values if {$ds1 > $maxds} { tk_messageBox -icon warning \ -message "ds1 must be less than maxds!" -parent . \ -title "Incorrect Parameters!" -type ok return } if {$ds1 <= 0} { tk_messageBox -icon warning \ -message "ds1 must be greater than 0!" -parent . \ -title "Incorrect Parameters!" -type ok return } if {$ds2 > $maxds} { tk_messageBox -icon warning \ -message "ds2 must be less than maxds!" -parent . \ -title "Incorrect Parameters!" -type ok return } if {$ds2 <= 0} { tk_messageBox -icon warning \ -message "ds2 must be greater than 0!" -parent . \ -title "Incorrect Parameters!" -type ok return } if {$maxds <= 0} { tk_messageBox -icon warning \ -message "maxds must be greater than 0!" -parent . \ -title "Incorrect Parameters!" -type ok return } gg::conDim $con_list -spacing $maxds gg::conBeginSpacing $con_list $ds1 gg::conEndSpacing $con_list $ds2 for {set n 0} {$n < [llength $con_list]} {incr n} { set cn [lindex $con_list $n] set new_p [gg::conDim $cn] set old_p 0 set avg_spacing $maxds for {set nit 0} {$nit < $maxit} {incr nit} { set old_p $new_p get_max_ds $cn set avg_spacing [expr $avg_spacing*$maxds/$cur_maxds] gg::conDim $cn -spacing $avg_spacing set new_p [gg::conDim $cn] if {$old_p == $new_p} { break } } if {$old_p != $new_p} { puts "did not converge for connector $cn" } } } proc get_max_ds { cn } { global cur_maxds set cur_maxds 0 set npnts [gg::conDim $cn] for {set n 1} {$n < $npnts} {incr n} { set p1 $n set p2 [expr $n + 1] set x1 [lindex [gg::conGetPt $cn $p1] 0] set y1 [lindex [gg::conGetPt $cn $p1] 1] set z1 [lindex [gg::conGetPt $cn $p1] 2] set x2 [lindex [gg::conGetPt $cn $p2] 0] set y2 [lindex [gg::conGetPt $cn $p2] 1] set z2 [lindex [gg::conGetPt $cn $p2] 2] set dx [expr $x2-$x1] set dy [expr $y2-$y1] set dz [expr $z2-$z1] set dr [expr sqrt($dx*$dx+$dy*$dy+$dz*$dz)] if {$dr > $cur_maxds} { set cur_maxds $dr } } } proc get_values { } { global ds1 maxds ds2 .ds1.ent get .maxds.ent get .ds2.ent get } proc pick_connectors { } { global con_list set con_list "" if { [llength [gg::conGetAll -enabled]] > 0 } { wm withdraw . set pickable [gg::conGetAll] set con_list [gg::dispPick CONNECTOR -message "Pick connectors to dimension:"] if {[winfo exists .]} { wm deiconify . } } } proc acquire_params { } { global ds1 maxds ds2 global con_list global cur_maxds set ref_con "" set tmp_cnlist [gg::conGetAll -enabled] set dimen_exist 0 for {set n 0} {$n < [llength $tmp_cnlist]} {incr n} { set cn [lindex $tmp_cnlist $n] set np [gg::conDim $cn] if {$np > 0} { set dimen_exist 1 break } } if {$dimen_exist == 0} { tk_messageBox -icon warning \ -message "There must be at least one dimensioned connector to use this option!" -parent . \ -title "No Dimensioned Connectors!" -type ok return } if { [llength [gg::conGetAll -enabled]] > 0 } { wm withdraw . set pickable [gg::conGetAll] set ref_con [gg::dispPick CONNECTOR -message "Pick connector to get parameters from:" \ -dimension DIMENSIONED \ -multiple FALSE] if {$ref_con != ""} { set ds1 [gg::conBeginSpacing $ref_con] set ds2 [gg::conEndSpacing $ref_con] get_max_ds $ref_con set maxds $cur_maxds } if {[winfo exists .]} { wm deiconify . } } } proc makeWindow { } { global ds1 maxds ds2 wm title . "Dimension Connectors" frame .title label .title.lbl1 -text "Dimension connectors" label .title.lbl2 -text "based on end spacing" label .title.lbl3 -text "and max spacing" pack .title -fill both -side top -pady 5 -padx 10 pack .title.lbl1 -fill both -side top pack .title.lbl2 -fill both -side top pack .title.lbl3 -fill both -side top frame .fr1 -bd 1 -height 2 -relief sunken pack .fr1 -fill x -pady 2 frame .connectors button .connectors.pick -text "Pick Connectors" -command {pick_connectors} -width 12 button .connectors.clear -text "Clear Connectors" -command {set con_list ""} -width 12 pack .connectors -fill both -side top pack .connectors.pick -padx 5 -side left pack .connectors.clear -padx 5 -side right frame .fr2 -bd 1 -height 2 -relief sunken pack .fr2 -fill x -pady 2 frame .ds1 label .ds1.lbl -text "ds1" entry .ds1.ent -textvariable ds1 pack .ds1 -fill both -side top -pady 5 -padx 5 pack .ds1.ent -fill both -side right pack .ds1.lbl -fill both -side right frame .maxds label .maxds.lbl -text "max ds" entry .maxds.ent -textvariable maxds pack .maxds -fill both -side top -pady 5 -padx 5 pack .maxds.ent -fill both -side right pack .maxds.lbl -fill both -side right frame .ds2 label .ds2.lbl -text "ds2" entry .ds2.ent -textvariable ds2 pack .ds2 -fill both -side top -pady 5 -padx 5 pack .ds2.ent -fill both -side right pack .ds2.lbl -fill both -side right frame .acquire button .acquire.pick -text "Acquire Params" -command {acquire_params} -width 12 pack .acquire -fill both -side top pack .acquire.pick -padx 5 -side top frame .fr3 -bd 1 -height 2 -relief sunken pack .fr3 -fill x -pady 2 frame .buttons button .buttons.split -text "Apply" -command {dimension_cons} -width 5 button .buttons.cancel -text "Close" -command {exit} -width 5 button .buttons.done -text "OK" -command {dimension_cons; exit} -width 5 pack .buttons -fill both -side top pack .buttons.split -padx 6 -side right -pady 5 -padx 5 pack .buttons.cancel -padx 3 -side right -pady 5 -padx 5 pack .buttons.done -padx 3 -side right -pady 5 -padx 5 } 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. #