Subversion Repositories Projects

Rev

Rev 2424 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2424 Rev 2425
Line 47... Line 47...
47
        PointLatLng end;
47
        PointLatLng end;
48
        PointLatLng pHome;
48
        PointLatLng pHome;
49
        GMapRoute mRouteWP;
49
        GMapRoute mRouteWP;
50
        GMapMarker wpActiveMarker;
50
        GMapMarker wpActiveMarker;
51
        List<PointLatLng> wpList = new List<PointLatLng>();
51
        List<PointLatLng> wpList = new List<PointLatLng>();
-
 
52
        List<int> wpOffset = new List<int>();
52
        Circle cWPBound = new Circle();
53
        Circle cWPBound = new Circle();
53
        double dWPMaxRange = 0;
54
        double dWPMaxRange = 0;
Line 54... Line 55...
54
 
55
 
55
        #region NC-Errors
56
        #region NC-Errors
Line 1927... Line 1928...
1927
            Dispatcher.Invoke((Action)(() => tbWPIndex.Text = data[48].ToString())); //Waypoint index
1928
            Dispatcher.Invoke((Action)(() => tbWPIndex.Text = data[48].ToString())); //Waypoint index
1928
            Dispatcher.Invoke((Action)(() => lblWPIndexNC.Content = data[48].ToString()));
1929
            Dispatcher.Invoke((Action)(() => lblWPIndexNC.Content = data[48].ToString()));
1929
            Dispatcher.Invoke((Action)(() => lblWPStatusIndexNC.Content = data[48].ToString()));
1930
            Dispatcher.Invoke((Action)(() => lblWPStatusIndexNC.Content = data[48].ToString()));
1930
            if(data[48] > 0 && _wpIndex != data[48] -1 && wpList.Count >= data[48] -1)
1931
            if(data[48] > 0 && _wpIndex != data[48] -1 && wpList.Count >= data[48] -1)
1931
            {
1932
            {
1932
                _setActiveWP(data[48]-1);
1933
                _setActiveWP(data[48]- 1);
1933
                if((data[67] & 2) == 2)
1934
                if((data[67] & 2) == 2)
1934
                    Dispatcher.Invoke(() => {
1935
                    Dispatcher.Invoke(() => {
1935
                        DataGridRow row;
1936
                        DataGridRow row;
1936
                        if (_wpIndex > -1)
1937
                        if (_wpIndex > -1)
1937
                        {
1938
                        {
1938
                            row = (DataGridRow)dgvWP.ItemContainerGenerator.ContainerFromIndex(_wpIndex);
1939
                            row = (DataGridRow)dgvWP.ItemContainerGenerator.ContainerFromIndex(wpOffset[_wpIndex]);
1939
                            row.Background = new SolidColorBrush(Colors.Transparent);
1940
                            row.Background = new SolidColorBrush(Colors.Transparent);
1940
                            row.BorderBrush = new SolidColorBrush(Colors.Transparent);
1941
                            row.BorderBrush = new SolidColorBrush(Colors.Transparent);
1941
                            row.BorderThickness = new Thickness(0);
1942
                            row.BorderThickness = new Thickness(0);
1942
                        }
1943
                        }
-
 
1944
 
1943
                        _wpIndex = data[48] - 1;
1945
                        _wpIndex = data[48] - 1;
1944
                        row = (DataGridRow)dgvWP.ItemContainerGenerator.ContainerFromIndex(_wpIndex);
1946
                        row = (DataGridRow)dgvWP.ItemContainerGenerator.ContainerFromIndex(wpOffset[_wpIndex]);
1945
                        row.Background = new SolidColorBrush(Color.FromArgb(80, 0, 255, 100));
1947
                        row.Background = new SolidColorBrush(Color.FromArgb(80, 0, 255, 100));
1946
                        row.BorderBrush = new SolidColorBrush(Colors.SpringGreen);
1948
                        row.BorderBrush = new SolidColorBrush(Colors.SpringGreen);
1947
                        row.BorderThickness = new Thickness(2);
1949
                        row.BorderThickness = new Thickness(2);
1948
                        dgvWP.UpdateLayout();
1950
                        dgvWP.UpdateLayout();
1949
                    });
1951
                    });
1950
                _wpIndex = data[48]-1;
1952
                _wpIndex = data[48]- 1;
1951
            }
1953
            }
1952
            else
1954
            else
