Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Commit

Permalink
[2023/03/05]
Browse files Browse the repository at this point in the history
* Changed the default target framework 'net45' for 'net48'. The library is compatible will all 4.x net framework versions.
* Renamed the constant 'NET45' with 'NET4X' in netDxf.csproj. This constant must be applicable when compiling against any net framework 4.x versions.
* Normalizing a zero vector will return the Zero vector instead of NaN.
* Added the ArcLengthDimension entity.
* Added an Arc constructor that takes a start point, an end point, and a bulge value to build the arc.
* Added the methods MathHelper.ArcFromBulge and MathHelper.ArcToBulge.
* The offset value for the AlignedDimension entity can now be positive or negative. The first and second reference point will not be swapped depending on the placement of the definition point, instead the sign of the offset will be changed.
* The offset value for the LinearDimension entity can now be positive or negative. A negative offset is like adding 180º to the dimension rotation. The first and second reference point will not be swapped depending on the placement of the definition point, instead the sign of the offset will be changed.
* The offset value for the Angular3PointDimension can now be posibive or negative. A negative offset will measure the oposite arc angle. The first and second reference point will not be swapped depending on the placement of the definition point, instead the sign of the offset will be changed.
* Now it is posible to initialize a HatchBoundaryPath directly form a list of HatchBoundaryPath.Edges.
* When converting a Polyline2D containing arc segments the precision value defines the number of divisions for a full circle, therefore, the final number of divisions for the arc will depend on the angle of the arc. This way small arcs will have less divisions than larger ones.
* Removed the method MathHelper.Swap, just use (obj1, obj2) = (obj2, obj1);
* Moved method MathHelper.RotateAboutAxis to Vector3.RotateAroundAxis.
* (fixed) Workaround for possible bad formatted tolerance string representations.
* (fixed) The vectors that define the start and end angle for 3 point angular dimensions can be parallel. This restriction still true for angular 2 line dimensions.
  • Loading branch information
haplokuon committed Mar 5, 2023
1 parent c25b08e commit 6b4f0ae
Show file tree
Hide file tree
Showing 42 changed files with 4,391 additions and 1,375 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# netDxf
netDxf Copyright(C) 2009-2022 Daniel Carvajal, licensed under MIT License
netDxf Copyright(C) 2009-2023 Daniel Carvajal, licensed under MIT License
## Description
netDxf is a .net library programmed in C# to read and write AutoCAD DXF files. It supports AutoCad2000, AutoCad2004, AutoCad2007, AutoCad2010, AutoCad2013, and AutoCad2018 DXF database versions, in both text and binary format.

