NamgraphModel.tcl
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:2k
源码类别:

通讯编程

开发平台:

Visual C++

  1. Class NamgraphModel -superclass Observable
  2. NamgraphModel instproc init { nid obs } {
  3.     $self next
  4.     $self instvar id_ datacount Maxy_ Maxx_ animator_id_ timeslider_swidth_
  5.     set id_ $nid
  6.     set datacount 0
  7.     set animator_id_ $obs
  8.     set Maxy_ [$obs set highest_seq($id_)]
  9.     set Maxx_ [$obs set maxtime]
  10. }
  11. NamgraphModel instproc id {} {
  12.     $self instvar id_
  13.     return $id_
  14. }
  15. NamgraphModel instproc animator {} {
  16.     $self instvar animator_id_
  17.     return $animator_id_
  18. }
  19. NamgraphModel instproc adddata { ob mid x y ymark } {
  20.     $self instvar dataname datacount id_ dataplotx dataploty
  21.     $self instvar plotmark plotcolor dataplotym
  22.     $self tkvar midbuilder
  23.     
  24.     if ![info exists midbuilder($mid)] {
  25. set midbuilder($mid) $datacount
  26. set mname [$ob set filter_id($mid)]
  27. set pmark [$ob set plotmark($id_.$mid)]
  28. set pcolor [$ob set plotcolor($id_.$mid)]
  29. set pcolor [$ob set colorname($pcolor)]
  30.         set dataname($datacount) $mname 
  31. set plotmark($datacount) $pmark
  32. set plotcolor($datacount) $pcolor
  33. incr datacount
  34.     }
  35.     set current_index $midbuilder($mid)
  36.     
  37.     lappend dataplotx($current_index) $x
  38.     lappend dataploty($current_index) $y
  39.     set dataplotym($y) $ymark
  40. }
  41. NamgraphModel instproc verifyymark { index } {
  42.     $self instvar dataplotym
  43.     if [info exists dataplotym($index)] {
  44. return $dataplotym($index)
  45.     }
  46.     return ""
  47. }
  48. NamgraphModel instproc startview {title} {
  49.     $self instvar Maxy_ Maxx_
  50.     set vob [new NamgraphView $title $self 0 $Maxx_ 0 $Maxy_ 1]
  51.     $self addObserver $vob
  52. }
  53. #----------------------------------------------------------------------
  54. # NamgraphModel instproc update { arg } 
  55. #  - Must have update 
  56. #  - two possible args
  57. #      1. Animator current time - single value
  58. #      2. trace event - a list 
  59. #
  60. #  - Requires that all trace events have a -t flag with a value
  61. #----------------------------------------------------------------------
  62. NamgraphModel instproc update { arg } {
  63.   # Check to see if it is a trace event
  64.   set now [get_trace_item "-t" $arg]
  65.   if { $now == "" } {
  66.     # no -t flag so assume it must be a single value
  67.     set now $arg
  68.     $self notifyObservers $now 
  69.   } else {
  70.     # arg is trace event, what to do ?
  71.   }
  72. }