| 1 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 2 | # FILE : setgraph.tcl |
|---|
| 3 | # PURPOSE : This file |
|---|
| 4 | # It's a child of bayesGraph so inherites all its functionalities. |
|---|
| 5 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 6 | |
|---|
| 7 | namespace eval ::SetGraph { |
|---|
| 8 | } |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 12 | proc ::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 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 149 | proc ::SetGraph::Configure {this} { |
|---|
| 150 | # |
|---|
| 151 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 152 | ::bayesGraph::Configure $this |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 157 | proc ::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 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 175 | proc ::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 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 197 | proc ::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 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 223 | proc ::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 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 244 | proc ::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 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 256 | proc ::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 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 268 | proc ::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 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 283 | proc ::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 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 320 | proc ::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 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 426 | proc ::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 | if {![CheckGraphicable] } { |
|---|
| 454 | tk_messageBox -type ok -icon warning -title [mc Warning]\ |
|---|
| 455 | -message [mc "Set not graphicable"] |
|---|
| 456 | return "" |
|---|
| 457 | } |
|---|
| 458 | # fill listX and listY |
|---|
| 459 | # TICKET 1450 |
|---|
| 460 | #::SetGraphDialog::SetDataVarList |
|---|
| 461 | switch $type { |
|---|
| 462 | 0 { |
|---|
| 463 | # custom |
|---|
| 464 | set lstLines {} |
|---|
| 465 | set len [llength $pairs] |
|---|
| 466 | for {set i 0} {[expr $i < $len]} {incr i} { |
|---|
| 467 | set xy [lindex $pairs $i] |
|---|
| 468 | set name [lindex $names $i] |
|---|
| 469 | if {![string length $name]} { |
|---|
| 470 | set name "Column [expr $i + 1]" |
|---|
| 471 | } |
|---|
| 472 | lappend lstLines [::SetGraphDialog::AddLine \ |
|---|
| 473 | [expr [lindex $xy 0] - 1] \ |
|---|
| 474 | [expr [lindex $xy 1] - 1] \ |
|---|
| 475 | $name \ |
|---|
| 476 | $lstLines] |
|---|
| 477 | } |
|---|
| 478 | } |
|---|
| 479 | 1 { |
|---|
| 480 | # all to one |
|---|
| 481 | ::SetGraphDialog::GrapthAllLine 1 0 $names |
|---|
| 482 | } |
|---|
| 483 | 2 { |
|---|
| 484 | # all to generic |
|---|
| 485 | ::SetGraphDialog::GrapthAllLine 0 0 $names |
|---|
| 486 | } |
|---|
| 487 | 3 { |
|---|
| 488 | # even to odd |
|---|
| 489 | ::SetGraphDialog::GrapthEvenUneven $names |
|---|
| 490 | } |
|---|
| 491 | } |
|---|
| 492 | # build info to graph |
|---|
| 493 | if [llength $data(selected)] { |
|---|
| 494 | ::SetGraphDialog::SetSelection |
|---|
| 495 | set info [list vectors $data(vectors) names $data(names) xTicks $data(xTicks)] |
|---|
| 496 | set instance [::SetGraph::Create $path $info $set $tableset $fileGCF $title] |
|---|
| 497 | bind $path <Destroy> +[list ::SetGraphDialog::OnDestroyGraph $data(nameVectors)] |
|---|
| 498 | return $instance |
|---|
| 499 | } else { |
|---|
| 500 | set msg [mc "There are no data to draw"] |
|---|
| 501 | ::TolConsole::HciWriter "<W>$msg</W>" |
|---|
| 502 | return "" |
|---|
| 503 | } |
|---|
| 504 | } |
|---|
| 505 | |
|---|
| 506 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 507 | proc ::SetGraphDialog::Init {path tableset set} { |
|---|
| 508 | # |
|---|
| 509 | # PURPOSE: Checks if the set is graphicable and if so, draws and assistant |
|---|
| 510 | # that allows to choose x and y columns for the elements to draw. |
|---|
| 511 | # |
|---|
| 512 | # PARAMETERS: |
|---|
| 513 | # path -> path of the blt graph |
|---|
| 514 | # tableset -> command of the set |
|---|
| 515 | # set -> reference to the TOL set |
|---|
| 516 | # |
|---|
| 517 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 518 | variable data |
|---|
| 519 | |
|---|
| 520 | ::SetGraphDialog::InitData $tableset |
|---|
| 521 | |
|---|
| 522 | if {![CheckGraphicable]} { |
|---|
| 523 | tk_messageBox -type ok -icon warning -title [mc Warning]\ |
|---|
| 524 | -message [mc "Set not graphicable"] |
|---|
| 525 | return 0 |
|---|
| 526 | } |
|---|
| 527 | DrawDialog |
|---|
| 528 | if [llength $data(vectors)] { |
|---|
| 529 | set info [list vectors $data(vectors) names $data(names) xTicks $data(xTicks)] |
|---|
| 530 | set Instance [::SetGraph::Create $path $info $set $tableset] |
|---|
| 531 | bind $path <Destroy> +[list ::SetGraphDialog::OnDestroyGraph $data(nameVectors)] |
|---|
| 532 | return $Instance |
|---|
| 533 | } else { |
|---|
| 534 | return 0 |
|---|
| 535 | } |
|---|
| 536 | } |
|---|
| 537 | |
|---|
| 538 | |
|---|
| 539 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 540 | proc ::SetGraphDialog::OnDestroyGraph {list} { |
|---|
| 541 | # |
|---|
| 542 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 543 | if [llength $list] { |
|---|
| 544 | eval blt::vector destroy $list |
|---|
| 545 | } |
|---|
| 546 | } |
|---|
| 547 | |
|---|
| 548 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 549 | proc ::SetGraphDialog::GetColTypes {tableset} { |
|---|
| 550 | # |
|---|
| 551 | # PURPOSE: Extracts information about the types of the columns of the tableset |
|---|
| 552 | # and stores this in the 'data' array of the namespace. There are |
|---|
| 553 | # four types of columns: |
|---|
| 554 | # 1- Graficable in X and Y axis (Real without ? or Inf) |
|---|
| 555 | # 2- Graficable only in X axis (Text or Date) |
|---|
| 556 | # 3- Graficable only in Y axis (Real with ?) |
|---|
| 557 | # 4- Not graficable (Real with Inf) |
|---|
| 558 | # |
|---|
| 559 | # PARAMETERS: |
|---|
| 560 | # tableset -> command of the tableset |
|---|
| 561 | # |
|---|
| 562 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 563 | |
|---|
| 564 | variable data |
|---|
| 565 | |
|---|
| 566 | set data(var,listX) \ |
|---|
| 567 | [list [list -1 "<Generic 1-[$tableset info datarows]>"]] |
|---|
| 568 | |
|---|
| 569 | set data(var,listY) {} |
|---|
| 570 | |
|---|
| 571 | set idx 0 |
|---|
| 572 | for {set i 1} {$i <= 4} {incr i} { |
|---|
| 573 | set data(idxColsType$i) "" |
|---|
| 574 | set data(nameColsType$i) "" |
|---|
| 575 | } |
|---|
| 576 | foreach it [$tableset info columns] { |
|---|
| 577 | #puts "**** it = $it" |
|---|
| 578 | foreach {key value} $it { |
|---|
| 579 | set data(infCols,$idx,$key) $value |
|---|
| 580 | } |
|---|
| 581 | switch -- $data(infCols,$idx,type) { |
|---|
| 582 | Date - |
|---|
| 583 | Text { |
|---|
| 584 | # first column |
|---|
| 585 | if {![info exists data(firstcolumn)] || ![string length $data(firstcolumn)]} { |
|---|
| 586 | set data(firstcolumn) $idx |
|---|
| 587 | } |
|---|
| 588 | |
|---|
| 589 | lappend data(idxColsType2) $idx |
|---|
| 590 | lappend data(var,listX) [ list $idx $data(infCols,$idx,name) ] |
|---|
| 591 | } |
|---|
| 592 | Real { |
|---|
| 593 | # first column |
|---|
| 594 | if {![info exists data(firstcolumn)] || ![string length $data(firstcolumn)]} { |
|---|
| 595 | set data(firstcolumn) $idx |
|---|
| 596 | } |
|---|
| 597 | if {$data(infCols,$idx,infinity)} { |
|---|
| 598 | lappend data(idxColsType4) $idx |
|---|
| 599 | # lappend data(idxColsType1) $idx |
|---|
| 600 | lappend data(var,listY) [ list $idx $data(infCols,$idx,name) ] |
|---|
| 601 | } elseif {$data(infCols,$idx,unknown)} { |
|---|
| 602 | lappend data(idxColsType3) $idx |
|---|
| 603 | lappend data(var,listY) [ list $idx $data(infCols,$idx,name) ] |
|---|
| 604 | } else { |
|---|
| 605 | lappend data(idxColsType1) $idx |
|---|
| 606 | lappend data(var,listX) [ list $idx $data(infCols,$idx,name) ] |
|---|
| 607 | lappend data(var,listY) [ list $idx $data(infCols,$idx,name) ] |
|---|
| 608 | } |
|---|
| 609 | } |
|---|
| 610 | } |
|---|
| 611 | incr idx |
|---|
| 612 | } |
|---|
| 613 | } |
|---|
| 614 | |
|---|
| 615 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 616 | proc ::SetGraphDialog::CheckGraphicable {} { |
|---|
| 617 | # |
|---|
| 618 | # PURPOSE: Check if the set is graphicable and returns a code |
|---|
| 619 | # |
|---|
| 620 | # RETURN: |
|---|
| 621 | # 0 if the set isn't graphicable |
|---|
| 622 | # !0 if there are some posibilities for choosing columns (assistant will be |
|---|
| 623 | # drawn) |
|---|
| 624 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 625 | variable data |
|---|
| 626 | |
|---|
| 627 | # there must be at least Real numbers |
|---|
| 628 | return [expr {[llength $data(idxColsType1)] + \ |
|---|
| 629 | [llength $data(idxColsType3)] + \ |
|---|
| 630 | [llength $data(idxColsType4)]}] |
|---|
| 631 | } |
|---|
| 632 | |
|---|
| 633 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 634 | proc ::SetGraphDialog::DrawDialog {} { |
|---|
| 635 | # |
|---|
| 636 | # PURPOSE: Draw an assistant to select the columns to plot |
|---|
| 637 | # |
|---|
| 638 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 639 | variable data |
|---|
| 640 | variable tmpOpt |
|---|
| 641 | |
|---|
| 642 | #puts "******* ::SetGraphDialog::DrawDialog" |
|---|
| 643 | set dialog [Dialog .t -title [mc "Columns Selector"] -separator yes\ |
|---|
| 644 | -modal local -parent .] |
|---|
| 645 | set tmpOpt(dialog) $dialog |
|---|
| 646 | |
|---|
| 647 | wm protocol $dialog WM_DELETE_WINDOW [list ::SetGraphDialog::Cancel $dialog] |
|---|
| 648 | set w [$dialog getframe] |
|---|
| 649 | |
|---|
| 650 | set f1 [frame $w.f1] |
|---|
| 651 | |
|---|
| 652 | # fill listX and listY |
|---|
| 653 | # TICKET 1450 |
|---|
| 654 | #::SetGraphDialog::SetDataVarList |
|---|
| 655 | |
|---|
| 656 | set values "" |
|---|
| 657 | set lst "" |
|---|
| 658 | foreach it $data(var,listX) { |
|---|
| 659 | lappend values [lindex $it 1] |
|---|
| 660 | lappend lst [lindex $it 0] |
|---|
| 661 | } |
|---|
| 662 | label $f1.lXAxis -text [mc "X Values"]: |
|---|
| 663 | set tmpOpt(widget,cbXAxis) [ComboBox $f1.cbXAxis -width 16 -height 5\ |
|---|
| 664 | -editable false -justify right\ |
|---|
| 665 | -values $values\ |
|---|
| 666 | -modifycmd [list ::SetGraphDialog::OnModifyXValues $lst ]] |
|---|
| 667 | |
|---|
| 668 | set values "" |
|---|
| 669 | set lst "" |
|---|
| 670 | foreach it $data(var,listY) { |
|---|
| 671 | lappend values [lindex $it 1] |
|---|
| 672 | lappend lst [lindex $it 0] |
|---|
| 673 | } |
|---|
| 674 | |
|---|
| 675 | label $f1.lInfoSelect -text [mc "Select series"]: |
|---|
| 676 | label $f1.lYAxis -text [mc "Y Values"]: |
|---|
| 677 | set tmpOpt(widget,cbYAxis) [ComboBox $f1.cbYAxis -width 16 -height 5\ |
|---|
| 678 | -editable false -justify right\ |
|---|
| 679 | -values $values\ |
|---|
| 680 | -modifycmd [list ::SetGraphDialog::OnModifyYValues $lst ]] |
|---|
| 681 | label $f1.lName -text [mc Name]: |
|---|
| 682 | set tmpOpt(widget,eName) [entry $f1.eName -width 18] |
|---|
| 683 | |
|---|
| 684 | grid $f1.lInfoSelect - -sticky nws -pady 2 |
|---|
| 685 | grid $f1.lXAxis $f1.cbXAxis -sticky news -pady 2 |
|---|
| 686 | grid $f1.lYAxis $f1.cbYAxis -sticky news -pady 2 |
|---|
| 687 | grid $f1.lName $f1.eName -sticky news -pady 2 |
|---|
| 688 | |
|---|
| 689 | grid rowconfigure $f1 4 -weight 1 |
|---|
| 690 | grid columnconfigure $f1 1 -weight 1 |
|---|
| 691 | |
|---|
| 692 | set f2 [frame $w.f2] |
|---|
| 693 | label $f2.lSeries -text [mc "Series to draw"]: |
|---|
| 694 | |
|---|
| 695 | set tmpOpt(widget,lbSeries) [blistboxplus $f2.lb \ |
|---|
| 696 | -selectmode multiple -nomenu true \ |
|---|
| 697 | -cols { lines } \ |
|---|
| 698 | -readonly false -parent $f2 -orientation vertical] |
|---|
| 699 | bind $tmpOpt(widget,lbSeries) <Button-1> +[list focus -force %W] |
|---|
| 700 | |
|---|
| 701 | button $f2.bAdd -width 6 -text [mc Add] -command ::SetGraphDialog::AddItem |
|---|
| 702 | button $f2.bDel -width 6 -text [mc Delete] -command ::SetGraphDialog::DelItem |
|---|
| 703 | |
|---|
| 704 | grid $f2.lSeries - -sticky nw -pady 0 |
|---|
| 705 | grid $f2.lb - -sticky news -pady 0 |
|---|
| 706 | grid $f2.bAdd $f2.bDel -sticky new -pady 0 |
|---|
| 707 | |
|---|
| 708 | grid rowconfigure $f2 1 -weight 1 |
|---|
| 709 | grid columnconfigure $f2 0 -weight 1 |
|---|
| 710 | grid columnconfigure $f2 1 -weight 1 |
|---|
| 711 | |
|---|
| 712 | # options advanced |
|---|
| 713 | TitleFrame $w.f3 -text [mc "Automatic generation"] |
|---|
| 714 | set f3 [$w.f3 getframe] |
|---|
| 715 | |
|---|
| 716 | radiobutton $f3.rbAllFirst -text [mc SetGraphAllFirst] \ |
|---|
| 717 | -value f -highlightthickness 0 -pady 0 \ |
|---|
| 718 | -variable ::SetGraphDialog::data(var,genAut) |
|---|
| 719 | DynamicHelp::add $f3.rbAllFirst -text [mc SetGraphAllFirstHint] |
|---|
| 720 | radiobutton $f3.rbAllGeneric -text [mc SetGraphAllGeneric] \ |
|---|
| 721 | -value g -highlightthickness 0 -pady 0\ |
|---|
| 722 | -variable ::SetGraphDialog::data(var,genAut) |
|---|
| 723 | DynamicHelp::add $f3.rbAllGeneric -text [mc SetGraphAllGenericHint] |
|---|
| 724 | radiobutton $f3.rbEvenUneven -text [mc SetGraphEvenUneven] \ |
|---|
| 725 | -value e -highlightthickness 0 -pady 0 \ |
|---|
| 726 | -variable ::SetGraphDialog::data(var,genAut) |
|---|
| 727 | DynamicHelp::add $f3.rbEvenUneven -text [mc SetGraphEvenUnevenHint] |
|---|
| 728 | Button $f3.bAddGenAut -text [mc Add] \ |
|---|
| 729 | -width 6 -command [list ::SetGraphDialog::AddGenAut] |
|---|
| 730 | |
|---|
| 731 | grid $f3.rbAllFirst - -sticky nws -pady 1 |
|---|
| 732 | grid $f3.rbAllGeneric - -sticky nws -pady 1 |
|---|
| 733 | grid $f3.rbEvenUneven $f3.bAddGenAut -sticky nws -pady 1 |
|---|
| 734 | |
|---|
| 735 | grid rowconfigure $f3 0 -weight 1 |
|---|
| 736 | grid rowconfigure $f3 1 -weight 1 |
|---|
| 737 | grid rowconfigure $f3 2 -weight 1 |
|---|
| 738 | grid columnconfigure $f3 0 -weight 1 |
|---|
| 739 | |
|---|
| 740 | set w_bbox \ |
|---|
| 741 | [ButtonBox $w.bb -orient horizontal -spacing 10 -padx 0 -pady 0 \ |
|---|
| 742 | -homogeneous false] |
|---|
| 743 | $w_bbox add -text [mc "Accept"] -relief link \ |
|---|
| 744 | -helptext [mc "Accept"] \ |
|---|
| 745 | -image [::Bitmap::get accept] -compound left -padx 5 -pady 1 \ |
|---|
| 746 | -command [list ::SetGraphDialog::Finish $dialog] |
|---|
| 747 | $w_bbox add -text [mc "Cancel"] -relief link \ |
|---|
| 748 | -helptext [mc "Cancel"]\ |
|---|
| 749 | -image [::Bitmap::get cancelx] -compound left -padx 5 -pady 1 \ |
|---|
| 750 | -command [list ::SetGraphDialog::Cancel $dialog] |
|---|
| 751 | |
|---|
| 752 | grid $f1 $f2 -sticky news |
|---|
| 753 | grid $w.f3 - -sticky news |
|---|
| 754 | grid $w_bbox - -sticky news |
|---|
| 755 | |
|---|
| 756 | grid rowconfigure $w 0 -weight 1 |
|---|
| 757 | grid columnconfigure $w 0 -weight 1 |
|---|
| 758 | grid columnconfigure $w 1 -weight 3 |
|---|
| 759 | |
|---|
| 760 | bind $dialog <F1> "ShowHelp Tb4GraSetSel" |
|---|
| 761 | $dialog draw |
|---|
| 762 | } |
|---|
| 763 | |
|---|
| 764 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 765 | proc ::SetGraphDialog::SetDataVarList {} { |
|---|
| 766 | # |
|---|
| 767 | # PURPOSE: Fill varible data(var,listX) and data(var,listY) |
|---|
| 768 | # |
|---|
| 769 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 770 | variable data |
|---|
| 771 | |
|---|
| 772 | # fill data(var,listX) |
|---|
| 773 | set data(var,listX) {} |
|---|
| 774 | |
|---|
| 775 | set data(var,listX) \ |
|---|
| 776 | [list [list -1 "<Generic 1-[$data(tableset) info datarows]>"]] |
|---|
| 777 | |
|---|
| 778 | foreach it [concat $data(idxColsType2) $data(idxColsType1)] { |
|---|
| 779 | lappend data(var,listX) [list $it $data(infCols,$it,name)] |
|---|
| 780 | } |
|---|
| 781 | |
|---|
| 782 | if {![string equal [$data(tableset) info header] "generic"] } { |
|---|
| 783 | set data(var,listX) [lsort -index 1 $data(var,listX)] |
|---|
| 784 | } |
|---|
| 785 | #set data(var,listX) [lsort $data(var,listX)] |
|---|
| 786 | |
|---|
| 787 | # fill data(var,listY) |
|---|
| 788 | set data(var,listY) {} |
|---|
| 789 | foreach it [concat $data(idxColsType1) $data(idxColsType3)] { |
|---|
| 790 | lappend data(var,listY) [list $it $data(infCols,$it,name)] |
|---|
| 791 | } |
|---|
| 792 | if {![string equal [$data(tableset) info header] "generic"] } { |
|---|
| 793 | set data(var,listY) [lsort -index 1 $data(var,listY)] |
|---|
| 794 | } |
|---|
| 795 | #set data(var,listY) [lsort $data(var,listY)] |
|---|
| 796 | } |
|---|
| 797 | |
|---|
| 798 | |
|---|
| 799 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 800 | proc ::SetGraphDialog::AddGenAut {} { |
|---|
| 801 | # |
|---|
| 802 | # PURPOSE: Control de la opción seleccionada para la generacion automatica de |
|---|
| 803 | # series |
|---|
| 804 | # |
|---|
| 805 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 806 | variable data |
|---|
| 807 | switch -exact $data(var,genAut) { |
|---|
| 808 | f { |
|---|
| 809 | ::SetGraphDialog::GrapthAllLine 1 0 |
|---|
| 810 | } |
|---|
| 811 | g { |
|---|
| 812 | ::SetGraphDialog::GrapthAllLine 0 0 |
|---|
| 813 | } |
|---|
| 814 | e { |
|---|
| 815 | ::SetGraphDialog::GrapthEvenUneven |
|---|
| 816 | } |
|---|
| 817 | } |
|---|
| 818 | } |
|---|
| 819 | |
|---|
| 820 | |
|---|
| 821 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 822 | proc ::SetGraphDialog::GrapthAllLine {indexX rangeY {names {}}} { |
|---|
| 823 | # |
|---|
| 824 | # PURPOSE: Seleccionamos todas las series contra una de ellas |
|---|
| 825 | # |
|---|
| 826 | # PARAMETERS: indexX -> Indice en X con el que se cruzan las demas columnas |
|---|
| 827 | # rangeY -> Rango inicial de columnas a usar en Y |
|---|
| 828 | # |
|---|
| 829 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 830 | variable tmpOpt |
|---|
| 831 | variable data |
|---|
| 832 | # first line ? |
|---|
| 833 | if {[expr $indexX == 1]} { |
|---|
| 834 | set firLinX $data(firstcolumn) |
|---|
| 835 | } else { |
|---|
| 836 | set firLinX [lindex [lindex $data(var,listX) $indexX] 0] |
|---|
| 837 | } |
|---|
| 838 | # control: uniqueXAxis |
|---|
| 839 | set ok [::SetGraphDialog::CheckAddSerie $firLinX] |
|---|
| 840 | if {!$ok} { |
|---|
| 841 | if {[info exists tmpOpt(dialog)]} { |
|---|
| 842 | set parent $tmpOpt(dialog) |
|---|
| 843 | } else { |
|---|
| 844 | set parent . |
|---|
| 845 | } |
|---|
| 846 | set parent |
|---|
| 847 | set msg "[mc {Item not selectable}].\n[mc UniqueXAxis]" |
|---|
| 848 | tk_messageBox -type ok -icon warning -message $msg\ |
|---|
| 849 | -parent $parent -title [mc Warning] |
|---|
| 850 | } else { |
|---|
| 851 | # find line axis X ? |
|---|
| 852 | if {([lindex $firLinX 0]==-1) || |
|---|
| 853 | ([lsearch -exact $data(idxColsType1) $firLinX]!=-1) || |
|---|
| 854 | ([lsearch -exact $data(idxColsType2) $firLinX]!=-1)} { |
|---|
| 855 | # remove first line |
|---|
| 856 | set row 0 |
|---|
| 857 | set lst [lrange $data(var,listY) $rangeY end] |
|---|
| 858 | foreach it $lst { |
|---|
| 859 | # line is graph Y ? |
|---|
| 860 | if {([lsearch -exact $data(idxColsType1) [lindex $it 0]]!=-1) || |
|---|
| 861 | ([lsearch -exact $data(idxColsType3) [lindex $it 0]]!=-1)} { |
|---|
| 862 | if {![string equal $firLinX [lindex $it 0]]} { |
|---|
| 863 | set name [lindex $names $row] |
|---|
| 864 | if {![string length $name]} { |
|---|
| 865 | set name [lindex $it 1] |
|---|
| 866 | } |
|---|
| 867 | lappend data(selected) [list $firLinX [lindex $it 0] $name] |
|---|
| 868 | if {([info exists tmpOpt(widget,lbSeries)]) && \ |
|---|
| 869 | ([winfo exists $tmpOpt(widget,lbSeries)])} { |
|---|
| 870 | $tmpOpt(widget,lbSeries) insert end \ |
|---|
| 871 | [list "$name ( X: $firLinX Y: [lindex $it 0] )"] |
|---|
| 872 | } |
|---|
| 873 | incr row |
|---|
| 874 | } |
|---|
| 875 | } else { |
|---|
| 876 | # no se puede graficar |
|---|
| 877 | Tolcon_Trace "Y. No se puede graficar: $it" |
|---|
| 878 | } |
|---|
| 879 | } |
|---|
| 880 | } else { |
|---|
| 881 | # No se puede graficar |
|---|
| 882 | Tolcon_Trace "X. No se puede graficar [lindex $data(var,listX) $indexX]: $firLinX" |
|---|
| 883 | } |
|---|
| 884 | } |
|---|
| 885 | } |
|---|
| 886 | |
|---|
| 887 | |
|---|
| 888 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 889 | proc ::SetGraphDialog::GrapthEvenUneven {{names {}}} { |
|---|
| 890 | # |
|---|
| 891 | # PURPOSE: Seleccionamos las serie impar contr la impar y las agregamos |
|---|
| 892 | # a la lista series a dibujar. Por ejemplo 1-2, 3-4, 5-6 |
|---|
| 893 | # |
|---|
| 894 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 895 | variable tmpOpt |
|---|
| 896 | variable data |
|---|
| 897 | # travel all columuns |
|---|
| 898 | #puts "DEBUG: ::SetGraphDialog::GrapthEvenUneven" |
|---|
| 899 | set row 0 |
|---|
| 900 | |
|---|
| 901 | # TICKET 1450: que cosa mas rara se hace aqui!!!!!!! |
|---|
| 902 | for {set i 0} {$i<[expr [llength $data(var,listY)] - 1]} {incr i 2} { |
|---|
| 903 | set colX [lindex [lindex $data(var,listY) $i] 0] |
|---|
| 904 | set colY [lindex $data(var,listY) [expr $i + 1]] |
|---|
| 905 | # control: uniqueXAxis |
|---|
| 906 | set ok [::SetGraphDialog::CheckAddSerie $colX] |
|---|
| 907 | if {$ok} { |
|---|
| 908 | # find line axis X ? |
|---|
| 909 | if {([lsearch -exact $data(idxColsType1) $colX]!=-1) || |
|---|
| 910 | ([lsearch -exact $data(idxColsType2) $colX]!=-1)} { |
|---|
| 911 | # line is graph Y ? |
|---|
| 912 | if {([lsearch -exact $data(idxColsType1) [lindex $colY 0]]!=-1) || |
|---|
| 913 | ([lsearch -exact $data(idxColsType3) [lindex $colY 0]]!=-1)} { |
|---|
| 914 | set name [lindex $names $row] |
|---|
| 915 | if {![string length $name]} { |
|---|
| 916 | set name [lindex $colY 1] |
|---|
| 917 | } |
|---|
| 918 | lappend data(selected) [list $colX [lindex $colY 0] $name] |
|---|
| 919 | if {(([info exists tmpOpt(widget,lbSeries)]) && \ |
|---|
| 920 | ([winfo exists $tmpOpt(widget,lbSeries)]))} { |
|---|
| 921 | $tmpOpt(widget,lbSeries) insert end \ |
|---|
| 922 | [list "$name ( X: $colX Y: [lindex $colY 0] )"] |
|---|
| 923 | } |
|---|
| 924 | } else { |
|---|
| 925 | # no se puede graficar |
|---|
| 926 | Tolcon_Trace "Y. No se puede graficar: $colY" |
|---|
| 927 | } |
|---|
| 928 | } else { |
|---|
| 929 | # No se puede graficar |
|---|
| 930 | Tolcon_Trace "X. No se puede graficar: $colX" |
|---|
| 931 | } |
|---|
| 932 | } |
|---|
| 933 | incr row |
|---|
| 934 | } |
|---|
| 935 | } |
|---|
| 936 | |
|---|
| 937 | |
|---|
| 938 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 939 | proc ::SetGraphDialog::CheckAddSerie {indexX} { |
|---|
| 940 | # |
|---|
| 941 | # PURPOSE: Comprobamos si una serie se puede anhadir a la lista de seleccion |
|---|
| 942 | # |
|---|
| 943 | # PARAMETERS: indexX -> index column X |
|---|
| 944 | # |
|---|
| 945 | # RETURN: true -> ok |
|---|
| 946 | # false -> not added |
|---|
| 947 | # |
|---|
| 948 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 949 | variable data |
|---|
| 950 | set ok 1 |
|---|
| 951 | # si el elemento que intento insertar es de tipo 2 |
|---|
| 952 | if {[string length $data(uniqueXAxis)]} { |
|---|
| 953 | if {$data(uniqueXAxis)!=$indexX} { |
|---|
| 954 | set ok 0 |
|---|
| 955 | } |
|---|
| 956 | } else { |
|---|
| 957 | if {[string length $data(selected)]} { |
|---|
| 958 | if {[lsearch -exact $data(idxColsType1) $indexX] == -1} { |
|---|
| 959 | # trere are items selection with type 1 |
|---|
| 960 | set ok 0 |
|---|
| 961 | } |
|---|
| 962 | } else { |
|---|
| 963 | if {($indexX==-1) || |
|---|
| 964 | ([lsearch -exact $data(idxColsType2) $indexX] != -1)} { |
|---|
| 965 | set data(uniqueXAxis) $indexX |
|---|
| 966 | } else { |
|---|
| 967 | # Type 1 |
|---|
| 968 | } |
|---|
| 969 | } |
|---|
| 970 | } |
|---|
| 971 | return $ok |
|---|
| 972 | } |
|---|
| 973 | |
|---|
| 974 | |
|---|
| 975 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 976 | proc ::SetGraphDialog::OnModifyXValues {list} { |
|---|
| 977 | # |
|---|
| 978 | # PURPOSE: Update variable tmpOpt(var,cbXAxis) with the index of the column |
|---|
| 979 | # when combo that shows names of possible X columns is changed |
|---|
| 980 | # |
|---|
| 981 | # PARAMETERS: |
|---|
| 982 | # list -> list of tranlated values (indexes) of the columns names |
|---|
| 983 | # |
|---|
| 984 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 985 | variable tmpOpt |
|---|
| 986 | |
|---|
| 987 | ::Objects::ComboUnTranslate $tmpOpt(widget,cbXAxis) $list\ |
|---|
| 988 | ::SetGraphDialog::tmpOpt(var,cbXAxis) |
|---|
| 989 | } |
|---|
| 990 | |
|---|
| 991 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 992 | proc ::SetGraphDialog::OnModifyYValues {list} { |
|---|
| 993 | # |
|---|
| 994 | # PURPOSE: Update variable tmpOpt(var,cbYAxis) with the index of the column |
|---|
| 995 | # when combo that shows names of possible Y columns is changed. |
|---|
| 996 | # It also changes the default name of the element |
|---|
| 997 | # |
|---|
| 998 | # PARAMETERS: |
|---|
| 999 | # list -> list of tranlated values (indexes) of the columns names |
|---|
| 1000 | # |
|---|
| 1001 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1002 | variable tmpOpt |
|---|
| 1003 | |
|---|
| 1004 | ::Objects::ComboUnTranslate $tmpOpt(widget,cbYAxis) $list\ |
|---|
| 1005 | ::SetGraphDialog::tmpOpt(var,cbYAxis) |
|---|
| 1006 | CheckName |
|---|
| 1007 | } |
|---|
| 1008 | |
|---|
| 1009 | |
|---|
| 1010 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1011 | proc ::SetGraphDialog::CheckName {} { |
|---|
| 1012 | # |
|---|
| 1013 | # PURPOSE: Sets the element's default name to the y column's name |
|---|
| 1014 | # |
|---|
| 1015 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1016 | |
|---|
| 1017 | variable tmpOpt |
|---|
| 1018 | $tmpOpt(widget,eName) delete 0 end |
|---|
| 1019 | $tmpOpt(widget,eName) insert 0 [$tmpOpt(widget,cbYAxis) cget -text] |
|---|
| 1020 | } |
|---|
| 1021 | |
|---|
| 1022 | |
|---|
| 1023 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1024 | proc ::SetGraphDialog::AddItem {} { |
|---|
| 1025 | # |
|---|
| 1026 | # PURPOSE: Adds a element to the selected series listbox checking if it can |
|---|
| 1027 | # be added. |
|---|
| 1028 | # |
|---|
| 1029 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1030 | variable tmpOpt |
|---|
| 1031 | variable data |
|---|
| 1032 | if { [$tmpOpt(widget,cbXAxis) getvalue] == -1} { |
|---|
| 1033 | tk_messageBox -type ok -icon warning -message [mc "You must fill X Values"]\ |
|---|
| 1034 | -parent $tmpOpt(dialog) -title [mc Warning] |
|---|
| 1035 | return |
|---|
| 1036 | } |
|---|
| 1037 | if { [$tmpOpt(widget,cbYAxis) getvalue] == -1} { |
|---|
| 1038 | tk_messageBox -type ok -icon warning -message [mc "You must fill Y Values"]\ |
|---|
| 1039 | -parent $tmpOpt(dialog) -title [mc Warning] |
|---|
| 1040 | return |
|---|
| 1041 | } |
|---|
| 1042 | if {[string equal [$tmpOpt(widget,eName) get] ""]} { |
|---|
| 1043 | tk_messageBox -type ok -icon warning -message [mc "You must specify a name"]\ |
|---|
| 1044 | -parent $tmpOpt(dialog) -title [mc Warning] |
|---|
| 1045 | return |
|---|
| 1046 | } |
|---|
| 1047 | |
|---|
| 1048 | # uniqueXAxis es un flag que indica que se ha elegido un elemento cuyos datos |
|---|
| 1049 | # en X provienen de una columna de tipo 2 (guardamos su indice) |
|---|
| 1050 | # En los comentarios de este bloque diremos que un elemento es de tipo 2 si sus |
|---|
| 1051 | # datos para el eje X provienen de una columna tipo 2 (solo graficable en X) |
|---|
| 1052 | |
|---|
| 1053 | # lst names |
|---|
| 1054 | set lstNames {} |
|---|
| 1055 | set inx [$tmpOpt(widget,lbSeries) get 0 end] |
|---|
| 1056 | foreach it $inx { |
|---|
| 1057 | lappend lstNames [$tmpOpt(widget,lbSeries) get $it] |
|---|
| 1058 | } |
|---|
| 1059 | set name [::SetGraphDialog::AddLine \ |
|---|
| 1060 | $tmpOpt(var,cbXAxis) \ |
|---|
| 1061 | $tmpOpt(var,cbYAxis) \ |
|---|
| 1062 | [$tmpOpt(widget,eName) get] \ |
|---|
| 1063 | $lstNames] |
|---|
| 1064 | if {[string length $name]} { |
|---|
| 1065 | $tmpOpt(widget,lbSeries) insert end [list $name] |
|---|
| 1066 | } |
|---|
| 1067 | } |
|---|
| 1068 | |
|---|
| 1069 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1070 | proc ::SetGraphDialog::AddLine {colX colY name lstLines} { |
|---|
| 1071 | # |
|---|
| 1072 | # PURPOSE: Adds a element to the selected series listbox checking if it can |
|---|
| 1073 | # be added. |
|---|
| 1074 | # |
|---|
| 1075 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1076 | variable tmpOpt |
|---|
| 1077 | variable data |
|---|
| 1078 | # parent ? |
|---|
| 1079 | if {[info exists tmpOpt(dialog)]} { |
|---|
| 1080 | set parent $tmpOpt(dialog) |
|---|
| 1081 | } else { |
|---|
| 1082 | set parent . |
|---|
| 1083 | } |
|---|
| 1084 | # uniqueXAxis es un flag que indica que se ha elegido un elemento cuyos |
|---|
| 1085 | # datos en X provienen de una columna de tipo 2 (guardamos su indice) |
|---|
| 1086 | # En los comentarios de este bloque diremos que un elemento es de tipo 2 si |
|---|
| 1087 | # sus datos para el eje X provienen de una columna tipo 2 |
|---|
| 1088 | # (solo graficable en X) |
|---|
| 1089 | |
|---|
| 1090 | # si no hay ningun elemento tipo 2 |
|---|
| 1091 | if {[string equal $data(uniqueXAxis) ""]} { |
|---|
| 1092 | # si el elemento que intento insertar es de tipo 2 |
|---|
| 1093 | if {(($colX == -1) || |
|---|
| 1094 | ([lsearch -exact $data(idxColsType2) $colX] != -1))} { |
|---|
| 1095 | # si no hay ningún elemento insertado |
|---|
| 1096 | if {[llength $lstLines]} { |
|---|
| 1097 | set msg "[mc {Item not selectionable}].\n[mc UniqueXAxis]" |
|---|
| 1098 | tk_messageBox -type ok -icon warning -message $msg\ |
|---|
| 1099 | -parent $parent -title [mc Warning] |
|---|
| 1100 | return {} |
|---|
| 1101 | } else { |
|---|
| 1102 | set data(uniqueXAxis) $colX |
|---|
| 1103 | } |
|---|
| 1104 | } |
|---|
| 1105 | # si ya hay algún elemento tipo 2 |
|---|
| 1106 | } else { |
|---|
| 1107 | # si el que intento insertar no es el mismo que el que ya hay |
|---|
| 1108 | if { ![string equal $data(uniqueXAxis) $colX] } { |
|---|
| 1109 | set msg "[mc {Item not selectionable}].\n[mc UniqueXAxis]" |
|---|
| 1110 | tk_messageBox -type ok -icon warning -message $msg\ |
|---|
| 1111 | -parent $parent -title [mc Warning] |
|---|
| 1112 | return {} |
|---|
| 1113 | } |
|---|
| 1114 | } |
|---|
| 1115 | |
|---|
| 1116 | if {[lsearch $name $lstLines] != -1} { |
|---|
| 1117 | tk_messageBox -type ok -icon warning\ |
|---|
| 1118 | -parent $parent -title [mc Warning]\ |
|---|
| 1119 | -message [mc "You have added another serie with this name"] |
|---|
| 1120 | # return {} |
|---|
| 1121 | } |
|---|
| 1122 | lappend data(selected) [list $colX $colY $name] |
|---|
| 1123 | return "$name ( X: $colX Y: $colY )" |
|---|
| 1124 | } |
|---|
| 1125 | |
|---|
| 1126 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1127 | proc ::SetGraphDialog::DelItem {} { |
|---|
| 1128 | # |
|---|
| 1129 | # PURPOSE: Deletes an elements selected from the selected series listbox |
|---|
| 1130 | # |
|---|
| 1131 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1132 | variable tmpOpt |
|---|
| 1133 | variable data |
|---|
| 1134 | set idx [$tmpOpt(widget,lbSeries) curselection] |
|---|
| 1135 | if {![llength $idx]} { |
|---|
| 1136 | tk_messageBox -type ok -icon warning -message [mc "You must select a serie"]\ |
|---|
| 1137 | -parent $tmpOpt(dialog) -title [mc Warning] |
|---|
| 1138 | } else { |
|---|
| 1139 | set ids [lsearch -all -regexp [$tmpOpt(widget,lbSeries) get] \ |
|---|
| 1140 | [join [ListToStr $idx " " ^ $] |]] |
|---|
| 1141 | for {set i [expr [llength $ids] - 1]} {[expr $i >= 0]} { incr i -1} { |
|---|
| 1142 | set id [lindex $ids $i] |
|---|
| 1143 | set data(selected) [lreplace $data(selected) $id $id] |
|---|
| 1144 | } |
|---|
| 1145 | foreach id $idx { |
|---|
| 1146 | $tmpOpt(widget,lbSeries) delete $id |
|---|
| 1147 | } |
|---|
| 1148 | # si eliminamos todos los elementos |
|---|
| 1149 | if {[$tmpOpt(widget,lbSeries) size]==0} { |
|---|
| 1150 | set data(uniqueXAxis) "" |
|---|
| 1151 | } |
|---|
| 1152 | } |
|---|
| 1153 | } |
|---|
| 1154 | |
|---|
| 1155 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1156 | proc ::SetGraphDialog::Finish {dialog} { |
|---|
| 1157 | # |
|---|
| 1158 | # PURPOSE: Creates the blt vectors acording to the columns selection done by |
|---|
| 1159 | # the user. It also get the maximun and minimun x value of the |
|---|
| 1160 | # selected series |
|---|
| 1161 | # |
|---|
| 1162 | # PARAMETERS: |
|---|
| 1163 | # dialog -> path of the dialog |
|---|
| 1164 | # |
|---|
| 1165 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1166 | ::SetGraphDialog::SetSelection |
|---|
| 1167 | Cancel $dialog |
|---|
| 1168 | } |
|---|
| 1169 | |
|---|
| 1170 | # TICKET #1450: aqui es donde se ponen los datos que luego se pintan. |
|---|
| 1171 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1172 | proc ::SetGraphDialog::SetSelection {} { |
|---|
| 1173 | # |
|---|
| 1174 | # PURPOSE: Creates the blt vectors acording to the columns selection done by |
|---|
| 1175 | # the user. It also get the maximun and minimun x value of the |
|---|
| 1176 | # selected series |
|---|
| 1177 | # |
|---|
| 1178 | # PARAMETERS: |
|---|
| 1179 | # |
|---|
| 1180 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1181 | variable tmpOpt |
|---|
| 1182 | variable data |
|---|
| 1183 | |
|---|
| 1184 | #puts "DEBUG: ::SetGraphDialog::SetSelection" |
|---|
| 1185 | set colX [lindex [lindex $data(selected) 0] 0] |
|---|
| 1186 | # Si la columna que fija el X del primer elemento es genérica o de tipo 2 |
|---|
| 1187 | # (será la misma para todas) |
|---|
| 1188 | if {($colX == -1) || ([lsearch -exact $data(idxColsType2) $colX] != -1)} { |
|---|
| 1189 | for {set i 0} {$i < [$data(tableset) info datarows]} {incr i} { |
|---|
| 1190 | lappend lst $i |
|---|
| 1191 | } |
|---|
| 1192 | if {($colX != -1)} { |
|---|
| 1193 | set data(xTicks) [$data(tableset) data column $colX] |
|---|
| 1194 | } |
|---|
| 1195 | set uniqueXAxis 1 |
|---|
| 1196 | } else { |
|---|
| 1197 | set uniqueXAxis 0 |
|---|
| 1198 | } |
|---|
| 1199 | |
|---|
| 1200 | # cross the selection |
|---|
| 1201 | foreach it $data(selected) { |
|---|
| 1202 | set colX [lindex $it 0] |
|---|
| 1203 | set colY [lindex $it 1] |
|---|
| 1204 | set name [lindex $it 2] |
|---|
| 1205 | if {$uniqueXAxis} { |
|---|
| 1206 | set vecX $lst |
|---|
| 1207 | } else { |
|---|
| 1208 | set vecX [$data(tableset) data column $colX] |
|---|
| 1209 | } |
|---|
| 1210 | set vecsY [$data(tableset) data column $colY] |
|---|
| 1211 | if {[llength $vecsY] > 1} { |
|---|
| 1212 | set i 0 |
|---|
| 1213 | set subVectors "" |
|---|
| 1214 | set subcurves {} |
|---|
| 1215 | set lstX {} |
|---|
| 1216 | set segX {} |
|---|
| 1217 | set lstY {} |
|---|
| 1218 | set segY {} |
|---|
| 1219 | foreach item $vecsY { |
|---|
| 1220 | #si no es un omitido (vacio o ?) |
|---|
| 1221 | if {[string equal $item ""] || [string equal $item "?"]} { |
|---|
| 1222 | # TICKET 1450 |
|---|
| 1223 | # close this segment |
|---|
| 1224 | if { [ llength $segX ] } { |
|---|
| 1225 | lappend subcurves [ list $segX $segY ] |
|---|
| 1226 | set segX {} |
|---|
| 1227 | set segY {} |
|---|
| 1228 | } |
|---|
| 1229 | } else { |
|---|
| 1230 | # TICKET 1450 |
|---|
| 1231 | #set datX [lindex $vecX $i] |
|---|
| 1232 | #lappend lstX $datX |
|---|
| 1233 | #lappend lstY $item |
|---|
| 1234 | lappend segX [lindex $vecX $i] |
|---|
| 1235 | lappend segY $item |
|---|
| 1236 | } |
|---|
| 1237 | incr i |
|---|
| 1238 | } |
|---|
| 1239 | # TICKET 1450 |
|---|
| 1240 | #lappend data(vectors) [list $lstX $lstY] |
|---|
| 1241 | if { [ llength $segX ] } { |
|---|
| 1242 | lappend subcurves [ list $segX $segY ] |
|---|
| 1243 | } |
|---|
| 1244 | lappend data(vectors) $subcurves |
|---|
| 1245 | } else { |
|---|
| 1246 | #puts "****** lappend data(vectors) [list [list $vecX $vecsY]]" |
|---|
| 1247 | lappend data(vectors) [list [list $vecX $vecsY]] |
|---|
| 1248 | } |
|---|
| 1249 | lappend data(names) $name |
|---|
| 1250 | } |
|---|
| 1251 | } |
|---|
| 1252 | |
|---|
| 1253 | |
|---|
| 1254 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1255 | proc ::SetGraphDialog::Cancel {dialog} { |
|---|
| 1256 | # |
|---|
| 1257 | # PURPOSE: Destroy the dialog |
|---|
| 1258 | # |
|---|
| 1259 | # PARAMETERS: |
|---|
| 1260 | # dialog -> path of the dialog |
|---|
| 1261 | # |
|---|
| 1262 | #///////////////////////////////////////////////////////////////////////////// |
|---|
| 1263 | destroy $dialog |
|---|
| 1264 | } |
|---|