40093367 |
1 | # File : begin |
2 | |
3 | # to prevent loops limit to 10 minutes |
4 | cpulimit 600 |
5 | |
6 | if { [array get Draw_Groups "TOPOLOGY Fillet construction commands"] == "" } { |
7 | pload TOPTEST |
8 | } |
9 | |
40093367 |
10 | # This procedure tries to load an EDGE (one point) or EDGE (two points) |
11 | proc get_element { type args } { |
12 | # First point |
13 | set x [lindex $args 0] |
14 | set y [lindex $args 1] |
15 | set z [lindex $args 2] |
16 | |
17 | # Second point if necessary |
18 | if { [string compare $type "FACE"] == 0 } { |
19 | set x1 [lindex $args 3] |
20 | set y1 [lindex $args 4] |
21 | set z1 [lindex $args 5] |
22 | |
23 | } else { |
24 | set x1 $x |
25 | set y1 $y |
26 | set z1 $z |
27 | } |
28 | |
29 | global ver |
30 | vertex ver $x $y $z |
31 | global dd |
32 | global dd_val |
33 | set res {} |
34 | |
35 | # Try to find element with points inside a bounding box |
36 | foreach element [directory] { |
37 | global $element |
38 | distmini dd ver $element |
39 | if { [string match "*$type*" [whatis $element]] } { |
1f26f80b |
40 | set bbox [bounding $element -save xx1 yy1 zz1 xx2 yy2 zz2 ] |
40093367 |
41 | # Get distance |
1a0339b4 |
42 | set dv [lindex [dump dd_val] 5] |
43 | if {[expr {[dval xx1-1e-2] <= $x && $x <= [dval xx2+1e-2] |
44 | && [dval yy1-1e-2] <= $y && $y <= [dval yy2+1e-2] |
45 | && [dval zz1-1e-2] <= $z && $z <= [dval zz2+1e-2] |
46 | && [dval xx1-1e-2] <= $x1 && $x1 <= [dval xx2+1e-2] |
47 | && [dval yy1-1e-2] <= $y1 && $y1 <= [dval yy2+1e-2] |
48 | && [dval zz1-1e-2] <= $z1 && $z1 <= [dval zz2+1e-2] |
40093367 |
49 | }] |
50 | } { |
51 | if { [llength $res] == 0 } { |
52 | lappend res $element |
53 | lappend res $dv |
54 | } else { |
55 | if { [lindex $res 1] > $dv } { |
56 | lset res 0 $element |
57 | lset res 1 $dv |
58 | } |
59 | } |
60 | # return $element |
61 | } |
62 | } |
63 | } |
64 | |
65 | unset dd |
66 | if { [llength $res] != 0 } { |
67 | return [lindex $res 0] |
68 | } |
69 | |
70 | set error "Error : $type is not found at $x $y $z" |
71 | if { [string compare $type "FACE"] == 0 } { |
72 | set error "$error and $x1 $y1 $z1" |
73 | } |
74 | |
75 | puts $error |
76 | return "" |
77 | } |
78 | |
79 | # Compute chamfer sequentially |
80 | # The edge and face numbers are changed after each step. |
81 | # It is necessary to compute new names on result shape after each camf command. |
82 | proc chamf_sequence { args } { |
83 | set len [llength $args] |
84 | if { $len == 1 } { |
85 | set args [lindex $args 0] |
86 | set len [llength $args] |
87 | } |
88 | set chamfer_list {} |
89 | set chamf_current {} |
90 | set result_shape [lindex $args 0] |
91 | set shape_edges [lindex $args 1] |
92 | set shape_faces [lindex $args 2] |
93 | |
1d54b807 |
94 | global group |
40093367 |
95 | global chamf_edge_face |
96 | global chamf_type |
97 | global chamf_parameters |
98 | |
99 | global $result_shape |
100 | foreach d [directory] { |
101 | global $d |
102 | } |
103 | |
104 | set len [llength $chamf_edge_face] |
105 | for {set i 0} {$i < $len} {incr i} { |
7b5e532f |
106 | # Numbers of EDGE and FACE in initial shape for step $i |
40093367 |
107 | set ef [lindex $chamf_edge_face $i] |
108 | # Parameters of chamfer for step $i |
109 | set p [lindex $chamf_parameters $i] |
110 | |
111 | # Name of EDGE in initial shape |
112 | set stre "${shape_edges}_[lindex $ef 0]" |
113 | # Name of FACE in initial shape |
114 | set strf "${shape_faces}_[lindex $ef 1]" |
115 | # Get a Cender of gravity for each element and compute new names of on each step. |
116 | # get_element procedure tries to find an element with Cender of gravity inside an bounding box. |
117 | foreach name [list EDGE FACE] { |
118 | if { [string compare $name "EDGE"] == 0 } { |
119 | set props [lprops $stre] |
120 | if { [llength $chamf_current] != 0 } { |
121 | lappend chamfer_list $chamf_current |
122 | set chamf_current {} |
123 | } |
124 | lappend chamf_current $result_shape |
125 | lappend chamf_current $shape_edges |
126 | } else { |
127 | set props [sprops $strf] |
128 | } |
129 | if { [regexp {Center of gravity[^0-9=]+= +([-0-9.+eE]+)[^0-9=]+= +([-0-9.+eE]+)[^0-9=]+= +([-0-9.+eE]+)} $props full x y z] } { |
130 | # New names of element will be computed dynamically on each step. |
131 | if { [string compare $name "EDGE"] == 0 } { |
132 | lappend chamf_current "\[get_element $name $x $y $z\]" |
133 | # Save EDGE center for get_element command with FACE argument. |
134 | set x1 $x |
135 | set y1 $y |
136 | set z1 $z |
137 | } else { |
1d54b807 |
138 | if { [string compare $group "equal_dist"] != 0 } { |
40093367 |
139 | lappend chamf_current "\[get_element $name $x $y $z $x1 $y1 $z1\]" |
1d54b807 |
140 | } |
40093367 |
141 | } |
142 | } |
143 | } |
144 | if { [string compare $chamf_type ""] != 0} { |
145 | lappend chamf_current $chamf_type |
146 | } |
147 | foreach pe $p { |
148 | lappend chamf_current $pe |
149 | } |
150 | } |
151 | lappend chamfer_list $chamf_current |
152 | foreach chamf_current $chamfer_list { |
153 | # Compute new name of EDGE |
154 | lset chamf_current 2 [expr [lindex $chamf_current 2]] |
155 | # Compute new name of FACE |
1d54b807 |
156 | if { [string compare $group "equal_dist"] != 0 } { |
40093367 |
157 | lset chamf_current 3 [expr [lindex $chamf_current 3]] |
1d54b807 |
158 | } |
40093367 |
159 | |
160 | set str "chamf $chamf_current" |
161 | puts $str |
162 | # Compute chamfer |
163 | set failed [catch $str res] |
164 | if { $failed } { |
165 | puts "Error : chamfer is not done. $res" |
166 | # Save previous shape in new name |
167 | renamevar $shape_edges $result_shape |
168 | } |
169 | # Delete temporary edges and faces |
170 | foreach str [directory] { |
171 | set type [whatis $str] |
172 | set is_edge [string match "*EDGE*" $type] |
173 | set is_face [string match "*FACE*" $type] |
174 | if { $is_edge || $is_face } { |
175 | unset $str |
176 | } |
177 | } |
178 | if { $failed == 0 } { |
179 | unset $shape_edges |
180 | } |
181 | # Allow to use exploded elements on next step |
182 | set nb [countshapes $result_shape] |
183 | regexp {EDGE[^0-9]+([0-9]+)} $nb full nbedges |
184 | regexp {FACE[^0-9]+([0-9]+)} $nb full nbfaces |
185 | for {set j 1} {$j <= $nbedges} {incr j} { |
186 | global "${result_shape}_$j" |
187 | } |
188 | for {set j 1} {$j <= $nbfaces} {incr j} { |
189 | global "${shape_edges}_$j" |
190 | } |
191 | explode $result_shape E |
192 | renamevar $result_shape $shape_edges |
193 | explode $shape_edges F |
194 | } |
195 | # Save result shape in new name |
196 | renamevar $shape_edges $result_shape |
197 | } |
198 | |
199 | # Compute chamfer at one command or sequentially |
200 | proc compute_chamf { args } { |
201 | global command |
1d54b807 |
202 | global group |
40093367 |
203 | if { [string compare $command "chamf_sequence"] == 0 } { |
204 | chamf_sequence $args |
205 | } else { |
206 | set len [llength $args] |
207 | set result_shape [lindex $args 0] |
208 | set shape_edges [lindex $args 1] |
209 | set shape_faces [lindex $args 2] |
210 | |
211 | global chamf_edge_face |
212 | global chamf_type |
213 | global chamf_parameters |
214 | |
215 | global $result_shape |
216 | foreach d [directory] { |
217 | global $d |
218 | } |
219 | |
220 | set chamf_str "chamf $result_shape $shape_edges" |
221 | |
222 | set len [llength $chamf_edge_face] |
223 | for {set i 0} {$i < $len} {incr i} { |
224 | set ef [lindex $chamf_edge_face $i] |
225 | set p [lindex $chamf_parameters $i] |
1d54b807 |
226 | if { [string compare $group "equal_dist"] == 0 } { |
227 | set chamf_str "${chamf_str} ${shape_edges}_[lindex $ef 0] $p" |
228 | } else { |
229 | set chamf_str "${chamf_str} ${shape_edges}_[lindex $ef 0] ${shape_faces}_[lindex $ef 1] $chamf_type $p" |
230 | } |
40093367 |
231 | } |
232 | |
233 | puts $chamf_str |
234 | # Compute chamfer in one command |
235 | if { [catch "$chamf_str" res] } { |
236 | puts "Error : chamfer is not done. $res" |
237 | renamevar $shape_edges $result_shape |
238 | } |
239 | } |
240 | } |