Skip to content

Commit

Permalink
Feature/add what is needed (#58)
Browse files Browse the repository at this point in the history
* Fixed warnings that were treated as errors

* Made needed fields public

* Added IsNotch flag extraction from contour point

* Fixed Errors

* Added Test

* Апнул версию

* Disabled some warnings

* Fixed Error

---------

Co-authored-by: rgaynetdinov <[email protected]>
  • Loading branch information
Rinatich and rgaynetdinov authored Feb 10, 2025
1 parent 1e200d3 commit acd412c
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 68 deletions.
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 @@ -298,6 +298,36 @@ public async Task TestTupleParseException()
#endif
}

/// <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>
2 changes: 1 addition & 1 deletion DSTV.Net/DSTV.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<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;net8.0;net9.0;netstandard2.0</TargetFrameworks>
<Version>1.2.1</Version>
<Version>1.3.0</Version>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>DSTV.Net.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
Expand Down
15 changes: 7 additions & 8 deletions DSTV.Net/Data/Contour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,19 @@ public record Contour : DstvElement
/// </summary>
public IReadOnlyList<DstvContourPoint> PointList => _pointList;

private readonly List<DstvContourPoint> _pointList;

/// <summary>
/// Gets the <see cref="ContourType"/> of the contour.
/// </summary>
public ContourType Type => _type;

private readonly List<DstvContourPoint> _pointList;
public ContourType Type { get; }

// ReSharper disable once NotAccessedField.Local
private readonly ContourType _type;
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 @@ -86,7 +85,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 @@ -138,7 +137,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}";
}
21 changes: 10 additions & 11 deletions DSTV.Net/Data/DstvHole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@ 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
public double Depth { get; }

/// <summary>
/// Gets the diameter of the hole. Represents the size of the hole in the object, defined during construction.
/// </summary>
public double Diameter => Diam;

//0 if through
private readonly double _depth;
protected readonly double Diam;
public double Diameter { get; }

protected DstvHole(string flCode, double xCoord, double yCoord, double diam, double depth) : base(flCode, xCoord,
yCoord)
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 @@ -56,8 +55,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 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;CA2263;CA1515</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Platform>AnyCPU</Platform>

Expand Down

0 comments on commit acd412c

Please sign in to comment.