| 1 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 2 | # FILE : tolmethods.tcl |
|---|
| 3 | # PURPOSE : Metodos de Tol desde TCL |
|---|
| 4 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | # includes. 1 -> Include. 0 -> No |
|---|
| 8 | if { 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 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 42 | proc 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::ZoomExtend $Instance |
|---|
| 140 | ::bayesGraph::TakePhoto $Instance $filetosave |
|---|
| 141 | after idle "destroy $tl" |
|---|
| 142 | } |
|---|
| 143 | } else { |
|---|
| 144 | set msg [mc {No selection information related}] |
|---|
| 145 | ::TolConsole::HciWriter "<W>${msg}</W>" |
|---|
| 146 | } |
|---|
| 147 | return $tl |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 152 | proc Tol_SerieTabulate { source {title ""} {geometry {}} } { |
|---|
| 153 | # |
|---|
| 154 | # PURPOSE: Tabulates a serie in a TolBase table window |
|---|
| 155 | # |
|---|
| 156 | # PARAMETERS: |
|---|
| 157 | # source -> the tol serie variable or variables (if a list is given) |
|---|
| 158 | # geometry -> geometry specification |
|---|
| 159 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 160 | |
|---|
| 161 | # chek type TOL of source |
|---|
| 162 | set gramVar [GetGlobalUniqueName __tabser__] |
|---|
| 163 | ::tol::console eval "Text $gramVar = Grammar($source);" |
|---|
| 164 | set namGra [string trim [TclGetVar Text $gramVar] {"}];#{"} |
|---|
| 165 | # destroy |
|---|
| 166 | ::tol::console stack release $gramVar |
|---|
| 167 | # list of series tabulate |
|---|
| 168 | set lstSerie {} |
|---|
| 169 | switch $namGra { |
|---|
| 170 | Serie { set lstSerie [ list [ list Serie $source ] ] } |
|---|
| 171 | Set { |
|---|
| 172 | set nsource [lindex [TclGetVar Set $source] 0] |
|---|
| 173 | for {set i 1} {$i <= $nsource} {incr i} { |
|---|
| 174 | lappend lstSerie [list Set $source $i ] |
|---|
| 175 | } |
|---|
| 176 | } |
|---|
| 177 | } |
|---|
| 178 | # lstSerie > 0 ? |
|---|
| 179 | set tl {} |
|---|
| 180 | if {[llength $lstSerie]} { |
|---|
| 181 | # create sergrp |
|---|
| 182 | set sergrp group[clock clicks] |
|---|
| 183 | eval "::tol::seriegrp create $sergrp $lstSerie" |
|---|
| 184 | #title |
|---|
| 185 | if { ![llength $title] } { |
|---|
| 186 | set title [mc "Time series table"] |
|---|
| 187 | } |
|---|
| 188 | # create |
|---|
| 189 | set tl [::project::CreateForm \ |
|---|
| 190 | -title $title \ |
|---|
| 191 | -iniconfig SeriesTable \ |
|---|
| 192 | -type Tables \ |
|---|
| 193 | -geometry $geometry |
|---|
| 194 | ] |
|---|
| 195 | $tl setgeometry $geometry |
|---|
| 196 | set tlf [$tl getframe] |
|---|
| 197 | # configuration |
|---|
| 198 | btable $tlf.t -parent $tl \ |
|---|
| 199 | -posteditcmd [list ::TolConsole::TableRecentUpdate $tlf.t] \ |
|---|
| 200 | -iniconfig btable |
|---|
| 201 | $tlf.t fillSerie $sergrp |
|---|
| 202 | bind $tlf.t <Destroy> +[list ::tol::seriegrp destroy $sergrp] |
|---|
| 203 | $tl bind <Control-F4> [list $tl kill] |
|---|
| 204 | pack $tlf.t -fill both -expand yes |
|---|
| 205 | update |
|---|
| 206 | } |
|---|
| 207 | return $tl |
|---|
| 208 | } |
|---|
| 209 | |
|---|
| 210 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 211 | proc Tol_SerieAutocor { source {title ""} {geometry {}} } { |
|---|
| 212 | # |
|---|
| 213 | # PURPOSE: Tabulates a serie in a TolBase table window |
|---|
| 214 | # |
|---|
| 215 | # PARAMETERS: |
|---|
| 216 | # source -> the tol serie variable or variables (if a list is given) |
|---|
| 217 | # geometry -> geometry specification |
|---|
| 218 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 219 | |
|---|
| 220 | # name |
|---|
| 221 | set objRef [ list "Serie" $source ] |
|---|
| 222 | set nameSerie [lindex [::tol::info variable $objRef] 1] |
|---|
| 223 | |
|---|
| 224 | #title |
|---|
| 225 | if { ![llength $title] } { |
|---|
| 226 | set title "[mc {Autocorrelation graph}]: $nameSerie" |
|---|
| 227 | } |
|---|
| 228 | # create |
|---|
| 229 | set tl [::project::CreateForm \ |
|---|
| 230 | -title $title \ |
|---|
| 231 | -iniconfig AutocorGraph \ |
|---|
| 232 | -type Graphs \ |
|---|
| 233 | -geometry $geometry -helpkey "Tb4GraAco" |
|---|
| 234 | ] |
|---|
| 235 | $tl setgeometry $geometry |
|---|
| 236 | set tlf [$tl getframe] |
|---|
| 237 | # configuration |
|---|
| 238 | ::AutocorGraph::Create $tlf.g $objRef |
|---|
| 239 | $tl bind <Control-F4> "$tl kill; break" |
|---|
| 240 | pack $tlf.g -fill both -expand yes |
|---|
| 241 | update |
|---|
| 242 | return $tl |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 246 | # Methods to Set |
|---|
| 247 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 248 | |
|---|
| 249 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 250 | proc Tol_SetChartMethod { title source gcfFile geometry filetosave lstNames |
|---|
| 251 | type lstPairs {holdon ""}} { |
|---|
| 252 | # |
|---|
| 253 | # PURPOSE: Hook of Chart method |
|---|
| 254 | # |
|---|
| 255 | # PARAMETERS: |
|---|
| 256 | # title -> title for the graph |
|---|
| 257 | # source -> reference to the set |
|---|
| 258 | # gcfFile -> a gcf to aply to the graph |
|---|
| 259 | # geometry -> geometry for the window of the graph |
|---|
| 260 | # file -> if a file name is given the graph is written to disk instead of displayed |
|---|
| 261 | # lstNames -> names for the series/points,.. |
|---|
| 262 | # type -> 0 for custom association of data columns |
|---|
| 263 | # -> 1 for all data columns to first one |
|---|
| 264 | # -> 2 for all data columns to generic |
|---|
| 265 | # -> 3 for even data columns to odd ones |
|---|
| 266 | # lstPairs -> when type is 0 pairs is the list of correspondence beetwen index |
|---|
| 267 | # columns to data columns (x-y pairs) |
|---|
| 268 | # holdon -> tell if the new graph goes into a new context or an existing one |
|---|
| 269 | # |
|---|
| 270 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 271 | # GCF |
|---|
| 272 | if {![string length $gcfFile]} { |
|---|
| 273 | set gcfFile [TclGetVar Text GCFFile] |
|---|
| 274 | } |
|---|
| 275 | if {![file exists $gcfFile]} { |
|---|
| 276 | set gcfFile {} |
|---|
| 277 | } |
|---|
| 278 | # Title |
|---|
| 279 | set wTitle $title |
|---|
| 280 | if {![string length $title]} { |
|---|
| 281 | set wTitle [mc "Set graph"] |
|---|
| 282 | } |
|---|
| 283 | # MDI |
|---|
| 284 | if {$holdon ne "" && (![winfo exists $holdon] || [winfo class $holdon] ne "Mdidoc")} { |
|---|
| 285 | 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>" |
|---|
| 286 | set holdon "" |
|---|
| 287 | } |
|---|
| 288 | if {[winfo exists $holdon]} { |
|---|
| 289 | set tl $holdon |
|---|
| 290 | } else { |
|---|
| 291 | puts "no existe '$holdon' por eso ... ::project::CreateForm" |
|---|
| 292 | |
|---|
| 293 | set tl [::project::CreateForm \ |
|---|
| 294 | -title $wTitle -type Graphs -iniconfig SetGraph -geometry $geometry] |
|---|
| 295 | $tl setgeometry $geometry |
|---|
| 296 | } |
|---|
| 297 | set top [$tl getframe] |
|---|
| 298 | # if source is a list is interpreted as a set name and indexes accesing a element |
|---|
| 299 | if {0} { |
|---|
| 300 | if { [llength $source] > 1 } { |
|---|
| 301 | set setname [GetUniqueName Set] |
|---|
| 302 | set sourcename [lindex $source 0] |
|---|
| 303 | set strtoeval "Set ${setname} = ${sourcename}" |
|---|
| 304 | for {set i 1} {$i < [llength $source]} {incr i} { |
|---|
| 305 | set elem [lindex $source $i] |
|---|
| 306 | set strtoeval "${strtoeval}\[$elem\]" |
|---|
| 307 | } |
|---|
| 308 | ::tol::console eval $strtoeval |
|---|
| 309 | set source $setname |
|---|
| 310 | } |
|---|
| 311 | } |
|---|
| 312 | set cmd tableset[clock clicks] |
|---|
| 313 | ::tol::tableset create $cmd [linsert $source 0 Set] |
|---|
| 314 | set Instance [::SetGraphDialog::DrawSet $top.g $cmd $source $type $lstPairs \ |
|---|
| 315 | $lstNames $gcfFile [list $title]] |
|---|
| 316 | if {$holdon ne ""} { |
|---|
| 317 | ::tol::tableset destroy $cmd |
|---|
| 318 | if { [llength $source] > 1} { |
|---|
| 319 | ::tol::stack release $source |
|---|
| 320 | } |
|---|
| 321 | } else { |
|---|
| 322 | bind $top.g <Destroy> +[list ::tol::tableset destroy $cmd] |
|---|
| 323 | if { [llength $source] > 1} { |
|---|
| 324 | bind $top.g <Destroy> +[list ::tol::stack release $source] |
|---|
| 325 | } |
|---|
| 326 | pack $top.g -fill both -expand yes |
|---|
| 327 | update |
|---|
| 328 | ::bayesGraph::GrapOptApplyAxisTicks $Instance ${Instance}::options gr,0 |
|---|
| 329 | if { [string length $filetosave] } { |
|---|
| 330 | ::bayesGraph::TakePhoto $Instance $filetosave |
|---|
| 331 | after idle "destroy $tl" |
|---|
| 332 | } |
|---|
| 333 | } |
|---|
| 334 | return $tl |
|---|
| 335 | } |
|---|
| 336 | |
|---|
| 337 | |
|---|
| 338 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 339 | proc Tol_SetTabulate { set {title ""} {geometry {}} } { |
|---|
| 340 | # |
|---|
| 341 | # PURPOSE: Tabulates a set in a TolBase table window |
|---|
| 342 | # |
|---|
| 343 | # PARAMETERS: |
|---|
| 344 | # source -> the tol set variable |
|---|
| 345 | # geometry -> geometry specification |
|---|
| 346 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 347 | |
|---|
| 348 | if {[llength $set] > 1} { |
|---|
| 349 | set nameSet [lindex [::tol::info variable $set] 1] |
|---|
| 350 | set setref $set |
|---|
| 351 | } else { |
|---|
| 352 | set nameSet $set |
|---|
| 353 | set setref [ list Set $set ] |
|---|
| 354 | } |
|---|
| 355 | |
|---|
| 356 | if { ![llength $title] } { set title "[mc "Set table"]: $nameSet" } |
|---|
| 357 | |
|---|
| 358 | set setgrp group[clock clicks] |
|---|
| 359 | |
|---|
| 360 | set tl {} |
|---|
| 361 | if { ![ catch { ::tol::tableset create $setgrp $setref } ] } { |
|---|
| 362 | # create |
|---|
| 363 | set tl [::project::CreateForm \ |
|---|
| 364 | -title $title \ |
|---|
| 365 | -iniconfig SetTable \ |
|---|
| 366 | -type Tables \ |
|---|
| 367 | -geometry $geometry |
|---|
| 368 | ] |
|---|
| 369 | $tl setgeometry $geometry |
|---|
| 370 | set tlf [$tl getframe] |
|---|
| 371 | # config |
|---|
| 372 | btable $tlf.t -parent $tl \ |
|---|
| 373 | -posteditcmd [list ::TolConsole::TableRecentUpdate $tlf.t] \ |
|---|
| 374 | -iniconfig btable |
|---|
| 375 | $tlf.t fillSet $setgrp |
|---|
| 376 | pack $tlf.t -fill both -expand yes |
|---|
| 377 | bind $tlf.t <Destroy> +[list ::tol::tableset destroy $setgrp] |
|---|
| 378 | $tl bind <Control-F4> [list $tl kill] |
|---|
| 379 | update |
|---|
| 380 | } else { |
|---|
| 381 | tk_messageBox -type ok -icon warning -message [mc "Set not tabulable"]\ |
|---|
| 382 | -parent . -title [mc Warning] |
|---|
| 383 | # -parent $w_tabset -title [mc Warning] |
|---|
| 384 | } |
|---|
| 385 | return $tl |
|---|
| 386 | } |
|---|