/// <summary>
        /// Creates a new Angular2LineDimension that is a copy of the current instance.
        /// </summary>
        /// <returns>A new Angular2LineDimension that is a copy of this instance.</returns>
        public override object Clone()
        {
            Angular2LineDimension entity = new Angular2LineDimension
            {
                //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,
                //Dimension properties
                Style             = (DimensionStyle)this.Style.Clone(),
                AttachmentPoint   = this.AttachmentPoint,
                LineSpacingStyle  = this.LineSpacingStyle,
                LineSpacingFactor = this.LineSpacingFactor,
                //Angular2LineDimension properties
                StartFirstLine  = this.startFirstLine,
                EndFirstLine    = this.endFirstLine,
                StartSecondLine = this.startSecondLine,
                EndSecondLine   = this.endSecondLine,
                Offset          = this.offset,
                Elevation       = this.Elevation
            };

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

            return(entity);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new Angular2LineDimension that is a copy of the current instance.
        /// </summary>
        /// <returns>A new Angular2LineDimension that is a copy of this instance.</returns>
        public override object Clone()
        {
            Angular2LineDimension entity = new Angular2LineDimension
            {
                //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,
                //Dimension properties
                Style             = this.style,
                AttachmentPoint   = this.attachmentPoint,
                LineSpacingStyle  = this.lineSpacingStyle,
                LineSpacingFactor = this.lineSpacing,
                //Angular2LineDimension properties
                StartFirstLine  = this.startFirstLine,
                EndFirstLine    = this.endFirstLine,
                StartSecondLine = this.startSecondLine,
                EndSecondLine   = this.endSecondLine,
                Offset          = this.offset
            };

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

            return(entity);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a new Angular2LineDimension that is a copy of the current instance.
        /// </summary>
        /// <returns>A new Angular2LineDimension that is a copy of this instance.</returns>
        public override object Clone()
        {
            Angular2LineDimension entity = new Angular2LineDimension
            {
                //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,
                //Dimension properties
                Style                   = (DimensionStyle)this.Style.Clone(),
                DefinitionPoint         = this.DefinitionPoint,
                TextReferencePoint      = this.TextReferencePoint,
                TextPositionManuallySet = this.TextPositionManuallySet,
                TextRotation            = this.TextRotation,
                AttachmentPoint         = this.AttachmentPoint,
                LineSpacingStyle        = this.LineSpacingStyle,
                LineSpacingFactor       = this.LineSpacingFactor,
                UserText                = this.UserText,
                Elevation               = this.Elevation,
                //Angular2LineDimension properties
                StartFirstLine     = this.startFirstLine,
                EndFirstLine       = this.endFirstLine,
                StartSecondLine    = this.startSecondLine,
                EndSecondLine      = this.endSecondLine,
                Offset             = this.offset,
                arcDefinitionPoint = this.arcDefinitionPoint
            };

            foreach (DimensionStyleOverride styleOverride in this.StyleOverrides.Values)
            {
                object     copy;
                ICloneable value = styleOverride.Value as ICloneable;
                copy = value != null?value.Clone() : styleOverride.Value;

                entity.StyleOverrides.Add(new DimensionStyleOverride(styleOverride.Type, copy));
            }

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

            return(entity);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a new Angular2LineDimension that is a copy of the current instance.
        /// </summary>
        /// <returns>A new Angular2LineDimension that is a copy of this instance.</returns>
        public override object Clone()
        {
            Angular2LineDimension entity = new Angular2LineDimension
            {
                //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,
                //Dimension properties
                Style = (DimensionStyle) this.Style.Clone(),
                AttachmentPoint = this.AttachmentPoint,
                LineSpacingStyle = this.LineSpacingStyle,
                LineSpacingFactor = this.LineSpacingFactor,
                //Angular2LineDimension properties
                StartFirstLine = this.startFirstLine,
                EndFirstLine = this.endFirstLine,
                StartSecondLine = this.startSecondLine,
                EndSecondLine = this.endSecondLine,
                Offset = this.offset,
                Elevation = this.Elevation
            };

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

            return entity;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a new Angular2LineDimension that is a copy of the current instance.
        /// </summary>
        /// <returns>A new Angular2LineDimension that is a copy of this instance.</returns>
        public override object Clone()
        {
            Angular2LineDimension entity = new Angular2LineDimension
                {
                    //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,
                    //Dimension properties
                    Style = (DimensionStyle)this.style.Clone(),
                    AttachmentPoint = this.attachmentPoint,
                    LineSpacingStyle = this.lineSpacingStyle,
                    LineSpacingFactor = this.lineSpacing,
                    //Angular2LineDimension properties
                    StartFirstLine = this.startFirstLine,
                    EndFirstLine = this.endFirstLine,
                    StartSecondLine = this.startSecondLine,
                    EndSecondLine = this.endSecondLine,
                    Offset = this.offset
                };

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

            return entity;

        }
Ejemplo n.º 6
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
            });
        }
Ejemplo n.º 7
0
        private void WriteAngular2LineDimension(Angular2LineDimension dim)
        {
            this.chunk.Write(100, SubclassMarker.Angular2LineDimension);

            this.chunk.Write(13, dim.StartFirstLine.X);
            this.chunk.Write(23, dim.StartFirstLine.Y);
            this.chunk.Write(33, dim.StartFirstLine.Z);

            this.chunk.Write(14, dim.EndFirstLine.X);
            this.chunk.Write(24, dim.EndFirstLine.Y);
            this.chunk.Write(34, dim.EndFirstLine.Z);

            this.chunk.Write(15, dim.StartSecondLine.X);
            this.chunk.Write(25, dim.StartSecondLine.Y);
            this.chunk.Write(35, dim.StartSecondLine.Z);

            this.chunk.Write(16, dim.ArcDefinitionPoint.X);
            this.chunk.Write(26, dim.ArcDefinitionPoint.Y);
            this.chunk.Write(36, dim.ArcDefinitionPoint.Z);

            this.chunk.Write(40, 0.0);

            this.WriteXData(dim.XData);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        public static Block Build(Angular2LineDimension dim, string name)
        {
            double offset = Math.Abs(dim.Offset);
            double side = Math.Sign(dim.Offset);
            double measure = dim.Measurement;
            DimensionStyle style = BuildDimensionStyleOverride(dim);
            List<EntityObject> entities = new List<EntityObject>();

            Vector2 ref1Start = dim.StartFirstLine;
            Vector2 ref1End = dim.EndFirstLine;
            Vector2 ref2Start = dim.StartSecondLine;
            Vector2 ref2End = dim.EndSecondLine;

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

            Vector2 dirRef1 = ref1End - ref1Start;
            Vector2 dirRef2 = ref2End - ref2Start;
            Vector2 center = MathHelper.FindIntersection(ref1Start, dirRef1, ref2Start, dirRef2);
            if (Vector2.IsNaN(center))
                throw new ArgumentException("The two lines that define the dimension are parallel.");

            double startAngle = Vector2.Angle(center, ref1End);
            double endAngle = Vector2.Angle(center, ref2End);
            double cross = Vector2.CrossProduct(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;
            }

            double midRot = startAngle + measure*MathHelper.DegToRad*0.5;
            //if (midRot > MathHelper.TwoPI) midRot -= MathHelper.TwoPI;
            Vector2 dimRef1 = Vector2.Polar(center, offset, startAngle);
            Vector2 dimRef2 = Vector2.Polar(center, offset, endAngle);
            Vector2 midDim = Vector2.Polar(center, offset, midRot);

            // 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, offset, style, out ext1, out ext2));

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

            // dimension lines
            double dimexo = style.ExtLineOffset*style.DimScaleOverall;
            double dimexe = style.ExtLineExtend*style.DimScaleOverall;

            // 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.ExtLine1 && t != 0)
            {
                Vector2 s = Vector2.Polar(t < 0 ? ref1Start : ref1End, t*dimexo, startAngle);
                entities.Add(ExtensionLine(s, Vector2.Polar(dimRef1, t*dimexe, startAngle), style, style.ExtLine1Linetype));
            }

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

            double textRot = midRot - MathHelper.HalfPI;
            double gap = style.TextOffset*style.DimScaleOverall;
            if (textRot > MathHelper.HalfPI && textRot <= MathHelper.ThreeHalfPI)
            {
                textRot += MathHelper.PI;
                gap *= -1;
            }
            string text = FormatDimensionText(measure, true, dim.UserText, style, dim.Owner.Record.Layout);
            MText mText = DimensionText(Vector2.Polar(midDim, gap, midRot), textRot, text, style);
            if (mText != null)
                entities.Add(mText);

            dim.DefinitionPoint =
                MathHelper.Transform(
                    new Vector3(dim.EndSecondLine.X, dim.EndSecondLine.Y, dim.Elevation),
                    dim.Normal, CoordinateSystem.Object, CoordinateSystem.World);
            dim.MidTextPoint = new Vector3(midDim.X, midDim.Y, dim.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};
        }
Ejemplo n.º 10
0
        private Angular2LineDimension ReadAngular2LineDimension(Vector3 defPoint, Vector3 normal)
        {
            Vector3 startFirstLine = Vector3.Zero;
            Vector3 endFirstLine = Vector3.Zero;
            Vector3 startSecondLine = Vector3.Zero;
            Vector3 arcDefinitionPoint = Vector3.Zero;

            List<XData> xData = new List<XData>();

            while (this.chunk.Code != 0)
            {
                switch (this.chunk.Code)
                {
                    case 13:
                        startFirstLine.X = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 23:
                        startFirstLine.Y = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 33:
                        startFirstLine.Z = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 14:
                        endFirstLine.X = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 24:
                        endFirstLine.Y = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 34:
                        endFirstLine.Z = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 15:
                        startSecondLine.X = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 25:
                        startSecondLine.Y = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 35:
                        startSecondLine.Z = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 16:
                        arcDefinitionPoint.X = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 26:
                        arcDefinitionPoint.Y = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 36:
                        arcDefinitionPoint.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;
                }
            }

            IList<Vector3> ocsPoints = MathHelper.Transform(
                new[]
                {
                    startFirstLine, endFirstLine, startSecondLine, defPoint
                },
                normal, CoordinateSystem.World, CoordinateSystem.Object);

            Angular2LineDimension entity = new Angular2LineDimension
            {
                StartFirstLine = new Vector2(ocsPoints[0].X, ocsPoints[0].Y),
                EndFirstLine = new Vector2(ocsPoints[1].X, ocsPoints[1].Y),
                StartSecondLine = new Vector2(ocsPoints[2].X, ocsPoints[2].Y),
                EndSecondLine = new Vector2(ocsPoints[3].X, ocsPoints[3].Y),
                Elevation = arcDefinitionPoint.Z
            };

            entity.SetDimensionLinePosition(new Vector2(arcDefinitionPoint.X, arcDefinitionPoint.Y));
            entity.XData.AddRange(xData);

            return entity;
        }
Ejemplo n.º 11
0
        private void WriteAngular2LineDimension(Angular2LineDimension dim)
        {
            this.chunk.Write(100, SubclassMarker.Angular2LineDimension);

            IList<Vector3> wcsPoints = MathHelper.Transform(
                new[]
                {
                    new Vector3(dim.StartFirstLine.X, dim.StartFirstLine.Y, dim.Elevation),
                    new Vector3(dim.EndFirstLine.X, dim.EndFirstLine.Y, dim.Elevation),
                    new Vector3(dim.StartSecondLine.X, dim.StartSecondLine.Y, dim.Elevation)
                },
                dim.Normal, CoordinateSystem.Object, CoordinateSystem.World);

            this.chunk.Write(13, wcsPoints[0].X);
            this.chunk.Write(23, wcsPoints[0].Y);
            this.chunk.Write(33, wcsPoints[0].Z);

            this.chunk.Write(14, wcsPoints[1].X);
            this.chunk.Write(24, wcsPoints[1].Y);
            this.chunk.Write(34, wcsPoints[1].Z);

            this.chunk.Write(15, wcsPoints[2].X);
            this.chunk.Write(25, wcsPoints[2].Y);
            this.chunk.Write(35, wcsPoints[2].Z);

            this.chunk.Write(16, dim.ArcDefinitionPoint.X);
            this.chunk.Write(26, dim.ArcDefinitionPoint.Y);
            this.chunk.Write(36, dim.ArcDefinitionPoint.Z);

            this.chunk.Write(40, 0.0);

            this.WriteXData(dim.XData);
        }
Ejemplo n.º 12
0
        public static Block Build(Angular2LineDimension dim, string name)
        {
            double offset = 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
            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);
            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 = Math.Sign(offset)*style.DIMEXO*style.DIMSCALE;
            double dimexe = Math.Sign(offset)*style.DIMEXE*style.DIMSCALE;
            if (!style.DIMSE1) entities.Add(ExtensionLine(Vector2.Polar(ref1End, dimexo, startAngle), Vector2.Polar(dimRef1, dimexe, startAngle), style, style.DIMLTEX1));
            if (!style.DIMSE2) entities.Add(ExtensionLine(Vector2.Polar(ref2End, 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 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};
        }
Ejemplo n.º 13
0
        public static void DimensionsLinearAndAngularUnits()
        {
            DimensionStyle style = new DimensionStyle("MyStyle")
            {
                // DIMDEC defines the number of decimal places.
                // For Architectural and Fractional units the minimum fraction is defined by 1/2^DIMDEC.
                DIMDEC = 4,
                DIMFRAC = FractionFormatType.Horizontal,
                DIMLUNIT = LinearUnitType.Engineering,
                SuppressLinearTrailingZeros = true,
                SuppressZeroFeet = false,
                SuppressZeroInches = false,
                DIMLFAC = 10.0,
                // the round off to nearest DIMRND is applied to the linear dimension measurement after applying the scale DIMLFAC
                DIMRND = 0.025,
                DIMADEC = 2,
                DIMAUNIT = AngleUnitType.DegreesMinutesSeconds
            };

            Layer layer = new Layer("Layer1") { Color = AciColor.Blue };

            Vector3 p1 = new Vector3(0, 0, 0);
            Vector3 p2 = new Vector3(21.2548, 0, 0);

            LinearDimension dim = new LinearDimension(p1, p2, 4, 0, style);

            Vector2 s1 = new Vector2(-2, 2);
            Vector2 s2 = new Vector2(2, -2);

            Vector2 e1 = new Vector2(-1, -3);
            Vector2 e2 = new Vector2(1, 3);

            Line line1 = new Line(s1, s2) { Layer = layer };
            Line line2 = new Line(e1, e2) { Layer = layer };
            Angular2LineDimension dim1 = new Angular2LineDimension(line2, line1, 4, style);

            DxfDocument doc = new DxfDocument();
            doc.AddEntity(dim);
            doc.AddEntity(dim1);
            doc.Save("DimensionsLinearAndAngularUnits.dxf");

            DxfDocument dxf = DxfDocument.Load("DimensionsLinearAndAngularUnits.dxf");
        }
Ejemplo n.º 14
0
        private static void Angular2LineDimensionDrawing()
        {
            double offset = 7.5;
            
            Line line1 = new Line(new Vector2(1, 2), new Vector2(6, 0));
            Line line2 = new Line(new Vector2(2, 1), new Vector2(4,5));

            Angular2LineDimension dim = new Angular2LineDimension(line1, line2, offset);
            
            DxfDocument dxf = new DxfDocument();
            //dxf.AddEntity(line1);
            //dxf.AddEntity(line2);
            //dxf.AddEntity(dim);

            Block block = new Block("DimensionBlock");
            block.Entities.Add(line1);
            block.Entities.Add(line2);
            block.Entities.Add(dim);
            Insert insert = new Insert(block);

            dxf.AddEntity(insert);

            dxf.Save("angular 2 line dimension.dxf");
            dxf = DxfDocument.Load("angular 2 line dimension.dxf");
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2010;
            dxf.Save("angular 2 line dimension.dxf");
        }
Ejemplo n.º 15
0
        private static void Angular2LineDimension()
        {
            DimensionStyle myStyle = CreateDimStyle();

            double offset = 4;

            Layer layer = new Layer("Layer1") {Color = AciColor.Blue};
            Vector2 s1 = new Vector2(-2, 2);
            Vector2 s2 = new Vector2(2, -2);

            Vector2 e1 = new Vector2(-1,-3);
            Vector2 e2 = new Vector2(1,3);

            Line line1 = new Line(s1, s2){Layer = layer};
            Line line2 = new Line(e1, e2){Layer = layer};
            Angular2LineDimension dim1 = new Angular2LineDimension(line1, line2, offset, myStyle);
            Angular2LineDimension dim2 = new Angular2LineDimension(line1, line2, -offset, myStyle);
            line1.Reverse();
            Angular2LineDimension dim3 = new Angular2LineDimension(line2, line1, offset, myStyle);
            Angular2LineDimension dim4 = new Angular2LineDimension(line2, line1, -offset, myStyle);

            DxfDocument dxf = new DxfDocument();
            dxf.AddEntity(line1);
            dxf.AddEntity(line2);
            dxf.AddEntity(dim1);
            dxf.AddEntity(dim2);
            dxf.AddEntity(dim3);
            dxf.AddEntity(dim4);
            dxf.Save("dimension drawing.dxf");
            dxf = DxfDocument.Load("dimension drawing.dxf");
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2010;
            dxf.Save("dimension drawing saved.dxf");
        }
Ejemplo n.º 16
0
        private Angular2LineDimension ReadAngular2LineDimension(Vector3 defPoint)
        {
            Vector3 startFirstLine = Vector3.Zero;
            Vector3 endFirstLine = Vector3.Zero;
            Vector3 startSecondLine = Vector3.Zero;
            Vector3 arcDefinitionPoint = Vector3.Zero;

            List<XData> xData = new List<XData>();

            while (this.chunk.Code != 0)
            {
                switch (this.chunk.Code)
                {
                    case 13:
                        startFirstLine.X = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 23:
                        startFirstLine.Y = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 33:
                        startFirstLine.Z = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 14:
                        endFirstLine.X = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 24:
                        endFirstLine.Y = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 34:
                        endFirstLine.Z = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 15:
                        startSecondLine.X = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 25:
                        startSecondLine.Y = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 35:
                        startSecondLine.Z = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 16:
                        arcDefinitionPoint.X = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 26:
                        arcDefinitionPoint.Y = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 36:
                        arcDefinitionPoint.Z = this.chunk.ReadDouble();
                        this.chunk.Next();
                        break;
                    case 1001:
                        string appId = this.DecodeEncodedNonAsciiCharacters(this.chunk.ReadString());
                        XData data = this.ReadXDataRecord(appId);
                        xData.Add(data);
                        break;
                    default:
                        if (this.chunk.Code >= 1000 && this.chunk.Code <= 1071)
                            throw new DxfInvalidCodeValueEntityException(this.chunk.Code, this.chunk.ReadString(),
                                "The extended data of an entity must start with the application registry code.");
                        this.chunk.Next();
                        break;
                }
            }
            Angular2LineDimension entity = new Angular2LineDimension
            {
                StartFirstLine = startFirstLine,
                EndFirstLine = endFirstLine,
                StartSecondLine = startSecondLine,
                EndSecondLine = defPoint,
                Offset = Vector3.Distance(startSecondLine, defPoint),
                ArcDefinitionPoint = arcDefinitionPoint
            };

            entity.XData.AddRange(xData);

            return entity;
        }