Cam
Cam
CC#
Created by Cam on 2/27/2024 in #help
[AVALONIA] Polylines not displaying on Canvas
I have been having this issue for a while. My Polylines which I have generated are not being displayed in the Canvas. I am using MVVM so I have created all the Models, ensured they are correctly populating, checked that they are inside the canvas using the F12 debugging tool but they just are not visible. Help? Canvas Model
c#
using Avalonia.Controls.Shapes;
using Avalonia.Media;
using System.Collections.Generic;
using System.Text;
using System.Xml.Linq;

namespace BirdsEye.Models.Panel
{
public class CanvasSegment
{
public string ID { get; set; } // IDENTIFICATION OF THE CANVAS SEGMENT
public string Name { get; set; } // NAME OF THE CANVAS SEGMENT
public List<Polyline> Polylines { get; set; } // LIST OF CANVAS RAILS WITHIN THE CANVAS SEGMENT
public LiveDisplay Display { get; set; } // DATA CONTROLLING THE LIVE DISPLAY OF THE CANVAS SEGMENT

}
}
c#
using Avalonia.Controls.Shapes;
using Avalonia.Media;
using System.Collections.Generic;
using System.Text;
using System.Xml.Linq;

namespace BirdsEye.Models.Panel
{
public class CanvasSegment
{
public string ID { get; set; } // IDENTIFICATION OF THE CANVAS SEGMENT
public string Name { get; set; } // NAME OF THE CANVAS SEGMENT
public List<Polyline> Polylines { get; set; } // LIST OF CANVAS RAILS WITHIN THE CANVAS SEGMENT
public LiveDisplay Display { get; set; } // DATA CONTROLLING THE LIVE DISPLAY OF THE CANVAS SEGMENT

}
}
Panel View Model
c#
using BirdsEye.Models.Panel;
using BirdsEye.Resources.Functions.Data;

namespace BirdsEye.ViewModels
{
public class PanelViewModel
{
public PanelSegment PanelSegment { get; set; }
public CanvasSegment CanvasSegment { get; set; }
public PanelViewModel()
{
PanelBuilder buildPanel = new PanelBuilder();
PanelSegment = buildPanel.PanelSegment;
CanvasSegment = buildPanel.CanvasSegment;
}
}
}
c#
using BirdsEye.Models.Panel;
using BirdsEye.Resources.Functions.Data;

