Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add what is needed #54

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions DSTV.Net.Test/Data/notch.nc1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
ST
**NC-DSTV-Schnittstelle
DSTV
1
3
3
RST37-2
1
HEB400
I
2000.00
400.00
300.00
24.00
13.50
27.00
155.000
1.930
0.000
0.000
0.000
0.000
TRAEGER



AK
v 200.00u 0.00 0.00
v 1952.00 0.00w 10.00
v 200.00 100.00 -10.00
200.00 110.00t -10.00
200.00 90.00 0.00
v 200.00 0.00 0.00
AK
u 200.00 0.00 0.00
u 1900.00 0.00 0.00
u 2000.00 300.00 0.00
u 200.00 300.00 0.00
u 200.00 0.00 0.00
AK
o 159.50s 0.00 0.00
o 159.50s 300.00 0.00
o 1650.00s 300.00 0.00
o 1750.00s 200.00 0.00
o 1750.00s 0.00 0.00
o 159.50s 0.00 0.00
30 changes: 30 additions & 0 deletions DSTV.Net.Test/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,36 @@ public async Task TestTupleParseException()
exception.Message);
}

/// <summary>
/// Example with notch points
/// Expect valid IsNotch flag for points
/// </summary>
[Fact]
public async Task TestIsNotchPoint()
{
using var streamReader = new StreamReader($"{DataPath}/Data/notch.nc1");
var dstvReader = new DstvReader();

var result = await dstvReader.ParseAsync(streamReader).ConfigureAwait(false);
var dstvElement = result.Elements.First();

Assert.IsType<Contour>(dstvElement);
var contour = (Contour)dstvElement;

Assert.Equal(ContourType.AK, contour.Type);
var actualPoints = contour.Points.ToArray();

Assert.Equal(6, actualPoints.Length);
// First notch "w" point with flange code
Assert.True(actualPoints[1].IsNotch);
// First not notch point with flange code
Assert.False(actualPoints[2].IsNotch);
// Second notch "t" point without flange code
Assert.True(actualPoints[3].IsNotch);
// Second not notch point without flange code
Assert.False(actualPoints[4].IsNotch);
}

// /// <summary>
// /// Example of an invalid end in the DSTV file
// /// Expect a <seealso cref="UnexpectedEndException" />
Expand Down
1 change: 1 addition & 0 deletions DSTV.Net.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=Coord/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=DSTV/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
4 changes: 2 additions & 2 deletions DSTV.Net/DSTV.Net.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>DSTV.Net is an open-source library tailored for .NET platforms, providing a powerful utility for interacting with DSTV (also known as NC1 or Tekla) files. These files serve as a key industry standard in the steel industry, defining geometry and project information for steel plates.</Description>
<PackageProjectUrl>https://github.com/Baseflow/DSTV.Net</PackageProjectUrl>
<TargetFrameworks>net6.0;net7.0;netstandard2.0</TargetFrameworks>
<Version>1.2.1</Version>
<Version>1.3.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
10 changes: 6 additions & 4 deletions DSTV.Net/Data/Contour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ public record Contour : DstvElement
private readonly List<DstvContourPoint> _pointList;

// ReSharper disable once NotAccessedField.Local
private readonly ContourType _type;
public ContourType Type { get; }

public IEnumerable<DstvContourPoint> Points => _pointList.AsEnumerable();

private Contour(List<DstvContourPoint> pointList, ContourType type)
{
_pointList = pointList;
_type = type;
Type = type;
}

[SuppressMessage("Design", "CA1002:Do not expose generic lists", Justification = "This is a record")]
Expand Down Expand Up @@ -72,7 +74,7 @@ public override string ToSvg()
{
var sb = new StringBuilder();
var sbLine = new StringBuilder();
var previous = new DstvContourPoint("x", 0, 0, 0);
var previous = new DstvContourPoint("x", 0, 0, false, 0);
foreach (var point in _pointList)
{
if (_pointList.IndexOf(point) == 0)
Expand Down Expand Up @@ -124,7 +126,7 @@ public override string ToSvg()
}

var points = sb.ToString();
var color = _type == ContourType.AK ? "grey" : "white";
var color = Type == ContourType.AK ? "grey" : "white";
return $"<path d=\"{points}\" fill=\"{color}\" stroke=\"black\" stroke-width=\"0.5\" />{sbLine}";
}
}
42 changes: 25 additions & 17 deletions DSTV.Net/Data/DstvContourPoint.cs
Original file line number Diff line number Diff line change
@@ -1,52 +1,53 @@
using DSTV.Net.Exceptions;
using DSTV.Net.Implementations;
using System.Diagnostics.CodeAnalysis;
using System.Text.RegularExpressions;

namespace DSTV.Net.Data;

