Esempio n. 1
0
        private void EstimateUnitConversionScale()
        {
            using (var reader = new AdvancedLineStreamReader(_filePath))
            {
                while (!reader.EndOfStream)
                {
                    var(successful, line) = reader.FindLineUntil(MatchDrillCommand, MatchEndOfFile);

                    if (successful)
                    {
                        var value = MatchValueCommand.Matches(line)[0].Groups[2].Value.Trim('-');

                        if (CoordinateSystem == CoordinateSystem.INCH)
                        {
                            SetUnitConversionScale(1d / 10000d);
                        }
                        else if (value.Length <= 5)
                        {
                            SetUnitConversionScale(1d / 100);
                        }
                        else
                        {
                            SetUnitConversionScale(1d / 1000);
                        }
                    }

                    break;
                }
            }
        }
Esempio n. 2
0
        private void ReadHeader()
        {
            using (var reader = new AdvancedLineStreamReader(_filePath))
            {
                while (!reader.EndOfStream)
                {
                    var line = reader.ReadLine()?.Trim();

                    if (MatchCoordinatesCommand.IsMatch(line))
                    {
                        CoordinateSystem = MatchCoordinatesCommand.Matches(line)[0].Groups[1].Value.StartsWith("METRIC", StringComparison.OrdinalIgnoreCase) ? CoordinateSystem.METRIC : CoordinateSystem.INCH;
                        if (MatchDecimalPointNotationStyleCommand.IsMatch(line))
                        {
                            TrailingZeroSuppressionStyle = line.EndsWith("LZ", StringComparison.OrdinalIgnoreCase) ? TrailingZeroSuppressionStyle.LZ : TrailingZeroSuppressionStyle.TZ;
                        }
                    }
                    else if (MatchVersionCommand.IsMatch(line))
                    {
                        Version = int.Parse(MatchVersionCommand.Matches(line)[0].Groups[1].Value);
                    }
                    else if (MatchFormatCommand.IsMatch(line))
                    {
                        Format = int.Parse(MatchFormatCommand.Matches(line)[0].Groups[1].Value);
                    }
                    else if (MatchToolCommand.IsMatch(line))
                    {
                        var match = MatchToolCommand.Matches(line)[0];
                        Tools[match.Groups[1].Value] = double.Parse(match.Groups[2].Value);
                    }
                    else if (
                        MatchDrillCommand.IsMatch(line) ||
                        MatchEndOfHeaderCommand.IsMatch(line)
                        )
                    {
                        break;
                    }
                }
            }
        }