Rev 2431 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2431 | Rev 2432 | ||
---|---|---|---|
Line 739... | Line 739... | ||
739 | private void Window_Closed(object sender, EventArgs e) |
739 | private void Window_Closed(object sender, EventArgs e) |
740 | { |
740 | { |
741 | Application.Current.Shutdown(); |
741 | Application.Current.Shutdown(); |
742 | } |
742 | } |
Line 743... | Line 743... | ||
743 | 743 | ||
744 | #region doubletap //http://stackoverflow.com/questions/9001023/capturing-double-tap-touch-on-multi-touch-screen |
744 | #region doubletap/click //http://stackoverflow.com/questions/9001023/capturing-double-tap-touch-on-multi-touch-screen |
745 | private Point? _lastTapLocation; |
745 | private Point? _lastTapLocation; |
Line 746... | Line 746... | ||
746 | private readonly Stopwatch _doubleTapStopwatch = new Stopwatch(); |
746 | private readonly Stopwatch _doubleTapStopwatch = new Stopwatch(); |
747 | 747 | ||
Line 779... | Line 779... | ||
779 | double a = p.X - q.X; |
779 | double a = p.X - q.X; |
780 | double b = p.Y - q.Y; |
780 | double b = p.Y - q.Y; |
781 | double distance = Math.Sqrt(a * a + b * b); |
781 | double distance = Math.Sqrt(a * a + b * b); |
782 | return distance; |
782 | return distance; |
783 | } |
783 | } |
- | 784 | private bool IsDoubleClick(MouseButtonEventArgs e) |
|
- | 785 | { |
|
- | 786 | Point currentTapPosition = e.GetPosition(this); |
|
- | 787 | bool tapsAreCloseInDistance = false; |
|
- | 788 | if (_lastTapLocation != null) |
|
- | 789 | { |
|
- | 790 | tapsAreCloseInDistance = GetDistanceBetweenPoints(currentTapPosition, (Point)_lastTapLocation) < 70; |
|
- | 791 | } |
|
- | 792 | _lastTapLocation = currentTapPosition; |
|
Line -... | Line 793... | ||
- | 793 | ||
- | 794 | TimeSpan elapsed = _doubleTapStopwatch.Elapsed; |
|
- | 795 | _doubleTapStopwatch.Restart(); |
|
- | 796 | bool tapsAreCloseInTime = (elapsed != TimeSpan.Zero && elapsed < TimeSpan.FromSeconds(0.4)); |
|
- | 797 | ||
- | 798 | if (tapsAreCloseInTime && tapsAreCloseInDistance) |
|
- | 799 | { |
|
- | 800 | _lastTapLocation = null; |
|
- | 801 | } |
|
- | 802 | return tapsAreCloseInDistance && tapsAreCloseInTime; |
|
- | 803 | } |
|
- | 804 | Point pWPAdd; |
|
- | 805 | private void GridGMapControl_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) |
|
- | 806 | { |
|
- | 807 | if (IsDoubleClick(e)) |
|
- | 808 | { |
|
- | 809 | pWPAdd = new Point(e.GetPosition(this).X, e.GetPosition(this).Y); |
|
- | 810 | canvasAddPoint.Margin = new Thickness(e.GetPosition(this).X, e.GetPosition(this).Y, canvasAddPoint.Margin.Left, canvasAddPoint.Margin.Bottom); |
|
- | 811 | canvasAddPoint.Visibility = Visibility.Visible; |
|
- | 812 | } |
|
- | 813 | ||
- | 814 | } |
|
- | 815 | private void canvasAddPoint_LostFocus(object sender, RoutedEventArgs e) |
|
- | 816 | { |
|
- | 817 | canvasAddPoint.Visibility = Visibility.Collapsed; |
|
- | 818 | } |
|
- | 819 | private void canvasAddPoint_MouseLeave(object sender, MouseEventArgs e) |
|
- | 820 | { |
|
- | 821 | canvasAddPoint.Visibility = Visibility.Collapsed; |
|
- | 822 | } |
|
- | 823 | private void btnCmAddWP_Click(object sender, RoutedEventArgs e) |
|
- | 824 | { |
|
- | 825 | if (pWPAdd != null) |
|
- | 826 | { |
|
- | 827 | PointLatLng p = MainMap.FromLocalToLatLng((int)pWPAdd.X, (int)pWPAdd.Y); |
|
- | 828 | _addWP(p,0); |
|
- | 829 | } |
|
- | 830 | } |
|
- | 831 | private void btnCmAddPOI_Click(object sender, RoutedEventArgs e) |
|
- | 832 | { |
|
- | 833 | if (pWPAdd != null) |
|
- | 834 | { |
|
- | 835 | PointLatLng p = MainMap.FromLocalToLatLng((int)pWPAdd.X, (int)pWPAdd.Y); |
|
- | 836 | _addWP(p,1); |
|
- | 837 | } |
|
- | 838 | } |
|
- | 839 | private void btnCmAddFailsave_Click(object sender, RoutedEventArgs e) |
|
- | 840 | { |
|
- | 841 | if (pWPAdd != null) |
|
- | 842 | { |
|
- | 843 | PointLatLng p = MainMap.FromLocalToLatLng((int)pWPAdd.X, (int)pWPAdd.Y); |
|
- | 844 | _addWP(p,2); |
|
- | 845 | } |
|
- | 846 | } |
|
- | 847 | private void btnCmAddLanding_Click(object sender, RoutedEventArgs e) |
|
- | 848 | { |
|
- | 849 | if (pWPAdd != null) |
|
- | 850 | { |
|
- | 851 | PointLatLng p = MainMap.FromLocalToLatLng((int)pWPAdd.X, (int)pWPAdd.Y); |
|
- | 852 | _addWP(p,3); |
|
- | 853 | } |
|
- | 854 | } |
|
784 | 855 | ||
785 | #endregion doubletap |
856 | #endregion doubletap/click |
Line 786... | Line 857... | ||
786 | #endregion events |
857 | #endregion events |
Line 787... | Line 858... | ||
787 | 858 | ||
Line 4263... | Line 4334... | ||
4263 | }); |
4334 | }); |
Line 4264... | Line 4335... | ||
4264 | 4335 | ||
Line 4265... | Line 4336... | ||
4265 | } |
4336 | } |
- | 4337 | ||
- | 4338 | } |
|
- | 4339 | void _addWP(PointLatLng p,int type) |
|
- | 4340 | { |
|
- | 4341 | object[] o = new object[16]; |
|
- | 4342 | ||
- | 4343 | o[0] = dgvWP.ItemContainerGenerator.Items.Count + 1; |
|
- | 4344 | o[1] = type; |
|
- | 4345 | // cbWPEditType.SelectedIndex = 0; |
|
- | 4346 | // tbWPEditPrefix.Text = "P"; |
|
- | 4347 | o[2] = "P" + o[0].ToString(); |
|
- | 4348 | // tbWPEditLat.Text = copter.Position.Lat.ToString(); |
|
- | 4349 | o[3] = p.Lat; |
|
- | 4350 | // tbWPEditLon.Text = copter.Position.Lng.ToString(); |
|
- | 4351 | o[4] = p.Lng; |
|
- | 4352 | // tbWPEditAlt.Text = ((double)iAnalogData[4] / (double)10).ToString(); |
|
- | 4353 | o[5] = iAnalogData[4].ToString(); |
|
- | 4354 | ||
- | 4355 | // cbWPEditHeading.SelectedIndex = 2; |
|
- | 4356 | o[6] = iAnalogData[10].ToString(); |
|
- | 4357 | //tbWPEditHeading.Text = iAnalogData[10].ToString(); |
|
- | 4358 | // tbWPEditHeading.IsReadOnly = false; |
|
- | 4359 | ||
- | 4360 | // cbWPEditSpeed.SelectedIndex = 1; |
|
- | 4361 | // tbWPEditSpeed.Text = "5.0"; |
|
- | 4362 | // tbWPEditSpeed.IsReadOnly = false; |
|
- | 4363 | o[7] = "10"; |
|
- | 4364 | ||
- | 4365 | // cbWPEditClimbrate.SelectedIndex = 1; |
|
- | 4366 | // tbWPEditClimbrate.Text = "5.0"; |
|
- | 4367 | // tbWPEditClimbrate.IsReadOnly = false; |
|
- | 4368 | o[8] = "10"; |
|
- | 4369 | ||
- | 4370 | // tbWPEditRadius.Text = "10"; |
|
- | 4371 | o[9] = "5"; |
|
- | 4372 | // tbWPEditHoldtime.Text = "5"; |
|
- | 4373 | o[10] = "5"; |
|
- | 4374 | // tbWPEditAutoTrigger.Text = "0"; |
|
- | 4375 | o[11] = "0"; |
|
- | 4376 | // cbWPEditCamAngle.SelectedIndex = 1; |
|
- | 4377 | // tbWPEditCamAngle.Text = "AUTO"; |
|
Line -... | Line 4378... | ||
- | 4378 | // tbWPEditCamAngle.IsReadOnly = true; |
|
- | 4379 | o[12] = "255"; |
|
- | 4380 | ||
- | 4381 | o[13] = "0"; |
|
- | 4382 | // tbWPEditOut1.Text = "0"; |
|
- | 4383 | o[14] = "0"; |
|
- | 4384 | o[15] = "0"; |
|
- | 4385 | ||
- | 4386 | dtWaypoints.Rows.Add(o); |
|
- | 4387 | _createWP(new PointLatLng((double)o[3], (double)o[4]), (string)o[2], (int)o[1], (int)o[0] - 1); |
|
- | 4388 | // Dispatcher.Invoke(() => lblWPCount.Content = o[0].ToString()); |
|
- | 4389 | if (mRouteWP != null) |
|
- | 4390 | MainMap.Markers.Remove(mRouteWP); |
|
- | 4391 | _routeUpdate(); |
|
- | 4392 | Dispatcher.Invoke(() => |
|
- | 4393 | { |
|
- | 4394 | dgvWP.Items.Refresh(); |
|
- | 4395 | dgvWP.UpdateLayout(); |
|
- | 4396 | dgvWP.SelectedIndex = (int)o[0] - 1; |
|
4266 | 4397 | _dgvWPselectEditRow(); |
|
4267 | } |
4398 | }); |
4268 | 4399 | } |
|
4269 | /// <summary> |
4400 | /// <summary> |
4270 | /// find the index of of a wp from datatable in the waypointlist wpList |
4401 | /// find the index of of a wp from datatable in the waypointlist wpList |
Line 4620... | Line 4751... | ||
4620 | { |
4751 | { |
4621 | if (dgvWP.SelectedIndex > -1 && dgvWP.SelectedIndex < dtWaypoints.Rows.Count) |
4752 | if (dgvWP.SelectedIndex > -1 && dgvWP.SelectedIndex < dtWaypoints.Rows.Count) |
4622 | { |
4753 | { |
4623 | Dispatcher.Invoke(() => { |
4754 | Dispatcher.Invoke(() => { |
4624 | DataGridRow row; |
4755 | DataGridRow row; |
- | 4756 | dgvWP.Items.Refresh(); |
|
4625 | dgvWP.UpdateLayout(); |
4757 | dgvWP.UpdateLayout(); |
4626 | if (_wpEdit > -1 && _wpEdit < dgvWP.ItemContainerGenerator.Items.Count) |
4758 | if (_wpEdit > -1 && _wpEdit < dgvWP.ItemContainerGenerator.Items.Count) |
4627 | { |
4759 | { |
4628 | row = (DataGridRow)dgvWP.ItemContainerGenerator.ContainerFromIndex(_wpEdit); |
4760 | row = (DataGridRow)dgvWP.ItemContainerGenerator.ContainerFromIndex(_wpEdit); |
- | 4761 | if (row != null) |
|
- | 4762 | { |
|
4629 | row.Background = new SolidColorBrush(Colors.Transparent); |
4763 | row.Background = new SolidColorBrush(Colors.Transparent); |
4630 | row.BorderBrush = new SolidColorBrush(Colors.Transparent); |
4764 | row.BorderBrush = new SolidColorBrush(Colors.Transparent); |
4631 | row.BorderThickness = new Thickness(0); |
4765 | row.BorderThickness = new Thickness(0); |
- | 4766 | } |
|
4632 | } |
4767 | } |
4633 | _wpEdit = dgvWP.SelectedIndex; |
4768 | _wpEdit = dgvWP.SelectedIndex; |
4634 | row = (DataGridRow)dgvWP.ItemContainerGenerator.ContainerFromIndex(_wpEdit); |
4769 | row = (DataGridRow)dgvWP.ItemContainerGenerator.ContainerFromIndex(_wpEdit); |
- | 4770 | if (row != null) |
|
- | 4771 | { |
|
4635 | row.Background = new SolidColorBrush(Color.FromArgb(80, 0, 100, 255)); |
4772 | row.Background = new SolidColorBrush(Color.FromArgb(80, 0, 100, 255)); |
4636 | row.BorderBrush = new SolidColorBrush(Colors.Aqua); |
4773 | row.BorderBrush = new SolidColorBrush(Colors.Aqua); |
4637 | row.BorderThickness = new Thickness(2); |
4774 | row.BorderThickness = new Thickness(2); |
4638 | dgvWP.UpdateLayout(); |
4775 | dgvWP.UpdateLayout(); |
Line 4639... | Line 4776... | ||
4639 | 4776 | ||
- | 4777 | _setWPEditFields(_wpEdit); |
|
4640 | _setWPEditFields(_wpEdit); |
4778 | } |
4641 | }); |
4779 | }); |
4642 | } |
4780 | } |
4643 | } |
4781 | } |
4644 | void _setWPEditFields(int index) |
4782 | void _setWPEditFields(int index) |
Line 4837... | Line 4975... | ||
4837 | dgvWP.Items.Refresh(); |
4975 | dgvWP.Items.Refresh(); |
Line 4838... | Line 4976... | ||
4838 | 4976 | ||
Line 4839... | Line 4977... | ||
4839 | } |
4977 | } |
- | 4978 | ||
- | 4979 | } |
|
- | 4980 | private void btnEditWPAdd_Click(object sender, RoutedEventArgs e) |
|
- | 4981 | { |
|
- | 4982 | DataRow dr = dtWaypoints.NewRow(); |
|
- | 4983 | dr[0] = dtWaypoints.Rows.Count+1; |
|
- | 4984 | dr[1] = cbWPEditType.SelectedIndex; |
|
- | 4985 | dr[2] = tbWPEditPrefix.Text + dr[0].ToString(); |
|
- | 4986 | dr[3] = Convert.ToDouble(tbWPEditLat.Text.Replace('.', ',')) + 0.00000001; |
|
- | 4987 | dr[4] = Convert.ToDouble(tbWPEditLon.Text.Replace('.', ',')) + 0.00000001; |
|
- | 4988 | dr[5] = tbWPEditAlt.Text; |
|
- | 4989 | switch (cbWPEditHeading.SelectedIndex) |
|
- | 4990 | { |
|
- | 4991 | case 0: |
|
- | 4992 | dr[6] = "0"; |
|
- | 4993 | break; |
|
- | 4994 | case 1: |
|
- | 4995 | dr[6] = "-" + tbWPEditHeading.Text; |
|
- | 4996 | break; |
|
- | 4997 | case 2: |
|
- | 4998 | dr[6] = tbWPEditHeading.Text; |
|
- | 4999 | break; |
|
- | 5000 | } |
|
- | 5001 | switch (cbWPEditSpeed.SelectedIndex) |
|
- | 5002 | { |
|
- | 5003 | case 0: |
|
- | 5004 | dr[7] = "0"; |
|
- | 5005 | break; |
|
- | 5006 | case 1: |
|
- | 5007 | dr[7] = (System.Convert.ToDouble(tbWPEditSpeed.Text.Replace('.', ',')) * 10).ToString("0"); |
|
- | 5008 | break; |
|
- | 5009 | case 2: |
|
- | 5010 | dr[7] = (256 - Convert.ToInt16(tbWPEditSpeed.Text)).ToString(); |
|
- | 5011 | break; |
|
- | 5012 | } |
|
- | 5013 | switch (cbWPEditClimbrate.SelectedIndex) |
|
- | 5014 | { |
|
- | 5015 | case 0: |
|
- | 5016 | dr[8] = "255"; |
|
- | 5017 | break; |
|
- | 5018 | case 1: |
|
- | 5019 | dr[8] = (System.Convert.ToDouble(tbWPEditClimbrate.Text.Replace('.', ',')) * 10).ToString("0"); |
|
- | 5020 | break; |
|
- | 5021 | } |
|
- | 5022 | dr[9] = tbWPEditRadius.Text; |
|
- | 5023 | dr[10] = tbWPEditHoldtime.Text; |
|
- | 5024 | dr[11] = tbWPEditAutoTrigger.Text; |
|
- | 5025 | switch (cbWPEditCamAngle.SelectedIndex) |
|
- | 5026 | { |
|
- | 5027 | case 0: |
|
- | 5028 | dr[12] = "0"; |
|
- | 5029 | break; |
|
- | 5030 | case 1: |
|
- | 5031 | dr[12] = "255"; |
|
- | 5032 | break; |
|
- | 5033 | case 2: |
|
- | 5034 | dr[12] = tbWPEditCamAngle.Text; |
|
- | 5035 | break; |
|
- | 5036 | } |
|
- | 5037 | dr[13] = ""; |
|
- | 5038 | dr[14] = tbWPEditOut1.Text; |
|
- | 5039 | dr[15] = ""; |
|
- | 5040 | _createWP(new PointLatLng((double)dr[3], (double)dr[4]),(string) dr[2], (int)dr[1], (int)dr[0]); |
|
- | 5041 | if (mRouteWP != null) |
|
- | 5042 | MainMap.Markers.Remove(mRouteWP); |
|
- | 5043 | _routeUpdate(); |
|
- | 5044 | dtWaypoints.Rows.Add(dr); |
|
4840 | 5045 | dgvWP.Items.Refresh(); |
|
4841 | } |
5046 | } |
4842 | private void btnEditWPDel_Click(object sender, RoutedEventArgs e) |
5047 | private void btnEditWPDel_Click(object sender, RoutedEventArgs e) |
4843 | { |
5048 | { |
4844 | if (dgvWP.SelectedIndex > -1 && dgvWP.SelectedIndex < dtWaypoints.Rows.Count) |
5049 | if (dgvWP.SelectedIndex > -1 && dgvWP.SelectedIndex < dtWaypoints.Rows.Count) |
Line 4972... | Line 5177... | ||
4972 | } |
5177 | } |
Line 4973... | Line 5178... | ||
4973 | 5178 | ||
4974 | } |
5179 | } |
4975 | private void btnWPAddCurrentPos_Click(object sender, RoutedEventArgs e) |
5180 | private void btnWPAddCurrentPos_Click(object sender, RoutedEventArgs e) |
4976 | { |
- | |
4977 | object[] o = new object[16]; |
- | |
4978 | - | ||
4979 | o[0] = dgvWP.ItemContainerGenerator.Items.Count+1; |
- | |
4980 | o[1] = 0; |
- | |
4981 | // cbWPEditType.SelectedIndex = 0; |
- | |
4982 | // tbWPEditPrefix.Text = "P"; |
- | |
4983 | o[2] = "P" + o[0].ToString(); |
5181 | { |
4984 | // tbWPEditLat.Text = copter.Position.Lat.ToString(); |
- | |
4985 | o[3] = copter.Position.Lat; |
- | |
4986 | // tbWPEditLon.Text = copter.Position.Lng.ToString(); |
- | |
4987 | o[4] = copter.Position.Lng; |
- | |
4988 | // tbWPEditAlt.Text = ((double)iAnalogData[4] / (double)10).ToString(); |
- | |
4989 | o[5] = iAnalogData[4].ToString(); |
- | |
4990 | - | ||
4991 | // cbWPEditHeading.SelectedIndex = 2; |
- | |
4992 | o[6] = tbWPEditHeading.Text = iAnalogData[10].ToString(); |
- | |
4993 | // tbWPEditHeading.IsReadOnly = false; |
- | |
4994 | - | ||
4995 | // cbWPEditSpeed.SelectedIndex = 1; |
- | |
4996 | // tbWPEditSpeed.Text = "5.0"; |
- | |
4997 | // tbWPEditSpeed.IsReadOnly = false; |
- | |
4998 | o[7] = "10"; |
- | |
4999 | - | ||
5000 | // cbWPEditClimbrate.SelectedIndex = 1; |
- | |
5001 | // tbWPEditClimbrate.Text = "5.0"; |
- | |
5002 | // tbWPEditClimbrate.IsReadOnly = false; |
- | |
5003 | o[8] = "10"; |
- | |
5004 | - | ||
5005 | // tbWPEditRadius.Text = "10"; |
- | |
5006 | o[9] = "5"; |
- | |
5007 | // tbWPEditHoldtime.Text = "5"; |
- | |
5008 | o[10] = "5"; |
- | |
5009 | // tbWPEditAutoTrigger.Text = "0"; |
- | |
5010 | o[11] = "0"; |
- | |
5011 | // cbWPEditCamAngle.SelectedIndex = 1; |
- | |
5012 | // tbWPEditCamAngle.Text = "AUTO"; |
- | |
5013 | // tbWPEditCamAngle.IsReadOnly = true; |
- | |
5014 | o[12] = "255"; |
- | |
5015 | - | ||
5016 | o[13] = "0"; |
- | |
5017 | // tbWPEditOut1.Text = "0"; |
- | |
5018 | o[14] = "0"; |
- | |
5019 | o[15] = "0"; |
- | |
5020 | - | ||
5021 | dtWaypoints.Rows.Add(o); |
- | |
5022 | _createWP(new PointLatLng((double)o[3], (double)o[4]), (string)o[2], (int)o[1],(int)o[0]-1); |
- | |
5023 | Dispatcher.Invoke(() => lblWPCount.Content = o[0].ToString()); |
- | |
5024 | if (mRouteWP != null) |
- | |
5025 | MainMap.Markers.Remove(mRouteWP); |
- | |
5026 | _routeUpdate(); |
- | |
5027 | Dispatcher.Invoke(() => { |
- | |
5028 | dgvWP.Items.Refresh(); |
- | |
5029 | dgvWP.SelectedIndex = (int)o[0] -1; |
- | |
5030 | dgvWP.UpdateLayout(); |
- | |
5031 | _dgvWPselectEditRow(); |
- | |
5032 | }); |
5182 | _addWP(new PointLatLng(copter.Position.Lat, copter.Position.Lng),0); |
Line 5033... | Line 5183... | ||
5033 | } |
5183 | } |
5034 | 5184 | ||
5035 | private void btnWPEditmoveUp_Click(object sender, RoutedEventArgs e) |
5185 | private void btnWPEditmoveUp_Click(object sender, RoutedEventArgs e) |
Line 5241... | Line 5391... | ||
5241 | myXmlTextWriter.Close(); |
5391 | myXmlTextWriter.Close(); |
5242 | } |
5392 | } |
5243 | } |
5393 | } |
5244 | } |
5394 | } |
Line 5245... | Line -... | ||
5245 | - | ||
5246 | private void Grid_TouchDown(object sender, TouchEventArgs e) |
- | |
5247 | { |
- | |
5248 | - | ||
5249 | } |
- | |
5250 | - | ||
5251 | 5395 | ||
5252 | private void btnLoadGPXLog_Click(object sender, RoutedEventArgs e) |
5396 | private void btnLoadGPXLog_Click(object sender, RoutedEventArgs e) |
5253 | { |
5397 | { |
5254 | _loadGPXLog(); |
5398 | _loadGPXLog(); |
5255 | } |
5399 | } |