# # Copyright 2000, 2001 (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. # #-------------------------------------------------------------------------- # SymmetryPlane.glf # # Prompt the user for a symmetry plane and tolerance and project all # connectors within the tolerance (but not on the plane) to the plane. #-------------------------------------------------------------------------- package require PWI_Glyph 1.1 catch { set scriptDir [file dirname [info script]] set logoFile [file join $scriptDir pwiLogo.glf] source $logoFile } # # Plane equation: Ax + By + Cz + D = 0 # set symPlane(A) 0.0 set symPlane(B) 1.0 set symPlane(C) 0.0 set symPlane(D) 0.0 set symPlane(validA) 1 set symPlane(validB) 1 set symPlane(validC) 1 set symPlane(validD) 1 set symPlane(validTol) 1 set symPlane(normal) [list $symPlane(A) $symPlane(B) $symPlane(C)] set symPlane(Tol) [gg::tolNode] set symPlane(includeDoms) 0 set symPlane(asNeeded) 1 proc conNeedToProject { con } { global symPlane set numPts [gg::conDim $con] set result 0 for {set n 1} {$n <= $numPts} {incr n} { # Get the distance to the plane in $delta set dist [ggu::vec3Dot $symPlane(normal) [gg::conGetPt $con $n]] set delta [expr {abs($dist + $symPlane(D))}] # If a point is further away from the plane than the tolerance, it is # not a candidate and we do not need to check further if {$delta > $symPlane(Tol)} { return -1 } # The point is within the tolerance. If it is not zero, we need to # project (or if we want to force) if {0 == $symPlane(asNeeded) || $delta > 0.0} { set result 1 } } return $result } proc domNeedToProject { dom } { global symPlane gg::domReport $dom data STRUCTURE set result 0 # Structured case if {[string equal "STRUCTURED" $data(type)]} { set iMax [lindex $data(dimensions) 0] set jMax [lindex $data(dimensions) 1] for {set j 1} {$j <= $jMax} {incr j} { for {set i 1} {$i <= $iMax} {incr i} { # Get the distance to the plane in $delta set dist [ggu::vec3Dot $symPlane(normal) \ [gg::domGetPt $dom [list $i $j]]] set delta [expr {abs($dist + $symPlane(D))}] # If a point is further away from the plane than the tolerance, it is # not a candidate and we do not need to check further if {$delta > $symPlane(Tol)} { return -1 } # The point is within the tolerance. If it is not zero, we need to # project (or if we want to force) if {0 == $symPlane(asNeeded) || $delta > 0.0} { set result 1 } } } # Unstructured case } elseif {[string equal "UNSTRUCTURED" $data(type)]} { set iMax $data(pointsTotal) for {set i 1} {$i <= $iMax} {incr i} { # Get the distance to the plane in $delta set dist [ggu::vec3Dot $symPlane(normal) [gg::domGetPt $dom $i]] set delta [expr {abs($dist + $symPlane(D))}] # If a point is further away from the plane than the tolerance, it is # not a candidate and we do not need to check further if {$delta > $symPlane(Tol)} { return -1 } # The point is within the tolerance. If it is not zero, we need to # project (or if we want to force) if {0 == $symPlane(asNeeded) || $delta > 0.0} { set result 1 } } # Unknown type } else { return -1 } return $result } proc cancelCB { } { ::exit } proc run { } { global symPlane set symPlane(normal) [list $symPlane(A) $symPlane(B) $symPlane(C)] set conProjList [list] foreach con [gg::conGetAll] { if {1 == [conNeedToProject $con]} { lappend conProjList $con } } set domProjList [list] if {$symPlane(includeDoms)} { foreach dom [gg::domGetAll] { if {1 == [domNeedToProject $dom]} { lappend domProjList $dom } } } if {[llength $conProjList] == 0 && [llength $domProjList] == 0} { tk_messageBox -icon info -message "No entities need to be projected." \ -title "Symmetry Plane" -type ok } else { set dbPlane [gg::dbPlane -coefficients $symPlane(A) $symPlane(B) \ $symPlane(C) $symPlane(D)] if {[llength $conProjList] > 0} { gg::conProject $conProjList -type LINEAR -dir $symPlane(normal) \ -db $dbPlane -maintain_linkage } if {[llength $domProjList] > 0} { gg::domProject $domProjList -type LINEAR -dir $symPlane(normal) \ -db $dbPlane -maintain_linkage -interior_only } gg::dbDelete $dbPlane -force } } proc runCB { } { . configure -cursor watch update run ::exit } proc addSeparator { name } { set f [frame $name -height 2 -relief sunken -borderwidth 1] pack $f -side top -fill x -expand TRUE return $f } proc bottomRow { name width args } { set f [frame $name] if {![catch {pwiLogoCreate $f.logo 1} b]} { $b configure -bd 0 -relief flat pack $b -side left -padx 5 } set buttons [list $f] for {set n [expr {[llength $args] - 1}]} {0 <= $n} {incr n -1} { foreach {label cmd} [lindex $args $n] {break} set b [button ${f}.b${n} -width $width -text $label -command $cmd] pack $b -side right -padx 5 set buttons [linsert $buttons 1 $b] } return $buttons } proc updateRunStatus { state index newValue } { global symPlane set A $symPlane(A) set B $symPlane(B) set C $symPlane(C) set D $symPlane(D) set Tol $symPlane(Tol) set $index $newValue set valid(A) $symPlane(validA) set valid(B) $symPlane(validB) set valid(C) $symPlane(validC) set valid(D) $symPlane(validD) set valid(Tol) $symPlane(validTol) set valid($index) $state if {$valid(A) && $valid(B) && $valid(C) && $valid(D)} { if {0.0 == $A && 0.0 == $B && 0.0 == $C} { set valid(A) 0 set valid(B) 0 set valid(C) 0 } } if {$valid(Tol) && $Tol <= 0.0} { set valid(Tol) 0 } set state 1 foreach i [list A B C D Tol] { if {$valid($i)} { $symPlane(widget$i) configure -background $symPlane(bg) } else { $symPlane(widget$i) configure -background "#ffc0c0" set state 0 } } $symPlane(run) configure -state [lindex {"disabled" "normal"} $state] } proc validateCB { index newValue } { global symPlane if {[string is double $newValue] && ![string equal "" $newValue]} { set symPlane(valid$index) 1 $symPlane(widget$index) configure -background $symPlane(bg) } else { set symPlane(valid$index) 0 $symPlane(widget$index) configure -background "#ffc0c0" } updateRunStatus $symPlane(valid$index) $index $newValue return 1 } proc principalCB { values } { global symPlane foreach {symPlane(A) symPlane(B) symPlane(C) symPlane(D)} $values {break} set symPlane(validA) 1 set symPlane(validB) 1 set symPlane(validC) 1 set symPlane(validD) 1 updateRunStatus 1 A $symPlane(validA) } proc buildGui { } { global symPlane # Title bar wm title . "Symmetry Plane" set top [frame .top] set f [frame $top.titleFrame] pack $f -side top -fill x -pady 5 set l [label $f.label -text "Symmetry Plane" -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 {2 * $fontSize}]] $l configure -font $bigLabelFont set regLabelFont [font create -family $fontFamily -weight bold \ -size [expr {int(1.25 * $fontSize)}]] pack $l -side top # Separator addSeparator $top.hr1 # Equation entry set f [frame $top.eqFrame] set w 8 set l [label $f.label -text "Plane Equation" -justify center \ -font $regLabelFont] pack $l -side top set symPlane(widgetA) [entry $f.aEntry -textvariable symPlane(A) -width $w] set l [label $f.eq1 -text "x + " -justify left -font $regLabelFont] pack $symPlane(widgetA) $l -side left set symPlane(widgetB) [entry $f.bEntry -textvariable symPlane(B) -width $w] set l [label $f.eq2 -text "y + " -justify left -font $regLabelFont] pack $symPlane(widgetB) $l -side left set symPlane(widgetC) [entry $f.cEntry -textvariable symPlane(C) -width $w] set l [label $f.eq3 -text "z + " -justify left -font $regLabelFont] pack $symPlane(widgetC) $l -side left set symPlane(widgetD) [entry $f.dEntry -textvariable symPlane(D) -width $w] set l [label $f.eq4 -text " = 0" -justify left -font $regLabelFont] pack $symPlane(widgetD) $l -side left pack $f -side top -pady 5 -padx 5 set symPlane(bg) [$symPlane(widgetA) cget -background] # Spacer set f [frame $top.spacer1 -height 5] pack $f -side top # Tolerance set f [frame $top.tolerance] set l [label $f.label -text "Tolerance" -justify right] set symPlane(widgetTol) [entry $f.entry -textvariable symPlane(Tol) -width $w] pack $l $symPlane(widgetTol) -side left -pady 5 pack $f -side top # Options set f [frame $top.options] set b [checkbutton $f.asNeeded -text "Only If Needed" \ -variable symPlane(asNeeded)] pack $b -side left -padx 5 -pady 5 set b [checkbutton $f.dom -text "Domains" -variable symPlane(includeDoms)] pack $b -side left -padx 5 -pady 5 pack $f -side top # Separator addSeparator $top.hrPrinc # Principal plane buttons set w 4 set f [frame $top.principal] set l [label $f.label -text "Principal Planes" -justify center \ -font $regLabelFont] pack $l -side top set bYZ [button $f.yz -text "X=0" -width $w \ -command [list principalCB {1.0 0.0 0.0 0.0}]] set bXZ [button $f.xz -text "Y=0" -width $w \ -command [list principalCB {0.0 1.0 0.0 0.0}]] set bXY [button $f.xy -text "Z=0" -width $w \ -command [list principalCB {0.0 0.0 1.0 0.0}]] pack $bYZ $bXZ $bXY -side left -padx 5 -pady 5 pack $f -side top # Separator addSeparator $top.hrBottom # Create the bottom buttons set buttons [bottomRow $top.cmdRow 8 {"Run" runCB} {"Cancel" cancelCB}] pack [lindex $buttons 0] -side bottom -fill x -expand FALSE -pady 5 set symPlane(run) [lindex $buttons 1] # Set text validation functions for equation entry widgets foreach b [list A B C D Tol] { $symPlane(widget$b) configure -validate all -vcmd [list validateCB $b %P] } # Finally, show the window pack $top -expand TRUE -fill both # Center the window ::tk::PlaceWindow . widget set w [winfo reqwidth .] set h [winfo reqheight .] wm resizable . 1 0 wm minsize . $w $h } gg::tkLoad buildGui 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. #