예제 #1
0
        private MText BuildAnnotation(string text)
        {
            int side = Math.Sign(this.vertexes[this.vertexes.Count - 1].X - this.vertexes[this.vertexes.Count - 2].X);
            MTextAttachmentPoint attachment;
            Vector2 textOffset;

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

            Vector2 position      = this.Hook + textOffset;
            Vector3 mTextPosition = MathHelper.Transform(position, this.Normal, this.elevation);
            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
            };

            if (!MathHelper.IsZero(this.vertexes[this.vertexes.Count - 1].Y - this.vertexes[this.vertexes.Count - 2].Y))
            {
                this.HasHookline = true;
            }

            return(entity);
        }
        /// <summary>
        /// Creates a new MText that is a copy of the current instance.
        /// </summary>
        /// <returns>A new MText that is a copy of this instance.</returns>
        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);
        }
예제 #3
0
        /// <summary>
        /// Creates a new MText that is a copy of the current instance.
        /// </summary>
        /// <returns>A new MText that is a copy of this instance.</returns>
        public override object Clone()
        {
            MText entity = new MText
            {
                //EntityObject properties
                Layer         = (Layer)Layer.Clone(),
                Linetype      = (Linetype)Linetype.Clone(),
                Color         = (AciColor)Color.Clone(),
                Lineweight    = Lineweight,
                Transparency  = (Transparency)Transparency.Clone(),
                LinetypeScale = LinetypeScale,
                Normal        = Normal,
                IsVisible     = IsVisible,
                //MText properties
                Position          = position,
                Rotation          = rotation,
                Height            = height,
                LineSpacingFactor = lineSpacing,
                LineSpacingStyle  = lineSpacingStyle,
                RectangleWidth    = rectangleWidth,
                AttachmentPoint   = attachmentPoint,
                Style             = (TextStyle)style.Clone(),
                Value             = text
            };

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

            return(entity);
        }
예제 #4
0
		/*Draw Leader*/
		public static void DrawLeader(Leader xLeader, Canvas mainCanvas)
		{
			Size txtSize = new Size(0, 0);
			/*ajout du texte*/
			if (xLeader.Annotation.Type == EntityType.MText) {
				netDxf.Entities.MText mText = (netDxf.Entities.MText)xLeader.Annotation;
				txtSize = DrawMText(mText, mainCanvas);
			}
			
			if (xLeader.Annotation.Type == EntityType.Text) {
				netDxf.Entities.Text mText = (netDxf.Entities.Text)xLeader.Annotation;
				DrawText(mText, mainCanvas);
			}
			if (xLeader.Annotation.Type == EntityType.Insert) {
				netDxf.Entities.Insert mText = (netDxf.Entities.Insert)xLeader.Annotation;
				DrawInsert(mText, mainCanvas);
			}
			
			
			
			
			
			System.Windows.Shapes.Polyline wPoly = new System.Windows.Shapes.Polyline();
			
			foreach (netDxf.Vector2 xVertex in xLeader.Vertexes) {
				System.Windows.Point myPt = TypeConverter.Vertex2ToPoint(xVertex);
				myPt.Y = mainCanvas.Height - myPt.Y;
				wPoly.Points.Add(myPt);
			}
			System.Windows.Point myPt2 = TypeConverter.Vertex2ToPoint(xLeader.Hook);
			myPt2.Y = mainCanvas.Height - myPt2.Y;
			wPoly.Points.Add(myPt2);
			
			if (txtSize.Width > 0) {
				myPt2.X = myPt2.X + txtSize.Width;
				wPoly.Points.Add(myPt2);
			}
			
			xLeader.Lineweight = Lineweight.W0;
			
			TypeConverter.Entity2Shape(xLeader, wPoly);
			
			if (xLeader.ShowArrowhead == true) {
				System.Windows.Shapes.Polygon arrow = DrawUtils.GetArrowhead(xLeader.Vertexes[0], xLeader.Vertexes[1], mainCanvas);
				TypeConverter.Entity2Shape(xLeader, arrow);
				arrow.StrokeThickness = 0.1;
				arrow.Fill = arrow.Stroke;
				mainCanvas.Children.Add(arrow);
			}
			
			mainCanvas.Children.Add(wPoly);
			
			

			

		}
예제 #5
0
        private static MText DimensionText(Vector2 position, double rotation, string text, DimensionStyle style)
        {
            MText mText = new MText(text, position, style.DIMTXT * style.DIMSCALE, 0.0, style.DIMTXSTY)
            {
                Color           = style.DIMCLRT,
                AttachmentPoint = MTextAttachmentPoint.BottomCenter,
                Rotation        = rotation * MathHelper.RadToDeg
            };

            return(mText);
        }
예제 #6
0
        private MText BuildAnnotation(string text)
        {
            Vector2 dir      = this.vertexes[this.vertexes.Count - 1] - this.vertexes[this.vertexes.Count - 2];
            int     side     = Math.Sign(dir.X);
            Vector2 position = this.vertexes[this.vertexes.Count - 1] + new Vector2(side * this.style.TextOffset * this.style.DimScaleOverall, this.style.TextOffset * this.style.DimScaleOverall);
            MText   entity   = new MText(text, position, this.style.TextHeight * this.style.DimScaleOverall, 0.0, this.style.TextStyle)
            {
                Color           = this.style.TextColor.IsByBlock ? AciColor.ByLayer : this.style.TextColor,
                AttachmentPoint = side >= 0 ? MTextAttachmentPoint.BottomLeft : MTextAttachmentPoint.BottomRight
            };

            return(entity);
        }
예제 #7
0
        private MText BuildAnnotation(string text)
        {
            Vector2 dir      = this.vertexes[this.vertexes.Count - 1] - this.vertexes[this.vertexes.Count - 2];
            int     side     = Math.Sign(dir.X);
            Vector2 position = this.vertexes[this.vertexes.Count - 1] + new Vector2(side * this.style.DIMGAP * this.style.DIMSCALE, this.style.DIMGAP * this.style.DIMSCALE);
            MText   entity   = new MText(text, position, this.style.DIMTXT * this.style.DIMSCALE, 0.0, this.style.DIMTXSTY)
            {
                Color           = this.style.DIMCLRT.IsByBlock ? AciColor.ByLayer : this.style.DIMCLRT,
                AttachmentPoint = side >= 0 ? MTextAttachmentPoint.BottomLeft : MTextAttachmentPoint.BottomRight,
            };

            return(entity);
        }
예제 #8
0
        private void CalculateAnnotationDirection()
        {
            double angle = 0.0;

            if (this.annotation != null)
            {
                switch (this.annotation.Type)
                {
                case EntityType.MText:
                    MText mText = (MText)this.annotation;
                    angle = mText.Rotation;
                    switch (mText.AttachmentPoint)
                    {
                    case MTextAttachmentPoint.TopRight:
                    case MTextAttachmentPoint.MiddleRight:
                    case MTextAttachmentPoint.BottomRight:
                        angle += 180.0;
                        break;
                    }
                    break;

                case EntityType.Text:
                    Text text = (Text)this.annotation;
                    angle = text.Rotation;
                    switch (text.Alignment)
                    {
                    case TextAlignment.TopRight:
                    case TextAlignment.MiddleRight:
                    case TextAlignment.BottomRight:
                    case TextAlignment.BaselineRight:
                        angle += 180.0;
                        break;
                    }
                    break;

                case EntityType.Insert:
                    angle = ((Insert)this.annotation).Rotation;
                    break;

                case EntityType.Tolerance:
                    angle = ((Tolerance)this.annotation).Rotation;
                    break;

                default:
                    throw new ArgumentException("Only MText, Text, Insert, and Tolerance entities are supported as a leader annotation.", nameof(this.annotation));
                }
            }
            this.direction = Vector2.Rotate(Vector2.UnitX, angle * MathHelper.DegToRad);
        }
예제 #9
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);
        }
예제 #10
0
        private void WriteMText(MText mText)
        {
            this.chunk.Write(100, SubclassMarker.MText);

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

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

            this.WriteMTextChunks(this.EncodeNonAsciiCharacters(mText.Value));

            this.chunk.Write(40, mText.Height);
            this.chunk.Write(41, mText.RectangleWidth);
            this.chunk.Write(44, mText.LineSpacingFactor);

            // even if the AutoCAD dxf documentation says that the rotation is in radians, this is wrong this value must be saved in degrees
            this.chunk.Write(50, mText.Rotation);

            this.chunk.Write(71, (short) mText.AttachmentPoint);

            // By style (the flow direction is inherited from the associated text style)
            this.chunk.Write(72, (short) 5);

            this.chunk.Write(7, this.EncodeNonAsciiCharacters(mText.Style.Name));

            this.WriteXData(mText.XData);
        }
예제 #11
0
        /// <summary>
        /// Creates a new MText that is a copy of the current instance.
        /// </summary>
        /// <returns>A new MText that is a copy of this instance.</returns>
        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 = (Lineweight)this.lineweight.Clone(),
                    Transparency = (Transparency)this.transparency.Clone(),
                    LineTypeScale = this.lineTypeScale,
                    Normal = this.normal,
                    //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.value
                };

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

            return entity;

        }
예제 #12
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="text"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object doc, Test2d.XText text, double dx, double dy, ImmutableArray<Test2d.ShapeProperty> db, Test2d.Record r)
        {
            var _doc = doc as DxfDocument;

            var tbind = text.BindToTextProperty(db, r);
            if (string.IsNullOrEmpty(tbind))
                return;

            var style = text.Style;
            var stroke = GetColor(style.Stroke);
            var strokeTansparency = GetTransparency(style.Stroke);

            var attachmentPoint = default(MTextAttachmentPoint);
            double x, y;
            var rect = Test2d.Rect2.Create(text.TopLeft, text.BottomRight, dx, dy);

            switch (text.Style.TextStyle.TextHAlignment)
            {
                default:
                case Test2d.TextHAlignment.Left:
                    x = rect.X;
                    break;
                case Test2d.TextHAlignment.Center:
                    x = rect.X + rect.Width / 2.0;
                    break;
                case Test2d.TextHAlignment.Right:
                    x = rect.X + rect.Width;
                    break;
            }

            switch (text.Style.TextStyle.TextVAlignment)
            {
                default:
                case Test2d.TextVAlignment.Top:
                    y = rect.Y;
                    break;
                case Test2d.TextVAlignment.Center:
                    y = rect.Y + rect.Height / 2.0;
                    break;
                case Test2d.TextVAlignment.Bottom:
                    y = rect.Y + rect.Height;
                    break;
            }

            switch (text.Style.TextStyle.TextVAlignment)
            {
                default:
                case Test2d.TextVAlignment.Top:
                    switch (text.Style.TextStyle.TextHAlignment)
                    {
                        default:
                        case Test2d.TextHAlignment.Left:
                            attachmentPoint = MTextAttachmentPoint.TopLeft;
                            break;
                        case Test2d.TextHAlignment.Center:
                            attachmentPoint = MTextAttachmentPoint.TopCenter;
                            break;
                        case Test2d.TextHAlignment.Right:
                            attachmentPoint = MTextAttachmentPoint.TopRight;
                            break;
                    }
                    break;
                case Test2d.TextVAlignment.Center:
                    switch (text.Style.TextStyle.TextHAlignment)
                    {
                        default:
                        case Test2d.TextHAlignment.Left:
                            attachmentPoint = MTextAttachmentPoint.MiddleLeft;
                            break;
                        case Test2d.TextHAlignment.Center:
                            attachmentPoint = MTextAttachmentPoint.MiddleCenter;
                            break;
                        case Test2d.TextHAlignment.Right:
                            attachmentPoint = MTextAttachmentPoint.MiddleRight;
                            break;
                    }
                    break;
                case Test2d.TextVAlignment.Bottom:
                    switch (text.Style.TextStyle.TextHAlignment)
                    {
                        default:
                        case Test2d.TextHAlignment.Left:
                            attachmentPoint = MTextAttachmentPoint.BottomLeft;
                            break;
                        case Test2d.TextHAlignment.Center:
                            attachmentPoint = MTextAttachmentPoint.BottomCenter;
                            break;
                        case Test2d.TextHAlignment.Right:
                            attachmentPoint = MTextAttachmentPoint.BottomRight;
                            break;
                    }
                    break;
            }

            var ts = new TextStyle(style.TextStyle.FontName, style.TextStyle.FontFile);
            var dxfMText = new MText(
                new Vector3(ToDxfX(x), ToDxfY(y), 0),
                text.Style.TextStyle.FontSize * 72.0 / 96.0,
                rect.Width,
                ts);
            dxfMText.AttachmentPoint = attachmentPoint;

            var fs = text.Style.TextStyle.FontStyle;
            var options = new MTextFormattingOptions(dxfMText.Style);
            options.Bold = fs.Flags.HasFlag(Test2d.FontStyleFlags.Bold);
            options.Italic = fs.Flags.HasFlag(Test2d.FontStyleFlags.Italic);
            options.Underline = fs.Flags.HasFlag(Test2d.FontStyleFlags.Underline);
            options.StrikeThrough = fs.Flags.HasFlag(Test2d.FontStyleFlags.Strikeout);

            options.Aligment = MTextFormattingOptions.TextAligment.Default;
            options.Color = null;
            dxfMText.Write(tbind, options);

            dxfMText.Layer = _currentLayer;
            dxfMText.Transparency.Value = strokeTansparency;
            dxfMText.Color = stroke;

            _doc.AddEntity(dxfMText);
        }
