Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2470 - 1
///============================================================================
2
/// MKLiveView 
3
/// Copyright © 2016 Steph
4
/// 
5
///This file is part of MKLiveView.
6
///
7
///MKLiveView is free software: you can redistribute it and/or modify
8
///it under the terms of the GNU General Public License as published by
9
///the Free Software Foundation, either version 3 of the License, or
10
///(at your option) any later version.
11
///
12
///MKLiveView is distributed in the hope that it will be useful,
13
///but WITHOUT ANY WARRANTY; without even the implied warranty of
14
///MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
///GNU General Public License for more details.
16
///
17
///You should have received a copy of the GNU General Public License
18
///along with cssRcon.  If not, see <http://www.gnu.org/licenses/>.
19
///
20
///============================================================================
21
///Credits:
22
 
23
/// radioman (http://www.codeplex.com/site/users/view/radioman)
24
/// for his really GreatMaps! (http://greatmaps.codeplex.com/)
25
///
26
/// I made some changes to the source, so You need all files from this project here in order to compile and run
27
///
28
/// JOHN C. MACDONALD at Ira A. Fulton College of Engineering and Technology
29
/// for his MIKROKOPTER SERIAL CONTROL TUTORIAL (http://hdl.lib.byu.edu/1877/2747)
30
/// and the sourcecode (http://hdl.lib.byu.edu/1877/2748)
31
/// By his work I finally managed to get the communication with the Mikrokopter controllers to run
32
/// Some of his code was used in this programm like the SimpelSerialPort class (with lots of changes)
33
/// and the FilghtControllerMessage class
34
/// 
35
///============================================================================
36
/// DISCLAIMER
37
/// ===========
38
/// 
39
/// I created this software with my best knowledge and belief.
40
/// 
41
/// IN NO EVENT, UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, 
42
/// SHALL I, OR ANY PERSON BE LIABLE FOR ANY LOSS, EXPENSE OR DAMAGE, 
43
/// OF ANY TYPE OR NATURE ARISING OUT OF THE USE OF, 
44
/// OR INABILITY TO USE THIS SOFTWARE OR PROGRAM, 
45
/// INCLUDING, BUT NOT LIMITED TO, CLAIMS, SUITS OR CAUSES OF ACTION 
46
/// INVOLVING ALLEGED INFRINGEMENT OF COPYRIGHTS, 
47
/// PATENTS, TRADEMARKS, TRADE SECRETS, OR UNFAIR COMPETITION.
48
/// 
49
/// This means: use it & have fun (but @ Your own risk...)
50
/// ===========================================================================
51
 
52
using System.Windows;
53
using System.Windows.Controls;
54
using System.Windows.Controls.Primitives;
55
using System.Windows.Input;
56
using System.Windows.Media;
57
using GMap.NET.WindowsPresentation;
58
using System.Diagnostics;
59
 
