# # Copyright 2003 (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. # # Create undimenionsed connectors for an ellipse. package require PWI_Glyph 1.1 gg::tkLoad catch { set scriptDir [file dirname [info script]] set logoFile [file join $scriptDir pwiLogo.glf] source $logoFile } # major axis along x of length 2A set A 10.0 # minor axis along y of length 2B set B 2.0 set center [list 0.0 0.0 0.0] proc createInput { c name msg x y width anchor } { global myVars set f [frame $c.$name] set l [label $f.l -text "$msg" -anchor w] set e [entry $f.e -width $width -textvariable myVars($name)] pack $e -side right -expand 0 pack $l -side right -expand 0 $c create window $x $y -window $f -anchor $anchor -tag $name return $e } proc checkValidity { } { global validInput global okButton foreach var [array names validInput] { if {$validInput($var) == 0} { $okButton configure -state disabled return 0 } } $okButton configure -state normal return 1 } proc checkABInput { w var text } { global myVars global validInput global myColors if {![string is double -strict $text] || $text == 0.0} { set okay 0 } else { set okay 1 } if {0 == $okay} { $w configure -bg $myColors(invalid) } else { $w configure -bg $myColors(valid) } set validInput($var) $okay checkValidity return 1 } proc checkOriginInput { w var text } { global myVars global validInput global myColors set n [llength $text] if {$n != 3} { set okay 0 } else { set okay 1 foreach x $text { if {![string is double -strict $x]} { set okay 0 break } } } if {0 == $okay} { $w configure -bg $myColors(invalid) } else { $w configure -bg $myColors(valid) } set validInput($var) $okay checkValidity return 1 } proc drawCanvas { c } { global myVars global validInput global myColors set w [$c cget -width] set h [$c cget -height] set w2 [expr {0.5 * $w}] set h2 [expr {0.5 * $h}] # The ellipse set xa [expr {0.1 * $w}] set xb [expr {0.9 * $w}] set yd [expr {0.25 * ($xb - $xa)}] set ya [expr {$h2 - 0.5 * $yd}] set yb [expr {$ya + 2.0 * $yd}] $c create arc $xa $ya $xb $yb -start 0 -extent 180 -style arc -outline red \ -width 3 # The center set d1 3.0 set d2 [expr {2.0 * $d1}] set d3 [expr {6.0 * $d1}] set d4 [expr {3.0 * $d1}] set pad 10 set ox [expr {int($w2)}] set oy [expr {int(0.5 * ($ya + $yb))}] $c create line [list [expr {$ox - $d1}] $oy [expr {$xb + $d3}] $oy] \ -arrow none -fill black $c create line [list $ox [expr {$ya - $d3}] $ox [expr {$oy + $d1 + 1}]] \ -arrow none -fill black # Vertical measurement set x1 [expr {$ox - $d2}] set x2 [expr {$x1 - $d3}] $c create line [list $x1 $oy $x2 $oy] -arrow none -fill black $c create line [list $x1 $ya $x2 $ya] -arrow none -fill black set xm [expr {0.5 * ($x1 + $x2)}] $c create line [list $xm $oy $xm $ya] -arrow both \ -arrowshape [list $d4 $d4 $d1] -fill black # Create B input set bInput [createInput $c bVal "B" [expr {$xm - $pad}] \ [expr {0.5 * ($oy + $ya)}] 6 e] set myVars(bVal) 5.0 set validInput(bVal) 1 $bInput configure -validate key -validatecommand \ [list checkABInput $bInput bVal %P] set myColors(valid) [$bInput cget -bg] set myColors(invalid) "#FFCCCC" # Create origin input set oInput [createInput $c origin "Origin" [expr {$ox + $pad}] \ [expr {$oy - $pad}] 15 sw] set myVars(origin) [list 0.0 0.0 0.0] set validInput(origin) 1 $oInput configure -validate key -validatecommand \ [list checkOriginInput $oInput origin %P] # Horizontal measurement set y1 [expr {$oy + $d2}] set y2 [expr {$y1 + $d3}] $c create line [list $ox $y1 $ox $y2] -arrow none -fill black $c create line [list $xb $y1 $xb $y2] -arrow none -fill black set ym [expr {0.5 * ($y1 + $y2)}] $c create line [list $ox $ym $xb $ym] -arrow both \ -arrowshape [list $d4 $d4 $d1] -fill black # Create A input set aInput [createInput $c aVal "A" [expr {0.5 * ($ox + $xb)}] \ [expr {$ym + $pad}] 6 n] set myVars(aVal) 10.0 set validInput(aVal) 1 $aInput configure -validate key -validatecommand \ [list checkABInput $aInput aVal %P] # Now shrink the size of the canvas to the needed size tkwait visibility $oInput set bbox [$c bbox all] set pad 15 set x1 [expr {[lindex $bbox 0] - $pad}] set y1 [expr {[lindex $bbox 1] - $pad}] set x2 [expr {[lindex $bbox 2] + $pad}] set y2 [expr {[lindex $bbox 3] + $pad}] set x [expr {$x2 - $x1}] set y [expr {$y2 - $y1}] set x1 [expr {-1 * $x1}] set y1 [expr {-1 * $y1}] $c move all $x1 $y1 $c config -height $y -width $x } proc buildWidgets { top } { global okButton if {$top == "."} { set parent [frame ${top}t] } else { set parent [frame ${top}.t] } pack $parent -fill both -expand 1 # Label set l [label $parent.l -text "Create an Ellipse"] 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 x -expand 0 -anchor c # Divider rule set f [frame $parent.hr1 -bd 1 -height 2 -relief sunken] pack $f -side top -fill x -expand 0 # Canvas set c [canvas $parent.c -width 500 -height 300 -bd 0 -highlightthickness 0] pack $c -side top -fill none -expand 0 -anchor c # Divider rule set f [frame $parent.hr2 -bd 1 -height 2 -relief sunken] pack $f -side top -fill x -expand 0 # Logo if {![catch {pwiLogoCreate $parent.logo 1} b]} { $b configure -bd 0 -relief flat pack $b -side left -padx 5 -fill y } # Button frame set f [frame $parent.f] pack $f -side right set buttonWidth 10 # Apply button set okButton [button $f.apply -text "OK" -width $buttonWidth \ -command {wm iconify . ; createEllipse; exit}] # Cancel button set cancelButton [button $f.abort -text "Cancel" -width $buttonWidth \ -command {gg::abort}] grid $okButton $cancelButton -pady 5 -padx 5 -sticky nsew pack $f -side right -fill x -expand 0 # Draw the canvas ::tk::PlaceWindow $top widget drawCanvas $c } proc createEllipse { } { global myVars set A $myVars(aVal) set B $myVars(bVal) set center $myVars(origin) # conic rho value for an ellipse set R [expr sqrt(2) - 1] # create 1/4 ellipse in the XY quadrant if {[catch { gg::conBegin gg::segBegin -type CONIC -rho $R gg::segAddControlPt [ggu::vec3Add "$A 0 0" $center] gg::segAddControlPt [ggu::vec3Add "0 $B 0" $center] gg::segAddControlPt -alternate INTERSECTION \ [ggu::vec3Add "$A $B 0" $center] gg::segEnd set A [expr {-1.0 * $A}] gg::segBegin -type CONIC -rho $R gg::segAddControlPt [ggu::vec3Add "0 $B 0" $center] gg::segAddControlPt [ggu::vec3Add "$A 0 0" $center] gg::segAddControlPt -alternate INTERSECTION \ [ggu::vec3Add "$A $B 0" $center] gg::segEnd set con [gg::conEnd]} msg]} { tk_messageBox -icon warning -message "Ellipse could not be created.\nThis is usually due to a duplicate connector." -title "Create an Ellipse" -type ok exit } return $con } buildWidgets . ::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. #