예제 #13
0
        /// <summary>
        /// Gets the the block that contains the entities that make up the dimension picture.
        /// </summary>
        /// <param name="name">Name to be asigned to the generated block.</param>
        /// <returns>The block that represents the actual dimension.</returns>
        internal override Block BuildBlock(string name)
        {
            // we will build the dimension block in object coordinates with normal the dimension normal
            Vector3 refPoint = MathHelper.Transform(this.center, this.normal,
                                                    MathHelper.CoordinateSystem.World,
                                                    MathHelper.CoordinateSystem.Object);

            Vector2 centerRef = new Vector2(refPoint.X, refPoint.Y);

            double elev        = refPoint.Z;
            double refRotation = this.rotation * MathHelper.DegToRad;

            Vector2 firstRef = Vector2.Polar(centerRef, this.diameter * 0.5, refRotation);

            this.definitionPoint = MathHelper.Transform(new Vector3(firstRef.X, firstRef.Y, elev), this.normal,
                                                        MathHelper.CoordinateSystem.Object,
                                                        MathHelper.CoordinateSystem.World);

            Vector2 secondRef = Vector2.Polar(centerRef, -this.diameter * 0.5, refRotation);

            this.circunferenceRef = MathHelper.Transform(new Vector3(secondRef.X, secondRef.Y, elev), this.normal,
                                                         MathHelper.CoordinateSystem.Object,
                                                         MathHelper.CoordinateSystem.World);
            // reference points
            Layer defPoints = new Layer("Defpoints")
            {
                Plot = false
            };
            Point startRef = new Point(firstRef)
            {
                Layer = defPoints
            };
            Point endRef = new Point(secondRef)
            {
                Layer = defPoints
            };

            // dimension lines
            Line dimLine = new Line(firstRef, secondRef);

            // center cross
            double  dist       = Math.Abs(this.style.DIMCEN);
            Vector2 c1         = new Vector2(0, -dist) + centerRef;
            Vector2 c2         = new Vector2(0, dist) + centerRef;
            Line    crossLine1 = new Line(c1, c2);

            c1 = new Vector2(-dist, 0) + centerRef;
            c2 = new Vector2(dist, 0) + centerRef;
            Line crossLine2 = new Line(c1, c2);

            // dimension arrows
            Vector2 arrowRef1 = Vector2.Polar(secondRef, this.style.DIMASZ, refRotation);
            Solid   arrow1    = new Solid(secondRef,
                                          Vector2.Polar(arrowRef1, -this.style.DIMASZ / 6, refRotation + MathHelper.HalfPI),
                                          Vector2.Polar(arrowRef1, this.style.DIMASZ / 6, refRotation + MathHelper.HalfPI),
                                          secondRef);
            Vector2 arrowRef2 = Vector2.Polar(firstRef, -this.style.DIMASZ, refRotation);
            Solid   arrow2    = new Solid(firstRef,
                                          Vector2.Polar(arrowRef2, this.style.DIMASZ / 6, refRotation + MathHelper.HalfPI),
                                          Vector2.Polar(arrowRef2, -this.style.DIMASZ / 6, refRotation + MathHelper.HalfPI),
                                          firstRef);

            // dimension text
            this.midTextPoint = new Vector3(centerRef.X, centerRef.Y, elev); // this value is in OCS
            MText text = new MText(this.FormatDimensionText(this.Value),
                                   Vector2.Polar(centerRef, this.style.DIMGAP, refRotation + MathHelper.HalfPI),
                                   this.style.DIMTXT, 0.0, this.style.TextStyle)
            {
                AttachmentPoint = MTextAttachmentPoint.BottomCenter,
                Rotation        = refRotation * MathHelper.RadToDeg
            };

            Block dim = new Block(name, false);

            dim.Entities.Add(startRef);
            dim.Entities.Add(endRef);
            dim.Entities.Add(dimLine);
            dim.Entities.Add(crossLine1);
            dim.Entities.Add(crossLine2);
            dim.Entities.Add(arrow1);
            dim.Entities.Add(arrow2);
            dim.Entities.Add(text);
            this.block = dim;
            return(dim);
        }
예제 #14
0
        public static Block Build(AlignedDimension dim, string name)
        {
            Vector2             ref1;
            Vector2             ref2;
            Vector2             dimRef1;
            Vector2             dimRef2;
            bool                reversed = false;
            double              measure  = dim.Measurement;
            DimensionStyle      style    = dim.Style;
            List <EntityObject> entities = new List <EntityObject>();

            // we will build the dimension block in object coordinates with normal the dimension normal

            Vector3 refPoint = MathHelper.Transform(dim.FirstReferencePoint, dim.Normal, CoordinateSystem.World, CoordinateSystem.Object);

            ref1 = new Vector2(refPoint.X, refPoint.Y);
            double elevation = refPoint.Z;

            refPoint = MathHelper.Transform(dim.SecondReferencePoint, dim.Normal, CoordinateSystem.World, CoordinateSystem.Object);
            ref2     = new Vector2(refPoint.X, refPoint.Y);

            double refAngle = Vector2.Angle(ref1, ref2);

            if (refAngle > MathHelper.HalfPI && refAngle <= MathHelper.ThreeHalfPI)
            {
                Vector2 tmp = ref1;
                ref1      = ref2;
                ref2      = tmp;
                refAngle += MathHelper.PI;
                reversed  = true;
            }

            dimRef1 = Vector2.Polar(ref1, dim.Offset, refAngle + MathHelper.HalfPI);
            dimRef2 = Vector2.Polar(ref2, dim.Offset, refAngle + MathHelper.HalfPI);
            Vector2 midDim = Vector2.MidPoint(dimRef1, dimRef2);

            // reference points
            Layer defPointLayer = new Layer("Defpoints")
            {
                Plot = false
            };

            entities.Add(new Point(ref1)
            {
                Layer = defPointLayer
            });
            entities.Add(new Point(ref2)
            {
                Layer = defPointLayer
            });
            entities.Add(reversed
                ? new Point(dimRef1)
            {
                Layer = defPointLayer
            }
                : new Point(dimRef2)
            {
                Layer = defPointLayer
            });

            // dimension lines
            entities.Add(DimensionLine(dimRef1, dimRef2, refAngle, style));

            // extension lines
            double dimexo = Math.Sign(dim.Offset) * style.DIMEXO * style.DIMSCALE;
            double dimexe = Math.Sign(dim.Offset) * style.DIMEXE * style.DIMSCALE;

            if (!style.DIMSE1)
            {
                entities.Add(ExtensionLine(Vector2.Polar(ref1, dimexo, refAngle + MathHelper.HalfPI), Vector2.Polar(dimRef1, dimexe, refAngle + MathHelper.HalfPI), style, style.DIMLTEX1));
            }
            if (!style.DIMSE2)
            {
                entities.Add(ExtensionLine(Vector2.Polar(ref2, dimexo, refAngle + MathHelper.HalfPI), Vector2.Polar(dimRef2, dimexe, refAngle + MathHelper.HalfPI), style, style.DIMLTEX2));
            }

            // dimension arrowheads
            if (reversed)
            {
                entities.Add(StartArrowHead(dimRef2, refAngle, style));
                entities.Add(EndArrowHead(dimRef1, refAngle + MathHelper.PI, style));
            }
            else
            {
                entities.Add(StartArrowHead(dimRef1, refAngle + MathHelper.PI, style));
                entities.Add(EndArrowHead(dimRef2, refAngle, style));
            }

            // dimension text
            string text = FormatDimensionText(measure, false, dim.UserText, style, dim.Owner.Record.Layout);

            MText mText = DimensionText(Vector2.Polar(midDim, style.DIMGAP * style.DIMSCALE, refAngle + MathHelper.HalfPI), refAngle, text, style);

            if (mText != null)
            {
                entities.Add(mText);
            }

            Vector3 defPoint = reversed ? new Vector3(dimRef1.X, dimRef1.Y, elevation) : new Vector3(dimRef2.X, dimRef2.Y, elevation);

            dim.DefinitionPoint = MathHelper.Transform(defPoint, dim.Normal, CoordinateSystem.Object, CoordinateSystem.World);
            dim.MidTextPoint    = new Vector3(midDim.X, midDim.Y, elevation); // this value is in OCS

            // drawing block
            return(new Block(name, false, entities, null)
            {
                Flags = BlockTypeFlags.AnonymousBlock
            });
        }
예제 #15
0
        public static Block Build(Angular3PointDimension dim, string name)
        {
            double              offset   = Math.Abs(dim.Offset);
            double              side     = Math.Sign(dim.Offset);
            double              measure  = dim.Measurement;
            double              aperture = measure * MathHelper.DegToRad;
            DimensionStyle      style    = dim.Style;
            List <EntityObject> entities = new List <EntityObject>();

            // we will build the dimension block in object coordinates with normal the dimension normal
            IList <Vector3> ocsPoints = MathHelper.Transform(new[] { dim.CenterPoint, dim.StartPoint, dim.EndPoint }, dim.Normal, CoordinateSystem.World, CoordinateSystem.Object);
            Vector3         refPoint;

            refPoint = ocsPoints[0];
            Vector2 refCenter = new Vector2(refPoint.X, refPoint.Y);

            refPoint = ocsPoints[1];
            Vector2 ref1 = new Vector2(refPoint.X, refPoint.Y);

            refPoint = ocsPoints[2];
            Vector2 ref2 = new Vector2(refPoint.X, refPoint.Y);

            double elevation = refPoint.Z;

            if (side < 0)
            {
                Vector2 tmp = ref1;
                ref1 = ref2;
                ref2 = tmp;
            }

            double  startAngle = Vector2.Angle(refCenter, ref1);
            double  endAngle   = Vector2.Angle(refCenter, ref2);
            Vector2 dimRef1    = Vector2.Polar(refCenter, offset, startAngle);
            Vector2 dimRef2    = Vector2.Polar(refCenter, offset, endAngle);
            double  midRot     = startAngle + aperture * 0.5;
            Vector2 midDim     = Vector2.Polar(refCenter, offset, midRot);

            // reference points
            Layer defPoints = new Layer("Defpoints")
            {
                Plot = false
            };

            entities.Add(new Point(ref1)
            {
                Layer = defPoints
            });
            entities.Add(new Point(ref2)
            {
                Layer = defPoints
            });
            entities.Add(new Point(refCenter)
            {
                Layer = defPoints
            });

            // dimension lines
            double ext1;
            double ext2;

            entities.Add(DimensionArc(refCenter, dimRef1, dimRef2, startAngle, endAngle, Math.Abs(offset), 1, style, out ext1, out ext2));

            // dimension arrows
            double angle1 = Math.Asin(ext1 * 0.5 / Math.Abs(offset));
            double angle2 = Math.Asin(ext2 * 0.5 / Math.Abs(offset));

            entities.Add(StartArrowHead(dimRef1, angle1 + startAngle - MathHelper.HalfPI, style));
            entities.Add(EndArrowHead(dimRef2, angle2 + endAngle + MathHelper.HalfPI, style));

            // dimension lines
            double dimexo = style.DIMEXO * style.DIMSCALE;
            double dimexe = style.DIMEXE * style.DIMSCALE;

            if (!style.DIMSE1)
            {
                entities.Add(ExtensionLine(Vector2.Polar(ref1, dimexo, startAngle), Vector2.Polar(dimRef1, dimexe, startAngle), style, style.DIMLTEX1));
            }
            if (!style.DIMSE2)
            {
                entities.Add(ExtensionLine(Vector2.Polar(ref2, dimexo, endAngle), Vector2.Polar(dimRef2, dimexe, endAngle), style, style.DIMLTEX1));
            }

            // dimension text
            string text = FormatDimensionText(measure, true, dim.UserText, style, dim.Owner.Record.Layout);

            double textRot = midRot - MathHelper.HalfPI;
            double gap     = style.DIMGAP * style.DIMSCALE;

            if (textRot < MathHelper.PI)
            {
                textRot += MathHelper.PI;
                gap     *= -1;
            }

            MText mText = DimensionText(Vector2.Polar(midDim, gap, midRot), textRot, text, style);

            if (mText != null)
            {
                entities.Add(mText);
            }

            dim.DefinitionPoint = MathHelper.Transform(new Vector3(midDim.X, midDim.Y, elevation), dim.Normal, CoordinateSystem.Object, CoordinateSystem.World);
            dim.MidTextPoint    = new Vector3(midDim.X, midDim.Y, elevation); // this value is in OCS

            // drawing block
            return(new Block(name, false, entities, null));
        }
