-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtrudePipe.glf
243 lines (205 loc) · 8.7 KB
/
ExtrudePipe.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
#############################################################################
#
# (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.
#
#############################################################################
package require PWI_Glyph 2
pw::Script loadTk
set Params(radius) 10
set Params(length) 40
# Make the cylindrical revolved surface
proc makeCylinderDB { r l } {
set seg [pw::SegmentSpline create]
$seg addPoint "[expr -0.5 * $l] $r 0"
$seg addPoint "[expr 0.5 * $l] $r 0"
set line [pw::Curve create]
$line addSegment $seg
set pipe [pw::Surface create]
$pipe revolve -angle 360 $line {0 0 0} {1 0 0}
pw::Display update
return $pipe
}
# Make connectors and domain on database
proc makeDomain { db avgspace } {
set omethod [pw::Connector getCalculateDimensionMethod]
set ospacing [pw::Connector getCalculateDimensionSpacing]
pw::Connector setCalculateDimensionMethod Spacing
pw::Connector setCalculateDimensionSpacing $avgspace
set cons [pw::Connector createOnDatabase $db]
foreach con $cons {
$con calculateDimension
}
set dom [pw::DomainStructured createOnDatabase [list $db]]
pw::Display update
pw::Connector setCalculateDimensionMethod $omethod
pw::Connector setCalculateDimensionSpacing $ospacing
return $dom
}
# Extrude domain inward
proc extrudeDomain { dom } {
global Params
set face [pw::FaceStructured create]
$face addDomain $dom
set block [pw::BlockStructured create]
$block addFace $face
$block setExtrusionBoundaryCondition [list 1 1] ConstantX
$block setExtrusionBoundaryCondition [list 3 1] ConstantX
$block setExtrusionSolverAttribute DirectionFlipped 1
$block setExtrusionSolverAttribute NormalInitialStepSize \
[expr $Params(radius)/100.0]
$block setExtrusionSolverAttribute StopAtHeight [expr $Params(radius)/3.0]
set mode [pw::Application begin ExtrusionSolver $block]
set result Completed
while {1 == [string equal $result Completed]} {
$mode run
set result [lindex [$mode getRunResult] 0]
switch $result {
Error -
SolverFailure {
puts "Extrusion solver encountered an error"
}
Completed -
StopCriteria {
}
}
}
$mode end
}
# Build a pipe mesh on a cylinder database
proc buildMesh { } {
global Params
wm withdraw .
set pipeDB [makeCylinderDB $Params(radius) $Params(length)]
pw::Display resetView
set view [pw::Display getCurrentView]
pw::Display setCurrentView [lreplace $view 2 3 {0.6 0.6 0.0} 60.0]
set spacing [expr ($Params(radius) + $Params(length)) / 50.0]
set Domain [makeDomain $pipeDB $spacing]
extrudeDomain $Domain
destroy .
}
# Check text field input
proc checkInput { w param text action } {
global Params
# Ignore force validations
if {$action == -1} {
return 1
}
if {![string is double $text]} {
$w configure -bg "#FFCCCC"
} else {
$w configure -bg "#FFFFFF"
}
if {[string is double $Params(radius)] && \
[string is double $Params(length)] && \
$Params(radius) > 0.0 && $Params(length) > 0.0} {
.buttons.ok configure -state normal
} else {
.buttons.ok configure -state disabled
}
return 1
}
# Create a text input field
proc makeInputField { parent name title param {width 7} {valid ""}} {
global Params
set row [lindex [grid size $parent] 1]
label .lbl$name -text $title
entry .ent$name -textvariable Params($param) -width $width -justify right
if { [string compare $valid ""] != 0 } {
.ent$name configure -validate all
.ent$name configure -validatecommand $valid
}
grid .lbl$name -row $row -column 0 -sticky e -in $parent
grid .ent$name -row $row -column 1 -sticky w -in $parent
grid columnconfigure $parent "0 1" -weight 1
return $parent.$name
}
# Build the Tk interface
proc makeWindow { } {
global Params
wm title . "Extruded Pipe"
label .title -text "Create Extruded Pipe"
set font [.title cget -font]
set wfont [font create -family [font actual $font -family] -weight bold]
.title configure -font $wfont
pack .title -side top
pack [frame .hr1 -relief sunken -height 2 -bd 1] \
-side top -padx 2 -fill x -pady 1
pack [frame .inputs] -fill x -padx 2 -expand 1
makeInputField .inputs radius "Radius:" radius 7 [list \
checkInput %W radius %P %d]
makeInputField .inputs length "Length:" length 7 [list \
checkInput %W length %P %d]
pack [frame .hr2 -relief sunken -height 2 -bd 1] \
-side top -padx 2 -fill x -pady 1
pack [frame .buttons] -fill x -padx 2 -pady 1 -side bottom
pack [button .buttons.cancel -text "Cancel" -command { exit }] \
-side right -padx 2
pack [button .buttons.ok -text "OK" -command {buildMesh}] \
-side right -padx 2
pack [label .buttons.logo -image [cadenceLogo] -bd 0 -relief flat] \
-side left -padx 5
bind . <KeyPress-Escape> { .buttons.cancel invoke }
bind . <Control-KeyPress-Return> { .buttons.ok invoke }
}
proc cadenceLogo {} {
set logoData "
R0lGODlhgAAYAPQfAI6MjDEtLlFOT8jHx7e2tv39/RYSE/Pz8+Tj46qoqHl3d+vq62ZjY/n4+NT
T0+gXJ/BhbN3d3fzk5vrJzR4aG3Fubz88PVxZWp2cnIOBgiIeH769vtjX2MLBwSMfIP///yH5BA
EAAB8AIf8LeG1wIGRhdGF4bXD/P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIe
nJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtdGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1w
dGs9IkFkb2JlIFhNUCBDb3JlIDU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AFBtIWIttZEQIwMzfEXNB2PZJ0J1HIrgIQkFILjBkUgSwFuJdnj3i4pEIlg
eY+Bc0AGSRxLg4zsblkcYODiK0KNzUEk1JAkaCkjDbSc+maE5d20i3HY0zDbdh1vQyWNuJkjXnJ
C/HDbCQeTVwOYHKEJJwmR/wlBYi16KMMBOHTnClZpjmpAYUh0GGoyJMxya6KcBlieIj7IsqB0ji
5iwyyu8ZboigKCd2RRVAUTQyBAugToqXDVhwKpUIxzgyoaacILMc5jQEtkIHLCjwQUMkxhnx5I/
seMBta3cKSk7BghQAQMeqMmkY20amA+zHtDiEwl10dRiBcPoacJr0qjx7Ai+yTjQvk31aws92JZ
Q1070mGsSQsS1uYWiJeDrCkGy+CZvnjFEUME7VaFaQAcXCCDyyBYA3NQGIY8ssgU7vqAxjB4EwA
DEIyxggQAsjxDBzRagKtbGaBXclAMMvNNuBaiGAAA7"
return [image create photo -format GIF -data $logoData]
}
# create the Tk window and place it
makeWindow
# process Tk events until the window is destroyed
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.
#
#############################################################################