Expand Down Expand Up @@ -37,17 +37,20 @@ public static void Main()
Are contained in the source code.
Well, at the moment they are just tests for the work in progress.
## Dependencies and distribution
Multitarget project, predefined frameworks for Net Framework 4.5, Net Standard 2.1, Net Core 3.1, NET 5.0, and NET 6.0.
Multitarget project, predefined frameworks for Net Framework 4.8, Net Standard 2.1, Net Core 3.1, NET 5.0, and NET 6.0.
Additionally the Net Standard 2.1 build requires a reference to the external library "System.Text.Encoding.CodePages".
## Compiling
Visual Studio 2022. The solution file is still usable by Visual Studio 2019 but it does not support NET 6.0.
netDxf is compatible with any net version from Net Framework 4.0.
If your desired version is not listed among the predefined frameworks manually edit the netdxf.csproj file and set the TargetFrameworks accordingly.
When compiling for any of the Net Framework 4 family make sure that the constant NET4X is defined for your selected framework.
## Development Status
See [changelog.txt](https://github.com/haplokuon/netDxf/blob/master/doc/Changelog.txt) or the [wiki page](https://github.com/haplokuon/netDxf/wiki) for information on the latest changes.
## Supported DXF entities
* 3dFace
* Arc
* Circle
* Dimensions (aligned, linear, radial, diametric, 3 point angular, 2 line angular, and ordinate)
* Dimensions (aligned, linear, radial, diametric, 3 point angular, 2 line angular, arc length, and ordinate)
* Ellipse
* Hatch (including Gradient patterns)
* Image
Expand Down
196 changes: 119 additions & 77 deletions TestDxfDocument/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using netDxf;
using netDxf.Blocks;
Expand All @@ -29,7 +30,7 @@ namespace TestDxfDocument
/// </summary>
public class Program
{
public static void Main()
public static void Main()
{
DxfDocument doc = Test(@"sample.dxf");

Expand All @@ -48,6 +49,7 @@ public static void Main()

#region Samples for new and modified features 3.0.0

//ArcLengthDimension();
//ReflectionMatrix();
//PolygonMesh();
//UcsTransform();
Expand Down Expand Up @@ -1240,6 +1242,35 @@ public static void NURBSSurface()

#region Samples for new and modified features 3.0.0

public static void ArcLengthDimension()
{
// create an arc length dimension to measure an arc entity
Arc arc = new Arc(new Vector2(0, 0), 4, 30, 120) { Color = AciColor.Blue };
ArcLengthDimension dim1 = new ArcLengthDimension(arc, 1);

// create an arc length dimension to measure a arc segment of a polyline 2D entity
Polyline2DVertex[] vertexes =
{
new Polyline2DVertex(new Vector2(10, 0)),
new Polyline2DVertex(new Vector2(10, 8), 1.0),
new Polyline2DVertex(new Vector2(8, 10)),
new Polyline2DVertex(new Vector2(0, 10))
};

Polyline2D polyline = new Polyline2D(vertexes) { Color = AciColor.Red };
ArcLengthDimension dim2 = new ArcLengthDimension(polyline.Vertexes[1], polyline.Vertexes[2], 1);

DxfDocument doc = new DxfDocument();

doc.Entities.Add(arc);
doc.Entities.Add(dim1);

doc.Entities.Add(polyline);
doc.Entities.Add(dim2);

doc.Save("test.dxf");
}

public static void ReflectionMatrix()
{
Polyline2D polyline = new Polyline2D(new []{
Expand All @@ -1254,7 +1285,7 @@ public static void ReflectionMatrix()

// line of symmetry
Line mirrorLine = new Line(new Vector3(20,5,0), new Vector3(0,15,0)) {Color = AciColor.Yellow};
// mirror plane normal perpendicular to the symmetry lane and the XY plane
// mirror plane normal perpendicular to the symmetry line and the XY plane
Vector3 mirrorNormal = Vector3.CrossProduct(mirrorLine.Direction, Vector3.UnitZ);

// make a copy of the original entity
Expand Down Expand Up @@ -3581,6 +3612,7 @@ private static void ResetLeaderAnnotationPosition()
private static void LinearDimensionTest()
{
DxfDocument doc = new DxfDocument();
doc.BuildDimensionBlocks = true;

Vector3 p1 = new Vector3(-5, 5, 0);
Vector3 p2 = new Vector3(5, -5, 0);
Expand Down Expand Up @@ -3626,6 +3658,8 @@ private static void LinearDimensionTest()
private static void AlignedDimensionTest()
{
DxfDocument doc = new DxfDocument();
doc.BuildDimensionBlocks = true;

double offset = 1;
Line line = new Line(new Vector3(10, 6, 0), new Vector3(1, 3, 0));
AlignedDimension dim = new AlignedDimension(line, -offset);
Expand Down Expand Up @@ -3861,7 +3895,7 @@ private static void OrdinateDimensionTest()
Line lineX = new Line(origin, origin + 5*Vector2.UnitX);
Line lineY = new Line(origin, origin + 5*Vector2.UnitY);

Vector2 point = Vector2.Polar(new Vector2(origin.X, origin.Y), 5, angle*MathHelper.DegToRad);
Vector2 point = Vector2.Polar(new Vector2(origin.X, origin.Y), 5, angle * MathHelper.DegToRad);
Line lineXRotate = new Line(origin, new Vector2(point.X, point.Y));

point = Vector2.Polar(new Vector2(origin.X, origin.Y), 5, angle*MathHelper.DegToRad + MathHelper.HalfPI);
Expand Down Expand Up @@ -4739,6 +4773,7 @@ private static DimensionStyle CreateDimStyle()
private static void LinearDimension()
{
DxfDocument dxf = new DxfDocument(DxfVersion.AutoCad2010);
dxf.BuildDimensionBlocks = true;

DimensionStyle myStyle = CreateDimStyle();

Expand Down Expand Up @@ -4795,6 +4830,7 @@ private static void LinearDimension()
private static void AlignedDimension()
{
DxfDocument dxf = new DxfDocument(DxfVersion.AutoCad2010);
dxf.BuildDimensionBlocks = true;
DimensionStyle myStyle = CreateDimStyle();

Vector3 p1 = new Vector3(0, -5, 0);
Expand Down Expand Up @@ -6021,91 +6057,94 @@ private static void ImageAndClipBoundary()

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.Entities.Add(ld1z);
//dxf1.Entities.Add(ld2z);
//dxf1.Entities.Add(ld3z);
//dxf1.Entities.Add(ld4z);
//dxf1.Entities.Add(ld5z);
//dxf1.Entities.Add(ld6z);
//dxf1.Entities.Add(ld7z);

//Line line = new Line(pt1, pt2);
//line.Color = AciColor.Yellow;
//dxf1.Entities.Add(line);

//dxf1.Save("test2.dxf");
DxfDocument dxf1 = new DxfDocument();
dxf1.BuildDimensionBlocks = true;

Vector2 pt1 = new Vector2(15, -5);
Vector2 pt2 = new Vector2(5, 5);
double offset = 10;

LinearDimension ld1z = new LinearDimension(pt2, pt1, -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.Entities.Add(ld1z);
dxf1.Entities.Add(ld2z);
dxf1.Entities.Add(ld3z);
dxf1.Entities.Add(ld4z);
dxf1.Entities.Add(ld5z);
dxf1.Entities.Add(ld6z);
dxf1.Entities.Add(ld7z);

Line line = new Line(pt1, pt2);
line.Color = AciColor.Yellow;
dxf1.Entities.Add(line);

dxf1.Save("test2.dxf");

DxfDocument dxf2 = new DxfDocument();
dxf2.BuildDimensionBlocks = true;

//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 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 ld2 = new LinearDimension(new Vector2(5, 15), new Vector2(5, 0), 1, 90);
LinearDimension ld3 = new LinearDimension(new Vector2(10, 15), new Vector2(10, 0), 1, 90);
//ld3.SetDimensionLinePosition(new Vector3(9, 1, 0));
//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(15, 0),new Vector2(0, 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.Entities.Add(ld1);
//dxf2.Entities.Add(ld1b);
//dxf2.Entities.Add(ld1c);

//dxf2.Entities.Add(ld2);
ld3.SetDimensionLinePosition(new Vector2(9, 1));
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(15, 0), new Vector2(0, 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.Entities.Add(ld1);
dxf2.Entities.Add(ld1b);
dxf2.Entities.Add(ld1c);

dxf2.Entities.Add(ld2);
dxf2.Entities.Add(ld3);

//dxf2.Entities.Add(ld4);
//dxf2.Entities.Add(ld4b);
//dxf2.Entities.Add(ld4c);
dxf2.Entities.Add(ld4);
dxf2.Entities.Add(ld4b);
dxf2.Entities.Add(ld4c);

//dxf2.Entities.Add(ld5);
//dxf2.Entities.Add(ld6);
dxf2.Entities.Add(ld5);
dxf2.Entities.Add(ld6);

//dxf2.Entities.Add(ld1a);
//dxf2.Entities.Add(ld2a);
//dxf2.Entities.Add(ld3a);
//dxf2.Entities.Add(ld4a);
//dxf2.Entities.Add(ld5a);
//dxf2.Entities.Add(ld6a);
dxf2.Entities.Add(ld1a);
dxf2.Entities.Add(ld2a);
dxf2.Entities.Add(ld3a);
dxf2.Entities.Add(ld4a);
dxf2.Entities.Add(ld5a);
dxf2.Entities.Add(ld6a);

dxf2.Save("test1.dxf");

DxfDocument load = DxfDocument.Load("test1.dxf");
load.Entities.Dimensions.ElementAt(0).Update();
//load.Dimensions[1].Update();
load.Entities.Add((EntityObject) ld3.Clone());
//load.Entities.Add((EntityObject)ld6.Clone());
load.Save("test2.dxf");
//DxfDocument load = DxfDocument.Load("test1.dxf");
//load.Entities.Dimensions.ElementAt(0).Update();
////load.Dimensions[1].Update();
//load.Entities.Add((EntityObject) ld3.Clone());
////load.Entities.Add((EntityObject)ld6.Clone());
//load.Save("test2.dxf");
}

private static void TestingTrueTypeFonts()
Expand Down Expand Up @@ -7473,10 +7512,11 @@ private static void RadialDimensionDrawing()
private static void LinearDimensionDrawing()
{
DxfDocument dxf = new DxfDocument();
dxf.BuildDimensionBlocks = true;

Vector3 p1 = new Vector3(0, 0, 0);
Vector3 p2 = new Vector3(5, 5, 0);
Line line = new Line(p1, p2);
Line line = new Line(p2, p1);

dxf.Entities.Add(line);

Expand All @@ -7486,8 +7526,10 @@ private static void LinearDimensionDrawing()
double offset = 7;
LinearDimension dimX = new LinearDimension(line, offset, 0.0, Vector3.UnitZ, myStyle);
dimX.Rotation += 30.0;
dimX.Update();
LinearDimension dimY = new LinearDimension(line, offset, 90.0, Vector3.UnitZ, myStyle);
dimY.Rotation += 30.0;
dimY.Update();

XData xdata = new XData(new ApplicationRegistry("other application"));
xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));
Expand Down
Binary file modified TestDxfDocument/sample binary.dxf
Binary file not shown.
Loading

0 comments on commit 6b4f0ae

Please sign in to comment.