/// <summary> /// Creates a new AlignedDimension that is a copy of the current instance. /// </summary> /// <returns>A new AlignedDimension that is a copy of this instance.</returns> public override object Clone() { AlignedDimension entity = new AlignedDimension { //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, //AlignedDimension properties FirstReferencePoint = this.firstRefPoint, SecondReferencePoint = this.secondRefPoint, 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 AlignedDimension that is a copy of the current instance. /// </summary> /// <returns>A new AlignedDimension that is a copy of this instance.</returns> public override object Clone() { AlignedDimension entity = new AlignedDimension { //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, //AlignedDimension properties FirstReferencePoint = this.firstRefPoint, SecondReferencePoint = this.secondRefPoint, Offset = this.offset }; foreach (XData data in this.XData.Values) { entity.XData.Add((XData)data.Clone()); } return(entity); }
/// <summary> /// Creates a new AlignedDimension that is a copy of the current instance. /// </summary> /// <returns>A new AlignedDimension that is a copy of this instance.</returns> public override object Clone() { AlignedDimension entity = new AlignedDimension { //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, //AlignedDimension properties FirstReferencePoint = this.firstRefPoint, SecondReferencePoint = this.secondRefPoint, 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); }
public static Block Build(AlignedDimension dim, string name) { Vector2 ref1; Vector2 ref2; Vector2 dimRef1; Vector2 dimRef2; bool reversed = false; double measure = dim.Measurement; DimensionStyle style = dim.Style; List <EntityObject> entities = new List <EntityObject>(); // we will build the dimension block in object coordinates with normal the dimension normal Vector3 refPoint = MathHelper.Transform(dim.FirstReferencePoint, dim.Normal, CoordinateSystem.World, CoordinateSystem.Object); ref1 = new Vector2(refPoint.X, refPoint.Y); double elevation = refPoint.Z; refPoint = MathHelper.Transform(dim.SecondReferencePoint, dim.Normal, CoordinateSystem.World, CoordinateSystem.Object); ref2 = new Vector2(refPoint.X, refPoint.Y); double refAngle = Vector2.Angle(ref1, ref2); if (refAngle > MathHelper.HalfPI && refAngle <= MathHelper.ThreeHalfPI) { Vector2 tmp = ref1; ref1 = ref2; ref2 = tmp; refAngle += MathHelper.PI; reversed = true; } dimRef1 = Vector2.Polar(ref1, dim.Offset, refAngle + MathHelper.HalfPI); dimRef2 = Vector2.Polar(ref2, dim.Offset, refAngle + MathHelper.HalfPI); Vector2 midDim = Vector2.MidPoint(dimRef1, dimRef2); // reference points Layer defPointLayer = new Layer("Defpoints") { Plot = false }; entities.Add(new Point(ref1) { Layer = defPointLayer }); entities.Add(new Point(ref2) { Layer = defPointLayer }); entities.Add(reversed ? new Point(dimRef1) { Layer = defPointLayer } : new Point(dimRef2) { Layer = defPointLayer }); // dimension lines entities.Add(DimensionLine(dimRef1, dimRef2, refAngle, style)); // extension lines double dimexo = Math.Sign(dim.Offset) * style.DIMEXO * style.DIMSCALE; double dimexe = Math.Sign(dim.Offset) * style.DIMEXE * style.DIMSCALE; if (!style.DIMSE1) { entities.Add(ExtensionLine(Vector2.Polar(ref1, dimexo, refAngle + MathHelper.HalfPI), Vector2.Polar(dimRef1, dimexe, refAngle + MathHelper.HalfPI), style, style.DIMLTEX1)); } if (!style.DIMSE2) { entities.Add(ExtensionLine(Vector2.Polar(ref2, dimexo, refAngle + MathHelper.HalfPI), Vector2.Polar(dimRef2, dimexe, refAngle + MathHelper.HalfPI), style, style.DIMLTEX2)); } // dimension arrowheads if (reversed) { entities.Add(StartArrowHead(dimRef2, refAngle, style)); entities.Add(EndArrowHead(dimRef1, refAngle + MathHelper.PI, style)); } else { entities.Add(StartArrowHead(dimRef1, refAngle + MathHelper.PI, style)); entities.Add(EndArrowHead(dimRef2, refAngle, style)); } // dimension text string text = FormatDimensionText(measure, false, dim.UserText, style, dim.Owner.Record.Layout); MText mText = DimensionText(Vector2.Polar(midDim, style.DIMGAP * style.DIMSCALE, refAngle + MathHelper.HalfPI), refAngle, text, style); if (mText != null) { entities.Add(mText); } Vector3 defPoint = reversed ? new Vector3(dimRef1.X, dimRef1.Y, elevation) : new Vector3(dimRef2.X, dimRef2.Y, elevation); dim.DefinitionPoint = MathHelper.Transform(defPoint, dim.Normal, CoordinateSystem.Object, CoordinateSystem.World); dim.MidTextPoint = new Vector3(midDim.X, midDim.Y, elevation); // this value is in OCS // drawing block return(new Block(name, false, entities, null) { Flags = BlockTypeFlags.AnonymousBlock }); }
private void WriteAlignedDimension(AlignedDimension dim) { this.chunk.Write(100, SubclassMarker.AlignedDimension); this.chunk.Write(13, dim.FirstReferencePoint.X); this.chunk.Write(23, dim.FirstReferencePoint.Y); this.chunk.Write(33, dim.FirstReferencePoint.Z); this.chunk.Write(14, dim.SecondReferencePoint.X); this.chunk.Write(24, dim.SecondReferencePoint.Y); this.chunk.Write(34, dim.SecondReferencePoint.Z); this.WriteXData(dim.XData); }
/// <summary> /// Creates a new AlignedDimension that is a copy of the current instance. /// </summary> /// <returns>A new AlignedDimension that is a copy of this instance.</returns> public override object Clone() { AlignedDimension entity = new AlignedDimension { //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, //AlignedDimension properties FirstReferencePoint = this.firstRefPoint, SecondReferencePoint = this.secondRefPoint, Offset = this.offset }; foreach (XData data in this.XData.Values) entity.XData.Add((XData) data.Clone()); return entity; }
public static Block Build(AlignedDimension dim, string name) { Vector2 ref1; Vector2 ref2; Vector2 dimRef1; Vector2 dimRef2; short reversed; double measure = dim.Value; DimensionStyle style = dim.Style; // we will build the dimension block in object coordinates with normal the dimension normal Vector3 refPoint; refPoint = MathHelper.Transform(dim.FirstReferencePoint, dim.Normal, MathHelper.CoordinateSystem.World, MathHelper.CoordinateSystem.Object); ref1 = new Vector2(refPoint.X, refPoint.Y); double elevation = refPoint.Z; refPoint = MathHelper.Transform(dim.SecondReferencePoint, dim.Normal, MathHelper.CoordinateSystem.World, MathHelper.CoordinateSystem.Object); ref2 = new Vector2(refPoint.X, refPoint.Y); double refAngle = Vector2.Angle(ref1, ref2); reversed = ReverseEnds(ref1, ref2, 0.0, refAngle); dimRef1 = Vector2.Polar(ref1, dim.Offset, refAngle + MathHelper.HalfPI); dimRef2 = Vector2.Polar(ref2, dim.Offset, refAngle + MathHelper.HalfPI); Vector2 midDim = Vector2.MidPoint(dimRef1, dimRef2); // reference points Layer defPointLayer = new Layer("Defpoints") { Plot = false }; Point ref1Point = new Point(ref1) { Layer = defPointLayer }; Point ref2Point = new Point(ref2) { Layer = defPointLayer }; Point defPoint = new Point(dimRef2) { Layer = defPointLayer }; // dimension lines Line dimLine = DimensionLine(dimRef1, dimRef2, refAngle, 1, style); // extension lines double dimexo = Math.Sign(dim.Offset) * style.DIMEXO * style.DIMSCALE; double dimexe = Math.Sign(dim.Offset) * style.DIMEXE * style.DIMSCALE; double extRot = refAngle + MathHelper.HalfPI; Line ext1Line = null; if (!style.DIMSE1) { ext1Line = ExtensionLine(Vector2.Polar(ref1, dimexo, extRot), Vector2.Polar(dimRef1, dimexe, extRot), style, style.DIMLTEX1); } Line ext2Line = null; if (!style.DIMSE2) { ext2Line = ExtensionLine(Vector2.Polar(ref2, dimexo, extRot), Vector2.Polar(dimRef2, dimexe, extRot), style, style.DIMLTEX2); } // dimension arrows EntityObject arrow1 = StartArrowHead(dimRef1, Vector2.Angle(dimRef2, dimRef1), style); EntityObject arrow2 = EndArrowHead(dimRef2, Vector2.Angle(dimRef1, dimRef2), style); // dimension text string text = FormatDimensionText(measure, false, style); double textRot = (refAngle + (1 - reversed) * MathHelper.HalfPI); MText mText = DimensionText(Vector2.Polar(midDim, reversed * style.DIMGAP * style.DIMSCALE, extRot), textRot, text, style); dim.DefinitionPoint = MathHelper.Transform(new Vector3(dimRef2.X, dimRef2.Y, elevation), dim.Normal, MathHelper.CoordinateSystem.Object, MathHelper.CoordinateSystem.World); dim.MidTextPoint = new Vector3(midDim.X, midDim.Y, elevation); // this value is in OCS // drawing block Block block = new Block(name, false) { Flags = BlockTypeFlags.AnonymousBlock }; block.Entities.Add(ref1Point); block.Entities.Add(ref2Point); block.Entities.Add(defPoint); block.Entities.Add(ext1Line); block.Entities.Add(ext2Line); block.Entities.Add(dimLine); block.Entities.Add(arrow1); block.Entities.Add(arrow2); block.Entities.Add(mText); return(block); }
public static Block Build(AlignedDimension dim, string name) { bool reversed = false; double measure = dim.Measurement; DimensionStyle style = BuildDimensionStyleOverride(dim); List<EntityObject> entities = new List<EntityObject>(); Vector2 ref1 = dim.FirstReferencePoint; Vector2 ref2 = dim.SecondReferencePoint; double refAngle = Vector2.Angle(ref1, ref2); if (refAngle > MathHelper.HalfPI && refAngle <= MathHelper.ThreeHalfPI) { Vector2 tmp = ref1; ref1 = ref2; ref2 = tmp; refAngle += MathHelper.PI; reversed = true; } Vector2 dimRef1 = Vector2.Polar(ref1, dim.Offset, refAngle + MathHelper.HalfPI); Vector2 dimRef2 = Vector2.Polar(ref2, dim.Offset, refAngle + MathHelper.HalfPI); Vector2 midDim = Vector2.MidPoint(dimRef1, dimRef2); // reference points Layer defPointLayer = new Layer("Defpoints") {Plot = false}; entities.Add(new Point(ref1) {Layer = defPointLayer}); entities.Add(new Point(ref2) {Layer = defPointLayer}); entities.Add(reversed ? new Point(dimRef1) {Layer = defPointLayer} : new Point(dimRef2) {Layer = defPointLayer}); // dimension lines entities.Add(DimensionLine(dimRef1, dimRef2, refAngle, style)); // extension lines double dimexo = style.ExtLineOffset*style.DimScaleOverall; double dimexe = style.ExtLineExtend*style.DimScaleOverall; if (dim.Offset < 0) { dimexo *= -1; dimexe *= -1; } if (!style.ExtLine1) entities.Add(ExtensionLine(Vector2.Polar(ref1, dimexo, refAngle + MathHelper.HalfPI), Vector2.Polar(dimRef1, dimexe, refAngle + MathHelper.HalfPI), style, style.ExtLine1Linetype)); if (!style.ExtLine2) entities.Add(ExtensionLine(Vector2.Polar(ref2, dimexo, refAngle + MathHelper.HalfPI), Vector2.Polar(dimRef2, dimexe, refAngle + MathHelper.HalfPI), style, style.ExtLine2Linetype)); // dimension arrowheads if (reversed) { entities.Add(StartArrowHead(dimRef2, refAngle, style)); entities.Add(EndArrowHead(dimRef1, refAngle + MathHelper.PI, style)); } else { entities.Add(StartArrowHead(dimRef1, refAngle + MathHelper.PI, style)); entities.Add(EndArrowHead(dimRef2, refAngle, style)); } // dimension text string text = FormatDimensionText(measure, false, dim.UserText, style, dim.Owner.Record.Layout); MText mText = DimensionText(Vector2.Polar(midDim, style.TextOffset*style.DimScaleOverall, refAngle + MathHelper.HalfPI), refAngle, text, style); if (mText != null) entities.Add(mText); Vector3 defPoint = reversed ? new Vector3(dimRef1.X, dimRef1.Y, dim.Elevation) : new Vector3(dimRef2.X, dimRef2.Y, dim.Elevation); dim.DefinitionPoint = MathHelper.Transform(defPoint, 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) {Flags = BlockTypeFlags.AnonymousBlock}; }
private static void AlignedDimension() { DxfDocument dxf = new DxfDocument(DxfVersion.AutoCad2010); DimensionStyle myStyle = CreateDimStyle(); Vector3 p1 = new Vector3(0, -5, 0); Vector3 p2 = new Vector3(-5, 0, 0); Line line1 = new Line(p1, p2) { Layer = new Layer("Reference line") { Color = AciColor.Green } }; dxf.AddEntity(line1); double offset = 4; AlignedDimension dim1 = new AlignedDimension(line1, offset, myStyle); AlignedDimension dim11 = new AlignedDimension(line1, -offset, myStyle); Vector3 p3 = new Vector3(6, -5, 0); Vector3 p4 = new Vector3(11, 0, 0); Line line2 = new Line(p3, p4) { Layer = new Layer("Reference line") { Color = AciColor.Green } }; dxf.AddEntity(line2); AlignedDimension dim2 = new AlignedDimension(line2, offset, myStyle); AlignedDimension dim21 = new AlignedDimension(line2, -offset, myStyle); dxf.AddEntity(dim1); dxf.AddEntity(dim11); dxf.AddEntity(dim2); dxf.AddEntity(dim21); dxf.Save("dimension drawing.dxf"); //Console.WriteLine("Press a key..."); //Console.ReadKey(); //DxfDocument dwg = DxfDocument.Load("dimension drawing.dxf"); //dwg.Save("dimension drawing saved.dxf"); }
private void WriteAlignedDimension(AlignedDimension dim) { this.chunk.Write(100, SubclassMarker.AlignedDimension); IList<Vector3> wcsPoints = MathHelper.Transform( new[] { new Vector3(dim.FirstReferencePoint.X, dim.FirstReferencePoint.Y, dim.Elevation), new Vector3(dim.SecondReferencePoint.X, dim.SecondReferencePoint.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.WriteXData(dim.XData); }
public static Block Build(AlignedDimension dim, string name) { Vector2 ref1; Vector2 ref2; Vector2 dimRef1; Vector2 dimRef2; short reversed; double measure = dim.Measurement; DimensionStyle style = dim.Style; List<EntityObject> entities = new List<EntityObject>(); // we will build the dimension block in object coordinates with normal the dimension normal Vector3 refPoint; refPoint = MathHelper.Transform(dim.FirstReferencePoint, dim.Normal, MathHelper.CoordinateSystem.World, MathHelper.CoordinateSystem.Object); ref1 = new Vector2(refPoint.X, refPoint.Y); double elevation = refPoint.Z; refPoint = MathHelper.Transform(dim.SecondReferencePoint, dim.Normal, MathHelper.CoordinateSystem.World, MathHelper.CoordinateSystem.Object); ref2 = new Vector2(refPoint.X, refPoint.Y); double refAngle = Vector2.Angle(ref1, ref2); reversed = ReverseEnds(ref1, ref2, 0.0, refAngle); dimRef1 = Vector2.Polar(ref1, dim.Offset, refAngle + MathHelper.HalfPI); dimRef2 = Vector2.Polar(ref2, dim.Offset, refAngle + MathHelper.HalfPI); Vector2 midDim = Vector2.MidPoint(dimRef1, dimRef2); // reference points Layer defPointLayer = new Layer("Defpoints") {Plot = false}; entities.Add(new Point(ref1) {Layer = defPointLayer}); entities.Add(new Point(ref2) {Layer = defPointLayer}); entities.Add(new Point(dimRef2) {Layer = defPointLayer}); // dimension lines entities.Add(DimensionLine(dimRef1, dimRef2, refAngle, 1, style)); // extension lines double dimexo = Math.Sign(dim.Offset)*style.DIMEXO*style.DIMSCALE; double dimexe = Math.Sign(dim.Offset)*style.DIMEXE*style.DIMSCALE; double extRot = refAngle + MathHelper.HalfPI; if (!style.DIMSE1) entities.Add(ExtensionLine(Vector2.Polar(ref1, dimexo, extRot), Vector2.Polar(dimRef1, dimexe, extRot), style, style.DIMLTEX1)); if (!style.DIMSE2) entities.Add(ExtensionLine(Vector2.Polar(ref2, dimexo, extRot), Vector2.Polar(dimRef2, dimexe, extRot), style, style.DIMLTEX2)); // dimension arrows entities.Add(StartArrowHead(dimRef1, Vector2.Angle(dimRef2, dimRef1), style)); entities.Add(EndArrowHead(dimRef2, Vector2.Angle(dimRef1, dimRef2), style)); // dimension text string text = FormatDimensionText(measure, false, dim.UserText, style, dim.Owner.Record.Layout); double textRot = (refAngle + (1 - reversed)*MathHelper.HalfPI); MText mText = DimensionText(Vector2.Polar(midDim, reversed * style.DIMGAP * style.DIMSCALE, extRot), textRot, text, style); if (mText != null) entities.Add(mText); dim.DefinitionPoint = MathHelper.Transform(new Vector3(dimRef2.X, dimRef2.Y, elevation), dim.Normal, MathHelper.CoordinateSystem.Object, MathHelper.CoordinateSystem.World); dim.MidTextPoint = new Vector3(midDim.X, midDim.Y, elevation); // this value is in OCS // drawing block return new Block(name, false, entities, null) {Flags = BlockTypeFlags.AnonymousBlock}; }
private static void AlignedDimensionDrawing() { DxfDocument dxf = new DxfDocument(); double offset = -0.9; Vector3 p1 = new Vector3(1, 2, 0); Vector3 p2 = new Vector3(2, 6, 0); Line line1 = new Line(p1, p2); Vector3 l1; Vector3 l2; MathHelper.OffsetLine(line1.StartPoint, line1.EndPoint, line1.Normal, offset, out l1, out l2); DimensionStyle myStyle = new DimensionStyle("MyStyle"); myStyle.DIMPOST = "<>mm"; AlignedDimension dim1 = new AlignedDimension(p1, p2, offset, myStyle); Vector3 p3 = p1 + new Vector3(4, 0, 0); Vector3 p4 = p2 + new Vector3(4, 0, 0); Line line2 = new Line(p3, p4); AlignedDimension dim2 = new AlignedDimension(p3, p4, -offset, myStyle); Vector2 perp = Vector2.Perpendicular(new Vector2(p2.X, p2.Y) - new Vector2(p1.X, p1.Y)); //dim.Normal = -new Vector3(perp.X, perp.Y, 0.0) ; XData xdata = new XData(new ApplicationRegistry("other application")); xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf")); xdata.XDataRecord.Add(XDataRecord.OpenControlString); xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "Aligned Dimension")); xdata.XDataRecord.Add(new XDataRecord(XDataCode.Real, 15.5)); xdata.XDataRecord.Add(new XDataRecord(XDataCode.Int32, 350)); xdata.XDataRecord.Add(XDataRecord.CloseControlString); dim1.XData.Add(xdata); //dxf.AddEntity(line1); //dxf.AddEntity(line2); //dxf.AddEntity(dim1); //dxf.AddEntity(dim2); Block block = new Block("DimensionBlock"); block.Entities.Add(line1); block.Entities.Add(line2); block.Entities.Add(dim1); block.Entities.Add(dim2); Insert insert = new Insert(block); dxf.AddEntity(insert); dxf.Save("aligned dimension.dxf"); dxf = DxfDocument.Load("aligned dimension.dxf"); }
private static void AddAndRemove() { Layer layer1 = new Layer("layer1") { Color = AciColor.Blue }; Layer layer2 = new Layer("layer2") { Color = AciColor.Green }; Line line = new Line(new Vector2(0, 0), new Vector2(10, 10)); line.Layer = layer1; Circle circle = new Circle(new Vector2(0, 0), 10); circle.Layer = layer2; double offset = -0.9; Vector3 p1 = new Vector3(1, 2, 0); Vector3 p2 = new Vector3(2, 6, 0); Line line1 = new Line(p1, p2); Vector3 l1; Vector3 l2; MathHelper.OffsetLine(line1.StartPoint, line1.EndPoint, line1.Normal, offset, out l1, out l2); DimensionStyle myStyle = new DimensionStyle("MyDimStyle"); myStyle.DIMPOST = "<>mm"; AlignedDimension dim1 = new AlignedDimension(p1, p2, offset, myStyle); //text TextStyle style = new TextStyle("MyTextStyle", "Arial.ttf"); Text text = new Text("Hello world!", Vector3.Zero, 10.0f, style) { Layer = new Layer("text") { Color = {Index = 8} } }; text.Alignment = TextAlignment.TopRight; HeaderVariables variables = new HeaderVariables { AcadVer = DxfVersion.AutoCad2004 }; DxfDocument dxf = new DxfDocument(); dxf.AddEntity(new EntityObject[] {line, circle, dim1, text}); dxf.Save("before remove.dxf"); dxf.RemoveEntity(circle); dxf.Save("after remove.dxf"); dxf.AddEntity(circle); dxf.Save("after remove and add.dxf"); dxf.RemoveEntity(dim1); dxf.Save("remove dim.dxf"); dxf.AddEntity(dim1); dxf.Save("add dim.dxf"); DxfDocument dxf2 = DxfDocument.Load("dim block names.dxf"); dxf2.AddEntity(dim1); dxf2.Save("dim block names2.dxf"); }
//private static void ExplodeInsert() //{ // DxfDocument dxf = DxfDocument.Load("explode\\ExplodeInsertUniformScale.dxf"); // List<DxfObject> refs = dxf.Blocks.References["ExplodeBlock"]; // Insert insert = (Insert)refs[0]; // dxf.RemoveEntity(insert); // insert.Layer = new Layer("Original block"); // insert.Layer.Color = AciColor.DarkGrey; // dxf.AddEntity(insert); // List<Entity> explodedEntities = insert.Explode(); // dxf.AddEntity(explodedEntities); // dxf.Save("ExplodeInsert.dxf"); //} private static void LinearDimensionTests() { DxfDocument dxf1 = new DxfDocument(); Vector2 pt1 = new Vector2(15, -5); Vector2 pt2 = new Vector2(5, 5); double offset = 10; LinearDimension ld1z = new LinearDimension(pt1, pt2, offset, 30); LinearDimension ld2z = new LinearDimension(pt1, pt2, offset, 45); LinearDimension ld3z = new LinearDimension(pt1, pt2, offset, 90); LinearDimension ld4z = new LinearDimension(pt1, pt2, offset, 135); LinearDimension ld5z = new LinearDimension(pt1, pt2, offset, 180); LinearDimension ld6z = new LinearDimension(pt1, pt2, offset, 220); LinearDimension ld7z = new LinearDimension(pt2, pt1, offset, 270); dxf1.AddEntity(ld1z); dxf1.AddEntity(ld2z); dxf1.AddEntity(ld3z); dxf1.AddEntity(ld4z); dxf1.AddEntity(ld5z); dxf1.AddEntity(ld6z); dxf1.AddEntity(ld7z); Line line = new Line(pt1, pt2); line.Color = AciColor.Yellow; dxf1.AddEntity(line); dxf1.Save("test2.dxf"); DxfDocument dxf2 = new DxfDocument(); LinearDimension ld1 = new LinearDimension(new Vector2(0, 0), new Vector2(0, 15), 1, 90); LinearDimension ld1b = new LinearDimension(new Vector2(0, 0), new Vector2(0, 15), 1, 100); LinearDimension ld1c = new LinearDimension(new Vector2(0, 0), new Vector2(0, 15), 1, 80); LinearDimension ld2 = new LinearDimension(new Vector2(5, 15), new Vector2(5, 0), 1, 90); LinearDimension ld3 = new LinearDimension(new Vector2(10, 0), new Vector2(10, 15), -1, 270); LinearDimension ld4 = new LinearDimension(new Vector2(15, 0), new Vector2(15, 15), 1, 270); LinearDimension ld4b = new LinearDimension(new Vector2(15, 0), new Vector2(15, 15), 1, 300); LinearDimension ld4c = new LinearDimension(new Vector2(15, 0), new Vector2(15, 15), 1, 240); LinearDimension ld5 = new LinearDimension(new Vector2(15, 0), new Vector2(0, 0), 1, 0); LinearDimension ld6 = new LinearDimension(new Vector2(0, 0), new Vector2(15, 0), -1, 0); AlignedDimension ld1a = new AlignedDimension(new Vector2(0, 0), new Vector2(0, 15), 1); ld1a.Color = AciColor.Yellow; AlignedDimension ld2a = new AlignedDimension(new Vector2(5, 15), new Vector2(5, 0), 1); ld2a.Color = AciColor.Yellow; AlignedDimension ld3a = new AlignedDimension(new Vector2(10, 0), new Vector2(10, 15), -1); ld3a.Color = AciColor.Yellow; AlignedDimension ld4a = new AlignedDimension(new Vector2(15, 0), new Vector2(15, 15), 1); ld4a.Color = AciColor.Yellow; AlignedDimension ld5a = new AlignedDimension(new Vector2(15, 0), new Vector2(0, 0), 1); ld5a.Color = AciColor.Yellow; AlignedDimension ld6a = new AlignedDimension(new Vector2(0, 0), new Vector2(15, 0), -1); ld6a.Color = AciColor.Yellow; dxf2.AddEntity(ld1); dxf2.AddEntity(ld1b); dxf2.AddEntity(ld1c); dxf2.AddEntity(ld2); dxf2.AddEntity(ld3); dxf2.AddEntity(ld4); dxf2.AddEntity(ld4b); dxf2.AddEntity(ld4c); dxf2.AddEntity(ld5); dxf2.AddEntity(ld6); dxf2.AddEntity(ld1a); dxf2.AddEntity(ld2a); dxf2.AddEntity(ld3a); dxf2.AddEntity(ld4a); dxf2.AddEntity(ld5a); dxf2.AddEntity(ld6a); dxf2.Save("test1.dxf"); }
/// <summary> /// Creates a new AlignedDimension that is a copy of the current instance. /// </summary> /// <returns>A new AlignedDimension that is a copy of this instance.</returns> public override object Clone() { AlignedDimension entity = new AlignedDimension { //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, //AlignedDimension properties FirstReferencePoint = this.firstRefPoint, SecondReferencePoint = this.secondRefPoint, Offset = this.offset, Elevation = this.Elevation }; foreach (XData data in this.XData.Values) entity.XData.Add((XData) data.Clone()); return entity; }
private AlignedDimension ReadAlignedDimension(Vector3 defPoint, Vector3 normal) { 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 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> { firstRef, secondRef, defPoint }, normal, CoordinateSystem.World, CoordinateSystem.Object); AlignedDimension entity = new AlignedDimension { FirstReferencePoint = new Vector2(ocsPoints[0].X, ocsPoints[0].Y), SecondReferencePoint = new Vector2(ocsPoints[1].X, ocsPoints[1].Y), Elevation = ocsPoints[2].Z, Normal = normal }; entity.SetDimensionLinePosition(new Vector2(ocsPoints[2].X, ocsPoints[2].Y)); entity.XData.AddRange(xData); return entity; }
private AlignedDimension ReadAlignedDimension(Vector3 defPoint) { 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 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; } } double offset = Vector3.Distance(secondRef, defPoint); AlignedDimension entity = new AlignedDimension { FirstReferencePoint = firstRef, SecondReferencePoint = secondRef, Offset = offset }; entity.XData.AddRange(xData); return entity; }