예제 #16
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));
            }
        }
예제 #17
0
        private static void MTextEntity()
        {
            TextStyle style = new TextStyle("Arial");

            MText text1 = new MText(Vector2.Zero, 10, 0, style);
            // you can set manually the text value with all available formatting commands
            text1.Value = "{\\C71;\\c10938556;Text} with true color\\P{\\C140;Text} with indexed color";

            MText text2 = new MText(new Vector2(0, 30), 10, 0, style);
            // or use the Write() method
            MTextFormattingOptions op = new MTextFormattingOptions(text2.Style);
            op.Color = new AciColor(188, 232, 166); // using true color
            text2.Write("Text", op);
            op.Color = null; // set color to the default defined in text2.Style
            text2.Write(" with true color");
            text2.EndParagraph();
            op.Color = new AciColor(140); // using index color
            text2.Write("Text", op); // set color to the default defined in text2.Style
            op.Color = null;
            text2.Write(" with indexed color");

            // both text1 and text2 should yield to the same result
            DxfDocument dxf = new DxfDocument(DxfVersion.AutoCad2010);
            dxf.AddEntity(text1);
            dxf.AddEntity(text2);

            dxf.Save("MText format.dxf");

            // now you can retrieve the MText text value without any formatting codes, control characters like tab '\t' will be preserved in the result,
            // the new paragraph command "\P" will be converted to new line feed '\r\n'.
            Console.WriteLine(text1.PlainText());
            Console.WriteLine();
            Console.WriteLine(text2.PlainText());
            Console.WriteLine();
            Console.WriteLine("Press a key to finish...");
            Console.ReadKey();

        }
예제 #18
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));
            }
        }
예제 #19
0
        /// <inheritdoc/>
        public override void Draw(object dc, Core2D.Shapes.XText text, double dx, double dy, ImmutableArray<Core2D.Data.XProperty> db, Core2D.Data.Database.XRecord r)
        {
            var dxf = dc as DxfDocument;

            var tbind = text.BindText(db, r);
            if (string.IsNullOrEmpty(tbind))
                return;

            var style = text.Style;
            var stroke = ToColor(style.Stroke);
            var strokeTansparency = ToTransparency(style.Stroke);

            var attachmentPoint = default(MTextAttachmentPoint);
            double x, y;
            var rect = Core2D.Math.Rect2.Create(text.TopLeft, text.BottomRight, dx, dy);

            switch (text.Style.TextStyle.TextHAlignment)
            {
                default:
                case Core2D.Style.TextHAlignment.Left:
                    x = rect.X;
                    break;
                case Core2D.Style.TextHAlignment.Center:
                    x = rect.X + rect.Width / 2.0;
                    break;
                case Core2D.Style.TextHAlignment.Right:
                    x = rect.X + rect.Width;
                    break;
            }

            switch (text.Style.TextStyle.TextVAlignment)
            {
                default:
                case Core2D.Style.TextVAlignment.Top:
                    y = rect.Y;
                    break;
                case Core2D.Style.TextVAlignment.Center:
                    y = rect.Y + rect.Height / 2.0;
                    break;
                case Core2D.Style.TextVAlignment.Bottom:
                    y = rect.Y + rect.Height;
                    break;
            }

            switch (text.Style.TextStyle.TextVAlignment)
            {
                default:
                case Core2D.Style.TextVAlignment.Top:
                    switch (text.Style.TextStyle.TextHAlignment)
                    {
                        default:
                        case Core2D.Style.TextHAlignment.Left:
                            attachmentPoint = MTextAttachmentPoint.TopLeft;
                            break;
                        case Core2D.Style.TextHAlignment.Center:
                            attachmentPoint = MTextAttachmentPoint.TopCenter;
                            break;
                        case Core2D.Style.TextHAlignment.Right:
                            attachmentPoint = MTextAttachmentPoint.TopRight;
                            break;
                    }
                    break;
                case Core2D.Style.TextVAlignment.Center:
                    switch (text.Style.TextStyle.TextHAlignment)
                    {
                        default:
                        case Core2D.Style.TextHAlignment.Left:
                            attachmentPoint = MTextAttachmentPoint.MiddleLeft;
                            break;
                        case Core2D.Style.TextHAlignment.Center:
                            attachmentPoint = MTextAttachmentPoint.MiddleCenter;
                            break;
                        case Core2D.Style.TextHAlignment.Right:
                            attachmentPoint = MTextAttachmentPoint.MiddleRight;
                            break;
                    }
                    break;
                case Core2D.Style.TextVAlignment.Bottom:
                    switch (text.Style.TextStyle.TextHAlignment)
                    {
                        default:
                        case Core2D.Style.TextHAlignment.Left:
                            attachmentPoint = MTextAttachmentPoint.BottomLeft;
                            break;
                        case Core2D.Style.TextHAlignment.Center:
                            attachmentPoint = MTextAttachmentPoint.BottomCenter;
                            break;
                        case Core2D.Style.TextHAlignment.Right:
                            attachmentPoint = MTextAttachmentPoint.BottomRight;
                            break;
                    }
                    break;
            }

            var ts = new TextStyle(style.TextStyle.FontName, style.TextStyle.FontFile);
            var dxfMText = new MText(
                new Vector3(ToDxfX(x), ToDxfY(y), 0),
                text.Style.TextStyle.FontSize * _targetDpi / _sourceDpi,
                rect.Width,
                ts);
            dxfMText.AttachmentPoint = attachmentPoint;

            var options = new MTextFormattingOptions(dxfMText.Style);
            var fs = text.Style.TextStyle.FontStyle;
            if (fs != null)
            {
                options.Bold = fs.Flags.HasFlag(Core2D.Style.FontStyleFlags.Bold);
                options.Italic = fs.Flags.HasFlag(Core2D.Style.FontStyleFlags.Italic);
                options.Underline = fs.Flags.HasFlag(Core2D.Style.FontStyleFlags.Underline);
                options.StrikeThrough = fs.Flags.HasFlag(Core2D.Style.FontStyleFlags.Strikeout);
            }

            options.Aligment = MTextFormattingOptions.TextAligment.Default;
            options.Color = null;
            dxfMText.Write(tbind, options);

            dxfMText.Layer = _currentLayer;
            dxfMText.Transparency.Value = strokeTansparency;
            dxfMText.Color = stroke;

            dxf.AddEntity(dxfMText);
        }
예제 #20
0
파일: DxfReader.cs 프로젝트: Core2D/netdxf
        private MText ReadMText()
        {
            Vector3 insertionPoint = Vector3.Zero;
            Vector2 direction = Vector2.UnitX;
            Vector3 normal = Vector3.UnitZ;
            double height = 0.0;
            double rectangleWidth = 0.0;
            double lineSpacing = 1.0;
            double rotation = 0.0;
            bool isRotationDefined = false;
            MTextAttachmentPoint attachmentPoint = MTextAttachmentPoint.TopLeft;
            TextStyle style = TextStyle.Default;
            string textString = string.Empty;
            List<XData> xData = new List<XData>();

            this.chunk.Next();
            while (this.chunk.Code != 0)
            {
                switch (this.chunk.Code)
                {
                    case 1:
                        textString = string.Concat(textString, this.chunk.ReadString());
                        this.chunk.Next();
                        break;
                    case 3:
                        textString = string.Concat(textString, this.chunk.ReadString());
                        this.chunk.Next();
                        break;
                    case 10:
                        insertionPoint.X = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 20:
                        insertionPoint.Y = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 30:
                        insertionPoint.Z = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 11:
                        direction.X = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 21:
                        direction.Y = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 31:
                        // Z direction value (direction.Z = double.Parse(dxfPairInfo.Value);)
                        // the angle of the text is defined on the plane where it belongs so Z value will be zero.
                        this.chunk.Next();
                        break;
                    case 40:
                        height = this.chunk.ReadDouble();
                        if (height <= 0.0)
                            height = this.doc.DrawingVariables.TextSize;
                        this.chunk.Next();
                        break;
                    case 41:
                        rectangleWidth = this.chunk.ReadDouble();
                        if (rectangleWidth < 0.0)
                            rectangleWidth = 0.0;
                        this.chunk.Next();
                        break;
                    case 44:
                        lineSpacing = this.chunk.ReadDouble();
                        if (lineSpacing < 0.25 || lineSpacing > 4.0)
                            lineSpacing = 1.0;
                        this.chunk.Next();
                        break;
                    case 50: // even if the AutoCAD dxf documentation says that the rotation is in radians, this is wrong this value is in degrees
                        isRotationDefined = true;
                        rotation = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 7:
                        string styleName = this.DecodeEncodedNonAsciiCharacters(this.chunk.ReadString());
                        if (string.IsNullOrEmpty(styleName))
                            styleName = this.doc.DrawingVariables.TextStyle;
                        style = this.GetTextStyle(styleName);
                        this.chunk.Next();
                        break;
                    case 71:
                        attachmentPoint = (MTextAttachmentPoint) this.chunk.ReadShort();
                        this.chunk.Next();
                        break;
                    case 210:
                        normal.X = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 220:
                        normal.Y = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 230:
                        normal.Z = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 1001:
                        string appId = this.DecodeEncodedNonAsciiCharacters(this.chunk.ReadString());
                        XData data = this.ReadXDataRecord(this.GetApplicationRegistry(appId));
                        xData.Add(data);
                        break;
                    default:
                        if (this.chunk.Code >= 1000 && this.chunk.Code <= 1071)
                            throw new Exception("The extended data of an entity must start with the application registry code.");

                        this.chunk.Next();
                        break;
                }
            }

            textString = this.DecodeEncodedNonAsciiCharacters(textString);
            // text dxf files stores the tabs as ^I in the MText texts, they will be replaced by the standard tab character
            if (!this.isBinary)
                textString = textString.Replace("^I", "\t");

            MText entity = new MText
            {
                Value = textString,
                Position = insertionPoint,
                Height = height,
                RectangleWidth = rectangleWidth,
                Style = style,
                LineSpacingFactor = lineSpacing,
                AttachmentPoint = attachmentPoint,
                Rotation = isRotationDefined ? rotation : Vector2.Angle(direction)*MathHelper.RadToDeg,
                Normal = normal,
            };

            entity.XData.AddRange(xData);

            return entity;
        }
