git_brcal/src/BreCalClient/ShipcallControlModel.cs

78 lines
1.9 KiB
C#

// Copyright (c) 2023 schick Informatik
// Description: Container model for shipcall related info
//
using BreCalClient.misc.Model;
using System;
namespace BreCalClient
{
/// <summary>
/// Container model to aggregate separate models for the Shipcall control data binding
/// </summary>
public class ShipcallControlModel
{
public enum TrafficLightMode
{
OFF,
GREEN,
YELLOW,
RED,
RED_YELLOW,
ALL
};
[Flags]
public enum StatusFlags
{
RED,
GREEN,
YELLOW,
BLINK_1,
BLINK_2
};
public Shipcall? Shipcall { get; set; }
public Ship? Ship { get; set; }
public string Test { get { return "Gurkensalat"; } }
public TrafficLightMode LightMode
{
get
{
if(IsFlagSet(StatusFlags.RED))
{
if(IsFlagSet((StatusFlags)StatusFlags.YELLOW))
{
if(IsFlagSet(StatusFlags.GREEN))
{
return TrafficLightMode.ALL;
}
return TrafficLightMode.RED_YELLOW;
}
return TrafficLightMode.RED;
}
if(IsFlagSet(StatusFlags.YELLOW))
return TrafficLightMode.YELLOW;
if(IsFlagSet(StatusFlags.GREEN))
return TrafficLightMode.GREEN;
return TrafficLightMode.OFF;
}
}
#region private helper
private bool IsFlagSet(StatusFlags flag)
{
if(this.Shipcall == null) return false;
return (this.Shipcall.Flags & (int) flag) != 0;
}
#endregion
}
}