1953
            {
1955
            {
1954
                if ((data[48] == 0 || wpList.Count == 0) & MainMap.Markers.Contains(wpActiveMarker))
1956
                if ((data[48] == 0 || wpList.Count == 0) & MainMap.Markers.Contains(wpActiveMarker))
1955
                {
1957
                {
Line 1957... Line 1959...
1957
                    Dispatcher.Invoke(() =>
1959
                    Dispatcher.Invoke(() =>
1958
                    {
1960
                    {
1959
                        DataGridRow row;
1961
                        DataGridRow row;
1960
                        if (_wpIndex > -1 && data[48] == 0 && wpList.Count > _wpIndex)
1962
                        if (_wpIndex > -1 && data[48] == 0 && wpList.Count > _wpIndex)
1961
                        {
1963
                        {
1962
                            row = (DataGridRow)dgvWP.ItemContainerGenerator.ContainerFromIndex(_wpIndex);
1964
                            row = (DataGridRow)dgvWP.ItemContainerGenerator.ContainerFromIndex(wpOffset[_wpIndex]);
1963
                            row.Background = new SolidColorBrush(Colors.Transparent);
1965
                            row.Background = new SolidColorBrush(Colors.Transparent);
1964
                            row.BorderBrush = new SolidColorBrush(Colors.Transparent);
1966
                            row.BorderBrush = new SolidColorBrush(Colors.Transparent);
1965
                            row.BorderThickness = new Thickness(0);
1967
                            row.BorderThickness = new Thickness(0);
1966
                            _wpIndex = -1;
1968
                            _wpIndex = -1;
1967
                        }
1969
                        }
Line 2159... Line 2161...
2159
                            if (wpActiveMarker != null)
2161
                            if (wpActiveMarker != null)
2160
                                MainMap.Markers.Remove(wpActiveMarker);
2162
                                MainMap.Markers.Remove(wpActiveMarker);
2161
                            lblWPRouteDistance.Content = "0 m";
2163
                            lblWPRouteDistance.Content = "0 m";
2162
                            dtWaypoints.Rows.Clear();
2164
                            dtWaypoints.Rows.Clear();
2163
                            _wpEdit = -1;_wpIndex = -1;
2165
                            _wpEdit = -1;_wpIndex = -1;
-
 
2166
                            wpOffset.Clear();
2164
                        });
2167
                        });
2165
                    }
2168
                    }
2166
                    DataRow dr = dtWaypoints.NewRow();
2169
                    DataRow dr = dtWaypoints.NewRow();
2167
                    dr = Waypoints.toDataRow(data, dr);
2170
                    dr = Waypoints.toDataRow(data, dr);
2168
                    dtWaypoints.Rows.Add(dr);
2171
                    dtWaypoints.Rows.Add(dr);
2169
                    _createWP(new PointLatLng((double)dr[3], (double)dr[4]), (string)dr[2], (int)dr[1]);
2172
                    _createWP(new PointLatLng((double)dr[3], (double)dr[4]), (string)dr[2], (int)dr[1],(int)data[1]-1);
2170
                    Dispatcher.Invoke(() => dgvWP.Items.Refresh());
2173
                    Dispatcher.Invoke(() => dgvWP.Items.Refresh());
2171
                    Dispatcher.Invoke(() => _iWPIndex = data[1]);
2174
                    Dispatcher.Invoke(() => _iWPIndex = data[1]);
2172
                    if (data[1] == data[0])
2175
                    if (data[1] == data[0])
2173
                    {
2176
                    {
2174
                        _bGetWP = false;
2177
                        _bGetWP = false;
Line 3485... Line 3488...
3485
                                int i;
3488
                                int i;
3486
                                NumberFormatInfo nfi = new NumberFormatInfo();
3489
                                NumberFormatInfo nfi = new NumberFormatInfo();
3487
                                nfi.NumberDecimalSeparator = ".";
3490
                                nfi.NumberDecimalSeparator = ".";
3488
                                dtWaypoints.Rows.Clear();
3491
                                dtWaypoints.Rows.Clear();
3489
                                _wpEdit = -1;_wpIndex = -1;
3492
                                _wpEdit = -1;_wpIndex = -1;
-
 
3493
                                wpOffset.Clear();
3490
                                _clearMapMarkers(typeof(CustomMarkerWP));
3494
                                _clearMapMarkers(typeof(CustomMarkerWP));
3491
                                _clearMapMarkers(typeof(CustomMarkerWPActive));
3495
                                _clearMapMarkers(typeof(CustomMarkerWPActive));
3492
                                wpList.Clear();
3496
                                wpList.Clear();
3493
                                if (mRouteWP != null)
3497
                                if (mRouteWP != null)
3494
                                    MainMap.Markers.Remove(mRouteWP);
3498
                                    MainMap.Markers.Remove(mRouteWP);
Line 3562... Line 3566...
3562
                                    i++;
3566
                                    i++;
3563
                                    o[i] = "New";
3567
                                    o[i] = "New";
Line 3564... Line 3568...
3564
 
3568
 
3565
                                    dr.ItemArray = o;
3569
                                    dr.ItemArray = o;
3566
                                    dtWaypoints.Rows.Add(dr);
3570
                                    dtWaypoints.Rows.Add(dr);
Line 3567... Line 3571...
3567
                                    _createWP(new PointLatLng((double)o[3], (double)o[4]), (string)dr[2], (int)o[1]);
3571
                                    _createWP(new PointLatLng((double)o[3], (double)o[4]), (string)dr[2], (int)o[1], (int)o[0]-1);
3568
 
3572
 
3569
                                    Dispatcher.Invoke(() => lblWPIndex.Content = k.ToString());
3573
                                    Dispatcher.Invoke(() => lblWPIndex.Content = k.ToString());
3570
                                    Dispatcher.Invoke(() => lblWPCount.Content = k.ToString());
3574
                                    Dispatcher.Invoke(() => lblWPCount.Content = k.ToString());
Line 3676... Line 3680...
3676
            });
3680
            });
