/// <summary> /// Creates a new DiametricDimension that is a copy of the current instance. /// </summary> /// <returns>A new DiametricDimension that is a copy of this instance.</returns> public override object Clone() { DiametricDimension entity = new DiametricDimension { //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, //DiametricDimension properties CenterPoint = this.center, ReferencePoint = this.refPoint, Offset = this.offset }; foreach (XData data in this.xData.Values) { entity.XData.Add((XData)data.Clone()); } return(entity); }
/// <summary> /// Creates a new DiametricDimension that is a copy of the current instance. /// </summary> /// <returns>A new DiametricDimension that is a copy of this instance.</returns> public override object Clone() { DiametricDimension entity = new DiametricDimension { //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, //DiametricDimension properties CenterPoint = this.center, ReferencePoint = this.refPoint, 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 DiametricDimension that is a copy of the current instance. /// </summary> /// <returns>A new DiametricDimension that is a copy of this instance.</returns> public override object Clone() { DiametricDimension entity = new DiametricDimension { //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, //DiametricDimension properties CenterPoint = this.center, ReferencePoint = this.refPoint }; 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); }
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)); }
private void WriteDiametricDimension(DiametricDimension dim) { this.chunk.Write(100, SubclassMarker.DiametricDimension); this.chunk.Write(15, dim.ReferencePoint.X); this.chunk.Write(25, dim.ReferencePoint.Y); this.chunk.Write(35, dim.ReferencePoint.Z); this.chunk.Write(40, 0.0); this.WriteXData(dim.XData); }
public static Block Build(DiametricDimension 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 * 0.5 - minOffset) && offset < measure * 0.5) { offset = measure * 0.5 - minOffset; side = 1; } else if (offset >= measure * 0.5 && offset < (measure * 0.5 + minOffset)) { offset = measure * 0.5 + 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 * 0.5, style); // dimension arrows //EntityObject arrow1 = StartArrowHead(ref1, angleRef, style); EntityObject arrow2 = EndArrowHead(ref1, (1 - side) * MathHelper.HalfPI + angleRef, style); // dimension text string text = Symbols.Diameter + 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(endRef); block.Entities.Add(dimLine); block.Entities.AddRange(centerCross); block.Entities.Add(arrow2); block.Entities.Add(mText); return(block); }
public static Block Build(DiametricDimension dim, string name) { double offset = dim.Offset; double measure = dim.Measurement; double radius = measure*0.5; DimensionStyle style = BuildDimensionStyleOverride(dim); List<EntityObject> entities = new List<EntityObject>(); Vector2 centerRef = dim.CenterPoint; Vector2 ref1 = dim.ReferencePoint; double angleRef = Vector2.Angle(centerRef, ref1); Vector2 ref2 = Vector2.Polar(ref1, -measure, angleRef); short side; double minOffset = 2*style.ArrowSize + style.TextOffset*style.DimScaleOverall; 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; short reverse = 1; if (textRot > MathHelper.HalfPI && textRot <= MathHelper.ThreeHalfPI) { textRot += MathHelper.PI; reverse = -1; } MText mText = DimensionText(Vector2.Polar(dimRef, -reverse*side*style.TextOffset*style.DimScaleOverall, 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, dim.Elevation), dim.Normal, CoordinateSystem.Object, CoordinateSystem.World); dim.MidTextPoint = new Vector3(dimRef.X, dimRef.Y, dim.Elevation); // this value is in OCS return new Block(name, false, entities, null); }
private DiametricDimension ReadDiametricDimension(Vector3 defPoint, Vector3 midtxtPoint, Vector3 normal) { Vector3 circunferenceRef = Vector3.Zero; List<XData> xData = new List<XData>(); while (this.chunk.Code != 0) { switch (this.chunk.Code) { case 15: circunferenceRef.X = this.chunk.ReadDouble(); this.chunk.Next(); break; case 25: circunferenceRef.Y = this.chunk.ReadDouble(); this.chunk.Next(); break; case 35: circunferenceRef.Z = this.chunk.ReadDouble(); this.chunk.Next(); break; case 40: 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 List<Vector3> { circunferenceRef, defPoint }, normal, CoordinateSystem.World, CoordinateSystem.Object); Vector3 center = Vector3.MidPoint(ocsPoints[0], ocsPoints[1]); double offset = Vector3.Distance(center, midtxtPoint); DiametricDimension entity = new DiametricDimension { CenterPoint = new Vector2(center.X, center.Y), ReferencePoint = new Vector2(ocsPoints[0].X, ocsPoints[0].Y), Elevation = ocsPoints[1].Z, Normal = normal, Offset = offset }; entity.XData.AddRange(xData); return entity; }
/// <summary> /// Creates a new DiametricDimension that is a copy of the current instance. /// </summary> /// <returns>A new DiametricDimension that is a copy of this instance.</returns> public override object Clone() { DiametricDimension entity = new DiametricDimension { //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, //DiametricDimension properties CenterPoint = this.center, ReferencePoint = this.refPoint, Offset = this.offset, Elevation = this.Elevation }; foreach (XData data in this.XData.Values) entity.XData.Add((XData) data.Clone()); return entity; }
private void WriteDiametricDimension(DiametricDimension dim) { this.chunk.Write(100, SubclassMarker.DiametricDimension); Vector3 wcsPoint = MathHelper.Transform(new Vector3(dim.ReferencePoint.X, dim.ReferencePoint.Y, dim.Elevation), dim.Normal, CoordinateSystem.Object, CoordinateSystem.World); this.chunk.Write(15, wcsPoint.X); this.chunk.Write(25, wcsPoint.Y); this.chunk.Write(35, wcsPoint.Z); this.chunk.Write(40, 0.0); this.WriteXData(dim.XData); }
/// <summary> /// Creates a new DiametricDimension that is a copy of the current instance. /// </summary> /// <returns>A new DiametricDimension that is a copy of this instance.</returns> public override object Clone() { DiametricDimension entity = new DiametricDimension { //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, //DiametricDimension properties CenterPoint = this.center, ReferencePoint = this.refPoint, Offset = this.offset }; foreach (XData data in this.xData.Values) entity.XData.Add((XData)data.Clone()); return entity; }
public static Block Build(DiametricDimension 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.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*0.5 - minOffset) && offset < measure*0.5) { offset = measure * 0.5 - minOffset; side = 1; } else if (offset >= measure*0.5 && offset < (measure*0.5 + minOffset)) { offset = measure * 0.5 + minOffset; 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, measure * 0.5, 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, MathHelper.CoordinateSystem.Object, MathHelper.CoordinateSystem.World); dim.MidTextPoint = new Vector3(dimRef.X, dimRef.Y, elev); // this value is in OCS return new Block(name, false, entities, null); }
private static void DiametricDimension() { DxfDocument dxf = new DxfDocument(); DimensionStyle myStyle = CreateDimStyle(); Vector3 center = new Vector3(1, 2, 0); double radius = 3; Circle circle = new Circle(center, radius); //circle.Normal = new Vector3(1, 1, 1); double angle = MathHelper.HalfPI*0.5; Vector3 refPoint = center + new Vector3(radius * Math.Cos(angle), radius * Math.Cos(angle), 0); //DiametricDimension dim = new DiametricDimension(center, refPoint, -1.0, myStyle); double offset = 0; DiametricDimension dim1 = new DiametricDimension(circle, 0, offset, myStyle); DiametricDimension dim2 = new DiametricDimension(circle, 45, offset, myStyle); DiametricDimension dim3 = new DiametricDimension(circle, 90, offset, myStyle); DiametricDimension dim4 = new DiametricDimension(circle, 120, offset, myStyle); DiametricDimension dim5 = new DiametricDimension(circle, 180, offset, myStyle); DiametricDimension dim6 = new DiametricDimension(circle, 220, offset, myStyle); DiametricDimension dim7 = new DiametricDimension(circle, 270, offset, myStyle); DiametricDimension dim8 = new DiametricDimension(circle, 330, offset, myStyle); // if the dimension normal is not equal to the circle normal strange things might happen at the moment //dim1.Normal = circle.Normal; dxf.AddEntity(circle); dxf.AddEntity(dim1); dxf.AddEntity(dim2); dxf.AddEntity(dim3); dxf.AddEntity(dim4); dxf.AddEntity(dim5); dxf.AddEntity(dim6); dxf.AddEntity(dim7); dxf.AddEntity(dim8); 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 DiametricDimension ReadDiametricDimension(Vector3 defPoint) { Vector3 circunferenceRef = Vector3.Zero; List<XData> xData = new List<XData>(); while (this.chunk.Code != 0) { switch (this.chunk.Code) { case 15: circunferenceRef.X = this.chunk.ReadDouble(); this.chunk.Next(); break; case 25: circunferenceRef.Y = this.chunk.ReadDouble(); this.chunk.Next(); break; case 35: circunferenceRef.Z = this.chunk.ReadDouble(); this.chunk.Next(); break; case 40: 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; } } DiametricDimension entity = new DiametricDimension { CenterPoint = Vector3.MidPoint(defPoint, circunferenceRef), ReferencePoint = circunferenceRef }; entity.XData.AddRange(xData); return entity; }