# # Copyright 2000-2002 (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. # Split a connector into N equal length pieces # $splitnCons # $splitnNum package require PWI_Glyph 1.1 gg::tkLoad catch { set scriptDir [file dirname [info script]] set logoFile [file join $scriptDir pwiLogo.glf] source $logoFile } proc showTitle { f } { set master [frame $f.title] pack $master -side top -expand FALSE -fill x set l [label $master.label -text "Split Connectors" -justify center] set font [$l cget -font] set fontFamily [font actual $font -family] set fontSize [font actual $font -size] set bigLabelFont [font create -family $fontFamily -weight bold \ -size [expr {int(1.25 * $fontSize)}]] $l configure -font $bigLabelFont pack $l -side top -fill y -pady 5 set hr [frame $master.hr -height 2 -relief sunken -borderwidth 1] pack $hr -side top -fill x } proc showEndMessage { msg } { set f [frame .f] pack $f showTitle $f set t [label $f.t -text $msg] pack $t -side top -expand true -fill both -padx 15 -pady 15 set hr [frame $f.hr -height 2 -relief sunken -borderwidth 1] pack $hr -side top -fill x if {![catch {pwiLogoCreate $f.logo 1} b]} { $b configure -bd 0 -relief flat pack $b -side left -padx 5 -fill y } set ok [button $f.ok -text "OK" -command exit] pack $ok -side right -pady 10 -padx 10 ::tk::PlaceWindow . widget gg::tkLoop } proc checkSplitsInput { w var okbut text } { if {![string is integer -strict $text] || $text < 2} { set okay 0 } else { set okay 1 } if {0 != $okay && $var > 0 && $text > [expr {$var - 1}]} { set okay 0 } if {0 == $okay} { $w configure -bg "#FFCCCC" $okbut configure -state disabled } else { $w configure -bg "#FFFFFF" $okbut configure -state normal } return true } proc doSplit { nPieces cons } { set newCons $cons foreach con $cons { for {set split 1} {$split < $nPieces} {incr split} { set dS [expr 1.0 / [expr {$nPieces - $split + 1}]] set pt [gg::conGetPt $con -arc $dS] set newcon [gg::conSplit $con $pt] # Make sure we have enough points to do remaining splits set newdim [gg::conDim $newcon] set neededDim [expr {$nPieces - $split + 1}] if {$newdim > 0 && $newdim < $neededDim} { set delta [expr {$neededDim - $newdim}] set olddim [gg::conDim $con] gg::conRedimBegin gg::conRedim $newcon [expr {$newdim + $delta}] gg::conRedim $con [expr {$olddim - $delta}] gg::conRedimEnd } set con $newcon set newCons [lappend newCons $con] } } gg::varSet conSplitCons $newCons exit } if {![info exists conSplitCons] || [llength $conSplitCons] == 0} { showEndMessage "No connectors have been selected\nTo select one or more connectors,\ncreate a Glyph variable by the name\nof conSplitCons and assign it a value\nby picking the desired connectors.\nThen, rerun this script." } set minDim -1 if {[catch {gg::conDim $conSplitCons} dims]} { puts "conSplitCons: $conSplitCons" puts "$dims" showEndMessage "The variable conSplitCons does not contain a\nvalid list of connectors. Please recreate\nthe variable conSplitCons and assign it a value\nby picking the desired connectors.\nThen, rerun this script." } foreach dim $dims { if {0 < $dim} { if {$minDim == -1 || $dim < $minDim} { set minDim $dim } } } if {$minDim == 2} { showEndMessage "At least one of the connectors chosen has\na dimension of 2 and can not be split." } # Add GUI to select the number of points. if {0 > $minDim} { set msg "Enter the number of equal length connectors into\nwhich each selected connector will be split:" set nPieces 2 } else { set nPieces [expr {$minDim - 1}] set msg "Enter the number of equal length connectors\ninto which each selected connector will be\nsplit (maximum is $nPieces):" } set f [frame .f] pack $f showTitle $f set t [label $f.t -text $msg] pack $t -side top -expand true -fill both -padx 15 -pady 15 set i [entry $f.i -width 10 -textvariable nPieces] pack $i -side top -expand false -pady 5 set hr [frame $f.hr -height 2 -relief sunken -borderwidth 1] pack $hr -side top -fill x set bf [frame $f.bf] pack $bf -expand true -fill x -pady 10 if {![catch {pwiLogoCreate $bf.logo 1} b]} { $b configure -bd 0 -relief flat pack $b -side left -padx 5 } set cancel [button $bf.cancel -text "Cancel" -command exit] pack $cancel -side right -padx 5 set ok [button $bf.ok -text "OK" -command {doSplit $nPieces $conSplitCons}] pack $ok -side right -padx 5 $i configure -validate key \ -validatecommand [list checkSplitsInput $i $minDim $ok %P] ::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. #