Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Models/Components/CustomComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public override void DrawSelection(DrawingContext ctx)
);
}

protected void AddTerminalPoints()
public override void AddTerminalPoints(bool notMode = false)
{
// Snap to multiples of Grid Spacing
Point SnapToGrid(Point pt)
Expand Down
2 changes: 1 addition & 1 deletion Models/Components/DLatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public override void DrawSelection(DrawingContext ctx)
);
}

private void AddTerminalPoints()
public override void AddTerminalPoints(bool notMode = false)
{
Point SnapToGrid(Point pt)
{
Expand Down
2 changes: 1 addition & 1 deletion Models/Components/Decoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public override void DrawSelection(DrawingContext ctx)
);
}

protected void AddTerminalPoints()
public override void AddTerminalPoints(bool notMode = false)
{
Point SnapToGrid(Point pt)
{
Expand Down
2 changes: 1 addition & 1 deletion Models/Components/Demultiplexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public override void DrawSelection(DrawingContext ctx)
}

// Layout: one data input on the left (centered vertically), selection lines at bottom, many outputs on right
protected void AddTerminalPoints()
public override void AddTerminalPoints(bool notMode = false)
{
// Helper to snap to nearest grid
Point SnapToGrid(Point pt)
Expand Down
2 changes: 1 addition & 1 deletion Models/Components/Encoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public override void DrawSelection(DrawingContext ctx)
);
}

protected void AddTerminalPoints()
public override void AddTerminalPoints(bool notMode = false)
{
Point SnapToGrid(Point pt)
{
Expand Down
2 changes: 1 addition & 1 deletion Models/Components/JKLatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public override void DrawSelection(DrawingContext ctx)
);
}

private void AddTerminalPoints()
public override void AddTerminalPoints(bool notMode = false)
{
Point SnapToGrid(Point pt)
{
Expand Down
2 changes: 1 addition & 1 deletion Models/Components/Multiplexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public override void DrawSelection(DrawingContext ctx)
}

// Inputs are on the left, output on right, selection lines at bottom
protected void AddTerminalPoints()
public override void AddTerminalPoints(bool notMode = false)
{
// Helper to snap to nearest multiple of 10
Point SnapToGrid(Point pt)
Expand Down
2 changes: 1 addition & 1 deletion Models/Components/SRLatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public override void DrawSelection(DrawingContext ctx)
);
}

private void AddTerminalPoints()
public override void AddTerminalPoints(bool notMode = false)
{
Point SnapToGrid(Point pt)
{
Expand Down
2 changes: 1 addition & 1 deletion Models/Components/TLatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public override void DrawSelection(DrawingContext ctx)
);
}