예제 #21
0
        private static MText DimensionText(Vector2 position, double rotation, string text, DimensionStyle style)
        {
            if (string.IsNullOrEmpty(text)) return null;

            MText mText = new MText(text, position, style.DIMTXT*style.DIMSCALE, 0.0, style.DIMTXSTY)
            {
                Color = style.DIMCLRT,
                AttachmentPoint = MTextAttachmentPoint.BottomCenter,
                Rotation = rotation * MathHelper.RadToDeg
            };

            return mText;
        }
예제 #22
0
        private static void WriteMText()
        {
            DxfDocument dxf = new DxfDocument();

            //xData sample
            XData xdata = new XData(new ApplicationRegistry("netDxf"));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));
            xdata.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionX, 0));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionY, 0));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.WorldSpacePositionZ, 0));
            xdata.XDataRecord.Add(XDataRecord.CloseControlString);

            //text
            TextStyle style = new TextStyle("Times.ttf");
            //TextStyle style = TextStyle.Default;
            MText mText = new MText(new Vector3(3,2,0), 1.0f, 100.0f, style);
            mText.Layer = new Layer("Multiline Text");
            //mText.Layer.Color.Index = 8;
            mText.Rotation = 0;
            mText.LineSpacingFactor = 1.0;
            mText.ParagraphHeightFactor = 1.0;

            //mText.AttachmentPoint = MTextAttachmentPoint.TopCenter;
            //mText.Write("Hello World!");
            //mText.Write(" we keep writting on the same line.");
            //mText.WriteLine("This text is in a new line");

            //mText.Write("Hello World! ");
            //for (int i = 0; i < 50; i++)
            //{
            //    mText.Write("1234567890");
            //}
            //mText.Write(" This text is over the limit of the 250 character chunk");
            //mText.NewParagraph();
            //mText.Write("This is a text in a new paragraph");
            //mText.Write(" and we continue writing in the previous paragraph");
            //mText.NewParagraph();
            MTextFormattingOptions options = new MTextFormattingOptions(mText.Style);
            options.Bold = true;
            mText.Write("Bold text in mText.Style", options);
            mText.EndParagraph();
            options.Italic = true;
            mText.Write("Bold and italic text in mText.Style", options);
            mText.EndParagraph();
            options.Bold = false;
            options.FontName = "Arial";
            options.Color = AciColor.Blue;
            mText.ParagraphHeightFactor = 2;
            mText.Write("Italic text in Arial", options);
            mText.EndParagraph();
            options.Italic = false;
            options.Color = null; // back to the default text color
            mText.Write("Normal text in Arial with the default paragraph height factor", options);
            mText.EndParagraph();
            mText.ParagraphHeightFactor = 1;
            mText.Write("No formatted text uses mText.Style");
            mText.Write(" and the text continues in the same paragraph.");
            mText.EndParagraph();

            //options.HeightPercentage = 2.5;
            //options.Color = AciColor.Red;
            //options.Overstrike = true;
            //options.Underline = true;
            //options.FontFile = "times.ttf";
            //options.ObliqueAngle = 15;
            //options.CharacterSpacePercentage = 2.35;
            //options.WidthFactor = 1.8;
            
            //for unknown reasons the aligment doesn't seem to change anything
            //mText.Write("Formatted text", options);
            //options.Aligment = MTextFormattingOptions.TextAligment.Center;
            //mText.Write("Center", options);
            //options.Aligment = MTextFormattingOptions.TextAligment.Top;
            //mText.Write("Top", options);
            //options.Aligment = MTextFormattingOptions.TextAligment.Bottom;
            //mText.Write("Bottom", options);

            mText.XData.Add(xdata);
            
            dxf.AddEntity(mText);

            dxf.Save("MText sample.dxf");

        }
예제 #23
0
        private static void WriteNoAsciiText()
        {
            TextStyle textStyle = new TextStyle("Arial.ttf");
            DxfDocument dxf = new DxfDocument();
            dxf.DrawingVariables.LastSavedBy = "ЉЊЋЌЍжзицрлЯ";
            //Text text = new Text("ÁÉÍÓÚ áéíóú Ññ àèìòù âêîôû", Vector2.Zero,10);
            Text text = new Text("ЉЊЋЌЍжзицрлЯ", Vector2.Zero, 10, textStyle);
            MText mtext = new MText("ЉЊЋЌЍжзицрлЯ", new Vector2(0, 50), 10, 0, textStyle);

            dxf.AddEntity(text);
            dxf.AddEntity(mtext);
            foreach (Text t in dxf.Texts)
            {
                Console.WriteLine(t.Value);
            }
            foreach (MText t in dxf.MTexts)
            {
                Console.WriteLine(t.Value);
            }
            Console.WriteLine("Press a key to continue...");
            Console.ReadLine();
            dxf.Save("text1.dxf");

            dxf = DxfDocument.Load("text1.dxf");
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2004;
            dxf.Save("text2.dxf");
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save("text3.dxf");
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2010;
            dxf.Save("text4.dxf");

        }
예제 #24
0
        private static void Text()
        {
            // use a font that has support for Chinese characters
            TextStyle textStyle = new TextStyle("Chinese text", "simsun.ttf");

            // for dxf database version 2007 and later you can use directly the characters,
            DxfDocument dxf1 = new DxfDocument(DxfVersion.AutoCad2010);
            Text text1 = new Text("这是中国文字", Vector2.Zero, 10, textStyle);
            MText mtext1 = new MText("这是中国文字", new Vector2(0, 30), 10, 0, textStyle);
            dxf1.AddEntity(text1);
            dxf1.AddEntity(mtext1);
            dxf1.Save("textCad2010.dxf");

            foreach (Text text in dxf1.Texts)
            {
                Console.WriteLine(text.Value);
            }
            foreach (MText text in dxf1.MTexts)
            {
                Console.WriteLine(text.Value);
            }

            Console.WriteLine("Press a key to continue...");
            Console.ReadLine();

            DxfDocument loadDxf = DxfDocument.Load("textCad2010.dxf");

            // for previous version (this method will also work for later ones) you will need to supply the unicode value (U+value),
            // you can get this value with the Windows Character Map application
            DxfDocument dxf2 = new DxfDocument(DxfVersion.AutoCad2010);
            Text text2 = new Text("\\U+8FD9\\U+662F\\U+4E2D\\U+56FD\\U+6587\\U+5B57", Vector2.Zero, 10, textStyle);
            MText mtext2 = new MText("\\U+8FD9\\U+662F\\U+4E2D\\U+56FD\\U+6587\\U+5B57", new Vector2(0, 30), 10, 0, textStyle);
            dxf2.AddEntity(text2);
            dxf2.AddEntity(mtext2);
            dxf2.Save("textCad2000.dxf");
        }
예제 #25
0
        private static MText DimensionText(Vector2 position, double rotation, string text, DimensionStyle style)
        {
            if (string.IsNullOrEmpty(text))
                return null;

            MText mText = new MText(text, position, style.TextHeight*style.DimScaleOverall, 0.0, style.TextStyle)
            {
                Color = style.TextColor,
                AttachmentPoint = MTextAttachmentPoint.BottomCenter,
                Rotation = rotation*MathHelper.RadToDeg
            };

            return mText;
        }
예제 #26
0
        public static Block Build(OrdinateDimension dim, string name)
        {
            DimensionStyle      style    = dim.Style;
            List <EntityObject> entities = new List <EntityObject>();

            double measure = dim.Measurement;

            dim.DefinitionPoint = dim.Origin;
            double angle = dim.Rotation * MathHelper.DegToRad;

            Vector3 localPoint = MathHelper.Transform(dim.Origin, dim.Normal, CoordinateSystem.World, CoordinateSystem.Object);
            Vector2 refCenter  = new Vector2(localPoint.X, localPoint.Y);

            double elev = localPoint.Z;

            Vector2 startPoint = refCenter + MathHelper.Transform(dim.ReferencePoint, angle, CoordinateSystem.Object, CoordinateSystem.World);

            dim.FirstPoint = MathHelper.Transform(new Vector3(startPoint.X, startPoint.Y, elev), dim.Normal, CoordinateSystem.Object, CoordinateSystem.World);

            if (dim.Axis == OrdinateDimensionAxis.X)
            {
                angle += MathHelper.HalfPI;
            }
            Vector2 endPoint = Vector2.Polar(startPoint, dim.Length, angle);

            dim.SecondPoint = MathHelper.Transform(new Vector3(endPoint.X, endPoint.Y, elev), dim.Normal, CoordinateSystem.Object, CoordinateSystem.World);

            // reference points
            Layer defPoints = new Layer("Defpoints")
            {
                Plot = false
            };

            entities.Add(new Point(refCenter)
            {
                Layer = defPoints
            });
            entities.Add(new Point(startPoint)
            {
                Layer = defPoints
            });

            short side = 1;

            if (dim.Length < 0)
            {
                side = -1;
            }

            // dimension lines
            entities.Add(new Line(Vector2.Polar(startPoint, side * style.DIMEXO * style.DIMSCALE, angle), endPoint));

            // dimension text
            Vector2 midText = Vector2.Polar(startPoint, dim.Length + side * style.DIMGAP * style.DIMSCALE, angle);

            dim.MidTextPoint = new Vector3(midText.X, midText.Y, elev); // this value is in OCS

            string text = FormatDimensionText(measure, false, dim.UserText, style, dim.Owner.Record.Layout);

            MText mText = DimensionText(midText, angle, text, style);

            if (mText != null)
            {
                mText.AttachmentPoint = side < 0 ? MTextAttachmentPoint.MiddleRight : MTextAttachmentPoint.MiddleLeft;
                entities.Add(mText);
            }

            // drawing block
            return(new Block(name, false, entities, null));
        }
예제 #27
0
        internal override Block BuildBlock(string name)
        {
            this.definitionPoint = this.origin;
            double angle = this.rotation * MathHelper.DegToRad;

            Vector3 localPoint = MathHelper.Transform(this.origin, this.normal, MathHelper.CoordinateSystem.World, MathHelper.CoordinateSystem.Object);
            Vector2 refCenter  = new Vector2(localPoint.X, localPoint.Y);

            double elev = localPoint.Z;

            Vector2 startPoint = refCenter + MathHelper.Transform(this.referencePoint, angle, MathHelper.CoordinateSystem.Object, MathHelper.CoordinateSystem.World);

            this.firstPoint = MathHelper.Transform(new Vector3(startPoint.X, startPoint.Y, elev), this.normal, MathHelper.CoordinateSystem.Object, MathHelper.CoordinateSystem.World);

            if (this.axis == OrdinateDimensionAxis.X)
            {
                angle += MathHelper.HalfPI;
            }
            Vector2 endPoint = Vector2.Polar(startPoint, this.length, angle);

            this.secondPoint = MathHelper.Transform(new Vector3(endPoint.X, endPoint.Y, elev), this.normal, MathHelper.CoordinateSystem.Object, MathHelper.CoordinateSystem.World);

            // reference points
            Layer defPoints = new Layer("Defpoints")
            {
                Plot = false
            };
            Point startRef = new Point(startPoint)
            {
                Layer = defPoints
            };
            Point endRef = new Point(endPoint)
            {
                Layer = defPoints
            };

            // dimension lines
            Line dimLine = new Line(Vector2.Polar(startPoint, this.style.DIMEXO, angle), endPoint);

            // dimension text
            Vector2 midText = Vector2.Polar(startPoint, this.length + this.style.DIMGAP, angle);

            this.midTextPoint = new Vector3(midText.X, midText.Y, elev); // this value is in OCS

            MText text = new MText(this.FormatDimensionText(this.Value),
                                   midText,
                                   this.style.DIMTXT, 0.0, this.style.TextStyle)
            {
                AttachmentPoint = MTextAttachmentPoint.MiddleLeft,
                Rotation        = angle * MathHelper.RadToDeg
            };

            // drawing block
            Block dim = new Block(name);

            dim.Entities.Add(startRef);
            dim.Entities.Add(endRef);
            dim.Entities.Add(dimLine);
            dim.Entities.Add(text);
            this.block = dim;
            return(dim);
        }
