Blame view

src/InputOutput/IHMImpl/Tools/IHMPlotContextFileClass.php 4.3 KB
63412837   Benjamin Renard   Retrieve plot con...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php

class IHMPlotContextFileClass {
	public static function parse($filePath) {
		if (!file_exists($filePath))
			return array("success" => false, "message" => "Cannot load plot context file");
		
		$doc = new DOMDocument("1.0", "UTF-8");
		$doc->preserveWhiteSpace = false;
		$doc->formatOutput = true;
		
		if (!$doc->load($filePath))
			return array("success" => false, "message" => "Cannot load plot context file");
		
		//<page>
		$pageNodes = $doc->getElementsByTagName('page');
		
		if ($pageNodes->length <= 0)
			return array("success" => false, "message" => "Cannot load context page node");
		
		$pageNode = $pageNodes->item(0);
		
f7e9b9f1   Benjamin Renard   Complete plot con...
23
24
		$isPortrait = $pageNode->getAttribute('portrait') == "true";
		
63412837   Benjamin Renard   Retrieve plot con...
25
26
27
		$pageContext = array(
			'startTime' => $pageNode->getAttribute('startTime'),
			'stopTime'  => $pageNode->getAttribute('stopTime'),
ef480e03   Benjamin Renard   Fix a bug in cont...
28
			'superposeMode' => ($pageNode->getAttribute('superposeMode') == "true"),
00a22067   Benjamin Renard   TT navigation
29
30
31
			'ttName' => $pageNode->getAttribute('ttName'),
			'ttIndex' => ($pageNode->getAttribute('ttIndex') == '') ? 0 : intval($pageNode->getAttribute('ttIndex')),
			'ttNbIntervals' => ($pageNode->getAttribute('ttNbIntervals') == '') ? 0 : intval($pageNode->getAttribute('ttNbIntervals')),
f7e9b9f1   Benjamin Renard   Complete plot con...
32
			'portrait'  => $isPortrait,
63412837   Benjamin Renard   Retrieve plot con...
33
			//An image rotation of 90 deg. is done after request execution if a page is in "portrait" mode
f7e9b9f1   Benjamin Renard   Complete plot con...
34
35
			'width'     => ($isPortrait ? intval($pageNode->getAttribute('height')) : intval($pageNode->getAttribute('width'))),
			'height'    => ($isPortrait ? intval($pageNode->getAttribute('width')) : intval($pageNode->getAttribute('height'))),
63412837   Benjamin Renard   Retrieve plot con...
36
37
38
			'panels'    => array()
		);
		
f7e9b9f1   Benjamin Renard   Complete plot con...
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
		//<panel>
		$panelNodes = $pageNode->getElementsByTagName('panel');
		
		foreach ($panelNodes as $panelNode)
		{
			$panelContext = array(
				'id'     => $panelNode->getAttribute('id')
			);
			
			if ($isPortrait)
			{
				$panelContext['x']      = intval($panelNode->getAttribute('y'));
				$panelContext['width']  = intval($panelNode->getAttribute('height'));
				$panelContext['height'] = intval($panelNode->getAttribute('width'));
				$panelContext['y']      = $pageContext['height'] - intval($panelNode->getAttribute('x')) - $panelContext['height'];
			}
			else
			{
				$panelContext['x']      = intval($panelNode->getAttribute('x'));
				$panelContext['height'] = intval($panelNode->getAttribute('height'));
				$panelContext['y']      = $pageContext['height'] - intval($panelNode->getAttribute('y')) - $panelContext['height'];
				$panelContext['width']  = intval($panelNode->getAttribute('width'));
			}
			
			//<plotArea>
			$plotAreaNodes = $panelNode->getElementsByTagName('plotArea');
			
			if ($plotAreaNodes->length > 0)
			{
				$panelContext['plotArea'] = array();
				$plotAreaNode = $plotAreaNodes->item(0);
			
				if ($isPortrait)
				{
					$panelContext['plotArea']['x']      = intval($plotAreaNode->getAttribute('y'));
					$panelContext['plotArea']['width']  = intval($plotAreaNode->getAttribute('height'));
					$panelContext['plotArea']['height'] = intval($plotAreaNode->getAttribute('width'));
					$panelContext['plotArea']['y']      = $pageContext['height'] - intval($plotAreaNode->getAttribute('x')) - $panelContext['plotArea']['height'];
				}
				else
				{
					$panelContext['plotArea']['x']      = intval($plotAreaNode->getAttribute('x'));
					$panelContext['plotArea']['height'] = intval($plotAreaNode->getAttribute('height'));
					$panelContext['plotArea']['y']      = $pageContext['height'] - intval($plotAreaNode->getAttribute('y')) - $panelContext['plotArea']['height'];
					$panelContext['plotArea']['width']  = intval($plotAreaNode->getAttribute('width'));
				}
				
05da1b4d   Benjamin Renard   Draw instant plot...
86
87
88
				//hasSpectro
				$panelContext['plotArea']['hasSpectro']  = ($plotAreaNode->getAttribute('hasSpectro') == "true");
				
f7e9b9f1   Benjamin Renard   Complete plot con...
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
				//<axis>
				$panelContext['plotArea']['axes'] = array();
				
				$axisNodes = $plotAreaNode->getElementsByTagName('axis');
				
				foreach($axisNodes as $axisNode)
				{
					$axisContext = array(
							'id' => $axisNode->getAttribute('id'),
							'logarithmic' => ($axisNode->getAttribute('logarithmic') == "true"),
							'min' => floatval($axisNode->getAttribute('min')),
							'max' => floatval($axisNode->getAttribute('max'))
					);
					
					$panelContext['plotArea']['axes'][] = $axisContext;
				}
			}
			
			$pageContext['panels'][] = $panelContext;
		}
		
63412837   Benjamin Renard   Retrieve plot con...
110
111
112
113
114
		return array("success" => true, "page" => $pageContext);
	}
}

?>