[SuppressMessage("Designer", "CA1051:Do not declare visible instance fields", Justification = "This is a DTO")]
public record DstvContourPoint : LocatedElement
public record DstvContourPoint(string FlCode, double XCoord, double YCoord, bool IsNotch, double Radius) : LocatedElement(FlCode, XCoord, YCoord)
{
protected readonly double _radius;

public DstvContourPoint(string flCode, double xCoord, double yCoord, double radius) :
base(flCode, xCoord, yCoord) => _radius = radius;

public double Radius => _radius;

public static DstvContourPoint CreatePoint(string dstvElement)
{
var separated = GetDataVector(dstvElement, FineSplitter.Instance);
// temporary flange-code in case of missing a signature in line
var flCode = "x";
separated[0] = separated[0].Trim();
if (ValidateFlange(separated[0])) flCode = separated[0];
var yCoordIndex = 1;
if (ValidateFlange(separated[0]))
{
flCode = separated[0];
++yCoordIndex;
}

var isNotchPoint = IsNotchPoint(separated[yCoordIndex]);
separated = CorrectSplits(separated);

var xCoord = double.Parse(separated[0], Constants.ParserCultureInfo);
var yCoord = double.Parse(separated[1], Constants.ParserCultureInfo);
var rad = double.Parse(separated[2], Constants.ParserCultureInfo);
if (separated.Length <= 4) return new DstvContourPoint(flCode, xCoord, yCoord, rad);
if (separated.Length <= 4) return new DstvContourPoint(flCode, xCoord, yCoord, isNotchPoint, rad);

double ang1;
double blunting1;
if (separated.Length == 5)
{
ang1 = double.Parse(separated[3], Constants.ParserCultureInfo);
blunting1 = double.Parse(separated[4], Constants.ParserCultureInfo);
if (ang1 == 0 && blunting1 == 0) return new DstvContourPoint(flCode, xCoord, yCoord, rad);
if (ang1 == 0 && blunting1 == 0) return new DstvContourPoint(flCode, xCoord, yCoord, isNotchPoint, rad);

return new DstvSkewedPoint(flCode, xCoord, yCoord, rad, ang1, blunting1, 0, 0);
return new DstvSkewedPoint(flCode, xCoord, yCoord, isNotchPoint, rad, ang1, blunting1, 0, 0);
}

if (separated.Length == 7)
{
ang1 = double.Parse(separated[4], Constants.ParserCultureInfo);
var ang2 = double.Parse(separated[6], Constants.ParserCultureInfo);
blunting1 = double.Parse(separated[5], Constants.ParserCultureInfo);
if (ang1 == 0 && blunting1 == 0) return new DstvContourPoint(flCode, xCoord, yCoord, rad);
if (ang1 == 0 && blunting1 == 0) return new DstvContourPoint(flCode, xCoord, yCoord, isNotchPoint, rad);

return new DstvSkewedPoint(flCode, xCoord, yCoord, rad, ang1, blunting1, ang2, 0);
return new DstvSkewedPoint(flCode, xCoord, yCoord, isNotchPoint, rad, ang1, blunting1, ang2, 0);
}

if (separated.Length == 8)
Expand All @@ -60,15 +61,22 @@ public static DstvContourPoint CreatePoint(string dstvElement)
&& ang2 == 0
&& blunting2 == 0)
{
return new DstvContourPoint(flCode, xCoord, yCoord, rad);
return new DstvContourPoint(flCode, xCoord, yCoord, isNotchPoint, rad);
}

return new DstvSkewedPoint(flCode, xCoord, yCoord, rad, ang1, blunting1, ang2, blunting2);
return new DstvSkewedPoint(flCode, xCoord, yCoord, isNotchPoint, rad, ang1, blunting1, ang2, blunting2);
}

throw new DstvParseException("Illegal data vector format (AK/IK)");
}

private static bool IsNotchPoint(string yCoordValue)
{
var numberRegexString = "[.\\d-]+";
var regexString = $"{numberRegexString}[wt]";
return Regex.IsMatch(yCoordValue, regexString, RegexOptions.None, TimeSpan.FromSeconds(1));
}

public override string ToString() =>
$"DStVContourPoint : radius={_radius}, flCode=\'{FlCode}\', xCoord={XCoord}, yCoord={YCoord}";
$"DStVContourPoint : radius={Radius}, flCode=\'{FlCode}\', xCoord={XCoord}, yCoord={YCoord}";
}
19 changes: 10 additions & 9 deletions DSTV.Net/Data/DstvHole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ namespace DSTV.Net.Data;
[SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "This is a DTO")]
public record DstvHole : LocatedElement
{
//0 if through
private readonly double _depth;
protected readonly double Diam;
// 0 if through
public double Depth { get; }

protected DstvHole(string flCode, double xCoord, double yCoord, double diam, double depth) : base(flCode, xCoord,
yCoord)
public double Diameter { get; }

protected DstvHole(string flCode, double xCoord, double yCoord, double diam, double depth)
: base(flCode, xCoord, yCoord)
{
Diam = diam;
_depth = depth;
Diameter = diam;
Depth = depth;
}


Expand Down Expand Up @@ -51,8 +52,8 @@ public static DstvElement CreateHole(string holeNote)
}

public override string ToString() =>
$"DStVHole : flCode='{FlCode}', xCoord={XCoord}, yCoord={YCoord}, diam={Diam}, depth={_depth}";
$"DStVHole : flCode='{FlCode}', xCoord={XCoord}, yCoord={YCoord}, diam={Diameter}, depth={Depth}";