예제 #28
0
 /// <summary>
 /// Convert a netDXF MText object to a Nucleus label
 /// </summary>
 /// <param name="text"></param>
 /// <returns></returns>
 public static Label Convert(netDxf.Entities.MText text)
 {
     return(new Label(Convert(text.Position), text.Value, text.Height * ConversionScaling,
                      ConvertVertical(text.AttachmentPoint), ConvertHorizontal(text.AttachmentPoint)));
 }
예제 #29
0
        public static Block Build(LinearDimension dim, string name)
        {
            Vector2             ref1;
            Vector2             ref2;
            Vector2             dimRef1;
            Vector2             dimRef2;
            double              measure  = dim.Measurement;
            bool                reversed = false;
            DimensionStyle      style    = dim.Style;
            List <EntityObject> entities = new List <EntityObject>();

            // we will build the dimension block in object coordinates with normal the dimension normal
            Vector3 refPoint;

            refPoint = MathHelper.Transform(dim.FirstReferencePoint, dim.Normal, CoordinateSystem.World, CoordinateSystem.Object);
            ref1     = new Vector2(refPoint.X, refPoint.Y);
            double elevation = refPoint.Z;

            refPoint = MathHelper.Transform(dim.SecondReferencePoint, dim.Normal, CoordinateSystem.World, CoordinateSystem.Object);
            ref2     = new Vector2(refPoint.X, refPoint.Y);
            Vector2 midRef = Vector2.MidPoint(ref1, ref2);
            //double refAngle = Vector2.Angle(ref1, ref2);
            //if (refAngle > MathHelper.HalfPI && refAngle <= MathHelper.ThreeHalfPI)
            //{
            //    Vector2 tmp = ref1;
            //    ref1 = ref2;
            //    ref2 = tmp;
            //}

            double  dimRotation = dim.Rotation * MathHelper.DegToRad;
            Vector2 dimRef1tmp  = new Vector2(-measure * 0.5, dim.Offset);
            Vector2 dimRef2tmp  = new Vector2(measure * 0.5, dim.Offset);

            dimRef1 = MathHelper.Transform(dimRef1tmp, dimRotation, CoordinateSystem.Object, CoordinateSystem.World) + midRef;
            dimRef2 = MathHelper.Transform(dimRef2tmp, dimRotation, CoordinateSystem.Object, CoordinateSystem.World) + midRef;
            Vector2 midDim        = Vector2.MidPoint(dimRef1, dimRef2);
            double  relativeAngle = Vector2.AngleBetween(ref2 - ref1, dimRef2 - dimRef1);

            if (relativeAngle > MathHelper.HalfPI && relativeAngle <= MathHelper.ThreeHalfPI)
            {
                Vector2 tmp = ref1;
                ref1     = ref2;
                ref2     = tmp;
                reversed = true;
            }

            // reference points
            Layer defPointLayer = new Layer("Defpoints")
            {
                Plot = false
            };

            entities.Add(new Point(ref1)
            {
                Layer = defPointLayer
            });
            entities.Add(new Point(ref2)
            {
                Layer = defPointLayer
            });
            entities.Add(reversed
                ? new Point(dimRef1)
            {
                Layer = defPointLayer
            }
                : new Point(dimRef2)
            {
                Layer = defPointLayer
            });

            // dimension line
            entities.Add(DimensionLine(dimRef1, dimRef2, dimRotation, style));

            // extension lines
            Vector2 dirRef1 = Vector2.Normalize(dimRef1 - ref1);
            Vector2 dirRef2 = Vector2.Normalize(dimRef2 - ref2);
            double  dimexo  = style.DIMEXO * style.DIMSCALE;
            double  dimexe  = style.DIMEXE * style.DIMSCALE;

            if (!style.DIMSE1)
            {
                entities.Add(ExtensionLine(ref1 + dimexo * dirRef1, dimRef1 + dimexe * dirRef1, style, style.DIMLTEX1));
            }
            if (!style.DIMSE2)
            {
                entities.Add(ExtensionLine(ref2 + dimexo * dirRef2, dimRef2 + dimexe * dirRef2, style, style.DIMLTEX2));
            }

            // dimension arrowheads
            if (reversed)
            {
                entities.Add(StartArrowHead(dimRef2, dimRotation, style));
                entities.Add(EndArrowHead(dimRef1, dimRotation + MathHelper.PI, style));
            }
            else
            {
                entities.Add(StartArrowHead(dimRef1, dimRotation + MathHelper.PI, style));
                entities.Add(EndArrowHead(dimRef2, dimRotation, style));
            }

            // dimension text
            string text = FormatDimensionText(measure, false, dim.UserText, style, dim.Owner.Record.Layout);

            double textRot = dimRotation;

            if (textRot > MathHelper.HalfPI && textRot <= MathHelper.ThreeHalfPI)
            {
                textRot += MathHelper.PI;
            }

            MText mText = DimensionText(Vector2.Polar(midDim, style.DIMGAP * style.DIMSCALE, textRot + MathHelper.HalfPI), textRot, text, style);

            if (mText != null)
            {
                entities.Add(mText);
            }

            Vector3 defPoint = reversed ? new Vector3(dimRef1.X, dimRef1.Y, elevation) : new Vector3(dimRef2.X, dimRef2.Y, elevation);

            dim.DefinitionPoint = MathHelper.Transform(defPoint, dim.Normal, CoordinateSystem.Object, CoordinateSystem.World);
            dim.MidTextPoint    = new Vector3(midDim.X, midDim.Y, elevation); // this value is in OCS

            // drawing block
            return(new Block(name, false, entities, null)
            {
                Flags = BlockTypeFlags.AnonymousBlock
            });
        }
예제 #30
0
        public static Block Build(AlignedDimension dim, string name)
        {
            Vector2        ref1;
            Vector2        ref2;
            Vector2        dimRef1;
            Vector2        dimRef2;
            short          reversed;
            double         measure = dim.Value;
            DimensionStyle style   = dim.Style;

            // we will build the dimension block in object coordinates with normal the dimension normal
            Vector3 refPoint;

            refPoint = MathHelper.Transform(dim.FirstReferencePoint, dim.Normal, MathHelper.CoordinateSystem.World, MathHelper.CoordinateSystem.Object);
            ref1     = new Vector2(refPoint.X, refPoint.Y);
            double elevation = refPoint.Z;

            refPoint = MathHelper.Transform(dim.SecondReferencePoint, dim.Normal, MathHelper.CoordinateSystem.World, MathHelper.CoordinateSystem.Object);
            ref2     = new Vector2(refPoint.X, refPoint.Y);

            double refAngle = Vector2.Angle(ref1, ref2);

            reversed = ReverseEnds(ref1, ref2, 0.0, refAngle);

            dimRef1 = Vector2.Polar(ref1, dim.Offset, refAngle + MathHelper.HalfPI);
            dimRef2 = Vector2.Polar(ref2, dim.Offset, refAngle + MathHelper.HalfPI);

            Vector2 midDim = Vector2.MidPoint(dimRef1, dimRef2);

            // reference points
            Layer defPointLayer = new Layer("Defpoints")
            {
                Plot = false
            };
            Point ref1Point = new Point(ref1)
            {
                Layer = defPointLayer
            };
            Point ref2Point = new Point(ref2)
            {
                Layer = defPointLayer
            };
            Point defPoint = new Point(dimRef2)
            {
                Layer = defPointLayer
            };

            // dimension lines
            Line dimLine = DimensionLine(dimRef1, dimRef2, refAngle, 1, style);

            // extension lines
            double dimexo   = Math.Sign(dim.Offset) * style.DIMEXO * style.DIMSCALE;
            double dimexe   = Math.Sign(dim.Offset) * style.DIMEXE * style.DIMSCALE;
            double extRot   = refAngle + MathHelper.HalfPI;
            Line   ext1Line = null;

            if (!style.DIMSE1)
            {
                ext1Line = ExtensionLine(Vector2.Polar(ref1, dimexo, extRot), Vector2.Polar(dimRef1, dimexe, extRot), style, style.DIMLTEX1);
            }

            Line ext2Line = null;

            if (!style.DIMSE2)
            {
                ext2Line = ExtensionLine(Vector2.Polar(ref2, dimexo, extRot), Vector2.Polar(dimRef2, dimexe, extRot), style, style.DIMLTEX2);
            }

            // dimension arrows
            EntityObject arrow1 = StartArrowHead(dimRef1, Vector2.Angle(dimRef2, dimRef1), style);
            EntityObject arrow2 = EndArrowHead(dimRef2, Vector2.Angle(dimRef1, dimRef2), style);

            // dimension text
            string text    = FormatDimensionText(measure, false, style);
            double textRot = (refAngle + (1 - reversed) * MathHelper.HalfPI);
            MText  mText   = DimensionText(Vector2.Polar(midDim, reversed * style.DIMGAP * style.DIMSCALE, extRot), textRot, text, style);

            dim.DefinitionPoint = MathHelper.Transform(new Vector3(dimRef2.X, dimRef2.Y, elevation), dim.Normal, MathHelper.CoordinateSystem.Object, MathHelper.CoordinateSystem.World);
            dim.MidTextPoint    = new Vector3(midDim.X, midDim.Y, elevation); // this value is in OCS

            // drawing block
            Block block = new Block(name, false)
            {
                Flags = BlockTypeFlags.AnonymousBlock
            };

            block.Entities.Add(ref1Point);
            block.Entities.Add(ref2Point);
            block.Entities.Add(defPoint);
            block.Entities.Add(ext1Line);
            block.Entities.Add(ext2Line);
            block.Entities.Add(dimLine);
            block.Entities.Add(arrow1);
            block.Entities.Add(arrow2);
            block.Entities.Add(mText);
            return(block);
        }
