public bool TryGetStyleFromXDataDifference(DxfXData xdata, out DxfDimStyle style) { style = default(DxfDimStyle); var dimStyleList = xdata?.Items.OfType <DxfXDataNamedList>().FirstOrDefault(l => l.Name == XDataStyleName); if (dimStyleList == null) { // no dim style override return(false); } if (dimStyleList.Items.Count % 2 != 0) { // must be an even number return(false); } var codePairs = new List <DxfCodePair>(); for (int i = 0; i < dimStyleList.Items.Count; i += 2) { if (!(dimStyleList.Items[i] is DxfXDataInteger codeItem)) { // must alternate between int/<data> return(false); } DxfCodePair pair; var valueItem = dimStyleList.Items[i + 1]; var code = codeItem.Value; switch (DxfCodePair.ExpectedType(code).Name) { case nameof(Boolean): pair = new DxfCodePair(code, true); break; case nameof(Double) when valueItem is DxfXDataDistance dist: pair = new DxfCodePair(code, dist.Value); break; case nameof(Double) when valueItem is DxfXDataReal real: pair = new DxfCodePair(code, real.Value); break; case nameof(Double) when valueItem is DxfXDataScaleFactor scale: pair = new DxfCodePair(code, scale.Value); break; case nameof(Int16) when valueItem is DxfXDataInteger i32: pair = new DxfCodePair(code, i32.Value); break; case nameof(Int32) when valueItem is DxfXDataLong i32: pair = new DxfCodePair(code, i32.Value); break; case nameof(Int64) when valueItem is DxfXDataLong i32: pair = new DxfCodePair(code, i32.Value); break; case nameof(String) when valueItem is DxfXDataString str: pair = new DxfCodePair(code, str.Value); break; default: // unexpected code pair type return(false); } codePairs.Add(pair); } if (codePairs.Count == 0) { // no difference to apply return(false); } // if we made it this far, there is a differnce that should be applied style = Clone(); foreach (var pair in codePairs) { style.ApplyCodePair(pair); } return(true); }
public bool TryGetStyleFromXDataDifference(DxfXDataApplicationItemCollection xdataItemCollection, out DxfDimStyle style) { // style data is encoded as // 1001 DSTYLE // 1002 { // ... style overrides // 1002 } style = default(DxfDimStyle); if (xdataItemCollection == null) { return(false); } for (int i = 0; i < xdataItemCollection.Count - 1; i++) { if (xdataItemCollection[i] is DxfXDataString xdataString && xdataString.Value == XDataStyleName && xdataItemCollection[i + 1] is DxfXDataItemList itemList) { if (itemList.Items.Count % 2 != 0) { // must be an even number return(false); } var codePairs = new List <DxfCodePair>(); for (int j = 0; j < itemList.Items.Count; j += 2) { if (!(itemList.Items[j] is DxfXDataInteger codeItem)) { // must alternate between int/<data> return(false); } DxfCodePair pair; var valueItem = itemList.Items[j + 1]; var code = codeItem.Value; switch (DxfCodePair.ExpectedType(code).Name) { case nameof(Boolean): pair = new DxfCodePair(code, true); break; case nameof(Double) when valueItem is DxfXDataDistance dist: pair = new DxfCodePair(code, dist.Value); break; case nameof(Double) when valueItem is DxfXDataReal real: pair = new DxfCodePair(code, real.Value); break; case nameof(Double) when valueItem is DxfXDataScaleFactor scale: pair = new DxfCodePair(code, scale.Value); break; case nameof(Int16) when valueItem is DxfXDataInteger i32: pair = new DxfCodePair(code, i32.Value); break; case nameof(Int32) when valueItem is DxfXDataLong i32: pair = new DxfCodePair(code, i32.Value); break; case nameof(Int64) when valueItem is DxfXDataLong i32: pair = new DxfCodePair(code, i32.Value); break; case nameof(String) when valueItem is DxfXDataString str: pair = new DxfCodePair(code, str.Value); break; default: // unexpected code pair type return(false); } codePairs.Add(pair); } if (codePairs.Count == 0) { // no difference to apply return(false); } // if we made it this far, there is a difference that should be applied style = Clone(); foreach (var pair in codePairs) { style.ApplyCodePair(pair); } return(true); } } return(false); }
internal static DxfDimStyle FromBuffer(DxfCodePairBufferReader buffer) { var item = new DxfDimStyle(); while (buffer.ItemsRemain) { var pair = buffer.Peek(); if (pair.Code == 0) { break; } buffer.Advance(); switch (pair.Code) { case 70: item.StandardFlags = (int)pair.ShortValue; break; case DxfCodePairGroup.GroupCodeNumber: var groupName = DxfCodePairGroup.GetGroupName(pair.StringValue); item.ExtensionDataGroups.Add(DxfCodePairGroup.FromBuffer(buffer, groupName)); break; case 3: item.DimensioningSuffix = (pair.StringValue); break; case 4: item.AlternateDimensioningSuffix = (pair.StringValue); break; case 5: item.ArrowBlockName = (pair.StringValue); break; case 6: item.FirstArrowBlockName = (pair.StringValue); break; case 7: item.SecondArrowBlockName = (pair.StringValue); break; case 40: item.DimensioningScaleFactor = (pair.DoubleValue); break; case 41: item.DimensioningArrowSize = (pair.DoubleValue); break; case 42: item.DimensionExtensionLineOffset = (pair.DoubleValue); break; case 43: item.DimensionLineIncrement = (pair.DoubleValue); break; case 44: item.DimensionExtensionLineExtension = (pair.DoubleValue); break; case 45: item.DimensionDistanceRoundingValue = (pair.DoubleValue); break; case 46: item.DimensionLineExtension = (pair.DoubleValue); break; case 47: item.DimensionPlusTolerance = (pair.DoubleValue); break; case 48: item.DimensionMinusTolerance = (pair.DoubleValue); break; case 71: item.GenerateDimensionTolerances = BoolShort(pair.ShortValue); break; case 72: item.GenerateDimensionLimits = BoolShort(pair.ShortValue); break; case 73: item.DimensionTextInsideHorizontal = BoolShort(pair.ShortValue); break; case 74: item.DimensionTextOutsideHorizontal = BoolShort(pair.ShortValue); break; case 75: item.SuppressFirstDimensionExtensionLine = BoolShort(pair.ShortValue); break; case 76: item.SuppressSecondDimensionExtensionLine = BoolShort(pair.ShortValue); break; case 77: item.TextAboveDimensionLine = BoolShort(pair.ShortValue); break; case 78: item.DimensionUnitZeroSuppression = (DxfUnitZeroSuppression)(pair.ShortValue); break; case 79: item.DimensionAngleZeroSuppression = (DxfUnitZeroSuppression)(pair.ShortValue); break; case 140: item.DimensioningTextHeight = (pair.DoubleValue); break; case 141: item.CenterMarkSize = (pair.DoubleValue); break; case 142: item.DimensioningTickSize = (pair.DoubleValue); break; case 143: item.AlternateDimensioningScaleFactor = (pair.DoubleValue); break; case 144: item.DimensionLinearMeasurementScaleFactor = (pair.DoubleValue); break; case 145: item.DimensionVerticalTextPosition = (pair.DoubleValue); break; case 146: item.DimensionToleranceDisplaceScaleFactor = (pair.DoubleValue); break; case 147: item.DimensionLineGap = (pair.DoubleValue); break; case 148: item.AlternateDimensioningUnitRounding = (pair.DoubleValue); break; case 170: item.UseAlternateDimensioning = BoolShort(pair.ShortValue); break; case 171: item.AlternateDimensioningDecimalPlaces = (pair.ShortValue); break; case 172: item.ForceDimensionLineExtensionsOutsideIfTextExists = BoolShort(pair.ShortValue); break; case 173: item.UseSeparateArrowBlocksForDimensions = BoolShort(pair.ShortValue); break; case 174: item.ForceDimensionTextInsideExtensions = BoolShort(pair.ShortValue); break; case 175: item.SuppressOutsideExtensionDimensionLines = BoolShort(pair.ShortValue); break; case 176: item.DimensionLineColor = DxfColor.FromRawValue(pair.ShortValue); break; case 177: item.DimensionExtensionLineColor = DxfColor.FromRawValue(pair.ShortValue); break; case 178: item.DimensionTextColor = DxfColor.FromRawValue(pair.ShortValue); break; case 179: item.AngularDimensionPrecision = (pair.ShortValue); break; case 270: item.DimensionUnitFormat = (DxfUnitFormat)(pair.ShortValue); break; case 271: item.DimensionUnitToleranceDecimalPlaces = (pair.ShortValue); break; case 272: item.DimensionToleranceDecimalPlaces = (pair.ShortValue); break; case 273: item.AlternateDimensioningUnits = (DxfUnitFormat)(pair.ShortValue); break; case 274: item.AlternateDimensioningToleranceDecimalPlaces = (pair.ShortValue); break; case 275: item.DimensioningAngleFormat = (DxfAngleFormat)(pair.ShortValue); break; case 276: item.DimensionFractionFormat = (DxfDimensionFractionFormat)(pair.ShortValue); break; case 277: item.DimensionNonAngularUnits = (DxfNonAngularUnits)(pair.ShortValue); break; case 278: item.DimensionDecimalSeparatorChar = (char)(pair.ShortValue); break; case 279: item.DimensionTextMovementRule = (DxfDimensionTextMovementRule)(pair.ShortValue); break; case 280: item.DimensionTextJustification = (DxfDimensionTextJustification)(pair.ShortValue); break; case 281: item.SuppressFirstDimensionExtensionLine = BoolShort(pair.ShortValue); break; case 282: item.SuppressSecondDimensionExtensionLine = BoolShort(pair.ShortValue); break; case 283: item.DimensionToleranceVerticalJustification = (DxfJustification)(pair.ShortValue); break; case 284: item.DimensionToleranceZeroSuppression = (DxfUnitZeroSuppression)(pair.ShortValue); break; case 285: item.AlternateDimensioningZeroSupression = (DxfUnitZeroSuppression)(pair.ShortValue); break; case 286: item.AlternateDimensioningToleranceZeroSupression = (DxfUnitZeroSuppression)(pair.ShortValue); break; case 287: item.DimensionTextAndArrowPlacement = (DxfDimensionFit)(pair.ShortValue); break; case 288: item.DimensionCursorControlsTextPosition = BoolShort(pair.ShortValue); break; case 289: item.DimensionTextAndArrowPlacement = (DxfDimensionFit)(pair.ShortValue); break; case 340: item.DimensionTextStyle = (pair.StringValue); break; case 341: item.DimensionLeaderBlockName = (pair.StringValue); break; case 342: item.ArrowBlockName = (pair.StringValue); break; case 343: item.FirstArrowBlockName = (pair.StringValue); break; case 344: item.SecondArrowBlockName = (pair.StringValue); break; case 371: item.DimensionLineWeight = DxfLineWeight.FromRawValue(pair.ShortValue); break; case 372: item.DimensionExtensionLineWeight = DxfLineWeight.FromRawValue(pair.ShortValue); break; case (int)DxfXDataType.ApplicationName: item.XData = DxfXData.FromBuffer(buffer, pair.StringValue); break; default: item.TrySetPair(pair); break; } } return(item); }