-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtrudeEdges.glf
301 lines (257 loc) · 11.9 KB
/
ExtrudeEdges.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
#############################################################################
#
# (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.
#
#############################################################################
# Written by J. Rhoads, 7/7/2014
# ==============================================================================
# Create extrusion of edges for trimming operations
# ==============================================================================
# This script prompts the user to select a quilt. An extrusion is then created
# from the edges of this quilt, assembled into a model, and layered into
# layer 999 for easy tracking. This operation can be very useful when trying to
# trim with a surface that doesn't intersect nicely.
#
#############################################################################
package require PWI_Glyph 2.3
pw::Script loadTk
proc ExtrudeEdges { } {
global input curSelection
wm withdraw .
set vec [pwu::Vector3 scale [pwu::Vector3 normalize $input(norm)] $input(dS)]
# If there was a valid quilt selected when script starts then don't do this section
# curSelection is already populated from retrieveQuilts proc
if { ! [array exists curSelection] ||
[llength [array get curSelection Databases]] == 0 ||
[llength $curSelection(Databases)] == 0 } {
## Selection of quilt
set text1 "Please select Quilt to extrude."
set mask [pw::Display createSelectionMask -requireDatabase {Quilts}]
set picked [pw::Display selectEntities -description $text1 \
-selectionmask $mask -single curSelection]
if {!$picked} {exit}
}
set surfs [list]
## Get initial layer states
catch { pw::Layer removeState _extrudeEdgesState }
pw::Layer saveState _extrudeEdgesState
## Change layer to 999 to contain all created entites
pw::Display isolateLayer 999
## Loop through quilts to get edges and create surfaces
set quilts $curSelection(Databases)
foreach qq $quilts {
set N [$qq getBoundaryCount]
for { set ii 1 } { $ii <= $N } {incr ii} {
set edge [$qq getBoundary $ii]
set tmp1 [pw::Surface create]
if { ! [catch {$tmp1 sweep $edge [pwu::Vector3 scale $vec 1]}] } {
lappend surfs [list $tmp1]
}
set tmp2 [pw::Surface create]
if { ! [catch {$tmp2 sweep $edge [pwu::Vector3 scale $vec -1]}] } {
lappend surfs [list $tmp2]
}
}
}
## Assemble extrusions into model
set newModel [pw::Model assemble -tolerance 0.01 $surfs]
## Restore initial layer state and cleanup, leaving layer 999 visible
pw::Layer restoreState {_extrudeEdgesState}
pw::Display showLayer 999
pw::Layer removeState {_extrudeEdgesState}
exit
}
## Create window
proc makeWindow {} {
global w input curSelection
wm title . "Extrude Edges"
label $w(LabelTitle) -text "Extrusion Parameters:" -padx 10
setTitleFont $w(LabelTitle)
frame $w(FrameMain)
label $w(LabelVector) -text "Normal Vector:" -anchor e
entry $w(EntryVector) -width 10 -bd 2 -textvariable input(norm)
label $w(LabelExtent) -text "Distance:" -padx 2 -anchor e
entry $w(EntryExtent) -width 10 -bd 2 -textvariable input(dS)
if { [array exists curSelection] &&
[llength [array get curSelection Databases]] == 2 &&
[llength $curSelection(Databases)] == 1 } {
# Set text on button to "Run" if there is already a quilt selected
button $w(ButtonSelect) -text "Run" -command { ExtrudeEdges }
} else {
# Set text on button to "Select" if a quilt needs to be selected by the user
button $w(ButtonSelect) -text "Select" -command { ExtrudeEdges }
}
button $w(ButtonCancel) -text "Cancel" -command { destroy . }
frame $w(FrameLogo) -relief sunken
label $w(Logo) -image [cadenceLogo] -bd 0 -relief flat
# set up validation after all widgets are created so that they all exist when
# validation fires the first time; if they don't all exist, updateButtons
# will fail
$w(EntryVector) configure -validate key -vcmd { validateNorm %P EntryVector }
$w(EntryExtent) configure -validate key -vcmd { validateAlpha %P EntryExtent }
# lay out the form
pack $w(LabelTitle) -side top
pack [frame .sp -bd 1 -height 2 -relief sunken] -pady 4 -side top -fill x
pack $w(FrameMain) -side top -fill both -expand 1
# lay out the form in a grid
grid $w(LabelVector) -row 1 -column 1 -sticky e -pady 3 -padx 3
grid $w(EntryVector) -row 1 -column 2 -sticky w -pady 3 -padx 3
grid $w(LabelExtent) -row 2 -column 1 -sticky e -pady 3 -padx 3
grid $w(EntryExtent) -row 2 -column 2 -sticky w -pady 3 -padx 3
grid $w(ButtonSelect) -row 3 -column 1 -pady 3
grid $w(ButtonCancel) -row 3 -column 2 -pady 3
grid columnconfigure $w(FrameMain) 1 -weight 1
# give all extra space to the second (last) column
grid columnconfigure $w(FrameMain) 1 -weight 1
grid columnconfigure $w(FrameMain) 2 -weight 1
pack $w(FrameLogo) -fill x -side bottom -padx 2 -pady 4 -anchor s
grid $w(Logo) -columnspan 2
bind . <Key-Escape> { $w(ButtonCancel) invoke }
bind . <Control-Key-Return> { $w(ButtonSelect) invoke }
bind . <Control-Key-f> { $w(ButtonSelect) invoke }
}
## Set up defaults for window
set color(Valid) "white"
set color(Invalid) "misty rose"
set input(norm) {1 0 0}
set input(dS) 0.01
set w(LabelTitle) .title
set w(FrameMain) .main
set w(LabelVector) $w(FrameMain).ldim
set w(EntryVector) $w(FrameMain).edim
set w(LabelExtent) $w(FrameMain).lext
set w(EntryExtent) $w(FrameMain).eext
set w(ButtonSelect) $w(FrameMain).select
set w(ButtonCancel) $w(FrameMain).bcancel
set w(FrameLogo) .fbuttons
set w(Logo) $w(FrameLogo).cadencelogo
# dimension field validation
proc validateNorm { norm widget } {
global w color
set flag 0
if {[llength $norm]==3} {
foreach dim $norm {
if { ![string is double -strict $dim] } {
incr flag
}
}
if {$flag==0} {
if { [pwu::Vector3 length $norm] > 0 } {
$w($widget) configure -background $color(Valid)
} else {
$w($widget) configure -background $color(Invalid)
}
} else {
$w($widget) configure -background $color(Invalid)
}
} else {
$w($widget) configure -background $color(Invalid)
}
updateButtons
return 1
}
# extent field validation
proc validateAlpha { alpha widget } {
global w color
if { [string is double -strict $alpha] && $alpha > 0 } {
$w($widget) configure -background $color(Valid)
} else {
$w($widget) configure -background $color(Invalid)
}
updateButtons
return 1
}
# return true if none of the entry fields are marked invalid
proc canCreate { } {
global w color
return [expr \
[string equal -nocase [$w(EntryVector) cget -background] $color(Valid)] &&\
[string equal -nocase [$w(EntryExtent) cget -background] $color(Valid)]]
}
# enable/disable action buttons based on current settings
proc updateButtons { } {
global w infoMessage
if { [canCreate] } {
$w(ButtonSelect) configure -state normal
} else {
$w(ButtonSelect) configure -state disabled
}
update
}
# set the font for the input widget to be bold and 1.5 times larger than
# the default font
proc setTitleFont { l } {
global titleFont
if { ! [info exists titleFont] } {
set fontSize [font actual TkCaptionFont -size]
set titleFont [font create -family [font actual TkCaptionFont -family] \
-weight bold -size [expr {int(1.5 * $fontSize)}]]
}
$l configure -font $titleFont
}
###############################################################################
# cadenceLogo: Define Cadence Design Systems logo
###############################################################################
proc cadenceLogo {} {
set logoData {
R0lGODlhgAAYAPQfAI6MjDEtLlFOT8jHx7e2tv39/RYSE/Pz8+Tj46qoqHl3d+vq62ZjY/n4+NT
T0+gXJ/BhbN3d3fzk5vrJzR4aG3Fubz88PVxZWp2cnIOBgiIeH769vtjX2MLBwSMfIP///yH5BA
EAAB8AIf8LeG1wIGRhdGF4bXD/P3hw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2oIy5RHrHr1qlOsw0AePwrsj47HFysrYpcBFcF1w8Mk2ti7wUaDRgg1EISNXVwF
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]
}
################################################################################
# Test if quilts were selected before script starts
################################################################################
pw::Display getSelectedEntities -selectionmask [pw::Display createSelectionMask -requireDatabase {Quilts}] curSelection
makeWindow
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.
#
#############################################################################