158 lines
5.9 KiB
C#
158 lines
5.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace Adaptation.FileHandlers.pcl;
|
|
|
|
#nullable enable
|
|
|
|
internal class Point
|
|
// internal record Point([property: JsonPropertyName("Site")] string Site,
|
|
// [property: JsonPropertyName("X")] string X,
|
|
// [property: JsonPropertyName("Y")] string Y,
|
|
// [property: JsonPropertyName("Navg")] string NAvg,
|
|
// [property: JsonPropertyName("Rhoavg")] string RhoAvg,
|
|
// [property: JsonPropertyName("Nsl")] string Nsl,
|
|
// [property: JsonPropertyName("Rhosl")] string Rhosl,
|
|
// [property: JsonPropertyName("Vd")] string Vd,
|
|
// [property: JsonPropertyName("Phase")] string Phase,
|
|
// [property: JsonPropertyName("Flat Z")] string FlatZ,
|
|
// [property: JsonPropertyName("Grade")] string Grade,
|
|
// [property: JsonPropertyName("X Left")] string XLeft,
|
|
// [property: JsonPropertyName("X Right")] string XRight,
|
|
// [property: JsonPropertyName("Bottom Y")] string BottomY,
|
|
// [property: JsonPropertyName("Top Y")] string TopY)
|
|
{
|
|
|
|
public Point(string site, string x, string y, string nAvg, string rhoAvg, string nsl, string rhosl, string vd, string phase, string flatZ, string grade, string xLeft, string xRight, string bottomY, string topY)
|
|
{
|
|
Site = site;
|
|
X = x;
|
|
Y = y;
|
|
NAvg = nAvg;
|
|
RhoAvg = rhoAvg;
|
|
Nsl = nsl;
|
|
Rhosl = rhosl;
|
|
Vd = vd;
|
|
Phase = phase;
|
|
FlatZ = flatZ;
|
|
Grade = grade;
|
|
XLeft = xLeft;
|
|
XRight = xRight;
|
|
BottomY = bottomY;
|
|
TopY = topY;
|
|
}
|
|
|
|
[JsonPropertyName("Site")] public string Site { get; }
|
|
[JsonPropertyName("X")] public string X { get; }
|
|
[JsonPropertyName("Y")] public string Y { get; }
|
|
[JsonPropertyName("Navg")] public string NAvg { get; }
|
|
[JsonPropertyName("Rhoavg")] public string RhoAvg { get; }
|
|
[JsonPropertyName("Nsl")] public string Nsl { get; }
|
|
[JsonPropertyName("Rhosl")] public string Rhosl { get; }
|
|
[JsonPropertyName("Vd")] public string Vd { get; }
|
|
[JsonPropertyName("Phase")] public string Phase { get; }
|
|
[JsonPropertyName("Flat Z")] public string FlatZ { get; }
|
|
[JsonPropertyName("Grade")] public string Grade { get; }
|
|
[JsonPropertyName("X Left")] public string XLeft { get; }
|
|
[JsonPropertyName("X Right")] public string XRight { get; }
|
|
[JsonPropertyName("Bottom Y")] public string BottomY { get; }
|
|
[JsonPropertyName("Top Y")] public string TopY { get; }
|
|
|
|
public static Point Get() =>
|
|
new(string.Empty,
|
|
string.Empty,
|
|
string.Empty,
|
|
string.Empty,
|
|
string.Empty,
|
|
string.Empty,
|
|
string.Empty,
|
|
string.Empty,
|
|
string.Empty,
|
|
string.Empty,
|
|
string.Empty,
|
|
string.Empty,
|
|
string.Empty,
|
|
string.Empty,
|
|
string.Empty);
|
|
|
|
public static ReadOnlyCollection<Point> GetCollection(string[] lines, int take, string site, string multiple, string summaryLine, string lastUnits)
|
|
{
|
|
List<Point> results = new();
|
|
string s;
|
|
string line;
|
|
Point point;
|
|
string[] segments;
|
|
string[] segmentsB;
|
|
bool found = false;
|
|
bool foundB = false;
|
|
string[] segmentsC;
|
|
List<string> sites = new();
|
|
for (int i = 0; i < lines.Length; i++)
|
|
{
|
|
line = lines[i];
|
|
segmentsC = line.Split(new string[] { site }, StringSplitOptions.RemoveEmptyEntries);
|
|
if (segmentsC.Length > 1)
|
|
{
|
|
foreach (string segment in segmentsC)
|
|
sites.Add(segment.Trim());
|
|
}
|
|
if (line == summaryLine)
|
|
{
|
|
sites.RemoveAt(0);
|
|
found = true;
|
|
}
|
|
if (!found)
|
|
continue;
|
|
if (!foundB && line.Contains(multiple))
|
|
foundB = true;
|
|
if (line != lastUnits)
|
|
continue;
|
|
if (foundB)
|
|
{
|
|
foundB = false;
|
|
continue;
|
|
}
|
|
for (int j = 0; j < sites.Count; j++)
|
|
{
|
|
s = sites[j];
|
|
if (i + take > lines.Length)
|
|
break;
|
|
segments = s.Split(new string[] { "(", ",", ")" }, StringSplitOptions.None);
|
|
if (segments.Length < 2)
|
|
break;
|
|
segmentsB = lines[i + 10].Split(' ');
|
|
if (segmentsB.Length < 2)
|
|
break;
|
|
point = new(segments[0].Trim(),
|
|
segments[1].Trim(),
|
|
segments[2].Trim(),
|
|
nAvg: lines[i + 2].Trim(),
|
|
nsl: lines[i + 3].Trim(),
|
|
vd: lines[i + 4].Trim(),
|
|
flatZ: lines[i + 5].Trim(),
|
|
rhoAvg: lines[i + 6].Trim(),
|
|
rhosl: lines[i + 7].Trim(),
|
|
phase: lines[i + 8].Trim(),
|
|
grade: lines[i + 9].Trim(),
|
|
xLeft: segmentsB[0],
|
|
xRight: segmentsB[1],
|
|
bottomY: lines[i + 11].Trim(),
|
|
topY: lines[i + 12].Trim());
|
|
results.Add(point);
|
|
i += take;
|
|
}
|
|
sites.Clear();
|
|
}
|
|
return new(results);
|
|
}
|
|
|
|
}
|
|
|
|
[JsonSourceGenerationOptions(WriteIndented = true)]
|
|
[JsonSerializable(typeof(Point))]
|
|
internal partial class PointSourceGenerationContext : JsonSerializerContext
|
|
{
|
|
}
|