forked from pointwise/ConvertGridToDatabase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConvertGridToDatabase.glf
404 lines (351 loc) · 14 KB
/
ConvertGridToDatabase.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
#############################################################################
#
# (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.
#
#############################################################################
################################################################################
# This script can be used to turn domains into database surfaces or turn
# connectors into database curves.
################################################################################
package require PWI_Glyph 2.3
pw::Script loadTk
# initialize globals
set databaseSourceEntity "connector"
set splineResult 0
# widget hierarchy
set w(LabelTitle) .title
set w(FrameMain) .main
set w(ConButton) $w(FrameMain).conbutton
set w(DomButton) $w(FrameMain).dombutton
set w(SplineCheck) $w(FrameMain).splinecheck
set w(FrameButtons) .fbuttons
set w(Logo) $w(FrameButtons).logo
set w(OkButton) $w(FrameButtons).okbutton
set w(CancelButton) $w(FrameButtons).cancelbutton
# procedure to let the user select domains with which to work
# returns a list of the selected domains
proc selectDomains {} {
set domMask [pw::Display createSelectionMask -requireDomain [list]]
pw::Display selectEntities \
-description "Select the domains you would like to convert." \
-selectionmask $domMask selection
return $selection(Domains)
}
# procedure to let the user select connectors with which to work
# returns a list of such connectors
proc selectConnectors { } {
set conMask [pw::Display createSelectionMask -requireConnector [list] \
-blockConnector "Pole"]
pw::Display selectEntities \
-description "Select the connectors you would like to convert." \
-selectionmask $conMask selection
set cons $selection(Connectors)
}
# procedure to get the structured domains from the list (returns as list)
proc getStructuredDomains { domains } {
set structured [list]
foreach dom $domains {
if {[$dom getType] eq "pw::DomainStructured"} {
lappend structured $dom
}
}
return $structured
}
# procedure to get the unstructured domains from the list (returns as list)
proc getUnstructuredDomains { domains } {
set unstructured [list]
foreach dom $domains {
if {[$dom getType] eq "pw::DomainUnstructured"} {
lappend unstructured $dom
}
}
return $unstructured
}
# convert structured domains
proc convertStructuredDomains { doms } {
if { [llength $doms] == 0 } {
return [list]
}
set structuredFile [file join [file dirname [info script]] \
"convertToDatabaseTempStructured.x"]
set entities [list]
foreach dom $doms {
# save structured domains to file
set mode [pw::Application begin GridExport $dom]
$mode initialize -type PLOT3D $structuredFile
if {![$mode verify]} {
$mode abort
return -code error "Verification failed"
}
$mode write
$mode end
set entity [pw::Database import -type PLOT3D $structuredFile]
set name "converted_"
append name [$dom getName]
$entity setName $name
lappend entities $entity
}
# delete structured domain file
file delete $structuredFile
return $entities
}
# convert unstructured domains
proc convertUnstructuredDomains { doms } {
if { [llength $doms] == 0 } {
return [list]
}
set unstructuredFile [file join [file dirname [info script]] \
"convertToDatabaseTempUnstructured.stl"]
set entities [list]
# loop through domains; for unstructured with STL
# (if done all at once will come back as one domain)
foreach dom $doms {
# save unstructured domains to file
set mode [pw::Application begin GridExport $dom]
$mode initialize -type STL $unstructuredFile
if {![$mode verify]} {
$mode abort
return -code error "Verification failed"
}
$mode write
$mode end
set entity [pw::Database import -type STL $unstructuredFile]
set name "converted_"
append name [$dom getName]
$entity setName $name
lappend entities $entity
}
# delete unstructured domain file
file delete $unstructuredFile
return $entities
}
proc convertCons { cons } {
set dbs [list]
foreach con $cons {
set db [pw::Curve create]
set name "converted_"
append name [$con getName]
$db setName $name
set nsegs [$con getSegmentCount]
for { set iseg 1 } { $iseg <= $nsegs } { incr iseg } {
set conseg [$con getSegment $iseg]
set dbseg [[$conseg getType] create]
switch [$conseg getType] {
pw::SegmentCircle {
$dbseg addPoint [$conseg getPoint 1]
$dbseg addPoint [$conseg getPoint 2]
switch [$conseg getAlternatePointType] {
Shoulder {
$dbseg setShoulderPoint [$conseg getShoulderPoint] \
[$conseg getNormal]
}
Center {
$dbseg setCenterPoint [$conseg getCenterPoint] [$conseg getNormal]
}
Angle {
$dbseg setAngle [$conseg getAngle] [$conseg getNormal]
}
EndAngle {
$dbseg setEndAngle [$conseg getAngle] [$conseg getNormal]
}
default {
}
}
}
pw::SegmentConic {
$dbseg addPoint [$conseg getPoint 1]
$dbseg addPoint [$conseg getPoint 2]
switch [$conseg getAlternatePointType] {
Shoulder {
$dbseg setShoulderPoint [$conseg getShoulderPoint]
}
Intersect {
$dbseg setIntersectPoint [$conseg getIntersectPoint]
}
default {
}
}
$dbseg setRho [$conseg getRho]
}
pw::SegmentSpline {
set npts [$conseg getPointCount]
for { set ipt 1 } { $ipt <= $npts } { incr ipt } {
$dbseg addPoint [$conseg getPoint $ipt]
}
$dbseg setSlope [$conseg getSlope]
if { [$conseg getSlope] eq "Free" } {
for { set ipt 2 } { $ipt <= $npts } { incr ipt } {
$dbseg setSlopeIn $ipt [$conseg getSlopeIn $ipt]
}
for { set ipt 1 } { $ipt < $npts } { incr ipt } {
$dbseg setSlopeOut $ipt [$conseg getSlopeOut $ipt]
}
}
}
pw::SegmentSurfaceSpline {
set npts [$conseg getPointCount]
for { set ipt 1 } { $ipt <= $npts } { incr ipt } {
$dbseg addPoint [$conseg getPoint $ipt]
}
$dbseg setSlope [$conseg getSlope]
if { [$conseg getSlope] eq "Free" } {
for { set ipt 2 } { $ipt <= $npts } { incr ipt } {
$dbseg setSlopeIn $ipt [$conseg getSlopeIn $ipt]
}
for { set ipt 1 } { $ipt < $npts } { incr ipt } {
$dbseg setSlopeOut $ipt [$conseg getSlopeOut $ipt]
}
}
}
default {
}
}
$db addSegment $dbseg
}
lappend dbs $db
}
}
# respond to ok being pressed
proc okAction { } {
if {$::databaseSourceEntity eq "connector"} {
set cons [selectConnectors ]
convertCons $cons
} else {
set doms [selectDomains ]
if {[catch {
set structured [getStructuredDomains $doms]
set entities [convertStructuredDomains $structured]
set unstructured [getUnstructuredDomains $doms]
lappend entities [convertUnstructuredDomains $unstructured]
if {$::splineResult} {
foreach entity $entities {
if { ! ($entity eq "") } {
if { [$entity getType] eq "pw::Curve" \
|| [$entity getType] eq "pw::Surface" } {
$entity spline
}
}
}
}
}]} { ;# catch section below
puts "Verification failed. Some of your entities could not be converted."
}
}
}
# 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
}
# load a GIF image from a file in base-64 encoded form
# proc loadImage { fname } {
# set fd [open [file join [file dirname [info script]] $fname] r]
# set data [read -nonewline $fd]
# return [image create photo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XDSxAdHetYIlkNDMAqJngxS47GESZ6DSiwDUNHvDd0KkhQJcIEOMlGkbhJlAK/0a8
NLDhUDdX914A+AWAkaJEOg0U/ZCgXgCGHxbAS4lXxketJcbO/aCgZi4SC34dK9CKoouxFT8cBNz
Q3K2+I/RVxXfAnIE/JTDUBC1k1S/SJATl+ltSxEcKAlJV2ALFBOTMp8f9ihVjLYUKTa8Z6GBCAF
rMN8Y8zPrZYL2oIy5RHrHr1qlOsw0AePwrsj47HFysrYpcBFcF1w8Mk2ti7wUaDRgg1EISNXVwF
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]
}
# build the user interface
proc makeWindow { } {
global w opt
# create the widgets
label $w(LabelTitle) -text "Convert Entities From Grid To Database"
setTitleFont $w(LabelTitle)
frame $w(FrameMain)
radiobutton $w(ConButton) -text "Convert connectors" \
-variable databaseSourceEntity -value connector -anchor w \
-command { $w(SplineCheck) configure -state disabled }
radiobutton $w(DomButton) -text "Convert domains" \
-variable databaseSourceEntity -value domain -anchor w \
-command { $w(SplineCheck) configure -state normal }
checkbutton $w(SplineCheck) -text "Spline resulting surfaces" \
-variable splineResult -anchor w -padx 20 -state disabled
frame $w(FrameButtons) -relief sunken
label $w(Logo) -image [cadenceLogo] -bd 0 -relief flat
button $w(OkButton) -text "OK" -width 12 -bd 2 \
-command { wm withdraw . ; okAction ; exit }
button $w(CancelButton) -text "Cancel" -width 12 -bd 2 \
-command { exit }
# 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(ConButton) -sticky ew -pady 3 -padx 3
grid $w(DomButton) -sticky ew -pady 3 -padx 3
grid $w(SplineCheck) -sticky ew -pady 3 -padx 3
# lay out buttons
pack $w(CancelButton) $w(OkButton) -pady 3 -padx 3 -side right
pack $w(Logo) -side left -padx 5
# give extra space to (only) column
grid columnconfigure $w(FrameMain) 1 -weight 1
pack $w(FrameButtons) -fill x -side bottom -padx 2 -pady 4 -anchor s
focus $w(ConButton)
raise .
# don't allow window to resize
wm resizable . 0 0
}
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.
#
#############################################################################