-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSplitConsAtIntersection.glf
312 lines (257 loc) · 9.92 KB
/
SplitConsAtIntersection.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
#############################################################################
#
# (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.
#
#############################################################################
#
# ============================================================================
# SPLIT CONNECTORS AT THEIR POINT OF INTERSECTION
# ============================================================================
# Written by: Zach Davis, Pointwise, Inc.
#
# This script prompts users to select two connectors they wish to split at
# common intersection points. The connectors are then converted to database
# curves, their points of intersection are determined, and then the original
# connectors are split using these points. Finally, the database curves and
# their points of intersection are deleted.
#
# --------------------------------------------------------
# -- INITIALIZATION
# --
# -- Load Glyph package, initialize Pointwise, and
# -- define the working directory.
# --
# --------------------------------------------------------
# Load Glyph and Tcl Libraries
package require PWI_Glyph
# Define Working Directory
set scriptDir [file dirname [info script]]
# --------------------------------------------------------
# -- USER-DEFINED PARAMETERS
# --
# -- Define a set of user-controllable settings.
# --
# --------------------------------------------------------
# --------------------------------------------------------
# -- SUBROUTINES
# --
# -- Define subroutines for frequent tasks.
# --
# --------------------------------------------------------
# Computes the Set Containing the Difference of Set1 and Set2
proc difference { set1 set2 } {
foreach item $set1 {
set found 0
if { [lsearch -exact $set2 $item] < 0 } {
set found 1
}
if { $found } {
lappend set3 $item
}
}
if { [info exists set3] } {
return $set3
} else {
return 1
}
}
# Query the System Clock
proc timestamp {} {
puts [clock format [clock seconds] -format "%a %b %d %Y %l:%M:%S%p %Z"]
}
# Query the System Clock (ISO 8601 formatting)
proc timestamp_iso {} {
puts [clock format [clock seconds] -format "%G-%m-%dT%T%Z"]
}
# Convert Time in Seconds to h:m:s Format
proc convSeconds { time } {
set h [expr { int(floor($time/3600)) }]
set m [expr { int(floor($time/60)) % 60 }]
set s [expr { int(floor($time)) % 60 }]
return [format "%02d Hours %02d Minutes %02d Seconds" $h $m $s]
}
# --------------------------------------------------------
# -- MAIN ROUTINE
# --
# -- Main meshing procedure:
# -- Acquire Connectors from User Selection
# -- Create Database Curves from Connectors
# -- Determine Points of Intersection Between Database
# Curves
# -- Split Connectors at Intersection Points
# -- Delete Database Curves & Intersection Points
# --------------------------------------------------------
# Start Time
set tBegin [clock seconds]
timestamp
# Acquire Connectors from User Selection
set prompt1 "Please select 2 connectors to split at their intersection."
set prompt2 "Please select only 2 connectors."
set conMask [pw::Display createSelectionMask -requireConnector {}]
if { ![pw::Display getSelectedEntities -selectionmask $conMask userCons] } {
puts "No active selection"
set numCons 0
while { $numCons != 2 } {
set conSelection [pw::Display selectEntities -description $prompt1 \
-selectionmask $conMask userCons]
set numCons [llength $userCons(Connectors)]
if { $numCons < 1 } {
puts "User canceled selection."
exit
}
if { $numCons != 2 } {
puts "Please select 2 connectors to split at their intersection."
}
}
} elseif { [llength $userCons(Connectors)] > 1 } {
set numCons [llength $userCons(Connectors)]
while { $numCons != 2 } {
set conSelection [pw::Display selectEntities -description $prompt2 \
-selectionmask $conMask userCons]
set numCons [llength $userCons(Connectors)]
if { $numCons < 1 } {
puts "User canceled selection."
exit
}
}
}
set conFirst [lindex $userCons(Connectors) 0]
set conSecond [lindex $userCons(Connectors) 1]
# Create Database Curves from Connectors
set dbCurves [list]
foreach con $userCons(Connectors) {
set db [pw::Curve create]
set name "converted_"
append name [$con getName]
$db setName $name
set numSegs [$con getSegmentCount]
for { set i 1 } { $i <= $numSegs } { incr i } {
set conSeg [$con getSegment $i]
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 numPts [$conSeg getPointCount]
for { set j 1 } { $j <= $numPts } { incr j } {
$dbSeg addPoint [$conSeg getPoint $j]
}
$dbSeg setSlope [$conSeg getSlope]
if { [$conSeg getSlope] eq "Free" } {
for { set j 2 } { $j <= $numPts } { incr j } {
$dbSeg setSlopeIn $j [$conSeg getSlopeIn $j]
}
for { set j 1 } { $j < $numPts } { incr j } {
$dbSeg setSlopeOut $j [$conSeg getSlopeOut $j]
}
}
}
pw::SegmentSurfaceSpline {
set numPts [$conSeg getPointCount]
for { set j 1 } { $j <= $numPts } { incr j } {
$dbSeg addPoint [$conSeg getPoint $j]
}
$dbSeg setSlope [$conSeg getSlope]
if { [$conSeg getSlope] eq "Free" } {
for { set j 2 } { $j <= $numPts } { incr j } {
$dbSeg setSlopeIn $j [$conSeg getSlopeIn $j]
}
for { set j 1 } { $j < $numPts } { incr j } {
$dbSeg setSlopeOut $j [$conSeg getSlopeOut $j]
}
}
}
default {
}
}
$db addSegment $dbSeg
}
lappend dbCurves $db
}
# Determine Points of Intersection between Database Curves
set curve1Pt1 [[lindex $dbCurves 0] getXYZ -parameter 0]
set curve1Pt2 [[lindex $dbCurves 0] getXYZ -parameter 1]
set curve2Pt1 [[lindex $dbCurves 1] getXYZ -parameter 0]
set curve2Pt2 [[lindex $dbCurves 1] getXYZ -parameter 1]
set intPts [pw::Database intersect $dbCurves]
# Split Connectors at Intersection Points
foreach point $intPts {
set pointTest1 [difference $curve1Pt1 [$point getXYZ]]
set pointTest2 [difference $curve1Pt2 [$point getXYZ]]
set pointTest3 [difference $curve2Pt1 [$point getXYZ]]
set pointTest4 [difference $curve2Pt2 [$point getXYZ]]
set x [pwu::Vector3 x [$point getXYZ]]
set y [pwu::Vector3 y [$point getXYZ]]
set z [pwu::Vector3 z [$point getXYZ]]
if { ($pointTest1=="1") || ($pointTest2== "1") } {
$conSecond closestPoint -parameter conFirstSpltPt [list $x $y $z]
$conSecond split [list $conSecondSpltPt]
} elseif { ($pointTest3=="1") || ($pointTest4=="1") } {
$conFirst closestPoint -parameter conFirstSpltPt [list $x $y $z]
$conFirst split [list $conFirstSpltPt]
} else {
$conFirst closestPoint -parameter conFirstSpltPt [list $x $y $z]
$conSecond closestPoint -parameter conSecondSpltPt [list $x $y $z]
$conFirst split [list $conFirstSpltPt]
$conSecond split [list $conSecondSpltPt]
}
}
# Delete Database Curves & Intersection Points
foreach curve $dbCurves {
$curve delete
}
foreach pt $intPts {
$pt delete
}
timestamp
puts "Run time: [convSeconds [pwu::Time elapsed $tBegin]]"
#############################################################################
#
# 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.
#
#############################################################################