tbf/SchematicDrawing/Enums.cs

146 lines
3.5 KiB
C#
Raw Permalink Normal View History

using Dirichlet.Numerics;
///
/// Copyright (c) 2020 Sensus Slovensko a.s.
///
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace SchematicDrawing
{
public static class Const
{
public const int GridSize = 10;
public const int SecondaryStart = 10000;
public const int Vacuum = 1000000;
}
public enum Element
{
None = 0,
Body = 1, /// Item body (component image)
Label = 2, /// Item label
MeasuredVal = 4, /// Item measured value
Setpoint = 8, /// Item setpoint
Node = 16, /// A node of an item
Pipe = 32, /// Pipe between two nodes
}
public enum Shape
{
Ambient,
Clamping,
Cover,
Cross,
Div,
EmergencyStop,
FlowM,
Junction,
Knee,
ParallelFlowM,
PressM,
Pump,
PumpFM,
RegV,
Scale,
Sink,
Tank,
TankHot,
Tee,
TempM,
UniCB,
Vacuum,
Valve,
ValveSw,
WaterM,
ElectricM,
Count,
Custom,
}
public enum Sz
{
None,
S,
M,
L,
XL,
Count,
}
public enum Orient
{
R,
Dn,
L,
Up,
Count,
}
public enum RouteCouple
{
None,
OpenWhen1,
ClosedWhen1,
}
public static class Utils
{
/// <summary>
/// Return coordinates of the vector in direction Orient
/// </summary>
/// <param name="orient">Orient</param>
/// <returns>Vector</returns>
public static Point GetVect(Orient orient)
{
switch (orient)
{
default:
case Orient.R: return new Point(1, 0);
case Orient.Up: return new Point(0, -1);
case Orient.L: return new Point(-1, 0);
case Orient.Dn: return new Point(0, 1);
}
}
/// <summary>
/// Return coordinates of the vector perpendicular to Orient
/// </summary>
/// <param name="orient">Orient</param>
/// <returns>Perpendicular vector</returns>
public static Point GetNormalVect(Orient orient)
{
switch (orient)
{
default:
case Orient.R: return new Point(0, 1);
case Orient.Up: return new Point(1, 0);
case Orient.L: return new Point(0, -1);
case Orient.Dn: return new Point(-1, 0);
}
}
/// <summary>
/// Returns true when item is hidden (both X and Y coordinates are 0)
/// </summary>
/// <param name="item">Drawing item</param>
/// <returns>true when hidden</returns>
public static bool IsHidden(IDrawingItem item)
{
return (item.X == 0) && (item.Y == 0);
}
/// <summary>
/// Updates distances of graph edges of IRouteBasedDrewingItem (valve, pump, ...) after route chanage.
/// </summary>
/// <param name="route">Route</param>
/// <param name="item">Item</param>
public static void UpdateGraphEdges(UInt128 route, IRouteBasedDrawingItem item)
{
bool routeBit = (route & (((UInt128)1) << item.BitNr)) != 0;
foreach (var gedge in item.EdgesToSet) gedge.UpdateFromRoute(item.Inverted ? (!routeBit) : routeBit);
}
}
}