973c2be1 |
1 | # Copyright (c) 1999-2014 OPEN CASCADE SAS |
2 | # |
3 | # This file is part of Open CASCADE Technology software library. |
4 | # |
d5f74e42 |
5 | # This library is free software; you can redistribute it and/or modify it under |
6 | # the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
7 | # by the Free Software Foundation, with special exception defined in the file |
8 | # OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | # distribution for complete text of the license and disclaimer of any warranty. |
10 | # |
11 | # Alternatively, this file may be used under the terms of Open CASCADE |
12 | # commercial license or contractual agreement. |
13 | |
f767df4e |
14 | ########################### |
15 | # # |
16 | # Version 1.4 # |
17 | # by SZV # |
18 | # # |
19 | ########################### |
20 | # |
21 | # Open : double-clic or + |
22 | # Close : double-clic or - |
23 | # Refresh tree : close top level and re-open |
24 | # |
25 | # Attributes: |
26 | # white : interoperable |
27 | # white + c : non interoperable |
28 | # X : X Reference |
29 | # Red : not yet commited in transaction #0 |
30 | # |
31 | # |
32 | |
33 | proc __update { args } { |
34 | } |
35 | |
36 | proc dftree { DDF_Browser } { |
37 | |
38 | global env |
39 | global DFTREE_WINDOWS |
40 | global DFTREE_GLOBALS |
41 | global $DDF_Browser |
42 | |
43 | puts $DDF_Browser |
44 | |
45 | package require Tk |
46 | |
47 | ## Create images |
48 | set DFTREE_GLOBALS(ImageLabel) [DFOpenImage dfb_folder.gif] |
49 | set DFTREE_GLOBALS(ImageAttrOther) [DFOpenImage dfb_attribute.gif] |
50 | set DFTREE_GLOBALS(ImageAttrNS) [DFOpenImage dfb_attribns.gif] |
51 | |
52 | ## set DFTREE_LabelStyle [tixDisplayStyle imagetext \ |
53 | ## -font 9x15bold \ |
54 | ## -background Bisque3 \ |
55 | ## ] |
56 | |
57 | ## set DFTREE_LabelStyle1 [tixDisplayStyle imagetext \ |
58 | ## -font 9x15bold \ |
59 | ## -background Bisque3 \ |
60 | ## -foreground SeaGreen2 \ |
61 | ## ] |
62 | |
63 | ## set DFTREE_AttributeStyle [tixDisplayStyle imagetext \ |
64 | ## -font 9x15 \ |
65 | ## -background Bisque3 \ |
66 | ## ] |
67 | |
68 | ## set DFTREE_AttributeStyle1 [tixDisplayStyle imagetext \ |
69 | ## -font 9x15 \ |
70 | ## -background Bisque3 \ |
71 | ## -foreground DarkGreen \ |
72 | ## ] |
73 | |
74 | ## set DFTREE_AttributeStyle2 [tixDisplayStyle imagetext \ |
75 | ## -font 9x15 \ |
76 | ## -background Bisque3 \ |
77 | ## -foreground Red \ |
78 | ## ] |
79 | |
80 | set w .$DDF_Browser |
81 | toplevel $w -height 400 -width 700 -background bisque3 |
82 | |
83 | ######## |
84 | # Tree # |
85 | ######## |
86 | |
87 | set tree1 [ttk::treeview $w.tree -show tree] |
88 | $tree1 tag bind Label <<TreeviewOpen>> [list DFTREE:Tree:Open $DDF_Browser $w] |
89 | $tree1 tag configure Label -font 9x15bold -foreground DarkGreen |
90 | #$tree1 tag configure Attribute -font 9x15 -background bisque3 |
91 | #$tree1 tag configure AttributeList -font 9x15 -background bisque3 |
92 | pack $tree1 -expand yes -fill both -padx 4 -pady 4 |
93 | |
94 | # to see different fonts: /usr/openwin/lib/X11/fonts/misc or xlsfonts? |
95 | # 8x13 8x13bold 9x15 9x15bold |
96 | # hlist.font 8x13bold |
97 | # hlist.gap "15" |
98 | # hlist.indent "30" |
99 | |
100 | set DFTREE_WINDOWS($w,tree) $tree1 |
101 | set DFTREE_WINDOWS($w,root) [$tree1 insert {} end \ |
102 | -text $DDF_Browser \ |
103 | -values "" \ |
104 | -tags Label] |
105 | |
106 | # Here we need to open first node! |
107 | |
108 | return |
109 | } |
110 | |
111 | ############################################################################### |
112 | # |
113 | # |
114 | proc DFTREE:Tree:Open { DDF_Browser w } { |
115 | |
116 | global DFTREE_WINDOWS |
117 | global DFTREE_GLOBALS |
118 | global $DDF_Browser |
119 | |
120 | set df_tree $DFTREE_WINDOWS($w,tree) |
121 | set df_node [$df_tree focus] |
122 | |
123 | #if {$df_node == $DFTREE_WINDOWS($w,root)} { |
124 | # This is root |
125 | set chdlist [$df_tree children $df_node] |
126 | if {$chdlist != {}} { |
127 | # The root branch already exists in hlist. |
128 | # Clear all its children to force the tree to be updated. |
129 | $df_tree delete $chdlist |
130 | } |
131 | #} |
132 | |
133 | #update |
134 | DFTREE:Tree:Fill $DDF_Browser $df_tree $df_node |
135 | return |
136 | } |
137 | |
138 | ############################################################################### |
139 | # |
140 | # |
141 | proc DFTREE:Tree:Fill { DDF_Browser df_tree df_node } { |
142 | |
143 | global DFTREE_GLOBALS |
144 | global $DDF_Browser |
145 | |
146 | set loc [lindex [$df_tree item $df_node -values] 0] |
147 | set type [lindex [$df_tree item $df_node -tags] 0] |
148 | |
149 | switch -glob $type { |
150 | |
151 | Label { |
152 | DFTREE:Tree:UpdateLabel $DDF_Browser $df_tree $df_node $loc |
153 | } |
154 | |
155 | #AttributeList { |
156 | # DFTREE:Tree:UpdateAttributeList $DDF_Browser $df_tree $df_node $loc |
157 | #} |
158 | |
159 | default { |
160 | } |
161 | } |
162 | return |
163 | } |
164 | |
165 | ############################################################################### |
166 | # $df_entry is a label entry, "1:3:2" for example, or "" for root. |
167 | # |
168 | proc DFTREE:Tree:UpdateLabel { DDF_Browser df_tree df_node df_entry } { |
169 | |
170 | global DFTREE_GLOBALS |
171 | global $DDF_Browser |
172 | |
173 | foreach fullname [split [DFOpenLabel $DDF_Browser $df_entry] "\\" ] { |
174 | FCTREE:Tree:DecodeLabelItem $DDF_Browser $df_tree $df_node $df_entry $fullname |
175 | } |
176 | return |
177 | } |
178 | |
179 | ############################################################################### |
180 | # |
181 | # |
182 | proc DFTREE:Tree:UpdateAttributeList { DDF_Browser df_tree df_node df_entry} { |
183 | |
184 | global DFTREE_GLOBALS |
185 | global $DDF_Browser |
186 | |
187 | set image_other $DFTREE_GLOBALS(ImageAttrOther) |
188 | set image_ns $DFTREE_GLOBALS(ImageAttrNS) |
189 | #set xrefimage $DFTREE_GLOBALS(ImageAttrOther) |
190 | |
191 | # abv: index attributes |
192 | set num 0 |
193 | set attributes [split [DFOpenAttributeList $DDF_Browser $df_entry ] "\\" ] |
194 | set iattributes {} |
195 | foreach fullname $attributes { |
196 | set num [expr $num + 1] |
197 | lappend fullname $num |
198 | lappend iattributes $fullname |
199 | } |
200 | |
201 | foreach fullname [lsort $iattributes] { |
202 | |
203 | # Information first split |
204 | set tmplist [split $fullname " "] |
205 | set name [lindex $tmplist 0] |
206 | set transaction [lindex $tmplist 1] |
207 | set valid [lindex $tmplist 2] |
208 | set forgotten [lindex $tmplist 3] |
209 | set backuped [lindex $tmplist 4] |
210 | set maybeopen [lindex $tmplist 5] |
211 | |
212 | # Name analysis to suppress the map address. |
213 | set shortlist [split $name "#"] |
214 | set shortname [lindex $shortlist 0] |
215 | set index [lindex $shortlist 1] |
216 | |
217 | # Package analysis to determine the icon type. |
218 | #set pk [lindex [split $name _] 0] |
219 | set node_img $image_other |
220 | #if {$pk == "TDataStd" || $pk == "TNaming"} {set node_img $standardimage} |
221 | #if {$pk == "TXRef"} {set node_img $xrefimage} |
222 | if {$shortname == "TNaming_NamedShape"} {set node_img $image_ns} |
223 | |
224 | set textname "$shortname" |
225 | |
226 | # if { [llength $tmplist] >5 } { set textname [lindex $tmplist 5] } |
227 | set textname "$textname [DFGetAttributeValue $DDF_Browser $df_entry [lindex $tmplist 6]]" |
228 | |
229 | # Transaction analysis |
230 | if {$transaction == "0"} { |
231 | # set locstyle $DFTREE_AttributeStyle |
232 | } else { |
233 | # set textname "$textname T=$transaction" |
234 | # set locstyle $DFTREE_AttributeStyle1 |
235 | } |
236 | |
237 | # Valid? |
238 | if {$valid == "NotValid"} {set textname "$textname $valid"} |
239 | |
240 | # Forgotten? |
241 | if {$forgotten == "Forgotten"} {set textname "$textname $forgotten"} |
242 | |
243 | # Backuped? |
244 | if {$backuped == "Backuped"} {set textname "$textname $backuped"} |
245 | |
246 | set df_new [$df_tree insert $df_node end \ |
247 | -text $textname -image $node_img -tags Attribute] |
248 | |
249 | if {$maybeopen == "1"} { |
250 | $df_tree item $df_new -open true |
251 | DFTREE:Tree:UpdateAttribute $DDF_Browser $df_tree $df_new $index |
252 | } |
253 | } |
254 | } |
255 | |
256 | ############################################################################### |
257 | # $loc is always the attribute index |
258 | # |
259 | proc DFTREE:Tree:UpdateAttribute { DDF_Browser df_tree df_node a_index } { |
260 | |
261 | global DFTREE_GLOBALS |
262 | global $DDF_Browser |
263 | |
264 | set tmplist [split [DFOpenAttribute $DDF_Browser $a_index ] "\\"] |
265 | |
266 | # Failed or not? |
267 | if {[lindex $tmplist 0] == "Failed"} { |
268 | ## set locstyle $DFTREE_AttributeStyle2 |
269 | } else { |
270 | ## set locstyle $DFTREE_AttributeStyle |
271 | } |
272 | |
273 | foreach name $tmplist { |
274 | $df_tree insert $df_node end -text $name -tags Terminal |
275 | } |
276 | return |
277 | } |
278 | |
279 | ############################################################################### |
280 | # item: |
281 | # "Entry Name=TheNameIfExists Modified|NotModified 0|1" |
282 | proc FCTREE:Tree:DecodeLabelItem { DDF_Browser df_tree df_node df_entry labelItem} { |
283 | |
284 | global DFTREE_GLOBALS |
285 | global $DDF_Browser |
286 | |
287 | set tmplist [split $labelItem " " ] |
288 | set labname [lindex $tmplist 0] |
289 | |
290 | set textname "$labname" |
291 | |
292 | if {$labname == "AttributeList"} { |
293 | |
294 | # Attribute List |
295 | # -------------- |
296 | |
297 | #set modified [lindex $tmplist 1] |
298 | |
299 | # Modified or not? |
300 | #if {$modified == "Modified"} { |
301 | # set textname "$textname $modified" |
302 | ## set locstyle $DFTREE_AttributeStyle1 |
303 | #} else { |
304 | ## set locstyle $DFTREE_AttributeStyle |
305 | #} |
306 | |
307 | #set df_new [$df_tree insert $df_node end \ |
308 | # -text $textname \ |
309 | # -image $DFTREE_GLOBALS(ImageAttrList) \ |
310 | # -tags AttributeList] |
311 | |
312 | #$df_tree item $df_new -open true |
313 | |
314 | DFTREE:Tree:UpdateAttributeList $DDF_Browser $df_tree $df_node $df_entry |
315 | |
316 | } else { |
317 | |
318 | # Sub-label(s) |
319 | # ------------ |
320 | |
321 | set name [lindex $tmplist 1] |
322 | set modified [lindex $tmplist 2] |
323 | set maybeopen [lindex $tmplist 3] |
324 | |
325 | # Name? |
326 | set ll [expr [string length $name] -2] |
327 | if {$ll > 0} { |
328 | set textname "$textname [string range $name 1 $ll]" |
329 | } |
330 | |
331 | # Modified or not? |
332 | if {$modified == "Modified"} { |
333 | set textname "$textname $modified" |
334 | } |
335 | |
336 | set df_new [$df_tree insert $df_node end \ |
337 | -text $textname \ |
338 | -image $DFTREE_GLOBALS(ImageLabel) \ |
339 | -values $labname \ |
340 | -tags Label] |
341 | |
342 | if {$maybeopen == "1"} { |
343 | $df_tree item $df_new -open true |
344 | } |
345 | |
346 | DFTREE:Tree:UpdateLabel $DDF_Browser $df_tree $df_new $labname |
347 | } |
348 | } |
349 | |
350 | ############################################################################### |
351 | # |
352 | # |
353 | proc DFGetAttributeValue { DDF_Browser lab index } { |
354 | |
355 | global $DDF_Browser; # necessary for DRAW command to see the browser |
356 | |
357 | if {[catch "XAttributeValue $DDF_Browser $lab $index" ret]} { |
358 | return "" |
359 | } |
360 | if {"$ret" == ""} { return "" } |
361 | return "\[$ret\]" |
362 | } |
363 | |
364 | ############################################################################### |
365 | # |
366 | # |
367 | proc DFOpenImage { img } { |
368 | |
369 | global env |
370 | |
3c9f082b |
371 | if {[catch "image create photo -file $env(CSF_OCCTResourcePath)/DrawResources/$img" ret]} { |
f767df4e |
372 | return "" |
373 | } |
374 | return $ret |
375 | } |