source: tol/tolbase/lib/toltk/tolmethods.tcl @ 78e136b

1941-docker-image-to-testdevel
Last change on this file since 78e136b was e4cddd7, checked in by Jorge Pérez <josp.jorge@…>, 15 years ago

fixes #1466, ::AutocorGraph::Create should receive the toltcl's object reference.

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

  • Property mode set to 100644
File size: 11.9 KB
Line 
1#/////////////////////////////////////////////////////////////////////////////
2# FILE    : tolmethods.tcl
3# PURPOSE : Metodos de Tol desde TCL
4#/////////////////////////////////////////////////////////////////////////////
5
6
7# includes. 1 -> Include.  0 -> No
8if { 0 } {
9  # packages
10  package require Tk
11  package require BWidget
12#  package require BLT
13  #
14  wm geometry . 1x1+1+1
15  set toltk_script_path [file dirname [info script]]
16  # load tclIndex
17  set dir $toltk_script_path
18  source [file join $toltk_script_path "tclIndex"]
19  unset dir
20  if { ![info exists toltk_library] } {
21    set toltk_library [file join $toltk_script_path ..]
22  }
23  # messages
24  package require msgcat
25  namespace import msgcat::*                                   
26  # bitmap
27  Bitmap::use
28  set toltk_script_path [file dirname [info script]]
29  #Tol load images:
30  set toltk_images_path [file join ${toltk_script_path} images]
31  if { [lsearch $Bitmap::path $toltk_images_path] == -1 } {
32    #añade la ruta de las imágenes para que Bitmap sepa donde están:
33    lappend Bitmap::path [file join $toltk_script_path images]
34  }
35}
36
37#/////////////////////////////////////////////////////////////////////////////
38# Methods to Serie
39#/////////////////////////////////////////////////////////////////////////////
40
41#/////////////////////////////////////////////////////////////////////////////
42proc Tol_SerieChartMethod { sergrp fileDest } {
43#
44# PURPOSE: Hook of Chart method
45#
46# PARAMETERS:
47#   sergrp   -> group of series
48#   fileDest -> destination file
49#/////////////////////////////////////////////////////////////////////////////
50  # cargamos la variable GCFFile de TOL
51  set fileGCF [TclGetVar Text GCFFile]
52  if {![file exists $fileGCF]} {
53    set fileGCF {}
54  } 
55  # MDI
56  set tl [::project::CreateForm \
57      -title [mc "Series graph"] \
58      -type Graphs \
59      -iniconfig SeriesGraph \
60      -width 600 -height 200
61  ]
62  set top [$tl getframe]
63
64  set isphoto [expr {$fileDest ne ""}]
65  #Tolcon_Trace "set isphoto [expr {$fileDest ne {}}]"
66  set Instance [::SeriesGraph::Create $top.g $sergrp \
67                    -photo $isphoto -fileGCF $fileGCF]
68  bind $top.g <Destroy> +[list ::tol::seriegrp destroy $sergrp]
69  pack $top.g -fill both -expand yes
70  update
71
72  ::bayesGraph::GrapOptApplyAxisTicks $Instance ${Instance}::options gr,0
73  if {$isphoto} {
74    ::bayesGraph::TakePhoto $Instance $fileDest
75    after idle "destroy $tl"
76  }
77}
78
79
80#/////////////////////////////////////////////////////////////////////////////
81  proc Tol_SerieChart { title source gcfFile geometry filetosave } {
82#
83# PURPOSE: Paint the graph of a set of series
84#
85# PARAMETERS:
86#   title      -> title for the graph
87#   source     -> reference to the set
88#   gcfFile    -> a gcf to aply to the graph
89#   geometry   -> geometry for the window of the graph
90#   filetosave -> if a file name is given the graph is written to disk instead
91#               of displayed
92#
93#/////////////////////////////////////////////////////////////////////////////
94  # GCF
95  if {![string length $gcfFile]} {
96    set gcfFile [TclGetVar Text GCFFile]
97    if {[string length $gcfFile]} {
98      eval set gcfFile $gcfFile
99    }
100  }
101  if {![file exists $gcfFile]} {
102    set gcfFile {}
103  }
104  #puts "GCF FILE: $gcfFile" 
105  # Title
106  set wTitle $title
107  if {![string length $title]} {
108    set wTitle [mc "Series graph"]
109  }
110
111  # Create Group Series
112  #puts "Tol_SerieChart: source = $source"
113  set nsource [lindex [TclGetVar Set $source] 0]
114  set lstSerie {}
115  for {set i 1} {$i <= $nsource} {incr i} {
116    lappend lstSerie "Set $source $i"
117  }
118  set sergrp tableserie[clock clicks]
119  set tl ""
120  if {[llength $lstSerie]} {
121      # MDI
122    set tl [::project::CreateForm \
123      -title $wTitle -type Graphs -iniconfig SeriesGraph -geometry $geometry]
124    $tl setgeometry $geometry
125    set top [$tl getframe]
126    #puts "Tol_SerieChart: tol::seriegrp sergrp = $sergrp, lstSerie = $lstSerie"
127    eval ::tol::seriegrp create $sergrp $lstSerie
128    # Create
129    set isphoto [expr {$filetosave ne ""}]
130    set Instance [::SeriesGraph::Create $top.g $sergrp \
131      -photo $isphoto -fileGCF $gcfFile -title [list $title]]
132    bind $top.g <Destroy> +[list ::tol::seriegrp destroy $sergrp]
133    pack $top.g -fill both -expand yes
134    update
135    # Control Axis
136    ::bayesGraph::GrapOptApplyAxisTicks $Instance ${Instance}::options gr,0
137    # Save graph ?
138    if {$isphoto} {
139      ::bayesGraph::TakePhoto $Instance $filetosave
140      after idle "destroy $tl"
141    }
142  } else {
143    set msg [mc {No selection information related}]
144    ::TolConsole::HciWriter "<W>${msg}</W>"
145  }
146  return $tl
147}
148
149
150#/////////////////////////////////////////////////////////////////////////////
151proc Tol_SerieTabulate { source {title ""} {geometry {}} } {
152#
153# PURPOSE: Tabulates a serie in a TolBase table window
154#
155# PARAMETERS:
156#   source   -> the tol serie variable or variables (if a list is given)
157#   geometry -> geometry specification
158#/////////////////////////////////////////////////////////////////////////////
159
160  # chek type TOL of source
161  set gramVar [GetGlobalUniqueName __tabser__]
162  ::tol::console eval "Text $gramVar = Grammar($source);"
163  set namGra [string trim [TclGetVar Text $gramVar] {"}];#{"}   
164  # destroy
165  ::tol::console stack release $gramVar   
166  # list of series tabulate
167  set lstSerie {}   
168  switch $namGra {
169    Serie   { set lstSerie [ list [ list Serie $source ] ] }
170    Set     {
171      set nsource [lindex [TclGetVar Set $source] 0]
172      for {set i 1} {$i <= $nsource} {incr i} {
173        lappend lstSerie [list Set $source $i ]
174      }
175    }
176  } 
177  # lstSerie > 0 ?
178  set tl {}
179  if {[llength $lstSerie]} {
180    # create sergrp
181    set sergrp group[clock clicks]
182    eval "::tol::seriegrp create $sergrp $lstSerie"
183    #title
184    if { ![llength $title] } {
185      set title [mc "Time series table"]
186    }
187    # create
188    set tl [::project::CreateForm \
189        -title $title \
190        -iniconfig SeriesTable \
191        -type Tables \
192        -geometry $geometry
193    ]
194    $tl setgeometry $geometry   
195    set tlf [$tl getframe]
196    # configuration
197    btable $tlf.t -parent $tl \
198                  -posteditcmd [list ::TolConsole::TableRecentUpdate $tlf.t] \
199                  -iniconfig btable
200    $tlf.t fillSerie $sergrp   
201    bind $tlf.t <Destroy> +[list ::tol::seriegrp destroy $sergrp]
202    $tl bind <Control-F4> [list $tl kill]
203    pack $tlf.t -fill both -expand yes
204    update
205  }
206  return $tl
207}
208
209#/////////////////////////////////////////////////////////////////////////////
210proc Tol_SerieAutocor { source {title ""} {geometry {}} } {
211#
212# PURPOSE: Tabulates a serie in a TolBase table window
213#
214# PARAMETERS:
215#   source   -> the tol serie variable or variables (if a list is given)
216#   geometry -> geometry specification
217#/////////////////////////////////////////////////////////////////////////////
218
219  # name
220  set objRef [ list "Serie" $source ]
221  set nameSerie [lindex [::tol::info variable $objRef] 1]
222 
223  #title
224  if { ![llength $title] } {
225    set title "[mc {Autocorrelation graph}]: $nameSerie"
226  }
227  # create
228  set tl [::project::CreateForm \
229    -title $title \
230    -iniconfig AutocorGraph \
231    -type Graphs \
232    -geometry $geometry -helpkey "Tb4GraAco"
233  ]
234  $tl setgeometry $geometry 
235  set tlf [$tl getframe]
236  # configuration
237  ::AutocorGraph::Create $tlf.g $objRef
238  $tl bind <Control-F4> "$tl kill; break"
239  pack $tlf.g -fill both -expand yes
240  update
241  return $tl 
242}
243
244#/////////////////////////////////////////////////////////////////////////////
245# Methods to Set
246#/////////////////////////////////////////////////////////////////////////////
247
248#/////////////////////////////////////////////////////////////////////////////
249proc Tol_SetChartMethod { title source gcfFile geometry filetosave lstNames
250                          type lstPairs {holdon ""}} {
251#
252# PURPOSE: Hook of Chart method
253#
254# PARAMETERS:
255#   title    -> title for the graph
256#   source   -> reference to the set
257#   gcfFile  -> a gcf to aply to the graph
258#   geometry -> geometry for the window of the graph
259#   file     -> if a file name is given the graph is written to disk instead of displayed
260#   lstNames -> names for the series/points,..
261#   type     -> 0 for custom association of data columns
262#            -> 1 for all data columns to first one
263#            -> 2 for all data columns to generic
264#            -> 3 for even data columns to odd ones
265#   lstPairs -> when type is 0 pairs is the list of correspondence beetwen index
266#               columns to data columns (x-y pairs)
267#   holdon   -> tell if the new graph goes into a new context or an existing one
268#
269#/////////////////////////////////////////////////////////////////////////////
270  # GCF
271  if {![string length $gcfFile]} {
272    set gcfFile [TclGetVar Text GCFFile]
273  }
274  if {![file exists $gcfFile]} {
275    set gcfFile {}
276  }
277  # Title
278  set wTitle $title
279  if {![string length $title]} {
280    set wTitle [mc "Set graph"]
281  }
282  # MDI
283  if {$holdon ne "" && (![winfo exists $holdon] || [winfo class $holdon] ne "Mdidoc")} {
284    Tol_HciWriter "<W>[mc {Graphic requested to be drawn on %s but that graphic context does not exist or is not a valid grafic windows} $holdon]</W>"
285    set holdon ""
286  }
287  if {[winfo exists $holdon]} {
288    set tl $holdon
289  } else {
290    puts "no existe '$holdon' por eso ... ::project::CreateForm"
291
292    set tl [::project::CreateForm \
293                -title $wTitle -type Graphs -iniconfig SetGraph -geometry $geometry]
294    $tl setgeometry $geometry
295  }
296  set top [$tl getframe]
297  # if source is a list is interpreted as a set name and indexes accesing a element
298  if {0} {
299  if { [llength $source] > 1 } {
300    set setname [GetUniqueName Set]
301    set sourcename [lindex $source 0]
302    set strtoeval "Set ${setname} = ${sourcename}"
303    for {set i 1} {$i < [llength $source]} {incr i} {
304      set elem [lindex $source $i]
305      set strtoeval "${strtoeval}\[$elem\]"
306    }
307    ::tol::console eval $strtoeval
308    set source $setname
309  }
310  }
311  set cmd tableset[clock clicks]
312  ::tol::tableset create $cmd [linsert $source 0 Set]
313  set Instance [::SetGraphDialog::DrawSet $top.g $cmd $source $type $lstPairs \
314    $lstNames $gcfFile [list $title]]
315  if {$holdon ne ""} {
316    ::tol::tableset destroy $cmd
317    if { [llength $source] > 1} {
318      ::tol::stack release $source
319    }
320  } else {
321    bind $top.g <Destroy> +[list ::tol::tableset destroy $cmd]
322    if { [llength $source] > 1} {
323      bind $top.g <Destroy> +[list ::tol::stack release $source]
324    }
325    pack $top.g -fill both -expand yes
326    update
327    ::bayesGraph::GrapOptApplyAxisTicks $Instance ${Instance}::options gr,0
328    if { [string length $filetosave] } {
329      ::bayesGraph::TakePhoto $Instance $filetosave
330      after idle "destroy $tl"
331    }
332  }
333  return $tl
334}
335
336
337#/////////////////////////////////////////////////////////////////////////////
338proc Tol_SetTabulate { set {title ""} {geometry {}} } {
339#
340# PURPOSE: Tabulates a set in a TolBase table window
341#
342# PARAMETERS:
343#   source   -> the tol set variable
344#   geometry -> geometry specification
345#/////////////////////////////////////////////////////////////////////////////
346
347  if {[llength $set] > 1} {
348    set nameSet [lindex [::tol::info variable $set] 1]
349    set setref $set
350  } else {
351    set nameSet $set
352    set setref [ list Set $set ]
353  }
354 
355  if { ![llength $title] } { set title  "[mc "Set table"]: $nameSet" }
356
357  set setgrp group[clock clicks]
358
359  set tl {}
360  if { ![ catch { ::tol::tableset create $setgrp $setref } ] } {
361    # create
362    set tl [::project::CreateForm \
363        -title $title \
364        -iniconfig SetTable \
365        -type Tables \
366        -geometry $geometry
367    ]
368    $tl setgeometry $geometry   
369    set tlf [$tl getframe]
370    # config
371    btable $tlf.t -parent $tl \
372                  -posteditcmd [list ::TolConsole::TableRecentUpdate $tlf.t] \
373                  -iniconfig btable
374    $tlf.t fillSet $setgrp
375    pack $tlf.t -fill both -expand yes
376    bind $tlf.t <Destroy> +[list ::tol::tableset destroy $setgrp]
377    $tl bind <Control-F4> [list $tl kill]
378    update
379  } else {
380    tk_messageBox -type ok -icon warning -message [mc "Set not tabulable"]\
381      -parent . -title [mc Warning]
382    #    -parent $w_tabset -title [mc Warning]
383  }
384  return $tl 
385}
Note: See TracBrowser for help on using the repository browser.