private void AddTerminalPoints()
public override void AddTerminalPoints(bool notMode = false)
{
Point SnapToGrid(Point pt)
{
Expand Down
3 changes: 0 additions & 3 deletions Models/Components/Wire.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ public Wire() : base(0, 0)
IsCommitted = false;
}

// DTO pattern for serializing



public void AddPoint(Point point)
{
Points.Add(point);
Expand Down
5 changes: 5 additions & 0 deletions Models/Core/Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public virtual bool HitTest(Point point)
return new Rect(0,0,Width,Height).Contains(point);
}

public virtual void AddTerminalPoints(bool notMode = false)
{

}

public override void Render(DrawingContext context)
{
// Applies rotation to the drawing
Expand Down
2 changes: 1 addition & 1 deletion Models/Core/Gate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public override void DrawSelection(DrawingContext ctx)

// The points are added differently for NOT-variants (NAND, NOT, NOR, XNOR)
// notMode: Extra wire length to account for the bubble
protected void AddTerminalPoints(bool notMode = false)
public override void AddTerminalPoints(bool notMode = false)
{
double spacing = Height / (InputLineCount + 1);

Expand Down
1 change: 1 addition & 0 deletions Models/DTOs/CircuitDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static List<Component> ToCircuit(CircuitDto circuit)
{
terminal.Wires = terminal.Wires.Select(w => wireDict[w.Id]).ToList();
}

}


Expand Down
11 changes: 9 additions & 2 deletions Models/DTOs/ComponentDto.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Avalonia;
using Avalonia.Controls;
using IRis.Models.Components;
using IRis.Models.Core;
Expand All @@ -8,8 +9,8 @@
namespace IRis.Models.DTOs;
public class ComponentDto
{
public string Type { get; set; }

Check warning on line 12 in Models/DTOs/ComponentDto.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Type' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 12 in Models/DTOs/ComponentDto.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Type' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 12 in Models/DTOs/ComponentDto.cs

View workflow job for this annotation

GitHub Actions / build-windows

Non-nullable property 'Type' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public List<TerminalDto> Terminals { get; set; }

Check warning on line 13 in Models/DTOs/ComponentDto.cs

View workflow job for this annotation

GitHub Actions / build-windows

Non-nullable property 'Terminals' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public int InputLineCount { get; set; }
public int SelectionLineCount { get; set; }
Expand All @@ -27,7 +28,7 @@
return new ComponentDto()
{
// Get only the type name, without the full namespace
Type = c.ToString().Split(".")[^1],

Check warning on line 31 in Models/DTOs/ComponentDto.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 31 in Models/DTOs/ComponentDto.cs

View workflow job for this annotation

GitHub Actions / build-linux

Dereference of a possibly null reference.

Check warning on line 31 in Models/DTOs/ComponentDto.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 31 in Models/DTOs/ComponentDto.cs

View workflow job for this annotation

GitHub Actions / build-linux

Dereference of a possibly null reference.

Check warning on line 31 in Models/DTOs/ComponentDto.cs

View workflow job for this annotation

GitHub Actions / build-windows

Dereference of a possibly null reference.

Check warning on line 31 in Models/DTOs/ComponentDto.cs

View workflow job for this annotation

GitHub Actions / build-windows

Dereference of a possibly null reference.

InputLineCount = c.InputLineCount,
SelectionLineCount = c.SelectionLineCount,
Expand All @@ -38,7 +39,7 @@
Y = Canvas.GetTop(c),

StoredStates = c.StoredStates,
Terminals = c.Terminals.Select(p => TerminalDto.ToDto(p)).ToList(),

Check warning on line 42 in Models/DTOs/ComponentDto.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'source' in 'IEnumerable<TerminalDto> Enumerable.Select<Terminal, TerminalDto>(IEnumerable<Terminal> source, Func<Terminal, TerminalDto> selector)'.

Check warning on line 42 in Models/DTOs/ComponentDto.cs

View workflow job for this annotation

GitHub Actions / build-linux

Possible null reference argument for parameter 'source' in 'IEnumerable<TerminalDto> Enumerable.Select<Terminal, TerminalDto>(IEnumerable<Terminal> source, Func<Terminal, TerminalDto> selector)'.

Check warning on line 42 in Models/DTOs/ComponentDto.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'source' in 'IEnumerable<TerminalDto> Enumerable.Select<Terminal, TerminalDto>(IEnumerable<Terminal> source, Func<Terminal, TerminalDto> selector)'.

Check warning on line 42 in Models/DTOs/ComponentDto.cs

View workflow job for this annotation

GitHub Actions / build-linux

Possible null reference argument for parameter 'source' in 'IEnumerable<TerminalDto> Enumerable.Select<Terminal, TerminalDto>(IEnumerable<Terminal> source, Func<Terminal, TerminalDto> selector)'.

Check warning on line 42 in Models/DTOs/ComponentDto.cs

View workflow job for this annotation

GitHub Actions / build-windows

Possible null reference argument for parameter 'source' in 'IEnumerable<TerminalDto> Enumerable.Select<Terminal, TerminalDto>(IEnumerable<Terminal> source, Func<Terminal, TerminalDto> selector)'.

Check warning on line 42 in Models/DTOs/ComponentDto.cs

View workflow job for this annotation

GitHub Actions / build-windows

Possible null reference argument for parameter 'source' in 'IEnumerable<TerminalDto> Enumerable.Select<Terminal, TerminalDto>(IEnumerable<Terminal> source, Func<Terminal, TerminalDto> selector)'.

};
}
Expand Down Expand Up @@ -78,8 +79,14 @@
result.Rotation = dto.Rotation;
result.IsSelected = dto.IsSelected;
result.StoredStates = dto.StoredStates;
result.Terminals = dto.Terminals.Select(p => TerminalDto.ToTerminal(p)).ToArray();


// Add terminal positions here by calling the function that generates them
result.AddTerminalPoints();
for (int i = 0; i < dto.Terminals.Count; i++)
{
result.Terminals[i].Wires = TerminalDto.ToTerminal(dto.Terminals[i]).Wires;

Check warning on line 87 in Models/DTOs/ComponentDto.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 87 in Models/DTOs/ComponentDto.cs

View workflow job for this annotation

GitHub Actions / build-linux

Dereference of a possibly null reference.

Check warning on line 87 in Models/DTOs/ComponentDto.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 87 in Models/DTOs/ComponentDto.cs

View workflow job for this annotation

GitHub Actions / build-linux

Dereference of a possibly null reference.

Check warning on line 87 in Models/DTOs/ComponentDto.cs

View workflow job for this annotation

GitHub Actions / build-windows

Dereference of a possibly null reference.

Check warning on line 87 in Models/DTOs/ComponentDto.cs

View workflow job for this annotation

GitHub Actions / build-windows

Dereference of a possibly null reference.
}

Canvas.SetLeft(result, dto.X);
Canvas.SetTop(result, dto.Y);

Expand Down
5 changes: 2 additions & 3 deletions Models/DTOs/TerminalDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@

public class TerminalDto
{
public Point Position { get; set; }

public List<Guid> ConnectedWireIds { get; set; }

Check warning on line 13 in Models/DTOs/TerminalDto.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'ConnectedWireIds' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in Models/DTOs/TerminalDto.cs

View workflow job for this annotation

GitHub Actions / build-linux

Non-nullable property 'ConnectedWireIds' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in Models/DTOs/TerminalDto.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'ConnectedWireIds' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in Models/DTOs/TerminalDto.cs

View workflow job for this annotation

GitHub Actions / build-linux

Non-nullable property 'ConnectedWireIds' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in Models/DTOs/TerminalDto.cs

View workflow job for this annotation

GitHub Actions / build-windows

Non-nullable property 'ConnectedWireIds' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 13 in Models/DTOs/TerminalDto.cs

View workflow job for this annotation

GitHub Actions / build-windows

Non-nullable property 'ConnectedWireIds' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public static TerminalDto ToDto(Terminal t)
{
return new TerminalDto()
{
Position = t.Position,
ConnectedWireIds = t.Wires.Select(w => w.Id).ToList(),
};
}
Expand All @@ -26,7 +24,8 @@
// This is required for post processing
public static Terminal ToTerminal(TerminalDto dto)
{
return new Terminal(dto.Position)
// Placeholder position
return new Terminal(new Point(1,1))
{
Wires = dto.ConnectedWireIds.Select(p => new Wire(){Id = p}).ToList()
};
Expand Down
92 changes: 0 additions & 92 deletions Services/XmlSerializationService.cs

This file was deleted.

Loading