source: tol/tolbase/lib/toltk/setgraph.tcl @ 8704ee9

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

fixes #1630, a aplica un ZoomExtend

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

  • Property mode set to 100644
File size: 40.5 KB
Line 
1#/////////////////////////////////////////////////////////////////////////////
2# FILE    : setgraph.tcl
3# PURPOSE : This file
4#           It's a child of bayesGraph so inherites all its functionalities.
5#/////////////////////////////////////////////////////////////////////////////
6
7namespace eval ::SetGraph {
8}
9
10
11#/////////////////////////////////////////////////////////////////////////////
12proc ::SetGraph::Create {path info set tableset {fileGCF {}} {title {}}} {
13#
14# PURPOSE: Creates an instance of a bayesGraph and inserts the graph lines
15#
16# PARAMETERS:
17#   path      -> path of the graph
18#   info      -> list with info of series to graph. Has next syntax:
19#     {vectors <vectors> names <names> minX <minX> maxX <maxX> xTicks <xTicks>}
20#     where:
21#       vectors ->
22#       names   ->
23#       xTicks  ->
24#   set       -> reference to the TOL set
25#   tableset  ->
26#   fileGCF   -> file the graphic configuration file. Default ""
27#   title     -> title of chart
28#
29# RETURN: The instance of the graph.
30#
31#/////////////////////////////////////////////////////////////////////////////
32  if {[winfo exists $path] && [winfo class $path] eq "bayesGraph"} {
33    set Instance "::bayesGraph::$path"
34    set holdon 1
35  } else {
36    set Instance [::bayesGraph::Create $path g]
37    set holdon 0
38  }
39  upvar \#0 ${Instance}::widgets widgets
40  upvar \#0 ${Instance}::data data
41  upvar \#0 ${Instance}::options opt
42
43  if {!$holdon} {
44    set data(namespace) SetGraph
45    set data(proc,OnComputeStepX)  ::SetGraph::ComputeStepX
46    set data(proc,OnEvalWindow)    ::SetGraph::EvalWindow
47    set data(proc,OnToTable)       ::SetGraph::ToTable
48    set data(proc,OnWriteIni)      ::SetGraph::WriteIni
49    set data(proc,xAxisCommand)    [list ::SetGraph::GetTickLabel $Instance]
50    set data(proc,x2AxisCommand)   [list ::SetGraph::GetTickLabel $Instance]
51  }
52 
53  set gr 0
54  set grpath $widgets(gr,$gr)
55
56  #::SetGraphDialog::Init $tableset
57
58  set gInfo(vectors) ""
59  set gInfo(names)   ""
60  set gInfo(xTicks)  ""
61
62  #puts "***** info : ***** \n$info"
63  array set gInfo $info
64
65  if {!$holdon} {
66    set data(xTicks) $gInfo(xTicks)
67   
68    set data(gr,$gr,set) $set
69    set data(gr,$gr,tableset) $tableset
70    set data(gr,$gr,OnGetXTicks)    ::SetGraph::GetXTicks 
71    set data(gr,$gr,OnGetXValues)   ::SetGraph::GetXValues 
72  }
73  # insert the series into the graph
74  if {$holdon} {
75    set ii 0
76    foreach item [$grpath element names] {
77      regexp {l(\d+)-(\d+)} $item ==> i
78      if {$i>$ii} {
79        set ii $i
80      }
81      incr ii
82    }
83  } else {
84    set ii  0
85  }
86  set i 0
87  # TICKET 1450
88  foreach segments $gInfo(vectors) {
89    #puts "**** $i -- [llength $segments] -- $segments"
90    set j  0
91    set segIds  {}
92
93    foreach seg $segments {
94      set xdata [lindex $seg 0]
95      set ydata [lindex $seg 1]
96      $grpath line create l$ii-$j -xdata $xdata -ydata $ydata
97      lappend segIds l$ii-$j
98      if { $j } {
99        $grpath line configure l$i-$j -label ""
100      } else {
101        set _label_ [lindex $gInfo(names) $i]
102        foreach _it_ [$grpath element names] {
103          if {$_label_ eq [$grpath element cget $_it_ -label]} {
104            append _label_ "x"
105          }
106        }
107        $grpath line configure l$ii-0 -label $_label_
108      }
109      incr j
110    }
111    incr i
112    incr ii
113    lappend data(gr,$gr,elements) $segIds
114  }
115  ::bayesGraph::BindLegend $Instance
116
117  if {!$holdon} {
118    # configurar grafico
119    #  $grpath axis configure x  -command "::SetGraph::GetTickLabel $Instance"
120   
121    #Establecer el fichero GCF del que se lee
122    #Establecer el fichero GCF del que se lee
123    if {[string length $fileGCF]} {
124      ::bayesGraph::LoadGCF $Instance $fileGCF
125    } else  {
126      ::bayesGraph::LoadGCF $Instance
127    }
128  }
129  ReadIni $Instance $holdon
130   
131  Configure $Instance
132 
133  if {!$holdon} {
134    #set title chart
135    if {[string length $title]} {
136      ::bayesGraph::SetMainTitle $Instance $title
137    } 
138    if {[string equal [winfo class [winfo parent $widgets(this)]] Toplevel]} {
139      wm geometry [winfo parent $widgets(this)] $data(geometry)
140      wm state    [winfo parent $widgets(this)] $data(wm,state)
141    }
142  }
143  ::bayesGraph::ZoomExtend  $Instance
144  return $Instance
145}
146
147
148#/////////////////////////////////////////////////////////////////////////////
149proc ::SetGraph::Configure {this} {
150#
151#/////////////////////////////////////////////////////////////////////////////
152  ::bayesGraph::Configure $this
153}
154
155
156#/////////////////////////////////////////////////////////////////////////////
157proc ::SetGraph::ComputeStepX {this min max total} {
158#
159#///////////////////////////////////////////////////////////////////////////// 
160  set step 1
161  # validamos que max y total tengan valor y min no
162  if {(![string length $min] && [string length $max] && \
163        [string length $total])} {
164    set step [expr $max / $total]
165  } elseif {([string length $min] && [string length $max] && \
166             [string length $total])} {
167    # validamos que max, min y total tengan valor
168    set step [expr ($max-$min)/$total]
169  }
170  return $step
171}
172
173
174#/////////////////////////////////////////////////////////////////////////////
175proc ::SetGraph::GetTickLabel {this bltg tick} {
176#
177#///////////////////////////////////////////////////////////////////////////// 
178  upvar \#0 ${this}::data data
179  upvar \#0 ${this}::options options
180
181  if {![string equal $data(xTicks) ""]} {
182    if {[string is int $tick]} {
183      set str [lindex $data(xTicks) $tick]
184    } else  {
185      return ""
186    }
187    set tvalue $str
188  } else {
189    set tvalue $tick
190  }
191  set gr $data(gr,active)
192  ::bayesGraph::FormatNumberAxis $options(gr,$gr,xFormatNumber) \
193      $options(gr,$gr,xFormatPercent) $bltg $tvalue
194}
195
196#/////////////////////////////////////////////////////////////////////////////
197proc ::SetGraph::GetXTicks {this} {
198#
199#///////////////////////////////////////////////////////////////////////////// 
200  upvar \#0 ${this}::data data
201  set gr $data(gr,active)
202  set values ""
203  if {![string equal $data(xTicks) ""]} {
204    set values $data(xTicks)
205  } else {
206    set limAxis [::bayesGraph::GetLimitsValueAxis $this x]
207    if {[llength $limAxis]} {
208      set minX [expr int(floor([lindex $limAxis 0]))]
209      set maxX [expr int(floor([lindex $limAxis 1]))]
210      # If the difference between the maximum and the minimum is very great,
211      # we remained with a sample
212      set inc [expr ($maxX-$minX) > 1000 ? ($maxX - $minX) / 1000 : 1]
213      for {set i $minX} {$i <= $maxX} {incr i $inc} {
214        lappend values $i
215      }
216    }   
217  }
218  return $values
219}
220
221
222#/////////////////////////////////////////////////////////////////////////////
223proc ::SetGraph::GetXValues {this} {
224#
225#///////////////////////////////////////////////////////////////////////////// 
226  upvar \#0 ${this}::data data
227  # si es unique X Axis
228  set gr $data(gr,active)
229  set values ""
230  set limAxis [::bayesGraph::GetLimitsValueAxis $this x]
231  set minX [expr int(floor([lindex $limAxis 0]))]
232  set maxX [expr int(floor([lindex $limAxis 1]))]
233  # If the difference between the maximum and the minimum is very great,
234  # we remained with a sample
235  set inc [expr ($maxX-$minX)>1000 ? ($maxX - $minX) / 1000 : 1]
236  for {set i $minX} {$i <= $maxX} {incr i $inc} {
237    lappend values $i
238  }   
239  return $values
240}
241
242
243#/////////////////////////////////////////////////////////////////////////////
244proc ::SetGraph::getSet {this} {
245#
246#///////////////////////////////////////////////////////////////////////////// 
247  upvar \#0 ${this}::data data
248
249  set gr $data(gr,active)
250  set set $data(gr,$gr,set)
251  return $set
252}
253
254
255#/////////////////////////////////////////////////////////////////////////////
256proc ::SetGraph::getTableSet {this} {
257#
258#///////////////////////////////////////////////////////////////////////////// 
259  upvar \#0 ${this}::data data
260
261  set gr $data(gr,active)
262  set tableset $data(gr,$gr,tableset)
263  return $tableset
264}
265
266
267#/////////////////////////////////////////////////////////////////////////////
268proc ::SetGraph::EvalWindow {this} {
269#
270#///////////////////////////////////////////////////////////////////////////// 
271  set grpath [::bayesGraph::getActiveGraph $this]
272  set set [getSet $this]
273  if {[llength $set] > 1} {
274    set nameSet [lindex [::tol::info variable $set] 1]
275  } else {
276    set nameSet $set
277  }
278  return $nameSet
279}
280
281
282#/////////////////////////////////////////////////////////////////////////////
283proc ::SetGraph::ToTable {this} {
284#
285#///////////////////////////////////////////////////////////////////////////// 
286  set grpath [::bayesGraph::getActiveGraph $this]
287  set set [getSet $this]
288  set tableset [getTableSet $this]
289
290  if {[llength $set] > 1} {
291    set nameSet [lindex [::tol::info variable $set] 1]
292  } else {
293    set nameSet $set
294  }
295 
296  set tl .tbl_from_$nameSet
297  if [winfo exists $tl] {
298     raise $tl
299  } else  {
300        set tl [::project::CreateForm \
301                    -title    "[mc {Set table}]: $nameSet" \
302                    -iniconfig Tables \
303                    -type     Tables ]
304
305    $tl withdraw
306        set tlf [$tl getframe]
307    btable $tlf.t -parent $tl \
308                  -posteditcmd [list ::TolConsole::TableRecentUpdate $tlf.t] \
309                  -iniconfig btable
310    $tlf.t fillSet $tableset
311    pack $tlf.t -fill both -expand yes
312    update
313    $tl bind <Control-F4> [list $tl kill]
314        $tl restore
315  }
316}
317
318
319#/////////////////////////////////////////////////////////////////////////////
320proc ::SetGraph::ReadIni {this {holdon 0}} {
321#
322# PURPOSE: Reads set graph specific options from .ini file. First of all,
323#          reads options from BayesGraph. Ini file is the active graphic
324#          configuration file.
325#
326# PARAMETERS:
327#   this  -> Instance of BayesGraph
328#
329#/////////////////////////////////////////////////////////////////////////////
330  upvar \#0 ${this}::data data
331
332  if {!$holdon} {
333    set rini ::iniFile::ReadGCF
334    set data(geometry)   [$rini SetGraph geometry 800x600]
335    set data(wm,state)   [::iniFile::ReadWMState $rini SetGraph]
336  }
337  ::bayesGraph::ReadIni $this $holdon
338}
339
340
341#/////////////////////////////////////////////////////////////////////////////
342  proc ::SetGraph::WriteIni {this} {
343#
344# PURPOSE: Writes set graph specific options to .ini file. This procedure
345#          is called by parent BayesGraph. Ini file is the active graphic
346#          configuration file.
347#
348# PARAMETERS:
349#   this  -> Instance of BayesGraph
350#
351#/////////////////////////////////////////////////////////////////////////////
352  upvar \#0 ${this}::data data
353  upvar \#0 ${this}::widgets widgets
354
355  set wini ::iniFile::WriteGCF
356
357  if {[string equal [winfo class [winfo parent $widgets(this)]] Toplevel]} {
358    set data(geometry) [wm geometry [winfo parent $widgets(this)]]
359    set data(wm,state) [wm state    [winfo parent $widgets(this)]]
360  }
361  $wini SetGraph geometry $data(geometry)
362  $wini SetGraph wm,state $data(wm,state)
363}
364
365
366#/////////////////////////////////////////////////////////////////////////////
367  namespace eval ::SetGraphDialog {
368# PURPOSE: The purpose of this namespace is to manage the columns selecting
369#          process of a set.
370#
371# VARIABLES:
372#   tmpOpt -> temporary array used to store the widgets and variables of the
373#             assistant.
374#   data   -> array used to store information about the set and its columns
375#     tableset     -> command of the set
376#     names        -> list with names of the elements selected for drawing
377#     vectors      -> list with pairs
378#     nameVectors  -> list with vector names created when partition is
379#                     necessary and when a type 2 column is choosen for x-axis
380#     xTicks       -> list with ticks of the x values when a type 2 column is
381#                     choosen for x-axis
382#     selected     -> temporary list with the pair of x-y columns selected for
383#                     drawing
384#     uniqueXAxis  -> flag that indicates if the user has choosen an element
385#                     which X data comes from a type 2 column. (if so, it
386#                     stores the column's index in the set)
387#     infoCols     -> array with information of '$tableset info columns'
388#                     command.
389#     idxColsType1 -> list of type 1 column's indexes in the set
390#     idxColsType2 -> list of type 2 column's indexes in the set
391#     idxColsType3 -> list of type 3 column's indexes in the set
392#     idxColsType4 -> list of type 4 column's indexes in the set
393#
394#/////////////////////////////////////////////////////////////////////////////
395  variable tmpOpt
396  variable data
397}
398
399#/////////////////////////////////////////////////////////////////////////////
400  proc ::SetGraphDialog::InitData {tableset} {
401#
402# PURPOSE: Checks if the set is graphicable and if so, draws and assistant
403#          that allows to choose x and y columns for the elements to draw.
404#
405# PARAMETERS:
406#   tableset -> command of the set
407#
408#/////////////////////////////////////////////////////////////////////////////
409  variable data
410
411  set data(tableset)    $tableset
412  set data(names)       ""
413  set data(vectors)     ""
414  set data(nameVectors) ""
415
416  set data(xTicks)      ""
417  set data(selected)    ""
418  set data(uniqueXAxis) ""
419
420  set data(firstcolumn) {}
421
422  GetColTypes $tableset
423}
424     
425#/////////////////////////////////////////////////////////////////////////////
426proc ::SetGraphDialog::DrawSet {path tableset set type {pairs {}} {names {}} {fileGCF {}} {title {}}} {
427#
428# PURPOSE: Checks if the set is graphicable and if so, draws and assistant
429#          that allows to choose x and y columns for the elements to draw.
430#
431# PARAMETERS:
432#   path     -> path of the blt graph
433#   tableset -> command of the set
434#   set      -> reference to the TOL set
435#   type     -> 0 for custom association of data columns
436#            -> 1 for all data columns to first one
437#            -> 2 for all data columns to generic
438#            -> 3 for even data columns to odd ones
439#   pairs    -> when type is 0 pairs is the list of correspondence beetwen index
440#               columns to data columns (x-y pairs)
441#   names    -> names for the series/points,..
442#   fileGcf  -> file configuration graph
443#   title    -> list of title of chart
444#   holdon   -> tell if the new graph goes into a new context or an existing one
445#
446#/////////////////////////////////////////////////////////////////////////////
447  variable data
448
449  #puts "**** ::SetGraphDialog::DrawSet $tableset type=$type"
450
451  ::SetGraphDialog::InitData $tableset
452
453  switch [CheckGraphicable] {
454    0 {
455      tk_messageBox -type ok -icon warning -title [mc Warning]\
456          -message [mc "Set not graphicable"]
457      return 0
458    }
459    1 {
460      # fill listX and listY
461      # TICKET 1450
462      #::SetGraphDialog::SetDataVarList
463      switch $type {
464        0 {
465          # custom
466          set lstLines {}
467          set len [llength $pairs]
468          for {set i 0} {[expr $i < $len]} {incr i} {
469            set xy   [lindex $pairs $i]
470            set name [lindex $names $i]
471            if {![string length $name]} {
472              set name "Column [expr $i + 1]"
473            }
474            lappend lstLines [::SetGraphDialog::AddLine \
475              [expr [lindex $xy 0] - 1] \
476              [expr [lindex $xy 1] - 1] \
477              $name          \
478              $lstLines]
479          }
480        }
481        1 {
482          # all to one
483          ::SetGraphDialog::GrapthAllLine 1 0 $names
484        }
485        2 {
486          # all to generic
487          ::SetGraphDialog::GrapthAllLine 0 0 $names
488        }
489        3 {
490          # even to odd
491          ::SetGraphDialog::GrapthEvenUneven $names
492        }
493      }
494      # build info to graph
495      if [llength $data(selected)] {
496        ::SetGraphDialog::SetSelection
497        set info [list vectors $data(vectors) names $data(names) xTicks $data(xTicks)]
498        set instance [::SetGraph::Create $path $info $set $tableset $fileGCF $title]
499        bind $path <Destroy> +[list ::SetGraphDialog::OnDestroyGraph $data(nameVectors)]
500        return $instance
501      } else {
502        set msg [mc "There are no data to draw"]
503        ::TolConsole::HciWriter "<W>$msg</W>"
504      }
505    }
506  }
507}
508
509#/////////////////////////////////////////////////////////////////////////////
510  proc ::SetGraphDialog::Init {path tableset set} {
511#
512# PURPOSE: Checks if the set is graphicable and if so, draws and assistant
513#          that allows to choose x and y columns for the elements to draw.
514#
515# PARAMETERS:
516#   path     -> path of the blt graph
517#   tableset -> command of the set
518#   set      -> reference to the TOL set
519#
520#/////////////////////////////////////////////////////////////////////////////
521  variable data
522
523  ::SetGraphDialog::InitData $tableset
524
525  switch [CheckGraphicable] {
526    0 {
527      tk_messageBox -type ok -icon warning -title [mc Warning]\
528          -message [mc "Set not graphicable"]
529      return 0
530    }
531    1 {
532      DrawDialog
533      if [llength $data(vectors)] {
534        set info [list vectors $data(vectors) names $data(names) xTicks $data(xTicks)]
535        set Instance [::SetGraph::Create $path $info $set $tableset]
536        bind $path <Destroy> +[list ::SetGraphDialog::OnDestroyGraph $data(nameVectors)]
537        return $Instance
538      } else {
539        return 0
540      }
541    }
542  }
543}
544
545
546#/////////////////////////////////////////////////////////////////////////////
547proc ::SetGraphDialog::OnDestroyGraph {list} {
548#
549#///////////////////////////////////////////////////////////////////////////// 
550  if [llength $list] {
551    eval blt::vector destroy $list
552  }
553}
554
555#/////////////////////////////////////////////////////////////////////////////
556  proc ::SetGraphDialog::GetColTypes {tableset} {
557#
558# PURPOSE: Extracts information about the types of the columns of the tableset
559#          and stores this in the 'data' array of the namespace. There are
560#          four types of columns:
561#            1- Graficable in X and Y axis (Real without ? or Inf)
562#            2- Graficable only in X axis  (Text or Date)
563#            3- Graficable only in Y axis  (Real with ?)
564#            4- Not graficable             (Real with Inf)
565#
566# PARAMETERS:
567#   tableset  -> command of the tableset
568#
569#/////////////////////////////////////////////////////////////////////////////
570
571  variable data
572
573  set data(var,listX) \
574    [list [list -1 "<Generic 1-[$tableset info datarows]>"]]
575
576  set data(var,listY) {}
577
578  set idx 0
579  for {set i 1} {$i <= 4} {incr i} {
580    set data(idxColsType$i) ""
581    set data(nameColsType$i) ""
582  }
583  foreach it [$tableset info columns] {
584    #puts "**** it = $it"
585    foreach {key value} $it {
586      set data(infCols,$idx,$key) $value
587    }
588    switch -- $data(infCols,$idx,type) {
589      Date -
590      Text {
591        # first column
592        if {![info exists data(firstcolumn)] || ![string length $data(firstcolumn)]} {
593          set data(firstcolumn) $idx
594        }
595
596        lappend data(idxColsType2) $idx
597        lappend data(var,listX) [ list $idx $data(infCols,$idx,name) ]
598      }
599      Real {
600        # first column
601        if {![info exists data(firstcolumn)] || ![string length $data(firstcolumn)]} {
602          set data(firstcolumn) $idx
603        }
604        if {$data(infCols,$idx,infinity)} {
605          lappend data(idxColsType4) $idx
606#         lappend data(idxColsType1) $idx
607          lappend data(var,listY) [ list $idx $data(infCols,$idx,name) ]
608        } elseif {$data(infCols,$idx,unknown)} {
609          lappend data(idxColsType3) $idx
610          lappend data(var,listY) [ list $idx $data(infCols,$idx,name) ]
611        } else {
612          lappend data(idxColsType1) $idx
613          lappend data(var,listX) [ list $idx $data(infCols,$idx,name) ]
614          lappend data(var,listY) [ list $idx $data(infCols,$idx,name) ]
615        }
616      }
617    }
618    incr idx
619  }
620}
621
622#/////////////////////////////////////////////////////////////////////////////
623  proc ::SetGraphDialog::CheckGraphicable {} {
624#
625# PURPOSE: Check if the set is graphicable and returns a code
626#
627# RETURN:
628#    0 if the set isn't graphicable
629#    1 if there are some posibilities for choosing columns (assistant will be
630#   drawn)
631#/////////////////////////////////////////////////////////////////////////////
632  variable data
633
634  #Para poder graficar =>
635  # debe haber al menos una col. tipo 1 o 2 y al menos otra col. tipo 1 o 3.
636  set tot1 [llength $data(idxColsType1)]
637  set tot2 [llength $data(idxColsType2)]
638  set tot3 [llength $data(idxColsType3)]
639  if { ([expr $tot1 + $tot2] >= 1) && ([expr $tot1 + $tot3] >= 1) } {
640    return 1
641  } else  {
642    return 0
643  }
644}
645
646#/////////////////////////////////////////////////////////////////////////////
647  proc ::SetGraphDialog::DrawDialog {} {
648#
649# PURPOSE: Draw an assistant to select the columns to plot
650#
651#/////////////////////////////////////////////////////////////////////////////
652  variable data
653  variable tmpOpt
654
655  #puts "******* ::SetGraphDialog::DrawDialog"
656  set dialog [Dialog .t -title [mc "Columns Selector"] -separator yes\
657                -modal local -parent .]
658  set tmpOpt(dialog) $dialog
659
660  wm protocol $dialog WM_DELETE_WINDOW [list ::SetGraphDialog::Cancel $dialog]
661  set w [$dialog getframe]
662
663  set f1 [frame $w.f1]
664 
665  # fill listX and listY
666  # TICKET 1450
667  #::SetGraphDialog::SetDataVarList
668
669  set values ""
670  set lst    ""
671  foreach it $data(var,listX) {
672    lappend values [lindex $it 1]
673    lappend lst    [lindex $it 0]
674  }
675  label $f1.lXAxis -text [mc "X Values"]:
676  set tmpOpt(widget,cbXAxis) [ComboBox $f1.cbXAxis -width 16 -height 5\
677     -editable false -justify right\
678     -values $values\
679     -modifycmd  [list ::SetGraphDialog::OnModifyXValues $lst ]]
680
681  set values ""
682  set lst    ""
683  foreach it $data(var,listY) {
684    lappend values [lindex $it 1]
685    lappend lst    [lindex $it 0]
686  }
687
688  label $f1.lInfoSelect -text [mc "Select series"]:
689  label $f1.lYAxis      -text [mc "Y Values"]:
690  set tmpOpt(widget,cbYAxis) [ComboBox $f1.cbYAxis -width 16 -height 5\
691     -editable false -justify right\
692     -values $values\
693     -modifycmd  [list ::SetGraphDialog::OnModifyYValues $lst ]]
694  label $f1.lName -text [mc Name]:
695  set tmpOpt(widget,eName) [entry $f1.eName -width 18]
696
697  grid $f1.lInfoSelect   -           -sticky nws -pady 2
698  grid $f1.lXAxis        $f1.cbXAxis -sticky news -pady 2
699  grid $f1.lYAxis        $f1.cbYAxis -sticky news -pady 2
700  grid $f1.lName         $f1.eName   -sticky news -pady 2
701
702  grid rowconfigure    $f1 4 -weight 1
703  grid columnconfigure $f1 1 -weight 1
704
705  set f2 [frame $w.f2]
706  label $f2.lSeries -text [mc "Series to draw"]:
707
708  set tmpOpt(widget,lbSeries) [blistboxplus $f2.lb \
709    -selectmode multiple -nomenu true \
710    -cols { lines } \
711    -readonly false -parent $f2 -orientation vertical]
712  bind $tmpOpt(widget,lbSeries) <Button-1> +[list focus -force %W]
713
714  button $f2.bAdd -width 6 -text [mc Add]    -command ::SetGraphDialog::AddItem
715  button $f2.bDel -width 6 -text [mc Delete] -command ::SetGraphDialog::DelItem
716
717  grid $f2.lSeries  -     -sticky nw    -pady 0
718  grid $f2.lb       -     -sticky news  -pady 0
719  grid $f2.bAdd $f2.bDel -sticky new   -pady 0
720
721  grid rowconfigure    $f2 1 -weight 1
722  grid columnconfigure $f2 0 -weight 1
723  grid columnconfigure $f2 1 -weight 1
724
725  # options advanced
726  TitleFrame $w.f3 -text [mc "Automatic generation"] 
727  set f3 [$w.f3 getframe]
728
729  radiobutton $f3.rbAllFirst -text [mc SetGraphAllFirst] \
730     -value f -highlightthickness 0 -pady 0 \
731     -variable ::SetGraphDialog::data(var,genAut)
732  DynamicHelp::add $f3.rbAllFirst -text [mc SetGraphAllFirstHint]
733  radiobutton $f3.rbAllGeneric -text [mc SetGraphAllGeneric] \
734     -value g -highlightthickness 0 -pady 0\
735     -variable ::SetGraphDialog::data(var,genAut)
736  DynamicHelp::add $f3.rbAllGeneric -text [mc SetGraphAllGenericHint]
737  radiobutton $f3.rbEvenUneven -text [mc SetGraphEvenUneven] \
738     -value e -highlightthickness 0 -pady 0 \
739     -variable ::SetGraphDialog::data(var,genAut)
740  DynamicHelp::add $f3.rbEvenUneven -text [mc SetGraphEvenUnevenHint]
741  Button $f3.bAddGenAut -text [mc Add] \
742    -width 6 -command [list ::SetGraphDialog::AddGenAut]
743
744  grid $f3.rbAllFirst    -              -sticky nws  -pady 1
745  grid $f3.rbAllGeneric  -              -sticky nws  -pady 1
746  grid $f3.rbEvenUneven  $f3.bAddGenAut -sticky nws  -pady 1
747
748  grid rowconfigure    $f3 0 -weight 1
749  grid rowconfigure    $f3 1 -weight 1
750  grid rowconfigure    $f3 2 -weight 1
751  grid columnconfigure $f3 0 -weight 1
752
753  set w_bbox \
754    [ButtonBox $w.bb -orient horizontal -spacing 10 -padx 0 -pady 0 \
755    -homogeneous false]
756  $w_bbox add -text [mc "Accept"] -relief link \
757    -helptext [mc "Accept"] \
758    -image [::Bitmap::get accept] -compound left -padx 5 -pady 1 \
759    -command [list ::SetGraphDialog::Finish $dialog]
760  $w_bbox add -text [mc "Cancel"] -relief link \
761    -helptext [mc "Cancel"]\
762    -image [::Bitmap::get cancelx] -compound left -padx 5 -pady 1 \
763    -command [list ::SetGraphDialog::Cancel $dialog]
764 
765  grid $f1   $f2 -sticky news
766  grid $w.f3 -   -sticky news
767  grid $w_bbox -   -sticky news
768
769  grid rowconfigure    $w 0 -weight 1
770  grid columnconfigure $w 0 -weight 1
771  grid columnconfigure $w 1 -weight 3
772
773  bind $dialog <F1> "ShowHelp Tb4GraSetSel"
774  $dialog draw
775}
776
777#/////////////////////////////////////////////////////////////////////////////
778  proc ::SetGraphDialog::SetDataVarList {} {
779#
780# PURPOSE: Fill varible data(var,listX) and data(var,listY)
781#
782#/////////////////////////////////////////////////////////////////////////////
783  variable data
784
785  # fill data(var,listX)
786  set data(var,listX) {}
787
788  set data(var,listX) \
789    [list [list -1 "<Generic 1-[$data(tableset) info datarows]>"]]
790
791  foreach it [concat $data(idxColsType2) $data(idxColsType1)] {
792    lappend data(var,listX) [list $it $data(infCols,$it,name)]
793  }
794
795  if {![string equal [$data(tableset) info header] "generic"] } {
796    set data(var,listX) [lsort -index 1 $data(var,listX)]
797  }
798  #set data(var,listX) [lsort $data(var,listX)] 
799
800  # fill data(var,listY)
801  set data(var,listY) {}
802  foreach it [concat $data(idxColsType1) $data(idxColsType3)] {
803    lappend data(var,listY) [list $it $data(infCols,$it,name)]
804  }
805  if {![string equal [$data(tableset) info header] "generic"] } {
806    set data(var,listY) [lsort -index 1 $data(var,listY)]
807  }
808  #set data(var,listY) [lsort $data(var,listY)]
809}
810
811
812#/////////////////////////////////////////////////////////////////////////////
813  proc ::SetGraphDialog::AddGenAut {} {
814#
815# PURPOSE: Control de la opción seleccionada para la generacion automatica de
816#          series
817#
818#/////////////////////////////////////////////////////////////////////////////
819  variable data
820  switch -exact $data(var,genAut) {
821    f {
822      ::SetGraphDialog::GrapthAllLine 1 0
823    }
824    g {
825      ::SetGraphDialog::GrapthAllLine 0 0
826    }
827    e {
828      ::SetGraphDialog::GrapthEvenUneven
829    }
830  }
831}
832
833
834#/////////////////////////////////////////////////////////////////////////////
835  proc ::SetGraphDialog::GrapthAllLine {indexX rangeY {names {}}} {
836#
837# PURPOSE: Seleccionamos todas las series contra una de ellas
838#
839# PARAMETERS: indexX -> Indice en X con el que se cruzan las demas columnas
840#             rangeY -> Rango inicial de columnas a usar en Y
841#
842#/////////////////////////////////////////////////////////////////////////////
843  variable tmpOpt
844  variable data
845  # first line ?
846  if {[expr $indexX == 1]} {
847    set firLinX $data(firstcolumn)
848  } else {
849    set firLinX [lindex [lindex $data(var,listX) $indexX] 0]
850  }
851  # control: uniqueXAxis
852  set ok [::SetGraphDialog::CheckAddSerie $firLinX]
853  if {!$ok} {
854    if {[info exists tmpOpt(dialog)]} {
855      set parent $tmpOpt(dialog)
856    } else {
857      set parent .
858    }
859    set parent 
860    set msg "[mc {Item not selectable}].\n[mc UniqueXAxis]"
861    tk_messageBox -type ok -icon warning -message $msg\
862                  -parent $parent        -title [mc Warning]
863  } else {
864    # find line axis X ?
865    if {([lindex $firLinX 0]==-1) ||
866        ([lsearch -exact $data(idxColsType1) $firLinX]!=-1) ||
867        ([lsearch -exact $data(idxColsType2) $firLinX]!=-1)} {
868      # remove first line
869      set row 0
870      set lst [lrange $data(var,listY) $rangeY end]
871      foreach it $lst {
872        # line is graph Y ?
873        if {([lsearch -exact $data(idxColsType1) [lindex $it 0]]!=-1) ||
874            ([lsearch -exact $data(idxColsType3) [lindex $it 0]]!=-1)} {
875          if {![string equal $firLinX [lindex $it 0]]} {             
876            set name [lindex $names $row]
877            if {![string length $name]} {
878              set name [lindex $it 1]
879            }
880            lappend data(selected) [list $firLinX [lindex $it 0] $name]
881            if {([info  exists  tmpOpt(widget,lbSeries)]) && \
882                ([winfo exists $tmpOpt(widget,lbSeries)])} {
883              $tmpOpt(widget,lbSeries) insert end \
884                [list "$name ( X: $firLinX Y: [lindex $it 0] )"]
885            }
886            incr row           
887          }
888        } else {
889        # no se puede graficar
890Tolcon_Trace "Y. No se puede graficar: $it" 
891        }
892      }
893    } else {
894    # No se puede graficar
895Tolcon_Trace "X. No se puede graficar [lindex $data(var,listX) $indexX]: $firLinX"
896    }
897  }
898}
899
900
901#/////////////////////////////////////////////////////////////////////////////
902  proc ::SetGraphDialog::GrapthEvenUneven {{names {}}} {
903#
904# PURPOSE: Seleccionamos las serie impar contr la impar y las agregamos
905#          a la lista series a dibujar. Por ejemplo 1-2, 3-4, 5-6
906#
907#/////////////////////////////////////////////////////////////////////////////
908  variable tmpOpt
909  variable data
910  # travel all columuns
911  #puts "DEBUG: ::SetGraphDialog::GrapthEvenUneven"
912  set row 0
913
914  # TICKET 1450: que cosa mas rara se hace aqui!!!!!!!
915  for {set i 0} {$i<[expr [llength $data(var,listY)] - 1]} {incr i 2} {
916    set colX [lindex [lindex $data(var,listY) $i] 0]
917    set colY [lindex $data(var,listY) [expr $i + 1]]
918    # control: uniqueXAxis
919    set ok [::SetGraphDialog::CheckAddSerie $colX]
920    if {$ok} {
921      # find line axis X ?
922      if {([lsearch -exact $data(idxColsType1) $colX]!=-1) ||
923          ([lsearch -exact $data(idxColsType2) $colX]!=-1)} {
924        # line is graph Y ?
925        if {([lsearch -exact $data(idxColsType1) [lindex $colY 0]]!=-1) ||
926            ([lsearch -exact $data(idxColsType3) [lindex $colY 0]]!=-1)} {
927          set name [lindex $names $row]
928          if {![string length $name]} {
929            set name [lindex $colY 1]
930          }
931          lappend data(selected) [list $colX [lindex $colY 0] $name]
932          if {(([info  exists  tmpOpt(widget,lbSeries)]) && \
933               ([winfo exists $tmpOpt(widget,lbSeries)]))} {
934            $tmpOpt(widget,lbSeries) insert end \
935              [list "$name ( X: $colX Y: [lindex $colY 0] )"]
936          }
937        } else {
938          # no se puede graficar
939Tolcon_Trace "Y. No se puede graficar: $colY" 
940        }
941      } else {
942      # No se puede graficar
943Tolcon_Trace "X. No se puede graficar: $colX"
944      }
945    }
946    incr row
947  }
948}
949
950
951#/////////////////////////////////////////////////////////////////////////////
952  proc ::SetGraphDialog::CheckAddSerie {indexX} {
953#
954# PURPOSE: Comprobamos si una serie se puede anhadir a la lista de seleccion
955#
956# PARAMETERS: indexX -> index column X
957#
958# RETURN: true  -> ok
959#         false -> not added
960#
961#/////////////////////////////////////////////////////////////////////////////
962  variable data
963  set ok 1
964  # si el elemento que intento insertar es de tipo 2
965  if {[string length $data(uniqueXAxis)]} {
966    if {$data(uniqueXAxis)!=$indexX} {
967      set ok 0
968    }
969  } else {
970    if {[string length $data(selected)]} {
971      if {[lsearch -exact $data(idxColsType1) $indexX] == -1} {
972        # trere are items selection with type 1
973        set ok 0
974      }
975    } else {
976      if {($indexX==-1) ||
977          ([lsearch -exact $data(idxColsType2) $indexX] != -1)} {
978        set data(uniqueXAxis) $indexX
979      } else {
980        # Type 1
981      }
982    }
983  }
984  return $ok
985}
986
987
988#/////////////////////////////////////////////////////////////////////////////
989  proc ::SetGraphDialog::OnModifyXValues {list} {
990#
991# PURPOSE: Update variable tmpOpt(var,cbXAxis) with the index of the column
992#          when combo that shows names of possible X columns is changed
993#
994# PARAMETERS:
995#   list -> list of tranlated values (indexes) of the columns names
996#
997#/////////////////////////////////////////////////////////////////////////////
998  variable tmpOpt
999
1000  ::Objects::ComboUnTranslate $tmpOpt(widget,cbXAxis) $list\
1001      ::SetGraphDialog::tmpOpt(var,cbXAxis)
1002}
1003
1004#/////////////////////////////////////////////////////////////////////////////
1005  proc ::SetGraphDialog::OnModifyYValues {list} {
1006#
1007# PURPOSE: Update variable tmpOpt(var,cbYAxis) with the index of the column
1008#          when combo that shows names of possible Y columns is changed.
1009#          It also changes the default name of the element
1010#
1011# PARAMETERS:
1012#   list -> list of tranlated values (indexes) of the columns names
1013#
1014#/////////////////////////////////////////////////////////////////////////////
1015  variable tmpOpt
1016
1017  ::Objects::ComboUnTranslate $tmpOpt(widget,cbYAxis) $list\
1018      ::SetGraphDialog::tmpOpt(var,cbYAxis)
1019  CheckName
1020}
1021
1022
1023#/////////////////////////////////////////////////////////////////////////////
1024  proc ::SetGraphDialog::CheckName {} {
1025#
1026# PURPOSE: Sets the element's default name to the y column's name
1027#
1028#/////////////////////////////////////////////////////////////////////////////
1029
1030  variable tmpOpt
1031  $tmpOpt(widget,eName) delete 0 end
1032  $tmpOpt(widget,eName) insert 0 [$tmpOpt(widget,cbYAxis) cget -text]
1033}
1034
1035
1036#/////////////////////////////////////////////////////////////////////////////
1037  proc ::SetGraphDialog::AddItem {} {
1038#
1039# PURPOSE:  Adds a element to the selected series listbox checking if it can
1040#          be added.
1041#
1042#/////////////////////////////////////////////////////////////////////////////
1043  variable tmpOpt
1044  variable data
1045  if { [$tmpOpt(widget,cbXAxis) getvalue] == -1} {
1046    tk_messageBox -type ok -icon warning -message [mc "You must fill X Values"]\
1047                  -parent $tmpOpt(dialog) -title [mc Warning]
1048    return
1049  }
1050  if { [$tmpOpt(widget,cbYAxis) getvalue] == -1} {
1051    tk_messageBox -type ok -icon warning -message [mc "You must fill Y Values"]\
1052                  -parent $tmpOpt(dialog) -title [mc Warning]
1053    return
1054  }
1055  if {[string equal [$tmpOpt(widget,eName) get] ""]} {
1056    tk_messageBox -type ok -icon warning -message [mc "You must specify a name"]\
1057                  -parent $tmpOpt(dialog) -title [mc Warning]
1058    return
1059  }
1060 
1061  #  uniqueXAxis es un flag que indica que se ha elegido un elemento cuyos datos
1062  # en X provienen de una columna de tipo 2 (guardamos su indice)
1063  #  En los comentarios de este bloque diremos que un elemento es de tipo 2 si sus
1064  # datos para el eje X provienen de una columna tipo 2 (solo graficable en X)
1065
1066  # lst names
1067  set lstNames {}
1068  set inx [$tmpOpt(widget,lbSeries) get 0 end]
1069  foreach it $inx {
1070    lappend lstNames [$tmpOpt(widget,lbSeries) get $it]
1071  }
1072  set name [::SetGraphDialog::AddLine \
1073    $tmpOpt(var,cbXAxis) \
1074    $tmpOpt(var,cbYAxis) \
1075    [$tmpOpt(widget,eName) get]        \
1076    $lstNames]
1077  if {[string length $name]} {
1078    $tmpOpt(widget,lbSeries) insert end [list $name]
1079  }
1080}
1081
1082#/////////////////////////////////////////////////////////////////////////////
1083  proc ::SetGraphDialog::AddLine {colX colY name lstLines} {
1084#
1085# PURPOSE:  Adds a element to the selected series listbox checking if it can
1086#          be added.
1087#
1088#/////////////////////////////////////////////////////////////////////////////
1089  variable tmpOpt
1090  variable data
1091  # parent ?
1092  if {[info exists tmpOpt(dialog)]} {
1093    set parent $tmpOpt(dialog)
1094  } else {
1095    set parent .
1096  }
1097  # uniqueXAxis es un flag que indica que se ha elegido un elemento cuyos
1098  #  datos en X provienen de una columna de tipo 2 (guardamos su indice)
1099  # En los comentarios de este bloque diremos que un elemento es de tipo 2 si
1100  #  sus datos para el eje X provienen de una columna tipo 2
1101  #  (solo graficable en X)
1102
1103  # si no hay ningun elemento tipo 2
1104  if {[string equal $data(uniqueXAxis) ""]} {
1105    # si el elemento que intento insertar es de tipo 2
1106    if {(($colX == -1) ||
1107         ([lsearch -exact $data(idxColsType2) $colX] != -1))} {
1108      # si no hay ningún elemento insertado
1109      if {[llength $lstLines]} {
1110        set msg "[mc {Item not selectionable}].\n[mc UniqueXAxis]"
1111        tk_messageBox -type ok -icon warning -message $msg\
1112             -parent $parent -title [mc Warning]
1113        return {}
1114      } else {
1115        set data(uniqueXAxis) $colX
1116      }
1117    }
1118  # si ya hay algún elemento tipo 2
1119  } else {
1120    # si el que intento insertar no es el mismo que el que ya hay
1121    if { ![string equal $data(uniqueXAxis) $colX] } {
1122      set msg "[mc {Item not selectionable}].\n[mc UniqueXAxis]"
1123      tk_messageBox -type ok -icon warning -message $msg\
1124                    -parent $parent -title [mc Warning]
1125      return {}
1126    }
1127  }
1128
1129  if {[lsearch $name $lstLines] != -1} {
1130    tk_messageBox -type ok -icon warning\
1131        -parent $parent -title [mc Warning]\
1132        -message [mc "You have added another serie with this name"]
1133#    return {}
1134  }
1135  lappend data(selected) [list $colX $colY $name]
1136  return "$name ( X: $colX Y: $colY )"
1137}
1138
1139#/////////////////////////////////////////////////////////////////////////////
1140  proc ::SetGraphDialog::DelItem {} {
1141#
1142# PURPOSE: Deletes an elements selected from the selected series listbox
1143#
1144#/////////////////////////////////////////////////////////////////////////////
1145  variable tmpOpt
1146  variable data
1147  set idx [$tmpOpt(widget,lbSeries) curselection]
1148  if {![llength $idx]} {
1149    tk_messageBox -type ok -icon warning -message [mc "You must select a serie"]\
1150                  -parent $tmpOpt(dialog) -title [mc Warning]   
1151  } else {
1152    set ids [lsearch -all -regexp [$tmpOpt(widget,lbSeries) get] \
1153      [join [ListToStr $idx " " ^ $] |]]
1154    for {set i [expr [llength $ids] - 1]} {[expr $i >= 0]} { incr i -1} {
1155      set id [lindex $ids $i]
1156      set data(selected) [lreplace $data(selected) $id $id]
1157    }
1158    foreach id $idx {
1159      $tmpOpt(widget,lbSeries) delete $id
1160    }
1161    # si eliminamos todos los elementos
1162    if {[$tmpOpt(widget,lbSeries) size]==0} {
1163      set data(uniqueXAxis) ""
1164    }
1165  }
1166}
1167
1168#/////////////////////////////////////////////////////////////////////////////
1169  proc ::SetGraphDialog::Finish {dialog} {
1170#
1171# PURPOSE: Creates the blt vectors acording to the columns selection done by
1172#          the user. It also get the maximun and minimun x value of the
1173#          selected series
1174#
1175# PARAMETERS:
1176#   dialog   -> path of the dialog
1177#
1178#/////////////////////////////////////////////////////////////////////////////
1179  ::SetGraphDialog::SetSelection
1180  Cancel $dialog
1181}
1182
1183# TICKET #1450: aqui es donde se ponen los datos que luego se pintan.
1184#/////////////////////////////////////////////////////////////////////////////
1185  proc ::SetGraphDialog::SetSelection {} {
1186#
1187# PURPOSE: Creates the blt vectors acording to the columns selection done by
1188#          the user. It also get the maximun and minimun x value of the
1189#          selected series
1190#
1191# PARAMETERS:
1192#
1193#/////////////////////////////////////////////////////////////////////////////
1194  variable tmpOpt
1195  variable data
1196 
1197  #puts "DEBUG: ::SetGraphDialog::SetSelection"
1198  set colX [lindex [lindex $data(selected) 0] 0]
1199  # Si la columna que fija el X del primer elemento es genérica o de tipo 2
1200  # (será la misma para todas)
1201  if {($colX == -1) || ([lsearch -exact $data(idxColsType2) $colX] != -1)} {
1202    for {set i 0} {$i < [$data(tableset) info datarows]} {incr i} {
1203      lappend lst $i
1204    }
1205    if {($colX != -1)} {
1206      set data(xTicks) [$data(tableset) data column $colX]
1207    }
1208    set uniqueXAxis 1
1209  } else  {
1210    set uniqueXAxis 0
1211  }
1212
1213  # cross the selection
1214  foreach it $data(selected) {
1215    set colX [lindex $it 0]
1216    set colY [lindex $it 1]
1217    set name [lindex $it 2]
1218    if {$uniqueXAxis} {
1219      set vecX $lst
1220    } else {
1221      set vecX  [$data(tableset) data column $colX]
1222    }
1223    set vecsY [$data(tableset) data column $colY]
1224    if {[llength $vecsY] > 1} {
1225      set i 0
1226      set subVectors ""
1227      set subcurves {}
1228      set lstX {}
1229      set segX {}
1230      set lstY {}
1231      set segY {}
1232      foreach item $vecsY {
1233        #si no es un omitido (vacio o ?)
1234        if {[string equal $item ""] || [string equal $item "?"]} {
1235          # TICKET 1450
1236          # close this segment
1237          if { [ llength $segX ] } {
1238            lappend subcurves [ list $segX $segY ]
1239            set segX {}
1240            set segY {}
1241          }
1242        } else  {
1243          # TICKET 1450
1244          #set datX [lindex $vecX $i]
1245          #lappend lstX $datX
1246          #lappend lstY $item
1247          lappend segX [lindex $vecX $i]
1248          lappend segY $item
1249        }
1250        incr i
1251      }
1252      # TICKET 1450
1253      #lappend data(vectors) [list $lstX $lstY]
1254      if { [ llength $segX ] } {
1255        lappend subcurves [ list $segX $segY ]
1256      }
1257      lappend data(vectors) $subcurves
1258    } else {
1259      #puts "****** lappend data(vectors) [list [list $vecX $vecsY]]"
1260      lappend data(vectors) [list [list $vecX $vecsY]]
1261    }
1262    lappend data(names) $name
1263  }
1264}
1265
1266
1267#/////////////////////////////////////////////////////////////////////////////
1268  proc ::SetGraphDialog::Cancel {dialog} {
1269#
1270# PURPOSE: Destroy the dialog
1271#
1272# PARAMETERS:
1273#   dialog   -> path of the dialog
1274#
1275#/////////////////////////////////////////////////////////////////////////////
1276  destroy $dialog
1277}
Note: See TracBrowser for help on using the repository browser.