60
namespace MKLiveView.GMapCustomMarkers
61
{
62
    /// <summary>
63
    /// Interaction logic for CustomMarkerCopter.xaml
64
    /// </summary>
65
    public partial class CustomMarkerCopter
66
    {
67
        //Popup Popup;
68
        //Label Label;
69
        GMapMarker Marker;
70
        MainWindow MainWindow;
71
 
72
        public CustomMarkerCopter(MainWindow window, GMapMarker marker, string title, string sColor)
73
        {
74
            this.InitializeComponent();
75
 
76
            this.MainWindow = window;
77
            this.Marker = marker;
78
 
79
            //Popup = new Popup();
80
            //Label = new Label();
81
 
82
            this.Unloaded += new RoutedEventHandler(CustomMarkerCopter_Unloaded);
83
            this.Loaded += new RoutedEventHandler(CustomMarkerCopter_Loaded);
84
            this.SizeChanged += new SizeChangedEventHandler(CustomMarkerCopter_SizeChanged);
85
            //this.MouseEnter += new MouseEventHandler(MarkerControl_MouseEnter);
86
            //this.MouseLeave += new MouseEventHandler(MarkerControl_MouseLeave);
87
            //this.MouseMove += new MouseEventHandler(CustomMarkerCopter_MouseMove);
88
            //this.MouseLeftButtonUp += new MouseButtonEventHandler(CustomMarkerCopter_MouseLeftButtonUp);
89
            //this.MouseLeftButtonDown += new MouseButtonEventHandler(CustomMarkerCopter_MouseLeftButtonDown);
90
 
91
            //Popup.Placement = PlacementMode.Mouse;
92
            //{
93
            //   Label.Background = Brushes.Blue;
94
            //   Label.Foreground = Brushes.White;
95
            //   Label.BorderBrush = Brushes.WhiteSmoke;
96
            //   Label.BorderThickness = new Thickness(2);
97
            //   Label.Padding = new Thickness(5);
98
            //   Label.FontSize = 22;
99
            //   Label.Content = title;
100
            //}
101
            //Popup.Child = Label;
102
            lbl.Content = title;
103
        }
104
 
105
        void CustomMarkerCopter_Loaded(object sender, RoutedEventArgs e)
106
        {
107
            //if (icon.Source.CanFreeze)
108
            //{
109
            //    icon.Source.Freeze();
110
            //}
111
        }
112
 
113
        void CustomMarkerCopter_Unloaded(object sender, RoutedEventArgs e)
114
        {
115
            this.Unloaded -= new RoutedEventHandler(CustomMarkerCopter_Unloaded);
116
            this.Loaded -= new RoutedEventHandler(CustomMarkerCopter_Loaded);
117
            this.SizeChanged -= new SizeChangedEventHandler(CustomMarkerCopter_SizeChanged);
118
            //this.MouseEnter -= new MouseEventHandler(MarkerControl_MouseEnter);
119
            //this.MouseLeave -= new MouseEventHandler(MarkerControl_MouseLeave);
120
            //this.MouseMove -= new MouseEventHandler(CustomMarkerCopter_MouseMove);
121
            //this.MouseLeftButtonUp -= new MouseButtonEventHandler(CustomMarkerCopter_MouseLeftButtonUp);
122
            //this.MouseLeftButtonDown -= new MouseButtonEventHandler(CustomMarkerCopter_MouseLeftButtonDown);
123
 
124
            Marker.Shape = null;
125
            //icon.Source = null;
126
            //icon = null;
127
            //Popup = null;
128
            //Label = null;         
129
        }
130
        public double rotate
131
        {
132
            set { Rotate1.Angle = value; }
133
            get { return Rotate1.Angle; }
134
        }
135
 
136
        public void setText(string s)
137
        {
138
            lbl.Content = s;
139
        }
140
        public void setCopterColor(string sColor)
141
        {
142
            switch (sColor)
143
            {
144
                case "red":
145
                    s1.Stroke = s2.Stroke = s3.Stroke = s4.Stroke = s5.Stroke = s6.Stroke = s7.Stroke = s8.Stroke =
146
                    f1.Fill = f2.Fill = f3.Fill = f4.Fill = f5.Fill = f6.Fill = new SolidColorBrush(Colors.Red);
147
                   // icon.Source = new System.Windows.Media.Imaging.BitmapImage(new System.Uri("CopterRed.png", System.UriKind.Relative));
148
                    break;
149
                case "green":
150
                    s1.Stroke = s2.Stroke = s3.Stroke = s4.Stroke = s5.Stroke = s6.Stroke = s7.Stroke = s8.Stroke =
151
                    f1.Fill = f2.Fill = f3.Fill = f4.Fill = f5.Fill = f6.Fill = new SolidColorBrush(Colors.SpringGreen);
152
                  //  icon.Source = new System.Windows.Media.Imaging.BitmapImage(new System.Uri("CopterGreen.png", System.UriKind.Relative));
153
                    break;
154
                case "blue":
155
                  //  icon.Source = new System.Windows.Media.Imaging.BitmapImage(new System.Uri("CopterBlue.png", System.UriKind.Relative));
156
                    s1.Stroke = s2.Stroke = s3.Stroke = s4.Stroke = s5.Stroke = s6.Stroke = s7.Stroke = s8.Stroke =
157
                    f1.Fill = f2.Fill = f3.Fill = f4.Fill = f5.Fill = f6.Fill = new SolidColorBrush(Colors.Cyan);
158
                    break;
159
                case "yellow":
160
                  //  icon.Source = new System.Windows.Media.Imaging.BitmapImage(new System.Uri("CopterYellow.png", System.UriKind.Relative));
161
                    s1.Stroke = s2.Stroke = s3.Stroke = s4.Stroke = s5.Stroke = s6.Stroke = s7.Stroke = s8.Stroke =
162
                    f1.Fill = f2.Fill = f3.Fill = f4.Fill = f5.Fill = f6.Fill = new SolidColorBrush(Colors.Yellow);
163
                    break;
164
                case "pink":
165
                 //   icon.Source = new System.Windows.Media.Imaging.BitmapImage(new System.Uri("CopterPink.png", System.UriKind.Relative));
166
                    s1.Stroke = s2.Stroke = s3.Stroke = s4.Stroke = s5.Stroke = s6.Stroke = s7.Stroke = s8.Stroke =
167
                    f1.Fill = f2.Fill = f3.Fill = f4.Fill = f5.Fill = f6.Fill = new SolidColorBrush(Colors.Magenta);
168
                    break;
169
 
170
                default:
171
                    s1.Stroke = s2.Stroke = s3.Stroke = s4.Stroke = s5.Stroke = s6.Stroke = s7.Stroke = s8.Stroke =
172
                    f1.Fill = f2.Fill = f3.Fill = f4.Fill = f5.Fill = f6.Fill = new SolidColorBrush(Colors.Red);
173
                 //   icon.Source = new System.Windows.Media.Imaging.BitmapImage(new System.Uri("CopterRed.png", System.UriKind.Relative));
174
                    break;
175
            }
176
        }
177
        public void setHeadingColor(string sColor)
178
        {
179
            switch (sColor)
180
            {
181
                case "red":
182
                    f7.Fill = new SolidColorBrush(Colors.Red);
183
                    // heading.Source = new System.Windows.Media.Imaging.BitmapImage(new System.Uri("CopterHeadingRed.png", System.UriKind.Relative));
184
                    break;
185
                case "green":
186
                    f7.Fill = new SolidColorBrush(Colors.SpringGreen);
187
                  //  heading.Source = new System.Windows.Media.Imaging.BitmapImage(new System.Uri("CopterHeadingGreen.png", System.UriKind.Relative));
188
                    break;
189
                case "blue":
190
                    f7.Fill = new SolidColorBrush(Colors.Cyan);
191
                 //   heading.Source = new System.Windows.Media.Imaging.BitmapImage(new System.Uri("CopterHeadingBlue.png", System.UriKind.Relative));
192
                    break;
193
                case "yellow":
194
                    f7.Fill = new SolidColorBrush(Colors.Yellow);
195
                 //   heading.Source = new System.Windows.Media.Imaging.BitmapImage(new System.Uri("CopterHeadingYellow.png", System.UriKind.Relative));
196
                    break;
197
                case "pink":
198
                    f7.Fill = new SolidColorBrush(Colors.Magenta);
199
                 //   heading.Source = new System.Windows.Media.Imaging.BitmapImage(new System.Uri("CopterHeadingPink.png", System.UriKind.Relative));
200
                    break;
201
 
202
                default:
203
                    f7.Fill = new SolidColorBrush(Colors.Red);
204
                 //   heading.Source = new System.Windows.Media.Imaging.BitmapImage(new System.Uri("CopterHeadingRed.png", System.UriKind.Relative));
205
                    break;
206
            }
207
        }
208
        void CustomMarkerCopter_SizeChanged(object sender, SizeChangedEventArgs e)
209
        {
210
           // Marker.Offset = new Point(-e.NewSize.Width / 4, -e.NewSize.Height /2);
211
        }
212
 
213
        void CustomMarkerCopter_MouseMove(object sender, MouseEventArgs e)
214
        {
215
            if (e.LeftButton == MouseButtonState.Pressed && IsMouseCaptured)
216
            {
217
                Point p = e.GetPosition(MainWindow.MainMap);
218
                Marker.Position = MainWindow.MainMap.FromLocalToLatLng((int)(p.X), (int)(p.Y));
219
            }
220
        }
221
 
222
        void CustomMarkerCopter_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
223
        {
224
            if (!IsMouseCaptured)
225
            {
226
                Mouse.Capture(this);
227
            }
228
        }
229
 
230
        void CustomMarkerCopter_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
231
        {
232
            if (IsMouseCaptured)
233
            {
234
                Mouse.Capture(null);
235
            }
236
        }
237
 
238
        void MarkerControl_MouseLeave(object sender, MouseEventArgs e)
239
        {
240
            Marker.ZIndex -= 10000;
241
            //Popup.IsOpen = false;
242
        }
243
 
244
        void MarkerControl_MouseEnter(object sender, MouseEventArgs e)
245
        {
246
            Marker.ZIndex += 10000;
247
            //Popup.IsOpen = true;
248
        }
249
 
250
    }
251
}