wCMF  3.6
 All Classes Namespaces Files Functions Variables Groups Pages
class.ElementImageOutputStrategy.php
Go to the documentation of this file.
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2014 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of any of the following licenses
7  * at your choice:
8  *
9  * - GNU Lesser General Public License (LGPL)
10  * http://www.gnu.org/licenses/lgpl.html
11  * - Eclipse Public License (EPL)
12  * http://www.eclipse.org/org/documents/epl-v10.php
13  *
14  * See the license.txt file distributed with this work for
15  * additional information.
16  *
17  * $Id: class.ElementImageOutputStrategy.php 1462 2014-02-04 23:52:27Z iherwig $
18  */
19 require_once(BASE."wcmf/lib/output/class.ImageOutputStrategy.php");
20 /**
21  * @class ElementImageOutputStrategy
22  * @ingroup Output
23  * @brief This OutputStrategy outputs a tree of objects into an image file. It must be configured
24  * with a map that was calculated by a LayoutVisitor.
25  *
26  * @author ingo herwig <ingo@wemove.com>
27  */
29 {
30  /**
31  * Constructor.
32  * @param format Image format name [IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP].
33  * @param file The output file name.
34  * @param map The position map provided by LayoutVisitor.
35  * @param lineType The linetype to use [LINETYPE_DIRECT|LINETYPE_ROUTED] DEFAULT LINETYPE_DIRECT.
36  * @param scale The image scale (will be xscale) DEFAULT 100.
37  * @param aspect The image aspect (aspect = xscale/yscale) DEFAULT 0.5.
38  * @param border The image border [px] DEFAULT 50.
39  * @param usemap Name of the HTML ImageMap to write to stdout ['' means no map] DEFAULT ''.
40  */
41  function ElementImageOutputStrategy($format, $file, $map, $lineType=LINETYPE_DIRECT, $scale=100, $aspect=0.5, $border=50, $usemap='')
42  {
43  ImageOutputStrategy::ImageOutputStrategy($format, $file, $map, $lineType, $scale, $aspect, $border, $usemap);
44  // define label dimensions relative to node connector position
45  $this->_labelDim['left'] = -10;
46  $this->_labelDim['top'] = -10;
47  $this->_labelDim['right'] = 80;
48  $this->_labelDim['bottom'] = 45;
49  // define text position relative to node connector position
50  $this->_textPos['left'] = -5;
51  $this->_textPos['top'] = -8;
52  }
53  /**
54  * Write the image header.
55  */
56  function writeHeader()
57  {
59  // print legend
60  $color = ImageColorAllocate($this->_img,0,150,0);
61  $this->writeFilledBorderedRect(new Position($this->_border, $this->_border, 0),
62  new Position($this->_border+10, $this->_border+10, 0), $this->_bgColor, $color);
63  ImageString($this->_img,1, $this->_border+20, $this->_border+2, "optional", $color);
64  $color = $this->_txtColor;
65  $this->writeFilledBorderedRect(new Position($this->_border, $this->_border+20, 0),
66  new Position($this->_border+10, $this->_border+30, 0), $this->_bgColor, $color);
67  ImageString($this->_img,1, $this->_border+20, $this->_border+22, "required", $color);
68  $color = ImageColorAllocate($this->_img,150,150,150);
69  for($i=2;$i>=0;$i--)
70  $this->writeFilledBorderedRect(new Position($this->_border+2*$i, $this->_border+40+2*$i, 0),
71  new Position($this->_border+10+2*$i, $this->_border+50+2*$i, 0), $this->_bgColor, $color);
72  ImageString($this->_img,1, $this->_border+20, $this->_border+42, "repetitive", $color);
73  }
74  /**
75  * Write the Nodes content.
76  * @param obj The object to write.
77  */
78  function writeObject(&$obj)
79  {
80  $properties = $obj->getValueProperties($obj->getType(), DATATYPE_ELEMENT);
81  if (!strstr($obj->getType(), '->'))
82  {
83  $smallText = $obj->getType();
84  $bigText = $properties['oid'];
85  $color = $this->_txtColor;
86  }
87  else
88  {
89  $smallText = substr ($obj->getType(), 0, strrpos ($obj->getType(), ":"));
90  $bigText = substr (strrchr ($obj->getType(), ":"), 1);
91  $color = ImageColorAllocate($this->_img,150,150,150);
92  }
93 
94  $oid = $obj->getOID();
95  $x = $this->_map[$oid]->x * $this->_xscale - $this->_labelDim['left'] + $this->_border;
96  $y = $this->_map[$oid]->y * $this->_yscale - $this->_labelDim['top'] + $this->_border;
97 
98  if ($obj->getProperty('minOccurs') == 0) // optional
99  {
100  $color = ImageColorAllocate($this->_img,0,150,0);
101  }
102 
103  // print box
104  if ($obj->getProperty('maxOccurs') == 'unbounded' || $obj->getProperty('maxOccurs') > 1) // repetitive
105  {
106  for($i=3;$i>=1;$i--)
107  $this->writeFilledBorderedRect(new Position($x + $this->_labelDim['left']+5*$i, $y + $this->_labelDim['top']+5*$i, 0),
108  new Position($x + $this->_labelDim['right']+5*$i, $y + $this->_labelDim['bottom']+5*$i, 0),
109  $this->_bgColor, $color);
110  }
111  // print label
112  $this->writeFilledBorderedRect(new Position($x + $this->_labelDim['left'], $y + $this->_labelDim['top'], 0),
113  new Position($x + $this->_labelDim['right'], $y + $this->_labelDim['bottom'], 0),
114  $this->_bgColor, $color);
115  // write text
116  ImageString($this->_img,2,
117  $x + $this->_textPos['left'],
118  $y + $this->_textPos['top'],
119  $smallText,
120  $color);
121  ImageString($this->_img,1,
122  $x + $this->_textPos['left'],
123  $y + $this->_textPos['top']+15,
124  "E: ".$properties['data_type'],
125  $color);
126  // write attribs
127  $attribs = $obj->getValueNames(DATATYPE_ATTRIBUTE);
128  $i = 0;
129  if (is_array($attribs))
130  {
131  foreach ($attribs as $attrib)
132  {
133  ImageString($this->_img,1,
134  $x + $this->_textPos['left'],
135  $y + $this->_textPos['top']+25+10*$i,
136  "A: ".$attrib,
137  $color);
138  $i++;
139  }
140  }
141  ImageString($this->_img,45,
142  $x + $this->_textPos['left']+65,
143  $y + $this->_textPos['top']+37,
144  $bigText,
145  $color);
146 
147  // draw line
148  $parent = & $obj->getParent();
149  if ($parent)
150  $this->drawConnectionLine($parent->getOID(), $oid);
151 
152  // print map
153  if ($this->_usemap != '')
154  {
155  echo '<area shape="rect" coords="'.
156  ($x + $this->_labelDim['left']).','.
157  ($y + $this->_labelDim['top']).','.
158  ($x + $this->_labelDim['right']).','.
159  ($y + $this->_labelDim['bottom'] + 8*$this->_map[$oid]->z).
160  '" onclick="javascript:alert(\'Node OID: '.$obj->getOID().'\')" alt="'.$obj->getOID().'">'."\n";
161  }
162  }
163  function writeFilledBorderedRect($topleft, $bottomright, $bgcolor, $bordercolor)
164  {
165  ImageFilledRectangle($this->_img, $topleft->x, $topleft->y, $bottomright->x, $bottomright->y, $bgcolor);
166  ImageRectangle($this->_img, $topleft->x, $topleft->y, $bottomright->x, $bottomright->y, $bordercolor);
167  }
168 }
169 ?>
170 
const DATATYPE_ATTRIBUTE
This OutputStrategy outputs a tree of objects into an image file. It must be configured with a map th...
ImageOutputStrategy($format, $file, $map, $lineType=LINETYPE_DIRECT, $scale=100, $aspect=0.5, $border=50, $usemap='')
const DATATYPE_ELEMENT
writeFilledBorderedRect($topleft, $bottomright, $bgcolor, $bordercolor)
const LINETYPE_DIRECT
This OutputStrategy outputs a tree of objects into an image file. It must be configured with a map th...
The Position class stores a coordinate tuple for use with the LayoutVisitor.
ElementImageOutputStrategy($format, $file, $map, $lineType=LINETYPE_DIRECT, $scale=100, $aspect=0.5, $border=50, $usemap='')