134 //tv.Width = this.ActualWidth - 30; |
133 //tv.Width = this.ActualWidth - 30; |
135 |
134 |
136 } |
135 } |
137 |
136 |
138 #region Timer |
137 #region Timer |
139 public void initTimer(Color col, CuttingViewModel cutVMPar) |
138 public void initTimer(Color col, Cutting cutPar) |
140 { |
139 { |
141 timer = new DispatcherTimer(); |
140 timer = new DispatcherTimer(); |
142 timer.Interval = new TimeSpan(0, 0, 0, 0, 100); |
141 timer.Interval = new TimeSpan(0, 0, 0, 0, 100); |
143 timer.Tick += new EventHandler(timer_Tick); |
142 timer.Tick += new EventHandler(timer_Tick); |
144 |
143 |
145 CurrentColor = col; |
144 CurrentColor = col; |
146 |
145 |
147 // DATA BINDING from the cutting sent in parameter (initialised before by the userPanel with the global project) |
146 // DATA BINDING from the cutting sent in parameter (initialised before by the userPanel with the global project) |
148 AnnotList = new List<Annotation>(); |
147 cut = cutPar; |
149 AnnotList.Add(new Annotation(0, 10, "Axe Cam 1", CurrentColor)); |
148 cut.AnnotList = new List<Annotation>(); |
150 //AnnotList.Add(new Annotation(100 - (1 * AnnotWidth), 70, "Mvt Cam 2")); |
149 cut.AnnotList.Add(new Annotation(0, 10, "Axe Cam 1", CurrentColor)); |
151 //AnnotList.Add(new Annotation(200 - (2 * AnnotWidth), 50, "Saut 3")); |
150 //cut.AnnotList.Add(new Annotation(100 - (1 * AnnotWidth), 70, "Mvt Cam 2")); |
152 //AnnotList.Add(new Annotation(100 - (3 * AnnotWidth), 20, "Saut 4")); |
151 //cut.AnnotList.Add(new Annotation(200 - (2 * AnnotWidth), 50, "Saut 3")); |
153 //AnnotList.Add(new Annotation(120 - (4 * AnnotWidth), 50, "Saut 5")); |
152 //cut.AnnotList.Add(new Annotation(100 - (3 * AnnotWidth), 20, "Saut 4")); |
154 CuttingVM = new CuttingViewModel(new Cutting(cutVMPar.Title, AnnotList), AnnotWidth); |
153 //cut.AnnotList.Add(new Annotation(120 - (4 * AnnotWidth), 50, "Saut 5")); |
155 cutVMPar = CuttingVM; |
154 //cut.AnnotList = AnnotList; |
156 tv.DataContext = CuttingVM; |
155 tv.DataContext = new CuttingViewModel(cut, AnnotWidth); |
157 |
156 |
158 } |
157 } |
159 |
158 |
160 public void timerStart() |
159 public void timerStart() |
161 { |
160 { |
227 } |
226 } |
228 public Boolean isAnnotationAccepted(AnnotationViewModel avm) |
227 public Boolean isAnnotationAccepted(AnnotationViewModel avm) |
229 { |
228 { |
230 Boolean annotOk = true; |
229 Boolean annotOk = true; |
231 // We check if the annotation's begin and end timecodes allow a new annotation creation |
230 // We check if the annotation's begin and end timecodes allow a new annotation creation |
232 if (CuttingVM != null && AnnotWaiting == false) |
231 if (cut != null && AnnotWaiting == false) |
233 { |
232 { |
234 foreach (Annotation a in AnnotList) |
233 foreach (Annotation a in cut.AnnotList) |
235 { |
234 { |
236 //Console.WriteLine("a.TcBegin = " + a.TcBegin + ", avm.TcBegin = " + avm.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur)); |
235 //Console.WriteLine("a.TcBegin = " + a.TcBegin + ", avm.TcBegin = " + avm.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur)); |
237 // Check begin TC |
236 // Check begin TC |
238 if (a.TcBegin <= avm.TcBegin && avm.TcBegin <= (a.TcBegin + a.Dur)) |
237 if (a.TcBegin <= avm.TcBegin && avm.TcBegin <= (a.TcBegin + a.Dur)) |
239 { |
238 { |
259 public void addAnnotation(AnnotationViewModel avm) |
258 public void addAnnotation(AnnotationViewModel avm) |
260 { |
259 { |
261 //Console.WriteLine("addAnnotation = " + avm.TcBegin + ", " + avm.Dur + ", " + avm.GestureType); |
260 //Console.WriteLine("addAnnotation = " + avm.TcBegin + ", " + avm.Dur + ", " + avm.GestureType); |
262 Boolean annotOk = true; |
261 Boolean annotOk = true; |
263 // We check if the annotation's begin and end timecodes allow a new annotation creation |
262 // We check if the annotation's begin and end timecodes allow a new annotation creation |
264 if (CuttingVM != null && AnnotWaiting == false) |
263 if (cut != null && AnnotWaiting == false) |
265 { |
264 { |
266 foreach (Annotation a in AnnotList) |
265 foreach (Annotation a in cut.AnnotList) |
267 { |
266 { |
268 //Console.WriteLine("a.TcBegin = " + a.TcBegin + ", avm.TcBegin = " + avm.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur)); |
267 //Console.WriteLine("a.TcBegin = " + a.TcBegin + ", avm.TcBegin = " + avm.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur)); |
269 // Check begin TC |
268 // Check begin TC |
270 if (a.TcBegin <= avm.TcBegin && avm.TcBegin <= (a.TcBegin + a.Dur)) |
269 if (a.TcBegin <= avm.TcBegin && avm.TcBegin <= (a.TcBegin + a.Dur)) |
271 { |
270 { |
280 } |
279 } |
281 } |
280 } |
282 // If everything's fine, we create the new one |
281 // If everything's fine, we create the new one |
283 if (annotOk == true) |
282 if (annotOk == true) |
284 { |
283 { |
285 AnnotList.Add(new Annotation(avm.TcBegin, avm.Dur, avm.GestureType, avm.Color)); |
284 cut.AnnotList.Add(new Annotation(avm.TcBegin, avm.Dur, avm.GestureType, avm.Color)); |
286 CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth, tv.ScaleX); |
285 tv.DataContext = new CuttingViewModel(cut, AnnotWidth, tv.ScaleX); |
287 tv.DataContext = null; |
|
288 tv.DataContext = CuttingVM; |
|
289 AnnotWaiting = false; |
286 AnnotWaiting = false; |
290 } |
287 } |
291 |
288 |
292 } |
289 } |
293 //Raise Event to display Annotation in all Openned UserPanels |
290 //Raise Event to display Annotation in all Openned UserPanels |
298 |
295 |
299 public void startOrEndAnnotation() |
296 public void startOrEndAnnotation() |
300 { |
297 { |
301 Boolean annotOk = true; |
298 Boolean annotOk = true; |
302 // We open a new annotation |
299 // We open a new annotation |
303 if (CuttingVM != null && AnnotWaiting == false) |
300 if (cut != null && AnnotWaiting == false) |
304 { |
301 { |
305 AnnotTcBegin = (float)slider.Value / 1000; |
302 AnnotTcBegin = (float)slider.Value / 1000; |
306 |
303 |
307 // First we check if the new annotation will not cover any |
304 // First we check if the new annotation will not cover any |
308 foreach (Annotation a in AnnotList) |
305 foreach (Annotation a in cut.AnnotList) |
309 { |
306 { |
310 //Console.WriteLine("a.TcBegin = " + a.TcBegin + ", AnnotTcBegin = " + AnnotTcBegin + ", tcOut = " + (a.TcBegin + a.Dur)); |
307 //Console.WriteLine("a.TcBegin = " + a.TcBegin + ", AnnotTcBegin = " + AnnotTcBegin + ", tcOut = " + (a.TcBegin + a.Dur)); |
311 if (a.TcBegin <= AnnotTcBegin && AnnotTcBegin <= (a.TcBegin + a.Dur)) |
308 if (a.TcBegin <= AnnotTcBegin && AnnotTcBegin <= (a.TcBegin + a.Dur)) |
312 { |
309 { |
313 annotOk = false; |
310 annotOk = false; |
314 } |
311 } |
315 } |
312 } |
316 // if not, we mark the beginning |
313 // if not, we mark the beginning |
317 if (annotOk == true) |
314 if (annotOk == true) |
318 { |
315 { |
319 AnnotList.Add(new Annotation(AnnotTcBegin, 0, AnnotList.Count.ToString(), CurrentColor)); |
316 cut.AnnotList.Add(new Annotation(AnnotTcBegin, 0, cut.AnnotList.Count.ToString(), CurrentColor)); |
320 CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth, tv.ScaleX); |
317 tv.DataContext = new CuttingViewModel(cut, AnnotWidth, tv.ScaleX); |
321 tv.DataContext = null; |
|
322 tv.DataContext = CuttingVM; |
|
323 AnnotWaiting = true; |
318 AnnotWaiting = true; |
324 } |
319 } |
325 } |
320 } |
326 // We close the current opened annotation... |
321 // We close the current opened annotation... |
327 else if (CuttingVM != null && AnnotWaiting == true && (((float)slider.Value/1000)>AnnotTcBegin)) |
322 else if (cut != null && AnnotWaiting == true && (((float)slider.Value/1000)>AnnotTcBegin)) |
328 { |
323 { |
329 // ... by setting setting the good beginning and the good duration |
324 // ... by setting setting the good beginning and the good duration |
330 float currentTC = (float)slider.Value / 1000; |
325 float currentTC = (float)slider.Value / 1000; |
331 float currentDuration = currentTC - AnnotTcBegin; |
326 float currentDuration = currentTC - AnnotTcBegin; |
332 |
327 |
333 // First we check if the new annotation will not cover any (AnnotTcBegin was already checked) |
328 // First we check if the new annotation will not cover any (AnnotTcBegin was already checked) |
334 foreach (Annotation a in AnnotList) |
329 foreach (Annotation a in cut.AnnotList) |
335 { |
330 { |
336 //Console.WriteLine("a.TcBegin = " + a.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur) + ", AnnotTcBegin = " + AnnotTcBegin + ", currentTC = " + currentTC); |
331 //Console.WriteLine("a.TcBegin = " + a.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur) + ", AnnotTcBegin = " + AnnotTcBegin + ", currentTC = " + currentTC); |
337 if (a.TcBegin <= currentTC && currentTC <= (a.TcBegin + a.Dur) || (AnnotTcBegin < a.TcBegin && (a.TcBegin + a.Dur) < currentTC)) |
332 if (a.TcBegin <= currentTC && currentTC <= (a.TcBegin + a.Dur) || (AnnotTcBegin < a.TcBegin && (a.TcBegin + a.Dur) < currentTC)) |
338 { |
333 { |
339 annotOk = false; |
334 annotOk = false; |
340 } |
335 } |
341 } |
336 } |
342 |
337 |
343 if (annotOk == true) |
338 if (annotOk == true) |
344 { |
339 { |
345 AnnotList.RemoveAt(AnnotList.Count - 1); |
340 cut.AnnotList.RemoveAt(cut.AnnotList.Count - 1); |
346 AnnotList.Add(new Annotation(AnnotTcBegin, currentDuration, AnnotList.Count.ToString(), CurrentColor)); |
341 cut.AnnotList.Add(new Annotation(AnnotTcBegin, currentDuration, cut.AnnotList.Count.ToString(), CurrentColor)); |
347 CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth, tv.ScaleX); |
342 //Console.WriteLine("currentTimecode = " + AnnotTcBegin + ", curDur = " + currentDuration + ", nb = " + cut.AnnotList.Count + ", res = " + (AnnotTcBegin - (cut.AnnotList.Count * AnnotWidth))); |
348 //Console.WriteLine("currentTimecode = " + AnnotTcBegin + ", curDur = " + currentDuration + ", nb = " + AnnotList.Count + ", res = " + (AnnotTcBegin - (AnnotList.Count * AnnotWidth))); |
343 tv.DataContext = new CuttingViewModel(cut, AnnotWidth, tv.ScaleX); |
349 tv.DataContext = null; |
|
350 tv.DataContext = CuttingVM; |
|
351 AnnotWaiting = false; |
344 AnnotWaiting = false; |
352 } |
345 } |
353 //Raise Event to display Annotation in all Openned UserPanels |
346 //Raise Event to display Annotation in all Openned UserPanels |
354 if (annotOk) |
347 if (annotOk) |
355 OnSuccessAnnotation(this, new EventArgs()); |
348 OnSuccessAnnotation(this, new EventArgs()); |
425 } |
418 } |
426 |
419 |
427 private void onDragCanceled(Object sender, SurfaceDragDropEventArgs e) |
420 private void onDragCanceled(Object sender, SurfaceDragDropEventArgs e) |
428 { |
421 { |
429 // We check if the annotation is well one of the current annotations |
422 // We check if the annotation is well one of the current annotations |
430 if (CuttingVM != null) |
423 if (cut != null) |
431 { |
424 { |
432 // e.Cursor.Visual is the ContentControl, so its Content is the dragged TimelineAnnotationView |
425 // e.Cursor.Visual is the ContentControl, so its Content is the dragged TimelineAnnotationView |
433 canceledAnnotationVM = (AnnotationViewModel)((TimelineAnnotationView)((ContentControl)e.Cursor.Visual).Content).DataContext; |
426 canceledAnnotationVM = (AnnotationViewModel)((TimelineAnnotationView)((ContentControl)e.Cursor.Visual).Content).DataContext; |
434 confirmCancelPopup.Visibility = Visibility.Visible; |
427 confirmCancelPopup.Visibility = Visibility.Visible; |
435 } |
428 } |
436 } |
429 } |
437 |
430 |
438 private void confirmCancelPopup_ConfirmYesOrNo(object sender, ConfirmEventArgs e) |
431 private void confirmCancelPopup_ConfirmYesOrNo(object sender, ConfirmEventArgs e) |
439 { |
432 { |
440 // We check if the annotation is well one of the current annotations |
433 // We check if the annotation is well one of the current annotations |
441 if (CuttingVM != null && canceledAnnotationVM != null && e.Confirmed == true) |
434 if (cut != null && canceledAnnotationVM != null && e.Confirmed == true) |
442 { |
435 { |
443 foreach (Annotation a in AnnotList) |
436 foreach (Annotation a in cut.AnnotList) |
444 { |
437 { |
445 // Check begin TcBegin, duration and gesture type |
438 // Check begin TcBegin, duration and gesture type |
446 if (a.TcBegin == canceledAnnotationVM.TcBegin && a.Dur == canceledAnnotationVM.Dur && a.GestureType == canceledAnnotationVM.GestureType) |
439 if (a.TcBegin == canceledAnnotationVM.TcBegin && a.Dur == canceledAnnotationVM.Dur && a.GestureType == canceledAnnotationVM.GestureType) |
447 { |
440 { |
448 // We found the good annotation so we can remove it |
441 // We found the good annotation so we can remove it |
449 AnnotList.Remove(a); |
442 cut.AnnotList.Remove(a); |
450 // We redisplay the timeline |
443 // We redisplay the timeline |
451 CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth, tv.ScaleX); |
444 //CuttingVM.setListFromAnnotations(cut.AnnotList, AnnotWidth, tv.ScaleX); |
452 tv.DataContext = null; |
445 tv.DataContext = null; |
453 tv.DataContext = CuttingVM; |
446 tv.DataContext = new CuttingViewModel(cut, AnnotWidth, tv.ScaleX); |
454 // We close the popup and return as soon as we removed the annotation to avoid an error on AnnotList, which is just modified |
447 // We close the popup and return as soon as we removed the annotation to avoid an error on cut.AnnotList, which is just modified |
455 confirmCancelPopup.Visibility = Visibility.Hidden; |
448 confirmCancelPopup.Visibility = Visibility.Hidden; |
456 canceledAnnotationVM = null; |
449 canceledAnnotationVM = null; |
457 return; |
450 return; |
458 } |
451 } |
459 } |
452 } |