1 # nam-pkt.tcl --
2 #
3 # FIXME: This file needs a description here.
4 #
5 # Copyright (c) 1997-2002 The Regents of the University of California.
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions are met:
10 #
11 # A. Redistributions of source code must retain the above copyright notice,
12 # this list of conditions and the following disclaimer.
13 # B. Redistributions in binary form must reproduce the above copyright notice,
14 # this list of conditions and the following disclaimer in the documentation
15 # and/or other materials provided with the distribution.
16 # C. Neither the names of the copyright holders nor the names of its
17 # contributors may be used to endorse or promote products derived from this
18 # software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
24 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31
32 #---------------------------------------------------------------------------
33 # NamPkt --
34 # A packet in Nam knows how to draw itself
35 #
36 Class AnmObj/NamPkt -superclass AnmObj
37
38 AnmObj/NamPkt instproc init {eId sT eT pos delay xmitT pktHt attr color pktId} {
39 $self next $eId $sT $eT
40
41 $self instvar attr_ sT_ xmitT_ convId_ pktId_ color_ arrvT_ delay_
42 set attr_ $attr
43 set arrvT_ [expr $sT + $delay]
44 set xmitT_ $xmitT
45 set color_ $color
46 set pktId_ $pktId
47 set delay_ $delay
48 eval $self inst_xform $pos $pktHt
49 $self set bbox_ $pos
50 }
51
52 AnmObj/NamPkt instproc destroy {} { $self next }
53
54 AnmObj/NamPkt instproc inst_xform {x0 y0 x1 y1 pktHt} {
55 set dx [expr $x1 - $x0]
56 set dy [expr $y1 - $y0]
57
58 $self instvar sx_ sy_ vx_ vy_ nx_ ny_ delay_ arrowOffset_
59 set sx_ $x0
60 set sy_ $y0
61
62 #[vx, vy] is the parallel vector, in units of delay_
63 set vx_ [expr $dx/$delay_]
64 set vy_ [expr $dy/$delay_]
65
66 #[nx, ny] is the normal vector in units of pktHt_/delay_
67 set nx_ [expr $vy_ * $pktHt * (-1)]
68 set ny_ [expr $vx_ * $pktHt]
69
70 set arrowOffset_ [expr 0.75 * $pktHt]
71 }
72
73 ####################################################################3
74 # AnmObj/NamPkt instproc xform --
75 #
76 # tail and head is in [0, delay],
77 #
78 # | ^ ->
79 # | | norm
80 # --------------------------------+
81 # ->
82 # vec_
83 #
84 # tail head - arrowOffset x1 = head - arrowOffset_
85 # y2 +------------- y2 = 1.5 (pktHt unit)
86 # | \
87 # y1 | + y1 = 1.0 (pktHt unit)
88 # |
89 # y0 +------------- / y0 = 0.5 (pktHt unit)
90 # head
91 #
92 AnmObj/NamPkt instproc xform {x y} {
93 $self instvar vx_ vy_ sx_ sy_ nx_ ny_
94
95 return [list [expr $sx_ + $x*$vx_ + $y*$nx_] \
96 [expr $sy_ + $x*$vy_ + $y*$ny_]]
97 }
98
99 AnmObj/NamPkt instproc compute_poly {tail head doarrow} {
100 $self instvar arrowOffset_
101
102 # change the coordinates
103 set p0 [$self xform $tail 0.6]
104 set ax [expr $doarrow ? ($head - $arrowOffset_) : $head]
105 if {$ax < $tail} { set ax $head }
106 set p1 [$self xform $ax 0.6]
107 if {!$doarrow} {
108 set p2 ""
109 } else {
110 set p2 [$self xform $head 1.2]
111 }
112 set p3 [$self xform $ax 1.8]
113 set p4 [$self xform $tail 1.8]
114 return [concat $p0 $p1 $p2 $p3 $p4]
115 }
116
117 #
118 # xmitTime edge delay
119 # | --------- | -------------|
120 # startTime arrvTime
121 #
122 #
123 # 0 |---------------------------| delay
124 # FIXME
125 # tail head (tail and head is in [0,delay])
126 #
127 AnmObj/NamPkt instproc draw {now} {
128 if ![$self inRange $now] {
129 $self remove
130 return
131 }
132 $self instvar sT_ xmitT_ arrvT_ drawboard_ color_
133
134 # compute startpt and endpt of packet on link
135 set arrow 1
136 if {$now < $arrvT_} {
137 set head [expr $now - $sT_]
138 } else {
139 set arrow 0
140 set head [expr $arrvT_ - $sT_]
141 }
142 set tail [expr $now - $xmitT_ - $sT_]
143 if {$tail < 0} {
144 set tail 0
145 }
146 #DbgOut "$self p:[$self set pktId_] t:$tail h:$head d:[$edge_ get_delay]"
147
148 eval $drawboard_ poly $color_ \
149 [$self compute_poly $tail $head $arrow]
150 if {$arrow} {
151 eval $drawboard_ text \
152 [$self xform $head 3.0] 0 [$self set pktId_]
153 }
154
155 #DbgOut "drawing pkt $self at $now"
156 }
157
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.