-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSymmetryPlane.glf
453 lines (403 loc) · 16.2 KB
/
SymmetryPlane.glf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
#############################################################################
#
# (C) 2021 Cadence Design Systems, Inc. All rights reserved worldwide.
#
# This sample script is not supported by Cadence Design Systems, 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 2
pw::Script loadTk
#
# 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) [pw::Grid getNodeTolerance]
set symPlane(includeDoms) 0
set symPlane(asNeeded) 1
############################################################################
# conNeedToProject: check to see if a connector needs to be projected
############################################################################
proc conNeedToProject { con } {
global symPlane
set numPts [$con getDimension]
set result 0
for {set n 1} {$n <= $numPts} {incr n} {
# Get the distance to the plane in $delta
set dist [pwu::Vector3 dot $symPlane(normal) [$con getXYZ -grid $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
}
############################################################################
# domNeedToProject: check to see if a domain needs to be projected
############################################################################
proc domNeedToProject { dom } {
global symPlane
set dims [$dom getDimensions]
set result 0
# Structured case
if [$dom isOfType pw::DomainStructured] {
set iMax [lindex $dims 0]
set jMax [lindex $dims 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 [pwu::Vector3 dot $symPlane(normal) \
[$dom getXYZ -grid [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 [$dom isOfType pw::DomainUnstructured] {
set iMax [lindex $dims 0]
for {set i 1} {$i <= $iMax} {incr i} {
# Get the distance to the plane in $delta
set dist [pwu::Vector3 dot $symPlane(normal) [$dom getXYZ -grid $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
}
############################################################################
# cancelCB: handle user pressing the Cancel button
############################################################################
proc cancelCB { } {
::exit
}
############################################################################
# run: project cons and doms
############################################################################
proc run { } {
global symPlane
set symPlane(normal) [list $symPlane(A) $symPlane(B) $symPlane(C)]
set conProjList [list]
foreach con [pw::Grid getAll -type pw::Connector] {
if {1 == [conNeedToProject $con]} {
lappend conProjList $con
}
}
set domProjList [list]
if {$symPlane(includeDoms)} {
foreach dom [pw::Grid getAll -type pw::Domain] {
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 [pw::Plane create]
$dbPlane setCoefficients $symPlane(A) $symPlane(B) $symPlane(C) \
$symPlane(D)
foreach con $conProjList {
$con project -type LINEAR $dbPlane
}
foreach dom $domProjList {
$dom project -type LINEAR -interior $dbPlane
}
$dbPlane delete -force
}
}
############################################################################
# runCB: handle the user pressing the Run button
############################################################################
proc runCB { } {
. configure -cursor watch
update
run
::exit
}
############################################################################
# addSeparator: add a Tk separator frame
############################################################################
proc addSeparator { name } {
set f [frame $name -height 2 -relief sunken -borderwidth 1]
pack $f -side top -fill x -expand TRUE
return $f
}
############################################################################
# bottomRow: add Tk button row
############################################################################
proc bottomRow { name width args } {
set f [frame $name]
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]
}
pack [label $f.logo -image [cadenceLogo] -bd 0 -relief flat] \
-side left -padx 5
return $buttons
}
############################################################################
# updateRunStatus: validate input and update widgets
############################################################################
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]
}
############################################################################
# validateCB: handle user input changes
############################################################################
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
}
############################################################################
# principalCB: handle user changing principal plane
############################################################################
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)
}
############################################################################
# buildGui: build the Tk window
############################################################################
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 {int(1.5 * $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 -textvar symPlane(A) -width $w -justify right]
set l [label $f.eq1 -text "x + " -justify left -font $regLabelFont]
pack $symPlane(widgetA) $l -side left
set symPlane(widgetB) [entry $f.bEntry -textvar symPlane(B) -width $w -justify right]
set l [label $f.eq2 -text "y + " -justify left -font $regLabelFont]
pack $symPlane(widgetB) $l -side left
set symPlane(widgetC) [entry $f.cEntry -textvar symPlane(C) -width $w -justify right]
set l [label $f.eq3 -text "z + " -justify left -font $regLabelFont]
pack $symPlane(widgetC) $l -side left
set symPlane(widgetD) [entry $f.dEntry -textvar symPlane(D) -width $w -justify right]
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]
}
bind . <Control-KeyPress-Return> { .top.cmdRow.b0 invoke }
bind . <KeyPress-Escape> { .top.cmdRow.b1 invoke }
# 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
}
proc cadenceLogo {} {
set logoData "
R0lGODlhgAAYAPQfAI6MjDEtLlFOT8jHx7e2tv39/RYSE/Pz8+Tj46qoqHl3d+vq62ZjY/n4+NT
T0+gXJ/BhbN3d3fzk5vrJzR4aG3Fubz88PVxZWp2cnIOBgiIeH769vtjX2MLBwSMfIP///yH5BA
EAAB8AIf8LeG1wIGRhdGF4bXD/P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1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F1w8Mk2ti7wUaDRgg1EISNXVwF
lKpdsEAIj9zNAFnW3e4gecCV7Ft/qKTNP0A2Et7AUIj3ysARLDBaC7MRkF+I+x3wzA08SLiTYER
KMJ3BoR3wzUUvLdJAFBtIWIttZEQIwMzfEXNB2PZJ0J1HIrgIQkFILjBkUgSwFuJdnj3i4pEIlg
eY+Bc0AGSRxLg4zsblkcYODiK0KNzUEk1JAkaCkjDbSc+maE5d20i3HY0zDbdh1vQyWNuJkjXnJ
C/HDbCQeTVwOYHKEJJwmR/wlBYi16KMMBOHTnClZpjmpAYUh0GGoyJMxya6KcBlieIj7IsqB0ji
5iwyyu8ZboigKCd2RRVAUTQyBAugToqXDVhwKpUIxzgyoaacILMc5jQEtkIHLCjwQUMkxhnx5I/
seMBta3cKSk7BghQAQMeqMmkY20amA+zHtDiEwl10dRiBcPoacJr0qjx7Ai+yTjQvk31aws92JZ
Q1070mGsSQsS1uYWiJeDrCkGy+CZvnjFEUME7VaFaQAcXCCDyyBYA3NQGIY8ssgU7vqAxjB4EwA
DEIyxggQAsjxDBzRagKtbGaBXclAMMvNNuBaiGAAA7"
return [image create photo -format GIF -data $logoData]
}
buildGui
tkwait window .
#############################################################################
#
# This file is licensed under the Cadence Public License Version 1.0 (the
# "License"), a copy of which is found in the included file named "LICENSE",
# and is distributed "AS IS." TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE
# LAW, CADENCE DISCLAIMS ALL WARRANTIES AND IN NO EVENT SHALL BE LIABLE TO
# ANY PARTY FOR ANY DAMAGES ARISING OUT OF OR RELATING TO USE OF THIS FILE.
# Please see the License for the full text of applicable terms.
#
#############################################################################