예제 #31
0
        public static Block Build(Angular2LineDimension dim, string name)
        {
            double              offset   = dim.Offset;
            double              side     = Math.Sign(dim.Offset);
            double              measure  = dim.Measurement;
            DimensionStyle      style    = dim.Style;
            List <EntityObject> entities = new List <EntityObject>();

            // we will build the dimension block in object coordinates with normal the dimension normal
            IList <Vector3> ocsPoints = MathHelper.Transform(new[] { dim.StartFirstLine, dim.EndFirstLine, dim.StartSecondLine, dim.EndSecondLine }, dim.Normal, CoordinateSystem.World, CoordinateSystem.Object);
            Vector3         refPoint;

            refPoint = ocsPoints[0];
            Vector2 ref1Start = new Vector2(refPoint.X, refPoint.Y);
            double  elevation = refPoint.Z;

            refPoint = ocsPoints[1];
            Vector2 ref1End = new Vector2(refPoint.X, refPoint.Y);

            refPoint = ocsPoints[2];
            Vector2 ref2Start = new Vector2(refPoint.X, refPoint.Y);

            refPoint = ocsPoints[3];
            Vector2 ref2End = new Vector2(refPoint.X, refPoint.Y);

            Vector2 dirRef1 = ref1End - ref1Start;
            Vector2 dirRef2 = ref2End - ref2Start;

            if (Vector2.AreParallel(dirRef1, dirRef2))
            {
                throw new ArgumentException("The two lines that define the dimension are parallel.");
            }

            Vector2 center     = FindIntersection(ref1Start, dirRef1, ref2Start, dirRef2);
            double  startAngle = Vector2.Angle(ref1Start, ref1End);
            double  endAngle   = Vector2.Angle(ref2Start, ref2End);
            double  cross      = Vector2.CrossProduct(dirRef1, dirRef2);
            double  aperture   = Vector2.AngleBetween(dirRef1, dirRef2);

            if (cross < 0)
            {
                Vector2 tmp1 = ref1Start;
                Vector2 tmp2 = ref1End;
                ref1Start = ref2Start;
                ref1End   = ref2End;
                ref2Start = tmp1;
                ref2End   = tmp2;
                double tmp = startAngle;
                startAngle = endAngle;
                endAngle   = tmp;
            }
            short reversed = 1;

            if (side < 0)
            {
                Vector2 tmp1 = ref1Start;
                Vector2 tmp2 = ref2Start;
                ref1Start = ref1End;
                ref1End   = tmp1;
                ref2Start = ref2End;
                ref2End   = tmp2;
                reversed  = -1;
            }

            Vector2 dimRef1 = Vector2.Polar(center, offset, startAngle);
            Vector2 dimRef2 = Vector2.Polar(center, offset, endAngle);
            Vector2 midDim  = Vector2.Polar(center, offset, startAngle + aperture * 0.5);

            // reference points
            Layer defPoints = new Layer("Defpoints")
            {
                Plot = false
            };

            entities.Add(new Point(ref1Start)
            {
                Layer = defPoints
            });
            entities.Add(new Point(ref1End)
            {
                Layer = defPoints
            });
            entities.Add(new Point(ref2Start)
            {
                Layer = defPoints
            });
            entities.Add(new Point(ref2End)
            {
                Layer = defPoints
            });

            // dimension lines
            double ext1;
            double ext2;

            entities.Add(DimensionArc(center, dimRef1, dimRef2, startAngle, endAngle, Math.Abs(offset), reversed, style, out ext1, out ext2));

            // dimension arrows
            double angle1 = Math.Asin(ext1 * 0.5 / Math.Abs(offset));
            double angle2 = Math.Asin(ext2 * 0.5 / Math.Abs(offset));

            entities.Add(StartArrowHead(dimRef1, (1 - reversed) * MathHelper.HalfPI + angle1 + startAngle - MathHelper.HalfPI, style));
            entities.Add(EndArrowHead(dimRef2, (1 - reversed) * MathHelper.HalfPI + angle2 + endAngle + MathHelper.HalfPI, style));

            // dimension lines
            double dimexo = side * style.DIMEXO * style.DIMSCALE;
            double dimexe = side * style.DIMEXE * style.DIMSCALE;
            // the dimension line is only drawn if the end of the extension line is outside the line segment
            int t;

            t = MathHelper.PointInSegment(dimRef1, ref1Start, ref1End);
            if (!style.DIMSE1 && t != 0)
            {
                Vector2 s;
                s = Vector2.Polar(t < 0 ? ref1Start : ref1End, t * dimexo, startAngle);
                entities.Add(ExtensionLine(s, Vector2.Polar(dimRef1, t * dimexe, startAngle), style, style.DIMLTEX1));
            }

            t = MathHelper.PointInSegment(dimRef2, ref2Start, ref2End);
            if (!style.DIMSE2 && t != 0)
            {
                Vector2 s;
                if (t < 0)
                {
                    s = Vector2.Polar(ref2Start, t * dimexo, endAngle);
                }
                else
                {
                    s = Vector2.Polar(ref2End, t * dimexo, endAngle);
                }
                entities.Add(ExtensionLine(s, Vector2.Polar(dimRef2, t * dimexe, endAngle), style, style.DIMLTEX1));
            }

            // dimension text
            string text = FormatDimensionText(measure, true, dim.UserText, style, dim.Owner.Record.Layout);

            double extRot  = startAngle + aperture * 0.5;
            double textRot = extRot - MathHelper.HalfPI;

            MText mText = DimensionText(Vector2.Polar(midDim, style.DIMGAP * style.DIMSCALE, extRot), textRot, text, style);

            if (mText != null)
            {
                entities.Add(mText);
            }

            dim.DefinitionPoint    = dim.EndSecondLine;
            dim.MidTextPoint       = new Vector3(midDim.X, midDim.Y, elevation); // this value is in OCS
            dim.ArcDefinitionPoint = dim.MidTextPoint;                           // this value is in OCS

            // drawing block
            return(new Block(name, false, entities, null)
            {
                Flags = BlockTypeFlags.AnonymousBlock
            });
        }
예제 #32
0
        public static Block Build(Angular2LineDimension dim, string name)
        {
            double         offset  = dim.Offset;
            double         measure = dim.Value;
            DimensionStyle style   = dim.Style;

            // we will build the dimension block in object coordinates with normal the dimension normal
            Vector3 refPoint;

            refPoint = MathHelper.Transform(dim.StartFirstLine, dim.Normal, MathHelper.CoordinateSystem.World, MathHelper.CoordinateSystem.Object);
            Vector2 ref1Start = new Vector2(refPoint.X, refPoint.Y);
            double  elevation = refPoint.Z;

            refPoint = MathHelper.Transform(dim.EndFirstLine, dim.Normal, MathHelper.CoordinateSystem.World, MathHelper.CoordinateSystem.Object);
            Vector2 ref1End = new Vector2(refPoint.X, refPoint.Y);

            refPoint = MathHelper.Transform(dim.StartSecondLine, dim.Normal, MathHelper.CoordinateSystem.World, MathHelper.CoordinateSystem.Object);
            Vector2 ref2Start = new Vector2(refPoint.X, refPoint.Y);

            refPoint = MathHelper.Transform(dim.EndSecondLine, dim.Normal, MathHelper.CoordinateSystem.World, MathHelper.CoordinateSystem.Object);
            Vector2 ref2End = new Vector2(refPoint.X, refPoint.Y);

            Vector2 dirRef1 = ref1End - ref1Start;
            Vector2 dirRef2 = ref2End - ref2Start;

            if (Vector2.AreParallel(dirRef1, dirRef2))
            {
                throw new ArgumentException("The two lines that define the dimension are parallel.");
            }

            Vector2 center     = FindIntersection(ref1Start, dirRef1, ref2Start, dirRef2);
            double  startAngle = Vector2.Angle(ref1Start, ref1End);
            double  endAngle   = Vector2.Angle(ref2Start, ref2End);
            double  cross      = Vector2.CrossProduct(dirRef1, dirRef2);
            double  aperture   = Vector2.AngleBetween(dirRef1, dirRef2);

            if (cross < 0)
            {
                Vector2 tmp1 = ref1Start;
                Vector2 tmp2 = ref1End;
                ref1Start = ref2Start;
                ref1End   = ref2End;
                ref2Start = tmp1;
                ref2End   = tmp2;
                double tmp = startAngle;
                startAngle = endAngle;
                endAngle   = tmp;
            }
            short reversed = 1;

            if (offset < 0)
            {
                Vector2 tmp1 = ref1Start;
                Vector2 tmp2 = ref2Start;
                ref1Start = ref1End;
                ref1End   = tmp1;
                ref2Start = ref2End;
                ref2End   = tmp2;
                reversed  = -1;
            }

            Vector2 dimRef1  = Vector2.Polar(center, offset, startAngle);
            Vector2 dimRef2  = Vector2.Polar(center, offset, endAngle);
            double  refAngle = Vector2.Angle(dimRef1, dimRef2);
            Vector2 midDim   = Vector2.Polar(center, offset, startAngle + aperture * 0.5);

            // reference points
            Layer defPoints = new Layer("Defpoints")
            {
                Plot = false
            };
            Point startFirstPoint = new Point(ref1Start)
            {
                Layer = defPoints
            };
            Point endFirstPoint = new Point(ref1End)
            {
                Layer = defPoints
            };
            Point startSecondPoint = new Point(ref2Start)
            {
                Layer = defPoints
            };
            Point endSecondPoint = new Point(ref2End)
            {
                Layer = defPoints
            };

            // dimension lines
            double ext1;
            double ext2;
            Arc    dimArc = DimensionArc(center, dimRef1, dimRef2, startAngle, endAngle, Math.Abs(offset), refAngle, reversed, style, out ext1, out ext2);

            // dimension arrows
            double       angle1 = Math.Asin(ext1 * 0.5 / Math.Abs(offset));
            double       angle2 = Math.Asin(ext2 * 0.5 / Math.Abs(offset));
            EntityObject arrow1 = StartArrowHead(dimRef1, (1 - reversed) * MathHelper.HalfPI + angle1 + startAngle - MathHelper.HalfPI, style);
            EntityObject arrow2 = EndArrowHead(dimRef2, (1 - reversed) * MathHelper.HalfPI + angle2 + endAngle + MathHelper.HalfPI, style);

            // dimension lines
            double dimexo = Math.Sign(offset) * style.DIMEXO * style.DIMSCALE;
            double dimexe = Math.Sign(offset) * style.DIMEXE * style.DIMSCALE;

            Line ext1Line = null;

            if (!style.DIMSE1)
            {
                ext1Line = ExtensionLine(Vector2.Polar(ref1End, dimexo, startAngle), Vector2.Polar(dimRef1, dimexe, startAngle), style, style.DIMLTEX1);
            }

            Line ext2Line = null;

            if (!style.DIMSE2)
            {
                ext2Line = ExtensionLine(Vector2.Polar(ref2End, dimexo, endAngle), Vector2.Polar(dimRef2, dimexe, endAngle), style, style.DIMLTEX1);
            }

            // dimension text
            string text    = FormatDimensionText(measure, true, style);
            double extRot  = startAngle + aperture * 0.5;
            double textRot = (extRot - MathHelper.HalfPI);
            MText  mText   = DimensionText(Vector2.Polar(midDim, style.DIMGAP * style.DIMSCALE, extRot), textRot, text, style);

            dim.DefinitionPoint    = dim.EndSecondLine;
            dim.MidTextPoint       = new Vector3(midDim.X, midDim.Y, elevation); // this value is in OCS
            dim.ArcDefinitionPoint = dim.MidTextPoint;                           // this value is in OCS

            // drawing block
            Block block = new Block(name, false)
            {
                Flags = BlockTypeFlags.AnonymousBlock
            };

            block.Entities.Add(startFirstPoint);
            block.Entities.Add(endFirstPoint);
            block.Entities.Add(startSecondPoint);
            block.Entities.Add(endSecondPoint);
            block.Entities.Add(ext1Line);
            block.Entities.Add(ext2Line);
            block.Entities.Add(dimArc);
            block.Entities.Add(arrow1);
            block.Entities.Add(arrow2);
            block.Entities.Add(mText);
            return(block);
        }
예제 #33
0
        public static Block Build(DiametricDimension dim, string name)
        {
            double              offset   = dim.Offset;
            double              measure  = dim.Measurement;
            double              radius   = measure * 0.5;
            DimensionStyle      style    = dim.Style;
            List <EntityObject> entities = new List <EntityObject>();

            // we will build the dimension block in object coordinates with normal the dimension normal
            Vector3 refPoint;

            refPoint = MathHelper.Transform(dim.CenterPoint, dim.Normal, CoordinateSystem.World, CoordinateSystem.Object);

            Vector2 centerRef = new Vector2(refPoint.X, refPoint.Y);
            double  elev      = refPoint.Z;

            refPoint = MathHelper.Transform(dim.ReferencePoint, dim.Normal, CoordinateSystem.World, CoordinateSystem.Object);
            Vector2 ref1 = new Vector2(refPoint.X, refPoint.Y);

            double  angleRef = Vector2.Angle(centerRef, ref1);
            Vector2 ref2     = Vector2.Polar(ref1, -measure, angleRef);

            short reverse = 1;

            if (angleRef > MathHelper.HalfPI && angleRef <= MathHelper.ThreeHalfPI)
            {
                reverse = -1;
            }

            short  side;
            double minOffset = 2 * style.DIMASZ + style.DIMGAP * style.DIMSCALE;

            if (offset >= radius && offset <= radius + minOffset)
            {
                offset = radius + minOffset;
                side   = -1;
            }
            else if (offset >= radius - minOffset && offset <= radius)
            {
                offset = radius - minOffset;
                side   = 1;
            }
            else if (offset > radius)
            {
                side = -1;
            }
            else
            {
                side = 1;
            }

            Vector2 dimRef = Vector2.Polar(centerRef, offset, angleRef);

            // reference points
            Layer defPoints = new Layer("Defpoints")
            {
                Plot = false
            };

            entities.Add(new Point(ref1)
            {
                Layer = defPoints
            });

            // dimension lines
            entities.Add(DimensionRadialLine(dimRef, ref1, angleRef, side, style));

            // center cross
            entities.AddRange(CenterCross(centerRef, radius, style));

            // dimension arrows
            entities.Add(EndArrowHead(ref1, (1 - side) * MathHelper.HalfPI + angleRef, style));

            // dimension text
            string text = "Ø" + FormatDimensionText(measure, false, dim.UserText, style, dim.Owner.Record.Layout);

            double textRot = angleRef;

            if (textRot > MathHelper.HalfPI && textRot <= MathHelper.ThreeHalfPI)
            {
                textRot += MathHelper.PI;
            }

            MText mText = DimensionText(Vector2.Polar(dimRef, -reverse * side * style.DIMGAP * style.DIMSCALE, textRot), textRot, text, style);

            if (mText != null)
            {
                mText.AttachmentPoint = reverse * side < 0 ? MTextAttachmentPoint.MiddleLeft : MTextAttachmentPoint.MiddleRight;
                entities.Add(mText);
            }

            dim.DefinitionPoint = MathHelper.Transform(new Vector3(ref2.X, ref2.Y, elev), dim.Normal, CoordinateSystem.Object, CoordinateSystem.World);
            dim.MidTextPoint    = new Vector3(dimRef.X, dimRef.Y, elev); // this value is in OCS

            return(new Block(name, false, entities, null));
        }
