@@ -6,7 +6,7 @@ using System.Windows.Shapes;
|
||||
namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
public class Pump : INode {
|
||||
|
||||
public const double DIAMETER = 24;
|
||||
public const double DIAMETER = 4.8;
|
||||
|
||||
public double CenterX { get; set; }
|
||||
public double CenterY { get; set; }
|
||||
@@ -25,8 +25,8 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
protected Func<bool> CallbackClearance;
|
||||
protected Func<Pump, bool> CallbackSelected;
|
||||
|
||||
private Shape? _circle;
|
||||
private Shape? _triangle;
|
||||
private Ellipse? _circle;
|
||||
private Polygon? _triangle;
|
||||
private TextBlock? _text;
|
||||
|
||||
public Pump(string label, double x, double y, Func<MotorState> cbState, Func<bool> cbClearance, Func<Pump, bool> cbSelected) {
|
||||
@@ -42,35 +42,40 @@ namespace PamhagenSysCtrl.Helpers.Pipeline {
|
||||
|
||||
public void Draw(Canvas canvas) {
|
||||
_circle = new Ellipse() {
|
||||
Height = DIAMETER,
|
||||
Width = DIAMETER,
|
||||
Fill = Brushes.WhiteSmoke,
|
||||
Stroke = Brushes.Black,
|
||||
StrokeThickness = 2,
|
||||
};
|
||||
var dx = Math.Cos(Math.PI / 6) * (DIAMETER / 2 - 2);
|
||||
var dy = Math.Sin(Math.PI / 6) * (DIAMETER / 2 - 2);
|
||||
_triangle = new Polygon() {
|
||||
Points = [new(CenterX - dx, CenterY - dy), new(CenterX + dx, CenterY - dy), new(CenterX, CenterY + DIAMETER / 2 - 2)],
|
||||
Fill = Brushes.Transparent,
|
||||
Stroke = Brushes.Black,
|
||||
StrokeThickness = 2,
|
||||
};
|
||||
_text = new() {
|
||||
Text = Label,
|
||||
FontSize = 14,
|
||||
TextAlignment = TextAlignment.Left,
|
||||
VerticalAlignment = VerticalAlignment.Center,
|
||||
};
|
||||
_circle.SetValue(Canvas.LeftProperty, CenterX - DIAMETER / 2);
|
||||
_circle.SetValue(Canvas.TopProperty, CenterY - DIAMETER / 2);
|
||||
_text.SetValue(Canvas.LeftProperty, CenterX + DIAMETER / 2 + 2);
|
||||
_text.SetValue(Canvas.TopProperty, CenterY - 10);
|
||||
canvas.Children.Add(_circle);
|
||||
canvas.Children.Add(_triangle);
|
||||
canvas.Children.Add(_text);
|
||||
}
|
||||
|
||||
public void Scale(double scale) {
|
||||
var border = Graph.ToBorder(scale);
|
||||
_circle?.StrokeThickness = border;
|
||||
Graph.SetCenter(_circle, CenterX, CenterY, DIAMETER, DIAMETER, scale);
|
||||
var dx = Math.Cos(Math.PI / 6) * (DIAMETER / 2);
|
||||
var dy = Math.Sin(Math.PI / 6) * (DIAMETER / 2);
|
||||
_triangle?.Points = [
|
||||
Graph.ToPx(CenterX - dx, CenterY - dy, scale, dxpx: border, dypx: border / 2, round: false),
|
||||
Graph.ToPx(CenterX + dx, CenterY - dy, scale, dxpx: -border, dypx: border / 2, round: false),
|
||||
Graph.ToPx(CenterX, CenterY + DIAMETER / 2, scale, dypx: -border, round: false),
|
||||
];
|
||||
_triangle?.StrokeThickness = border;
|
||||
_text?.FontSize = 14;
|
||||
_text?.SetValue(Canvas.LeftProperty, (CenterX + DIAMETER / 2) * scale + 2);
|
||||
_text?.SetValue(Canvas.TopProperty, CenterY * scale - 10);
|
||||
}
|
||||
|
||||
public bool IsInside(double x, double y) {
|
||||
return Math.Sqrt(Math.Pow(CenterX - x, 2) + Math.Pow(CenterY - y, 2)) <= DIAMETER / 2;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user