/// <summary> /// Removes any link that the given <paramref name="element"/> contains. /// </summary> /// <param name="element">The element to clean the links.</param> public void UnlinkElement(TimelineElement element) { TimelineElementLink link = this.elementLinks.Where(l => l.ElementId == element.Id).SingleOrDefault(); if (link != null) { this.elementLinks.Remove(link); link = this.elementLinks.Where(l => l.NextElementId == element.Id).SingleOrDefault(); if (link != null) { link.NextElementId = Guid.Empty; } link = this.elementLinks.Where(l => l.PreviousElementId == element.Id).SingleOrDefault(); if (link != null) { link.PreviousElementId = Guid.Empty; } this.CleanEmptyLinks(); } }
/// <summary> /// Tries to link the given <paramref name="element"/> to a next element in the timeline. /// </summary> /// <param name="element">The element being linked.</param> /// <param name="nextElement">The next element being linked to the element.</param> /// <returns>True if the link is effective;otherwise false.</returns> public bool LinkNextElement(TimelineElement element, TimelineElement nextElement) { if (element.Position + element.Duration != nextElement.Position) { // Elements are not in the correct position return(false); } var link = this.elementLinks.Where(l => l.ElementId == element.Id).SingleOrDefault(); if (link == null) { link = new TimelineElementLink(element.Id); this.elementLinks.Add(link); } link.NextElementId = nextElement.Id; link = this.elementLinks.Where(l => l.ElementId == nextElement.Id).SingleOrDefault(); if (link == null) { link = new TimelineElementLink(nextElement.Id); this.elementLinks.Add(link); } link.PreviousElementId = element.Id; this.OnElementLinked(element); return(true); }
/// <summary> /// Determines if two elements are linked or not. /// </summary> /// <param name="element">The element to verify is linked to other element.</param> /// <param name="linkedElement">The linked element to verify if is linked to the element.</param> /// <returns>True if the elements are linked;otherwise false.</returns> public bool IsElementLinkedTo(TimelineElement element, TimelineElement linkedElement) { if (element == null || linkedElement == null) { return(false); } TimelineElementLink link = this.GetElementLink(element); return(link.PreviousElementId == linkedElement.Id || link.NextElementId == linkedElement.Id); }
/// <summary> /// Looks to the first element linked starting from the given <paramref name="element"/>. /// </summary> /// <param name="element">The element to start the search.</param> /// <param name="layer">The track where the element is being searched.</param> /// <returns>The first element linked.</returns> public TimelineElement FindFirstElementLinking(TimelineElement element, Track layer) { TimelineElement firstElement = element; TimelineElementLink link = this.GetElementLink(element); TimelineElement linkedElement = layer.Shots.Where(e => e.Id == link.PreviousElementId).SingleOrDefault(); while (linkedElement != null) { firstElement = linkedElement; link = this.GetElementLink(linkedElement); linkedElement = layer.Shots.Where(e => e.Id == link.PreviousElementId).SingleOrDefault(); } return(firstElement); }