Add a Shape Library dialog (Nest > Shape Library) for creating drawings
from built-in parametric shapes. Supports configuration presets loaded
from JSON files — ships with 136 standard pipe flanges. Parameters use
TextBox inputs with architectural unit parsing (feet/inches, fractions).
- ShapeLibraryForm with split layout: shape list, preview, parameters
- ShapePreviewControl for auto-zoom rendering with info overlay
- ArchUnits utility for parsing architectural measurements
- SetPreviewDefaults() on all ShapeDefinition subclasses
- Convention-based config discovery (Configurations/{ShapeName}.json)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
85 lines
2.3 KiB
C#
85 lines
2.3 KiB
C#
using OpenNest.IO.Bom;
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Windows.Forms;
|
|
|
|
namespace OpenNest
|
|
{
|
|
public static class ArchUnits
|
|
{
|
|
private static readonly Regex UnitRegex =
|
|
new Regex("^(?<Feet>\\d+\\.?\\d*\\s*')?\\s*(?<Inches>\\d+\\.?\\d*\\s*\")?$");
|
|
|
|
public static double ParseToInches(string input)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(input))
|
|
return 0;
|
|
|
|
var sb = new StringBuilder(input.Trim().ToLower());
|
|
|
|
sb.Replace("ft", "'");
|
|
sb.Replace("feet", "'");
|
|
sb.Replace("foot", "'");
|
|
sb.Replace("inches", "\"");
|
|
sb.Replace("inch", "\"");
|
|
sb.Replace("in", "\"");
|
|
|
|
input = Fraction.ReplaceFractionsWithDecimals(sb.ToString());
|
|
|
|
var match = UnitRegex.Match(input);
|
|
|
|
if (!match.Success)
|
|
{
|
|
if (!input.Contains("'") && !input.Contains("\""))
|
|
{
|
|
if (double.TryParse(input.Trim(), out var plainInches))
|
|
return System.Math.Round(plainInches, 8);
|
|
}
|
|
|
|
throw new FormatException("Input is not in a valid format.");
|
|
}
|
|
|
|
var feet = match.Groups["Feet"];
|
|
var inches = match.Groups["Inches"];
|
|
var totalInches = 0.0;
|
|
|
|
if (feet.Success)
|
|
{
|
|
var x = double.Parse(feet.Value.Remove(feet.Length - 1));
|
|
totalInches += x * 12;
|
|
}
|
|
|
|
if (inches.Success)
|
|
{
|
|
var x = double.Parse(inches.Value.Remove(inches.Length - 1));
|
|
totalInches += x;
|
|
}
|
|
|
|
return System.Math.Round(totalInches, 8);
|
|
}
|
|
|
|
public static double GetLengthInches(TextBox tb)
|
|
{
|
|
try
|
|
{
|
|
if (double.TryParse(tb.Text, out var d))
|
|
{
|
|
tb.ForeColor = SystemColors.WindowText;
|
|
return d;
|
|
}
|
|
|
|
var x = ParseToInches(tb.Text);
|
|
tb.ForeColor = SystemColors.WindowText;
|
|
return x;
|
|
}
|
|
catch
|
|
{
|
|
tb.ForeColor = Color.Red;
|
|
return double.NaN;
|
|
}
|
|
}
|
|
}
|
|
}
|