namespace BirdsEye.ViewModels
{
public class PanelViewModel
{
public PanelSegment PanelSegment { get; set; }
public CanvasSegment CanvasSegment { get; set; }
public PanelViewModel()
{
PanelBuilder buildPanel = new PanelBuilder();
PanelSegment = buildPanel.PanelSegment;
CanvasSegment = buildPanel.CanvasSegment;
}
}
}
69 replies
CC#
Created by Cam on 2/4/2024 in #help
✅ [AVALONIA] Get all coordinates along a Polyline
Whilst you define the points for a Polyline, is there any way that I can get or calculate the rest of the coordinates in between the Polyline points. Essentially wanting to return all the X and Y coordinates that make up the entire Polyline and store them in a List/Dictionary
1 replies
CC#
Created by Cam on 2/4/2024 in #help
✅ [AVALONIA] Return Coordinates (Only if a Polyline is present in those coordinates)
No description
1 replies
CC#
Created by Cam on 2/4/2024 in #help
✅ Return Coordinates (Only if a Polyline is present in those coordinates)
No description
2 replies
CC#
Created by Cam on 2/3/2024 in #help
✅ Dictionary not returning Value
HashCode keys are the same however its for some reason not returning the value from the dictionary Pathfinding Class
c#
public List<PathNode>? findPath(int startPointX, int startPointY, int endPointX, int endPointY)
{
PathNode startNode = getNode(startPointX, startPointY);
PathNode endNode = getNode(endPointX, endPointY);
Debug.WriteLine("[Birds Eye] New Pathfinding Begun");
{
openList.Add(startNode);

for (int x = 0; x < panelWidth; x++)
{
for (int y = 0; y < panelHeight; y++)
{
PathNode pathNode = getNode(x, y);
pathNode.gCost = int.MaxValue;
pathNode.calculateFCost();
pathNode.cameFromNode = null;
}
}
startNode.gCost = 0;
Debug.WriteLine("[Birds Eye] G Cost Initialized");
startNode.hCost = calculatDistanceCost(startNode, endNode);
Debug.WriteLine("[Birds Eye] H Cost Initialized");
startNode.calculateFCost();
Debug.WriteLine("[Birds Eye] F Cost Initialized");

while (openList.Count > 0)
{
PathNode currentNode = getLowestFCostNode(openList);
Debug.WriteLine("[Birds Eye] Current Node Initialized");
if (currentNode == endNode)
{
return finalPath(endNode);
}
openList.Remove(currentNode);
closedList.Add(currentNode);
Debug.WriteLine("[Birds Eye] Searching Neighbours");
foreach (PathNode neighbourNode in getNeighbour(currentNode))
{

Debug.WriteLine("[Birds Eye] New Panel Node Reached");
if (closedList.Contains(neighbourNode)) continue;
int tentativeGCost = currentNode.gCost + calculatDistanceCost(currentNode, neighbourNode);
if (tentativeGCost < currentNode.gCost)
{

neighbourNode.cameFromNode = currentNode;
neighbourNode.gCost = tentativeGCost;
neighbourNode.hCost = calculatDistanceCost(neighbourNode, endNode);
neighbourNode.calculateFCost();

if (!openList.Contains(neighbourNode))
{
openList.Add(neighbourNode);
Debug.WriteLine("[Birds Eye] Added Neighbour to Open List");

}
}
}
}
Debug.WriteLine("[Birds Eye] No Path Found");
return null;
}
}
c#
public List<PathNode>? findPath(int startPointX, int startPointY, int endPointX, int endPointY)
{
PathNode startNode = getNode(startPointX, startPointY);
PathNode endNode = getNode(endPointX, endPointY);
Debug.WriteLine("[Birds Eye] New Pathfinding Begun");
{
openList.Add(startNode);

for (int x = 0; x < panelWidth; x++)
{
for (int y = 0; y < panelHeight; y++)
{
PathNode pathNode = getNode(x, y);
pathNode.gCost = int.MaxValue;
pathNode.calculateFCost();
pathNode.cameFromNode = null;
}
}
startNode.gCost = 0;
Debug.WriteLine("[Birds Eye] G Cost Initialized");
startNode.hCost = calculatDistanceCost(startNode, endNode);
Debug.WriteLine("[Birds Eye] H Cost Initialized");
startNode.calculateFCost();
Debug.WriteLine("[Birds Eye] F Cost Initialized");

while (openList.Count > 0)
{
PathNode currentNode = getLowestFCostNode(openList);
Debug.WriteLine("[Birds Eye] Current Node Initialized");
if (currentNode == endNode)
{
return finalPath(endNode);
}
openList.Remove(currentNode);
closedList.Add(currentNode);
Debug.WriteLine("[Birds Eye] Searching Neighbours");
foreach (PathNode neighbourNode in getNeighbour(currentNode))
{

Debug.WriteLine("[Birds Eye] New Panel Node Reached");
if (closedList.Contains(neighbourNode)) continue;
int tentativeGCost = currentNode.gCost + calculatDistanceCost(currentNode, neighbourNode);
if (tentativeGCost < currentNode.gCost)
{

neighbourNode.cameFromNode = currentNode;
neighbourNode.gCost = tentativeGCost;
neighbourNode.hCost = calculatDistanceCost(neighbourNode, endNode);
neighbourNode.calculateFCost();

if (!openList.Contains(neighbourNode))
{
openList.Add(neighbourNode);
Debug.WriteLine("[Birds Eye] Added Neighbour to Open List");

}
}
}
}
Debug.WriteLine("[Birds Eye] No Path Found");
return null;
}
}
30 replies
CC#
Created by Cam on 2/3/2024 in #help
✅ HashCode returning different numbers when parsing the same value
I pass 0, 420 into HashCode.Combine, but when they are in different files the hashcode does not return the same number back
42 replies
CC#
Created by Cam on 1/31/2024 in #help
✅ Help with Simplifying Method further
Anyway to make this code smaller so that i dont have to write "new List<Avalonia.Point>" and "new Avalonia.Point(x,y)" so many times? Preferably wanting a function where i can parse as many points into the method as i need. I have already added a method to create the line but it still contains too much rubbish repetitive code
c#
public partial class Newmarket : UserControl
{
public List<Polyline> newmarketTurnouts = new List<Polyline>();
public bool normal = true;
public Newmarket()
{
InitializeComponent();
buildPanel();
PanelGrid panelGrid = new PanelGrid(NewmarketPanel);
}

public void buildPanel() // Build Dynamic Points to Panel
{
newmarketTurnouts.Add(drawToPanel(new List<Avalonia.Point> { new Avalonia.Point(100, 480), new Avalonia.Point(112, 480) })); // 251B - Down Main
newmarketTurnouts.Add(drawToPanel(new List<Avalonia.Point> { new Avalonia.Point(138, 420), new Avalonia.Point(150, 420) })); // 251A - Up Main
newmarketTurnouts.Add(drawToPanel(new List<Avalonia.Point> { new Avalonia.Point(150, 430), new Avalonia.Point(140, 430), new Avalonia.Point(110, 470), new Avalonia.Point(100, 470) })); // 251 Crossover


NewmarketPanel.Children.Add(newmarketTurnouts);
}
public Polyline drawToPanel(List<Avalonia.Point> points) // Create new Polyline
{
Polyline newObject = new Polyline
{
Stroke = Avalonia.Media.Brushes.Red,
StrokeThickness = 2
};
var n = points.Count;
for (int i = 0; i < n; i++)
{
newObject.Points.Add(points[i]);
}
return newObject;
}
}
c#
public partial class Newmarket : UserControl
{
public List<Polyline> newmarketTurnouts = new List<Polyline>();
public bool normal = true;
public Newmarket()
{
InitializeComponent();
buildPanel();
PanelGrid panelGrid = new PanelGrid(NewmarketPanel);
}

public void buildPanel() // Build Dynamic Points to Panel
{
newmarketTurnouts.Add(drawToPanel(new List<Avalonia.Point> { new Avalonia.Point(100, 480), new Avalonia.Point(112, 480) })); // 251B - Down Main
newmarketTurnouts.Add(drawToPanel(new List<Avalonia.Point> { new Avalonia.Point(138, 420), new Avalonia.Point(150, 420) })); // 251A - Up Main
newmarketTurnouts.Add(drawToPanel(new List<Avalonia.Point> { new Avalonia.Point(150, 430), new Avalonia.Point(140, 430), new Avalonia.Point(110, 470), new Avalonia.Point(100, 470) })); // 251 Crossover


NewmarketPanel.Children.Add(newmarketTurnouts);
}
public Polyline drawToPanel(List<Avalonia.Point> points) // Create new Polyline
{
Polyline newObject = new Polyline
{
Stroke = Avalonia.Media.Brushes.Red,
StrokeThickness = 2
};
var n = points.Count;
for (int i = 0; i < n; i++)
{
newObject.Points.Add(points[i]);
}
return newObject;
}
}
12 replies
CC#
Created by Cam on 1/30/2024 in #help
✅ A* Algorithm Get Node where x and y is 1 less (Neigbour)
Any idea how to get the neighbours? ive tried to grab the neighbour pathnode item by subtracting 1 from x. Either im not doing it correctly or the list needs to be formatted better but all the ways i have tried are not seeming to work so help?.
c#
public class PathNode
{
private double width;
private double height;
public double x;
public double y;
//private List<double> neighbours;
private bool closed = false;
private bool walkable = true;
public PathNode(double width, double height, double x, double y)
{
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public bool barrierNode()
{
return walkable = false;
}
public void updateNeighbours(List<PathNode> panelNodes)
{
if (x < width - 1 /* Code Here to get the pathnode with x - 1 and y -1*/ )
{

}
}
}
c#
public class PathNode
{
private double width;
private double height;
public double x;
public double y;
//private List<double> neighbours;
private bool closed = false;
private bool walkable = true;
public PathNode(double width, double height, double x, double y)
{
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public bool barrierNode()
{
return walkable = false;
}
public void updateNeighbours(List<PathNode> panelNodes)
{
if (x < width - 1 /* Code Here to get the pathnode with x - 1 and y -1*/ )
{

}
}
}
137 replies
CC#
Created by Cam on 1/26/2024 in #help
✅ Avalonia Polyline Method Help
Any idea why this wont work?
c#
public void buildPanel(Canvas NewmarketPanel) // Get Live Session State of Panel and apply to View
{

Polyline X251 = drawToPanel(new List<Avalonia.Point> { new Avalonia.Point(-575, 100), new Avalonia.Point(-560, 100) });
NewmarketPanel.Children.Add(X251);

}
public Polyline drawToPanel(List<Avalonia.Point> points)
{
Polyline newObject = new Polyline
{
Stroke = Avalonia.Media.Brushes.Red,
StrokeThickness = 2
};
var n = points.Count - 1;
for (int i = 0; i < n; i++)
{
newObject.Points.Add(points[i]);
}
//Debug.WriteLine(newObject.ToString());
return newObject;
}
c#
public void buildPanel(Canvas NewmarketPanel) // Get Live Session State of Panel and apply to View
{

Polyline X251 = drawToPanel(new List<Avalonia.Point> { new Avalonia.Point(-575, 100), new Avalonia.Point(-560, 100) });
NewmarketPanel.Children.Add(X251);

}
public Polyline drawToPanel(List<Avalonia.Point> points)
{
Polyline newObject = new Polyline
{
Stroke = Avalonia.Media.Brushes.Red,
StrokeThickness = 2
};
var n = points.Count - 1;
for (int i = 0; i < n; i++)
{
newObject.Points.Add(points[i]);
}
//Debug.WriteLine(newObject.ToString());
return newObject;
}
2 replies
CC#
Created by Cam on 1/4/2024 in #help
✅ Adding XAML code from a seperate file into the MainWindow
Is it possible to add XAML code into a file from own other. These are files that I will regularly need to edit and update so having them in a seperate file from the MainWindow is important. E.g “Panel1.xaml” needs to have its code “injected” into MainWindow
20 replies