source: tol/tolbase/lib/toltk/sertable.tcl @ 567b369

1941-docker-image-to-testdevel
Last change on this file since 567b369 was 6d7779d, checked in by Jorge Pérez <josp.jorge@…>, 18 years ago

initial import

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

  • Property mode set to 100644
File size: 11.6 KB
RevLine 
[6d7779d]1#/////////////////////////////////////////////////////////////////////////////
2# FILE    : sertable.tcl
3# PURPOSE : This file contains a namespace called SeriesTable with its
4#           functions. It's for managing series tables.
5#           It's a child of BayesTable so inherites all its functionalities.
6#/////////////////////////////////////////////////////////////////////////////
7
8
9#/////////////////////////////////////////////////////////////////////////////
10  namespace eval ::SeriesTable {
11#
12# PURPOSE: The purpose of this namespace is organize code and functions and
13#          provides functions to create and manage a series table.
14#          A special namespace is created for each instance of Series table.
15#
16# VARIABLES:
17#   tmpOpt  -> temporary array used to store the widgets and variables of the
18#              options dialog.
19#   formats ->
20#
21#/////////////////////////////////////////////////////////////////////////////
22}
23
24
25#/////////////////////////////////////////////////////////////////////////////
26  proc ::SeriesTable::Create {path sergrp} {
27#
28# PURPOSE: Creates a series table instance
29#
30# PARAMETERS:
31#   path   -> series table path (frame)
32#   sergrp -> tol series group to be tabulated
33#
34#/////////////////////////////////////////////////////////////////////////////
35  set this [::BayesTable::Create $path \
36      -fillproc "::SeriesTable::Fill $sergrp" -child SeriesTable\
37      -OnWriteIni "::SeriesTable::WriteIni" \
38      -OnOptionCreate "::SeriesTable::OptionsCreate" \
39      -OnOptionDestroy "::SeriesTable::OptionsDestroy" \
40      -OnOptionApply "::SeriesTable::OptionsApply"]
41  ::BayesTable::SetData $this sergrp $sergrp
42  ReadIni   $this
43  Configure $this
44}
45
46#/////////////////////////////////////////////////////////////////////////////
47  proc ::SeriesTable::Fill {sergrp this} {
48#
49# PURPOSE: Procedure to fill data elements of the table. Gets data from a
50#          group of series and sets them to the table.
51#
52# PARAMETERS:
53#   sergrp -> tol series group (created by toltcl ::tol::create command)
54#   this   -> Instance of BayesTable
55#
56#/////////////////////////////////////////////////////////////////////////////
57  # insert the series into the table
58  set numCols [$sergrp serie size]
59  set numRows [$sergrp dating size]
60  ::BayesTable::SetElement $this 0 0 [$sergrp dating name]
61  for {set i 0} {$i < $numRows} {incr i} {
62    ::BayesTable::SetElement $this [expr $i+1] 0 [GetTickLabel $sergrp $i]
63  }
64  for {set j 0} {$j < $numCols} {incr j} {
65    ::BayesTable::SetElement $this 0 [expr $j+1] [$sergrp serie $j name]
66    foreach vec_data [$sergrp serie $j data] {
67      set x [lindex $vec_data 0]
68      set y [lindex $vec_data 1]
69      for {set i 0} {$i < [llength $x]} {incr i} {
70        ::BayesTable::SetElement $this [expr round([lindex $x $i])+1]\
71                   [expr $j+1] [lindex $y $i]
72      }
73    }
74  }
75  ::BayesTable::SetMatrixInfo $this\
76                [list [expr $numRows+1] [expr $numCols+1]] ""
77}
78
79#/////////////////////////////////////////////////////////////////////////////
80  proc ::SeriesTable::GetTickLabel { group tick } {
81#
82# PURPOSE:
83#
84# PARAMETERS:
85#   group ->
86#   tick  ->
87#
88#/////////////////////////////////////////////////////////////////////////////
89  set str ""
90  catch {
91    set str [$group dating $tick]
92  }
93  return $str
94}
95
96
97#/////////////////////////////////////////////////////////////////////////////
98# OPTIONS
99#/////////////////////////////////////////////////////////////////////////////
100
101#/////////////////////////////////////////////////////////////////////////////
102  proc ::SeriesTable::OptionsDestroy {this} {
103#
104# PURPOSE: Called before options dialog is destroyed. This procedure is called
105#          by parent BayesTable. Actually doesn't do anything.
106#
107# PARAMETERS:
108#   this -> Instance of BayesTable
109#
110#/////////////////////////////////////////////////////////////////////////////
111
112}
113
114#/////////////////////////////////////////////////////////////////////////////
115  proc ::SeriesTable::OptionsCreate {this ts} {
116#
117# PURPOSE: Creates especific options of a series table. It's called by
118#          BayesTable when general table options are created.
119#
120# PARAMETERS:
121#   this -> Instance of BayesTable
122#   ts   -> tabset in which options must be created
123#
124#/////////////////////////////////////////////////////////////////////////////
125  #insertar tabset
126  $ts insert end Series
127  set f [frame $ts.f]
128  $ts tab configure "Series" -text "Series" -window $f\
129    -fill both -padx 0 -selectbackground \#d9d9d9 -bg gray75
130
131  set w_tabset [::blt::tabset $f.ts -relief flat -highlightthickness 0\
132                        -bd 0 -outerpad 0 -tier 2 -slant right -textside right]
133  $w_tabset insert end DateFormat
134  set f1 [frame $w_tabset.f1]
135
136  $w_tabset tab configure "DateFormat" -text [mc "Date Format"]\
137    -window $f1 -fill both -padx 0 -selectbackground \#d9d9d9 -bg gray75
138
139  OptionsGet $this
140  OptionsCreateDateFormat $this $f1
141  OptionsCheck $this
142  OptionsSet   $this
143
144  grid $w_tabset -sticky news 
145  grid rowconfigure    $f 0 -weight 1
146  grid columnconfigure $f 0 -weight 1
147}
148
149
150#/////////////////////////////////////////////////////////////////////////////
151  proc ::SeriesTable::OptionsCreateDateFormat {this w} {
152#
153# PURPOSE: Creates a frame with date format options
154#
155# PARAMETERS:
156#   this -> Instance of BayesTable
157#   w    -> widget's path to allocate the frame
158#
159#/////////////////////////////////////////////////////////////////////////////
160  variable tmpOpt
161  variable formats
162
163  # X-Axis
164  TitleFrame $w.tf1 -text [mc "Format String"]
165  set f1 [$w.tf1 getframe]
166
167  set formats [list \
168     [mc "TOL Long Format"]   "%cy%Ym%md%d%uh%hi%is%s" \
169     [mc "TOL Short Format"]  "%cy%Ym%md%d" \
170     "Completo YYYY/MM/dd"    "%c%w %Y/%m/%d" \
171     "Completo dd/MM/YYYY"    "%c%w %d/%m/%Y" \
172     "Fecha larga"            "%c%W, %d de %N de %Y" \
173     "Completo dd/Month/YYYY" "%c%w %d/%n/%Y" \
174     [mc "User Defined"]]
175  foreach {cad for} $formats {
176    lappend lstCad $cad
177  }
178
179  label $f1.lFormat -text [mc Format]:
180  ComboBox $f1.cbFormat -width 30 -height 6 -editable false -values $lstCad\
181      -textvariable ::SeriesTable::tmpOpt(var,dateFormat)\
182      -modifycmd [list ::SeriesTable::OptionsCheckDateFormat $this]
183  label $f1.lString -text [mc String]:
184  set tmpOpt(widgets,dateString) [Entry $f1.eString -width 45 -state disabled\
185         -textvariable ::SeriesTable::tmpOpt(var,dateString)]
186  bind $f1.eString <KeyRelease> [list ::SeriesTable::OptionsCheckDateString $this]
187  label $f1.lView   -text [mc Sample]:
188  set tmpOpt(widgets,dateView) [Entry $f1.eView   -width 45 -state disabled\
189         -textvariable ::SeriesTable::tmpOpt(var,dateView)]
190  button $f1.bHelp  -text [mc "Format Specifiers"]\
191     -command [list ::SeriesGraph::ShowSpecifiers $w]
192  frame $f1.f -width 25
193  grid $f1.f $f1.lFormat $f1.cbFormat -sticky nw -padx 2 -pady 2
194  grid ^     $f1.lString $f1.eString  -sticky nw -padx 2 -pady 2
195  grid ^     $f1.lView   $f1.eView    -sticky nw -padx 2 -pady 2
196  grid ^     $f1.bHelp   -            -column 1    -sticky nw -pady 2
197  grid rowconfigure    $f1 3 -weight 1
198  grid columnconfigure $f1 2 -weight 1
199  grid $w.tf1 -sticky news -padx 2
200  grid rowconfigure    $w 0 -weight 1
201  grid columnconfigure $w 0 -weight 1
202}
203
204
205#/////////////////////////////////////////////////////////////////////////////
206  proc ::SeriesTable::OptionsGet {this} {
207#
208# PURPOSE: Initializes all options variables and stores them into the
209#          temporary 'tmpOpt' array.
210#
211# PARAMETERS:
212#   this   -> Instance of BayesTable
213#
214#/////////////////////////////////////////////////////////////////////////////
215  variable tmpOpt
216
217  set tmpOpt(var,dateString)   [::BayesTable::GetOption $this dateString]
218}
219
220
221#/////////////////////////////////////////////////////////////////////////////
222  proc ::SeriesTable::OptionsSet {this} {
223#
224# PURPOSE: Commits all options values from the temporary 'tmpOpt' array to
225#          other structure.
226#
227# PARAMETERS:
228#   this   -> Instance of BayesTable
229#
230#/////////////////////////////////////////////////////////////////////////////
231  variable tmpOpt
232
233  regsub -all var, [array names ::SeriesTable::tmpOpt var,*] "" optNames
234  foreach it $optNames {
235    ::BayesTable::SetOption $this dateString $tmpOpt(var,$it)
236  }
237}
238
239
240#/////////////////////////////////////////////////////////////////////////////
241  proc ::SeriesTable::OptionsApply {this} {
242#
243# PURPOSE: Applies options from the options dialog. It's called by BayesTable
244#          when general table options are applied.
245#
246# PARAMETERS:
247#   this  -> Instance of BayesTable
248#
249#/////////////////////////////////////////////////////////////////////////////
250  variable tmpOpt
251  OptionsApplyDateFormat $this $tmpOpt(var,dateString)
252  #Save options after apply
253  OptionsSet $this
254}
255
256
257proc ::SeriesTable::OptionsApplyDateFormat {this dateString} {
258  set sergrp [::BayesTable::GetData $this sergrp]
259  $sergrp format $dateString
260  ::SeriesTable::Fill $sergrp $this
261}
262
263
264proc ::SeriesTable::OptionsCheck {this} {
265  OptionsCheckDateString $this
266  #OptionsCheckDateFormat $this
267}
268
269proc ::SeriesTable::OptionsCheckDateFormat {this} {
270  variable tmpOpt
271  variable formats
272
273  if [string equal $tmpOpt(var,dateFormat) [mc "User Defined"]] {
274    $tmpOpt(widgets,dateString) configure -state normal
275    #set tmpOpt(var,dateString) ""
276  } else  {
277    $tmpOpt(widgets,dateString) configure -state disabled
278    set idx [lsearch -exact $formats $tmpOpt(var,dateFormat)]
279    set tmpOpt(var,dateString) [lindex $formats [expr $idx+1]]
280    #Coger la fecha del sistema, aplicarle el formato y mostrarla
281    set tmpOpt(var,dateView) [::tol::date now $tmpOpt(var,dateString)]
282  }
283}
284
285proc ::SeriesTable::OptionsCheckDateString {this} {
286  variable tmpOpt
287  variable formats
288
289  if {[set idx [lsearch -exact $formats $tmpOpt(var,dateString)]] != -1} {
290    set tmpOpt(var,dateFormat) [lindex $formats [expr $idx-1]]
291  } else  {
292    set tmpOpt(var,dateFormat) [lindex $formats end]
293    $tmpOpt(widgets,dateString) configure -state normal
294  }
295  set tmpOpt(var,dateView) [::tol::date now $tmpOpt(var,dateString)]
296}
297
298
299#/////////////////////////////////////////////////////////////////////////////
300# INIFILE
301#/////////////////////////////////////////////////////////////////////////////
302
303#/////////////////////////////////////////////////////////////////////////////
304  proc ::SeriesTable::ReadIni {this} {
305#
306# PURPOSE: Reads series table specific options from .ini file. First of all,
307#          reads options from BayesTable.
308#
309# PARAMETERS:
310#   this  -> Instance of BayesTable
311#
312#/////////////////////////////////////////////////////////////////////////////
313  # General options (parent)
314  ::BayesTable::ReadIni $this
315  # Specific options
316  set rini ::iniFile::Read
317  set sergrp [::BayesTable::GetData $this sergrp]
318  ::BayesTable::SetOption $this dateString \
319     [$rini SeriesTable dateString [$sergrp format]]
320}
321
322
323#/////////////////////////////////////////////////////////////////////////////
324  proc ::SeriesTable::WriteIni {this} {
325#
326# PURPOSE: Writes series table specific options to .ini file. This procedure
327#          is called by parent BayesTable.
328#
329# PARAMETERS:
330#   this  -> Instance of BayesTable
331#
332#/////////////////////////////////////////////////////////////////////////////
333  set wini ::iniFile::Write
334  $wini SeriesTable dateString  [::BayesTable::GetOption $this dateString]
335}
336
337
338#/////////////////////////////////////////////////////////////////////////////
339  proc ::SeriesTable::Configure {this} {
340#
341# PURPOSE: Configures some options of Series Table. First of all, configures
342#          options from BayesTable.
343#
344# PARAMETERS:
345#   this  -> Instance of BayesTable
346#
347#/////////////////////////////////////////////////////////////////////////////
348  # General options (parent)
349  ::BayesTable::Configure $this
350  # Specific options
351  OptionsApplyDateFormat $this [::BayesTable::GetOption $this dateString]
352}
Note: See TracBrowser for help on using the repository browser.