Line 3677... Line 3681...
3677
 
3681
 
3678
            MapRoute mr = new MapRoute(wpList, "WPList");
3682
            MapRoute mr = new MapRoute(wpList, "WPList");
3679
            Dispatcher.Invoke(() => lblWPRouteDistance.Content = (mr.Distance * 1000).ToString("0 m"));
3683
            Dispatcher.Invoke(() => lblWPRouteDistance.Content = (mr.Distance * 1000).ToString("0 m"));
3680
        }
3684
        }
3681
        GMapMarker _createWP(PointLatLng p, string name, int type)
3685
        GMapMarker _createWP(PointLatLng p, string name, int type, int index)
3682
        {
3686
        {
3683
            GMapMarker wpMarker = new GMapMarker(p);
3687
            GMapMarker wpMarker = new GMapMarker(p);
3684
            Dispatcher.Invoke(()=>
3688
            Dispatcher.Invoke(()=>
3685
            {
3689
            {
Line 3688... Line 3692...
3688
                wpMarker.Offset = new System.Windows.Point(-11.5, -11.5);
3692
                wpMarker.Offset = new System.Windows.Point(-11.5, -11.5);
3689
                wpMarker.ZIndex = 100;
3693
                wpMarker.ZIndex = 100;
3690
                _setMarkerColor(wpMarker, type);
3694
                _setMarkerColor(wpMarker, type);
3691
                MainMap.Markers.Add(wpMarker);
3695
                MainMap.Markers.Add(wpMarker);
3692
                if (type == 0 || type == 3)
3696
                if (type == 0 || type == 3)
-
 
3697
                {
3693
                    wpList.Add(p);
3698
                    wpList.Add(p);
-
 
3699
                    wpOffset.Add(index);
-
 
3700
                }
3694
                ((CustomMarkerWP)wpMarker.Shape).positionChanged += _updateDTWPPos;
3701
                ((CustomMarkerWP)wpMarker.Shape).positionChanged += _updateDTWPPos;
3695
                ((CustomMarkerWP)wpMarker.Shape).newPosition += _updateDTWPPosFin;
3702
                ((CustomMarkerWP)wpMarker.Shape).newPosition += _updateDTWPPosFin;
3696
                ((CustomMarkerWP)wpMarker.Shape).mouseCaptured += _WPMouseCaptured;
3703
                ((CustomMarkerWP)wpMarker.Shape).mouseCaptured += _WPMouseCaptured;
3697
            });
3704
            });
3698
            return wpMarker;
3705
            return wpMarker;
Line 3743... Line 3750...
3743
                });
3750
                });
Line 3744... Line 3751...
3744
 
3751
 
Line 3745... Line 3752...
3745
            }
3752
            }
-
 
3753
 
-
 
3754
        }
-
 
3755
        /// <summary>
-
 
3756
        /// find the index of of a wp from datatable in the waypointlist wpList
-
 
3757
        /// </summary>
-
 
3758
        /// <param name="dtIndex">the index of wp in datatable (0-based)</param>
-
 
3759
        /// <returns></returns>
-
 
3760
        int _getWPIndexfromList(int dtIndex)
-
 
3761
        {
-
 
3762
            if ((int)dtWaypoints.Rows[dtIndex][1] == 0 || (int)dtWaypoints.Rows[dtIndex][1] == 3)
-
 
3763
            {
-
 
3764
                GMapMarker wp = _findWPMarker((string)dtWaypoints.Rows[dtIndex][2]);
-
 
3765
                if (wp != null)
-
 
3766
                    return wpList.IndexOf(wp.Position);
-
 
3767
            }
-
 
3768
            return -1;
-
 
3769
        }
