Blame view

src/InputOutput/IHMImpl/Tools/IHMPlotContextFileClass.php 5.98 KB
63412837   Benjamin Renard   Retrieve plot con...
1
2
<?php

f514c09f   Menouar AZIB   Send Parameter's ...
3
4
5
6
class IHMPlotContextFileClass
{
	public static function parse($filePath)
	{
63412837   Benjamin Renard   Retrieve plot con...
7
8
		if (!file_exists($filePath))
			return array("success" => false, "message" => "Cannot load plot context file");
f514c09f   Menouar AZIB   Send Parameter's ...
9

63412837   Benjamin Renard   Retrieve plot con...
10
11
12
		$doc = new DOMDocument("1.0", "UTF-8");
		$doc->preserveWhiteSpace = false;
		$doc->formatOutput = true;
f514c09f   Menouar AZIB   Send Parameter's ...
13

63412837   Benjamin Renard   Retrieve plot con...
14
15
		if (!$doc->load($filePath))
			return array("success" => false, "message" => "Cannot load plot context file");
f514c09f   Menouar AZIB   Send Parameter's ...
16

63412837   Benjamin Renard   Retrieve plot con...
17
18
		//<page>
		$pageNodes = $doc->getElementsByTagName('page');
f514c09f   Menouar AZIB   Send Parameter's ...
19

63412837   Benjamin Renard   Retrieve plot con...
20
21
		if ($pageNodes->length <= 0)
			return array("success" => false, "message" => "Cannot load context page node");
f514c09f   Menouar AZIB   Send Parameter's ...
22

63412837   Benjamin Renard   Retrieve plot con...
23
		$pageNode = $pageNodes->item(0);
f514c09f   Menouar AZIB   Send Parameter's ...
24

f7e9b9f1   Benjamin Renard   Complete plot con...
25
		$isPortrait = $pageNode->getAttribute('portrait') == "true";
f514c09f   Menouar AZIB   Send Parameter's ...
26

63412837   Benjamin Renard   Retrieve plot con...
27
28
29
		$pageContext = array(
			'startTime' => $pageNode->getAttribute('startTime'),
			'stopTime'  => $pageNode->getAttribute('stopTime'),
ef480e03   Benjamin Renard   Fix a bug in cont...
30
			'superposeMode' => ($pageNode->getAttribute('superposeMode') == "true"),
00a22067   Benjamin Renard   TT navigation
31
32
33
			'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...
34
			'portrait'  => $isPortrait,
63412837   Benjamin Renard   Retrieve plot con...
35
			//An image rotation of 90 deg. is done after request execution if a page is in "portrait" mode
f7e9b9f1   Benjamin Renard   Complete plot con...
36
37
			'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...
38
39
			'panels'    => array()
		);
f514c09f   Menouar AZIB   Send Parameter's ...
40

f7e9b9f1   Benjamin Renard   Complete plot con...
41
42
		//<panel>
		$panelNodes = $pageNode->getElementsByTagName('panel');
f514c09f   Menouar AZIB   Send Parameter's ...
43
44

		foreach ($panelNodes as $panelNode) {
f7e9b9f1   Benjamin Renard   Complete plot con...
45
46
47
			$panelContext = array(
				'id'     => $panelNode->getAttribute('id')
			);
f514c09f   Menouar AZIB   Send Parameter's ...
48
49

			if ($isPortrait) {
f7e9b9f1   Benjamin Renard   Complete plot con...
50
51
52
53
				$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'];
f514c09f   Menouar AZIB   Send Parameter's ...
54
			} else {
f7e9b9f1   Benjamin Renard   Complete plot con...
55
56
57
58
59
				$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'));
			}
b4f15874   Erdogan Furkan   Showing TT inform...
60

f514c09f   Menouar AZIB   Send Parameter's ...
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
			//Parameters
			$PARAMETERS_TAG = 'parameters';
			$parametersNodes = $panelNode->getElementsByTagName($PARAMETERS_TAG);
			$PARAMETER_TAG = 'parameter';
			if ($parametersNodes->length > 0) {
				$panelContext[$PARAMETERS_TAG] = array();
				$parametersNode = $parametersNodes->item(0);
				$items = $parametersNode->getElementsByTagName($PARAMETER_TAG);
				foreach ($items as $item) {
					$pContext = array(
						'id' => $item->getAttribute('id'),
						'MinSampling' => $item->getAttribute('MinSampling')
					);

					$panelContext[$PARAMETERS_TAG][] = $pContext;
				}
			}


b4f15874   Erdogan Furkan   Showing TT inform...
80
81
82
83
			//<intervals>
			$intervalsNodes = $panelNode->getElementsByTagName('intervals');
			if ($intervalsNodes->length > 0) {
				$panelContext['intervals'] = array();
b4f15874   Erdogan Furkan   Showing TT inform...
84

17e90e13   Erdogan Furkan   #10098 Modificati...
85
86
87
88
89
90
91
92
93
94
95
				foreach ($intervalsNodes as $intervalsNode) {
					$intervalsContext = array(
						'name' => $intervalsNode->getAttribute('name'),
						'id' => $intervalsNode->getAttribute('id'),
						'startTime' => $intervalsNode->getAttribute('startTime'),
						'stopTime'  => $intervalsNode->getAttribute('stopTime'),
						'params' => $intervalsNode->getAttribute('params')
					);

					$panelContext['intervals'][] = $intervalsContext;
				}
b4f15874   Erdogan Furkan   Showing TT inform...
96
97
			}

f7e9b9f1   Benjamin Renard   Complete plot con...
98
99
			//<plotArea>
			$plotAreaNodes = $panelNode->getElementsByTagName('plotArea');
f514c09f   Menouar AZIB   Send Parameter's ...
100
101

			if ($plotAreaNodes->length > 0) {
f7e9b9f1   Benjamin Renard   Complete plot con...
102
103
				$panelContext['plotArea'] = array();
				$plotAreaNode = $plotAreaNodes->item(0);
f514c09f   Menouar AZIB   Send Parameter's ...
104
105

				if ($isPortrait) {
f7e9b9f1   Benjamin Renard   Complete plot con...
106
107
108
109
					$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'];
f514c09f   Menouar AZIB   Send Parameter's ...
110
				} else {
f7e9b9f1   Benjamin Renard   Complete plot con...
111
112
113
114
115
					$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'));
				}
fdeea5c7   Erdogan Furkan   For Z axis values
116
117
				//BG COLOR
				$panelContext['plotArea']['plotAreaBackgroundColor'] = ($plotAreaNode->getAttribute('plotAreaBackgroundColor'));
f514c09f   Menouar AZIB   Send Parameter's ...
118

05da1b4d   Benjamin Renard   Draw instant plot...
119
120
				//hasSpectro
				$panelContext['plotArea']['hasSpectro']  = ($plotAreaNode->getAttribute('hasSpectro') == "true");
f514c09f   Menouar AZIB   Send Parameter's ...
121

f7e9b9f1   Benjamin Renard   Complete plot con...
122
123
				//<axis>
				$panelContext['plotArea']['axes'] = array();
f514c09f   Menouar AZIB   Send Parameter's ...
124

f7e9b9f1   Benjamin Renard   Complete plot con...
125
				$axisNodes = $plotAreaNode->getElementsByTagName('axis');
f514c09f   Menouar AZIB   Send Parameter's ...
126
127

				foreach ($axisNodes as $axisNode) {
f7e9b9f1   Benjamin Renard   Complete plot con...
128
					$axisContext = array(
f514c09f   Menouar AZIB   Send Parameter's ...
129
130
131
						'id' => $axisNode->getAttribute('id'),
						'logarithmic' => ($axisNode->getAttribute('logarithmic') == "true"),
						'min' => floatval($axisNode->getAttribute('min')),
fdeea5c7   Erdogan Furkan   For Z axis values
132
133
						'max' => floatval($axisNode->getAttribute('max')),
						'colorsList' => $axisNode->getAttribute('colorsList')
f7e9b9f1   Benjamin Renard   Complete plot con...
134
					);
f514c09f   Menouar AZIB   Send Parameter's ...
135

f7e9b9f1   Benjamin Renard   Complete plot con...
136
137
138
					$panelContext['plotArea']['axes'][] = $axisContext;
				}
			}
f514c09f   Menouar AZIB   Send Parameter's ...
139

f7e9b9f1   Benjamin Renard   Complete plot con...
140
141
			$pageContext['panels'][] = $panelContext;
		}
99b4e6e2   Erdogan Furkan   Done
142
143
144
145
146
147
148
149
150
151
152
153
		$instantTimeNavNodes = $pageNode->getElementsByTagName('instantTimeNav');
		foreach($instantTimeNavNodes as $instantTimeNavNode){
			if ($instantTimeNavNode != "")
			{
				$instantTimeNavContext = array(
					'prevTime' => $instantTimeNavNode->getAttribute('prevTime'),
					'nextTime' => $instantTimeNavNode->getAttribute('nextTime'),
				);
				$pageContext['instantTimeNav']= $instantTimeNavContext;
			}
			
		}
63412837   Benjamin Renard   Retrieve plot con...
154
155
156
		return array("success" => true, "page" => $pageContext);
	}
}