예제 #34
0
        /// <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));
            }
        }
예제 #35
0
        /// <summary>
        /// Gets the the block that contains the entities that make up the dimension picture.
        /// </summary>
        /// <param name="name">Name to be asigned to the generated block.</param>
        /// <returns>The block that represents the actual dimension.</returns>
        internal override Block BuildBlock(string name)
        {
            // we will build the dimension block in object coordinates with normal the dimension normal
            Vector3 refPoint = MathHelper.Transform(this.firstPoint, this.normal,
                                                    MathHelper.CoordinateSystem.World,
                                                    MathHelper.CoordinateSystem.Object);

            Vector2 firstRef = new Vector2(refPoint.X, refPoint.Y);

            refPoint = MathHelper.Transform(this.secondPoint, this.normal,
                                            MathHelper.CoordinateSystem.World,
                                            MathHelper.CoordinateSystem.Object);

            Vector2 secondRef = new Vector2(refPoint.X, refPoint.Y);

            double measurement = this.Value;
            double dimRot      = this.rotation * MathHelper.DegToRad;
            double elev        = refPoint.Z;

            Vector2 midRef = Vector2.MidPoint(firstRef, secondRef);

            Vector2 midDimLine = Vector2.Polar(midRef, this.offset, dimRot + MathHelper.HalfPI);


            Vector2 startDimLine = Vector2.Polar(midDimLine, measurement * 0.5, dimRot + MathHelper.PI);
            Vector2 endDimLine   = Vector2.Polar(midDimLine, measurement * 0.5, dimRot);

            // reference points
            Layer defPoints = new Layer("Defpoints")
            {
                Plot = false
            };
            Point startRef = new Point(firstRef)
            {
                Layer = defPoints
            };
            Point endRef = new Point(secondRef)
            {
                Layer = defPoints
            };
            Point defPoint = new Point(endDimLine)
            {
                Layer = defPoints
            };

            // dimension lines
            Line startBorder = new Line(Vector2.Polar(firstRef, this.style.DIMEXO, dimRot + MathHelper.HalfPI),
                                        Vector2.Polar(startDimLine, this.style.DIMEXE, dimRot + MathHelper.HalfPI));

            Line endBorder = new Line(Vector2.Polar(secondRef, this.style.DIMEXO, dimRot + MathHelper.HalfPI),
                                      Vector2.Polar(endDimLine, this.style.DIMEXE, dimRot + MathHelper.HalfPI));

            Line dimLine = new Line(startDimLine, endDimLine);

            this.definitionPoint = MathHelper.Transform(new Vector3(endDimLine.X, endDimLine.Y, elev), this.normal,
                                                        MathHelper.CoordinateSystem.Object,
                                                        MathHelper.CoordinateSystem.World);


            // dimension arrows
            Vector2 arrowRefBegin = Vector2.Polar(startDimLine, this.style.DIMASZ, dimRot);
            Solid   arrowBegin    = new Solid(startDimLine,
                                              Vector2.Polar(arrowRefBegin, -this.style.DIMASZ / 6, dimRot + MathHelper.HalfPI),
                                              Vector2.Polar(arrowRefBegin, this.style.DIMASZ / 6, dimRot + MathHelper.HalfPI),
                                              startDimLine);

            Vector2 arrowRefEnd = Vector2.Polar(endDimLine, -this.style.DIMASZ, dimRot);
            Solid   arrowEnd    = new Solid(endDimLine,
                                            Vector2.Polar(arrowRefEnd, this.style.DIMASZ / 6, dimRot + MathHelper.HalfPI),
                                            Vector2.Polar(arrowRefEnd, -this.style.DIMASZ / 6, dimRot + MathHelper.HalfPI),
                                            endDimLine);

            // dimension text
            this.midTextPoint = new Vector3(midDimLine.X, midDimLine.Y, elev); // this value is in OCS
            MText text = new MText(this.FormatDimensionText(this.Value),
                                   Vector2.Polar(midDimLine, this.style.DIMGAP, dimRot + MathHelper.HalfPI),
                                   this.style.DIMTXT, 0.0, this.style.TextStyle)
            {
                AttachmentPoint = MTextAttachmentPoint.BottomCenter,
                Rotation        = this.rotation
            };

            // drawing block
            Block dim = new Block(name);

            dim.Entities.Add(startRef);
            dim.Entities.Add(endRef);
            dim.Entities.Add(defPoint);
            dim.Entities.Add(startBorder);
            dim.Entities.Add(endBorder);
            dim.Entities.Add(dimLine);
            dim.Entities.Add(arrowBegin);
            dim.Entities.Add(arrowEnd);
            dim.Entities.Add(text);
            this.block = dim;
            return(dim);
        }
예제 #36
0
 private MText BuildAnnotation(string text)
 {
     Vector2 dir = this.vertexes[this.vertexes.Count - 1] - this.vertexes[this.vertexes.Count - 2];
     int side = Math.Sign(dir.X);
     Vector2 position = this.vertexes[this.vertexes.Count - 1] + new Vector2(side * this.style.DIMGAP * this.style.DIMSCALE, this.style.DIMGAP * this.style.DIMSCALE);
     MText entity = new MText(text, position, this.style.DIMTXT * this.style.DIMSCALE, 0.0, this.style.DIMTXSTY)
     {
         Color = this.style.DIMCLRT.IsByBlock ? AciColor.ByLayer : this.style.DIMCLRT,
         AttachmentPoint = side >= 0 ? MTextAttachmentPoint.BottomLeft : MTextAttachmentPoint.BottomRight,
     };
     return entity;
 }
예제 #37
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;
            }

            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));
            }
        }
예제 #38
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));
            }
        }
예제 #39
0
        public static Block Build(Angular3PointDimension dim, string name)
        {
            double         offset   = dim.Offset;
            double         measure  = dim.Value;
            double         aperture = measure * MathHelper.DegToRad;
            DimensionStyle style    = dim.Style;

            // we will build the dimension block in object coordinates with normal the dimension normal
            Vector3 refPoint;

            refPoint = MathHelper.Transform(dim.CenterPoint, dim.Normal, MathHelper.CoordinateSystem.World, MathHelper.CoordinateSystem.Object);
            Vector2 refCenter = new Vector2(refPoint.X, refPoint.Y);

            refPoint = MathHelper.Transform(dim.StartPoint, dim.Normal, MathHelper.CoordinateSystem.World, MathHelper.CoordinateSystem.Object);
            Vector2 ref1 = new Vector2(refPoint.X, refPoint.Y);

            refPoint = MathHelper.Transform(dim.EndPoint, dim.Normal, MathHelper.CoordinateSystem.World, MathHelper.CoordinateSystem.Object);
            Vector2 ref2 = new Vector2(refPoint.X, refPoint.Y);

            double elevation = refPoint.Z;

            double  startAngle = Vector2.Angle(refCenter, ref1);
            double  endAngle   = Vector2.Angle(refCenter, ref2);
            Vector2 dimRef1    = Vector2.Polar(refCenter, offset, startAngle);
            Vector2 dimRef2    = Vector2.Polar(refCenter, offset, endAngle);
            double  refAngle   = Vector2.Angle(dimRef1, dimRef2);
            double  midRot     = startAngle + aperture * 0.5;
            Vector2 midDim     = Vector2.Polar(refCenter, offset, midRot);

            // reference points
            Layer defPoints = new Layer("Defpoints")
            {
                Plot = false
            };
            Point startRef = new Point(ref1)
            {
                Layer = defPoints
            };
            Point endRef = new Point(ref2)
            {
                Layer = defPoints
            };
            Point centerPoint = new Point(refCenter)
            {
                Layer = defPoints
            };

            // dimension lines
            double ext1;
            double ext2;
            Arc    dimArc = DimensionArc(refCenter, dimRef1, dimRef2, startAngle, endAngle, Math.Abs(offset), refAngle, 1, style, out ext1, out ext2);

            // dimension arrows
            double       angle1 = Math.Asin(ext1 * 0.5 / Math.Abs(offset));
            double       angle2 = Math.Asin(ext2 * 0.5 / Math.Abs(offset));
            EntityObject arrow1 = StartArrowHead(dimRef1, angle1 + startAngle - MathHelper.HalfPI, style);
            EntityObject arrow2 = EndArrowHead(dimRef2, angle2 + endAngle + MathHelper.HalfPI, style);

            // dimension lines
            double dimexo = Math.Sign(offset) * style.DIMEXO * style.DIMSCALE;
            double dimexe = Math.Sign(offset) * style.DIMEXE * style.DIMSCALE;

            Line ext1Line = null;

            if (!style.DIMSE1)
            {
                ext1Line = ExtensionLine(Vector2.Polar(ref1, dimexo, startAngle), Vector2.Polar(dimRef1, dimexe, startAngle), style, style.DIMLTEX1);
            }

            Line ext2Line = null;

            if (!style.DIMSE2)
            {
                ext2Line = ExtensionLine(Vector2.Polar(ref2, dimexo, endAngle), Vector2.Polar(dimRef2, dimexe, endAngle), style, style.DIMLTEX1);
            }

            // dimension text
            string text    = FormatDimensionText(measure, true, style);
            double textRot = midRot - MathHelper.HalfPI;
            MText  mText   = DimensionText(Vector2.Polar(midDim, style.DIMGAP * style.DIMSCALE, midRot), textRot, text, style);

            dim.DefinitionPoint = MathHelper.Transform(new Vector3(midDim.X, midDim.Y, elevation), dim.Normal, MathHelper.CoordinateSystem.Object, MathHelper.CoordinateSystem.World);
            dim.MidTextPoint    = new Vector3(midDim.X, midDim.Y, elevation); // this value is in OCS

            // drawing block
            Block block = new Block(name, false);

            block.Entities.Add(startRef);
            block.Entities.Add(endRef);
            block.Entities.Add(centerPoint);
            block.Entities.Add(ext1Line);
            block.Entities.Add(ext2Line);
            block.Entities.Add(dimArc);
            block.Entities.Add(arrow1);
            block.Entities.Add(arrow2);
            block.Entities.Add(mText);
            return(block);
        }