-
 
3770
        /// <summary>
-
 
3771
        /// find the index of of a wp from datatable in the waypointlist wpList
-
 
3772
        /// </summary>
-
 
3773
        /// <param name="name">the name of the wp</param>
-
 
3774
        /// <returns></returns>
-
 
3775
        int _getWPIndexfromList(string name)
-
 
3776
        {
-
 
3777
            GMapMarker wp = _findWPMarker(name);
-
 
3778
            if ((wp != null && wp.Shape != null) && ((CustomMarkerWP)wp.Shape).WPType == 0 | ((CustomMarkerWP)wp.Shape).WPType == 3)
-
 
3779
                return wpList.IndexOf(wp.Position);
-
 
3780
            else
-
 
3781
                return -1;
-
 
3782
        }
-
 
3783
        int _getWPListOffset(int index)
-
 
3784
        {
-
 
3785
            int k = 0;
-
 
3786
            for(int i = 0; i < wpOffset.Count;i++)
-
 
3787
            {
-
 
3788
                if (wpOffset[i] <= index)
Line -... Line 3789...
-
 
3789
                    k++;
-
 
3790
            }
3746
 
3791
 
3747
        }
3792
            return k;
3748
 
3793
        }
3749
        void _setMarkerColor(GMapMarker wpMarker,int iType)
3794
        void _setMarkerColor(GMapMarker wpMarker,int iType)
3750
        {
3795
        {
Line 3919... Line 3964...
3919
            //if (wpActiveMarker != null)
3964
            //if (wpActiveMarker != null)
3920
            //    MainMap.Markers.Remove(wpActiveMarker);
3965
            //    MainMap.Markers.Remove(wpActiveMarker);
3921
            dtWaypoints.Rows.Clear();
3966
            dtWaypoints.Rows.Clear();
3922
            _wpEdit = -1;
3967
            _wpEdit = -1;
3923
            _wpIndex = -1;
3968
            _wpIndex = -1;
-
 
3969
            wpOffset.Clear();
3924
            Dispatcher.Invoke(() => dgvWP.Items.Refresh());
3970
            Dispatcher.Invoke(() => dgvWP.Items.Refresh());
3925
            Dispatcher.Invoke(() => lblWPIndex.Content = 0);
3971
            Dispatcher.Invoke(() => lblWPIndex.Content = 0);
3926
            Dispatcher.Invoke(() => lblWPCount.Content = 0);
3972
            Dispatcher.Invoke(() => lblWPCount.Content = 0);
3927
            Dispatcher.Invoke(() => lblWPRouteDistance.Content = "0 m");
3973
            Dispatcher.Invoke(() => lblWPRouteDistance.Content = "0 m");
3928
        }
3974
        }
Line 4171... Line 4217...
4171
        private void btnWPEditmoveUp_Click(object sender, RoutedEventArgs e)
4217
        private void btnWPEditmoveUp_Click(object sender, RoutedEventArgs e)
