Exemple #1
0
        public override object Clone()
        {
            MText entity = new MText
            {
                //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,
                //MText properties
                Position              = this.position,
                Rotation              = this.rotation,
                Height                = this.height,
                LineSpacingFactor     = this.lineSpacing,
                ParagraphHeightFactor = this.paragraphHeightFactor,
                LineSpacingStyle      = this.lineSpacingStyle,
                RectangleWidth        = this.rectangleWidth,
                AttachmentPoint       = this.attachmentPoint,
                Style = (TextStyle)this.style.Clone(),
                Value = this.text
            };

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

            return(entity);
        }
Exemple #2
0
        private MText BuildAnnotation(string text)
        {
            Vector2 hook = this.vertexes[this.vertexes.Count - 1];
            Vector2 dir  = this.vertexes[this.vertexes.Count - 1] - this.vertexes[this.vertexes.Count - 2];
            int     side = Math.Sign(dir.X);

            Vector2 position;
            MTextAttachmentPoint attachment;
            double mTextXoffset = 0.0;

            if (this.style.TextVerticalPlacement == DimensionStyleTextVerticalPlacement.Centered)
            {
                if (side >= 0)
                {
                    attachment   = MTextAttachmentPoint.MiddleLeft;
                    mTextXoffset = -this.style.TextOffset * this.style.DimScaleOverall;
                }
                else
                {
                    attachment   = MTextAttachmentPoint.MiddleRight;
                    mTextXoffset = this.style.TextOffset * this.style.DimScaleOverall;
                }
                position = hook;
            }
            else
            {
                position   = hook + new Vector2(side * this.style.TextOffset * this.style.DimScaleOverall, this.style.TextOffset * this.style.DimScaleOverall);
                attachment = side >= 0 ? MTextAttachmentPoint.BottomLeft : MTextAttachmentPoint.BottomRight;
            }

            position = position + this.offset;
            Vector3 mTextPosition = MathHelper.Transform(new Vector3(position.X - mTextXoffset, position.Y, this.elevation), this.Normal, CoordinateSystem.Object, CoordinateSystem.World);
            MText   entity        = new MText(text, mTextPosition, this.style.TextHeight * this.style.DimScaleOverall, 0.0, this.style.TextStyle)
            {
                Color           = this.style.TextColor.IsByBlock ? AciColor.ByLayer : this.style.TextColor,
                AttachmentPoint = attachment
            };

            return(entity);
        }
Exemple #3
0
        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));
            }
        }