1 | 85 | simandl | <?php |
2 | | | // PHP Weathermap 0.97a |
3 | | | // Copyright Howard Jones, 2005-2010 howie@thingy.com |
4 | | | // http://www.network-weathermap.com/ |
5 | | | // Released under the GNU Public License |
6 | | | |
7 | | | require_once "HTML_ImageMap.class.php"; |
8 | | | |
9 | | | class WeatherMapLink extends WeatherMapItem |
10 | | | { |
11 | | | var $owner, $name; |
12 | | | var $id; |
13 | | | var $maphtml; |
14 | | | var $a, $b; // the ends - references to nodes |
15 | | | var $width, $arrowstyle, $linkstyle; |
16 | | | var $bwfont, $labelstyle, $labelboxstyle; |
17 | | | var $zorder; |
18 | | | var $overliburl = array(); |
19 | | | var $infourl = array(); |
20 | | | var $notes; |
21 | | | var $overlibcaption = array(); |
22 | | | var $overlibwidth, $overlibheight; |
23 | | | var $bandwidth_in, $bandwidth_out; |
24 | | | var $max_bandwidth_in, $max_bandwidth_out; |
25 | | | var $max_bandwidth_in_cfg, $max_bandwidth_out_cfg; |
26 | | | var $targets = array(); |
27 | | | var $a_offset, $b_offset; |
28 | | | var $in_ds, $out_ds; |
29 | | | var $colours = array(); |
30 | | | var $selected; |
31 | | | var $inpercent, $outpercent; |
32 | | | var $inherit_fieldlist; |
33 | | | var $vialist = array(); |
34 | | | var $viastyle; |
35 | | | var $usescale, $duplex; |
36 | | | var $scaletype; |
37 | | | var $outlinecolour; |
38 | | | var $bwoutlinecolour; |
39 | | | var $bwboxcolour; |
40 | | | var $splitpos; |
41 | | | var $commentfont; |
42 | | | var $notestext = array(); |
43 | | | var $inscalekey,$outscalekey; |
44 | | | var $inscaletag, $outscaletag; |
45 | | | # var $incolour,$outcolour; |
46 | | | var $commentfontcolour; |
47 | | | var $commentstyle; |
48 | | | var $bwfontcolour; |
49 | | | # var $incomment, $outcomment; |
50 | | | var $comments = array(); |
51 | | | var $bwlabelformats = array(); |
52 | | | var $curvepoints; |
53 | | | var $labeloffset_in, $labeloffset_out; |
54 | | | var $commentoffset_in, $commentoffset_out; |
55 | | | var $template; |
56 | | | |
57 | | | function WeatherMapLink() { $this->inherit_fieldlist=array |
58 | | | ( |
59 | | | 'my_default' => NULL, |
60 | | | 'width' => 7, |
61 | | | 'commentfont' => 1, |
62 | | | 'bwfont' => 2, |
63 | | | 'template' => ':: DEFAULT ::', |
64 | | | 'splitpos'=>50, |
65 | | | 'labeloffset_out' => 25, |
66 | | | 'labeloffset_in' => 75, |
67 | | | 'commentoffset_out' => 5, |
68 | | | 'commentoffset_in' => 95, |
69 | | | 'commentstyle' => 'edge', |
70 | | | 'arrowstyle' => 'classic', |
71 | | | 'viastyle' => 'curved', |
72 | | | 'usescale' => 'DEFAULT', |
73 | | | 'scaletype' => 'percent', |
74 | | | 'targets' => array(), |
75 | | | 'duplex' => 'full', |
76 | | | 'infourl' => array('',''), |
77 | | | 'notes' => array(), |
78 | | | 'hints' => array(), |
79 | | | 'comments' => array('',''), |
80 | | | 'bwlabelformats' => array(FMT_PERC_IN,FMT_PERC_OUT), |
81 | | | 'overliburl' => array(array(),array()), |
82 | | | 'notestext' => array(IN=>'',OUT=>''), |
83 | | | 'labelstyle' => 'percent', |
84 | | | 'labelboxstyle' => 'classic', |
85 | | | 'linkstyle' => 'twoway', |
86 | | | 'overlibwidth' => 0, |
87 | | | 'overlibheight' => 0, |
88 | | | 'outlinecolour' => array(0, 0, 0), |
89 | | | 'bwoutlinecolour' => array(0, 0, 0), |
90 | | | 'bwfontcolour' => array(0, 0, 0), |
91 | | | 'bwboxcolour' => array(255, 255, 255), |
92 | | | 'commentfontcolour' => array(192,192,192), |
93 | | | 'inpercent'=>0, 'outpercent'=>0, |
94 | | | 'inscalekey'=>'', 'outscalekey'=>'', |
95 | | | # 'incolour'=>-1,'outcolour'=>-1, |
96 | | | 'a_offset' => 'C', |
97 | | | 'b_offset' => 'C', |
98 | | | #'incomment' => '', |
99 | | | #'outcomment' => '', |
100 | | | 'zorder' => 300, |
101 | | | 'overlibcaption' => array('',''), |
102 | | | 'max_bandwidth_in' => 100000000, |
103 | | | 'max_bandwidth_out' => 100000000, |
104 | | | 'max_bandwidth_in_cfg' => '100M', |
105 | | | 'max_bandwidth_out_cfg' => '100M' |
106 | | | ); |
107 | | | // $this->a_offset = 'C'; |
108 | | | // $this->b_offset = 'C'; |
109 | | | // $this->targets = array(); |
110 | | | } |
111 | | | |
112 | | | function Reset(&$newowner) |
113 | | | { |
114 | | | $this->owner=$newowner; |
115 | | | |
116 | | | $template = $this->template; |
117 | | | if($template == '') $template = "DEFAULT"; |
118 | | | |
119 | | | debug("Resetting $this->name with $template\n"); |
120 | | | |
121 | | | // the internal default-default gets it's values from inherit_fieldlist |
122 | | | // everything else comes from a link object - the template. |
123 | | | if($this->name==':: DEFAULT ::') |
124 | | | { |
125 | | | foreach (array_keys($this->inherit_fieldlist) as $fld) { |
126 | | | $this->$fld=$this->inherit_fieldlist[$fld]; |
127 | | | } |
128 | | | } |
129 | | | else |
130 | | | { |
131 | | | $this->CopyFrom($this->owner->links[$template]); |
132 | | | } |
133 | | | $this->template = $template; |
134 | | | |
135 | | | // to stop the editor tanking, now that colours are decided earlier in ReadData |
136 | | | $this->colours[IN] = new Colour(192,192,192); |
137 | | | $this->colours[OUT] = new Colour(192,192,192); |
138 | | | $this->id = $newowner->next_id++; |
139 | | | } |
140 | | | |
141 | | | function my_type() { return "LINK"; } |
142 | | | |
143 | | | function CopyFrom(&$source) |
144 | | | { |
145 | | | debug("Initialising LINK $this->name from $source->name\n"); |
146 | | | assert('is_object($source)'); |
147 | | | |
148 | | | foreach (array_keys($this->inherit_fieldlist) as $fld) { |
149 | | | if($fld != 'template') $this->$fld = $source->$fld; |
150 | | | } |
151 | | | } |
152 | | | |
153 | | | // image = GD image references |
154 | | | // col = array of Colour objects |
155 | | | // widths = array of link widths |
156 | | | function DrawComments($image,$col,$widths) |
157 | | | { |
158 | | | $curvepoints =& $this->curvepoints; |
159 | | | $last = count($curvepoints)-1; |
160 | | | |
161 | | | $totaldistance = $curvepoints[$last][2]; |
162 | | | |
163 | | | $start[OUT] = 0; |
164 | | | $commentpos[OUT] = $this->commentoffset_out; |
165 | | | $commentpos[IN] = $this->commentoffset_in; |
166 | | | $start[IN] = $last; |
167 | | | |
168 | | | if($this->linkstyle=="oneway") |
169 | | | { |
170 | | | $dirs = array(OUT); |
171 | | | } |
172 | | | else |
173 | | | { |
174 | | | $dirs = array(OUT,IN); |
175 | | | } |
176 | | | |
177 | | | foreach ($dirs as $dir) |
178 | | | { |
179 | | | |
180 | | | |
181 | | | // Time to deal with Link Comments, if any |
182 | | | $comment = $this->owner->ProcessString($this->comments[$dir], $this); |
183 | | | |
184 | | | # print "COMMENT: $comment"; |
185 | | | |
186 | | | if($this->owner->get_hint('screenshot_mode')==1) $comment=screenshotify($comment); |
187 | | | |
188 | | | if($comment != '') |
189 | | | { |
190 | | | # print "\n\n----------------------------------------------------------------\nComment $dir for ".$this->name."\n";; |
191 | | | |
192 | | | list($textlength, $textheight) = $this->owner->myimagestringsize($this->commentfont, $comment); |
193 | | | |
194 | | | $extra_percent = $commentpos[$dir]; |
195 | | | |
196 | | | // $font = $this->commentfont; |
197 | | | // nudge pushes the comment out along the link arrow a little bit |
198 | | | // (otherwise there are more problems with text disappearing underneath links) |
199 | | | # $nudgealong = 0; $nudgeout=0; |
200 | | | $nudgealong = intval($this->get_hint("comment_nudgealong")); |
201 | | | $nudgeout = intval($this->get_hint("comment_nudgeout")); |
202 | | | |
203 | | | $extra = ($totaldistance * ($extra_percent/100)); |
204 | | | # $comment_index = find_distance($curvepoints,$extra); |
205 | | | |
206 | | | list($x,$y,$comment_index,$angle) = find_distance_coords_angle($curvepoints,$extra); |
207 | | | |
208 | | | # print "$extra_percent => $extra ($totaldistance)\n"; |
209 | | | #printf(" Point A is %f,%f\n",$curvepoints[$comment_index][0], $curvepoints[$comment_index][1]); |
210 | | | #printf(" Point B is %f,%f\n",$curvepoints[$comment_index+1][0], $curvepoints[$comment_index+1][1]); |
211 | | | #printf(" Point X is %f,%f\n",$x, $y); |
212 | | | |
213 | | | # if( ($comment_index != 0)) print "I "; |
214 | | | # if (($x != $curvepoints[$comment_index][0]) ) print "X "; |
215 | | | # if (($y != $curvepoints[$comment_index][1]) ) print "Y "; |
216 | | | # print "\n"; |
217 | | | |
218 | | | if( ($comment_index != 0) && (($x != $curvepoints[$comment_index][0]) || ($y != $curvepoints[$comment_index][1])) ) |
219 | | | { |
220 | | | # print " -> Path 1\n"; |
221 | | | $dx = $x - $curvepoints[$comment_index][0]; |
222 | | | $dy = $y - $curvepoints[$comment_index][1]; |
223 | | | } |
224 | | | else |
225 | | | { |
226 | | | # print " -> Path 2\n"; |
227 | | | $dx = $curvepoints[$comment_index+1][0] - $x; |
228 | | | $dy = $curvepoints[$comment_index+1][1] - $y; |
229 | | | } |
230 | | | |
231 | | | $centre_distance = $widths[$dir] + 4 + $nudgeout; |
232 | | | if($this->commentstyle == 'center') |
233 | | | { |
234 | | | $centre_distance = $nudgeout - ($textheight/2); |
235 | | | } |
236 | | | |
237 | | | // find the normal to our link, so we can get outside the arrow |
238 | | | |
239 | | | $l=sqrt(($dx * $dx) + ($dy * $dy)); |
240 | | | |
241 | | | # print "$extra => $comment_index/$last => $x,$y => $dx,$dy => $l\n"; |
242 | | | |
243 | | | $dx = $dx/$l; $dy = $dy/$l; |
244 | | | $nx = $dy; $ny = -$dx; |
245 | | | $flipped=FALSE; |
246 | | | |
247 | | | // if the text will be upside-down, rotate it, flip it, and right-justify it |
248 | | | // not quite as catchy as Missy's version |
249 | | | if(abs($angle)>90) |
250 | | | { |
251 | | | # $col = $map->selected; |
252 | | | $angle -= 180; |
253 | | | if($angle < -180) $angle +=360; |
254 | | | $edge_x = $x + $nudgealong*$dx - $nx * $centre_distance; |
255 | | | $edge_y = $y + $nudgealong*$dy - $ny * $centre_distance; |
256 | | | # $comment .= "@"; |
257 | | | $flipped = TRUE; |
258 | | | } |
259 | | | else |
260 | | | { |
261 | | | $edge_x = $x + $nudgealong*$dx + $nx * $centre_distance; |
262 | | | $edge_y = $y + $nudgealong*$dy + $ny * $centre_distance; |
263 | | | } |
264 | | | |
265 | | | |
266 | | | |
267 | | | if( !$flipped && ($extra + $textlength) > $totaldistance) |
268 | | | { |
269 | | | $edge_x -= $dx * $textlength; |
270 | | | $edge_y -= $dy * $textlength; |
271 | | | # $comment .= "#"; |
272 | | | } |
273 | | | |
274 | | | if( $flipped && ($extra - $textlength) < 0) |
275 | | | { |
276 | | | $edge_x += $dx * $textlength; |
277 | | | $edge_y += $dy * $textlength; |
278 | | | # $comment .= "%"; |
279 | | | } |
280 | | | |
281 | | | // FINALLY, draw the text! |
282 | | | # imagefttext($image, $fontsize, $angle, $edge_x, $edge_y, $col, $font,$comment); |
283 | | | $this->owner->myimagestring($image, $this->commentfont, $edge_x, $edge_y, $comment, $col[$dir], $angle); |
284 | | | #imagearc($image,$x,$y,10,10,0, 360,$this->owner->selected); |
285 | | | #imagearc($image,$edge_x,$edge_y,10,10,0, 360,$this->owner->selected); |
286 | | | } |
287 | | | } |
288 | | | } |
289 | | | |
290 | | | function Draw($im, &$map) |
291 | | | { |
292 | | | // Get the positions of the end-points |
293 | | | $x1=$map->nodes[$this->a->name]->x; |
294 | | | $y1=$map->nodes[$this->a->name]->y; |
295 | | | |
296 | | | $x2=$map->nodes[$this->b->name]->x; |
297 | | | $y2=$map->nodes[$this->b->name]->y; |
298 | | | |
299 | | | if(is_null($x1)) { warn("LINK ".$this->name." uses a NODE with no POSITION! [WMWARN35]\n"); return; } |
300 | | | if(is_null($y1)) { warn("LINK ".$this->name." uses a NODE with no POSITION! [WMWARN35]\n"); return; } |
301 | | | if(is_null($x2)) { warn("LINK ".$this->name." uses a NODE with no POSITION! [WMWARN35]\n"); return; } |
302 | | | if(is_null($y2)) { warn("LINK ".$this->name." uses a NODE with no POSITION! [WMWARN35]\n"); return; } |
303 | | | |
304 | | | |
305 | | | if( ($this->linkstyle=='twoway') && ($this->labeloffset_in < $this->labeloffset_out) && (intval($map->get_hint("nowarn_bwlabelpos"))==0) ) |
306 | | | { |
307 | | | warn("LINK ".$this->name." probably has it's BWLABELPOSs the wrong way around [WMWARN50]\n"); |
308 | | | } |
309 | | | |
310 | | | list($dx, $dy)=calc_offset($this->a_offset, $map->nodes[$this->a->name]->width, $map->nodes[$this->a->name]->height); |
311 | | | $x1+=$dx; |
312 | | | $y1+=$dy; |
313 | | | |
314 | | | list($dx, $dy)=calc_offset($this->b_offset, $map->nodes[$this->b->name]->width, $map->nodes[$this->b->name]->height); |
315 | | | $x2+=$dx; |
316 | | | $y2+=$dy; |
317 | | | |
318 | | | if( ($x1==$x2) && ($y1==$y2) && sizeof($this->vialist)==0) |
319 | | | { |
320 | | | warn("Zero-length link ".$this->name." skipped. [WMWARN45]"); |
321 | | | return; |
322 | | | } |
323 | | | |
324 | | | $outlinecol = new Colour($this->outlinecolour); |
325 | | | $commentcol = new Colour($this->commentfontcolour); |
326 | | | |
327 | | | $outline_colour = $outlinecol->gdallocate($im); |
328 | | | |
329 | | | $xpoints = array ( ); |
330 | | | $ypoints = array ( ); |
331 | | | |
332 | | | $xpoints[]=$x1; |
333 | | | $ypoints[]=$y1; |
334 | | | |
335 | | | # warn("There are VIAs.\n"); |
336 | | | foreach ($this->vialist as $via) |
337 | | | { |
338 | | | # imagearc($im, $via[0],$via[1],20,20,0,360,$map->selected); |
339 | | | if(isset($via[2])) |
340 | | | { |
341 | | | $xpoints[]=$map->nodes[$via[2]]->x + $via[0]; |
342 | | | $ypoints[]=$map->nodes[$via[2]]->y + $via[1]; |
343 | | | } |
344 | | | else |
345 | | | { |
346 | | | $xpoints[]=$via[0]; |
347 | | | $ypoints[]=$via[1]; |
348 | | | } |
349 | | | } |
350 | | | |
351 | | | $xpoints[]=$x2; |
352 | | | $ypoints[]=$y2; |
353 | | | |
354 | | | # list($link_in_colour,$link_in_scalekey, $link_in_scaletag) = $map->NewColourFromPercent($this->inpercent,$this->usescale,$this->name); |
355 | | | # list($link_out_colour,$link_out_scalekey, $link_out_scaletag) = $map->NewColourFromPercent($this->outpercent,$this->usescale,$this->name); |
356 | | | |
357 | | | $link_in_colour = $this->colours[IN]; |
358 | | | $link_out_colour = $this->colours[OUT]; |
359 | | | |
360 | | | $gd_in_colour = $link_in_colour->gdallocate($im); |
361 | | | $gd_out_colour = $link_out_colour->gdallocate($im); |
362 | | | |
363 | | | // $map->links[$this->name]->inscalekey = $link_in_scalekey; |
364 | | | // $map->links[$this->name]->outscalekey = $link_out_scalekey; |
365 | | | |
366 | | | $link_width=$this->width; |
367 | | | // these will replace the one above, ultimately. |
368 | | | $link_in_width=$this->width; |
369 | | | $link_out_width=$this->width; |
370 | | | |
371 | | | // for bulging animations |
372 | | | if ( ($map->widthmod) || ($map->get_hint('link_bulge') == 1)) |
373 | | | { |
374 | | | // a few 0.1s and +1s to fix div-by-zero, and invisible links |
375 | | | $link_width = (($link_width * $this->inpercent * 1.5 + 0.1) / 100) + 1; |
376 | | | // these too |
377 | | | $link_in_width = (($link_in_width * $this->inpercent * 1.5 + 0.1) / 100) + 1; |
378 | | | $link_out_width = (($link_out_width * $this->outpercent * 1.5 + 0.1) / 100) + 1; |
379 | | | } |
380 | | | |
381 | | | |
382 | | | if($this->viastyle=='curved') |
383 | | | { |
384 | | | // Calculate the spine points - the actual curve |
385 | | | $this->curvepoints = calc_curve($xpoints, $ypoints); |
386 | | | |
387 | | | // then draw the curve itself |
388 | | | draw_curve($im, $this->curvepoints, |
389 | | | array($link_in_width,$link_out_width), $outline_colour, array($gd_in_colour, $gd_out_colour), |
390 | | | $this->name, $map, $this->splitpos, ($this->linkstyle=='oneway'?TRUE:FALSE) ); |
391 | | | } |
392 | | | |
393 | | | if($this->viastyle=='angled') |
394 | | | { |
395 | | | // Calculate the spine points - the actual not a curve really, but we |
396 | | | // need to create the array, and calculate the distance bits, otherwise |
397 | | | // things like bwlabels won't know where to go. |
398 | | | |
399 | | | $this->curvepoints = calc_straight($xpoints, $ypoints); |
400 | | | |
401 | | | // then draw the "curve" itself |
402 | | | draw_straight($im, $this->curvepoints, |
403 | | | array($link_in_width,$link_out_width), $outline_colour, array($gd_in_colour, $gd_out_colour), |
404 | | | $this->name, $map, $this->splitpos, ($this->linkstyle=='oneway'?TRUE:FALSE) ); |
405 | | | } |
406 | | | |
407 | | | if ( !$commentcol->is_none() ) |
408 | | | { |
409 | | | if($commentcol->is_contrast()) |
410 | | | { |
411 | | | $commentcol_in = $link_in_colour->contrast(); |
412 | | | $commentcol_out = $link_out_colour->contrast(); |
413 | | | } |
414 | | | else |
415 | | | { |
416 | | | $commentcol_in = $commentcol; |
417 | | | $commentcol_out = $commentcol; |
418 | | | } |
419 | | | |
420 | | | $comment_colour_in = $commentcol_in->gdallocate($im); |
421 | | | $comment_colour_out = $commentcol_out->gdallocate($im); |
422 | | | |
423 | | | $this->DrawComments($im,array($comment_colour_in, $comment_colour_out),array($link_in_width*1.1,$link_out_width*1.1)); |
424 | | | } |
425 | | | |
426 | | | $curvelength = $this->curvepoints[count($this->curvepoints)-1][2]; |
427 | | | // figure out where the labels should be, and what the angle of the curve is at that point |
428 | | | list($q1_x,$q1_y,$junk,$q1_angle) = find_distance_coords_angle($this->curvepoints,($this->labeloffset_out/100)*$curvelength); |
429 | | | list($q3_x,$q3_y,$junk,$q3_angle) = find_distance_coords_angle($this->curvepoints,($this->labeloffset_in/100)*$curvelength); |
430 | | | |
431 | | | # imageline($im, $q1_x+20*cos(deg2rad($q1_angle)),$q1_y-20*sin(deg2rad($q1_angle)), $q1_x-20*cos(deg2rad($q1_angle)), $q1_y+20*sin(deg2rad($q1_angle)), $this->owner->selected ); |
432 | | | # imageline($im, $q3_x+20*cos(deg2rad($q3_angle)),$q3_y-20*sin(deg2rad($q3_angle)), $q3_x-20*cos(deg2rad($q3_angle)), $q3_y+20*sin(deg2rad($q3_angle)), $this->owner->selected ); |
433 | | | |
434 | | | # warn("$q1_angle $q3_angle\n"); |
435 | | | |
436 | | | if (!is_null($q1_x)) |
437 | | | { |
438 | | | $outbound=array |
439 | | | ( |
440 | | | $q1_x, |
441 | | | $q1_y, |
442 | | | 0, |
443 | | | 0, |
444 | | | $this->outpercent, |
445 | | | $this->bandwidth_out, |
446 | | | $q1_angle, |
447 | | | OUT |
448 | | | ); |
449 | | | |
450 | | | $inbound=array |
451 | | | ( |
452 | | | $q3_x, |
453 | | | $q3_y, |
454 | | | 0, |
455 | | | 0, |
456 | | | $this->inpercent, |
457 | | | $this->bandwidth_in, |
458 | | | $q3_angle, |
459 | | | IN |
460 | | | ); |
461 | | | |
462 | | | if ($map->sizedebug) |
463 | | | { |
464 | | | $outbound[5]=$this->max_bandwidth_out; |
465 | | | $inbound[5]=$this->max_bandwidth_in; |
466 | | | } |
467 | | | |
468 | | | |
469 | | | if($this->linkstyle=='oneway') |
470 | | | { |
471 | | | $tasks = array($outbound); |
472 | | | } |
473 | | | else |
474 | | | { |
475 | | | $tasks = array($inbound,$outbound); |
476 | | | } |
477 | | | |
478 | | | foreach ($tasks as $task) |
479 | | | { |
480 | | | $thelabel=""; |
481 | | | |
482 | | | $thelabel = $map->ProcessString($this->bwlabelformats[$task[7]],$this); |
483 | | | |
484 | | | if ($thelabel != '') |
485 | | | { |
486 | | | debug("Bandwidth for label is ".$task[5]."\n"); |
487 | | | |
488 | | | $padding = intval($this->get_hint('bwlabel_padding')); |
489 | | | |
490 | | | // if screenshot_mode is enabled, wipe any letters to X and wipe any IP address to 127.0.0.1 |
491 | | | // hopefully that will preserve enough information to show cool stuff without leaking info |
492 | | | if($map->get_hint('screenshot_mode')==1) $thelabel = screenshotify($thelabel); |
493 | | | |
494 | | | if($this->labelboxstyle == 'angled') |
495 | | | { |
496 | | | $angle = $task[6]; |
497 | | | } |
498 | | | else |
499 | | | { |
500 | | | $angle = 0; |
501 | | | } |
502 | | | |
503 | | | $map->DrawLabelRotated($im, $task[0], $task[1],$angle, $thelabel, $this->bwfont, $padding, |
504 | | | $this->name, $this->bwfontcolour, $this->bwboxcolour, $this->bwoutlinecolour,$map, $task[7]); |
505 | | | |
506 | | | // imagearc($im, $task[0], $task[1], 10,10,0,360,$map->selected); |
507 | | | } |
508 | | | } |
509 | | | } |
510 | | | } |
511 | | | |
512 | | | function WriteConfig() |
513 | | | { |
514 | | | $output=''; |
515 | | | # $output .= "# ID ".$this->id." - first seen in ".$this->defined_in."\n"; |
516 | | | |
517 | | | if($this->config_override != '') |
518 | | | { |
519 | | | $output = $this->config_override."\n"; |
520 | | | } |
521 | | | else |
522 | | | { |
523 | | | # $defdef = $this->owner->defaultlink; |
524 | | | $dd = $this->owner->links[$this->template]; |
525 | | | |
526 | | | debug("Writing config for LINK $this->name against $this->template\n"); |
527 | | | |
528 | | | $basic_params = array( |
529 | | | array('width','WIDTH',CONFIG_TYPE_LITERAL), |
530 | | | array('zorder','ZORDER',CONFIG_TYPE_LITERAL), |
531 | | | array('overlibwidth','OVERLIBWIDTH',CONFIG_TYPE_LITERAL), |
532 | | | array('overlibheight','OVERLIBHEIGHT',CONFIG_TYPE_LITERAL), |
533 | | | array('arrowstyle','ARROWSTYLE',CONFIG_TYPE_LITERAL), |
534 | | | array('viastyle','VIASTYLE',CONFIG_TYPE_LITERAL), |
535 | | | array('linkstyle','LINKSTYLE',CONFIG_TYPE_LITERAL), |
536 | | | array('splitpos','SPLITPOS',CONFIG_TYPE_LITERAL), |
537 | | | array('duplex','DUPLEX',CONFIG_TYPE_LITERAL), |
538 | | | array('commentstyle','COMMENTSTYLE',CONFIG_TYPE_LITERAL), |
539 | | | array('labelboxstyle','BWSTYLE',CONFIG_TYPE_LITERAL), |
540 | | | array('usescale','USESCALE',CONFIG_TYPE_LITERAL), |
541 | | | |
542 | | | array('bwfont','BWFONT',CONFIG_TYPE_LITERAL), |
543 | | | array('commentfont','COMMENTFONT',CONFIG_TYPE_LITERAL), |
544 | | | |
545 | | | array('bwoutlinecolour','BWOUTLINECOLOR',CONFIG_TYPE_COLOR), |
546 | | | array('bwboxcolour','BWBOXCOLOR',CONFIG_TYPE_COLOR), |
547 | | | array('outlinecolour','OUTLINECOLOR',CONFIG_TYPE_COLOR), |
548 | | | array('commentfontcolour','COMMENTFONTCOLOR',CONFIG_TYPE_COLOR), |
549 | | | array('bwfontcolour','BWFONTCOLOR',CONFIG_TYPE_COLOR) |
550 | | | ); |
551 | | | |
552 | | | # TEMPLATE must come first. DEFAULT |
553 | | | if($this->template != 'DEFAULT' && $this->template != ':: DEFAULT ::') |
554 | | | { |
555 | | | $output.="\tTEMPLATE " . $this->template . "\n"; |
556 | | | } |
557 | | | |
558 | | | foreach ($basic_params as $param) |
559 | | | { |
560 | | | $field = $param[0]; |
561 | | | $keyword = $param[1]; |
562 | | | |
563 | | | # $output .= "# For $keyword: ".$this->$field." vs ".$dd->$field."\n"; |
564 | | | if ($this->$field != $dd->$field) |
565 | | | #if (1==1) |
566 | | | { |
567 | | | if($param[2] == CONFIG_TYPE_COLOR) $output.="\t$keyword " . render_colour($this->$field) . "\n"; |
568 | | | if($param[2] == CONFIG_TYPE_LITERAL) $output.="\t$keyword " . $this->$field . "\n"; |
569 | | | } |
570 | | | } |
571 | | | |
572 | | | if ($this->infourl[IN] == $this->infourl[OUT]) { |
573 | | | $dirs = array(IN=>""); // only use the IN value, since they're both the same, but don't prefix the output keyword |
574 | | | } else { |
575 | | | $dirs = array( IN=>"IN", OUT=>"OUT" );// the full monty two-keyword version |
576 | | | } |
577 | | | |
578 | | | foreach ($dirs as $dir=>$tdir) { |
579 | | | if ($this->infourl[$dir] != $dd->infourl[$dir]) { |
580 | | | $output .= "\t" . $tdir . "INFOURL " . $this->infourl[$dir] . "\n"; |
581 | | | } |
582 | | | } |
583 | | | |
584 | | | if ($this->overlibcaption[IN] == $this->overlibcaption[OUT]) { |
585 | | | $dirs = array(IN=>""); // only use the IN value, since they're both the same, but don't prefix the output keyword |
586 | | | } else { |
587 | | | $dirs = array( IN=>"IN", OUT=>"OUT" );// the full monty two-keyword version |
588 | | | } |
589 | | | |
590 | | | foreach ($dirs as $dir=>$tdir) { |
591 | | | if ($this->overlibcaption[$dir] != $dd->overlibcaption[$dir]) { |
592 | | | $output .= "\t".$tdir."OVERLIBCAPTION " . $this->overlibcaption[$dir] . "\n"; |
593 | | | } |
594 | | | } |
595 | | | |
596 | | | if ($this->notestext[IN] == $this->notestext[OUT]) { |
597 | | | $dirs = array(IN=>""); // only use the IN value, since they're both the same, but don't prefix the output keyword |
598 | | | } else { |
599 | | | $dirs = array( IN=>"IN", OUT=>"OUT" );// the full monty two-keyword version |
600 | | | } |
601 | | | |
602 | | | foreach ($dirs as $dir=>$tdir) { |
603 | | | if ($this->notestext[$dir] != $dd->notestext[$dir]) { |
604 | | | $output .= "\t" . $tdir . "NOTES " . $this->notestext[$dir] . "\n"; |
605 | | | } |
606 | | | } |
607 | | | |
608 | | | if ($this->overliburl[IN]==$this->overliburl[OUT]) { |
609 | | | $dirs = array(IN=>""); // only use the IN value, since they're both the same, but don't prefix the output keyword |
610 | | | } else { |
611 | | | $dirs = array( IN=>"IN", OUT=>"OUT" );// the full monty two-keyword version |
612 | | | } |
613 | | | |
614 | | | foreach ($dirs as $dir=>$tdir) { |
615 | | | if ($this->overliburl[$dir] != $dd->overliburl[$dir]) { |
616 | | | $output.="\t".$tdir."OVERLIBGRAPH " . join(" ",$this->overliburl[$dir]) . "\n"; |
617 | | | } |
618 | | | } |
619 | | | |
620 | | | // if formats have been set, but they're just the longform of the built-in styles, set them back to the built-in styles |
621 | | | if($this->labelstyle=='--' && $this->bwlabelformats[IN] == FMT_PERC_IN && $this->bwlabelformats[OUT] == FMT_PERC_OUT) |
622 | | | { |
623 | | | $this->labelstyle = 'percent'; |
624 | | | } |
625 | | | if($this->labelstyle=='--' && $this->bwlabelformats[IN] == FMT_BITS_IN && $this->bwlabelformats[OUT] == FMT_BITS_OUT) |
626 | | | { |
627 | | | $this->labelstyle = 'bits'; |
628 | | | } |
629 | | | if($this->labelstyle=='--' && $this->bwlabelformats[IN] == FMT_UNFORM_IN && $this->bwlabelformats[OUT] == FMT_UNFORM_OUT) |
630 | | | { |
631 | | | $this->labelstyle = 'unformatted'; |
632 | | | } |
633 | | | |
634 | | | // if specific formats have been set, then the style will be '--' |
635 | | | // if it isn't then use the named style |
636 | | | if ( ($this->labelstyle != $dd->labelstyle) && ($this->labelstyle != '--') ) { |
637 | | | $output .= "\tBWLABEL " . $this->labelstyle . "\n"; |
638 | | | } |
639 | | | |
640 | | | // if either IN or OUT field changes, then both must be written because a regular BWLABEL can't do it |
641 | | | // XXX this looks wrong |
642 | | | $comparison = $dd->bwlabelformats[IN]; |
643 | | | $comparison2 = $dd->bwlabelformats[OUT]; |
644 | | | |
645 | | | if ( ( $this->labelstyle == '--') && ( ($this->bwlabelformats[IN] != $comparison) || ($this->bwlabelformats[OUT]!= '--')) ) |
646 | | | { |
647 | | | $output .= "\tINBWFORMAT " . $this->bwlabelformats[IN]. "\n"; |
648 | | | $output .= "\tOUTBWFORMAT " . $this->bwlabelformats[OUT]. "\n"; |
649 | | | } |
650 | | | |
651 | | | $comparison = $dd->labeloffset_in; |
652 | | | $comparison2 = $dd->labeloffset_out; |
653 | | | |
654 | | | if ( ($this->labeloffset_in != $comparison) || ($this->labeloffset_out != $comparison2) ) |
655 | | | { $output.="\tBWLABELPOS " . $this->labeloffset_in . " " . $this->labeloffset_out . "\n"; } |
656 | | | |
657 | | | $comparison=$dd->commentoffset_in.":".$dd->commentoffset_out; |
658 | | | $mine = $this->commentoffset_in.":".$this->commentoffset_out; |
659 | | | if ($mine != $comparison) { $output.="\tCOMMENTPOS " . $this->commentoffset_in." ".$this->commentoffset_out. "\n"; } |
660 | | | |
661 | | | |
662 | | | $comparison=$dd->targets; |
663 | | | |
664 | | | if ($this->targets != $comparison) { |
665 | | | $output.="\tTARGET"; |
666 | | | |
667 | | | foreach ($this->targets as $target) { |
668 | | | if(strpos($target[4]," ") == FALSE) { |
669 | | | $output .= " " . $target[4]; |
670 | | | } else { |
671 | | | $output .= ' "' . $target[4] . '"'; |
672 | | | } |
673 | | | } |
674 | | | $output .= "\n"; |
675 | | | } |
676 | | | |
677 | | | foreach (array(IN,OUT) as $dir) { |
678 | | | if ($dir==IN) { |
679 | | | $tdir="IN"; |
680 | | | } |
681 | | | if ($dir==OUT) { |
682 | | | $tdir="OUT"; |
683 | | | } |
684 | | | |
685 | | | $comparison=$dd->comments[$dir]; |
686 | | | if ($this->comments[$dir] != $comparison) { |
687 | | | $output .= "\t" . $tdir . "COMMENT " . $this->comments[$dir] . "\n"; |
688 | | | } |
689 | | | } |
690 | | | |
691 | | | if (isset($this->a) && isset($this->b)) { |
692 | | | $output .= "\tNODES " . $this->a->name; |
693 | | | |
694 | | | if ($this->a_offset != 'C') { |
695 | | | $output .= ":" . $this->a_offset; |
696 | | | } |
697 | | | |
698 | | | $output .= " " . $this->b->name; |
699 | | | |
700 | | | if ($this->b_offset != 'C') { |
701 | | | $output .= ":" . $this->b_offset; |
702 | | | } |
703 | | | |
704 | | | $output .= "\n"; |
705 | | | } |
706 | | | |
707 | | | if (count($this->vialist) > 0) { |
708 | | | foreach ($this->vialist as $via) { |
709 | | | if( isset($via[2])) { |
710 | | | $output .= sprintf("\tVIA %s %d %d\n", $via[2],$via[0], $via[1]); |
711 | | | } else { |
712 | | | $output .= sprintf("\tVIA %d %d\n", $via[0], $via[1]); |
713 | | | } |
714 | | | } |
715 | | | } |
716 | | | |
717 | | | if (($this->max_bandwidth_in != $dd->max_bandwidth_in) |
718 | | | || ($this->max_bandwidth_out != $dd->max_bandwidth_out) |
719 | | | || ($this->name == 'DEFAULT')) |
720 | | | { |
721 | | | if ($this->max_bandwidth_in == $this->max_bandwidth_out) |
722 | | | { $output.="\tBANDWIDTH " . $this->max_bandwidth_in_cfg . "\n"; } |
723 | | | else { $output |
724 | | | .="\tBANDWIDTH " . $this->max_bandwidth_in_cfg . " " . $this->max_bandwidth_out_cfg . "\n"; } |
725 | | | } |
726 | | | |
727 | | | foreach ($this->hints as $hintname=>$hint) |
728 | | | { |
729 | | | // all hints for DEFAULT node are for writing |
730 | | | // only changed ones, or unique ones, otherwise |
731 | | | if( |
732 | | | ($this->name == 'DEFAULT') |
733 | | | || |
734 | | | (isset($dd->hints[$hintname]) |
735 | | | && |
736 | | | $dd->hints[$hintname] != $hint) |
737 | | | || |
738 | | | (!isset($dd->hints[$hintname])) |
739 | | | ) |
740 | | | { |
741 | | | $output .= "\tSET $hintname $hint\n"; |
742 | | | } |
743 | | | } |
744 | | | |
745 | | | if ($output != '') { |
746 | | | $output = "LINK " . $this->name . "\n".$output."\n"; |
747 | | | } |
748 | | | } |
749 | | | return($output); |
750 | | | } |
751 | | | |
752 | | | function asJS() |
753 | | | { |
754 | | | $js=''; |
755 | | | $js.="Links[" . js_escape($this->name) . "] = {"; |
756 | | | $js .= "\"id\":" . $this->id. ", "; |
757 | | | |
758 | | | if (isset($this->a)) |
759 | | | { |
760 | | | $js.="a:'" . $this->a->name . "', "; |
761 | | | $js.="b:'" . $this->b->name . "', "; |
762 | | | } |
763 | | | |
764 | | | $js.="width:'" . $this->width . "', "; |
765 | | | $js.="target:"; |
766 | | | |
767 | | | $tgt=''; |
768 | | | |
769 | | | foreach ($this->targets as $target) { |
770 | | | if(strpos($target[4]," ") == FALSE) { |
771 | | | $tgt .= $target[4] . ' '; |
772 | | | } else { |
773 | | | $tgt .= '"'.$target[4] . '" '; |
774 | | | } |
775 | | | } |
776 | | | |
777 | | | $js.=js_escape(trim($tgt)); |
778 | | | $js.=","; |
779 | | | |
780 | | | $js.="bw_in:" . js_escape($this->max_bandwidth_in_cfg) . ", "; |
781 | | | $js.="bw_out:" . js_escape($this->max_bandwidth_out_cfg) . ", "; |
782 | | | |
783 | | | $js.="name:" . js_escape($this->name) . ", "; |
784 | | | $js.="overlibwidth:'" . $this->overlibheight . "', "; |
785 | | | $js.="overlibheight:'" . $this->overlibwidth . "', "; |
786 | | | $js.="overlibcaption:" . js_escape($this->overlibcaption[IN]) . ", "; |
787 | | | |
788 | | | $js.="commentin:" . js_escape($this->comments[IN]) . ", "; |
789 | | | $js.="commentposin:" . intval($this->commentoffset_in) . ", "; |
790 | | | |
791 | | | $js.="commentout:" . js_escape($this->comments[OUT]) . ", "; |
792 | | | $js.="commentposout:" . intval($this->commentoffset_out) . ", "; |
793 | | | |
794 | | | $js.="infourl:" . js_escape($this->infourl[IN]) . ", "; |
795 | | | $js.="overliburl:" . js_escape(join(" ",$this->overliburl[IN])); |
796 | | | |
797 | | | $js.="};\n"; |
798 | | | $js .= "LinkIDs[\"L" . $this->id . "\"] = ". js_escape($this->name) . ";\n"; |
799 | | | return $js; |
800 | | | } |
801 | | | |
802 | | | function asJSON($complete=TRUE) |
803 | | | { |
804 | | | $js = ''; |
805 | | | $js .= "" . js_escape($this->name) . ": {"; |
806 | | | $js .= "\"id\":" . $this->id. ", "; |
807 | | | if (isset($this->a)) |
808 | | | { |
809 | | | $js.="\"a\":\"" . $this->a->name . "\", "; |
810 | | | $js.="\"b\":\"" . $this->b->name . "\", "; |
811 | | | } |
812 | | | |
813 | | | if($complete) |
814 | | | { |
815 | | | $js.="\"infourl\":" . js_escape($this->infourl) . ", "; |
816 | | | $js.="\"overliburl\":" . js_escape($this->overliburl). ", "; |
817 | | | $js.="\"width\":\"" . $this->width . "\", "; |
818 | | | $js.="\"target\":"; |
819 | | | |
820 | | | $tgt=""; |
821 | | | |
822 | | | foreach ($this->targets as $target) { $tgt.=$target[4] . " "; } |
823 | | | |
824 | | | $js.=js_escape(trim($tgt)); |
825 | | | $js.=","; |
826 | | | |
827 | | | $js.="\"bw_in\":" . js_escape($this->max_bandwidth_in_cfg) . ", "; |
828 | | | $js.="\"bw_out\":" . js_escape($this->max_bandwidth_out_cfg) . ", "; |
829 | | | |
830 | | | $js.="\"name\":" . js_escape($this->name) . ", "; |
831 | | | $js.="\"overlibwidth\":\"" . $this->overlibheight . "\", "; |
832 | | | $js.="\"overlibheight\":\"" . $this->overlibwidth . "\", "; |
833 | | | $js.="\"overlibcaption\":" . js_escape($this->overlibcaption) . ", "; |
834 | | | } |
835 | | | $vias = "\"via\": ["; |
836 | | | foreach ($this->vialist as $via) |
837 | | | $vias .= sprintf("[%d,%d,'%s'],", $via[0], $via[1],$via[2]); |
838 | | | $vias .= "],"; |
839 | | | $vias = str_replace("],],", "]]", $vias); |
840 | | | $vias = str_replace("[],", "[]", $vias); |
841 | | | $js .= $vias; |
842 | | | |
843 | | | $js.="},\n"; |
844 | | | return $js; |
845 | | | } |
846 | | | }; |
847 | | | |
848 | | | // vim:ts=4:sw=4: |
849 | | | ?> |