4172
        {
4218
        {
4173
            if (dgvWP.SelectedIndex > 0 && dgvWP.SelectedIndex < dtWaypoints.Rows.Count)
4219
            if (dgvWP.SelectedIndex > 0 && dgvWP.SelectedIndex < dtWaypoints.Rows.Count)
4174
            {
4220
            {
4175
                int index = dgvWP.SelectedIndex;
4221
                int index = dgvWP.SelectedIndex;
-
 
4222
                if (((int)dtWaypoints.Rows[index][1] == 0 | (int)dtWaypoints.Rows[index][1] == 3) && ((int)dtWaypoints.Rows[index - 1][1] == 0 | (int)dtWaypoints.Rows[index - 1][1] == 3))// && wpList.Count > index)
-
 
4223
                {
-
 
4224
                    PointLatLng x = new PointLatLng((double)dtWaypoints.Rows[index][3], (double)dtWaypoints.Rows[index][4]);
-
 
4225
                    int wpListIndex = wpList.IndexOf(x);
-
 
4226
                    if (wpListIndex > 0)
-
 
4227
                    {
-
 
4228
                        wpList.RemoveAt(wpListIndex);
-
 
4229
                        wpList.Insert(wpListIndex - 1, x);
-
 
4230
                        MainMap.Markers.Remove(mRouteWP);
-
 
4231
                        _routeUpdate();
-
 
4232
                    }
-
 
4233
                }
4176
                DataRow dr = dtWaypoints.Rows[index];
4234
                DataRow dr = dtWaypoints.Rows[index];
4177
                DataRow newRow = dtWaypoints.NewRow();
4235
                DataRow newRow = dtWaypoints.NewRow();
4178
                newRow.ItemArray = dr.ItemArray;
4236
                newRow.ItemArray = dr.ItemArray;
4179
                dtWaypoints.Rows.Remove(dr);
4237
                dtWaypoints.Rows.Remove(dr);
4180
                dtWaypoints.Rows.InsertAt(newRow, index - 1);
4238
                dtWaypoints.Rows.InsertAt(newRow, index - 1);
Line 4188... Line 4246...
4188
                dtWaypoints.Rows[index][2] = dtWaypoints.Rows[index][2].ToString().Substring(0, 1) + (index+1).ToString();
4246
                dtWaypoints.Rows[index][2] = dtWaypoints.Rows[index][2].ToString().Substring(0, 1) + (index+1).ToString();
4189
                ((CustomMarkerWP)m2.Shape).text.Text = dtWaypoints.Rows[index][2].ToString();
4247
                ((CustomMarkerWP)m2.Shape).text.Text = dtWaypoints.Rows[index][2].ToString();
4190
                dgvWP.Items.Refresh();
4248
                dgvWP.Items.Refresh();
4191
                dgvWP.SelectedIndex = index - 1;
4249
                dgvWP.SelectedIndex = index - 1;
4192
                _dgvWPselectEditRow();
4250
                _dgvWPselectEditRow();
4193
                if (((int)dtWaypoints.Rows[index][1] == 0 | (int)dtWaypoints.Rows[index][1] == 3) && ((int)dtWaypoints.Rows[index - 1][1] == 0 | (int)dtWaypoints.Rows[index - 1][1] == 3))// && wpList.Count > index)
4251
                if (wpOffset.Contains(index)) // calculating offset for wpList (index is 0-based - offset starts with index 1)
4194
                {
4252
                {
4195
                    PointLatLng x = new PointLatLng((double)dtWaypoints.Rows[index][3], (double)dtWaypoints.Rows[index][4]);
-
 
4196
                    int wpListIndex = wpList.IndexOf(x);
4253
                    int iOffset = wpOffset.IndexOf(index);
4197
                    if (wpListIndex > 0)
4254
                    if (iOffset > 0) // if not first element
4198
                    {
4255
                    {
-
 
4256
                        if (wpOffset[iOffset - 1] < index-1) //if previous element is not immediately before actual offset
-
 
4257
                            wpOffset[iOffset] = index-1;  //then decrease offset value by one
-
 
4258
                    }
4199
                        wpList.RemoveAt(wpListIndex);
4259
                    else
-
 
4260
                        wpOffset[iOffset] = index-1; //if first element, decrease offset by one
-
 
4261
                }
4200
                        wpList.Insert(wpListIndex - 1, x);
4262
                else //selected line is POI
-
 
4263
                {
4201
                        MainMap.Markers.Remove(mRouteWP);
4264
                    if (wpOffset.Contains(index - 1)) // if next point is WP
4202
                        _routeUpdate();
4265
                    {
-
 
4266
                        int iOffset = wpOffset.IndexOf(index - 1);
-
 
4267
                        wpOffset[iOffset] = index; //decrease linenumber of following WP
4203
                    }
4268
                    }
4204
                }
4269
                }
-
 
4270
 
4205
            }
4271
            }
4206
        }
4272
        }
Line 4207... Line 4273...
4207
 
4273
 
4208
        private void btnWPEditmoveDown_Click(object sender, RoutedEventArgs e)
4274
        private void btnWPEditmoveDown_Click(object sender, RoutedEventArgs e)
