internal DimensionStyle(string name, bool checkName) : base(name, DxfObjectCode.DimStyle, checkName) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException("name", "The dimension style name should be at least one character long."); } this.IsReserved = name.Equals(DefaultName, StringComparison.OrdinalIgnoreCase); // dimension and extension lines this.dimclrd = AciColor.ByBlock; this.dimltype = Linetype.ByBlock; this.dimlwd = Lineweight.ByBlock; this.dimdle = 0.0; this.dimdli = 0.38; this.dimsd1 = false; this.dimsd2 = false; this.dimclre = AciColor.ByBlock; this.dimltex1 = Linetype.ByBlock; this.dimltex2 = Linetype.ByBlock; this.dimlwe = Lineweight.ByBlock; this.dimse1 = false; this.dimse2 = false; this.dimexo = 0.0625; this.dimexe = 0.18; this.dimfxlon = false; this.dimfxl = 1.0; // symbols and arrows this.dimldrblk = null; this.dimblk1 = null; this.dimblk2 = null; this.dimasz = 0.18; this.dimcen = 0.09; // text this.dimtxsty = TextStyle.Default; this.dimclrt = AciColor.ByBlock; this.dimtfillclr = null; this.dimtxt = 0.18; this.dimtad = DimensionStyleTextVerticalPlacement.Centered; this.dimjust = DimensionStyleTextHorizontalPlacement.Centered; this.dimgap = 0.09; this.dimtih = false; this.dimtoh = false; this.dimtxtdirection = DimensionStyleTextDirection.LeftToRight; this.dimtfac = 1.0; // fit this.dimtofl = false; this.dimsoxd = true; this.dimscale = 1.0; this.dimatfit = DimensionStyleFitOptions.BestFit; this.dimtix = false; this.dimtmove = DimensionStyleFitTextMove.BesideDimLine; // primary units this.dimdec = 4; this.dimadec = 0; this.dimPrefix = string.Empty; this.dimSuffix = string.Empty; this.dimdsep = '.'; this.dimlfac = 1.0; this.dimaunit = AngleUnitType.DecimalDegrees; this.dimlunit = LinearUnitType.Decimal; this.dimfrac = FractionFormatType.Horizontal; this.suppressLinearLeadingZeros = false; this.suppressLinearTrailingZeros = false; this.suppressZeroFeet = true; this.suppressZeroInches = true; this.suppressAngularLeadingZeros = false; this.suppressAngularTrailingZeros = false; this.dimrnd = 0.0; // alternate units this.alternateUnits = new DimensionStyleAlternateUnits(); // tolerances this.tolerances = new DimensionStyleTolerances(); }
/// <summary> /// Resets the annotation position according to the leader hook. /// </summary> private void ResetAnnotationPosition() { DimensionStyleOverride styleOverride; DimensionStyleTextVerticalPlacement textVerticalPlacement = this.Style.TextVerticalPlacement; if (this.StyleOverrides.TryGetValue(DimensionStyleOverrideType.TextVerticalPlacement, out styleOverride)) { textVerticalPlacement = (DimensionStyleTextVerticalPlacement)styleOverride.Value; } double textGap = this.Style.TextOffset; if (this.StyleOverrides.TryGetValue(DimensionStyleOverrideType.TextOffset, out styleOverride)) { textGap = (double)styleOverride.Value; } double dimScale = this.Style.DimScaleOverall; if (this.StyleOverrides.TryGetValue(DimensionStyleOverrideType.DimScaleOverall, out styleOverride)) { dimScale = (double)styleOverride.Value; } double textHeight = this.Style.TextHeight; if (this.StyleOverrides.TryGetValue(DimensionStyleOverrideType.TextHeight, out styleOverride)) { textHeight = (double)styleOverride.Value; } AciColor textColor = this.Style.TextColor; if (this.StyleOverrides.TryGetValue(DimensionStyleOverrideType.TextColor, out styleOverride)) { textColor = (AciColor)styleOverride.Value; } Vector2 hook = this.Hook; Vector2 position; Vector2 textOffset; Vector2 dir = this.Direction; int side; textGap *= dimScale; switch (this.annotation.Type) { case EntityType.MText: MText mText = (MText)this.annotation; side = MathHelper.Sign(dir.X); if (side == 0) { side = MathHelper.Sign(dir.Y); } if (mText.Rotation > 90.0 && mText.Rotation <= 270.0) { side *= -1; } if (side >= 0) { switch (mText.AttachmentPoint) { case MTextAttachmentPoint.TopRight: mText.AttachmentPoint = MTextAttachmentPoint.TopLeft; break; case MTextAttachmentPoint.MiddleRight: mText.AttachmentPoint = MTextAttachmentPoint.MiddleLeft; break; case MTextAttachmentPoint.BottomRight: mText.AttachmentPoint = MTextAttachmentPoint.BottomLeft; break; } } else { switch (mText.AttachmentPoint) { case MTextAttachmentPoint.TopLeft: mText.AttachmentPoint = MTextAttachmentPoint.TopRight; break; case MTextAttachmentPoint.MiddleLeft: mText.AttachmentPoint = MTextAttachmentPoint.MiddleRight; break; case MTextAttachmentPoint.BottomLeft: mText.AttachmentPoint = MTextAttachmentPoint.BottomRight; break; } } textOffset = textVerticalPlacement == DimensionStyleTextVerticalPlacement.Centered ? new Vector2(side * textGap, 0.0) : new Vector2(side * textGap, textGap); position = hook + this.offset + Vector2.Rotate(textOffset, mText.Rotation * MathHelper.DegToRad); mText.Position = MathHelper.Transform(position, Normal, this.elevation); mText.Height = textHeight * dimScale; mText.Color = textColor.IsByBlock ? AciColor.ByLayer : textColor; break; case EntityType.Text: Text text = (Text)this.annotation; side = MathHelper.Sign(dir.X); if (side == 0) { side = MathHelper.Sign(dir.Y); } if (text.Rotation > 90.0 && text.Rotation <= 270.0) { side *= -1; } if (side >= 0) { switch (text.Alignment) { case TextAlignment.TopRight: text.Alignment = TextAlignment.TopLeft; break; case TextAlignment.MiddleRight: text.Alignment = TextAlignment.MiddleLeft; break; case TextAlignment.BottomRight: text.Alignment = TextAlignment.BottomLeft; break; case TextAlignment.BaselineRight: text.Alignment = TextAlignment.BaselineLeft; break; } } else { switch (text.Alignment) { case TextAlignment.TopLeft: text.Alignment = TextAlignment.TopRight; break; case TextAlignment.MiddleLeft: text.Alignment = TextAlignment.MiddleRight; break; case TextAlignment.BottomLeft: text.Alignment = TextAlignment.BottomRight; break; case TextAlignment.BaselineLeft: text.Alignment = TextAlignment.BaselineRight; break; } } textOffset = textVerticalPlacement == DimensionStyleTextVerticalPlacement.Centered ? new Vector2(side * textGap, 0.0) : new Vector2(side * textGap, textGap); position = hook + this.offset + Vector2.Rotate(textOffset, text.Rotation * MathHelper.DegToRad); text.Position = MathHelper.Transform(position, this.Normal, this.elevation); text.Height = textHeight * dimScale; text.Color = textColor.IsByBlock ? AciColor.ByLayer : textColor; break; case EntityType.Insert: Insert ins = (Insert)this.annotation; position = hook + this.offset; ins.Position = MathHelper.Transform(position, this.Normal, this.elevation); ins.Color = textColor.IsByBlock ? AciColor.ByLayer : textColor; break; case EntityType.Tolerance: Tolerance tol = (Tolerance)this.annotation; position = hook + this.offset; tol.Position = MathHelper.Transform(position, this.Normal, this.elevation); tol.Color = textColor.IsByBlock ? AciColor.ByLayer : textColor; break; default: throw new Exception(string.Format("The entity type: {0} not supported as a leader annotation.", this.annotation.Type)); } }
/// <summary> /// Resets the annotation position according to the leader hook. /// </summary> private void ResetAnnotationPosition() { if (this.vertexes.Count < 2) { throw new Exception("The leader vertexes list requires at least two points."); } if (this.annotation == null) { return; } DimensionStyleOverride styleOverride; DimensionStyleTextVerticalPlacement textVerticalPlacement = this.Style.TextVerticalPlacement; if (this.StyleOverrides.TryGetValue(DimensionStyleOverrideType.TextVerticalPlacement, out styleOverride)) { textVerticalPlacement = (DimensionStyleTextVerticalPlacement)styleOverride.Value; } double textOffset = this.Style.TextOffset; if (this.StyleOverrides.TryGetValue(DimensionStyleOverrideType.TextOffset, out styleOverride)) { textOffset = (double)styleOverride.Value; } double dimScale = this.Style.DimScaleOverall; if (this.StyleOverrides.TryGetValue(DimensionStyleOverrideType.DimScaleOverall, out styleOverride)) { dimScale = (double)styleOverride.Value; } double textHeight = this.Style.TextHeight; if (this.StyleOverrides.TryGetValue(DimensionStyleOverrideType.TextHeight, out styleOverride)) { textHeight = (double)styleOverride.Value; } AciColor textColor = this.Style.TextColor; if (this.StyleOverrides.TryGetValue(DimensionStyleOverrideType.TextColor, out styleOverride)) { textColor = (AciColor)styleOverride.Value; } Vector2 hook = this.vertexes[this.vertexes.Count - 1]; Vector2 position; switch (this.annotation.Type) { case EntityType.MText: MText mText = (MText)this.annotation; Vector2 dir = this.vertexes[this.vertexes.Count - 1] - this.vertexes[this.vertexes.Count - 2]; double mTextXoffset = 0.0; int mTextSide = Math.Sign(dir.X); if (textVerticalPlacement == DimensionStyleTextVerticalPlacement.Centered) { if (mTextSide >= 0) { mText.AttachmentPoint = MTextAttachmentPoint.MiddleLeft; mTextXoffset = -textOffset * dimScale; } else { mText.AttachmentPoint = MTextAttachmentPoint.MiddleRight; mTextXoffset = textOffset * dimScale; } position = hook; } else { position = hook + new Vector2(mTextSide * textOffset * dimScale, textOffset * dimScale); mText.AttachmentPoint = mTextSide >= 0 ? MTextAttachmentPoint.BottomLeft : MTextAttachmentPoint.BottomRight; } position = position + this.offset; mText.Position = MathHelper.Transform(new Vector3(position.X - mTextXoffset, position.Y, this.elevation), this.Normal, CoordinateSystem.Object, CoordinateSystem.World); mText.Height = textHeight * dimScale; mText.Color = textColor.IsByBlock ? AciColor.ByLayer : textColor; break; case EntityType.Insert: Insert ins = (Insert)this.annotation; position = hook + this.offset; ins.Position = MathHelper.Transform(new Vector3(position.X, position.Y, this.elevation), this.Normal, CoordinateSystem.Object, CoordinateSystem.World); ins.Color = textColor.IsByBlock ? AciColor.ByLayer : textColor; break; case EntityType.Tolerance: Tolerance tol = (Tolerance)this.annotation; position = hook + this.offset; tol.Position = MathHelper.Transform(new Vector3(position.X, position.Y, this.elevation), this.Normal, CoordinateSystem.Object, CoordinateSystem.World); tol.Color = textColor.IsByBlock ? AciColor.ByLayer : textColor; break; case EntityType.Text: Text text = (Text)this.annotation; double textXoffset = 0.0; Vector2 textDir = this.vertexes[this.vertexes.Count - 1] - this.vertexes[this.vertexes.Count - 2]; int textSide = Math.Sign(textDir.X); if (textVerticalPlacement == DimensionStyleTextVerticalPlacement.Centered) { if (textSide >= 0) { text.Alignment = TextAlignment.MiddleLeft; textXoffset = -textOffset * dimScale; } else { text.Alignment = TextAlignment.MiddleRight; textXoffset = textOffset * dimScale; } position = hook; } else { position = hook + new Vector2(textSide * textOffset * dimScale, textOffset * dimScale); text.Alignment = textSide >= 0 ? TextAlignment.BottomLeft : TextAlignment.BottomRight; } position = position + this.offset; text.Position = MathHelper.Transform(new Vector3(position.X - textXoffset, position.Y, this.elevation), this.Normal, CoordinateSystem.Object, CoordinateSystem.World); text.Height = textHeight * dimScale; text.Color = textColor.IsByBlock ? AciColor.ByLayer : textColor; break; default: throw new Exception(string.Format("The entity type: {0} not supported as a leader annotation.", this.annotation.Type)); } }
/// <summary> /// Resets the leader hook position according to the annotation position. /// </summary> private void ResetHookPosition() { if (vertexes.Count < 2) { throw new Exception("The leader vertexes list requires at least two points."); } if (annotation == null) { return; } DimensionStyleOverride styleOverride; DimensionStyleTextVerticalPlacement textVerticalPlacement = Style.TextVerticalPlacement; if (StyleOverrides.TryGetValue(DimensionStyleOverrideType.TextVerticalPlacement, out styleOverride)) { textVerticalPlacement = (DimensionStyleTextVerticalPlacement)styleOverride.Value; } double textOffset = Style.TextOffset; if (StyleOverrides.TryGetValue(DimensionStyleOverrideType.TextOffset, out styleOverride)) { textOffset = (double)styleOverride.Value; } double dimScale = Style.DimScaleOverall; if (StyleOverrides.TryGetValue(DimensionStyleOverrideType.DimScaleOverall, out styleOverride)) { dimScale = (double)styleOverride.Value; } double textHeight = Style.TextHeight; if (StyleOverrides.TryGetValue(DimensionStyleOverrideType.TextHeight, out styleOverride)) { textHeight = (double)styleOverride.Value; } AciColor textColor = Style.TextColor; if (StyleOverrides.TryGetValue(DimensionStyleOverrideType.TextColor, out styleOverride)) { textColor = (AciColor)styleOverride.Value; } Vector3 ocsHook; switch (annotation.Type) { case EntityType.MText: MText mText = (MText)annotation; ocsHook = MathHelper.Transform(mText.Position, Normal, CoordinateSystem.World, CoordinateSystem.Object); int mTextSide = Math.Sign(ocsHook.X - vertexes[vertexes.Count - 2].X); if (textVerticalPlacement == DimensionStyleTextVerticalPlacement.Centered) { double xOffset; if (mTextSide >= 0) { mText.AttachmentPoint = MTextAttachmentPoint.MiddleLeft; xOffset = -textOffset * dimScale; } else { mText.AttachmentPoint = MTextAttachmentPoint.MiddleRight; xOffset = textOffset * dimScale; } vertexes[vertexes.Count - 1] = new Vector2(ocsHook.X + xOffset, ocsHook.Y) - offset; } else { ocsHook -= new Vector3(mTextSide * textOffset * dimScale, textOffset * dimScale, 0.0); mText.AttachmentPoint = mTextSide >= 0 ? MTextAttachmentPoint.BottomLeft : MTextAttachmentPoint.BottomRight; vertexes[vertexes.Count - 1] = new Vector2(ocsHook.X, ocsHook.Y) - offset; } mText.Height = textHeight * dimScale; mText.Color = textColor.IsByBlock ? AciColor.ByLayer : textColor; break; case EntityType.Insert: Insert ins = (Insert)annotation; ocsHook = MathHelper.Transform(ins.Position, Normal, CoordinateSystem.World, CoordinateSystem.Object); vertexes[vertexes.Count - 1] = new Vector2(ocsHook.X, ocsHook.Y) - offset; ins.Color = textColor.IsByBlock ? AciColor.ByLayer : textColor; break; case EntityType.Tolerance: Tolerance tol = (Tolerance)annotation; ocsHook = MathHelper.Transform(tol.Position, Normal, CoordinateSystem.World, CoordinateSystem.Object); vertexes[vertexes.Count - 1] = new Vector2(ocsHook.X, ocsHook.Y) - offset; tol.Color = textColor.IsByBlock ? AciColor.ByLayer : textColor; break; case EntityType.Text: Text text = (Text)annotation; ocsHook = MathHelper.Transform(text.Position, Normal, CoordinateSystem.World, CoordinateSystem.Object); int textSide = Math.Sign(ocsHook.X - vertexes[vertexes.Count - 2].X); if (textVerticalPlacement == DimensionStyleTextVerticalPlacement.Centered) { double xOffset; if (textSide >= 0) { text.Alignment = TextAlignment.MiddleLeft; xOffset = -textOffset * dimScale; } else { text.Alignment = TextAlignment.MiddleRight; xOffset = textOffset * dimScale; } vertexes[vertexes.Count - 1] = new Vector2(ocsHook.X + xOffset, ocsHook.Y) - offset; } else { ocsHook -= new Vector3(textSide * textOffset * dimScale, textOffset * dimScale, 0.0); text.Alignment = textSide >= 0 ? TextAlignment.BottomLeft : TextAlignment.BottomRight; vertexes[vertexes.Count - 1] = new Vector2(ocsHook.X, ocsHook.Y) - offset; } text.Height = textHeight * dimScale; text.Color = textColor.IsByBlock ? AciColor.ByLayer : textColor; break; default: throw new Exception(string.Format("The entity type: {0} not supported as a leader annotation.", annotation.Type)); } }