/// <summary> /// Clones the specified diagram. /// </summary> /// <param name="diagram">The diagram.</param> /// <returns></returns> public MarbleItemViewModel Clone(IMarbleDiagramContext diagram) { var marble = new MarbleItemViewModel(Item); var item = marble.Item; marble.MainContext = diagram.MainContext; marble.DiagramContext = diagram; marble.Color = diagram.Color; return(marble); }
/// <summary> /// Adds the specified item wrapper. /// </summary> /// <param name="itemWrapper">The item wrapper.</param> public void AppendMarble(MarbleItemViewModel itemWrapper) { #region Validation if (itemWrapper == null) { Debug.Fail("itemWrapper == null"); return; } #endregion Validation int sequence = Interlocked.Increment(ref _sequence); itemWrapper.Sequence = sequence; RawItems.AddAsync(itemWrapper); }
/// <summary> /// Appends the marble. /// </summary> /// <param name="itemWrapper">The item wrapper.</param> public void AppendMarble(MarbleItemViewModel itemWrapper) { #region Validation if (itemWrapper == null) { throw new NullReferenceException("itemWrapper"); } #endregion Validation MarbleBase item = itemWrapper.Item; if (TabKind == TabKind.Flat) { FlatItems.AddAsync(item); return; } itemWrapper.MainContext = this; #region Diagrams.AddAsync(diagram) MarbleDiagramModel diagram; if (!_marbleDiagrams.TryGetValue(item.Name, out diagram)) { diagram = new MarbleDiagramModel(item.Name, item.IndexOrder, this); if (_marbleDiagrams.TryAdd(item.Name, diagram)) { Diagrams.AddAsync(diagram); } else { diagram.Dispose(); diagram = _marbleDiagrams[item.Name]; } } #endregion // Diagrams.AddAsync(diagram) itemWrapper = itemWrapper.Clone(diagram); diagram.AppendMarble(itemWrapper); }
/// <summary> /// Translates the offset. /// </summary> /// <param name="itemWrapper">The item wrapper.</param> /// <returns></returns> public double TranslateOffset(MarbleItemViewModel itemWrapper) { #region Validation if (itemWrapper == null) { throw new NullReferenceException("itemWrapper"); } #endregion Validation MarbleBase item = itemWrapper.Item; TimeSpan offset = item.Offset; IMarbleDiagramContext diagram = itemWrapper.DiagramContext; double totalSeconds = offset.TotalSeconds; double initTimeInSeconds = _initTimeInSeconds; double totalSecondsByDiagram; if (_initTimeInSeconds == -1) { initTimeInSeconds = Interlocked.CompareExchange(ref _initTimeInSeconds, totalSeconds, -1); } totalSecondsByDiagram = diagram.GetLocalTimeInSeconds(totalSeconds); #region totalSeconds = ... (PositioningStrategy) switch (diagram.PositioningStrategy) { case MarblePositioningStrategy.GlobalTime: totalSeconds -= _initTimeInSeconds; totalSeconds = TranslateByFactor(offset, totalSeconds); break; case MarblePositioningStrategy.PrivateTime: totalSeconds = TranslateByFactor(offset, totalSecondsByDiagram); break; case MarblePositioningStrategy.Sequence: totalSeconds = itemWrapper.Sequence; break; } #endregion totalSeconds = ... (PositioningStrategy) int correction = diagram.Size + MarbleDiagramModel.DIAGRAM_WIDTH_CORRECTION; double result = totalSeconds * (itemWrapper.DiagramContext.Size * 2 + 5); if ((item.Kind == MarbleKind.OnCompleted || item.Kind == MarbleKind.OnError) && diagram.PositioningStrategy != MarblePositioningStrategy.Sequence) { result += itemWrapper.DiagramContext.Size; } double candidateWidth = result + correction; if (candidateWidth > _diagramWidth) { _diagramWidth = candidateWidth; PropertyChanged(this, new PropertyChangedEventArgs("DiagramWidth")); } return(result); }