4209
        {
4275
        {
4210
            if (dgvWP.SelectedIndex > -1 && dgvWP.SelectedIndex < dtWaypoints.Rows.Count - 1)
4276
            if (dgvWP.SelectedIndex > -1 && dgvWP.SelectedIndex < dtWaypoints.Rows.Count - 1)
4211
            {
4277
            {
-
 
4278
                int index = dgvWP.SelectedIndex;
-
 
4279
                if (((int)dtWaypoints.Rows[index][1] == 0 | (int)dtWaypoints.Rows[index][1] == 3) && ((int)dtWaypoints.Rows[index+1][1] == 0 | (int)dtWaypoints.Rows[index+1][1] == 3))// && wpList.Count > index)
-
 
4280
                {
-
 
4281
                    PointLatLng x = new PointLatLng((double)dtWaypoints.Rows[index][3], (double)dtWaypoints.Rows[index][4]);
-
 
4282
                    int wpListIndex = wpList.IndexOf(x);
-
 
4283
                    if (wpListIndex > -1)
-
 
4284
                    {
-
 
4285
                        wpList.RemoveAt(wpListIndex);
-
 
4286
                        if (wpList.Count > wpListIndex)
-
 
4287
                            wpList.Insert(wpListIndex + 1, x);
-
 
4288
                        else
-
 
4289
                            wpList.Add(x);
-
 
4290
                        MainMap.Markers.Remove(mRouteWP);
-
 
4291
                        _routeUpdate();
-
 
4292
                    }
4212
                int index = dgvWP.SelectedIndex;
4293
                }
4213
                DataRow dr = dtWaypoints.Rows[index];
4294
                DataRow dr = dtWaypoints.Rows[index];
4214
                DataRow newRow = dtWaypoints.NewRow();
4295
                DataRow newRow = dtWaypoints.NewRow();
4215
                newRow.ItemArray = dr.ItemArray;
4296
                newRow.ItemArray = dr.ItemArray;
4216
                dtWaypoints.Rows.Remove(dr);
4297
                dtWaypoints.Rows.Remove(dr);
Line 4225... Line 4306...
4225
                dtWaypoints.Rows[index][2] = dtWaypoints.Rows[index][2].ToString().Substring(0, 1) + (index+1).ToString();
4306
                dtWaypoints.Rows[index][2] = dtWaypoints.Rows[index][2].ToString().Substring(0, 1) + (index+1).ToString();
4226
                ((CustomMarkerWP)m2.Shape).text.Text = dtWaypoints.Rows[index][2].ToString();
4307
                ((CustomMarkerWP)m2.Shape).text.Text = dtWaypoints.Rows[index][2].ToString();
4227
                dgvWP.Items.Refresh();
4308
                dgvWP.Items.Refresh();
4228
                dgvWP.SelectedIndex = index + 1;
4309
                dgvWP.SelectedIndex = index + 1;
4229
                _dgvWPselectEditRow();
4310
                _dgvWPselectEditRow();
4230
                if (((int)dtWaypoints.Rows[index][1] == 0 | (int)dtWaypoints.Rows[index][1] == 3) && ((int)dtWaypoints.Rows[index+1][1] == 0 | (int)dtWaypoints.Rows[index+1][1] == 3))// && wpList.Count > index)
4311
                if(wpOffset.Contains(index)) // If selected line is WP
4231
                {
4312
                {
4232
                    PointLatLng x = new PointLatLng((double)dtWaypoints.Rows[index][3], (double)dtWaypoints.Rows[index][4]);
-
 
4233
                    int wpListIndex = wpList.IndexOf(x);
4313
                    int iOffset = wpOffset.IndexOf(index);
4234
                    if (wpListIndex > -1)
4314
                    if(iOffset < wpOffset.Count -1) // if not last element
4235
                    {
4315
                    {
4236
                        wpList.RemoveAt(wpListIndex);
4316
                        if (wpOffset[iOffset + 1] > index + 1) //if next element is not immediately after actual offset
4237
                        if (wpList.Count > wpListIndex)
4317
                            wpOffset[iOffset] = index + 1;  //then increase offset value by one
4238
                            wpList.Insert(wpListIndex + 1, x);
4318
                    }
4239
                        else
4319
                    else
-
 
4320
                        wpOffset[iOffset] = index + 1; //if last element increase offset by one
-
 
4321
                }
4240
                            wpList.Add(x);
4322
                else //selected line is POI
-
 
4323
                {
4241
                        MainMap.Markers.Remove(mRouteWP);
4324
                    if (wpOffset.Contains(index + 1)) // if next point is WP
4242
                        _routeUpdate();
4325
                    {
-
 
4326
                        int iOffset = wpOffset.IndexOf(index + 1);
-
 
4327
                        wpOffset[iOffset] = index; //decrease linenumber of following WP
4243
                    }
4328
                    }
4244
                }
4329
                }
4245
            }
4330
            }
Line 4246... Line 4331...
4246
 
4331
 
Line 4258... Line 4343...
4258
                dtWaypoints.Rows[dgvWP.SelectedIndex][2] = tbWPEditPrefix.Text + (dgvWP.SelectedIndex + 1).ToString();
4343
                dtWaypoints.Rows[dgvWP.SelectedIndex][2] = tbWPEditPrefix.Text + (dgvWP.SelectedIndex + 1).ToString();
4259
                dtWaypoints.Rows[dgvWP.SelectedIndex][3] = Convert.ToDouble(tbWPEditLat.Text.Replace('.', ','));
4344
                dtWaypoints.Rows[dgvWP.SelectedIndex][3] = Convert.ToDouble(tbWPEditLat.Text.Replace('.', ','));
4260
                dtWaypoints.Rows[dgvWP.SelectedIndex][4] = Convert.ToDouble(tbWPEditLon.Text.Replace('.', ','));
4345
                dtWaypoints.Rows[dgvWP.SelectedIndex][4] = Convert.ToDouble(tbWPEditLon.Text.Replace('.', ','));
4261
                if (i > -1)
4346
                if (i > -1)
4262
                {
4347
                {
4263
                    if((int)dtWaypoints.Rows[dgvWP.SelectedIndex][1] == 0 || (int)dtWaypoints.Rows[dgvWP.SelectedIndex][1] == 3)
4348
                    if ((int)dtWaypoints.Rows[dgvWP.SelectedIndex][1] == 0 || (int)dtWaypoints.Rows[dgvWP.SelectedIndex][1] == 3)
4264
                        wpList[i] = (new PointLatLng((double)dtWaypoints.Rows[dgvWP.SelectedIndex][3], (double)dtWaypoints.Rows[dgvWP.SelectedIndex][4]));
4349
                        wpList[i] = (new PointLatLng((double)dtWaypoints.Rows[dgvWP.SelectedIndex][3], (double)dtWaypoints.Rows[dgvWP.SelectedIndex][4]));
4265
                    else
4350
                    else
-
 
4351
                    {
4266
                        wpList.Remove(pOld);
4352
                        wpList.Remove(pOld);
-
 
4353
                        wpOffset.Remove(wpOffset[i]);
-
 
4354
                    }
4267
                }
4355
                }
4268
                else
4356
                else
4269
                {
4357
                {
4270
                    if ((int)dtWaypoints.Rows[dgvWP.SelectedIndex][1] == 0 || (int)dtWaypoints.Rows[dgvWP.SelectedIndex][1] == 3)
4358
                    if ((int)dtWaypoints.Rows[dgvWP.SelectedIndex][1] == 0 || (int)dtWaypoints.Rows[dgvWP.SelectedIndex][1] == 3)
4271
                    {
4359
                    {
4272
                        int found = 0;
4360
                        int found = 0;
4273
                        for (int k = 0; k < dgvWP.SelectedIndex; k++)
4361
                        for (int k = 0; k < dgvWP.SelectedIndex; k++)
-
 
4362
                        {
4274
                            if ((int)dtWaypoints.Rows[k][1] == 0)
4363
                            if ((int)dtWaypoints.Rows[k][1] == 0 || (int)dtWaypoints.Rows[k][1] == 3)
-
 
4364
                            {
4275
                                found++;
4365
                                found++;
-
 
4366
                            }
-
 
4367
                        }
4276
                        wpList.Insert(found, new PointLatLng((double)dtWaypoints.Rows[dgvWP.SelectedIndex][3], (double)dtWaypoints.Rows[dgvWP.SelectedIndex][4]));
4368
                        wpList.Insert(found, new PointLatLng((double)dtWaypoints.Rows[dgvWP.SelectedIndex][3], (double)dtWaypoints.Rows[dgvWP.SelectedIndex][4]));
-
 
4369
                        wpOffset.Insert(found, dgvWP.SelectedIndex);
4277
                    }
4370
                    }
4278
                }
4371
                }
4279
                dtWaypoints.Rows[dgvWP.SelectedIndex][5] = tbWPEditAlt.Text;
4372
                dtWaypoints.Rows[dgvWP.SelectedIndex][5] = tbWPEditAlt.Text;
4280
                switch (cbWPEditHeading.SelectedIndex)
4373
                switch (cbWPEditHeading.SelectedIndex)
4281
                {
4374
                {
Line 4361... Line 4454...
4361
                        row.BorderBrush = new SolidColorBrush(Colors.Transparent);
4454
                        row.BorderBrush = new SolidColorBrush(Colors.Transparent);
4362
                        row.BorderThickness = new Thickness(0);
4455
                        row.BorderThickness = new Thickness(0);
4363
                    }
4456
                    }
4364
                    if ((int)dtWaypoints.Rows[index][1] == 0 || (int)dtWaypoints.Rows[index][1] == 3)
4457
                    if ((int)dtWaypoints.Rows[index][1] == 0 || (int)dtWaypoints.Rows[index][1] == 3)
4365
                        wpList.Remove(new PointLatLng((double)dtWaypoints.Rows[index][3], (double)dtWaypoints.Rows[index][4]));
4458
                        wpList.Remove(new PointLatLng((double)dtWaypoints.Rows[index][3], (double)dtWaypoints.Rows[index][4]));
-
 
4459
                    else
-
 
4460
                        wpOffset.Remove((int)dtWaypoints.Rows[index][0] + 1);
4366
                    _clearWPMarker((string)dtWaypoints.Rows[index][2]);
4461
                    _clearWPMarker((string)dtWaypoints.Rows[index][2]);
4367
                    if (wpActiveMarker != null)
4462
                    if (wpActiveMarker != null)
4368
                        MainMap.Markers.Remove(wpActiveMarker);
4463
                        MainMap.Markers.Remove(wpActiveMarker);
4369
                    dtWaypoints.Rows[index].Delete();
4464
                    dtWaypoints.Rows[index].Delete();
4370
                    _wpIndex = -1;
4465
                    _wpIndex = -1;
Line 4523... Line 4618...
4523
           //     tbWPEditOut1.Text = "0";
4618
           //     tbWPEditOut1.Text = "0";
4524
            o[14] = "0";
4619
            o[14] = "0";
4525
            o[15] = "0";
4620
            o[15] = "0";
Line 4526... Line 4621...
4526
 
4621
 
4527
            dtWaypoints.Rows.Add(o);
4622
            dtWaypoints.Rows.Add(o);
4528
            _createWP(new PointLatLng((double)o[3], (double)o[4]), (string)o[2], (int)o[1]);
4623
            _createWP(new PointLatLng((double)o[3], (double)o[4]), (string)o[2], (int)o[1],(int)o[0]-1);
4529
            Dispatcher.Invoke(() => lblWPCount.Content = o[0].ToString());
4624
            Dispatcher.Invoke(() => lblWPCount.Content = o[0].ToString());
4530
            if (mRouteWP != null)
4625
            if (mRouteWP != null)
4531
                MainMap.Markers.Remove(mRouteWP);
4626
                MainMap.Markers.Remove(mRouteWP);
4532
            _routeUpdate();
4627
            _routeUpdate();
Line 4629... Line 4724...
4629
                {
4724
                {
4630
                    myXmlTextWriter.Close();
4725
                    myXmlTextWriter.Close();
4631
                }
4726
                }
4632
            }
4727
            }
