source: tol/tolbase/lib/toltk/graph.tcl @ 7b8f6fc

1941-docker-image-to-testdevel
Last change on this file since 7b8f6fc was 7b8f6fc, checked in by Pedro Gea <pgea@…>, 10 years ago

Refs #1933
Se redibuja el gráfico tras actualizar los ejes ($graph configure axis ...) ya que según parece con rbc esto no se hace automáticamente.
Se añade el método ClearCrosshairs.
Se soluciona un bug decompilando archivos desde la ventana derecha del inspector.
Se corrige la actualización del inspector según el item seleccionado en el árbol.

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@7359 be4846ae-f051-483a-831f-b64e7d08527f

  • Property mode set to 100644
File size: 7.4 KB
Line 
1#/////////////////////////////////////////////////////////////////////////////
2# FILE    : graph.tcl
3# PURPOSE : This file is part of RBC Toolkit
4#/////////////////////////////////////////////////////////////////////////////
5
6# force rbc load
7
8if { [info command "_rbc_InitStack"] eq "" } {
9  rbc::graph .__g__
10  Rbc_ZoomStack .__g__
11  destroy .__g__
12  rename rbc::InitStack _rbc_InitStack
13}
14
15proc Busy_Patched { cmd args } {
16    puts "-- Busy $cmd $args --"
17    switch $cmd {
18      patched {
19        return 1
20      }
21      default {
22
23      }
24    }
25}
26
27if { [ catch { rbc::busy patched } ] } {
28  rename ::rbc::busy _rbc_busy
29  interp alias {} ::rbc::busy {} Busy_Patched
30  puts "interp alias {} ::rbc::busy {} Busy_Patched"
31}
32
33
34# Cambia el ViewMode
35# modos posibles:
36#   zoom-frame
37#   zoom-in
38#   zoom-out
39#   scroll
40
41proc Rbc_ViewMode { graph mode } {
42  global zoomInfo
43
44  if { ![rbc::ClearMode $graph $mode] } return
45
46  set zoomInfo($graph,mode) $mode
47
48  if { [string equal $mode "scroll"] } {
49    # limpio el stack
50    rbc::InitStack $graph $mode
51    bind scroll-$graph <ButtonPress-1> { rbc::SetScrollPoint %W %x %y }
52    bind scroll-$graph <ButtonRelease-1> { rbc::SetScrollPoint %W %x %y }
53    # este evento posiblemente ya no hara falta
54    bind scroll-$graph <ButtonPress-3> {
55      if { [%W inside %x %y] } {
56        rbc::ResetScroll %W
57      }
58    }
59    rbc::AddBindTag $graph scroll-$graph
60  } elseif { [regexp "zoom-*" $mode] } {
61    puts "mode = $mode"
62    bind zoom-$graph <ButtonPress-1> { rbc::SetZoomPoint %W %x %y }
63    if { [string equal $mode zoom-frame] } {
64      bind zoom-$graph <ButtonRelease-1> { rbc::SetZoomPoint %W %x %y }
65    } else {
66      bind zoom-$graph <ButtonRelease-1> ""
67    }
68    bind zoom-$graph <ButtonPress-3> {
69      if { [%W inside %x %y] } {
70        rbc::ResetZoom %W
71      }
72    }
73    rbc::AddBindTag $graph zoom-$graph
74  }
75}
76
77proc rbc::RemoveBindTag { widget args } {
78  set oldTagList [bindtags $widget]
79  foreach tag $args {
80    set index [lsearch $oldTagList $tag]
81    if { $index >= 0 } {
82        bindtags $widget [lreplace $oldTagList $index $index]
83    }
84  }
85}
86
87proc rbc::ClearCrosshairs { graph } {
88    rbc::RemoveBindTag $graph crosshairs-$graph
89    $graph crosshairs off
90}
91
92proc rbc::InitStack { graph {mode zoom-frame} } {
93    global zoomInfo
94
95    _rbc_InitStack $graph
96    # this is to allow zoom in, out scroll
97
98    set zoomInfo($graph,mode) $mode
99}
100
101proc rbc::SetZoomScale { graph scale } {
102  global zoomInfo
103
104  set zoomInfo($graph,scale) $scale
105}
106
107proc rbc::ClearMode { graph newmode } {
108  global zoomInfo
109
110  if { [info exists zoomInfo($graph,mode)] } {
111    if { [string equal $newmode $zoomInfo($graph,mode)] } {
112      return 0
113    }
114    set zoomInfo($graph,corner) A
115    if { [string equal $zoomInfo($graph,mode) "scroll"] } {
116      eval $graph marker delete [$graph marker names "scroll*"]
117      rbc::RemoveBindTag $graph "scroll-region-$graph" "scroll-$graph"
118    } else {
119      eval $graph marker delete [$graph marker names "zoom*"]
120      rbc::RemoveBindTag $graph "select-region-$graph" "zoom-$graph"
121    }
122  } else {
123    rbc::InitStack $graph ""
124  }
125  return 1
126}
127
128proc rbc::ZoomScale { graph } {
129  global zoomInfo
130
131  set cmd {}
132  foreach axis {x y} {
133    set limits [$graph axis limits $axis]
134    set min [lindex $limits 0]
135    set max [lindex $limits 1]
136    set delta$axis [expr 0.5 * ($max - $min)]
137    set c [list $graph axis configure $axis -min $min -max $max]
138    append cmd "$c\n"
139  }
140  set zoomInfo($graph,stack) [linsert $zoomInfo($graph,stack) 0 $cmd]
141  busy hold $graph
142  # This update lets the busy cursor take effect.
143  update
144
145  Tolcon_Trace "En ZoomScale zoomInfo($graph,scale) vale  $zoomInfo($graph,scale)"
146
147  if { [string equal $zoomInfo($graph,mode) "zoom-in"] } {
148    set deltax [expr $deltax * $zoomInfo($graph,scale)]
149    set deltay [expr $deltay * $zoomInfo($graph,scale)]
150  } else {
151    set deltax [expr $deltax / $zoomInfo($graph,scale)]
152    set deltay [expr $deltay / $zoomInfo($graph,scale)]
153  }
154
155  foreach {axis delta} [list x $deltax y $deltay] {
156    set v [$graph axis invtransform $axis $zoomInfo($graph,A,$axis)]
157    set min [expr $v - $delta]
158    set max [expr $v + $delta]
159    $graph axis configure $axis -min $min -max $max
160  }
161  #@! Redibuja el gráfico
162  event generate $graph <Configure>
163  # This "update" forces the graph to be redrawn
164  set this [::bayesGraph::getInstance $graph]
165  upvar \#0 ${this}::data data
166  set gr $data(gr,active)
167  #Tolcon_Trace "Aplicando Axis Ticks ZoomScale"
168  ::bayesGraph::GrapOptApplyAxisTicks    $this ${this}::options gr,$gr
169  update
170
171  busy release $graph
172}
173
174proc rbc::SetZoomPoint { graph x y } {
175  global zoomInfo zoomMod
176  if { ![info exists zoomInfo($graph,corner)] } {
177    rbc::InitStack $graph
178  }
179  rbc::GetCoords $graph $x $y $zoomInfo($graph,corner)
180
181  #puts  rbc::SetZoomPoint
182
183  if { [string compare $zoomInfo($graph,mode) "zoom-frame"] } {
184    rbc::ZoomScale $graph
185    return
186  }
187
188  if { [info exists zoomMod] } {
189    set modifier $zoomMod
190  } else {
191    set modifier "Any-"
192  }
193  bind select-region-$graph <${modifier}Motion> {
194    rbc::GetCoords %W %x %y B
195    #rbc::MarkPoint $graph B
196    rbc::Box %W
197  }
198  if { $zoomInfo($graph,corner) == "A" } {
199    if { ![$graph inside $x $y] } {
200      return
201    }
202    # First corner selected, start watching motion events
203
204    #rbc::MarkPoint $graph A
205    rbc::ZoomTitleNext $graph
206
207    rbc::AddBindTag $graph select-region-$graph
208    set zoomInfo($graph,corner) B
209  } else {
210    # Delete the modal binding
211    rbc::RemoveBindTag $graph select-region-$graph
212    rbc::PushZoom $graph
213    set zoomInfo($graph,corner) A
214  }
215}
216
217proc rbc::SetScrollPoint { graph x y } {
218    global zoomInfo
219
220    rbc::GetCoords $graph $x $y A
221    bind scroll-region-$graph <Any-Motion> {
222        rbc::GetCoords %W %x %y B
223        #rbc::MarkPoint $graph B
224        rbc::Scroll %W
225    }
226    if { $zoomInfo($graph,corner) == "A" } {
227        if { ![$graph inside $x $y] } {
228          return
229        }
230        # First corner selected, start watching motion events
231
232        #rbc::MarkPoint $graph A
233        rbc::ScrollTitle $graph
234
235        rbc::AddBindTag $graph scroll-region-$graph
236        set zoomInfo($graph,corner) B
237    } else {
238        # Delete the modal binding
239        ResetScroll $graph
240    }
241}
242
243proc rbc::Scroll { graph } {
244  global zoomInfo
245
246  set x1 [$graph xaxis invtransform $zoomInfo($graph,A,x)]
247  set x2 [$graph xaxis invtransform $zoomInfo($graph,B,x)]
248  set y1 [$graph yaxis invtransform $zoomInfo($graph,A,y)]
249  set y2 [$graph yaxis invtransform $zoomInfo($graph,B,y)]
250  #set deltax [expr $x2 - $x1]
251  #set deltay [expr $y2 - $y1]
252  # Cambiado para efecto 'agarrar el gráfico'
253  set deltax [expr $x1 - $x2]
254  set deltay [expr $y1 - $y2]
255  foreach {delta axis} [list $deltax x $deltay y] {
256    set limits [$graph axis limits $axis]
257    set lower [expr [lindex $limits 0] + $delta]
258    set upper [expr [lindex $limits 1] + $delta]
259    $graph axis configure $axis -min $lower -max $upper
260  }
261  #@! Redibuja el gráfico
262  event generate $graph <Configure>
263  set zoomInfo($graph,A,x) $zoomInfo($graph,B,x)
264  set zoomInfo($graph,A,y) $zoomInfo($graph,B,y)
265}
266
267proc rbc::ResetScroll { graph } {
268  global zoomInfo
269
270  eval $graph marker delete [$graph marker names "scroll*"]
271  rbc::RemoveBindTag $graph scroll-region-$graph
272  set zoomInfo($graph,corner) A
273}
274
275proc rbc::ScrollTitle { graph } {
276    if { [$graph cget -invertxy] } {
277        set coords "-Inf -Inf"
278    } else {
279        set coords "-Inf Inf"
280    }
281    $graph marker create text -name "scrollTitle" -text "scrolling ..." \
282        -coords $coords -bindtags "" -anchor nw
283}
Note: See TracBrowser for help on using the repository browser.