source: CPL/oasis3-mct/branches/OASIS3-MCT_2.0_branch/util/oasisgui/opentea/create_cluster.tcl @ 4775

Last change on this file since 4775 was 4775, checked in by aclsce, 5 years ago
  • Imported oasis3-mct from Cerfacs svn server (not suppotred anymore).

The version has been extracted from https://oasis3mct.cerfacs.fr/svn/branches/OASIS3-MCT_2.0_branch/oasis3-mct@1818

File size: 17.2 KB
Line 
1#  This program is under CECILL_B licence. See footer for details.
2
3proc cluster_create { args } {
4    set mandatory_arguments { path_father address }
5   
6    # Initializes the widget
7    initWidget
8
9    set widgetInfo($address-status) 1
10    set widgetInfo($address-renaming) 0
11    set widgetInfo($address-lastclick) [clock milliseconds]
12    set widgetInfo($address-ratio) [dTree_tryGetAttribute $XMLtree $full_address_XML_clean "ratio" "0.5" ] 
13     
14           
15    if  {[dTree_attrExists $XMLtree $full_address_XML_clean "require"]==1} {
16        set widgetInfo($address-clustermode) "require"
17    } else {
18        if  {[dTree_attrExists $XMLtree $full_address_XML_clean "fixed"]==1} {
19            set widgetInfo($address-clustermode) "fixed"           
20        } else {
21            set widgetInfo($address-clustermode) "independant"
22        }
23    }
24   
25   
26   
27    ###############
28    # MAIN FRAMES #
29    ###############
30   
31    ttk::frame $win
32    eval $widgetInfo(packme-$win)
33   
34   
35   
36   
37    ttk::frame $win.ftv 
38    ttk::frame $win.ftv.forceps -width $widgetInfo(guiSmallWidgetWidth) -height 0 
39    pack $win.ftv -fill both -side left -expand 1 
40    ############
41    # TREEVIEW #
42    ############
43   
44    set title [dTree_getAttribute $XMLtree $full_address_XML_clean "title"]   
45    ttk::label $win.ftv.lb  -text "$title:" -anchor ne -justify right
46   
47    set widgetInfo($address-status) 0
48    set widgetInfo($address-status_txt) ""
49    ttk::label $win.ftv.status -textvariable widgetInfo($address-status_txt) -foreground "red" -justify center -compound left -anchor center
50    $win.ftv.status configure -wraplength [expr { 0.6*$widgetInfo(guiSmallWidgetWidth)}]
51   
52   
53    set widgetInfo($address-labelstype) [dTree_tryGetAttribute $XMLtree $full_address_XML_clean "labels" "ascii"]
54   
55    ttk::treeview $win.ftv.tv -selectmode none -show {}
56    if {$widgetInfo($address-clustermode) == "independant"} {
57        $win.ftv.tv configure -selectmode browse
58    }
59    #yscrollcommand [list $win.ftv.sby set] 
60    # create the columns of the treeview   
61   
62   
63    #$win.ftv.lb configure -width "[expr {int([expr {1.* $widgetInfo(guiSmallWidgetWidth)}])}]p"
64    set colwidth [expr {int([expr {0.5* $widgetInfo(guiSmallWidgetWidth)}])}]
65   
66   
67    $win.ftv.tv configure -columns "lbl var"
68    $win.ftv.tv column #1 -width $colwidth -anchor e
69    $win.ftv.tv column #2 -width $colwidth -anchor w
70   
71    #ttk::scrollbar $win.ftv.sby -orient vertical -command [list $win.ftv.tv yview]
72   
73    # avoid tab scrolling for mousewheel
74    bind $win.ftv.tv <MouseWheel> {+set tabscroll 0}
75    bind $win.ftv.tv  <Leave> {+set tabscroll 1}
76    #bind $win.ftv.tv  <FocusOut> [subst {$win.ftv.tv selection set  {} }]
77    # ce binding est inutilisable ca il bloque la deletion d'un item
78   
79   
80    grid $win.ftv.lb -sticky ne -column 0 -row 0 
81    grid columnconfigure  $win.ftv  $win.ftv.lb  -weight 1
82    grid rowconfigure  $win.ftv  $win.ftv.lb  -weight 1
83    grid $win.ftv.tv -sticky e -column 1 -row 0 -rowspan 2
84    grid $win.ftv.forceps -sticky news -column 0 -row 3 -columnspan 2
85    grid $win.ftv.status -sticky news -column 0 -row 4 -columnspan 2
86   
87   
88   
89 
90   
91
92   
93   
94    ############
95    # CONTROLS #
96    ############
97    ttk::frame $win.ftv.controls
98    grid $win.ftv.controls -sticky se -column 0 -row 1
99    grid columnconfigure  $win.ftv  $win.ftv.controls  -weight 1
100    grid rowconfigure  $win.ftv  $win.ftv.controls  -weight 1
101   
102   
103    #icons with buttons
104    ttk::button $win.ftv.controls.add -text "+" -command [subst {
105        cluster_ctrl_addcomponent $win $address
106        eval \$widgetInfo($address-check)   
107    }]
108    ttk::button $win.ftv.controls.rm  -text "-" -command [subst {
109        cluster_ctrl_rmcomponent $win $address
110        eval \$widgetInfo($address-check)   
111    }]
112   
113   
114   
115    if {$widgetInfo($address-clustermode)=="independant"} {
116       pack $win.ftv.controls.add $win.ftv.controls.rm -side right -anchor nw -padx 0 -pady 0     
117    }
118     
119   
120   
121    append widgetInfo($address-refreshStatus) [subst {cluster_refreshStatus $win $address}]
122    append widgetInfo($address-refresh) [subst {cluster_refresh $win $address}]
123   
124   
125    finishWidget
126   
127    cluster_refresh $win $address
128   
129   
130    # reaction to cells
131    bind $win.ftv.tv <ButtonPress> [subst {+cluster_simple_trigger $win $address %x %y}]
132   
133    # clean the widget callBack on dstruction
134    bind $win <Destroy> [ subst {widget_destroy $win $address}]
135   
136    return $win
137}
138
139
140# Simple Click : raise the form relative to the component
141proc cluster_simple_trigger {win address x y} {
142    global widgetInfo
143    set row [$win.ftv.tv identify row $x $y]
144    set col [$win.ftv.tv identify column $x $y]
145   
146    set double_click "0"
147    set current_time_ms [clock milliseconds]
148    set delay [expr {$current_time_ms - $widgetInfo($address-lastclick)}]
149    set widgetInfo($address-lastclick) $current_time_ms
150    if {$delay <300 } {
151        set double_click 1
152    }
153   
154   
155    if {$col=="#1" && $widgetInfo($address-clustermode)!="independant"} { return 0}   
156    if {$row!= ""} {
157       
158        if { $widgetInfo($address-renaming) != 0 } {
159            cluster_setname $address $win $widgetInfo($address-renaming) $widgetInfo($address-renamingCol)
160            set widgetInfo($address-renaming) 0
161            destroy $win.ftv.tv.rename 
162        }
163       
164        if {$double_click} {
165            cluster_rename $win $address $row $col
166           
167        }
168       
169    }
170}
171
172
173
174
175# called by the "+" button is invoked
176proc cluster_ctrl_addcomponent {win address} {
177    global widgetInfo tmpTree
178   
179    set row [$win.ftv.tv selection ]
180    if { $row != "" } {
181        set rank [lsearch [cluster_component_list $address] $row]
182        incr rank
183    } else {
184        set rank "end"
185    }
186    cluster_new_component $win $address $rank
187    cluster_refreshStatus $win $address
188}
189
190proc cluster_ctrl_rmcomponent {win address } {
191    global widgetInfo
192     
193   
194    set row [$win.ftv.tv selection ]
195    if { $row != "" } {
196        set rank [lsearch [cluster_component_list $address] $row]
197    } else {
198        return
199    }
200    cluster_del_component $win $address $row
201    cluster_refreshStatus $win $address
202}
203
204
205
206# called when :
207# - "+" button is invoked
208# - a new component is needed
209proc cluster_new_component { win address rank   } {
210    global widgetInfo
211    set index 1
212    set lbl_ok 0
213    while {$lbl_ok == 0} {
214       
215        set rank [lsearch [cluster_component_list $address] "x_$index"]
216
217        if {$rank == -1} {
218            set lbl_ok 1
219        } else {
220            incr index
221        }
222    }
223    set newcontent [ linsert [cluster_variable_to_content $address] end "x_$index void"]
224    cluster_content_to_variable $address $newcontent
225}
226
227
228# called when :
229# - "-" button is invoked
230# - a  component must be deleted
231proc cluster_del_component { win address component_node } {
232    global widgetInfo
233   
234    set rank [lsearch [cluster_component_list $address] $component_node]
235    # remove from the main cluster widget
236   
237   
238   
239    set newcontent [ lreplace [cluster_variable_to_content $address] $rank $rank  ]
240    cluster_content_to_variable $address $newcontent
241   
242}
243
244
245
246proc cluster_rename {win address row col } {
247   
248    global widgetInfo
249    if { $widgetInfo($address-renaming) != 0 } {
250        focus $win.ftv.tv.rename.entry
251        return   
252    }                   
253   
254    set widgetInfo($address-renaming) $row                   
255    set widgetInfo($address-renamingCol) $col
256   
257
258   
259   
260    frame $win.ftv.tv.rename -background red  -bd 2
261    set bbox [$win.ftv.tv bbox $row $col]
262   
263    place $win.ftv.tv.rename -x [lindex $bbox 0] -y [lindex $bbox 1] -width [lindex $bbox 2] -height [lindex $bbox 3]
264   
265    focus $win.ftv.tv.rename
266   
267    set widgetInfo($address-entry) [$win.ftv.tv set $row $col]
268    ttk::entry $win.ftv.tv.rename.entry -textvariable widgetInfo($address-entry) 
269    pack $win.ftv.tv.rename.entry -expand 1
270    $win.ftv.tv.rename.entry selection range 0 end
271    $win.ftv.tv.rename.entry icursor end
272    focus $win.ftv.tv.rename.entry
273
274
275    bind $win.ftv.tv.rename.entry <Return>  [ subst {
276        # change value
277        cluster_setname $address $win $row $col
278        # kill dialog
279        destroy $win.ftv.tv.rename
280        set widgetInfo($address-renaming) 0
281    }]
282   
283    bind $win.ftv.tv.rename.entry <FocusOut>  [ subst {
284         # change value
285        cluster_setname $address $win $row $col
286        # kill dialog
287        destroy $win.ftv.tv.rename
288        set widgetInfo($address-renaming) 0
289    }]
290   
291   
292    bind $win.ftv.tv.rename.entry <Escape>  [ subst {
293        # kill dialog
294        destroy $win.ftv.tv.rename
295        set widgetInfo($address-renaming) 0
296    }]
297   
298   
299    #bind $win.ftv.tv.rename.entry <Tab>  [ subst {
300    #   
301    #    #change value
302    #    cluster_setname $address $win $row $col
303    #    # kill dialog
304    #    destroy $win.ftv.tv.rename
305    #    set widgetInfo($address-renaming) 0
306    #   
307    #    # find nex row
308    #    set list_row \[cluster_component_list $address\]
309    #    set rank \[lsearch \$list_row $row\]
310    #    incr rank
311    #    if {\$rank == \[llength \$list_row\]} {
312    #        set rank 0
313    #    }
314    #    set newrow \[lindex \$list_row \$rank\]
315    #    # restart dialog
316    #    cluster_rename $win $address \$newrow $col
317    #    puts "test"
318    #}]
319}
320
321
322
323# change the label assigned
324proc cluster_setname { address win row col } {
325    global widgetInfo tmpTree
326   
327   
328   
329    set new_label [stringcleanBalise $widgetInfo($address-entry)]
330    set newcontent ""
331   
332   
333    if {$col == "#1"} {
334        set list_of_components [cluster_component_list $address]
335       
336        if {[lsearch $list_of_components $new_label ] != -1} {
337            warning "The component $new_label is already existing. Use another component."
338            return
339        }   
340    }
341   
342    foreach couple  [cluster_variable_to_content $address] {
343        set component [lindex $couple 0]
344        set vars [lrange  $couple 1 end]
345        if {$component ==$row } {
346            switch $col {
347                "#1" {
348                    set couple "$new_label $vars"
349                }
350                "#2" {
351                    set couple "$component $new_label"
352                }
353            }
354        }
355        lappend newcontent $couple
356    }
357   
358    cluster_content_to_variable $address $newcontent
359    eval $widgetInfo($address-check)
360}
361
362
363
364
365proc cluster_refresh {win address} {
366    global widgetInfo XMLtree
367    # Reinitialize the treeview
368   
369    if {$widgetInfo($address-clustermode) =="require"} {
370        cluster_require $win $address
371    }
372}
373
374
375proc cluster_refreshStatus {win address} {
376    global widgetInfo XMLtree
377    # Reinitialize the treeview
378   
379 
380   
381   
382    $win.ftv.tv delete [$win.ftv.tv children {}]
383   
384    set compolenght 0
385    # create the lines of the treeview
386    set widgetInfo($address-status_txt) ""
387    set widgetInfo($address-status) 1
388   
389    set full_address_XML [split $address "."]
390    set full_type [dTree_getAttribute $XMLtree $full_address_XML "type"]
391    set type [string range $full_type  5 end ]
392   
393    set sum 0   
394   
395    foreach couple [cluster_variable_to_content $address]  {
396        set component [lindex  $couple 0]
397        set var [lrange  $couple 1 end]
398
399        set cl [string length $component]
400        if {$cl>$compolenght} {set compolenght $cl}
401             
402        set test_label [test_vartype $component $widgetInfo($address-labelstype) ]       
403        set test_cluster [test_vartype $var $type ]
404        if { $test_cluster == 1 && $test_label == 1} {
405            $win.ftv.tv insert {} end -id $component -text "$component" -image "" -tags "true"
406        } else {
407           
408            if { $test_cluster != 1} {
409                 set widgetInfo($address-status_txt) $test_cluster
410            }
411           
412            if { $test_label != 1} {
413                 set widgetInfo($address-status_txt) $test_label
414            }
415           
416            set widgetInfo($address-status) -1
417            $win.ftv.tv insert {} end -id $component -text "$component" -image "" -tags "false"
418        }
419       
420        if {$type == "fraction" && [string is double $var]} {
421            set sum [expr {$sum + $var}] 
422        }
423   
424       
425        $win.ftv.tv set $component #1 "$component"
426        $win.ftv.tv set $component #2 $var
427    }
428   
429    if {$type == "fraction"} {
430        if {$sum != 1.0 } {
431            set test_cluster "sum fractions not one"
432            set widgetInfo($address-status_txt) $test_cluster
433            set widgetInfo($address-status) -1
434        }
435    }
436   
437   
438    $win.ftv.tv tag configure false -background #ff5050
439    $win.ftv.tv tag configure unknown -background #ffcd7c
440    $win.ftv.tv tag configure true -background ""
441   
442    set colwidth1 [expr {int([expr {0.5* $widgetInfo(guiSmallWidgetWidth)  *$widgetInfo($address-ratio)  }])}]
443    set colwidth2 [expr {int([expr {0.5* $widgetInfo(guiSmallWidgetWidth)}]) - $colwidth1}]
444    $win.ftv.tv column #1 -width $colwidth1 -anchor w
445    $win.ftv.tv column #2 -width $colwidth2 -anchor w
446   
447   
448    set nrows  [llength [cluster_variable_to_content $address] ]
449   
450    $win.ftv.tv configure -height $nrows
451   
452    if { $widgetInfo($address-status) == -1 } { 
453       $win.ftv.status configure -image icon_flag
454    } else {
455        $win.ftv.status configure -image ""
456    }
457    smartpacker_update_visibility $win $address
458   
459   
460}
461
462
463
464
465
466
467proc cluster_content_to_variable {address content} {
468    global widgetInfo
469    set buffer ""
470    foreach couple $content {
471        lappend buffer [lindex  $couple 0]
472        lappend buffer [lrange  $couple 1 end]
473    }
474    set widgetInfo($address-variable) [join $buffer ";" ]
475}
476
477
478proc cluster_variable_to_content {address} {
479    global widgetInfo
480    set couple ""
481    set content ""
482    foreach item [split $widgetInfo($address-variable)  ";" ] {
483        set couple "$couple $item"
484        if {[llength $couple] == 2 } {
485            lappend content $couple
486            set couple ""
487        }
488    }
489    return $content
490}
491
492proc cluster_component_list {address} {
493    global widgetInfo
494    set list_component ""
495    foreach couple [cluster_variable_to_content $address] {
496        set component [lindex $couple 0]
497        lappend list_component $component
498    }
499    return $list_component
500}
501
502proc cluster_var_list {address} {
503    global widgetInfo
504    set list_vars ""
505    foreach couple [cluster_variable_to_content $address] {
506        set vars [lrange  $couple 1 end]
507        lappend list_vars $vars
508    }
509    return $list_vars
510}
511
512
513
514
515
516
517# prepare the filling in a different manner if a require is waiting
518proc cluster_require { win address } {
519    global widgetInfo
520    set reqVar $widgetInfo($address-requiredValue) 
521    set default [lindex [split $widgetInfo($address-default) ";"]  1]
522    if {$default==""} {set default 0 }
523    set old_content [cluster_variable_to_content $address]
524    set new_content ""       
525    # get the present values of the components if they belong to reQvar   
526    foreach actual_component $reqVar {
527        set component_found 0
528        foreach couple $old_content {
529            set component [lindex $couple 0]
530            set var [lrange  $couple 1 end]
531            if {$component == $actual_component} {
532                lappend new_content "$component $var"
533                set component_found 1
534            }
535        }
536        if {$component_found==0 } {lappend new_content "$actual_component $default"}
537    }
538   
539   
540   
541    if {$new_content != $old_content} {
542       cluster_content_to_variable $address $new_content
543    } 
544   
545    # hide if void list
546    if {[llength $new_content] == 0} {
547        pack forget $win
548        return
549    } else {
550        eval $widgetInfo(packme-$win)
551    }
552    return
553}
554
555
556
557
558#  Copyright CERFACS 2014
559#   
560#  antoine.dauptain@cerfacs.fr
561#   
562#  This software is a computer program whose purpose is to ensure technology
563#  transfer between academia and industry.
564#   
565#  This software is governed by the CeCILL-B license under French law and
566#  abiding by the rules of distribution of free software.  You can  use,
567#  modify and/ or redistribute the software under the terms of the CeCILL-B
568#  license as circulated by CEA, CNRS and INRIA at the following URL
569#  "http://www.cecill.info".
570#   
571#  As a counterpart to the access to the source code and  rights to copy,
572#  modify and redistribute granted by the license, users are provided only
573#  with a limited warranty  and the software's author,  the holder of the
574#  economic rights,  and the successive licensors  have only  limited
575#  liability.
576#   
577#  In this respect, the user's attention is drawn to the risks associated
578#  with loading,  using,  modifying and/or developing or reproducing the
579#  software by the user in light of its specific status of free software,
580#  that may mean  that it is complicated to manipulate,  and  that  also
581#  therefore means  that it is reserved for developers  and  experienced
582#  professionals having in-depth computer knowledge. Users are therefore
583#  encouraged to load and test the software's suitability as regards their
584#  requirements in conditions enabling the security of their systems and/or
585#  data to be ensured and,  more generally, to use and operate it in the
586#  same conditions as regards security.
587#   
588#  The fact that you are presently reading this means that you have had
589#  knowledge of the CeCILL-B license and that you accept its terms.
Note: See TracBrowser for help on using the repository browser.