4633
        }
4728
        }
-
 
4729
 
-
 
4730
        private void Grid_TouchDown(object sender, TouchEventArgs e)
-
 
4731
        {
-
 
4732
 
-
 
4733
        }
-
 
4734
 
4634
        private void btnLoadGPXLog_Click(object sender, RoutedEventArgs e)
4735
        private void btnLoadGPXLog_Click(object sender, RoutedEventArgs e)
4635
        {
4736
        {
4636
            _loadGPXLog();
4737
            _loadGPXLog();
4637
        }
4738
        }
4638
        private void btnClearRoute_Click(object sender, RoutedEventArgs e)
4739
        private void btnClearRoute_Click(object sender, RoutedEventArgs e)
Line 4711... Line 4812...
4711
            }
4812
            }
4712
        }
4813
        }
4713
        #endregion GPX
4814
        #endregion GPX
4714
        #endregion functions
4815
        #endregion functions
4715
    }
4816
    }
-
 
4817
 
4716
     /// <summary>
4818
    /// <summary>
4717
    /// formats the wp datatable values for display in datagrid - this is bound in the datagrid as a converter
4819
    /// formats the wp datatable values for display in datagrid - this is bound in the datagrid as a converter
4718
    /// </summary>
4820
    /// </summary>
4719
    public class waypointsConverter : IValueConverter
4821
    public class waypointsConverter : IValueConverter
4720
    {
4822
    {
4721
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
4823
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
Line 4758... Line 4860...
4758
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
4860
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
4759
        {
4861
        {
4760
            throw new NotImplementedException();
4862
            throw new NotImplementedException();
4761
        }
4863
        }
4762
    }
4864
    }
4763
 
-
 
4764
    public class IniFile
4865
    public class IniFile
4765
    {
4866
    {
4766
        public string path;
4867
        public string path;
Line 4767... Line 4868...
4767
 
4868
 
Line 4813... Line 4914...
4813
            return local.Substring(0, local.Length - 1).Split('\0');
4914
            return local.Substring(0, local.Length - 1).Split('\0');
Line 4814... Line 4915...
4814
 
4915
 
4815
 
4916
 
4816
        }
-
 
4817
    }
4917
        }
4818
 
4918
    }
4819
    /// <summary>
4919
    /// <summary>
4820
    /// Selected Win AI Function Calls
4920
    /// Selected Win AI Function Calls
4821
    /// </summary>
4921
    /// </summary>