예제 #40
0
        public static Block Build(LinearDimension dim, string name)
        {
            Vector2             ref1;
            Vector2             ref2;
            Vector2             dimRef1;
            Vector2             dimRef2;
            short               reversed;
            double              measure  = dim.Measurement;
            DimensionStyle      style    = dim.Style;
            List <EntityObject> entities = new List <EntityObject>();

            // we will build the dimension block in object coordinates with normal the dimension normal
            Vector3 refPoint;

            refPoint = MathHelper.Transform(dim.FirstReferencePoint, dim.Normal, MathHelper.CoordinateSystem.World, MathHelper.CoordinateSystem.Object);
            ref1     = new Vector2(refPoint.X, refPoint.Y);
            double elevation = refPoint.Z;

            refPoint = MathHelper.Transform(dim.SecondReferencePoint, dim.Normal, MathHelper.CoordinateSystem.World, MathHelper.CoordinateSystem.Object);
            ref2     = new Vector2(refPoint.X, refPoint.Y);

            double dimRotation = dim.Rotation * MathHelper.DegToRad;
            double refAngle    = Vector2.Angle(ref1, ref2);

            reversed = ReverseEnds(ref1, ref2, dimRotation, refAngle);

            Vector2 midRef = Vector2.MidPoint(ref1, ref2);
            Vector2 midDim = Vector2.Polar(midRef, dim.Offset, dimRotation + MathHelper.HalfPI);

            dimRef1 = Vector2.Polar(midDim, -reversed * measure * 0.5, dimRotation);
            dimRef2 = Vector2.Polar(midDim, reversed * measure * 0.5, dimRotation);

            // reference points
            Layer defPointLayer = new Layer("Defpoints")
            {
                Plot = false
            };

            entities.Add(new Point(ref1)
            {
                Layer = defPointLayer
            });
            entities.Add(new Point(ref2)
            {
                Layer = defPointLayer
            });
            entities.Add(new Point(dimRef2)
            {
                Layer = defPointLayer
            });

            // dimension line
            entities.Add(DimensionLine(dimRef1, dimRef2, dimRotation, reversed, style));

            // extension lines
            double dimexo = Math.Sign(dim.Offset) * style.DIMEXO * style.DIMSCALE;
            double dimexe = Math.Sign(dim.Offset) * style.DIMEXE * style.DIMSCALE;
            double extRot = dimRotation + MathHelper.HalfPI;

            if (!style.DIMSE1)
            {
                entities.Add(ExtensionLine(Vector2.Polar(ref1, dimexo, extRot), Vector2.Polar(dimRef1, dimexe, extRot), style, style.DIMLTEX1));
            }

            if (!style.DIMSE2)
            {
                entities.Add(ExtensionLine(Vector2.Polar(ref2, dimexo, extRot), Vector2.Polar(dimRef2, dimexe, extRot), style, style.DIMLTEX2));
            }

            entities.Add(StartArrowHead(dimRef1, Vector2.Angle(dimRef2, dimRef1), style));
            entities.Add(EndArrowHead(dimRef2, Vector2.Angle(dimRef1, dimRef2), style));

            // dimension text
            string text = FormatDimensionText(measure, false, dim.UserText, style, dim.Owner.Record.Layout);

            MText mText = DimensionText(Vector2.Polar(midDim, style.DIMGAP * style.DIMSCALE, extRot), dimRotation, text, style);

            if (mText != null)
            {
                entities.Add(mText);
            }

            dim.DefinitionPoint = MathHelper.Transform(new Vector3(dimRef2.X, dimRef2.Y, elevation), dim.Normal, MathHelper.CoordinateSystem.Object, MathHelper.CoordinateSystem.World);
            dim.MidTextPoint    = new Vector3(midDim.X, midDim.Y, elevation); // this value is in OCS

            // drawing block
            return(new Block(name, false, entities, null)
            {
                Flags = BlockTypeFlags.AnonymousBlock
            });
        }
        /// <summary>
        /// Gets the the block that contains the entities that make up the dimension picture.
        /// </summary>
        /// <param name="name">Name to be asigned to the generated block.</param>
        /// <returns>The block that represents the actual dimension.</returns>
        internal override Block BuildBlock(string name)
        {
            // we will build the dimension block in object coordinates with normal the dimension normal
            Vector3 refPoint = MathHelper.Transform(this.startFirstLine, this.normal,
                                                    MathHelper.CoordinateSystem.World,
                                                    MathHelper.CoordinateSystem.Object);
            Vector2 refStartFirst = new Vector2(refPoint.X, refPoint.Y);
            double  elev          = refPoint.Z;

            refPoint = MathHelper.Transform(this.endFirstLine, this.normal,
                                            MathHelper.CoordinateSystem.World,
                                            MathHelper.CoordinateSystem.Object);
            Vector2 refEndFirst = new Vector2(refPoint.X, refPoint.Y);

            refPoint = MathHelper.Transform(this.startSecondLine, this.normal,
                                            MathHelper.CoordinateSystem.World,
                                            MathHelper.CoordinateSystem.Object);
            Vector2 refStartSecond = new Vector2(refPoint.X, refPoint.Y);

            refPoint = MathHelper.Transform(this.endSecondLine, this.normal,
                                            MathHelper.CoordinateSystem.World,
                                            MathHelper.CoordinateSystem.Object);
            Vector2 refEndSecond = new Vector2(refPoint.X, refPoint.Y);

            double  startAngle = Vector2.Angle(refStartFirst, refEndFirst);
            double  endAngle   = Vector2.Angle(refStartSecond, refEndSecond);
            Vector2 centerRef;

            MathHelper.FindIntersection(refStartFirst, refEndFirst - refStartFirst, refStartSecond, refEndSecond - refStartSecond, out centerRef);

            // reference points
            Layer defPoints = new Layer("Defpoints")
            {
                Plot = false
            };
            Point startFirstPoint = new Point(refStartFirst)
            {
                Layer = defPoints
            };
            Point endFirstPoint = new Point(refEndFirst)
            {
                Layer = defPoints
            };
            Point startSecondPoint = new Point(refStartSecond)
            {
                Layer = defPoints
            };
            Point endSecondPoint = new Point(refEndSecond)
            {
                Layer = defPoints
            };

            // dimension lines
            Vector2 startArc    = Vector2.Polar(centerRef, this.offset, startAngle);
            Line    startBorder = new Line(Vector2.Polar(refEndFirst, this.style.DIMEXO, startAngle),
                                           Vector2.Polar(startArc, this.style.DIMEXE, startAngle));

            Vector2 endArc    = Vector2.Polar(centerRef, this.offset, endAngle);
            Line    endBorder = new Line(Vector2.Polar(refEndSecond, this.style.DIMEXO, endAngle),
                                         Vector2.Polar(endArc, this.style.DIMEXE, endAngle));

            Arc dimArc = new Arc(centerRef, this.offset, startAngle * MathHelper.RadToDeg, endAngle * MathHelper.RadToDeg);

            // dimension arrows
            Vector2 arrowRefBegin = Vector2.Polar(startArc, this.style.DIMASZ, startAngle + MathHelper.HalfPI);
            Solid   arrowBegin    = new Solid(startArc,
                                              Vector2.Polar(arrowRefBegin, -this.style.DIMASZ / 6, startAngle),
                                              Vector2.Polar(arrowRefBegin, this.style.DIMASZ / 6, startAngle),
                                              startArc);

            Vector2 arrowRefEnd = Vector2.Polar(endArc, -this.style.DIMASZ, endAngle + MathHelper.HalfPI);
            Solid   arrowEnd    = new Solid(endArc,
                                            Vector2.Polar(arrowRefEnd, this.style.DIMASZ / 6, endAngle),
                                            Vector2.Polar(arrowRefEnd, -this.style.DIMASZ / 6, endAngle),
                                            endArc);

            // dimension text
            double  aperture = this.Value;
            double  rotText  = Vector2.Angle(endArc, startArc);
            Vector2 midText  = Vector2.Polar(centerRef, this.offset + this.style.DIMGAP, startAngle + aperture * MathHelper.DegToRad * 0.5);

            this.definitionPoint    = this.endSecondLine;
            this.midTextPoint       = new Vector3(midText.X, midText.Y, elev); // this value is in OCS
            this.arcDefinitionPoint = midTextPoint;                            // this value is in OCS

            MText text = new MText(this.FormatDimensionText(aperture),
                                   midTextPoint,
                                   this.style.DIMTXT, 0.0, this.style.TextStyle)
            {
                AttachmentPoint = MTextAttachmentPoint.BottomCenter,
                Rotation        = rotText * MathHelper.RadToDeg
            };

            // drawing block
            Block dim = new Block(name);

            dim.Entities.Add(startFirstPoint);
            dim.Entities.Add(endFirstPoint);
            dim.Entities.Add(startSecondPoint);
            dim.Entities.Add(endSecondPoint);
            dim.Entities.Add(startBorder);
            dim.Entities.Add(endBorder);
            dim.Entities.Add(dimArc);
            dim.Entities.Add(arrowBegin);
            dim.Entities.Add(arrowEnd);
            dim.Entities.Add(text);
            this.block = dim;
            return(dim);
        }
예제 #42
0
        public static Block Build(RadialDimension dim, string name)
        {
            double         offset  = dim.Offset;
            double         measure = dim.Value;
            DimensionStyle style   = dim.Style;

            // we will build the dimension block in object coordinates with normal the dimension normal
            Vector3 refPoint;

            refPoint = MathHelper.Transform(dim.CenterPoint, dim.Normal, MathHelper.CoordinateSystem.World, MathHelper.CoordinateSystem.Object);

            Vector2 centerRef = new Vector2(refPoint.X, refPoint.Y);
            double  elev      = refPoint.Z;

            refPoint = MathHelper.Transform(dim.ReferencePoint, dim.Normal, MathHelper.CoordinateSystem.World, MathHelper.CoordinateSystem.Object);
            Vector2 ref1 = new Vector2(refPoint.X, refPoint.Y);

            double  angleRef = Vector2.Angle(centerRef, ref1);
            Vector2 ref2     = Vector2.Polar(ref1, -measure, angleRef);

            short reverse = 1;

            if (angleRef > MathHelper.HalfPI && angleRef <= MathHelper.ThreeHalfPI)
            {
                reverse = -1;
            }

            short  side      = 1;
            double minOffset = 2 * style.DIMASZ + style.DIMGAP * style.DIMSCALE;

            if (offset > (measure - minOffset) && offset < measure)
            {
                offset = measure - minOffset;
                side   = 1;
            }
            else if (offset >= measure && offset < (measure + minOffset))
            {
                offset = measure + minOffset;
                side   = -1;
            }

            Vector2 dimRef = Vector2.Polar(centerRef, offset, angleRef);

            // reference points
            Layer defPoints = new Layer("Defpoints")
            {
                Plot = false
            };
            Point startRef = new Point(ref1)
            {
                Layer = defPoints
            };

            // dimension lines
            Line dimLine = DimensionRadialLine(dimRef, ref1, angleRef, side, style);

            // center cross
            List <EntityObject> centerCross = CenterCross(centerRef, measure, style);

            // dimension arrows
            //EntityObject arrow1 = StartArrowHead(ref1, angleRef, style);
            EntityObject arrow2 = EndArrowHead(ref1, (1 - side) * MathHelper.HalfPI + angleRef, style);

            // dimension text
            string text    = "R" + FormatDimensionText(measure, false, style);
            double textRot = angleRef;

            if (textRot > MathHelper.HalfPI && textRot <= MathHelper.ThreeHalfPI)
            {
                textRot += MathHelper.PI;
            }
            MText mText = DimensionText(Vector2.Polar(dimRef, -reverse * side * style.DIMGAP * style.DIMSCALE, textRot), textRot, text, style);

            mText.AttachmentPoint = reverse * side < 0 ? MTextAttachmentPoint.MiddleLeft : MTextAttachmentPoint.MiddleRight;
            dim.DefinitionPoint   = MathHelper.Transform(new Vector3(ref2.X, ref2.Y, elev), dim.Normal, MathHelper.CoordinateSystem.Object, MathHelper.CoordinateSystem.World);
            dim.MidTextPoint      = new Vector3(dimRef.X, dimRef.Y, elev); // this value is in OCS

            Block block = new Block(name, false);

            block.Entities.Add(startRef);
            block.Entities.Add(dimLine);
            block.Entities.AddRange(centerCross);
            block.Entities.Add(arrow2);
            block.Entities.Add(mText);
            return(block);
        }