1 | # This program is under CECILL_B licence. See footer for details. |
---|
2 | |
---|
3 | |
---|
4 | |
---|
5 | |
---|
6 | # TIMELINE CREATION |
---|
7 | |
---|
8 | proc timeline_create { args } { |
---|
9 | set mandatory_arguments { path_father address } |
---|
10 | |
---|
11 | # Initializes the widget |
---|
12 | initWidget |
---|
13 | |
---|
14 | set widgetInfo($address-status) 1 |
---|
15 | set widgetInfo($address-message) "" |
---|
16 | set widgetInfo($address-accepted_keys) {"name" "run" "start" "end" "color" "comment" "sce"} |
---|
17 | |
---|
18 | ttk::frame $win |
---|
19 | eval $widgetInfo(packme-$win) |
---|
20 | |
---|
21 | set title [dTree_getAttribute $XMLtree $full_address_XML "title"] |
---|
22 | ttk::label $win.lb -text "$title" |
---|
23 | ttk::frame $win.t |
---|
24 | |
---|
25 | pack $win.lb -side top -pady 3 |
---|
26 | pack $win.t -side top -pady {0 5} |
---|
27 | |
---|
28 | set size_v [expr { (0.6)*$widgetInfo(guiSmallWidgetWidth)}] |
---|
29 | set size_h [expr { (1)*$widgetInfo(guiSmallWidgetWidth)}] |
---|
30 | set size [split [dTree_tryGetAttribute $XMLtree $full_address_XML_clean "size" "1;1" ] ";"] |
---|
31 | set size_h [expr {int([lindex $size 1]*1.*$size_h)}] |
---|
32 | set size_v [expr {int([lindex $size 1]*1.*$size_v)}] |
---|
33 | |
---|
34 | set widgetInfo($address-width) $size_h |
---|
35 | set widgetInfo($address-height) $size_v |
---|
36 | set widgetInfo($address-widthcanvas) $size_h |
---|
37 | set widgetInfo($address-heightcanvas) $size_v |
---|
38 | |
---|
39 | |
---|
40 | # timeline part |
---|
41 | canvas $win.t.can -yscrollcommand [list $win.t.sby set] -xscrollcommand [list $win.t.sbx set] -width $size_h -height $size_v |
---|
42 | ttk::scrollbar $win.t.sby -orient vertical -command [list $win.t.can yview] |
---|
43 | ttk::scrollbar $win.t.sbx -orient horizontal -command [list $win.t.can xview] |
---|
44 | |
---|
45 | grid $win.t.can -row 1 -column 0 -sticky news |
---|
46 | grid $win.t.sby -row 1 -column 1 -sticky ns |
---|
47 | grid $win.t.sbx -row 2 -column 0 -sticky ew |
---|
48 | |
---|
49 | |
---|
50 | |
---|
51 | # controls part |
---|
52 | ttk::frame $win.c |
---|
53 | pack $win.c -side top -fill x |
---|
54 | |
---|
55 | |
---|
56 | |
---|
57 | # message label |
---|
58 | ttk::label $win.c.message -textvariable widgetInfo($address-message) |
---|
59 | pack $win.c.message -side left |
---|
60 | |
---|
61 | #add the check/refresh procedure to the bindings of the variable |
---|
62 | |
---|
63 | append widgetInfo($address-refresh) [ subst { timeline_refresh $win $address}] |
---|
64 | append widgetInfo($address-check) [subst { timeline_check $win $address}] |
---|
65 | finishWidget |
---|
66 | |
---|
67 | #trick? |
---|
68 | bind $win.t.can <ButtonPress-1> {+; focus %W} |
---|
69 | |
---|
70 | bind $win.t.can <Motion> [subst {timeline_showlocation $win $address}] |
---|
71 | |
---|
72 | # zoom binding |
---|
73 | #bind $win.t.can <KeyPress-x> [ subst {timeline_zoom $address $win 0.8 1.0}] |
---|
74 | #bind $win.t.can <KeyPress-X> [ subst {timeline_zoom $address $win 1.2 1.0}] |
---|
75 | #bind $win.t.can <KeyPress-y> [ subst {timeline_zoom $address $win 1.0 0.8}] |
---|
76 | #bind $win.t.can <KeyPress-Y> [ subst {timeline_zoom $address $win 1.0 1.2}] |
---|
77 | bind $win.t.can <KeyPress-z> [ subst {timeline_zoom $address $win 0.8 0.8}] |
---|
78 | bind $win.t.can <KeyPress-Z> [ subst {timeline_zoom $address $win 1.2 1.2}] |
---|
79 | |
---|
80 | # ctrl move |
---|
81 | bind $win.t.can <Control-Motion> [ subst {timeline_move $win $address %x %y }] |
---|
82 | |
---|
83 | timeline_scrollupdate $win $address 1.0 1.0 |
---|
84 | |
---|
85 | # clean the widget callBack on dstruction |
---|
86 | bind $win <Destroy> [ subst {widget_destroy $win $address}] |
---|
87 | |
---|
88 | return $win |
---|
89 | } |
---|
90 | |
---|
91 | |
---|
92 | proc timeline_refresh {win address} { |
---|
93 | global widgetInfo |
---|
94 | #$win.t.can create rect 0 0 $widgetInfo($address-widthcanvas) $widgetInfo($address-heightcanvas) -fill white -tags "xscalable yscalable" |
---|
95 | |
---|
96 | $win.t.can delete all |
---|
97 | |
---|
98 | set xmin 1000000000 |
---|
99 | set xmax -1000000000 |
---|
100 | set ymin 0 |
---|
101 | set ymax 0 |
---|
102 | set xtitle "" |
---|
103 | set ytitle "" |
---|
104 | |
---|
105 | # first pass, to get bounds |
---|
106 | foreach dataset [split $widgetInfo($address-variable) "#" ] { |
---|
107 | set ds_start [timeline_parsecontent $address $dataset "start"] |
---|
108 | set ds_end [timeline_parsecontent $address $dataset "end"] |
---|
109 | if {$ds_end>$xmax} {set xmax $ds_end} |
---|
110 | if {$ds_start<$xmin} {set xmin $ds_start} |
---|
111 | incr ymax |
---|
112 | |
---|
113 | } |
---|
114 | |
---|
115 | |
---|
116 | if {$ymin == $ymax} { |
---|
117 | set ymin [expr {$ymin-1.0}] |
---|
118 | set ymax [expr {$ymax+1.0}] |
---|
119 | } |
---|
120 | if {$xmin == $xmax} { |
---|
121 | set xmin [expr {$xmin-1.0}] |
---|
122 | set xmax [expr {$xmax+1.0}] |
---|
123 | } |
---|
124 | |
---|
125 | |
---|
126 | # initialize bounds and scaling |
---|
127 | set widgetInfo($address-xmin) $xmin |
---|
128 | set widgetInfo($address-xmax) $xmax |
---|
129 | set widgetInfo($address-ymin) $ymin |
---|
130 | set widgetInfo($address-ymax) $ymax |
---|
131 | |
---|
132 | set widgetInfo($address-xscale) [expr {0.8 *$widgetInfo($address-widthcanvas) /($widgetInfo($address-xmax)-$widgetInfo($address-xmin))}] |
---|
133 | set widgetInfo($address-yscale) [expr {0.8*$widgetInfo($address-heightcanvas)/($widgetInfo($address-ymax)-$widgetInfo($address-ymin))}] |
---|
134 | |
---|
135 | |
---|
136 | |
---|
137 | |
---|
138 | # draw frame an midlines |
---|
139 | set xmin_pix [timeline_pix_x $address $xmin] |
---|
140 | set xmax_pix [timeline_pix_x $address $xmax] |
---|
141 | set ymin_pix [timeline_pix_y $address $ymin] |
---|
142 | set ymax_pix [timeline_pix_y $address $ymax] |
---|
143 | set xzero_pix [timeline_pix_x $address 0.0] |
---|
144 | |
---|
145 | |
---|
146 | #$win.t.can create text $xmax_pix $ymin_pix -text "$xmax, $ymin" -anchor "se" -tags "xscalable yscalable" |
---|
147 | #$win.t.can create text $xmin_pix $ymax_pix -text "$xmin, $ymax" -anchor "nw" -tags "xscalable yscalable" |
---|
148 | foreach frac {0 0.2 0.4 0.6 0.8 1 } { |
---|
149 | set xfrac [expr {$frac * $xmin + (1.-$frac)*$xmax}] |
---|
150 | set xfrac_pix [timeline_pix_x $address $xfrac] |
---|
151 | $win.t.can create line $xfrac_pix $ymin_pix $xfrac_pix $ymax_pix -fill grey80 -tags "xscalable yscalable axis" |
---|
152 | canvas_text_vector $win.t.can $xfrac_pix $ymin_pix [format %.4g $xfrac] se 11 45 black "xscalable yscalable axis" |
---|
153 | } |
---|
154 | |
---|
155 | |
---|
156 | set xtit [expr {0.5 * $xmin + 0.5*$xmax}] |
---|
157 | set xtit_pix [timeline_pix_x $address $xtit] |
---|
158 | canvas_text_vector $win.t.can $xtit_pix $ymin_pix "Time \[s\]" se 11 45 black "xscalable yscalable axis" |
---|
159 | |
---|
160 | |
---|
161 | |
---|
162 | |
---|
163 | # second pass pass, to draw |
---|
164 | set ystart 0 |
---|
165 | foreach dataset [split $widgetInfo($address-variable) "#" ] { |
---|
166 | |
---|
167 | set ds_name [timeline_parsecontent $address $dataset "name"] |
---|
168 | set ds_color [timeline_parsecontent $address $dataset "color"] |
---|
169 | set ds_run [timeline_parsecontent $address $dataset "run"] |
---|
170 | set ds_start [timeline_parsecontent $address $dataset "start"] |
---|
171 | set ds_end [timeline_parsecontent $address $dataset "end"] |
---|
172 | set ds_comment [timeline_parsecontent $address $dataset "comment"] |
---|
173 | set ds_sce [timeline_parsecontent $address $dataset "sce"] |
---|
174 | |
---|
175 | |
---|
176 | |
---|
177 | set xpix1 [timeline_pix_x $address $ds_start] |
---|
178 | set xpix2 [timeline_pix_x $address $ds_end] |
---|
179 | set ypixm [timeline_pix_y $address [expr {$ystart +0.5}]] |
---|
180 | set ypix1 [timeline_pix_y $address [expr {$ystart +0.2}]] |
---|
181 | set ypix2 [timeline_pix_y $address [expr {$ystart +0.8}]] |
---|
182 | if {[expr {$ypix2-$ypix1}] > 20} { |
---|
183 | set ypix1 [expr {$ypixm - 10}] |
---|
184 | set ypix2 [expr {$ypixm + 10}] |
---|
185 | } |
---|
186 | |
---|
187 | incr ystart |
---|
188 | |
---|
189 | set shorttitle "$ds_name#$ds_run" |
---|
190 | set description "$ds_name $ds_run $ds_comment" |
---|
191 | |
---|
192 | |
---|
193 | set tags "xscalable yscalable $shorttitle " |
---|
194 | set h 5 |
---|
195 | |
---|
196 | $win.t.can create rectangle $xpix1 $ypix1 $xpix2 $ypix2 -fill $ds_color -outline black -width 1 -tags $tags -activewidth 3 |
---|
197 | $win.t.can create oval [expr {$xpix1-$h}] [expr {$ypixm-$h}] [expr {$xpix1+$h}] [expr {$ypixm+$h}] -fill black -outline black -width 1 -tags $tags -activewidth 3 |
---|
198 | canvas_text_vector $win.t.can $xpix2 $ypixm "$shorttitle" e 11 0 black "xscalable yscalable $shorttitle" |
---|
199 | $win.t.can bind $shorttitle <Enter> [subst {set widgetInfo($address-message) "$description" }] |
---|
200 | $win.t.can bind $shorttitle <Leave> [subst {set widgetInfo($address-message) ""}] |
---|
201 | |
---|
202 | } |
---|
203 | |
---|
204 | $win.t.can lower "axis" |
---|
205 | |
---|
206 | $win.t.can configure -scrollregion [ $win.t.can bbox all] |
---|
207 | |
---|
208 | smartpacker_update_visibility $win $address |
---|
209 | |
---|
210 | #canvas_makegif $win.t.can "$widgetInfo($address-name).gif" |
---|
211 | |
---|
212 | } |
---|
213 | |
---|
214 | |
---|
215 | proc timeline_parsecontent {address curve_data arg} { |
---|
216 | global widgetInfo |
---|
217 | |
---|
218 | set ds [split $curve_data ";"] |
---|
219 | set dsi(name) "NAME???" |
---|
220 | set dsi(run) "RUN_???" |
---|
221 | set dsi(color) "grey" |
---|
222 | set dsi(comment) "" |
---|
223 | set dsi(start) "0.0" |
---|
224 | set dsi(end) "0.0" |
---|
225 | set dsi(sce) "0" |
---|
226 | |
---|
227 | set dsi(raw) "" |
---|
228 | |
---|
229 | foreach item $ds { |
---|
230 | if {[string match "*=*" $item] == 1} { |
---|
231 | set key [lindex [split $item "="] 0] |
---|
232 | set value [lindex [split $item "="] 1] |
---|
233 | if {$key in $widgetInfo($address-accepted_keys)} { |
---|
234 | |
---|
235 | if {$key in {"start" "end"} } { |
---|
236 | if {![string is double $value]} { |
---|
237 | set value "0.0" |
---|
238 | } |
---|
239 | } |
---|
240 | set dsi($key) $value |
---|
241 | } else { |
---|
242 | debug "Timeline key $key not recognized among $widgetInfo($address-accepted_keys)" |
---|
243 | } |
---|
244 | } else { |
---|
245 | lappend dsi(raw) $item |
---|
246 | } |
---|
247 | |
---|
248 | } |
---|
249 | |
---|
250 | |
---|
251 | if {$dsi(end) < $dsi(start)} { |
---|
252 | set dsi(end) $dsi(start) |
---|
253 | } |
---|
254 | |
---|
255 | return $dsi($arg) |
---|
256 | } |
---|
257 | |
---|
258 | proc timeline_pix_x { address x } { |
---|
259 | global widgetInfo |
---|
260 | set xpix [expr {($x -$widgetInfo($address-xmin)) * $widgetInfo($address-xscale)}] |
---|
261 | return $xpix |
---|
262 | } |
---|
263 | proc timeline_pix_y { address y} { |
---|
264 | global widgetInfo |
---|
265 | set ypix [expr {($y - $widgetInfo($address-ymax) ) * $widgetInfo($address-yscale)}] |
---|
266 | return $ypix |
---|
267 | |
---|
268 | } |
---|
269 | proc timeline_pix_realx { address xpix} { |
---|
270 | global widgetInfo |
---|
271 | set x [expr {$widgetInfo($address-xmin) + $xpix/$widgetInfo($address-xscale)}] |
---|
272 | return $x |
---|
273 | } |
---|
274 | proc timeline_pix_realy { address ypix} { |
---|
275 | global widgetInfo |
---|
276 | set y [expr {$widgetInfo($address-ymax) - $ypix/$widgetInfo($address-yscale)}] |
---|
277 | return $y |
---|
278 | } |
---|
279 | |
---|
280 | proc timeline_showlocation {win address} { |
---|
281 | global widgetInfo |
---|
282 | $win.t.can delete "pointer" |
---|
283 | set x [$win.t.can canvasx [expr {[winfo pointerx $win.t.can] - [winfo rootx $win.t.can]}]] |
---|
284 | set y [$win.t.can canvasy [expr {[winfo pointery $win.t.can] - [winfo rooty $win.t.can]}]] |
---|
285 | |
---|
286 | set realx [timeline_pix_realx $address $x ] |
---|
287 | set widgetInfo($address-position) "[format %+.4f $realx]" |
---|
288 | canvas_text_highlighted $win.t.can $x $y $widgetInfo($address-position) "pointer" |
---|
289 | } |
---|
290 | |
---|
291 | |
---|
292 | |
---|
293 | proc timeline_scrollupdate { win address xzoom yzoom} { |
---|
294 | global widgetInfo |
---|
295 | set width $widgetInfo($address-width) |
---|
296 | set height $widgetInfo($address-height) |
---|
297 | set widthcanvas $widgetInfo($address-widthcanvas) |
---|
298 | set heightcanvas $widgetInfo($address-heightcanvas) |
---|
299 | |
---|
300 | set widthcanvas [expr $widthcanvas*$xzoom ] |
---|
301 | set heightcanvas [expr $heightcanvas*$yzoom ] |
---|
302 | |
---|
303 | set widgetInfo($address-widthcanvas) $widthcanvas |
---|
304 | set widgetInfo($address-heightcanvas) $heightcanvas |
---|
305 | |
---|
306 | set scroll_factor_x [expr 1.0/$width*(1.0-$width*1.0/$widthcanvas)] |
---|
307 | if { $width > $widthcanvas} { set scroll_factor_x 0} |
---|
308 | set widgetInfo($address-scroll_factor_x) $scroll_factor_x |
---|
309 | set scroll_factor_y [expr 1.0/$height*(1.0-$height*1.0/$heightcanvas)] |
---|
310 | if { $height > $heightcanvas} { set scroll_factor_y 0} |
---|
311 | set widgetInfo($address-scroll_factor_y) $scroll_factor_y |
---|
312 | |
---|
313 | } |
---|
314 | |
---|
315 | # to move the canvases using Control_move binding |
---|
316 | proc timeline_zoom { address win xzoom yzoom} { |
---|
317 | global widgetInfo |
---|
318 | set y0 0 |
---|
319 | set x0 0 |
---|
320 | $win.t.can scale xscalable $x0 $y0 $xzoom 1 |
---|
321 | $win.t.can scale yscalable $x0 $y0 1 $yzoom |
---|
322 | |
---|
323 | set widgetInfo($address-xscale) [expr {$widgetInfo($address-xscale) * $xzoom} ] |
---|
324 | set widgetInfo($address-yscale) [expr {$widgetInfo($address-yscale) * $yzoom} ] |
---|
325 | |
---|
326 | $win.t.can configure -scrollregion [ $win.t.can bbox all] |
---|
327 | timeline_scrollupdate $win $address $xzoom $yzoom |
---|
328 | |
---|
329 | } |
---|
330 | |
---|
331 | |
---|
332 | |
---|
333 | |
---|
334 | |
---|
335 | # to move the canvases using Control_move binding |
---|
336 | proc timeline_move { win address x y} { |
---|
337 | global widgetInfo |
---|
338 | set xv [expr $x * $widgetInfo($address-scroll_factor_x)] |
---|
339 | set yv [expr $y * $widgetInfo($address-scroll_factor_y)] |
---|
340 | $win.t.can xview moveto $xv |
---|
341 | $win.t.can yview moveto $yv |
---|
342 | } |
---|
343 | |
---|
344 | |
---|
345 | proc timeline_check {win address} { |
---|
346 | global widgetInfo |
---|
347 | |
---|
348 | } |
---|
349 | |
---|
350 | |
---|
351 | |
---|
352 | # Copyright CERFACS 2014 |
---|
353 | # |
---|
354 | # antoine.dauptain@cerfacs.fr |
---|
355 | # |
---|
356 | # This software is a computer program whose purpose is to ensure technology |
---|
357 | # transfer between academia and industry. |
---|
358 | # |
---|
359 | # This software is governed by the CeCILL-B license under French law and |
---|
360 | # abiding by the rules of distribution of free software. You can use, |
---|
361 | # modify and/ or redistribute the software under the terms of the CeCILL-B |
---|
362 | # license as circulated by CEA, CNRS and INRIA at the following URL |
---|
363 | # "http://www.cecill.info". |
---|
364 | # |
---|
365 | # As a counterpart to the access to the source code and rights to copy, |
---|
366 | # modify and redistribute granted by the license, users are provided only |
---|
367 | # with a limited warranty and the software's author, the holder of the |
---|
368 | # economic rights, and the successive licensors have only limited |
---|
369 | # liability. |
---|
370 | # |
---|
371 | # In this respect, the user's attention is drawn to the risks associated |
---|
372 | # with loading, using, modifying and/or developing or reproducing the |
---|
373 | # software by the user in light of its specific status of free software, |
---|
374 | # that may mean that it is complicated to manipulate, and that also |
---|
375 | # therefore means that it is reserved for developers and experienced |
---|
376 | # professionals having in-depth computer knowledge. Users are therefore |
---|
377 | # encouraged to load and test the software's suitability as regards their |
---|
378 | # requirements in conditions enabling the security of their systems and/or |
---|
379 | # data to be ensured and, more generally, to use and operate it in the |
---|
380 | # same conditions as regards security. |
---|
381 | # |
---|
382 | # The fact that you are presently reading this means that you have had |
---|
383 | # knowledge of the CeCILL-B license and that you accept its terms. |
---|