source: tol/tolbase/lib/toltk/tolmethods.tcl @ 2490d320

1941-docker-image-to-testdevel
Last change on this file since 2490d320 was 2490d320, checked in by Christian Paz <cpaz@…>, 18 years ago

First part of correction of TclChartSerie method to chart series.

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

  • Property mode set to 100644
File size: 11.3 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 [::tol::info variable [list 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 [::tol::info variable [list Text GCFFile]]
97    if {[string length $gcfFile]} {
98      eval set gcfFile $gcfFile
99    }
100  }
101  if {![file exists $gcfFile]} {
102    set gcfFile {}
103  }
104puts "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  # ::tol::info variable returns a list [Grammar VariableName [numofelements "Elementos"] ... ]
113  # so get the index 0 of the index 2
114  set nsource [lindex [lindex [::tol::info variable [list Set $source]] 2] 0]
115  set lstSerie {}
116  set i 1
117  while {$i <= $nsource && $i <= 32 } {
118    lappend lstSerie "$source $i"
119        set i [expr $i+1]
120  }
121  set sergrp tableserie[clock clicks]
122
123  set tl ""
124  if {[llength $lstSerie]} {
125      # MDI
126
127    set tl [::project::CreateForm \
128      -title $wTitle -type Graphs -iniconfig SeriesGraph -geometry $geometry]
129    $tl setgeometry $geometry
130    set top [$tl getframe]
131    eval ::tol::seriegrp create $sergrp $lstSerie
132    # Create
133    set isphoto [expr {$filetosave ne ""}]
134    set Instance [::SeriesGraph::Create $top.g $sergrp \
135      -photo $isphoto -fileGCF $gcfFile -title [list $title]]
136    bind $top.g <Destroy> +[list ::tol::seriegrp destroy $sergrp]
137    pack $top.g -fill both -expand yes
138    update
139    # Control Axis
140    ::bayesGraph::GrapOptApplyAxisTicks $Instance ${Instance}::options gr,0
141    # Save graph ?
142    if {$isphoto} {
143      ::bayesGraph::TakePhoto $Instance $filetosave
144      after idle "destroy $tl"
145    }
146  } else {
147    set msg [mc {No selection information related}]
148    ::TolConsole::HciWriter "<W>${msg}</W>"
149  }
150  return $tl
151}
152
153
154#/////////////////////////////////////////////////////////////////////////////
155proc Tol_SerieTabulate { source {title ""} {geometry {}} } {
156#
157# PURPOSE: Tabulates a serie in a TolBase table window
158#
159# PARAMETERS:
160#   source   -> the tol serie variable or variables (if a list is given)
161#   geometry -> geometry specification
162#/////////////////////////////////////////////////////////////////////////////
163
164  # chek type TOL of source
165  set gramVar [GetGlobalUniqueName __tabser__]
166  ::tol::console eval "Text $gramVar = Grammar($source);"
167  set namGra [string trim [::tol::info variable [list Text $gramVar] ] {"}];#{"}   
168  # destroy
169  ::tol::console stack release $gramVar   
170  # list of series tabulate
171  set lstSerie {}   
172  switch $namGra {
173    Serie   { set lstSerie $source }
174    Set     {
175      set nsource [lindex [::tol::info variable [list Set $source] ] 0]
176      for {set i 1} {$i <= $nsource} {incr i} {
177        lappend lstSerie "$source $i"
178      }
179    }
180  } 
181  # lstSerie > 0 ?
182  set tl {}
183  if {[llength $lstSerie]} {
184    # create sergrp
185    set sergrp group[clock clicks]
186    eval "::tol::seriegrp create $sergrp $lstSerie"
187    #title
188    if { ![llength $title] } {
189      set title [mc "Time series table"]
190    }
191    # create
192    set tl [::project::CreateForm \
193        -title $title \
194        -iniconfig SeriesTable \
195        -type Tables \
196        -geometry $geometry
197    ]
198    $tl setgeometry $geometry   
199    set tlf [$tl getframe]
200    # configuration
201    btable $tlf.t -parent $tl \
202                  -posteditcmd [list ::TolConsole::TableRecentUpdate $tlf.t] \
203                  -iniconfig btable
204    $tlf.t fillSerie $sergrp   
205    bind $tlf.t <Destroy> +[list ::tol::seriegrp destroy $sergrp]
206    $tl bind <Control-F4> [list $tl kill]
207    pack $tlf.t -fill both -expand yes
208    update
209  }
210  return $tl
211}
212
213#/////////////////////////////////////////////////////////////////////////////
214proc Tol_SerieAutocor { source {title ""} {geometry {}} } {
215#
216# PURPOSE: Tabulates a serie in a TolBase table window
217#
218# PARAMETERS:
219#   source   -> the tol serie variable or variables (if a list is given)
220#   geometry -> geometry specification
221#/////////////////////////////////////////////////////////////////////////////
222
223  # name
224  if {[llength $source] > 1} {
225    set nameSerie [lindex [::tol::info variable $source] 1]
226  } else {
227    set nameSerie $source
228  } 
229  #title
230  if { ![llength $title] } {
231    set title "[mc "Autocorrelation graph"]: $nameSerie"
232  }
233  # create
234  set tl [::project::CreateForm \
235    -title $title \
236    -iniconfig AutocorGraph \
237    -type Graphs \
238    -geometry $geometry -helpkey "Tb4GraAco"
239  ]
240  $tl setgeometry $geometry 
241  set tlf [$tl getframe]
242  # configuration
243  ::AutocorGraph::Create $tlf.g $source
244  $tl bind <Control-F4> "$tl kill; break"
245  pack $tlf.g -fill both -expand yes
246  update
247  return $tl 
248}
249
250#/////////////////////////////////////////////////////////////////////////////
251# Methods to Set
252#/////////////////////////////////////////////////////////////////////////////
253
254#/////////////////////////////////////////////////////////////////////////////
255proc Tol_SetChartMethod { title source gcfFile geometry filetosave lstNames type lstPairs } {
256#
257# PURPOSE: Hook of Chart method
258#
259# PARAMETERS:
260#   title    -> title for the graph
261#   source   -> reference to the set
262#   gcfFile  -> a gcf to aply to the graph
263#   geometry -> geometry for the window of the graph
264#   file     -> if a file name is given the graph is written to disk instead of displayed
265#   lstNames -> names for the series/points,..
266#   type     -> 0 for custom association of data columns
267#            -> 1 for all data columns to first one
268#            -> 2 for all data columns to generic
269#            -> 3 for even data columns to odd ones
270#   lstPairs -> when type is 0 pairs is the list of correspondence beetwen index
271#               columns to data columns (x-y pairs)
272#
273#/////////////////////////////////////////////////////////////////////////////
274  # GCF
275  if {![string length $gcfFile]} {
276    set gcfFile [::tol::info variable [list Text GCFFile] ]
277  }
278  if {![file exists $gcfFile]} {
279    set gcfFile {}
280  }
281  # Title
282  set wTitle $title
283  if {![string length $title]} {
284    set wTitle [mc "Set graph"]
285  }
286  # MDI
287  set tl [::project::CreateForm \
288    -title $wTitle -type Graphs -iniconfig SetGraph -geometry $geometry]
289  $tl setgeometry $geometry 
290  set top [$tl getframe]
291  # if source is a list is interpreted as a set name and indexes accesing a element
292  if { [llength $source] > 1 } {
293    set setname [GetUniqueName Set]
294    set sourcename [lindex $source 0]
295    set strtoeval "Set ${setname} = ${sourcename}"
296    for {set i 1} {$i < [llength $source]} {incr i} {
297      set elem [lindex $source $i]
298      set strtoeval "${strtoeval}\[$elem\]"
299    }
300    ::tol::console eval $strtoeval
301    set source $setname
302  }
303  set cmd tableset[clock clicks]
304  ::tol::tableset create $cmd $source
305  set Instance [::SetGraphDialog::DrawSet $top.g $cmd $source $type $lstPairs \
306    $lstNames $gcfFile [list $title]]
307  bind $top.g <Destroy> +[list ::tol::tableset destroy $cmd]
308  if { [llength $source] > 1} {
309    bind $top.g <Destroy> +[list ::tol::stack release $source]
310  }
311  pack $top.g -fill both -expand yes
312  update
313  ::bayesGraph::GrapOptApplyAxisTicks $Instance ${Instance}::options gr,0
314  if { [string length $filetosave] } {
315    ::bayesGraph::TakePhoto $Instance $filetosave
316    after idle "destroy $tl"
317  }
318  return $tl
319}
320
321
322#/////////////////////////////////////////////////////////////////////////////
323proc Tol_SetTabulate { set {title ""} {geometry {}} } {
324#
325# PURPOSE: Tabulates a set in a TolBase table window
326#
327# PARAMETERS:
328#   source   -> the tol set variable
329#   geometry -> geometry specification
330#/////////////////////////////////////////////////////////////////////////////
331
332  if {[llength $set] > 1} {
333    set nameSet [lindex [::tol::info variable $set] 1]
334  } else {
335    set nameSet $set
336  }
337 
338  if { ![llength $title] } { set title  "[mc "Set table"]: $nameSet" }
339
340  set setgrp group[clock clicks]
341
342  set tl {}
343  if {![catch {::tol::tableset create $setgrp $set}]} {
344    # create
345    set tl [::project::CreateForm \
346        -title $title \
347        -iniconfig SetTable \
348        -type Tables \
349        -geometry $geometry
350    ]
351    $tl setgeometry $geometry   
352    set tlf [$tl getframe]
353    # config
354    btable $tlf.t -parent $tl \
355                  -posteditcmd [list ::TolConsole::TableRecentUpdate $tlf.t] \
356                  -iniconfig btable
357    $tlf.t fillSet $setgrp
358    pack $tlf.t -fill both -expand yes
359    bind $tlf.t <Destroy> +[list ::tol::tableset destroy $setgrp]
360    $tl bind <Control-F4> [list $tl kill]
361    update
362  } else {
363    tk_messageBox -type ok -icon warning -message [mc "Set not tabulable"]\
364      -parent . -title [mc Warning]
365    #    -parent $w_tabset -title [mc Warning]
366  }
367  return $tl 
368}
Note: See TracBrowser for help on using the repository browser.