summaryrefslogtreecommitdiff
path: root/src/hmi/qml/NavigationCalculatedRoute.qml
blob: 5b4ab6d5d8b95bed551dd64564994784792289b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/**
* @licence app begin@
* SPDX-License-Identifier: MPL-2.0
*
* \copyright Copyright (C) 2013-2014, PCA Peugeot Citroen
*
* \file NavigationCalculatedRoute.qml
*
* \brief This file is part of the navigation hmi.
*
* \author Martin Schaller <martin.schaller@it-schaller.de>
* \author Philippe Colliot <philippe.colliot@mpsa.com>
*
* \version 1.1
*
* This Source Code Form is subject to the terms of the
* Mozilla Public License (MPL), v. 2.0.
* If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* For further information see http://www.genivi.org/.
*
* List of changes:
* 2014-03-05, Philippe Colliot, migration to the new HMI design
* <date>, <name>, <description of change>
*
* @licence end@
*/
import QtQuick 2.1 
import "Core"
import "Core/genivi.js" as Genivi;
import "Core/style-sheets/style-constants.js" as Constants;
import "Core/style-sheets/navigation-calculated-route-menu-css.js" as StyleSheet;
import lbs.plugin.dbusif 1.0

HMIMenu {
	id: menu
    headlineFg: "grey"
    headlineBg: "blue"
    text: Genivi.gettext("NavigationCalculatedRoute")
	next: back
    prev: show_route_in_list
	property Item routeCalculationSuccessfulSignal;
	property Item routeCalculationFailedSignal;
	property Item routeCalculationProgressUpdateSignal;
	property string routeText:" "

	DBusIf {
		id:dbusIf
	}

	function routeCalculationFailed(args)
	{
		//console.log("routeCalculationFailed:");
		//Genivi.dump("",args);

        menu.text=Genivi.gettext("CalculatedRouteFailed");
        // Tell the FSA that there's no route available
        Genivi.fuel_stop_advisor_message(dbusIf,"ReleaseRouteHandle",Genivi.g_routing_handle);
	}

	function routeCalculationProgressUpdate(args)
	{
        menu.text=Genivi.gettext("CalculatedRouteInProgress")+ " "+args[7]+"%";
	}

	function updateStartStop()
	{
		var res=Genivi.nav_message(dbusIf,"Guidance","GetGuidanceStatus",[]);
		//Genivi.dump("",res);
		if (res[0] == "uint16" && res[1] != Genivi.NAVIGATIONCORE_INACTIVE) {
            guidance_start.disabled=true;
            guidance_stop.disabled=false;
		} else {
            guidance_start.disabled=false;
            guidance_stop.disabled=true;
        }
	}

	function routeCalculationSuccessful(args)
	{
        show_route_on_map.disabled=false;
        show_route_in_list.disabled=false;
        menu.text=Genivi.gettext("NavigationCalculatedRoute");

        var para=[], pref=[];
        pref=pref.concat("uint16",Genivi.NAVIGATIONCORE_TOTAL_TIME,"uint16",Genivi.NAVIGATIONCORE_TOTAL_DISTANCE);
        para = para.concat("array",[pref]);
        var res=Genivi.routing_message_get(dbusIf,"GetRouteOverview",para);

        var i, time = 0, distance = 0;
        if (res[0] == "map") {
             for (i=0;i<res[1].length;i+=4)
            {
                if (res[1][i] == "uint16" && res[1][i+1] == Genivi.NAVIGATIONCORE_TOTAL_TIME)
                {
                    if (res[1][i+2] == "variant" && res[1][i+3][0] == "uint32")
                    {
                        time = res[1][i+3][1];
                    }
                }
                else
                {
                    if (res[1][i] == "uint16" && res[1][i+1] == Genivi.NAVIGATIONCORE_TOTAL_DISTANCE)
                    {
                        if (res[1][i+2] == "variant" && res[1][i+3][0] == "uint32")
                        {
                            distance = res[1][i+3][1];
                        }
                    }

                }
            }

            distanceValue.text =Genivi.distance(distance);
            timeValue.text= Genivi.time(time);

		} else {
			console.log("Unexpected result from GetRouteOverview:\n");
			Genivi.dump("",res);
		}
        // Give the route handle to the FSA
        Genivi.fuel_stop_advisor_message(dbusIf,"SetRouteHandle",Genivi.g_routing_handle);
		updateStartStop();
	}

	function connectSignals()
    {
        routeCalculationSuccessfulSignal=dbusIf.connect("","/org/genivi/navigationcore","org.genivi.navigationcore.Routing","RouteCalculationSuccessful",menu,"routeCalculationSuccessful");
        routeCalculationFailedSignal=dbusIf.connect("","/org/genivi/navigationcore","org.genivi.navigationcore.Routing","RouteCalculationFailed",menu,"routeCalculationFailed");
        routeCalculationProgressUpdateSignal=dbusIf.connect("","/org/genivi/navigationcore","org.genivi.navigationcore.Routing","RouteCalculationProgressUpdate",menu,"routeCalculationProgressUpdate");
    }

    function disconnectSignals()
    {
        routeCalculationSuccessfulSignal.destroy();
        routeCalculationFailedSignal.destroy();
        routeCalculationProgressUpdateSignal.destroy();
    }


    HMIBgImage {
        image:StyleSheet.navigation_calculated_route_menu_background[Constants.SOURCE];
        anchors { fill: parent; topMargin: parent.headlineHeight}

        Text {
            x:StyleSheet.guidanceTitle[Constants.X]; y:StyleSheet.guidanceTitle[Constants.Y]; width:StyleSheet.guidanceTitle[Constants.WIDTH]; height:StyleSheet.guidanceTitle[Constants.HEIGHT];color:StyleSheet.guidanceTitle[Constants.TEXTCOLOR];styleColor:StyleSheet.guidanceTitle[Constants.STYLECOLOR]; font.pixelSize:StyleSheet.guidanceTitle[Constants.PIXELSIZE];
            id:guidanceTitle;
            style: Text.Sunken;
            smooth: true
            text: Genivi.gettext("Guidance")
        }

        Text {
            x:StyleSheet.displayRouteTitle[Constants.X]; y:StyleSheet.displayRouteTitle[Constants.Y]; width:StyleSheet.displayRouteTitle[Constants.WIDTH]; height:StyleSheet.displayRouteTitle[Constants.HEIGHT];color:StyleSheet.displayRouteTitle[Constants.TEXTCOLOR];styleColor:StyleSheet.displayRouteTitle[Constants.STYLECOLOR]; font.pixelSize:StyleSheet.displayRouteTitle[Constants.PIXELSIZE];
            id:displayRouteTitle;
            style: Text.Sunken;
            smooth: true
            text: Genivi.gettext("DisplayRoute")
        }


        Text {
            x:StyleSheet.distanceTitle[Constants.X]; y:StyleSheet.distanceTitle[Constants.Y]; width:StyleSheet.distanceTitle[Constants.WIDTH]; height:StyleSheet.distanceTitle[Constants.HEIGHT];color:StyleSheet.distanceTitle[Constants.TEXTCOLOR];styleColor:StyleSheet.distanceTitle[Constants.STYLECOLOR]; font.pixelSize:StyleSheet.distanceTitle[Constants.PIXELSIZE];
            id:distanceTitle;
            style: Text.Sunken;
            smooth: true
            text: Genivi.gettext("RouteDistance")
        }

        Text {
            x:StyleSheet.distanceValue[Constants.X]; y:StyleSheet.distanceValue[Constants.Y]; width:StyleSheet.distanceValue[Constants.WIDTH]; height:StyleSheet.distanceValue[Constants.HEIGHT];color:StyleSheet.distanceValue[Constants.TEXTCOLOR];styleColor:StyleSheet.distanceValue[Constants.STYLECOLOR]; font.pixelSize:StyleSheet.distanceValue[Constants.PIXELSIZE];
            id:distanceValue
            wrapMode: Text.WordWrap
            style: Text.Sunken;
            smooth: true
        }

        Text {
            x:StyleSheet.timeTitle[Constants.X]; y:StyleSheet.timeTitle[Constants.Y]; width:StyleSheet.timeTitle[Constants.WIDTH]; height:StyleSheet.timeTitle[Constants.HEIGHT];color:StyleSheet.timeTitle[Constants.TEXTCOLOR];styleColor:StyleSheet.timeTitle[Constants.STYLECOLOR]; font.pixelSize:StyleSheet.timeTitle[Constants.PIXELSIZE];
            id:timeTitle;
            style: Text.Sunken;
            smooth: true
            text: Genivi.gettext("RouteTime")
        }

        Text {
            x:StyleSheet.timeValue[Constants.X]; y:StyleSheet.timeValue[Constants.Y]; width:StyleSheet.timeValue[Constants.WIDTH]; height:StyleSheet.timeValue[Constants.HEIGHT];color:StyleSheet.timeValue[Constants.TEXTCOLOR];styleColor:StyleSheet.timeValue[Constants.STYLECOLOR]; font.pixelSize:StyleSheet.timeValue[Constants.PIXELSIZE];
            id:timeValue
            wrapMode: Text.WordWrap
            style: Text.Sunken;
            smooth: true
        }

        StdButton {
            source:StyleSheet.show_route_on_map[Constants.SOURCE]; x:StyleSheet.show_route_on_map[Constants.X]; y:StyleSheet.show_route_on_map[Constants.Y]; width:StyleSheet.show_route_on_map[Constants.WIDTH]; height:StyleSheet.show_route_on_map[Constants.HEIGHT];
            id: show_route_on_map
            explode:false; disabled:true; next:show_route_in_list; prev:back
            onClicked: {
                disconnectSignals();
                Genivi.data["mapback"]="NavigationCalculatedRoute";
                Genivi.data["show_route_handle"]=Genivi.routing_handle(dbusIf);
                Genivi.data["zoom_route_handle"]=Genivi.routing_handle(dbusIf);
                pageOpen("NavigationBrowseMap");
            }
        }
        StdButton {
            source:StyleSheet.show_route_in_list[Constants.SOURCE]; x:StyleSheet.show_route_in_list[Constants.X]; y:StyleSheet.show_route_in_list[Constants.Y]; width:StyleSheet.show_route_in_list[Constants.WIDTH]; height:StyleSheet.show_route_in_list[Constants.HEIGHT];
            id:show_route_in_list;
            page:"NavigationRouteDescription";
            explode:false; disabled:true; next:back; prev:show_route_on_map
        }

        StdButton {
            source:StyleSheet.guidance_start[Constants.SOURCE]; x:StyleSheet.guidance_start[Constants.X]; y:StyleSheet.guidance_start[Constants.Y]; width:StyleSheet.guidance_start[Constants.WIDTH]; height:StyleSheet.guidance_start[Constants.HEIGHT];textColor:StyleSheet.startText[Constants.TEXTCOLOR]; pixelSize:StyleSheet.startText[Constants.PIXELSIZE];
            id:guidance_start; text: Genivi.gettext("On");explode:false; disabled:true; next:guidance_stop; prev:show_route_on_map
            onClicked: {
                disconnectSignals();
                Genivi.guidance_message(dbusIf,"StartGuidance",Genivi.routing_handle(dbusIf));
                Genivi.data["mapback"]="NavigationCalculatedRoute";
                Genivi.data["show_route_handle"]=Genivi.routing_handle(dbusIf);
                Genivi.data["show_current_position"]=true;
                pageOpen("NavigationBrowseMap");
            }
        }
        StdButton {
            source:StyleSheet.guidance_stop[Constants.SOURCE]; x:StyleSheet.guidance_stop[Constants.X]; y:StyleSheet.guidance_stop[Constants.Y]; width:StyleSheet.guidance_stop[Constants.WIDTH]; height:StyleSheet.guidance_stop[Constants.HEIGHT];textColor:StyleSheet.stopText[Constants.TEXTCOLOR]; pixelSize:StyleSheet.stopText[Constants.PIXELSIZE];
            id:guidance_stop;text: Genivi.gettext("Off");explode:false; disabled:true; next:show_route_on_map; prev:guidance_start
            onClicked: {
                Genivi.guidance_message(dbusIf,"StopGuidance",[]);
                guidance_start.disabled=false;
                guidance_stop.disabled=true;
            }
        }
        StdButton { source:StyleSheet.back[Constants.SOURCE]; x:StyleSheet.back[Constants.X]; y:StyleSheet.back[Constants.Y]; width:StyleSheet.back[Constants.WIDTH]; height:StyleSheet.back[Constants.HEIGHT];textColor:StyleSheet.backText[Constants.TEXTCOLOR]; pixelSize:StyleSheet.backText[Constants.PIXELSIZE];
            id:back; text: Genivi.gettext("Back"); disabled:false; next:show_route_on_map; prev:show_route_in_list;
            onClicked: {
                disconnectSignals();
                pageOpen("NavigationRoute");
            }
        }
    }

	Component.onCompleted: {
		//console.log(Genivi.data);
		connectSignals();
		if (Genivi.data["calculate_route"]) {
			Genivi.routing_message(dbusIf,"CalculateRoute",[]);
			delete(Genivi.data["calculate_route"]);
		} else {
			routeCalculationSuccessful("dummy");
		}
		updateStartStop();
	}
}