/// <summary> /// Creates a new Angular3PointDimension that is a copy of the current instance. /// </summary> /// <returns>A new Angular3PointDimension that is a copy of this instance.</returns> public override object Clone() { Angular3PointDimension entity = new Angular3PointDimension { //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, //Angular3PointDimension properties CenterPoint = this.center, StartPoint = this.start, EndPoint = this.end, Offset = this.offset }; foreach (XData data in this.XData.Values) { entity.XData.Add((XData)data.Clone()); } return(entity); }
/// <summary> /// Creates a new Angular3PointDimension that is a copy of the current instance. /// </summary> /// <returns>A new Angular3PointDimension that is a copy of this instance.</returns> public override object Clone() { Angular3PointDimension entity = new Angular3PointDimension { //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, UserText = this.UserText, //Angular3PointDimension properties CenterPoint = this.center, StartPoint = this.start, EndPoint = this.end, Offset = this.offset, Elevation = this.Elevation }; foreach (XData data in this.XData.Values) { entity.XData.Add((XData)data.Clone()); } return(entity); }
/// <summary> /// Creates a new Angular3PointDimension that is a copy of the current instance. /// </summary> /// <returns>A new Angular3PointDimension that is a copy of this instance.</returns> public override object Clone() { Angular3PointDimension entity = new Angular3PointDimension { //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, //Angular3PointDimension properties CenterPoint = this.center, StartPoint = this.start, EndPoint = this.end, Offset = this.offset }; 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); }
private void WriteAngular3PointDimension(Angular3PointDimension dim) { this.chunk.Write(100, SubclassMarker.Angular3PointDimension); this.chunk.Write(13, dim.FirstPoint.X); this.chunk.Write(23, dim.FirstPoint.Y); this.chunk.Write(33, dim.FirstPoint.Z); this.chunk.Write(14, dim.SecondPoint.X); this.chunk.Write(24, dim.SecondPoint.Y); this.chunk.Write(34, dim.SecondPoint.Z); this.chunk.Write(15, dim.CenterPoint.X); this.chunk.Write(25, dim.CenterPoint.Y); this.chunk.Write(35, dim.CenterPoint.Z); this.chunk.Write(40, 0.0); this.WriteXData(dim.XData); }
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); }
public static Block Build(Angular3PointDimension 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 refCenter = dim.CenterPoint; Vector2 ref1 = dim.StartPoint; Vector2 ref2 = dim.EndPoint; if (side < 0) { Vector2 tmp = ref1; ref1 = ref2; ref2 = tmp; } double startAngle = Vector2.Angle(refCenter, ref1); double endAngle = Vector2.Angle(refCenter, ref2); double midRot = startAngle + measure*MathHelper.DegToRad*0.5; //if (midRot > MathHelper.TwoPI) midRot -= MathHelper.TwoPI; Vector2 dimRef1 = Vector2.Polar(refCenter, offset, startAngle); Vector2 dimRef2 = Vector2.Polar(refCenter, offset, endAngle); 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, 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; if (!style.ExtLine1) entities.Add(ExtensionLine(Vector2.Polar(ref1, dimexo, startAngle), Vector2.Polar(dimRef1, dimexe, startAngle), style, style.ExtLine1Linetype)); if (!style.ExtLine2) entities.Add(ExtensionLine(Vector2.Polar(ref2, dimexo, endAngle), Vector2.Polar(dimRef2, dimexe, endAngle), style, style.ExtLine1Linetype)); // dimension text 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(midDim.X, midDim.Y, dim.Elevation), dim.Normal, CoordinateSystem.Object, CoordinateSystem.World); dim.MidTextPoint = new Vector3(midDim.X, midDim.Y, dim.Elevation); // this value is in OCS // drawing block return new Block(name, false, entities, null); }
private Angular3PointDimension ReadAngular3PointDimension(Vector3 defPoint, Vector3 normal) { Vector3 center = Vector3.Zero; Vector3 firstRef = Vector3.Zero; Vector3 secondRef = Vector3.Zero; List<XData> xData = new List<XData>(); while (this.chunk.Code != 0) { switch (this.chunk.Code) { case 13: firstRef.X = this.chunk.ReadDouble(); this.chunk.Next(); break; case 23: firstRef.Y = this.chunk.ReadDouble(); this.chunk.Next(); break; case 33: firstRef.Z = this.chunk.ReadDouble(); this.chunk.Next(); break; case 14: secondRef.X = this.chunk.ReadDouble(); this.chunk.Next(); break; case 24: secondRef.Y = this.chunk.ReadDouble(); this.chunk.Next(); break; case 34: secondRef.Z = this.chunk.ReadDouble(); this.chunk.Next(); break; case 15: center.X = this.chunk.ReadDouble(); this.chunk.Next(); break; case 25: center.Y = this.chunk.ReadDouble(); this.chunk.Next(); break; case 35: center.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[] { center, firstRef, secondRef, defPoint }, normal, CoordinateSystem.World, CoordinateSystem.Object); Angular3PointDimension entity = new Angular3PointDimension { CenterPoint = new Vector2(ocsPoints[0].X, ocsPoints[0].Y), StartPoint = new Vector2(ocsPoints[1].X, ocsPoints[1].Y), EndPoint = new Vector2(ocsPoints[2].X, ocsPoints[2].Y), }; entity.SetDimensionLinePosition(new Vector2(ocsPoints[3].X, ocsPoints[3].Y)); entity.XData.AddRange(xData); return entity; }
private void WriteAngular3PointDimension(Angular3PointDimension dim) { this.chunk.Write(100, SubclassMarker.Angular3PointDimension); IList<Vector3> wcsPoints = MathHelper.Transform( new[] { new Vector3(dim.StartPoint.X, dim.StartPoint.Y, dim.Elevation), new Vector3(dim.EndPoint.X, dim.EndPoint.Y, dim.Elevation), new Vector3(dim.CenterPoint.X, dim.CenterPoint.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(40, 0.0); this.WriteXData(dim.XData); }
public static Block Build(Angular3PointDimension dim, string name) { double offset = 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 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 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 = Math.Sign(offset) * style.DIMEXO * style.DIMSCALE; double dimexe = Math.Sign(offset) * 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; MText mText = DimensionText(Vector2.Polar(midDim, style.DIMGAP * style.DIMSCALE, midRot), textRot, text, style); if (mText != null) entities.Add(mText); 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 return new Block(name, false, entities, null); }
private static void Angular3PointDimensionDrawing() { DxfDocument dxf = new DxfDocument(); Vector3 center = new Vector3(1, 2, 0); double radius = 2.42548; Arc arc = new Arc(center, radius, -30, 60); //arc.Normal = new Vector3(1, 1, 1); DimensionStyle myStyle = new DimensionStyle("MyStyle"); Angular3PointDimension dim = new Angular3PointDimension(arc, 5, myStyle); dxf.AddEntity(arc); dxf.AddEntity(dim); dxf.Save("angular 3 point dimension.dxf"); dxf = DxfDocument.Load("angular 3 point dimension.dxf"); }
private static void Angular3PointDimension() { DxfDocument dxf = new DxfDocument(); DimensionStyle myStyle = CreateDimStyle(); myStyle.DIMADEC = 4; myStyle.DIMAUNIT = AngleUnitType.DegreesMinutesSeconds; Vector3 center = new Vector3(1, 2, 0); double radius = 2.5; Arc arc = new Arc(center, radius, -32.8, 160.5); Angular3PointDimension dim1 = new Angular3PointDimension(arc, 5, myStyle); Angular3PointDimension dim2 = new Angular3PointDimension(arc, -5, myStyle); dxf.AddEntity(arc); dxf.AddEntity(dim1); dxf.AddEntity(dim2); dxf.Save("dimension drawing.dxf"); dxf = DxfDocument.Load("dimension drawing.dxf"); DxfDocument doc = new DxfDocument(); foreach (var c in dxf.Circles) { doc.AddEntity((EntityObject)c.Clone()); } foreach (var d in dxf.Dimensions) { doc.AddEntity((EntityObject)d.Clone()); } doc.Save("dimension drawing saved.dxf"); }
private Angular3PointDimension ReadAngular3PointDimension(Vector3 defPoint) { Vector3 center = Vector3.Zero; Vector3 firstRef = Vector3.Zero; Vector3 secondRef = Vector3.Zero; List<XData> xData = new List<XData>(); while (this.chunk.Code != 0) { switch (this.chunk.Code) { case 13: firstRef.X = this.chunk.ReadDouble(); this.chunk.Next(); break; case 23: firstRef.Y = this.chunk.ReadDouble(); this.chunk.Next(); break; case 33: firstRef.Z = this.chunk.ReadDouble(); this.chunk.Next(); break; case 14: secondRef.X = this.chunk.ReadDouble(); this.chunk.Next(); break; case 24: secondRef.Y = this.chunk.ReadDouble(); this.chunk.Next(); break; case 34: secondRef.Z = this.chunk.ReadDouble(); this.chunk.Next(); break; case 15: center.X = this.chunk.ReadDouble(); this.chunk.Next(); break; case 25: center.Y = this.chunk.ReadDouble(); this.chunk.Next(); break; case 35: center.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; } } Angular3PointDimension entity = new Angular3PointDimension { CenterPoint = center, FirstPoint = firstRef, SecondPoint = secondRef, Offset = Vector3.Distance(center, defPoint) }; entity.XData.AddRange(xData); return entity; }
/// <summary> /// Creates a new Angular3PointDimension that is a copy of the current instance. /// </summary> /// <returns>A new Angular3PointDimension that is a copy of this instance.</returns> public override object Clone() { Angular3PointDimension entity = new Angular3PointDimension { //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, //Angular3PointDimension properties CenterPoint = this.center, StartPoint = this.start, EndPoint = this.end, Offset = this.offset, Elevation = this.Elevation }; foreach (XData data in this.XData.Values) entity.XData.Add((XData) data.Clone()); return entity; }
private Angular3PointDimension ReadAngular3PointDimension(Vector3 defPoint, Vector3 normal) { Vector3 center = Vector3.Zero; Vector3 firstRef = Vector3.Zero; Vector3 secondRef = Vector3.Zero; List<XData> xData = new List<XData>(); while (this.chunk.Code != 0) { switch (this.chunk.Code) { case 13: firstRef.X = this.chunk.ReadDouble(); this.chunk.Next(); break; case 23: firstRef.Y = this.chunk.ReadDouble(); this.chunk.Next(); break; case 33: firstRef.Z = this.chunk.ReadDouble(); this.chunk.Next(); break; case 14: secondRef.X = this.chunk.ReadDouble(); this.chunk.Next(); break; case 24: secondRef.Y = this.chunk.ReadDouble(); this.chunk.Next(); break; case 34: secondRef.Z = this.chunk.ReadDouble(); this.chunk.Next(); break; case 15: center.X = this.chunk.ReadDouble(); this.chunk.Next(); break; case 25: center.Y = this.chunk.ReadDouble(); this.chunk.Next(); break; case 35: center.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; } } IList<Vector3> ocsPoints = MathHelper.Transform(new[] {center, firstRef, secondRef, defPoint}, 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); refPoint = ocsPoints[3]; Vector2 midTxt = new Vector2(refPoint.X, refPoint.Y); double aperture = (Vector2.Angle(refCenter, ref2) - Vector2.Angle(refCenter, ref1)) * MathHelper.RadToDeg; aperture = MathHelper.NormalizeAngle(aperture); double angle = (Vector2.Angle(refCenter, ref2) - Vector2.Angle(refCenter, midTxt)) * MathHelper.RadToDeg; angle = MathHelper.NormalizeAngle(angle); double offset = Vector3.Distance(center, defPoint); if (angle > aperture) offset *= -1; Angular3PointDimension entity = new Angular3PointDimension { CenterPoint = center, FirstPoint = firstRef, SecondPoint = secondRef, Offset = offset }; entity.XData.AddRange(xData); return entity; }
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)); }
/// <summary> /// Creates a new Angular3PointDimension that is a copy of the current instance. /// </summary> /// <returns>A new Angular3PointDimension that is a copy of this instance.</returns> public override object Clone() { Angular3PointDimension entity = new Angular3PointDimension { //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, //Angular3PointDimension properties CenterPoint = this.center, StartPoint = this.start, EndPoint = this.end, Offset = this.offset }; foreach (XData data in this.XData.Values) entity.XData.Add((XData)data.Clone()); return entity; }
private static void Angular3PointDimension() { DxfDocument dxf = new DxfDocument(); DimensionStyle myStyle = CreateDimStyle(); Vector3 center = new Vector3(1, 2, 0); double radius = 2.42548; Arc arc = new Arc(center, radius, -30, 60); Angular3PointDimension dim1 = new Angular3PointDimension(arc, 5, myStyle); Angular3PointDimension dim2 = new Angular3PointDimension(arc, -5, myStyle); dxf.AddEntity(arc); dxf.AddEntity(dim1); dxf.AddEntity(dim2); dxf.Save("dimension drawing.dxf"); dxf = DxfDocument.Load("dimension drawing.dxf"); }