public override string ToSvg() =>
$"<circle cx=\"{XCoord:F}\" cy=\"{YCoord:F}\" r=\"{Diam / 2:F}\" fill=\"white\" />";
$"<circle cx=\"{XCoord:F}\" cy=\"{YCoord:F}\" r=\"{Diameter / 2:F}\" fill=\"white\" />";
}
32 changes: 12 additions & 20 deletions DSTV.Net/Data/DstvSkewedPoint.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
namespace DSTV.Net.Data;

public record DstvSkewedPoint : DstvContourPoint
public record DstvSkewedPoint(
string FlCode,
double XCoord,
double YCoord,
bool IsNotch,
double Radius,
double FirstAngle,
double FirstBlunting,
double SecondAngle,
double SecondBlunting)
: DstvContourPoint(FlCode, XCoord, YCoord, IsNotch, Radius)
{
private readonly double _ang1;

private readonly double _ang2;

private readonly double _blunting1;

private readonly double _blunting2;

public DstvSkewedPoint(string flCode, double xCoord, double yCoord, double radius, double ang1, double blunting1,
double ang2, double blunting2) : base(flCode, xCoord, yCoord, radius)
{
_ang1 = ang1;
_blunting1 = blunting1;
_ang2 = ang2;
_blunting2 = blunting2;
}


public override string ToString() =>
$"DStVSkewedPoint{{ang1={_ang1}, blunting1={_blunting1}, ang2={_ang2}, blunting2={_blunting2}, radius={_radius}, flCode='{FlCode}', xCoord={XCoord}, yCoord={YCoord}}}";
$"DStVSkewedPoint{{ang1={FirstAngle}, blunting1={FirstBlunting}, ang2={SecondAngle}, blunting2={SecondBlunting}, radius={Radius}, flCode='{FlCode}', xCoord={XCoord}, yCoord={YCoord}}}";
}
29 changes: 19 additions & 10 deletions DSTV.Net/Data/DstvSlot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,30 @@ namespace DSTV.Net.Data;

public record DstvSlot : DstvHole
{
private readonly double _slotAng;
public double SlotAngle { get; }

//optional, for slots only
private readonly double _slotLen;
private readonly double _slotWidth;
public double SlotLength { get; }

public DstvSlot(string flCode, double xCoord, double yCoord, double diam, double depth, double slotLen,
double slotWidth, double slotAng) : base(flCode, xCoord, yCoord, diam, depth)
public double SlotWidth { get; }

public DstvSlot(
string flCode,
double xCoord,
double yCoord,
double diam,
double depth,
double slotLen,
double slotWidth,
double slotAng)
: base(flCode, xCoord, yCoord, diam, depth)
{
_slotLen = slotLen;
_slotWidth = slotWidth;
_slotAng = slotAng;
SlotLength = slotLen;
SlotWidth = slotWidth;
SlotAngle = slotAng;
}

public override string ToString() => $"{base.ToString()}, SlotLength : {_slotLen}, SlothWidth : {_slotWidth}, SlotAngle : {_slotAng}";
public override string ToString() => $"{base.ToString()}, SlotLength : {SlotLength}, SlothWidth : {SlotWidth}, SlotAngle : {SlotAngle}";

public override string ToSvg() => $"<rect x=\"{XCoord}\" y=\"{YCoord}\" width=\"{_slotLen + Diam}\" height=\"{Diam}\" fill=\"white\" rx=\"{Diam / 2}\" />";
public override string ToSvg() => $"<rect x=\"{XCoord}\" y=\"{YCoord}\" width=\"{SlotLength + Diameter}\" height=\"{Diameter}\" fill=\"white\" rx=\"{Diameter / 2}\" />";
}
2 changes: 1 addition & 1 deletion DSTV.Net/Implementations/DotSplitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public string[] Split(string input)
{
var prevPos = 0;
if (i > 0) prevPos = dotPoss[i - 1];
dotPoss[i] = input.IndexOf(".", prevPos + 1, StringComparison.Ordinal);
dotPoss[i] = input.IndexOf('.', prevPos + 1);
}

var outArr = new string[n];
Expand Down
3 changes: 2 additions & 1 deletion DSTV.Net/Implementations/FineSplitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ namespace DSTV.Net.Implementations;
internal class FineSplitter : ISplitter
{
internal static readonly ISplitter Instance = new Lazy<FineSplitter>(() => new FineSplitter()).Value;
internal static readonly string[] Separator = {" "};

/// <summary>
/// Splitter for full carefully splitting - saving all lexemes
/// </summary>
public string[] Split(string input) => input.Split(new [] {" "}, StringSplitOptions.RemoveEmptyEntries);
public string[] Split(string input) => input.Split(Separator, StringSplitOptions.RemoveEmptyEntries);
}
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
<NoWarn>$(NoWarn);1591;1701;1702;1705;VSX1000;NU1603;CA1014;NU5125</NoWarn>
<NoWarn>$(NoWarn);1591;1701;1702;1705;VSX1000;NU1603;CA1014;NU5125;CA1510</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Platform>AnyCPU</Platform>

Expand Down