Skip to content

Commit

Permalink
Fixes #47
Browse files Browse the repository at this point in the history
  • Loading branch information
andreashuber-lawo committed Jun 16, 2017
1 parent 001d5fa commit 13ac3f5
Showing 1 changed file with 35 additions and 28 deletions.
63 changes: 35 additions & 28 deletions Lawo.EmberPlusSharp/Model/MatrixBase`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ public IReadOnlyList<MatrixLabel> Labels
/// <inheritdoc/>
public IReadOnlyList<int> Targets
{
get { return this.targets; }
private set { this.SetValue(ref this.targets, value); }
get => this.targets;
private set => this.SetSignals(ref this.targets, value, this.sources);
}

/// <inheritdoc/>
public IReadOnlyList<int> Sources
{
get { return this.sources; }
private set { this.SetValue(ref this.sources, value); }
get => this.sources;
private set => this.SetSignals(ref this.sources, value, this.targets);
}

/// <inheritdoc/>
Expand All @@ -82,12 +82,22 @@ public IReadOnlyDictionary<int, ObservableCollection<int>> Connections

private set
{
if (this.SetValue(ref this.connections, value))
this.SetValue(ref this.connections, value);

foreach (var connection in this.connections)
{
foreach (var connection in this.connections)
{
connection.Value.CollectionChanged += (s, e) => this.OnSourcesChanged(connection.Key);
}
connection.Value.CollectionChanged += (s, e) => this.OnSourcesChanged(connection.Key);
}

if (this.MaximumTotalConnects == 0)
{
this.MaximumTotalConnects =
GetMaximumTotalConnects(this.type, this.Targets.Count, this.Sources.Count);
}

if (this.MaximumConnectsPerTarget == 0)
{
this.MaximumConnectsPerTarget = this.type == MatrixType.NToN ? this.Sources.Count : 1;
}
}
}
Expand Down Expand Up @@ -120,7 +130,6 @@ internal sealed override bool WriteRequest(EmberWriter writer, IStreamedParamete
internal sealed override RetrievalState ReadContents(EmberReader reader, ElementType actualType)
{
this.AssertElementType(ElementType.Matrix, actualType);
var type = MatrixType.OneToN;
var addressingMode = MatrixAddressingMode.Linear;

while (reader.Read() && (reader.InnerNumber != InnerNumber.EndContainer))
Expand All @@ -131,7 +140,7 @@ internal sealed override RetrievalState ReadContents(EmberReader reader, Element
this.Description = reader.AssertAndReadContentsAsString();
break;
case GlowMatrixContents.Type.OuterNumber:
type = this.ReadEnum<MatrixType>(reader, GlowMatrixContents.Type.Name);
this.type = this.ReadEnum<MatrixType>(reader, GlowMatrixContents.Type.Name);
break;
case GlowMatrixContents.AddressingMode.OuterNumber:
addressingMode =
Expand Down Expand Up @@ -170,22 +179,6 @@ internal sealed override RetrievalState ReadContents(EmberReader reader, Element
}
}

if ((this.Targets != null) && (this.Sources != null))
{
this.Connections = this.Targets.ToDictionary(i => i, i => new ObservableCollection<int>());

if (this.MaximumTotalConnects == 0)
{
this.MaximumTotalConnects =
GetMaximumTotalConnects(type, this.Targets.Count, this.Sources.Count);
}

if (this.MaximumConnectsPerTarget == 0)
{
this.MaximumConnectsPerTarget = type == MatrixType.NToN ? this.Sources.Count : 1;
}
}

return this.RetrievalState;
}

Expand All @@ -207,7 +200,7 @@ internal sealed override RetrievalState ReadAdditionalField(EmberReader reader,
GlowTarget.InnerNumber,
GlowTarget.Number.OuterNumber,
GlowTarget.Number.Name);
this.Connections = this.Targets.ToDictionary(i => i, i => new ObservableCollection<int>());

break;
case GlowMatrix.Sources.OuterNumber:
reader.AssertInnerNumber(GlowSourceCollection.InnerNumber);
Expand Down Expand Up @@ -365,6 +358,7 @@ private static void Insert(ObservableCollection<int> existingSources, int[] sour
}

private readonly HashSet<int> targetsWithChangedConnections = new HashSet<int>();
private MatrixType type = MatrixType.OneToN;
private int maximumTotalConnects;
private int maximumConnectsPerTarget;
private IReadOnlyList<int> parametersLocation;
Expand Down Expand Up @@ -403,6 +397,19 @@ private enum ConnectionDisposition
Locked
}

private void SetSignals(ref IReadOnlyList<int> field, IReadOnlyList<int> signals, IReadOnlyList<int> other)
{
if (field?.SequenceEqual(signals) != true)
{
this.SetValue(ref field, signals);

if (other != null)
{
this.Connections = this.targets.ToDictionary(i => i, i => new ObservableCollection<int>());
}
}
}

private void OnSourcesChanged(int target)
{
if (!this.isProviderChangeInProgress)
Expand Down

0 comments on commit 13ac3f5

Please sign in to comment.