Ejemplo n.º 1
0
        public override object Clone()
        {
            Tolerance entity = new Tolerance
            {
                //EntityObject properties
                Layer = (Layer) this.Layer.Clone(),
                Linetype = (Linetype) this.Linetype.Clone(),
                Color = (AciColor) this.Color.Clone(),
                Lineweight = this.Lineweight,
                Transparency = (Transparency) this.Transparency.Clone(),
                LinetypeScale = this.LinetypeScale,
                Normal = this.Normal,
                IsVisible = this.IsVisible,
                //Tolerance properties
                Entry1 = (ToleranceEntry) this.entry1.Clone(),
                Entry2 = (ToleranceEntry) this.entry2.Clone(),
                Height = this.height,
                ShowProjectedToleranceZoneSymbol = this.showProjectedToleranceZoneSymbol,
                DatumIdentifier = this.datumIdentifier,
                Style = (DimensionStyle) this.style.Clone(),
                Position = this.position,
                Rotation = this.rotation
            };

            foreach (XData data in this.XData.Values)
                entity.XData.Add((XData) data.Clone());

            return entity;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts the string representation of a tolerance to its tolerance entity equivalent.
        /// </summary>
        /// <param name="s">A string that represents a tolerance to convert.</param>
        /// <returns>The Tolerance entity equivalent to the tolerance contained in s.</returns>
        public static Tolerance ParseRepresentation(string s)
        {
            string[] lines = Regex.Split(s, "\\^J");

            ToleranceEntry t1 = null;
            ToleranceEntry t2 = null;
            string height = string.Empty;
            bool showProjSymbol = false;
            string datumIdentifier = string.Empty;

            for (int i = 0; i < lines.Length; i++)
            {
                string line = lines[i];
                if (line.StartsWith("{") || line.StartsWith("%%v"))
                {
                    switch (i)
                    {
                        case 0:
                            t1 = ParseToleranceEntry(line);
                            break;
                        case 1:
                            t2 = ParseToleranceEntry(line);
                            break;
                    }
                }
                else
                {
                    if (i == lines.Length - 1)
                    {
                        datumIdentifier = line;
                    }
                    else
                    {
                        StringBuilder value = new StringBuilder();

                        CharEnumerator chars = line.GetEnumerator();
                        while (chars.MoveNext())
                        {
                            char token = chars.Current;
                            if (token == '{')
                            {
                                char symbol = Symbol(chars);
                                if (symbol == 'p')
                                    showProjSymbol = true;
                            }
                            else
                            {
                                value.Append(token);
                            }
                        }
                        height = value.ToString();
                    }
                }
            }

            Tolerance tolerance = new Tolerance
            {
                Entry1 = t1,
                Entry2 = t2,
                Height = height,
                ShowProjectedToleranceZoneSymbol = showProjSymbol,
                DatumIdentifier = datumIdentifier
            };

            return tolerance;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Tries to convert the specified string representation of a tolerance to its tolerance entity equivalent.
 /// A return value indicates whether the conversion succeeded or failed.
 /// </summary>
 /// <param name="s">A string that represents the tolerance to convert.</param>
 /// <param name="result">If the conversion has been successful, it contains the tolerance entity equivalent to the string representation; otherwise, null.</param>
 /// <returns>True if the string was converted successfully; otherwise, false.</returns>
 public static bool TryParseRepresentation(string s, out Tolerance result)
 {
     try
     {
         result = ParseRepresentation(s);
     }
     catch
     {
         result = null;
         return false;
     }
     return true;
 }
Ejemplo n.º 4
0
        private void WriteTolerance(Tolerance tolerance)
        {
            this.chunk.Write(100, SubclassMarker.Tolerance);

            this.chunk.Write(3, this.EncodeNonAsciiCharacters(tolerance.Style.Name));

            this.chunk.Write(10, tolerance.Position.X);
            this.chunk.Write(20, tolerance.Position.Y);
            this.chunk.Write(30, tolerance.Position.Z);

            string rep = tolerance.ToStringRepresentation();
            this.chunk.Write(1, this.EncodeNonAsciiCharacters(rep));

            this.chunk.Write(210, tolerance.Normal.X);
            this.chunk.Write(220, tolerance.Normal.Y);
            this.chunk.Write(230, tolerance.Normal.Z);

            double angle = tolerance.Rotation*MathHelper.DegToRad;
            Vector3 xAxis = new Vector3(Math.Cos(angle), Math.Sin(angle), 0.0);
            xAxis = MathHelper.Transform(xAxis, tolerance.Normal, CoordinateSystem.Object, CoordinateSystem.World);

            this.chunk.Write(11, xAxis.X);
            this.chunk.Write(21, xAxis.Y);
            this.chunk.Write(31, xAxis.Z);

        }
Ejemplo n.º 5
0
        /// <summary>
        /// Resets the leader hook position according to the annotation position.
        /// </summary>
        private void ResetHookPosition()
        {
            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;
            }

            Vector3 ocsHook;

            switch (this.annotation.Type)
            {
            case EntityType.MText:
                MText mText = (MText)this.annotation;
                ocsHook = MathHelper.Transform(mText.Position, this.Normal, CoordinateSystem.World, CoordinateSystem.Object);
                int mTextSide = Math.Sign(ocsHook.X - this.vertexes[this.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;
                    }
                    this.vertexes[this.vertexes.Count - 1] = new Vector2(ocsHook.X + xOffset, ocsHook.Y) - this.offset;
                }
                else
                {
                    ocsHook -= new Vector3(mTextSide * textOffset * dimScale, textOffset * dimScale, 0.0);
                    mText.AttachmentPoint = mTextSide >= 0 ? MTextAttachmentPoint.BottomLeft : MTextAttachmentPoint.BottomRight;
                    this.vertexes[this.vertexes.Count - 1] = new Vector2(ocsHook.X, ocsHook.Y) - this.offset;
                }
                mText.Height = textHeight * dimScale;
                mText.Color  = textColor.IsByBlock ? AciColor.ByLayer : textColor;
                break;

            case EntityType.Insert:
                Insert ins = (Insert)this.annotation;
                ocsHook = MathHelper.Transform(ins.Position, this.Normal, CoordinateSystem.World, CoordinateSystem.Object);
                this.vertexes[this.vertexes.Count - 1] = new Vector2(ocsHook.X, ocsHook.Y) - this.offset;
                ins.Color = textColor.IsByBlock ? AciColor.ByLayer : textColor;
                break;

            case EntityType.Tolerance:
                Tolerance tol = (Tolerance)this.annotation;
                ocsHook = MathHelper.Transform(tol.Position, this.Normal, CoordinateSystem.World, CoordinateSystem.Object);
                this.vertexes[this.vertexes.Count - 1] = new Vector2(ocsHook.X, ocsHook.Y) - this.offset;
                tol.Color = textColor.IsByBlock ? AciColor.ByLayer : textColor;
                break;

            case EntityType.Text:
                Text text = (Text)this.annotation;
                ocsHook = MathHelper.Transform(text.Position, this.Normal, CoordinateSystem.World, CoordinateSystem.Object);
                int textSide = Math.Sign(ocsHook.X - this.vertexes[this.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;
                    }
                    this.vertexes[this.vertexes.Count - 1] = new Vector2(ocsHook.X + xOffset, ocsHook.Y) - this.offset;
                }
                else
                {
                    ocsHook       -= new Vector3(textSide * textOffset * dimScale, textOffset * dimScale, 0.0);
                    text.Alignment = textSide >= 0 ? TextAlignment.BottomLeft : TextAlignment.BottomRight;
                    this.vertexes[this.vertexes.Count - 1] = new Vector2(ocsHook.X, ocsHook.Y) - this.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.", this.annotation.Type));
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Updates the leader hook (last leader vertex) according to the actual annotation position.
        /// </summary>
        /// <remarks>
        /// This method should be manually called if the annotation position is modified, or the leader properties like Style, Annotation, TextVerticalPosition, and/or Offset.
        /// </remarks>
        public void Update()
        {
            if (this.vertexes.Count < 2)
            {
                throw new Exception("The leader vertexes list requires at least two points.");
            }

            if (this.annotation == null)
            {
                return;
            }

            Vector3 ocsHook;

            switch (this.annotation.Type)
            {
            case EntityType.MText:
                MText mText = (MText)this.annotation;
                ocsHook = MathHelper.Transform(mText.Position, this.normal, CoordinateSystem.World, CoordinateSystem.Object);
                int mTextSide = Math.Sign(ocsHook.X - this.vertexes[this.vertexes.Count - 2].X);

                if (this.TextVerticalPosition == LeaderTextVerticalPosition.Centered)
                {
                    if (mTextSide < 0 && mText.AttachmentPoint == MTextAttachmentPoint.TopLeft)
                    {
                        mText.AttachmentPoint = MTextAttachmentPoint.TopRight;
                    }
                    else if (mTextSide > 0 && mText.AttachmentPoint == MTextAttachmentPoint.TopRight)
                    {
                        mText.AttachmentPoint = MTextAttachmentPoint.TopLeft;
                    }
                    else if (mTextSide < 0 && mText.AttachmentPoint == MTextAttachmentPoint.MiddleLeft)
                    {
                        mText.AttachmentPoint = MTextAttachmentPoint.MiddleRight;
                    }
                    else if (mTextSide > 0 && mText.AttachmentPoint == MTextAttachmentPoint.MiddleRight)
                    {
                        mText.AttachmentPoint = MTextAttachmentPoint.MiddleLeft;
                    }
                    else if (mTextSide < 0 && mText.AttachmentPoint == MTextAttachmentPoint.BottomLeft)
                    {
                        mText.AttachmentPoint = MTextAttachmentPoint.BottomRight;
                    }
                    else if (mTextSide > 0 && mText.AttachmentPoint == MTextAttachmentPoint.BottomRight)
                    {
                        mText.AttachmentPoint = MTextAttachmentPoint.BottomLeft;
                    }

                    double xOffset = 0.0;
                    switch (mText.AttachmentPoint)
                    {
                    case MTextAttachmentPoint.TopLeft:
                    case MTextAttachmentPoint.MiddleLeft:
                    case MTextAttachmentPoint.BottomLeft:
                        xOffset = -this.style.DIMGAP * this.style.DIMSCALE;
                        break;

                    case MTextAttachmentPoint.TopCenter:
                    case MTextAttachmentPoint.MiddleCenter:
                    case MTextAttachmentPoint.BottomCenter:
                        xOffset = 0.0;
                        break;

                    case MTextAttachmentPoint.TopRight:
                    case MTextAttachmentPoint.MiddleRight:
                    case MTextAttachmentPoint.BottomRight:
                        xOffset = this.style.DIMGAP * this.style.DIMSCALE;
                        break;
                    }
                    this.vertexes[this.vertexes.Count - 1] = new Vector2(ocsHook.X + xOffset, ocsHook.Y) + this.offset;
                }
                else
                {
                    ocsHook -= new Vector3(mTextSide * this.style.DIMGAP * this.style.DIMSCALE, this.style.DIMGAP * this.style.DIMSCALE, 0.0);
                    mText.AttachmentPoint = mTextSide >= 0 ? MTextAttachmentPoint.BottomLeft : MTextAttachmentPoint.BottomRight;
                    this.vertexes[this.vertexes.Count - 1] = new Vector2(ocsHook.X, ocsHook.Y) + this.offset;
                }
                mText.Height     = this.style.DIMTXT * this.style.DIMSCALE;
                mText.Color      = this.style.DIMCLRT.IsByBlock ? AciColor.ByLayer : this.style.DIMCLRT;
                this.hasHookline = true;
                break;

            case EntityType.Insert:
                Insert ins = (Insert)this.annotation;
                ocsHook = MathHelper.Transform(ins.Position, this.normal, CoordinateSystem.World, CoordinateSystem.Object);
                this.vertexes[this.vertexes.Count - 1] = new Vector2(ocsHook.X, ocsHook.Y) + this.offset;
                ins.Color        = this.style.DIMCLRT.IsByBlock ? AciColor.ByLayer : this.style.DIMCLRT;
                this.hasHookline = false;
                break;

            case EntityType.Tolerance:
                Tolerance tol = (Tolerance)this.annotation;
                ocsHook = MathHelper.Transform(tol.Position, this.normal, CoordinateSystem.World, CoordinateSystem.Object);
                this.vertexes[this.vertexes.Count - 1] = new Vector2(ocsHook.X, ocsHook.Y) + this.offset;
                tol.Color        = this.style.DIMCLRT.IsByBlock ? AciColor.ByLayer : this.style.DIMCLRT;
                this.hasHookline = false;
                break;

            case EntityType.Text:
                Text text = (Text)this.annotation;
                ocsHook = MathHelper.Transform(text.Position, this.normal, CoordinateSystem.World, CoordinateSystem.Object);
                int textSide = Math.Sign(ocsHook.X - this.vertexes[this.vertexes.Count - 2].X);
                ocsHook       -= new Vector3(textSide * this.style.DIMGAP * this.style.DIMSCALE, this.style.DIMGAP * this.style.DIMSCALE, 0.0);
                text.Alignment = textSide >= 0 ? TextAlignment.BottomLeft : TextAlignment.BottomRight;
                text.Height    = this.style.DIMTXT * this.style.DIMSCALE;
                text.Color     = this.style.DIMCLRT.IsByBlock ? AciColor.ByLayer : this.style.DIMCLRT;
                this.vertexes[this.vertexes.Count - 1] = new Vector2(ocsHook.X, ocsHook.Y) + this.offset;
                this.hasHookline = true;
                break;

            default:
                throw new Exception(string.Format("The entity type: {0} not supported as a leader annotation.", this.annotation.Type));
            }
        }
Ejemplo n.º 7
0
        /// <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;
            }

            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  xOffset   = 0.0;
                int     mTextSide = Math.Sign(dir.X);
                if (this.TextVerticalPosition == LeaderTextVerticalPosition.Centered)
                {
                    if (mTextSide < 0 && mText.AttachmentPoint == MTextAttachmentPoint.TopLeft)
                    {
                        mText.AttachmentPoint = MTextAttachmentPoint.TopRight;
                    }
                    else if (mTextSide > 0 && mText.AttachmentPoint == MTextAttachmentPoint.TopRight)
                    {
                        mText.AttachmentPoint = MTextAttachmentPoint.TopLeft;
                    }
                    else if (mTextSide < 0 && mText.AttachmentPoint == MTextAttachmentPoint.MiddleLeft)
                    {
                        mText.AttachmentPoint = MTextAttachmentPoint.MiddleRight;
                    }
                    else if (mTextSide > 0 && mText.AttachmentPoint == MTextAttachmentPoint.MiddleRight)
                    {
                        mText.AttachmentPoint = MTextAttachmentPoint.MiddleLeft;
                    }
                    else if (mTextSide < 0 && mText.AttachmentPoint == MTextAttachmentPoint.BottomLeft)
                    {
                        mText.AttachmentPoint = MTextAttachmentPoint.BottomRight;
                    }
                    else if (mTextSide > 0 && mText.AttachmentPoint == MTextAttachmentPoint.BottomRight)
                    {
                        mText.AttachmentPoint = MTextAttachmentPoint.BottomLeft;
                    }

                    switch (mText.AttachmentPoint)
                    {
                    case MTextAttachmentPoint.TopLeft:
                    case MTextAttachmentPoint.MiddleLeft:
                    case MTextAttachmentPoint.BottomLeft:
                        xOffset = -this.style.TextOffset * this.style.DimScaleOverall;
                        break;

                    case MTextAttachmentPoint.TopCenter:
                    case MTextAttachmentPoint.MiddleCenter:
                    case MTextAttachmentPoint.BottomCenter:
                        xOffset = 0.0;
                        break;

                    case MTextAttachmentPoint.TopRight:
                    case MTextAttachmentPoint.MiddleRight:
                    case MTextAttachmentPoint.BottomRight:
                        xOffset = this.style.TextOffset * this.style.DimScaleOverall;
                        break;
                    }
                    position = hook;
                }
                else
                {
                    position = hook + new Vector2(mTextSide * this.style.TextOffset * this.style.DimScaleOverall, this.style.TextOffset * this.style.DimScaleOverall);
                    mText.AttachmentPoint = mTextSide >= 0 ? MTextAttachmentPoint.BottomLeft : MTextAttachmentPoint.BottomRight;
                }

                position         = position - this.offset;
                mText.Position   = MathHelper.Transform(new Vector3(position.X - xOffset, position.Y, this.elevation), this.Normal, CoordinateSystem.Object, CoordinateSystem.World);
                mText.Height     = this.style.TextHeight * this.style.DimScaleOverall;
                mText.Color      = this.style.TextColor.IsByBlock ? AciColor.ByLayer : this.style.TextColor;
                this.hasHookLine = true;
                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        = this.style.TextColor.IsByBlock ? AciColor.ByLayer : this.style.TextColor;
                this.hasHookLine = false;
                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        = this.style.TextColor.IsByBlock ? AciColor.ByLayer : this.style.TextColor;
                this.hasHookLine = false;
                break;

            case EntityType.Text:
                Text    text     = (Text)this.annotation;
                Vector2 textDir  = this.vertexes[this.vertexes.Count - 1] - this.vertexes[this.vertexes.Count - 2];
                int     textSide = Math.Sign(textDir.X);
                position         = hook + new Vector2(textSide * this.style.TextOffset * this.style.DimScaleOverall, this.style.TextOffset * this.style.DimScaleOverall) - this.offset;
                text.Position    = MathHelper.Transform(new Vector3(position.X, position.Y, this.elevation), this.Normal, CoordinateSystem.Object, CoordinateSystem.World);
                text.Alignment   = textSide >= 0 ? TextAlignment.BottomLeft : TextAlignment.BottomRight;
                text.Height      = this.style.TextHeight * this.style.DimScaleOverall;
                text.Color       = this.style.TextColor.IsByBlock ? AciColor.ByLayer : this.style.TextColor;
                this.hasHookLine = true;
                break;

            default:
                throw new Exception(string.Format("The entity type: {0} not supported as a leader annotation.", this.annotation.Type));
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Converts the string representation of a tolerance to its tolerance entity equivalent.
        /// </summary>
        /// <param name="s">A string that represents a tolerance to convert.</param>
        /// <returns>The Tolerance entity equivalent to the tolerance contained in s.</returns>
        public static Tolerance ParseRepresentation(string s)
        {
            string[] lines = Regex.Split(s, "\\^J");

            ToleranceEntry t1              = null;
            ToleranceEntry t2              = null;
            string         height          = string.Empty;
            bool           showProjSymbol  = false;
            string         datumIdentifier = string.Empty;

            for (int i = 0; i < lines.Length; i++)
            {
                string line = lines[i];
                if (line.StartsWith("{") || line.StartsWith("%%v"))
                {
                    switch (i)
                    {
                    case 0:
                        t1 = ParseToleranceEntry(line);
                        break;

                    case 1:
                        t2 = ParseToleranceEntry(line);
                        break;
                    }
                }
                else
                {
                    if (i == lines.Length - 1)
                    {
                        datumIdentifier = line;
                    }
                    else
                    {
                        StringBuilder value = new StringBuilder();

                        CharEnumerator chars = line.GetEnumerator();
                        while (chars.MoveNext())
                        {
                            char token = chars.Current;
                            if (token == '{')
                            {
                                char symbol = Symbol(chars);
                                if (symbol == 'p')
                                {
                                    showProjSymbol = true;
                                }
                            }
                            else
                            {
                                value.Append(token);
                            }
                        }
                        height = value.ToString();
                    }
                }
            }

            Tolerance tolerance = new Tolerance
            {
                Entry1 = t1,
                Entry2 = t2,
                Height = height,
                ShowProjectedToleranceZoneSymbol = showProjSymbol,
                DatumIdentifier = datumIdentifier
            };

            return(tolerance);
        }
Ejemplo n.º 9
0
        private void Tolerance_DimStyleChanged(Tolerance sender, TableObjectChangedEventArgs<DimensionStyle> e)
        {
            this.dimStyles.References[e.OldValue.Name].Remove(sender);

            e.NewValue = this.dimStyles.Add(e.NewValue);
            this.dimStyles.References[e.NewValue.Name].Add(sender);
        }
Ejemplo n.º 10
0
        /// <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));
            }
        }
Ejemplo n.º 11
0
        private static void ToleranceEntity()
        {
            ToleranceEntry entry = new ToleranceEntry
            {
                GeometricSymbol = ToleranceGeometricSymbol.Symmetry,
                Tolerance1 = new ToleranceValue(true, "12.5", ToleranceMaterialCondition.Maximum)
            };
            Tolerance tolerance = new Tolerance();
            tolerance.Entry1 = entry;
            tolerance.Rotation = 30;

            DxfDocument doc = new DxfDocument();
            doc.AddEntity(tolerance);
            doc.Save("Tolerance.dxf");

            DxfDocument dxf = DxfDocument.Load("Tolerance.dxf");
            dxf.Save("Test.dxf");
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Resets the annotation position according to the leader hook.
        /// </summary>
        private void ResetAnnotationPosition()
        {
            if (this.vertexes.Count < 2)
            {
                throw new DxfException("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 mTextdir     = this.vertexes[this.vertexes.Count - 1] - this.vertexes[this.vertexes.Count - 2];
                double  mTextXoffset = 0.0;
                int     mTextSide    = Math.Sign(mTextdir.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.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;

            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;

            default:
                throw new DxfException(string.Format("The entity type: {0} not supported as a leader annotation.", this.annotation.Type));
            }
        }